<commit_before>// Copyright © 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.Collections.Generic;
using System.Threading.Tasks;
using CefSharp.Callback;
using CefSharp.Enums;
using CefSharp.Structs;
using Size = CefSharp.Structs.Size;

namespace CefSharp
{
    /// <summary>
    /// Interface used to represent the browser process aspects of a browser window.
    /// They may be called on any thread in that process unless otherwise indicated in the comments. 
    /// </summary>
    public interface IBrowserHost : IDisposable
    {
        /// <summary>
        /// Add the specified word to the spelling dictionary.
        /// </summary>
        /// <param name="word">custom word to be added to dictionary</param>
        void AddWordToDictionary(string word);

        /// <summary>
        /// Request that the browser close. The JavaScript 'onbeforeunload' event will be fired.
        /// </summary>
        /// <param name="forceClose">
        /// If forceClose is false the event handler, if any, will be allowed to prompt the user and the
        /// user can optionally cancel the close. If forceClose is true the prompt will not be displayed
        /// and the close will proceed. Results in a call to <see cref="ILifeSpanHandler.DoClose"/> if
        /// the event handler allows the close or if forceClose is true
        /// See <see cref="ILifeSpanHandler.DoClose"/> documentation for additional usage information.
        /// </param>
        void CloseBrowser(bool forceClose);

        /// <summary>
        /// Helper for closing a browser. Call this method from the top-level window close handler. Internally this calls CloseBrowser(false) if the close has not yet been initiated. This method returns false while the close is pending and true after the close has completed.
        /// See <see cref="CloseBrowser(bool)"/> and <see cref="ILifeSpanHandler.DoClose(IWebBrowser, IBrowser)"/> documentation for additional usage information. This method must be called on the CEF UI thread.
        /// </summary>
        /// <returns>
        /// This method returns false while the close is pending and true after the close has completed
        /// </returns>
        bool TryCloseBrowser();

        /// <summary>
        /// Explicitly close the developer tools window if one exists for this browser instance.
        /// </summary>
        void CloseDevTools();

        /// <summary>
        /// Returns true if this browser currently has an associated DevTools browser.
        /// Must be called on the CEF UI thread.
        /// </summary>
        bool HasDevTools { get; }

        /// <summary>
        /// Call this method when the user drags the mouse into the web view (before calling <see cref="DragTargetDragOver"/>/<see cref="DragTargetDragLeave"/>/<see cref="DragTargetDragDrop"/>).
        /// </summary>
        void DragTargetDragEnter(IDragData dragData, MouseEvent mouseEvent, DragOperationsMask allowedOperations);

        /// <summary>
        /// Call this method each time the mouse is moved across the web view during a drag operation (after calling <see cref="DragTargetDragEnter"/> and before calling <see cref="DragTargetDragLeave"/>/<see cref="DragTargetDragDrop"/>). 
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragOver(MouseEvent mouseEvent, DragOperationsMask allowedOperations);

        /// <summary>
        /// Call this method when the user completes the drag operation by dropping the object onto the web view (after calling <see cref="DragTargetDragEnter"/>). 
        /// The object being dropped is <see cref="IDragData"/>, given as an argument to the previous <see cref="DragTargetDragEnter"/> call. 
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragDrop(MouseEvent mouseEvent);

        /// <summary>
        /// Call this method when the drag operation started by a <see cref="CefSharp.Internals.IRenderWebBrowser.StartDragging(IDragData, DragOperationsMask, int, int)"/> call has ended either in a drop or by being cancelled.
        /// If the web view is both the drag source and the drag target then all DragTarget* methods should be called before DragSource* methods.
        /// This method is only used when window rendering is disabled. 
        /// </summary>
        /// <param name="x">x mouse coordinate relative to the upper-left corner of the view.</param>
        /// <param name="y">y mouse coordinate relative to the upper-left corner of the view.</param>
        /// <param name="op">Drag Operations mask</param>
        void DragSourceEndedAt(int x, int y, DragOperationsMask op);

        /// <summary>
        /// Call this method when the user drags the mouse out of the web view (after calling <see cref="DragTargetDragEnter"/>).
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragLeave();

        /// <summary>
        /// Call this method when the drag operation started by a <see cref="CefSharp.Internals.IRenderWebBrowser.StartDragging(IDragData, DragOperationsMask, int, int)"/> call has completed.
        /// This method may be called immediately without first calling DragSourceEndedAt to cancel a drag operation.
        /// If the web view is both the drag source and the drag target then all DragTarget* methods should be called before DragSource* mthods.
        /// This method is only used when window rendering is disabled. 
        /// </summary>
        void DragSourceSystemDragEnded();

