// Copyright © 2021 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 CefSharp.Enums;
using CefSharp.Structs;
using System;
using System.Collections.Generic;
using Size = CefSharp.Structs.Size;
namespace CefSharp.Handler
{
///
/// Handle events related to browser display state.
///
public class DisplayHandler : IDisplayHandler
{
///
void IDisplayHandler.OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs)
{
OnAddressChanged(chromiumWebBrowser, addressChangedArgs);
}
///
/// Called when a frame's address has changed.
///
/// the ChromiumWebBrowser control
/// args
protected virtual void OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs)
{
}
///
bool IDisplayHandler.OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, Size newSize)
{
return OnAutoResize(chromiumWebBrowser, browser, newSize);
}
///
/// Called when auto-resize is enabled via IBrowserHost.SetAutoResizeEnabled and the contents have auto-resized.
///
/// the ChromiumWebBrowser control
/// the browser object
/// will be the desired size in view coordinates
/// Return true if the resize was handled or false for default handling.
protected virtual bool OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, Size newSize)
{
return false;
}
///
bool IDisplayHandler.OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
{
return OnCursorChange(chromiumWebBrowser, browser, cursor, type, customCursorInfo);
}
///
/// Called when the browser's cursor has changed.
///
/// the ChromiumWebBrowser control
/// the browser object
/// If type is Custom then customCursorInfo will be populated with the custom cursor information
/// cursor type
/// custom cursor Information
/// Return true if the cursor change was handled or false for default handling.
protected virtual bool OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
{
return false;
}
///
void IDisplayHandler.OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs)
{
OnTitleChanged(chromiumWebBrowser, titleChangedArgs);
}
///
/// Called when the page title changes.
///
/// the ChromiumWebBrowser control
/// args
protected virtual void OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs)
{
}
///
void IDisplayHandler.OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls)
{
OnFaviconUrlChange(chromiumWebBrowser, browser, urls);
}
///
/// Called when the page icon changes.
///
/// the ChromiumWebBrowser control
/// the browser object
/// list of urls where the favicons can be downloaded
protected virtual void OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls)
{
}
///
void IDisplayHandler.OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen)
{
OnFullscreenModeChange(chromiumWebBrowser, browser, fullscreen);
}
///
/// Called when web content in the page has toggled fullscreen mode. The client is
/// responsible for resizing the browser if desired.
///
/// The ChromiumWebBrowser control
/// the browser object
/// If true the content will automatically be sized to fill the browser content area.
/// If false the content will automatically return to its original size and position.
protected virtual void OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen)
{
}
///
void IDisplayHandler.OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress)
{
OnLoadingProgressChange(chromiumWebBrowser, browser, progress);
}
///
/// Called when the overall page loading progress has changed
///
/// The ChromiumWebBrowser control
/// the browser object
/// ranges from 0.0 to 1.0.
protected virtual void OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress)
{
}
///
bool IDisplayHandler.OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text)
{
return OnTooltipChanged(chromiumWebBrowser, ref text);
}
///
/// Called when the browser is about to display a tooltip. text contains the
/// text that will be displayed in the tooltip. You can optionally modify text
/// and then return false to allow the browser to display the tooltip.
/// When window rendering is disabled the application is responsible for
/// drawing tooltips and the return value is ignored.
///
/// The ChromiumWebBrowser control
/// the text that will be displayed in the tooltip
/// To handle the display of the tooltip yourself return true otherwise return false
/// to allow the browser to display the tooltip.
/// Only called when using Off-screen rendering (WPF and OffScreen)
protected virtual bool OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text)
{
return false;
}
///
void IDisplayHandler.OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs)
{
}
///
/// Called when the browser receives a status message.
///
/// The control this popup is related to.
/// args
protected virtual void OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs)
{
}
///
bool IDisplayHandler.OnConsoleMessage(IWebBrowser chromiumWebBrowser, ConsoleMessageEventArgs consoleMessageArgs)
{
return OnConsoleMessage(chromiumWebBrowser, consoleMessageArgs);
}
///
/// Called to display a console message.
///
/// The ChromiumWebBrowser control
/// args
/// Return true to stop the message from being output to the console.
protected virtual bool OnConsoleMessage(IWebBrowser chromiumWebBrowser, ConsoleMessageEventArgs consoleMessageArgs)
{
return false;
}
}
}