From 091339de255b3f492506d09ed01bf19981d27907 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 1 Jul 2015 19:24:49 +1000 Subject: [PATCH 01/11] OffScreen control - update to throw exception if Browser has not been initialized It's quite common for users to attempt to execute a browser function before it's initialized and for it to silently fail if it's not been initialized --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 20 +++++++++++--------- CefSharp/WebBrowserExtensions.cs | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index f39c5b0cc..1b6766902 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -257,25 +257,31 @@ namespace CefSharp.OffScreen public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) { + this.ThrowExceptionIfBrowserNotInitialized(); + managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); } public IFrame GetMainFrame() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetMainFrame() : null; + this.ThrowExceptionIfBrowserNotInitialized(); + + return managedCefBrowserAdapter.GetMainFrame(); } public IFrame GetFocusedFrame() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetFocusedFrame() : null; + this.ThrowExceptionIfBrowserNotInitialized(); + + return managedCefBrowserAdapter.GetFocusedFrame(); } public IBrowser GetBrowser() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetBrowser() : null; - } + this.ThrowExceptionIfBrowserNotInitialized(); - #region IRenderWebBrowser (rendering to bitmap; derived from CefSharp.Wpf.ChromiumWebBrowser) + return managedCefBrowserAdapter.GetBrowser(); + } ScreenInfo IRenderWebBrowser.GetScreenInfo() { @@ -332,9 +338,6 @@ namespace CefSharp.OffScreen void IRenderWebBrowser.SetPopupSizeAndPosition(int width, int height, int x, int y) { } - #endregion - - #region IWebBrowserInternal (notifications from CEF to C#; derived from CefSharp.Wpf.ChromiumWebBrowser) void IWebBrowserInternal.OnConsoleMessage(string message, string source, int line) { @@ -426,6 +429,5 @@ namespace CefSharp.OffScreen { TooltipText = tooltipText; } - #endregion } } diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index dafe1c10f..155ed4412 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -553,6 +553,15 @@ namespace CefSharp } } + public static void ThrowExceptionIfBrowserNotInitialized(this IWebBrowser browser) + { + if (!browser.IsBrowserInitialized) + { + throw new Exception("Browser Is Not yet initialized. Use the IsBrowserInitializedChanged event and check" + + "the IsBrowserInitialized property to determine when the browser has been intialized."); + } + } + private static void ThrowExceptionIfFrameNull(IFrame frame) { if (frame == null) From 93e99dadfc644a511050cdafa9ae33eea5ad1bf5 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 1 Jul 2015 19:27:04 +1000 Subject: [PATCH 02/11] Apply changes to the WinForms control so exception throw Will refactor a few more methods into extensions so it's not really a problem --- CefSharp.WinForms/ChromiumWebBrowser.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 382747de4..f7ec146a9 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -157,6 +157,8 @@ namespace CefSharp.WinForms public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) { + this.ThrowExceptionIfBrowserNotInitialized(); + managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); } @@ -317,10 +319,9 @@ namespace CefSharp.WinForms public void NotifyMoveOrResizeStarted() { - if (IsBrowserInitialized) - { - managedCefBrowserAdapter.NotifyMoveOrResizeStarted(); - } + this.ThrowExceptionIfBrowserNotInitialized(); + + managedCefBrowserAdapter.NotifyMoveOrResizeStarted(); } protected override void OnGotFocus(EventArgs e) @@ -334,25 +335,26 @@ namespace CefSharp.WinForms /// public void SetFocus(bool isFocused) { - if (IsBrowserInitialized) - { - managedCefBrowserAdapter.SetFocus(isFocused); - } + this.ThrowExceptionIfBrowserNotInitialized(); + + managedCefBrowserAdapter.SetFocus(isFocused); } public IFrame GetMainFrame() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetMainFrame() : null; + this.ThrowExceptionIfBrowserNotInitialized(); + + return managedCefBrowserAdapter.GetMainFrame(); } public IFrame GetFocusedFrame() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetFocusedFrame() : null; + return managedCefBrowserAdapter.GetFocusedFrame(); } public IBrowser GetBrowser() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetBrowser() : null; + return managedCefBrowserAdapter.GetBrowser(); } } } From f239503bb356872dec01ab9294985a64e6b18ae1 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 1 Jul 2015 19:38:14 +1000 Subject: [PATCH 03/11] Move SendMouseWheelEvent to IBrowserHost --- .../Internals/CefBrowserHostWrapper.cpp | 12 ++++++++++++ CefSharp.Core/Internals/CefBrowserHostWrapper.h | 2 ++ CefSharp.Core/ManagedCefBrowserAdapter.cpp | 14 -------------- CefSharp.Core/ManagedCefBrowserAdapter.h | 1 - CefSharp.OffScreen/ChromiumWebBrowser.cs | 7 ------- CefSharp.WinForms/ChromiumWebBrowser.cs | 7 ------- CefSharp.Wpf/ChromiumWebBrowser.cs | 11 ++++------- CefSharp/IBrowserHost.cs | 9 +++++++++ CefSharp/IWebBrowser.cs | 9 --------- CefSharp/WebBrowserExtensions.cs | 16 ++++++++++++++++ 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp index 01f1196e5..064f5f224 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -87,4 +87,16 @@ double CefBrowserHostWrapper::GetZoomLevelOnUI() } return 0.0; +} + +void CefBrowserHostWrapper::SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) +{ + if (_browserHost.get()) + { + CefMouseEvent mouseEvent; + mouseEvent.x = x; + mouseEvent.y = y; + + _browserHost->SendMouseWheelEvent(mouseEvent, deltaX, deltaY); + } } \ No newline at end of file diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.h b/CefSharp.Core/Internals/CefBrowserHostWrapper.h index 21dc7d08a..8a6f40286 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -48,6 +48,8 @@ namespace CefSharp virtual void Find(int identifier, String^ searchText, bool forward, bool matchCase, bool findNext); virtual void StopFinding(bool clearSelection); + + virtual void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); }; } } diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 0bd4e3dd4..824214d10 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -258,20 +258,6 @@ void ManagedCefBrowserAdapter::OnMouseButton(int x, int y, int mouseButtonType, } } -void ManagedCefBrowserAdapter::OnMouseWheel(int x, int y, int deltaX, int deltaY) -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser != nullptr) - { - CefMouseEvent mouseEvent; - mouseEvent.x = x; - mouseEvent.y = y; - - browser->GetHost()->SendMouseWheelEvent(mouseEvent, deltaX, deltaY); - } -} - void ManagedCefBrowserAdapter::CreateBrowser(BrowserSettings^ browserSettings, IntPtr sourceHandle, String^ address) { HWND hwnd = static_cast(sourceHandle.ToPointer()); diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index 61f065a9f..5a29e5906 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -105,7 +105,6 @@ namespace CefSharp bool SendKeyEvent(int message, int wParam, int lParam); void OnMouseMove(int x, int y, bool mouseLeave, CefEventFlags modifiers); void OnMouseButton(int x, int y, int mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); - void OnMouseWheel(int x, int y, int deltaX, int deltaY); void Resize(int width, int height); void NotifyMoveOrResizeStarted(); void NotifyScreenInfoChanged(); diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 1b6766902..1f40b676b 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -255,13 +255,6 @@ namespace CefSharp.OffScreen return false; } - public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) - { - this.ThrowExceptionIfBrowserNotInitialized(); - - managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); - } - public IFrame GetMainFrame() { this.ThrowExceptionIfBrowserNotInitialized(); diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index f7ec146a9..c443e266d 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -155,13 +155,6 @@ namespace CefSharp.WinForms managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, camelCaseJavascriptNames); } - public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) - { - this.ThrowExceptionIfBrowserNotInitialized(); - - managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); - } - protected override void OnHandleCreated(EventArgs e) { managedCefBrowserAdapter.CreateBrowser(BrowserSettings, Handle, Address); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 975815587..f07506a52 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1173,9 +1173,11 @@ namespace CefSharp.Wpf { var point = GetPixelPosition(e); - if (managedCefBrowserAdapter != null) + var browser = GetBrowser(); + + if (browser != null) { - managedCefBrowserAdapter.OnMouseWheel( + browser.SendMouseWheelEvent( (int)point.X, (int)point.Y, deltaX: 0, @@ -1184,11 +1186,6 @@ namespace CefSharp.Wpf } } - public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) - { - managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); - } - protected void PopupMouseEnter(object sender, MouseEventArgs e) { Focus(); diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index eac83d09a..7687a8ef6 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -24,5 +24,14 @@ namespace CefSharp void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext); void StopFinding(bool clearSelection); + + /// + /// Send a mouse wheel event to the browser. + /// + /// X-Axis coordinate relative to the upper-left corner of the view. + /// Y-Axis coordinate relative to the upper-left corner of the view. + /// Movement delta for X direction. + /// movement delta for Y direction. + void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); } } diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index b753373bc..3247e3bb4 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -180,15 +180,6 @@ namespace CefSharp /// true if keyboard focus and logical focus were set to this element; false if only logical focus /// was set to this element, or if the call to this method did not force the focus to change. bool Focus(); - - /// - /// Send a mouse wheel event to the browser. - /// - /// X-Axis coordinate relative to the upper-left corner of the view. - /// Y-Axis coordinate relative to the upper-left corner of the view. - /// Movement delta for X direction. - /// movement delta for Y direction. - void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); /// /// Returns the main (top-level) frame for the browser window. diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 155ed4412..38bc7aa92 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -538,6 +538,22 @@ namespace CefSharp cefBrowser.AddWordToDictionary(word); } + public static void SendMouseWheelEvent(this IWebBrowser browser, int x, int y, int deltaX, int deltaY) + { + var cefBrowser = browser.GetBrowser(); + ThrowExceptionIfBrowserNull(cefBrowser); + + cefBrowser.SendMouseWheelEvent(x, y, deltaX, deltaY); + } + + public static void SendMouseWheelEvent(this IBrowser browser, int x, int y, int deltaX, int deltaY) + { + var host = browser.GetHost(); + ThrowExceptionIfBrowserHostNull(host); + + host.SendMouseWheelEvent(x, y, deltaX, deltaY); + } + public static Task EvaluateScriptAsync(this IWebBrowser browser, string script, TimeSpan? timeout = null) { if (timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32.MaxValue) From df94d54a610b7519a97a9583580b16e3b30bf9d2 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 1 Jul 2015 19:49:27 +1000 Subject: [PATCH 04/11] Remove duplicate GetMainFrame and GetFocusedFrame methods - turned them into extensions --- CefSharp.Core/ManagedCefBrowserAdapter.cpp | 124 --------------------- CefSharp.Core/ManagedCefBrowserAdapter.h | 41 ------- CefSharp.OffScreen/ChromiumWebBrowser.cs | 22 +--- CefSharp.WinForms/ChromiumWebBrowser.cs | 14 +-- CefSharp.Wpf/ChromiumWebBrowser.cs | 12 +- CefSharp/IWebBrowser.cs | 12 -- CefSharp/WebBrowserExtensions.cs | 26 +++++ 7 files changed, 29 insertions(+), 222 deletions(-) diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 824214d10..f57452eef 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -369,130 +369,6 @@ void ManagedCefBrowserAdapter::OnDragTargetDragDrop(MouseEvent^ mouseEvent) } } -/// -// Returns the number of frames that currently exist. -/// -/*--cef()--*/ -int ManagedCefBrowserAdapter::GetFrameCount() -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser != nullptr) - { - return browser->GetFrameCount(); - } - return 0; -} - -/// -// Returns the identifiers of all existing frames. -/// -/*--cef(count_func=identifiers:GetFrameCount)--*/ -List^ ManagedCefBrowserAdapter::GetFrameIdentifiers() -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser == nullptr) - { - return nullptr; - } - - std::vector identifiers; - browser->GetFrameIdentifiers(identifiers); - List^ results = gcnew List(identifiers.size()); - for (UINT i = 0; i < identifiers.size(); i++) - { - results->Add(identifiers[i]); - } - return results; -} - -/// -// Returns the names of all existing frames. -/// -/*--cef()--*/ -List^ ManagedCefBrowserAdapter::GetFrameNames() -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser == nullptr) - { - return nullptr; - } - - std::vector names; - browser->GetFrameNames(names); - return StringUtils::ToClr(names); -} - -/// -// Returns the main (top-level) frame for the browser window. -/// -IFrame^ ManagedCefBrowserAdapter::GetMainFrame() -{ - auto browser = _clientAdapter->GetCefBrowser(); - if (browser == nullptr) - { - return nullptr; - } - return gcnew CefFrameWrapper(browser->GetMainFrame()); -} - -/// -// Returns the focused frame for the browser window. -/// -/*--cef()--*/ -IFrame^ ManagedCefBrowserAdapter::GetFocusedFrame() -{ - auto browser = _clientAdapter->GetCefBrowser(); - if (browser == nullptr) - { - return nullptr; - } - - return gcnew CefFrameWrapper(browser->GetFocusedFrame()); -} - -/// -// Returns the frame with the specified identifier, or NULL if not found. -/// -/*--cef(capi_name=get_frame_byident)--*/ -IFrame^ ManagedCefBrowserAdapter::GetFrame(System::Int64 identifier) -{ - auto browser = _clientAdapter->GetCefBrowser(); - if (browser == nullptr) - { - return nullptr; - } - auto result = browser->GetFrame(identifier); - if (result == nullptr) - { - return nullptr; - } - - return gcnew CefFrameWrapper(result); -} - -/// -// Returns the frame with the specified name, or NULL if not found. -/// -/*--cef(optional_param=name)--*/ -IFrame^ ManagedCefBrowserAdapter::GetFrame(String^ name) -{ - auto browser = _clientAdapter->GetCefBrowser(); - if (browser == nullptr) - { - return nullptr; - } - auto result = browser->GetFrame(StringUtils::ToNative(name)); - if (result == nullptr) - { - return nullptr; - } - - return gcnew CefFrameWrapper(result); -} - /// /// Gets the CefBrowserWrapper instance /// diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index 5a29e5906..0e045dbcc 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -114,47 +114,6 @@ namespace CefSharp void OnDragTargetDragLeave(); void OnDragTargetDragDrop(MouseEvent^ mouseEvent); - /// - // Returns the main (top-level) frame for the browser window. - /// - IFrame^ GetMainFrame(); - - /// - // Returns the focused frame for the browser window. - /// - /*--cef()--*/ - IFrame^ GetFocusedFrame(); - - /// - // Returns the frame with the specified identifier, or NULL if not found. - /// - /*--cef(capi_name=get_frame_byident)--*/ - IFrame^ GetFrame(System::Int64 identifier); - - /// - // Returns the frame with the specified name, or NULL if not found. - /// - /*--cef(optional_param=name)--*/ - IFrame^ GetFrame(String^ name); - - /// - // Returns the number of frames that currently exist. - /// - /*--cef()--*/ - int GetFrameCount(); - - /// - // Returns the identifiers of all existing frames. - /// - /*--cef(count_func=identifiers:GetFrameCount)--*/ - List^ GetFrameIdentifiers(); - - /// - // Returns the names of all existing frames. - /// - /*--cef()--*/ - List^ GetFrameNames(); - /// /// Gets the CefBrowserWrapper instance /// diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 1f40b676b..359f8c515 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -231,13 +231,7 @@ namespace CefSharp.OffScreen { Address = url; - var frame = GetMainFrame(); - if (frame == null) - { - throw new Exception("IFrame instance is null. Browser has likely not finished initializing or is in the process of disposing."); - } - - frame.LoadUrl(url); + this.GetMainFrame().LoadUrl(url); } public void RegisterJsObject(string name, object objectToBind, bool camelCaseJavascriptNames = true) @@ -255,20 +249,6 @@ namespace CefSharp.OffScreen return false; } - public IFrame GetMainFrame() - { - this.ThrowExceptionIfBrowserNotInitialized(); - - return managedCefBrowserAdapter.GetMainFrame(); - } - - public IFrame GetFocusedFrame() - { - this.ThrowExceptionIfBrowserNotInitialized(); - - return managedCefBrowserAdapter.GetFocusedFrame(); - } - public IBrowser GetBrowser() { this.ThrowExceptionIfBrowserNotInitialized(); diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index c443e266d..e97d809cf 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -142,7 +142,7 @@ namespace CefSharp.WinForms { if (IsBrowserInitialized) { - GetMainFrame().LoadUrl(url); + this.GetMainFrame().LoadUrl(url); } else { @@ -333,18 +333,6 @@ namespace CefSharp.WinForms managedCefBrowserAdapter.SetFocus(isFocused); } - public IFrame GetMainFrame() - { - this.ThrowExceptionIfBrowserNotInitialized(); - - return managedCefBrowserAdapter.GetMainFrame(); - } - - public IFrame GetFocusedFrame() - { - return managedCefBrowserAdapter.GetFocusedFrame(); - } - public IBrowser GetBrowser() { return managedCefBrowserAdapter.GetBrowser(); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index f07506a52..b49431c16 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1256,7 +1256,7 @@ namespace CefSharp.Wpf Dispatcher ); - GetMainFrame().LoadUrl(url); + this.GetMainFrame().LoadUrl(url); } } @@ -1330,16 +1330,6 @@ namespace CefSharp.Wpf return managedCefBrowserAdapter.SendKeyEvent(message, wParam, lParam); } - public IFrame GetMainFrame() - { - return managedCefBrowserAdapter == null ? null : managedCefBrowserAdapter.GetMainFrame(); - } - - public IFrame GetFocusedFrame() - { - return managedCefBrowserAdapter == null ? null : managedCefBrowserAdapter.GetFocusedFrame(); - } - public IBrowser GetBrowser() { return managedCefBrowserAdapter == null ? null : managedCefBrowserAdapter.GetBrowser(); diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index 3247e3bb4..222ed3f30 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -181,18 +181,6 @@ namespace CefSharp /// was set to this element, or if the call to this method did not force the focus to change. bool Focus(); - /// - /// Returns the main (top-level) frame for the browser window. - /// - /// Frame - IFrame GetMainFrame(); - - /// - /// Returns the focused frame for the browser window. - /// - /// Frame - IFrame GetFocusedFrame(); - /// /// Returns the current CEF Browser Instance /// diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 38bc7aa92..cdac033b5 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -10,6 +10,32 @@ namespace CefSharp { public static class WebBrowserExtensions { + /// + /// Returns the main (top-level) frame for the browser window. + /// + /// Frame + public static IFrame GetMainFrame(this IWebBrowser webBrowser) + { + var browser = webBrowser.GetBrowser(); + + ThrowExceptionIfBrowserNull(browser); + + return browser.MainFrame; + } + + /// + /// Returns the focused frame for the browser window. + /// + /// Frame + public static IFrame GetFocusedFrame(this IWebBrowser webBrowser) + { + var browser = webBrowser.GetBrowser(); + + ThrowExceptionIfBrowserNull(browser); + + return browser.FocusedFrame; + } + /// /// Execute Undo on the focused frame /// From cf10fdf9dc7bb9c3e8eece4e7430f0774cf6ebda Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 1 Jul 2015 19:58:54 +1000 Subject: [PATCH 05/11] Add ThrowExceptionIfBrowserNotInitialized to WinForms GetBrowser Haven't done WPF yet as it's IsBrowserInitialized implementation is a DependencyProperty which will likely cause problems if run on a CEF thread --- CefSharp.WinForms/ChromiumWebBrowser.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index e97d809cf..b4daff681 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -335,6 +335,8 @@ namespace CefSharp.WinForms public IBrowser GetBrowser() { + this.ThrowExceptionIfBrowserNotInitialized(); + return managedCefBrowserAdapter.GetBrowser(); } } From bbe267b44c3e0ad903695422d8707ea9a909ffb8 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 6 Jul 2015 12:16:58 +1000 Subject: [PATCH 06/11] Throw exception if IsBrowserInitialized when trying to call RegisterJsObject --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 5 +++++ CefSharp.WinForms/ChromiumWebBrowser.cs | 6 +++++- CefSharp.Wpf/ChromiumWebBrowser.cs | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 359f8c515..10063f411 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -236,6 +236,11 @@ namespace CefSharp.OffScreen public void RegisterJsObject(string name, object objectToBind, bool camelCaseJavascriptNames = true) { + if (IsBrowserInitialized) + { + throw new Exception("Browser is already initialized. RegisterJsObject must be" + + "called before the underlying CEF browser is created."); + } managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, camelCaseJavascriptNames); } diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index b4daff681..a036a9dfa 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -3,7 +3,6 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; -using System.Threading.Tasks; using System.Windows.Forms; using CefSharp.Internals; using CefSharp.WinForms.Internals; @@ -152,6 +151,11 @@ namespace CefSharp.WinForms public void RegisterJsObject(string name, object objectToBind, bool camelCaseJavascriptNames = true) { + if (IsBrowserInitialized) + { + throw new Exception("Browser is already initialized. RegisterJsObject must be" + + "called before the underlying CEF browser is created."); + } managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, camelCaseJavascriptNames); } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index b49431c16..704b47448 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1286,6 +1286,11 @@ namespace CefSharp.Wpf public void RegisterJsObject(string name, object objectToBind, bool camelCaseJavascriptNames = true) { + if (IsBrowserInitialized) + { + throw new Exception("Browser is already initialized. RegisterJsObject must be" + + "called before the underlying CEF browser is created."); + } managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, camelCaseJavascriptNames); } From fbe8ccd61c2dd08a8acb5ccfc7070f59c1e8328d Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 6 Jul 2015 12:25:09 +1000 Subject: [PATCH 07/11] Move Invalidate method from ManagedCefBrowserAdapter into CefBrowserHostWrapper - now can be used in OffScreen --- CefSharp.Core/CefSharp.Core.vcxproj | 1 - CefSharp.Core/CefSharp.Core.vcxproj.filters | 3 --- .../Internals/CefBrowserHostWrapper.cpp | 5 +++++ CefSharp.Core/Internals/CefBrowserHostWrapper.h | 2 ++ CefSharp.Core/ManagedCefBrowserAdapter.cpp | 10 ---------- CefSharp.Core/ManagedCefBrowserAdapter.h | 2 -- CefSharp.Core/PaintElementType.h | 16 ---------------- CefSharp.Wpf/ChromiumWebBrowser.cs | 9 --------- CefSharp.Wpf/IWpfWebBrowser.cs | 6 ------ CefSharp/CefSharp.csproj | 1 + CefSharp/IBrowserHost.cs | 7 +++++++ CefSharp/PaintElementType.cs | 12 ++++++++++++ 12 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 CefSharp.Core/PaintElementType.h create mode 100644 CefSharp/PaintElementType.cs diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 251aaa81a..3c8727ae2 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -277,7 +277,6 @@ - diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index 40b6058ed..055c55c71 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -100,9 +100,6 @@ Header Files - - Header Files - Header Files diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp index 064f5f224..31e1c4d8d 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -99,4 +99,9 @@ void CefBrowserHostWrapper::SendMouseWheelEvent(int x, int y, int deltaX, int de _browserHost->SendMouseWheelEvent(mouseEvent, deltaX, deltaY); } +} + +void CefBrowserHostWrapper::Invalidate(PaintElementType type) +{ + _browserHost->Invalidate((CefBrowserHost::PaintElementType)type); } \ No newline at end of file diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.h b/CefSharp.Core/Internals/CefBrowserHostWrapper.h index 8a6f40286..922f74192 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -50,6 +50,8 @@ namespace CefSharp virtual void StopFinding(bool clearSelection); virtual void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); + + virtual void Invalidate(PaintElementType type); }; } } diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index f57452eef..4a703c2ec 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -73,16 +73,6 @@ void ManagedCefBrowserAdapter::WasHidden(bool hidden) } } -void ManagedCefBrowserAdapter::Invalidate(PaintElementType type) -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser != nullptr) - { - browser->GetHost()->Invalidate((CefBrowserHost::PaintElementType)type); - } -} - void ManagedCefBrowserAdapter::SendFocusEvent(bool isFocused) { auto browser = _clientAdapter->GetCefBrowser(); diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index 0e045dbcc..bda5aa2ca 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -9,7 +9,6 @@ #include #include "BrowserSettings.h" -#include "PaintElementType.h" #include "Internals/ClientAdapter.h" #include "Internals/CefDragDataWrapper.h" #include "Internals/RenderClientAdapter.h" @@ -99,7 +98,6 @@ namespace CefSharp void CreateBrowser(BrowserSettings^ browserSettings, IntPtr sourceHandle, String^ address); void WasResized(); void WasHidden(bool hidden); - void Invalidate(PaintElementType type); void SendFocusEvent(bool isFocused); void SetFocus(bool isFocused); bool SendKeyEvent(int message, int wParam, int lParam); diff --git a/CefSharp.Core/PaintElementType.h b/CefSharp.Core/PaintElementType.h deleted file mode 100644 index 504df5c79..000000000 --- a/CefSharp.Core/PaintElementType.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright © 2010-2015 The CefSharp Authors. All rights reserved. -// -// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. - -#pragma once - -#include "include/cef_browser.h" - -namespace CefSharp -{ - public enum class PaintElementType - { - View = CefBrowserHost::PaintElementType::PET_VIEW, - Popup = CefBrowserHost::PaintElementType::PET_POPUP - }; -} \ No newline at end of file diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 704b47448..06e74ea1d 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1314,15 +1314,6 @@ namespace CefSharp.Wpf return pixelPosition; } - /// - /// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously. - /// - /// indicates which surface to re-paint either View or Popup. - public void Invalidate(PaintElementType type) - { - managedCefBrowserAdapter.Invalidate(type); - } - /// /// Sends a Key Event directly to the underlying Browser (CEF). /// diff --git a/CefSharp.Wpf/IWpfWebBrowser.cs b/CefSharp.Wpf/IWpfWebBrowser.cs index 0afbf4d49..9b8e5fa05 100644 --- a/CefSharp.Wpf/IWpfWebBrowser.cs +++ b/CefSharp.Wpf/IWpfWebBrowser.cs @@ -92,12 +92,6 @@ namespace CefSharp.Wpf /// ICommand RedoCommand { get; } - /// - /// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously. - /// - /// indicates which surface to re-paint either View or Popup. - void Invalidate(PaintElementType type); - /// /// Gets the associated with this instance. /// diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 9fc6c4a13..582fc8991 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -155,6 +155,7 @@ + diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index 7687a8ef6..57b7be924 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -33,5 +33,12 @@ namespace CefSharp /// Movement delta for X direction. /// movement delta for Y direction. void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); + + /// + /// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously. + /// This method is only used when window rendering is disabled (OSR). + /// + /// indicates which surface to re-paint either View or Popup. + void Invalidate(PaintElementType type); } } diff --git a/CefSharp/PaintElementType.cs b/CefSharp/PaintElementType.cs new file mode 100644 index 000000000..e9bd83f06 --- /dev/null +++ b/CefSharp/PaintElementType.cs @@ -0,0 +1,12 @@ +// Copyright © 2010-2015 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp +{ + public enum PaintElementType + { + View = 0, + Popup + }; +} From 98d186c33ceba784e70713fe8013d6abbe7e0302 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 6 Jul 2015 12:39:33 +1000 Subject: [PATCH 08/11] Move OnMouseButton into IBrowserHost (rename to SendMouseClickEvent) --- CefSharp.Core/Internals/CefBrowserHostWrapper.cpp | 10 ++++++++++ CefSharp.Core/Internals/CefBrowserHostWrapper.h | 2 ++ CefSharp.Core/ManagedCefBrowserAdapter.cpp | 15 --------------- CefSharp.Core/ManagedCefBrowserAdapter.h | 1 - CefSharp.Wpf/ChromiumWebBrowser.cs | 6 ++++-- CefSharp/CefSharp.csproj | 1 + CefSharp/IBrowserHost.cs | 11 +++++++++++ CefSharp/MouseButtonType.cs | 13 +++++++++++++ 8 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 CefSharp/MouseButtonType.cs diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp index 31e1c4d8d..01754a3e0 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -104,4 +104,14 @@ void CefBrowserHostWrapper::SendMouseWheelEvent(int x, int y, int deltaX, int de void CefBrowserHostWrapper::Invalidate(PaintElementType type) { _browserHost->Invalidate((CefBrowserHost::PaintElementType)type); +} + +void CefBrowserHostWrapper::SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers) +{ + CefMouseEvent mouseEvent; + mouseEvent.x = x; + mouseEvent.y = y; + mouseEvent.modifiers = (uint32)modifiers; + + _browserHost->SendMouseClickEvent(mouseEvent, (CefBrowserHost::MouseButtonType) mouseButtonType, mouseUp, clickCount); } \ No newline at end of file diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.h b/CefSharp.Core/Internals/CefBrowserHostWrapper.h index 922f74192..33894fc29 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -52,6 +52,8 @@ namespace CefSharp virtual void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY); virtual void Invalidate(PaintElementType type); + + virtual void SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); }; } } diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 4a703c2ec..0960d95a7 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -233,21 +233,6 @@ void ManagedCefBrowserAdapter::OnMouseMove(int x, int y, bool mouseLeave, CefEve } } -void ManagedCefBrowserAdapter::OnMouseButton(int x, int y, int mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers) -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser != nullptr) - { - CefMouseEvent mouseEvent; - mouseEvent.x = x; - mouseEvent.y = y; - mouseEvent.modifiers = (uint32)modifiers; - - browser->GetHost()->SendMouseClickEvent(mouseEvent, (CefBrowserHost::MouseButtonType) mouseButtonType, mouseUp, clickCount); - } -} - void ManagedCefBrowserAdapter::CreateBrowser(BrowserSettings^ browserSettings, IntPtr sourceHandle, String^ address) { HWND hwnd = static_cast(sourceHandle.ToPointer()); diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index bda5aa2ca..4f52eccce 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -102,7 +102,6 @@ namespace CefSharp void SetFocus(bool isFocused); bool SendKeyEvent(int message, int wParam, int lParam); void OnMouseMove(int x, int y, bool mouseLeave, CefEventFlags modifiers); - void OnMouseButton(int x, int y, int mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); void Resize(int width, int height); void NotifyMoveOrResizeStarted(); void NotifyScreenInfoChanged(); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 06e74ea1d..8542a2778 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1232,9 +1232,11 @@ namespace CefSharp.Wpf var mouseUp = (e.ButtonState == MouseButtonState.Released); var point = GetPixelPosition(e); - if (managedCefBrowserAdapter != null) + var browser = GetBrowser(); + + if (browser != null) { - managedCefBrowserAdapter.OnMouseButton((int)point.X, (int)point.Y, (int)e.ChangedButton, mouseUp, e.ClickCount, modifiers); + browser.GetHost().SendMouseClickEvent((int)point.X, (int)point.Y, (MouseButtonType)e.ChangedButton, mouseUp, e.ClickCount, modifiers); } } diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 582fc8991..99318ad16 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -91,6 +91,7 @@ + diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index 57b7be924..11209bb50 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -40,5 +40,16 @@ namespace CefSharp /// /// indicates which surface to re-paint either View or Popup. void Invalidate(PaintElementType type); + + /// + /// Send a mouse click event to the browser. The |x| and |y| coordinates are relative to the upper-left corner of the view. + /// + /// x + /// y + /// Mouse ButtonType + /// mouse up + /// click count + /// click modifiers e.g. Ctrl + void SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); } } diff --git a/CefSharp/MouseButtonType.cs b/CefSharp/MouseButtonType.cs new file mode 100644 index 000000000..a612ad56f --- /dev/null +++ b/CefSharp/MouseButtonType.cs @@ -0,0 +1,13 @@ +// Copyright © 2010-2015 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp +{ + public enum MouseButtonType + { + Left = 0, + Middle, + Right + } +} From 5c27b7befa2c21c7dc6e77fa23fb0cdb68ae7ba4 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 6 Jul 2015 12:42:50 +1000 Subject: [PATCH 09/11] Set toolTip to null after mouse leaves --- CefSharp.Core/ManagedCefBrowserAdapter.cpp | 5 ----- CefSharp.Wpf/ChromiumWebBrowser.cs | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 0960d95a7..69d433fbe 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -225,11 +225,6 @@ void ManagedCefBrowserAdapter::OnMouseMove(int x, int y, bool mouseLeave, CefEve mouseEvent.modifiers = (uint32)modifiers; browser->GetHost()->SendMouseMoveEvent(mouseEvent, mouseLeave); - - if (mouseLeave == true) - { - _webBrowserInternal->SetTooltipText(nullptr); - } } } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 8542a2778..3b11ab211 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1217,6 +1217,8 @@ namespace CefSharp.Wpf if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.OnMouseMove(-1, -1, true, modifiers); + + ((IWebBrowserInternal)this).SetTooltipText(null); } } From df29944016b2cbb86983d487449713a25d94b0a9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 6 Jul 2015 12:47:29 +1000 Subject: [PATCH 10/11] Implement SendMouseMoveEvent in IBrowserHost Can now be used by offscreen --- .../Internals/CefBrowserHostWrapper.cpp | 11 +++++++++++ .../Internals/CefBrowserHostWrapper.h | 2 ++ CefSharp.Core/ManagedCefBrowserAdapter.cpp | 16 ---------------- CefSharp.Core/ManagedCefBrowserAdapter.h | 1 - CefSharp.Wpf/ChromiumWebBrowser.cs | 18 +++++++++++------- CefSharp/IBrowserHost.cs | 15 ++++++++++++--- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp index 01754a3e0..276d7db2c 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -114,4 +114,15 @@ void CefBrowserHostWrapper::SendMouseClickEvent(int x, int y, MouseButtonType mo mouseEvent.modifiers = (uint32)modifiers; _browserHost->SendMouseClickEvent(mouseEvent, (CefBrowserHost::MouseButtonType) mouseButtonType, mouseUp, clickCount); +} + +void CefBrowserHostWrapper::SendMouseMoveEvent(int x, int y, bool mouseLeave, CefEventFlags modifiers) +{ + CefMouseEvent mouseEvent; + mouseEvent.x = x; + mouseEvent.y = y; + + mouseEvent.modifiers = (uint32)modifiers; + + _browserHost->SendMouseMoveEvent(mouseEvent, mouseLeave); } \ No newline at end of file diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.h b/CefSharp.Core/Internals/CefBrowserHostWrapper.h index 33894fc29..fe1870eb8 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -54,6 +54,8 @@ namespace CefSharp virtual void Invalidate(PaintElementType type); virtual void SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); + + virtual void SendMouseMoveEvent(int x, int y, bool mouseLeave, CefEventFlags modifiers); }; } } diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 69d433fbe..68c4d39fe 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -212,22 +212,6 @@ int ManagedCefBrowserAdapter::GetCefKeyboardModifiers(WPARAM wparam, LPARAM lpar return modifiers; } -void ManagedCefBrowserAdapter::OnMouseMove(int x, int y, bool mouseLeave, CefEventFlags modifiers) -{ - auto browser = _clientAdapter->GetCefBrowser(); - - if (browser != nullptr) - { - CefMouseEvent mouseEvent; - mouseEvent.x = x; - mouseEvent.y = y; - - mouseEvent.modifiers = (uint32)modifiers; - - browser->GetHost()->SendMouseMoveEvent(mouseEvent, mouseLeave); - } -} - void ManagedCefBrowserAdapter::CreateBrowser(BrowserSettings^ browserSettings, IntPtr sourceHandle, String^ address) { HWND hwnd = static_cast(sourceHandle.ToPointer()); diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index 4f52eccce..49457c4ca 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -101,7 +101,6 @@ namespace CefSharp void SendFocusEvent(bool isFocused); void SetFocus(bool isFocused); bool SendKeyEvent(int message, int wParam, int lParam); - void OnMouseMove(int x, int y, bool mouseLeave, CefEventFlags modifiers); void Resize(int width, int height); void NotifyMoveOrResizeStarted(); void NotifyScreenInfoChanged(); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 3b11ab211..c97b481c4 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1160,12 +1160,14 @@ namespace CefSharp.Wpf protected override void OnMouseMove(MouseEventArgs e) { - var point = GetPixelPosition(e); - var modifiers = GetModifiers(e); + var browser = GetBrowser(); - if (managedCefBrowserAdapter != null) + if (browser != null) { - managedCefBrowserAdapter.OnMouseMove((int)point.X, (int)point.Y, false, modifiers); + var point = GetPixelPosition(e); + var modifiers = GetModifiers(e); + + browser.GetHost().SendMouseMoveEvent((int)point.X, (int)point.Y, false, modifiers); } } @@ -1212,11 +1214,13 @@ namespace CefSharp.Wpf protected override void OnMouseLeave(MouseEventArgs e) { - var modifiers = GetModifiers(e); + var browser = GetBrowser(); - if (managedCefBrowserAdapter != null) + if (browser != null) { - managedCefBrowserAdapter.OnMouseMove(-1, -1, true, modifiers); + var modifiers = GetModifiers(e); + + browser.GetHost().SendMouseMoveEvent(-1, -1, true, modifiers); ((IWebBrowserInternal)this).SetTooltipText(null); } diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index 11209bb50..5ab7c984e 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -42,14 +42,23 @@ namespace CefSharp void Invalidate(PaintElementType type); /// - /// Send a mouse click event to the browser. The |x| and |y| coordinates are relative to the upper-left corner of the view. + /// Send a mouse click event to the browser. /// - /// x - /// y + /// x coordinate - relative to upper-left corner of view + /// y coordinate - relative to upper-left corner of view /// Mouse ButtonType /// mouse up /// click count /// click modifiers e.g. Ctrl void SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers); + + /// + /// Send a mouse move event to the browser + /// + /// x coordinate - relative to upper-left corner of view + /// y coordinate - relative to upper-left corner of view + /// mouse leave + /// click modifiers .e.g Ctrl + void SendMouseMoveEvent(int x, int y, bool mouseLeave, CefEventFlags modifiers); } } From 0188329d10aab7e79805d8534304b855fc6b02c9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 7 Jul 2015 10:26:45 +1000 Subject: [PATCH 11/11] Untabify --- CefSharp/MouseButtonType.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CefSharp/MouseButtonType.cs b/CefSharp/MouseButtonType.cs index a612ad56f..97e1e99d2 100644 --- a/CefSharp/MouseButtonType.cs +++ b/CefSharp/MouseButtonType.cs @@ -4,10 +4,10 @@ namespace CefSharp { - public enum MouseButtonType - { - Left = 0, - Middle, - Right - } + public enum MouseButtonType + { + Left = 0, + Middle, + Right + } }