        /// <summary>
        /// Search for text
        /// </summary>
        /// <param name="identifier">can be used to have multiple searches running simultaniously</param>
        /// <param name="searchText">text to search for</param>
        /// <param name="forward">indicates whether to search forward or backward within the page</param>
        /// <param name="matchCase">indicates whether the search should be case-sensitive</param>
        /// <param name="findNext">indicates whether this is the first request or a follow-up</param>
        /// <remarks>The IFindHandler instance, if any, will be called to report find results. </remarks>
        void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);

        /// <summary>
        /// Returns the extension hosted in this browser or null if no extension is hosted. See <see cref="IRequestContext.LoadExtension"/> for details.
        /// </summary>
        IExtension Extension { get; }

        /// <summary>
        /// Retrieve the window handle of the browser that opened this browser.
        /// </summary>
        /// <returns>The handler</returns>
        IntPtr GetOpenerWindowHandle();

        /// <summary>
        /// Retrieve the window handle for this browser. 
        /// </summary>
        /// <returns>The handler</returns>
        IntPtr GetWindowHandle();

        /// <summary>
        /// Gets the current zoom level. The default zoom level is 0.0. This method can only be called on the CEF UI thread. 
        /// </summary>
        /// <returns>zoom level (default is 0.0)</returns>
        double GetZoomLevel();

        /// <summary>
        /// Get the current zoom level. The default zoom level is 0.0. This method executes GetZoomLevel on the CEF UI thread
        /// in an async fashion.
        /// </summary>
        /// <returns> a <see cref="Task{Double}"/> that when executed returns the zoom level as a double.</returns>
        Task<double> GetZoomLevelAsync();

        /// <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>
        /// Returns true if this browser is hosting an extension background script. Background hosts do not have a window and are not displayable.
        /// See <see cref="IRequestContext.LoadExtension"/> for details.
        /// </summary>
        /// <returns>Returns true if this browser is hosting an extension background script.</returns>
        bool IsBackgroundHost { get; }

        /// <summary>
        /// Begins a new composition or updates the existing composition. Blink has a
        /// special node (a composition node) that allows the input method to change
        /// text without affecting other DOM nodes. 
        ///
        /// This method may be called multiple times as the composition changes. When
        /// the client is done making changes the composition should either be canceled
        /// or completed. To cancel the composition call ImeCancelComposition. To
        /// complete the composition call either ImeCommitText or
        /// ImeFinishComposingText. Completion is usually signaled when:
        /// The client receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR
        /// flag (on Windows).
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="text">is the optional text that
        /// will be inserted into the composition node</param>
        /// <param name="underlines">is an optional set
        /// of ranges that will be underlined in the resulting text.</param>
        /// <param name="replacementRange">is an optional range of the existing text that will be replaced. (MAC OSX ONLY)</param>
        /// <param name="selectionRange"> is an optional range of the resulting text that
        /// will be selected after insertion or replacement. </param>
        void ImeSetComposition(string text, CompositionUnderline[] underlines, Range? replacementRange, Range? selectionRange);

        /// <summary>
        /// Completes the existing composition by optionally inserting the specified
        /// text into the composition node.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="text">text that will be committed</param>
        /// <param name="replacementRange">is an optional range of the existing text that will be replaced. (MAC OSX ONLY)</param>
        /// <param name="relativeCursorPos">is where the cursor will be positioned relative to the current cursor position. (MAC OSX ONLY)</param>
        void ImeCommitText(string text, Range? replacementRange, int relativeCursorPos);

        /// <summary>
        /// Completes the existing composition by applying the current composition node
        /// contents. See comments on ImeSetComposition for usage.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="keepSelection">If keepSelection is false the current selection, if any, will be discarded.</param>
        void ImeFinishComposingText(bool keepSelection);

        /// <summary>
        /// Cancels the existing composition and discards the composition node
        /// contents without applying them. See comments on ImeSetComposition for
        /// usage.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        void ImeCancelComposition();

        /// <summary>
        /// Get/Set Mouse cursor change disabled
        /// </summary>
        bool MouseCursorChangeDisabled { get; set; }

        /// <summary>
        /// Notify the browser that the window hosting it is about to be moved or resized.
        /// </summary>
        void NotifyMoveOrResizeStarted();

        /// <summary>
        /// Send a notification to the browser that the screen info has changed.
        /// The browser will then call CefRenderHandler::GetScreenInfo to update the screen information with the new values.
        /// This simulates moving the webview window from one display to another, or changing the properties of the current display.
        /// This method is only used when window rendering is disabled. <commit_msg>Core - Improve IBrowserHost.NotifyMoveOrResizeStarted xml doc<commit_after>// Copyright © 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.Collections.Generic;
using System.Threading.Tasks;
using CefSharp.Callback;
using CefSharp.Enums;
using CefSharp.Structs;
using Size = CefSharp.Structs.Size;

namespace CefSharp
{
    /// <summary>
    /// Interface used to represent the browser process aspects of a browser window.
    /// They may be called on any thread in that process unless otherwise indicated in the comments. 
    /// </summary>
    public interface IBrowserHost : IDisposable
    {
        /// <summary>
        /// Add the specified word to the spelling dictionary.
        /// </summary>
        /// <param name="word">custom word to be added to dictionary</param>
        void AddWordToDictionary(string word);

