Merge pull request #1100 from amaitland/cleanup/throwexceptions

Throw Exceptions rather than Fail quietly
This commit is contained in:
Alex Maitland
2015-07-07 10:34:14 +10:00
17 changed files with 210 additions and 367 deletions
-1
View File
@@ -277,7 +277,6 @@
<ClInclude Include="Internals\TypeConversion.h" />
<ClInclude Include="NativeMethodWrapper.h" />
<ClInclude Include="Internals\Serialization\V8Serialization.h" />
<ClInclude Include="PaintElementType.h" />
<ClInclude Include="ManagedCefBrowserAdapter.h" />
<ClInclude Include="CefSettings.h" />
<ClInclude Include="Internals\Serialization\Primitives.h" />
@@ -100,9 +100,6 @@
<ClInclude Include="BrowserSettings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PaintElementType.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Internals\RenderClientAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -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);
}
@@ -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);
};
}
}
-184
View File
@@ -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<HWND>(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<Int64>^ ManagedCefBrowserAdapter::GetFrameIdentifiers()
{
auto browser = _clientAdapter->GetCefBrowser();
if (browser == nullptr)
{
return nullptr;
}
std::vector<Int64> identifiers;
browser->GetFrameIdentifiers(identifiers);
List<Int64>^ results = gcnew List<Int64>(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<String^>^ ManagedCefBrowserAdapter::GetFrameNames()
{
auto browser = _clientAdapter->GetCefBrowser();
if (browser == nullptr)
{
return nullptr;
}
std::vector<CefString> 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);
}
/// <summary>
/// Gets the CefBrowserWrapper instance
/// </summary>
-46
View File
@@ -9,7 +9,6 @@
#include <include/cef_runnable.h>
#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<System::Int64>^ GetFrameIdentifiers();
///
// Returns the names of all existing frames.
///
/*--cef()--*/
List<String^>^ GetFrameNames();
/// <summary>
/// Gets the CefBrowserWrapper instance
/// </summary>
-16
View File
@@ -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
};
}
+9 -29
View File
@@ -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
}
}
+14 -25
View File
@@ -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
/// </summary>
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();
}
}
}
+27 -36
View File
@@ -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;
}
/// <summary>
/// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously.
/// </summary>
/// <param name="type">indicates which surface to re-paint either View or Popup.</param>
public void Invalidate(PaintElementType type)
{
managedCefBrowserAdapter.Invalidate(type);
}
/// <summary>
/// Sends a Key Event directly to the underlying Browser (CEF).
/// </summary>
@@ -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();
-6
View File
@@ -92,12 +92,6 @@ namespace CefSharp.Wpf
/// </summary>
ICommand RedoCommand { get; }
/// <summary>
/// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously.
/// </summary>
/// <param name="type">indicates which surface to re-paint either View or Popup.</param>
void Invalidate(PaintElementType type);
/// <summary>
/// Gets the <see cref="Dispatcher"/> associated with this instance.
/// </summary>
+2
View File
@@ -91,6 +91,7 @@
<Compile Include="CefDirtyRect.cs" />
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="CefJsDialogType.cs" />
<Compile Include="MouseButtonType.cs" />
<Compile Include="CefReturnValue.cs" />
<Compile Include="CefSharpSettings.cs" />
<Compile Include="CefThreadIds.cs" />
@@ -155,6 +156,7 @@
<Compile Include="Internals\BrowserProcessServiceHost.cs" />
<Compile Include="Internals\WCFExtensions.cs" />
<Compile Include="KeyType.cs" />
<Compile Include="PaintElementType.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="ResourceHandler.cs" />
<Compile Include="ResponseAction.cs" />
+36
View File
@@ -24,5 +24,41 @@ namespace CefSharp
void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);
void StopFinding(bool clearSelection);
/// <summary>
/// Send a mouse wheel event to the browser.
/// </summary>
/// <param name="x">X-Axis coordinate relative to the upper-left corner of the view.</param>
/// <param name="y">Y-Axis coordinate relative to the upper-left corner of the view.</param>
/// <param name="deltaX">Movement delta for X direction.</param>
/// <param name="deltaY">movement delta for Y direction.</param>
void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY);
/// <summary>
/// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously.
/// This method is only used when window rendering is disabled (OSR).
/// </summary>
/// <param name="type">indicates which surface to re-paint either View or Popup.</param>
void Invalidate(PaintElementType type);
/// <summary>
/// Send a mouse click event to the browser.
/// </summary>
/// <param name="x">x coordinate - relative to upper-left corner of view</param>
/// <param name="y">y coordinate - relative to upper-left corner of view</param>
/// <param name="mouseButtonType">Mouse ButtonType</param>
/// <param name="mouseUp">mouse up</param>
/// <param name="clickCount">click count</param>
/// <param name="modifiers">click modifiers e.g. Ctrl</param>
void SendMouseClickEvent(int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers);
/// <summary>
/// Send a mouse move event to the browser
/// </summary>
/// <param name="x">x coordinate - relative to upper-left corner of view</param>
/// <param name="y">y coordinate - relative to upper-left corner of view</param>
/// <param name="mouseLeave">mouse leave</param>
/// <param name="modifiers">click modifiers .e.g Ctrl</param>
void SendMouseMoveEvent(int x, int y, bool mouseLeave, CefEventFlags modifiers);
}
}
-21
View File
@@ -180,27 +180,6 @@ namespace CefSharp
/// <returns><c>true</c> if keyboard focus and logical focus were set to this element; <c>false</c> if only logical focus
/// was set to this element, or if the call to this method did not force the focus to change.</returns>
bool Focus();
/// <summary>
/// Send a mouse wheel event to the browser.
/// </summary>
/// <param name="x">X-Axis coordinate relative to the upper-left corner of the view.</param>
/// <param name="y">Y-Axis coordinate relative to the upper-left corner of the view.</param>
/// <param name="deltaX">Movement delta for X direction.</param>
/// <param name="deltaY">movement delta for Y direction.</param>
void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY);
/// <summary>
/// Returns the main (top-level) frame for the browser window.
/// </summary>
/// <returns>Frame</returns>
IFrame GetMainFrame();
/// <summary>
/// Returns the focused frame for the browser window.
/// </summary>
/// <returns>Frame</returns>
IFrame GetFocusedFrame();
/// <summary>
/// Returns the current CEF Browser Instance
+13
View File
@@ -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
}
}
+12
View File
@@ -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
};
}
+51
View File
@@ -10,6 +10,32 @@ namespace CefSharp
{
public static class WebBrowserExtensions
{
/// <summary>
/// Returns the main (top-level) frame for the browser window.
/// </summary>
/// <returns>Frame</returns>
public static IFrame GetMainFrame(this IWebBrowser webBrowser)
{
var browser = webBrowser.GetBrowser();
ThrowExceptionIfBrowserNull(browser);
return browser.MainFrame;
}
/// <summary>
/// Returns the focused frame for the browser window.
/// </summary>
/// <returns>Frame</returns>
public static IFrame GetFocusedFrame(this IWebBrowser webBrowser)
{
var browser = webBrowser.GetBrowser();
ThrowExceptionIfBrowserNull(browser);
return browser.FocusedFrame;
}
/// <summary>
/// Execute Undo on the focused frame
/// </summary>
@@ -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<JavascriptResponse> 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)