// Copyright © 2014 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.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Threading.Tasks;
using CefSharp.Enums;
using CefSharp.Internals;
using CefSharp.Structs;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
namespace CefSharp.OffScreen
{
///
/// An offscreen instance of Chromium that you can use to take
/// snapshots or evaluate JavaScript.
///
///
public class ChromiumWebBrowser : IRenderWebBrowser
{
///
/// The managed cef browser adapter
///
private ManagedCefBrowserAdapter managedCefBrowserAdapter;
///
/// Size of the Chromium viewport.
/// This must be set to something other than 0x0 otherwise Chromium will not render,
/// and the ScreenshotAsync task will deadlock.
///
private Size size = new Size(1366, 768);
///
/// The browser
///
private IBrowser browser;
///
/// Flag to guard the creation of the underlying offscreen browser - only one instance can be created
///
private bool browserCreated;
///
/// The value for disposal, if it's 1 (one) then this instance is either disposed
/// or in the process of getting disposed
///
private int disposeSignaled;
///
/// Gets a value indicating whether this instance is disposed.
///
/// if this instance is disposed; otherwise, .
public bool IsDisposed
{
get
{
return Interlocked.CompareExchange(ref disposeSignaled, 1, 1) == 1;
}
}
///
/// A flag that indicates whether the WebBrowser is initialized (true) or not (false).
///
/// true if this instance is browser initialized; otherwise, false.
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
public bool IsBrowserInitialized { get; private set; }
///
/// A flag that indicates whether the control is currently loading one or more web pages (true) or not (false).
///
/// true if this instance is loading; otherwise, false.
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
public bool IsLoading { get; private set; }
///
/// The text that will be displayed as a ToolTip
///
/// The tooltip text.
public string TooltipText { get; private set; }
///
/// The address (URL) which the browser control is currently displaying.
/// Will automatically be updated as the user navigates to another page (e.g. by clicking on a link).
///
/// The address.
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
public string Address { get; private set; }
///
/// A flag that indicates whether the state of the control current supports the GoBack action (true) or not (false).
///
/// true if this instance can go back; otherwise, false.
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
public bool CanGoBack { get; private set; }
///
/// A flag that indicates whether the state of the control currently supports the GoForward action (true) or not (false).
///
/// true if this instance can go forward; otherwise, false.
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
public bool CanGoForward { get; private set; }
///
/// Gets the request context.
///
/// The request context.
public IRequestContext RequestContext { get; private set; }
///
/// Implement and assign to handle events related to JavaScript Dialogs.
///
/// The js dialog handler.
public IJsDialogHandler JsDialogHandler { get; set; }
///
/// Implement and assign to handle dialog events.
///
/// The dialog handler.
public IDialogHandler DialogHandler { get; set; }
///
/// Implement and assign to handle events related to downloading files.
///
/// The download handler.
public IDownloadHandler DownloadHandler { get; set; }
///
/// Implement and assign to handle events related to key press.
///
/// The keyboard handler.
public IKeyboardHandler KeyboardHandler { get; set; }
///
/// Implement and assign to handle events related to browser load status.
///
/// The load handler.
public ILoadHandler LoadHandler { get; set; }
///
/// Implement and assign to handle events related to popups.
///
/// The life span handler.
public ILifeSpanHandler LifeSpanHandler { get; set; }
///
/// Implement and assign to handle events related to browser display state.
///
/// The display handler.
public IDisplayHandler DisplayHandler { get; set; }
///
/// Implement and assign to handle events related to the browser context menu
///
/// The menu handler.
public IContextMenuHandler MenuHandler { get; set; }
///
/// Implement and assign to handle events related to the browser component's focus
///
/// The focus handler.
public IFocusHandler FocusHandler { get; set; }
///
/// Implement and assign to handle events related to browser requests.
///
/// The request handler.
public IRequestHandler RequestHandler { get; set; }
///
/// Implement and assign to handle events related to browser rendering.
///
/// The render handler.
public IRenderHandler RenderHandler { get; set; }
///
/// Implement and assign to handle events related to dragging.
///
/// The drag handler.
public IDragHandler DragHandler { get; set; }
///
/// Implement and control the loading of resources
///
/// The resource handler factory.
public IResourceRequestHandlerFactory ResourceRequestHandlerFactory { get; set; }
///
/// Implement and assign to handle messages from the render process.
///
/// The render process message handler.
public IRenderProcessMessageHandler RenderProcessMessageHandler { get; set; }
///
/// Implement to handle events related to find results.
///
/// The find handler.
public IFindHandler FindHandler { get; set; }
///
/// Implement to handle audio events.
///
public IAudioHandler AudioHandler { get; set; }
///
/// Implement to handle events related to accessibility.
///
/// The accessibility handler.
public IAccessibilityHandler AccessibilityHandler { get; set; }
///
/// Event handler that will get called when the resource load for a navigation fails or is canceled.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
///
public event EventHandler LoadError;
///
/// Event handler that will get called when the browser begins loading a frame. Multiple frames may be loading at the same
/// time. Sub-frames may start or continue loading after the main frame load has ended. This method may not be called for a
/// particular frame if the load request for that frame fails. For notification of overall browser load status use
/// OnLoadingStateChange instead.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
///
/// Whilst this may seem like a logical place to execute js, it's called before the DOM has been loaded, implement
/// as it's called when the underlying V8Context is created
///
public event EventHandler FrameLoadStart;
///
/// Event handler that will get called when the browser is done loading a frame. Multiple frames may be loading at the same
/// time. Sub-frames may start or continue loading after the main frame load has ended. This method will always be called
/// for all frames irrespective of whether the request completes successfully.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
///
public event EventHandler FrameLoadEnd;
///
/// Event handler for receiving Javascript console messages being sent from web pages.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
///
public event EventHandler ConsoleMessage;
///
/// Event called after the underlying CEF browser instance has been created.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
///
public event EventHandler BrowserInitialized;
///
/// Event handler for changes to the status message.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang.
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
///
public event EventHandler StatusMessage;
///
/// Event handler that will get called when the Loading state has changed.
/// This event will be fired twice. Once when loading is initiated either programmatically or
/// by user action, and once when loading is terminated due to completion, cancellation of failure.
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
///
public event EventHandler LoadingStateChanged;
///
/// Occurs when [address changed].
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
///
public event EventHandler AddressChanged;
///
/// Occurs when [title changed].
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
///
public event EventHandler TitleChanged;
///
/// Fired on the CEF UI thread, which by default is not the same as your application main thread.
/// Called when an element should be painted. Pixel values passed to this method are scaled relative to view coordinates
/// based on the value of ScreenInfo.DeviceScaleFactor returned from GetScreenInfo.
///
public event EventHandler Paint;
///
/// Event handler that will get called when the message that originates from CefSharp.PostMessage
///
public event EventHandler JavascriptMessageReceived;
///
/// A flag that indicates if you can execute javascript in the main frame.
/// Flag is set to true in IRenderProcessMessageHandler.OnContextCreated.
/// and false in IRenderProcessMessageHandler.OnContextReleased
///
public bool CanExecuteJavascriptInMainFrame { get; private set; }
///
/// Create a new OffScreen Chromium Browser. If you use = true then you must
/// set to false and call after the objects are registered.
///
/// Initial address (url) to load
/// The browser settings to use. If null, the default settings are used.
/// See for more details. Defaults to null
/// automatically create the underlying Browser
/// Cef::Initialize() failed
public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null,
IRequestContext requestContext = null, bool automaticallyCreateBrowser = true)
{
if (!Cef.IsInitialized)
{
var settings = new CefSettings();
if (!Cef.Initialize(settings))
{
throw new InvalidOperationException("Cef::Initialize() failed");
}
}
RequestContext = requestContext;
Cef.AddDisposable(this);
Address = address;
managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
if (automaticallyCreateBrowser)
{
CreateBrowser(null, browserSettings);
}
RenderHandler = new DefaultRenderHandler(this);
}
///
/// Finalizes an instance of the class.
///
~ChromiumWebBrowser()
{
Dispose(false);
}
///
/// Releases all resources used by the object
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources for the
///
/// to release both managed and unmanaged resources; to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
// Attempt to move the disposeSignaled state from 0 to 1. If successful, we can be assured that
// this thread is the first thread to do so, and can safely dispose of the object.
if (Interlocked.CompareExchange(ref disposeSignaled, 1, 0) != 0)
{
return;
}
if (disposing)
{
IsBrowserInitialized = false;
// Don't reference event listeners any longer:
AddressChanged = null;
BrowserInitialized = null;
ConsoleMessage = null;
FrameLoadEnd = null;
FrameLoadStart = null;
LoadError = null;
LoadingStateChanged = null;
Paint = null;
StatusMessage = null;
TitleChanged = null;
JavascriptMessageReceived = null;
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
this.SetHandlersToNullExceptLifeSpan();
browser = null;
if (managedCefBrowserAdapter != null)
{
managedCefBrowserAdapter.Dispose();
managedCefBrowserAdapter = null;
}
// LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
// is called.
LifeSpanHandler = null;
}
Cef.RemoveDisposable(this);
}
///
/// Create the underlying browser. The instance address, browser settings and request context will be used.
///
/// Window information used when creating the browser
/// Browser initialization settings
/// An instance of the underlying offscreen browser has already been created, this method can only be called once.
public void CreateBrowser(IWindowInfo windowInfo = null, BrowserSettings browserSettings = null)
{
if (browserCreated)
{
throw new Exception("An instance of the underlying offscreen browser has already been created, this method can only be called once.");
}
browserCreated = true;
if (browserSettings == null)
{
browserSettings = new BrowserSettings(frameworkCreated: true);
}
if (windowInfo == null)
{
windowInfo = new WindowInfo();
windowInfo.SetAsWindowless(IntPtr.Zero);
}
managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings, (RequestContext)RequestContext, Address);
browserSettings = null;
}
///
/// Get/set the size of the Chromium viewport, in pixels.
/// This also changes the size of the next rendered bitmap.
///
/// The size.
public Size Size
{
get { return size; }
set
{
if (size != value)
{
size = value;
if (IsBrowserInitialized)
{
browser.GetHost().WasResized();
}
}
}
}
///
/// Immediately returns a copy of the last rendering from Chrome,
/// or null if no rendering has occurred yet.
/// Chrome also renders the page loading, so if you want to see a complete rendering,
/// only start this task once your page is loaded (which you can detect via FrameLoadEnd
/// or your own heuristics based on evaluating JavaScript).
/// It is your responsibility to dispose the returned Bitmap.
/// The bitmap size is determined by the Size property set earlier.
///
/// Choose which bitmap to retrieve, choose for a merged bitmap.
/// Bitmap.
public Bitmap ScreenshotOrNull(PopupBlending blend = PopupBlending.Main)
{
if (RenderHandler == null)
{
throw new NullReferenceException("RenderHandler cannot be null. Use DefaultRenderHandler unless implementing your own");
}
var renderHandler = RenderHandler as DefaultRenderHandler;
if (renderHandler == null)
{
throw new Exception("ScreenshotOrNull and ScreenshotAsync can only be used in combination with the DefaultRenderHandler");
}
lock (renderHandler.BitmapLock)
{
if (blend == PopupBlending.Main)
{
return renderHandler.BitmapBuffer.CreateBitmap();
}
if (blend == PopupBlending.Popup)
{
return renderHandler.PopupOpen ? renderHandler.PopupBuffer.CreateBitmap() : null;
}
var bitmap = renderHandler.BitmapBuffer.CreateBitmap();
if (renderHandler.PopupOpen && bitmap != null)
{
var popup = renderHandler.PopupBuffer.CreateBitmap();
if (popup == null)
{
return bitmap;
}
return MergeBitmaps(bitmap, popup, renderHandler.PopupPosition);
}
return bitmap;
}
}
///
/// Starts a task that waits for the next rendering from Chrome.
/// Chrome also renders the page loading, so if you want to see a complete rendering,
/// only start this task once your page is loaded (which you can detect via FrameLoadEnd
/// or your own heuristics based on evaluating JavaScript).
/// It is your responsibility to dispose the returned Bitmap.
/// The bitmap size is determined by the Size property set earlier.
///
/// Ignore existing bitmap (if any) and return the next avaliable bitmap
/// Choose which bitmap to retrieve, choose for a merged bitmap.
/// Task<Bitmap>.
public Task ScreenshotAsync(bool ignoreExistingScreenshot = false, PopupBlending blend = PopupBlending.Main)
{
// Try our luck and see if there is already a screenshot, to save us creating a new thread for nothing.
var screenshot = ScreenshotOrNull(blend);
var completionSource = new TaskCompletionSource();
if (screenshot == null || ignoreExistingScreenshot)
{
EventHandler paint = null; // otherwise we cannot reference ourselves in the anonymous method below
paint = (sender, e) =>
{
// Chromium has rendered. Tell the task about it.
Paint -= paint;
completionSource.TrySetResultAsync(ScreenshotOrNull(blend));
};
Paint += paint;
}
else
{
completionSource.TrySetResultAsync(screenshot);
}
return completionSource.Task;
}
///
/// Loads the specified URL.
///
/// The URL to be loaded.
public void Load(string url)
{
Address = url;
//Destroy the frame wrapper when we're done
using (var frame = this.GetMainFrame())
{
frame.LoadUrl(url);
}
}
///
/// The javascript object repository, one repository per ChromiumWebBrowser instance.
///
public IJavascriptObjectRepository JavascriptObjectRepository
{
get { return managedCefBrowserAdapter?.JavascriptObjectRepository; }
}
///
/// Has Focus - Always False
///
/// returns false
bool IWebBrowser.Focus()
{
// no control to focus for offscreen browser
return false;
}
///
/// Returns the current CEF Browser Instance
///
/// browser instance or null
public IBrowser GetBrowser()
{
this.ThrowExceptionIfBrowserNotInitialized();
return browser;
}
///
/// Gets the screen information (scale factor).
///
/// ScreenInfo.
ScreenInfo? IRenderWebBrowser.GetScreenInfo()
{
return GetScreenInfo();
}
///
/// Gets the screen information (scale factor).
///
/// ScreenInfo.
protected virtual ScreenInfo? GetScreenInfo()
{
return RenderHandler?.GetScreenInfo();
}
///
/// Gets the view rect (width, height)
///
/// ViewRect.
Rect IRenderWebBrowser.GetViewRect()
{
return GetViewRect();
}
///
/// Gets the view rect (width, height)
///
/// ViewRect.
protected virtual Rect GetViewRect()
{
if (RenderHandler == null)
{
return new Rect(0, 0, 640, 480);
}
return RenderHandler.GetViewRect();
}
///
/// Called to retrieve the translation from view coordinates to actual screen coordinates.
///
/// x
/// y
/// screen x
/// screen y
/// Return true if the screen coordinates were provided.
bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
{
return GetScreenPoint(viewX, viewY, out screenX, out screenY);
}
///
/// Called to retrieve the translation from view coordinates to actual screen coordinates.
///
/// x
/// y
/// screen x
/// screen y
/// Return true if the screen coordinates were provided.
protected virtual bool GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
{
screenX = 0;
screenY = 0;
return RenderHandler?.GetScreenPoint(viewX, viewY, out screenX, out screenY) ?? false;
}
///
/// Called when an element has been rendered to the shared texture handle.
/// This method is only called when is set to true
///
/// indicates whether the element is the view or the popup widget.
/// contains the set of rectangles in pixel coordinates that need to be repainted
/// is the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method.
void IRenderWebBrowser.OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle)
{
RenderHandler?.OnAcceleratedPaint(type, dirtyRect, sharedHandle);
}
///
/// Called when an element should be painted. (Invoked from CefRenderHandler.OnPaint)
///
/// indicates whether the element is the view or the popup widget.
/// contains the set of rectangles in pixel coordinates that need to be repainted
/// The bitmap will be will be width * height *4 bytes in size and represents a BGRA image with an upper-left origin
/// width
/// height
void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
{
var handled = false;
var handler = Paint;
if (handler != null)
{
var args = new OnPaintEventArgs(type == PaintElementType.Popup, dirtyRect, buffer, width, height);
handler(this, args);
handled = args.Handled;
}
if (!handled)
{
RenderHandler?.OnPaint(type, dirtyRect, buffer, width, height);
}
}
///
/// Called when the browser's cursor has changed. .
///
/// If type is Custom then customCursorInfo will be populated with the custom cursor information
/// cursor type
/// custom cursor Information
void IRenderWebBrowser.OnCursorChange(IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
{
RenderHandler?.OnCursorChange(cursor, type, customCursorInfo);
}
///
/// Starts dragging.
///
/// The drag data.
/// The mask.
/// The x.
/// The y.
/// true if XXXX, false otherwise.
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
{
return RenderHandler?.StartDragging(dragData, mask, x, y) ?? false;
}
void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation)
{
RenderHandler?.UpdateDragCursor(operation);
}
///
/// Sets the popup is open.
///
/// if set to true [show].
void IRenderWebBrowser.OnPopupShow(bool show)
{
RenderHandler?.OnPopupShow(show);
}
///
/// Called when the browser wants to move or resize the popup widget.
///
/// contains the new location and size in view coordinates.
void IRenderWebBrowser.OnPopupSize(Rect rect)
{
RenderHandler?.OnPopupSize(rect);
}
void IRenderWebBrowser.OnImeCompositionRangeChanged(Range selectedRange, Rect[] characterBounds)
{
RenderHandler?.OnImeCompositionRangeChanged(selectedRange, characterBounds);
}
void IRenderWebBrowser.OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode)
{
RenderHandler?.OnVirtualKeyboardRequested(browser, inputMode);
}
///
/// Handles the event.
///
/// The instance containing the event data.
void IWebBrowserInternal.OnConsoleMessage(ConsoleMessageEventArgs args)
{
ConsoleMessage?.Invoke(this, args);
}
///
/// Handles the event.
///
/// The instance containing the event data.
void IWebBrowserInternal.OnFrameLoadStart(FrameLoadStartEventArgs args)
{
FrameLoadStart?.Invoke(this, args);
}
///
/// Handles the event.
///
/// The instance containing the event data.
void IWebBrowserInternal.OnFrameLoadEnd(FrameLoadEndEventArgs args)
{
FrameLoadEnd?.Invoke(this, args);
}
///
/// Called when [after browser created].
///
/// The browser.
void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
{
this.browser = browser;
IsBrowserInitialized = true;
BrowserInitialized?.Invoke(this, EventArgs.Empty);
}
///
/// Handles the event.
///
/// The instance containing the event data.
void IWebBrowserInternal.OnLoadError(LoadErrorEventArgs args)
{
LoadError?.Invoke(this, args);
}
///
/// Gets the browser adapter.
///
/// The browser adapter.
IBrowserAdapter IWebBrowserInternal.BrowserAdapter
{
get { return managedCefBrowserAdapter; }
}
///
/// Gets or sets a value indicating whether this instance has parent.
///
/// true if this instance has parent; otherwise, false.
bool IWebBrowserInternal.HasParent { get; set; }
///
/// Handles the event.
///
/// The instance containing the event data.
void IWebBrowserInternal.OnStatusMessage(StatusMessageEventArgs args)
{
StatusMessage?.Invoke(this, args);
}
///
/// Sets the address.
///
/// The instance containing the event data.
void IWebBrowserInternal.SetAddress(AddressChangedEventArgs args)
{
Address = args.Address;
AddressChanged?.Invoke(this, args);
}
///
/// Sets the loading state change.
///
/// The instance containing the event data.
void IWebBrowserInternal.SetLoadingStateChange(LoadingStateChangedEventArgs args)
{
CanGoBack = args.CanGoBack;
CanGoForward = args.CanGoForward;
IsLoading = args.IsLoading;
LoadingStateChanged?.Invoke(this, args);
}
///
/// Sets the title.
///
/// The instance containing the event data.
void IWebBrowserInternal.SetTitle(TitleChangedEventArgs args)
{
TitleChanged?.Invoke(this, args);
}
///
/// Sets the tooltip text.
///
/// The tooltip text.
void IWebBrowserInternal.SetTooltipText(string tooltipText)
{
TooltipText = tooltipText;
}
void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(bool canExecute)
{
CanExecuteJavascriptInMainFrame = canExecute;
}
void IWebBrowserInternal.SetJavascriptMessageReceived(JavascriptMessageReceivedEventArgs args)
{
JavascriptMessageReceived?.Invoke(this, args);
}
///
/// Creates a new bitmap with the dimensions of firstBitmap, then
/// draws the firstBitmap, then overlays the secondBitmap
///
/// First bitmap, this will be the first image drawn
/// Second bitmap, this image will be drawn on the first
/// Position of the second bitmap
/// The merged bitmap, size of firstBitmap
private Bitmap MergeBitmaps(Bitmap firstBitmap, Bitmap secondBitmap, Point secondBitmapPosition)
{
var mergedBitmap = new Bitmap(firstBitmap.Width, firstBitmap.Height, PixelFormat.Format32bppPArgb);
using (var g = Graphics.FromImage(mergedBitmap))
{
g.DrawImage(firstBitmap, new Rectangle(0, 0, firstBitmap.Width, firstBitmap.Height));
g.DrawImage(secondBitmap, new Rectangle(secondBitmapPosition.X, secondBitmapPosition.Y, secondBitmap.Width, secondBitmap.Height));
}
return mergedBitmap;
}
}
}