        /// <summary>
        /// Request that the browser close. The JavaScript 'onbeforeunload' event will be fired.
        /// </summary>
        /// <param name="forceClose">
        /// If forceClose is false the event handler, if any, will be allowed to prompt the user and the
        /// user can optionally cancel the close. If forceClose is true the prompt will not be displayed
        /// and the close will proceed. Results in a call to <see cref="ILifeSpanHandler.DoClose"/> if
        /// the event handler allows the close or if forceClose is true
        /// See <see cref="ILifeSpanHandler.DoClose"/> documentation for additional usage information.
        /// </param>
        void CloseBrowser(bool forceClose);

        /// <summary>
        /// Helper for closing a browser. Call this method from the top-level window close handler. Internally this calls CloseBrowser(false) if the close has not yet been initiated. This method returns false while the close is pending and true after the close has completed.
        /// See <see cref="CloseBrowser(bool)"/> and <see cref="ILifeSpanHandler.DoClose(IWebBrowser, IBrowser)"/> documentation for additional usage information. This method must be called on the CEF UI thread.
        /// </summary>
        /// <returns>
        /// This method returns false while the close is pending and true after the close has completed
        /// </returns>
        bool TryCloseBrowser();

        /// <summary>
        /// Explicitly close the developer tools window if one exists for this browser instance.
        /// </summary>
        void CloseDevTools();

        /// <summary>
        /// Returns true if this browser currently has an associated DevTools browser.
        /// Must be called on the CEF UI thread.
        /// </summary>
        bool HasDevTools { get; }

        /// <summary>
        /// Call this method when the user drags the mouse into the web view (before calling <see cref="DragTargetDragOver"/>/<see cref="DragTargetDragLeave"/>/<see cref="DragTargetDragDrop"/>).
        /// </summary>
        void DragTargetDragEnter(IDragData dragData, MouseEvent mouseEvent, DragOperationsMask allowedOperations);

        /// <summary>
        /// Call this method each time the mouse is moved across the web view during a drag operation (after calling <see cref="DragTargetDragEnter"/> and before calling <see cref="DragTargetDragLeave"/>/<see cref="DragTargetDragDrop"/>). 
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragOver(MouseEvent mouseEvent, DragOperationsMask allowedOperations);

        /// <summary>
        /// Call this method when the user completes the drag operation by dropping the object onto the web view (after calling <see cref="DragTargetDragEnter"/>). 
        /// The object being dropped is <see cref="IDragData"/>, given as an argument to the previous <see cref="DragTargetDragEnter"/> call. 
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragDrop(MouseEvent mouseEvent);

        /// <summary>
        /// Call this method when the drag operation started by a <see cref="CefSharp.Internals.IRenderWebBrowser.StartDragging(IDragData, DragOperationsMask, int, int)"/> call has ended either in a drop or by being cancelled.
        /// If the web view is both the drag source and the drag target then all DragTarget* methods should be called before DragSource* methods.
        /// This method is only used when window rendering is disabled. 
        /// </summary>
        /// <param name="x">x mouse coordinate relative to the upper-left corner of the view.</param>
        /// <param name="y">y mouse coordinate relative to the upper-left corner of the view.</param>
        /// <param name="op">Drag Operations mask</param>
        void DragSourceEndedAt(int x, int y, DragOperationsMask op);

        /// <summary>
        /// Call this method when the user drags the mouse out of the web view (after calling <see cref="DragTargetDragEnter"/>).
        /// This method is only used when window rendering is disabled.
        /// </summary>
        void DragTargetDragLeave();

        /// <summary>
        /// Call this method when the drag operation started by a <see cref="CefSharp.Internals.IRenderWebBrowser.StartDragging(IDragData, DragOperationsMask, int, int)"/> call has completed.
        /// This method may be called immediately without first calling DragSourceEndedAt to cancel a drag operation.
        /// If the web view is both the drag source and the drag target then all DragTarget* methods should be called before DragSource* mthods.
        /// This method is only used when window rendering is disabled. 
        /// </summary>
        void DragSourceSystemDragEnded();

        /// <summary>
        /// Search for text
        /// </summary>
        /// <param name="identifier">can be used to have multiple searches running simultaniously</param>
        /// <param name="searchText">text to search for</param>
        /// <param name="forward">indicates whether to search forward or backward within the page</param>
        /// <param name="matchCase">indicates whether the search should be case-sensitive</param>
        /// <param name="findNext">indicates whether this is the first request or a follow-up</param>
        /// <remarks>The IFindHandler instance, if any, will be called to report find results. </remarks>
        void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);

