// 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.
using System;
using System.Text;
using System.Threading.Tasks;
namespace CefSharp
{
public interface IWebBrowser : IDisposable
{
///
/// Event handler for receiving Javascript console messages being sent from web pages.
///
event EventHandler ConsoleMessage;
///
/// Event handler for changes to the status message.
///
event EventHandler StatusMessage;
///
/// 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.
///
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.
///
event EventHandler FrameLoadEnd;
///
/// Event handler that will get called when the resource load for a navigation fails or is canceled.
///
event EventHandler LoadError;
///
/// 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.
///
event EventHandler LoadingStateChanged;
///
/// Loads the specified URL.
///
/// The URL to be loaded.
void Load(string url);
///
/// Registers a Javascript object in this specific browser instance.
///
/// The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).
/// The object to be made accessible to Javascript.
/// camel case the javascript names of properties/methods, defaults to true
void RegisterJsObject(string name, object objectToBind, bool camelCaseJavascriptNames = true);
///
/// Execute some Javascript code in the context of this WebBrowser, and return the result of the evaluation
/// in an Async fashion
///
/// The Javascript code that should be executed.
/// The timeout after which the Javascript code execution should be aborted.
/// A Task that can be awaited to perform the script execution
Task EvaluateScriptAsync(string script, TimeSpan? timeout = null);
///
/// Implement and assign to handle dialog events.
///
IDialogHandler DialogHandler { get; set; }
///
/// Implement and assign to handle events related to browser requests.
///
IRequestHandler RequestHandler { get; set; }
///
/// Implement and assign to handle events related to popup window events.
///
IPopupHandler PopupHandler { get; set; }
///
/// Implement and assign to handle events related to popups.
///
ILifeSpanHandler LifeSpanHandler { get; set; }
///
/// Implement and assign to handle events related to key press.
///
IKeyboardHandler KeyboardHandler { get; set; }
///
/// Implement and assign to handle events related to JavaScript Dialogs.
///
IJsDialogHandler JsDialogHandler { get; set; }
///
/// Implement and assign to handle events related to dragging.
///
IDragHandler DragHandler { get; set; }
///
/// Implement and assign to handle events related to downloading files.
///
IDownloadHandler DownloadHandler { get; set; }
///
/// Implement and assign to handle events related to the browser context menu
///
IMenuHandler MenuHandler { get; set; }
///
/// Implement and assign to handle events related to the browser component's focus
///
IFocusHandler FocusHandler { get; set; }
///
/// Implement and control the loading of resources
///
IResourceHandlerFactory ResourceHandlerFactory { get; set; }
///
/// Implement and assign to handle requests for permission to use geolocation.
///
IGeolocationHandler GeolocationHandler { get; set; }
///
/// A flag that indicates whether the WebBrowser is initialized (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool IsBrowserInitialized { get; }
///
/// A flag that indicates whether the control is currently loading one or more web pages (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool IsLoading { get; }
///
/// A flag that indicates whether the state of the control current supports the GoBack action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanGoBack { get; }
///
/// A flag that indicates whether the state of the control currently supports the GoForward action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanGoForward { get; }
///
/// A flag that indicates whether the state of the control currently supports the Reload action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanReload { get; }
///
/// 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).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
string Address { get; }
///
/// The title of the web page being currently displayed.
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
string Title { get; }
///
/// The text that will be displayed as a ToolTip
///
string TooltipText { get; }
///
/// Asynchronously gets the current Zoom Level.
///
Task GetZoomLevelAsync();
///
/// Change the ZoomLevel to the specified value. Can be set to 0.0 to clear the zoom level.
///
///
/// If called on the CEF UI thread the change will be applied immediately.
/// Otherwise, the change will be applied asynchronously on the CEF UI thread.
/// The CEF UI thread is different to the WPF/WinForms UI Thread
///
/// zoom level
void SetZoomLevel(double level);
///
/// Search for text within the current page.
///
/// Can be used in can conjunction with searchText to have multiple
/// searches running simultaneously.
/// search text
/// indicates whether to search forward or backward within the page.
/// indicates whether the search should be case-sensitive.
/// indicates whether this is the first request or a follow-up.
void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);
///
/// Cancel all searches that are currently going on.
///
/// clear the current search selection
void StopFinding(bool clearSelection);
///
/// Attempts to give focus to the IWpfWebBrowser control.
///
/// 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();
///
/// Opens a Print Dialog which if used (can be user cancelled) will print the browser contents.
///
void Print();
///
/// Open developer tools in its own window.
///
void ShowDevTools();
///
/// Explicitly close the developer tools window if one exists for this browser instance.
///
void CloseDevTools();
///
/// If a misspelled word is currently selected in an editable node calling
/// this method will replace it with the specified word.
///
/// The new word that will replace the currently selected word.
void ReplaceMisspelling(string word);
///
/// Add the specified word to the spelling dictionary.
///
/// The new word that will be added to the dictionary.
void AddWordToDictionary(string word);
///
/// 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
///
/// browser instance or null
IBrowser GetBrowser();
}
}