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 01f1196e5..276d7db2c 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -87,4 +87,42 @@ 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); + } +} + +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); +} + +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 21dc7d08a..fe1870eb8 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -48,6 +48,14 @@ 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); + + 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 0bd4e3dd4..68c4d39fe 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(); @@ -222,56 +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); - - if (mouseLeave == true) - { - _webBrowserInternal->SetTooltipText(nullptr); - } - } -} - -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::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()); @@ -383,130 +323,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 61f065a9f..49457c4ca 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,13 +98,9 @@ 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); - 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(); @@ -115,47 +110,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.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.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index f39c5b0cc..10063f411 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -231,17 +231,16 @@ 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) { + 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); } @@ -255,27 +254,12 @@ namespace CefSharp.OffScreen return false; } - public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) - { - managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); - } - - public IFrame GetMainFrame() - { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetMainFrame() : null; - } - - public IFrame GetFocusedFrame() - { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetFocusedFrame() : null; - } - 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 +316,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 +407,5 @@ namespace CefSharp.OffScreen { TooltipText = tooltipText; } - #endregion } } diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 382747de4..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; @@ -142,7 +141,7 @@ namespace CefSharp.WinForms { if (IsBrowserInitialized) { - GetMainFrame().LoadUrl(url); + this.GetMainFrame().LoadUrl(url); } else { @@ -152,14 +151,14 @@ 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); } - public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) - { - managedCefBrowserAdapter.OnMouseWheel(x, y, deltaX, deltaY); - } - protected override void OnHandleCreated(EventArgs e) { managedCefBrowserAdapter.CreateBrowser(BrowserSettings, Handle, Address); @@ -317,10 +316,9 @@ namespace CefSharp.WinForms public void NotifyMoveOrResizeStarted() { - if (IsBrowserInitialized) - { - managedCefBrowserAdapter.NotifyMoveOrResizeStarted(); - } + this.ThrowExceptionIfBrowserNotInitialized(); + + managedCefBrowserAdapter.NotifyMoveOrResizeStarted(); } protected override void OnGotFocus(EventArgs e) @@ -334,25 +332,16 @@ namespace CefSharp.WinForms /// public void SetFocus(bool isFocused) { - if (IsBrowserInitialized) - { - managedCefBrowserAdapter.SetFocus(isFocused); - } - } + this.ThrowExceptionIfBrowserNotInitialized(); - public IFrame GetMainFrame() - { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetMainFrame() : null; - } - - public IFrame GetFocusedFrame() - { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetFocusedFrame() : null; + managedCefBrowserAdapter.SetFocus(isFocused); } public IBrowser GetBrowser() { - return IsBrowserInitialized ? managedCefBrowserAdapter.GetBrowser() : null; + this.ThrowExceptionIfBrowserNotInitialized(); + + return managedCefBrowserAdapter.GetBrowser(); } } } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 975815587..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); } } @@ -1173,9 +1175,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 +1188,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(); @@ -1215,11 +1214,15 @@ 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); } } @@ -1235,9 +1238,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); } } @@ -1259,7 +1264,7 @@ namespace CefSharp.Wpf Dispatcher ); - GetMainFrame().LoadUrl(url); + this.GetMainFrame().LoadUrl(url); } } @@ -1289,6 +1294,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); } @@ -1312,15 +1322,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). /// @@ -1333,16 +1334,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.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..99318ad16 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -91,6 +91,7 @@ + @@ -155,6 +156,7 @@ + diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index eac83d09a..5ab7c984e 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -24,5 +24,41 @@ 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); + + /// + /// 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); + + /// + /// Send a mouse click event to the browser. + /// + /// 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); } } diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index b753373bc..222ed3f30 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -180,27 +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. - /// - /// Frame - IFrame GetMainFrame(); - - /// - /// Returns the focused frame for the browser window. - /// - /// Frame - IFrame GetFocusedFrame(); /// /// Returns the current CEF Browser Instance diff --git a/CefSharp/MouseButtonType.cs b/CefSharp/MouseButtonType.cs new file mode 100644 index 000000000..97e1e99d2 --- /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 + } +} 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 + }; +} diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index dafe1c10f..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 /// @@ -538,6 +564,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) @@ -553,6 +595,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)