        /// <summary>
        /// Returns the extension hosted in this browser or null if no extension is hosted. See <see cref="IRequestContext.LoadExtension"/> for details.
        /// </summary>
        IExtension Extension { get; }

        /// <summary>
        /// Retrieve the window handle of the browser that opened this browser.
        /// </summary>
        /// <returns>The handler</returns>
        IntPtr GetOpenerWindowHandle();

        /// <summary>
        /// Retrieve the window handle for this browser. 
        /// </summary>
        /// <returns>The handler</returns>
        IntPtr GetWindowHandle();

        /// <summary>
        /// Gets the current zoom level. The default zoom level is 0.0. This method can only be called on the CEF UI thread. 
        /// </summary>
        /// <returns>zoom level (default is 0.0)</returns>
        double GetZoomLevel();

        /// <summary>
        /// Get the current zoom level. The default zoom level is 0.0. This method executes GetZoomLevel on the CEF UI thread
        /// in an async fashion.
        /// </summary>
        /// <returns> a <see cref="Task{Double}"/> that when executed returns the zoom level as a double.</returns>
        Task<double> GetZoomLevelAsync();

        /// <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>
        /// Returns true if this browser is hosting an extension background script. Background hosts do not have a window and are not displayable.
        /// See <see cref="IRequestContext.LoadExtension"/> for details.
        /// </summary>
        /// <returns>Returns true if this browser is hosting an extension background script.</returns>
        bool IsBackgroundHost { get; }

        /// <summary>
        /// Begins a new composition or updates the existing composition. Blink has a
        /// special node (a composition node) that allows the input method to change
        /// text without affecting other DOM nodes. 
        ///
        /// This method may be called multiple times as the composition changes. When
        /// the client is done making changes the composition should either be canceled
        /// or completed. To cancel the composition call ImeCancelComposition. To
        /// complete the composition call either ImeCommitText or
        /// ImeFinishComposingText. Completion is usually signaled when:
        /// The client receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR
        /// flag (on Windows).
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="text">is the optional text that
        /// will be inserted into the composition node</param>
        /// <param name="underlines">is an optional set
        /// of ranges that will be underlined in the resulting text.</param>
        /// <param name="replacementRange">is an optional range of the existing text that will be replaced. (MAC OSX ONLY)</param>
        /// <param name="selectionRange"> is an optional range of the resulting text that
        /// will be selected after insertion or replacement. </param>
        void ImeSetComposition(string text, CompositionUnderline[] underlines, Range? replacementRange, Range? selectionRange);

        /// <summary>
        /// Completes the existing composition by optionally inserting the specified
        /// text into the composition node.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="text">text that will be committed</param>
        /// <param name="replacementRange">is an optional range of the existing text that will be replaced. (MAC OSX ONLY)</param>
        /// <param name="relativeCursorPos">is where the cursor will be positioned relative to the current cursor position. (MAC OSX ONLY)</param>
        void ImeCommitText(string text, Range? replacementRange, int relativeCursorPos);

        /// <summary>
        /// Completes the existing composition by applying the current composition node
        /// contents. See comments on ImeSetComposition for usage.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        /// <param name="keepSelection">If keepSelection is false the current selection, if any, will be discarded.</param>
        void ImeFinishComposingText(bool keepSelection);

        /// <summary>
        /// Cancels the existing composition and discards the composition node
        /// contents without applying them. See comments on ImeSetComposition for
        /// usage.
        /// This method is only used when window rendering is disabled. (WPF and OffScreen) 
        /// </summary>
        void ImeCancelComposition();

        /// <summary>
        /// Get/Set Mouse cursor change disabled
        /// </summary>
        bool MouseCursorChangeDisabled { get; set; }

        /// <summary>
        /// Notify the browser that the window hosting it is about to be moved or resized.
        /// This will dismiss any existing popups (dropdowns).
        /// </summary>
        void NotifyMoveOrResizeStarted();

        /// <summary>
        /// Send a notification to the browser that the screen info has changed.
        /// The browser will then call CefRenderHandler::GetScreenInfo to update the screen information with the new values.
        /// This simulates moving the webview window from one display to another, or changing the properties of the current display.
        /// This method is only used when window rendering is disabled. 
{'fraction_non_alphanumeric': 0.09638941322944697, 'fraction_numerical': 0.0008032451102453913, 'mean_word_length': 2.4297520661157024, 'pattern_counts': {'":': 0, '<': 253, '<?xml version=': 0, '>': 253, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231136', 'n_tokens_mistral': 5909, 'n_tokens_neox': 5784, 'n_words': 2687}