2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2010 The CefSharp Authors. All rights reserved.
|
2015-09-18 13:22:11 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
using System;
|
2015-12-28 14:29:25 -05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-09-10 02:41:13 +02:00
|
|
|
using System.Runtime.InteropServices;
|
2016-04-07 23:13:25 +10:00
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-09-10 02:41:13 +02:00
|
|
|
using System.Windows.Forms;
|
2018-09-17 00:46:21 +02:00
|
|
|
using CefSharp.Example;
|
2018-10-29 16:21:42 +10:00
|
|
|
using CefSharp.Example.Handlers;
|
|
|
|
|
using CefSharp.Example.JavascriptBinding;
|
2018-09-17 00:46:21 +02:00
|
|
|
using CefSharp.WinForms.Example.Handlers;
|
|
|
|
|
using CefSharp.WinForms.Internals;
|
2014-06-25 16:39:09 +10:00
|
|
|
|
|
|
|
|
namespace CefSharp.WinForms.Example
|
|
|
|
|
{
|
|
|
|
|
public partial class BrowserTabUserControl : UserControl
|
|
|
|
|
{
|
2014-06-25 20:04:50 +10:00
|
|
|
public IWinFormsWebBrowser Browser { get; private set; }
|
2016-03-02 07:50:54 +10:00
|
|
|
private IntPtr browserHandle;
|
2016-04-07 23:13:25 +10:00
|
|
|
private ChromeWidgetMessageInterceptor messageInterceptor;
|
2016-09-08 08:52:42 +10:00
|
|
|
private bool multiThreadedMessageLoopEnabled;
|
2014-06-25 16:39:09 +10:00
|
|
|
|
2016-09-08 08:52:42 +10:00
|
|
|
public BrowserTabUserControl(Action<string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
|
2014-06-25 16:39:09 +10:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2014-06-25 20:04:50 +10:00
|
|
|
var browser = new ChromiumWebBrowser(url)
|
2014-06-25 16:39:09 +10:00
|
|
|
{
|
2014-06-25 17:21:23 +10:00
|
|
|
Dock = DockStyle.Fill
|
2014-06-25 16:39:09 +10:00
|
|
|
};
|
2014-10-13 15:52:59 +10:00
|
|
|
|
|
|
|
|
browserPanel.Controls.Add(browser);
|
2014-06-25 20:04:50 +10:00
|
|
|
|
|
|
|
|
Browser = browser;
|
2014-06-25 16:39:09 +10:00
|
|
|
|
2014-10-20 14:20:21 +10:00
|
|
|
browser.MenuHandler = new MenuHandler();
|
2015-09-18 13:22:11 +10:00
|
|
|
browser.RequestHandler = new WinFormsRequestHandler(openNewTab);
|
2015-01-11 13:45:27 +10:00
|
|
|
browser.JsDialogHandler = new JsDialogHandler();
|
2015-01-30 15:02:01 +10:00
|
|
|
browser.DownloadHandler = new DownloadHandler();
|
2016-10-04 08:46:18 +10:00
|
|
|
if (multiThreadedMessageLoopEnabled)
|
|
|
|
|
{
|
|
|
|
|
browser.KeyboardHandler = new KeyboardHandler();
|
|
|
|
|
}
|
2018-07-23 21:18:44 +10:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//When MultiThreadedMessageLoop is disabled we don't need the
|
|
|
|
|
//CefSharp focus handler implementation.
|
|
|
|
|
browser.FocusHandler = null;
|
|
|
|
|
}
|
2018-01-30 15:01:38 +10:00
|
|
|
//browser.LifeSpanHandler = new LifeSpanHandler();
|
2015-04-08 11:09:37 +10:00
|
|
|
browser.LoadingStateChanged += OnBrowserLoadingStateChanged;
|
2014-10-20 14:20:21 +10:00
|
|
|
browser.ConsoleMessage += OnBrowserConsoleMessage;
|
|
|
|
|
browser.TitleChanged += OnBrowserTitleChanged;
|
|
|
|
|
browser.AddressChanged += OnBrowserAddressChanged;
|
|
|
|
|
browser.StatusMessage += OnBrowserStatusMessage;
|
2014-12-08 14:19:16 +10:00
|
|
|
browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
|
2015-03-12 10:53:39 +10:00
|
|
|
browser.LoadError += OnLoadError;
|
2018-01-24 10:02:44 +10:00
|
|
|
|
|
|
|
|
browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync: false, options: BindingOptions.DefaultBinder);
|
|
|
|
|
browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
|
2018-01-23 21:35:23 +10:00
|
|
|
|
|
|
|
|
//If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet
|
|
|
|
|
//bound, then ResolveObject will be called, you can then register it
|
|
|
|
|
browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
var repo = e.ObjectRepository;
|
|
|
|
|
if (e.ObjectName == "boundAsync2")
|
|
|
|
|
{
|
2018-01-24 10:02:44 +10:00
|
|
|
repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
|
2018-01-23 21:35:23 +10:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-09 11:23:06 +10:00
|
|
|
browser.RenderProcessMessageHandler = new RenderProcessMessageHandler();
|
2016-03-30 10:58:05 +10:00
|
|
|
browser.DisplayHandler = new DisplayHandler();
|
2016-03-02 08:32:55 +10:00
|
|
|
//browser.MouseDown += OnBrowserMouseClick;
|
2016-03-02 07:50:54 +10:00
|
|
|
browser.HandleCreated += OnBrowserHandleCreated;
|
2016-01-18 18:32:44 +10:00
|
|
|
//browser.ResourceHandlerFactory = new FlashResourceHandlerFactory();
|
2016-09-08 08:52:42 +10:00
|
|
|
this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;
|
2014-06-25 16:39:09 +10:00
|
|
|
|
2015-12-28 14:29:25 -05:00
|
|
|
var eventObject = new ScriptedMethodsBoundObject();
|
|
|
|
|
eventObject.EventArrived += OnJavascriptEventArrived;
|
2015-12-30 09:57:34 +10:00
|
|
|
// Use the default of camelCaseJavascriptNames
|
|
|
|
|
// .Net methods starting with a capitol will be translated to starting with a lower case letter when called from js
|
2018-09-10 02:41:13 +02:00
|
|
|
browser.JavascriptObjectRepository.Register("boundEvent", eventObject, isAsync: false, options: BindingOptions.DefaultBinder);
|
2015-12-28 14:29:25 -05:00
|
|
|
|
2014-12-09 12:49:20 +10:00
|
|
|
CefExample.RegisterTestResources(browser);
|
|
|
|
|
|
2014-06-25 16:39:09 +10:00
|
|
|
var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
|
|
|
|
|
DisplayOutput(version);
|
2014-06-25 17:21:23 +10:00
|
|
|
}
|
|
|
|
|
|
2016-04-07 23:13:25 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Clean up any resources being used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
if (components != null)
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
|
|
|
|
components = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageInterceptor != null)
|
|
|
|
|
{
|
|
|
|
|
messageInterceptor.ReleaseHandle();
|
|
|
|
|
messageInterceptor = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 07:50:54 +10:00
|
|
|
private void OnBrowserHandleCreated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
browserHandle = ((ChromiumWebBrowser)Browser).Handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBrowserMouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Mouse Clicked" + e.X + ";" + e.Y + ";" + e.Button);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 10:53:39 +10:00
|
|
|
private void OnLoadError(object sender, LoadErrorEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
DisplayOutput("Load Error:" + args.ErrorCode + ";" + args.ErrorText);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 16:39:09 +10:00
|
|
|
private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
DisplayOutput(string.Format("Line: {0}, Source: {1}, Message: {2}", args.Line, args.Source, args.Message));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 12:42:09 +10:00
|
|
|
private void OnBrowserStatusMessage(object sender, StatusMessageEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => statusLabel.Text = args.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 11:09:37 +10:00
|
|
|
private void OnBrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs args)
|
2014-06-25 16:39:09 +10:00
|
|
|
{
|
|
|
|
|
SetCanGoBack(args.CanGoBack);
|
|
|
|
|
SetCanGoForward(args.CanGoForward);
|
|
|
|
|
|
2017-02-23 12:37:44 +10:00
|
|
|
this.InvokeOnUiThreadIfRequired(() => SetIsLoading(args.IsLoading));
|
2014-06-25 16:39:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBrowserTitleChanged(object sender, TitleChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => Parent.Text = args.Title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBrowserAddressChanged(object sender, AddressChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => urlTextBox.Text = args.Address);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 09:57:34 +10:00
|
|
|
private static void OnJavascriptEventArrived(string eventName, object eventData)
|
2015-12-28 14:29:25 -05:00
|
|
|
{
|
|
|
|
|
switch (eventName)
|
|
|
|
|
{
|
|
|
|
|
case "click":
|
2015-12-30 09:57:34 +10:00
|
|
|
{
|
2015-12-28 14:29:25 -05:00
|
|
|
var message = eventData.ToString();
|
|
|
|
|
var dataDictionary = eventData as Dictionary<string, object>;
|
|
|
|
|
if (dataDictionary != null)
|
|
|
|
|
{
|
2015-12-30 09:57:34 +10:00
|
|
|
var result = string.Join(", ", dataDictionary.Select(pair => pair.Key + "=" + pair.Value));
|
|
|
|
|
message = "event data: " + result;
|
2015-12-28 14:29:25 -05:00
|
|
|
}
|
|
|
|
|
MessageBox.Show(message, "Javascript event arrived", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
break;
|
2015-12-30 09:57:34 +10:00
|
|
|
}
|
2015-12-28 14:29:25 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 16:39:09 +10:00
|
|
|
private void SetCanGoBack(bool canGoBack)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => backButton.Enabled = canGoBack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetCanGoForward(bool canGoForward)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => forwardButton.Enabled = canGoForward);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetIsLoading(bool isLoading)
|
|
|
|
|
{
|
|
|
|
|
goButton.Text = isLoading ?
|
|
|
|
|
"Stop" :
|
|
|
|
|
"Go";
|
|
|
|
|
goButton.Image = isLoading ?
|
|
|
|
|
Properties.Resources.nav_plain_red :
|
|
|
|
|
Properties.Resources.nav_plain_green;
|
|
|
|
|
|
|
|
|
|
HandleToolStripLayout();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 16:45:02 +10:00
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
|
|
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
|
|
2014-12-08 14:19:16 +10:00
|
|
|
private void OnIsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs args)
|
|
|
|
|
{
|
2015-07-22 22:34:02 +10:00
|
|
|
if (args.IsBrowserInitialized)
|
|
|
|
|
{
|
2016-02-02 07:35:38 +10:00
|
|
|
//Get the underlying browser host wrapper
|
|
|
|
|
var browserHost = Browser.GetBrowser().GetHost();
|
|
|
|
|
var requestContext = browserHost.RequestContext;
|
|
|
|
|
string errorMessage;
|
|
|
|
|
// Browser must be initialized before getting/setting preferences
|
|
|
|
|
var success = requestContext.SetPreference("enable_do_not_track", true, out errorMessage);
|
2018-09-10 02:41:13 +02:00
|
|
|
if (!success)
|
2016-02-02 07:35:38 +10:00
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => MessageBox.Show("Unable to set preference enable_do_not_track errorMessage: " + errorMessage));
|
|
|
|
|
}
|
2016-04-20 07:45:28 +10:00
|
|
|
|
|
|
|
|
//Example of disable spellchecking
|
|
|
|
|
//success = requestContext.SetPreference("browser.enable_spellchecking", false, out errorMessage);
|
|
|
|
|
|
2016-02-02 07:35:38 +10:00
|
|
|
var preferences = requestContext.GetAllPreferences(true);
|
|
|
|
|
var doNotTrack = (bool)preferences["enable_do_not_track"];
|
2016-04-07 23:13:25 +10:00
|
|
|
|
2016-06-13 19:07:26 +10:00
|
|
|
//Use this to check that settings preferences are working in your code
|
|
|
|
|
//success = requestContext.SetPreference("webkit.webprefs.minimum_font_size", 24, out errorMessage);
|
2016-04-07 23:13:25 +10:00
|
|
|
|
2016-09-08 08:52:42 +10:00
|
|
|
//If we're using CefSetting.MultiThreadedMessageLoop (the default) then to hook the message pump,
|
|
|
|
|
// which running in a different thread we have to use a NativeWindow
|
|
|
|
|
if (multiThreadedMessageLoopEnabled)
|
2015-07-22 22:34:02 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
Task.Run(() =>
|
2016-04-07 23:13:25 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
try
|
2016-04-07 23:13:25 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
while (true)
|
2016-04-07 23:13:25 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
IntPtr chromeWidgetHostHandle;
|
|
|
|
|
if (ChromeWidgetHandleFinder.TryFindHandle(browserHandle, out chromeWidgetHostHandle))
|
2016-04-07 23:13:25 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
messageInterceptor = new ChromeWidgetMessageInterceptor((Control)Browser, chromeWidgetHostHandle, message =>
|
2016-04-07 23:13:25 +10:00
|
|
|
{
|
2016-09-08 08:52:42 +10:00
|
|
|
const int WM_MOUSEACTIVATE = 0x0021;
|
|
|
|
|
const int WM_NCLBUTTONDOWN = 0x00A1;
|
|
|
|
|
const int WM_LBUTTONDOWN = 0x0201;
|
|
|
|
|
|
|
|
|
|
if (message.Msg == WM_MOUSEACTIVATE)
|
|
|
|
|
{
|
|
|
|
|
// The default processing of WM_MOUSEACTIVATE results in MA_NOACTIVATE,
|
|
|
|
|
// and the subsequent mouse click is eaten by Chrome.
|
|
|
|
|
// This means any .NET ToolStrip or ContextMenuStrip does not get closed.
|
|
|
|
|
// By posting a WM_NCLBUTTONDOWN message to a harmless co-ordinate of the
|
|
|
|
|
// top-level window, we rely on the ToolStripManager's message handling
|
|
|
|
|
// to close any open dropdowns:
|
|
|
|
|
// http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ToolStripManager.cs,1249
|
|
|
|
|
var topLevelWindowHandle = message.WParam;
|
|
|
|
|
PostMessage(topLevelWindowHandle, WM_NCLBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
//Forward mouse button down message to browser control
|
|
|
|
|
//else if(message.Msg == WM_LBUTTONDOWN)
|
|
|
|
|
//{
|
|
|
|
|
// PostMessage(browserHandle, WM_LBUTTONDOWN, message.WParam, message.LParam);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// The ChromiumWebBrowserControl does not fire MouseEnter/Move/Leave events, because Chromium handles these.
|
|
|
|
|
// However we can hook into Chromium's messaging window to receive the events.
|
|
|
|
|
//
|
|
|
|
|
//const int WM_MOUSEMOVE = 0x0200;
|
|
|
|
|
//const int WM_MOUSELEAVE = 0x02A3;
|
|
|
|
|
//
|
|
|
|
|
//switch (message.Msg) {
|
|
|
|
|
// case WM_MOUSEMOVE:
|
|
|
|
|
// Console.WriteLine("WM_MOUSEMOVE");
|
|
|
|
|
// break;
|
|
|
|
|
// case WM_MOUSELEAVE:
|
|
|
|
|
// Console.WriteLine("WM_MOUSELEAVE");
|
|
|
|
|
// break;
|
|
|
|
|
//}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Chrome hasn't yet set up its message-loop window.
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
}
|
2016-04-07 23:13:25 +10:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-08 08:52:42 +10:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Errors are likely to occur if browser is disposed, and no good way to check from another thread
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-07-22 22:34:02 +10:00
|
|
|
}
|
2014-12-08 14:19:16 +10:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 08:23:10 +10:00
|
|
|
private void DisplayOutput(string output)
|
2014-06-25 16:39:09 +10:00
|
|
|
{
|
|
|
|
|
this.InvokeOnUiThreadIfRequired(() => outputLabel.Text = output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleToolStripLayout(object sender, LayoutEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
HandleToolStripLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleToolStripLayout()
|
|
|
|
|
{
|
|
|
|
|
var width = toolStrip1.Width;
|
|
|
|
|
foreach (ToolStripItem item in toolStrip1.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item != urlTextBox)
|
|
|
|
|
{
|
|
|
|
|
width -= item.Width - item.Margin.Horizontal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
urlTextBox.Width = Math.Max(0, width - urlTextBox.Margin.Horizontal - 18);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GoButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadUrl(urlTextBox.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BackButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-06-25 19:33:25 +10:00
|
|
|
Browser.Back();
|
2014-06-25 16:39:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ForwardButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-06-25 19:33:25 +10:00
|
|
|
Browser.Forward();
|
2014-06-25 16:39:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UrlTextBoxKeyUp(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode != Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadUrl(urlTextBox.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
|
|
|
|
|
{
|
2014-06-25 19:33:25 +10:00
|
|
|
Browser.Load(url);
|
2014-06-25 16:39:09 +10:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-25 16:53:05 +10:00
|
|
|
|
2015-01-06 16:50:32 +10:00
|
|
|
public async void CopySourceToClipBoardAsync()
|
2014-06-25 16:53:05 +10:00
|
|
|
{
|
2015-01-06 16:50:32 +10:00
|
|
|
var htmlSource = await Browser.GetSourceAsync();
|
2014-06-25 16:53:05 +10:00
|
|
|
|
2015-01-06 16:50:32 +10:00
|
|
|
Clipboard.SetText(htmlSource);
|
|
|
|
|
DisplayOutput("HTML Source copied to clipboard");
|
2014-06-25 16:53:05 +10:00
|
|
|
}
|
2014-06-25 17:07:08 +10:00
|
|
|
|
|
|
|
|
private void ToggleBottomToolStrip()
|
|
|
|
|
{
|
2014-08-26 17:19:42 +10:00
|
|
|
if (toolStrip2.Visible)
|
2014-06-25 17:07:08 +10:00
|
|
|
{
|
2014-06-25 19:33:25 +10:00
|
|
|
Browser.StopFinding(true);
|
2014-08-26 17:19:42 +10:00
|
|
|
toolStrip2.Visible = false;
|
2014-06-25 17:07:08 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-26 17:19:42 +10:00
|
|
|
toolStrip2.Visible = true;
|
2014-06-25 17:07:08 +10:00
|
|
|
findTextBox.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FindNextButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Find(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FindPreviousButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Find(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Find(bool next)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(findTextBox.Text))
|
|
|
|
|
{
|
2014-06-25 19:33:25 +10:00
|
|
|
Browser.Find(0, findTextBox.Text, next, false, false);
|
2014-06-25 17:07:08 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FindTextBoxKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode != Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Find(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFind()
|
|
|
|
|
{
|
|
|
|
|
ToggleBottomToolStrip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FindCloseButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ToggleBottomToolStrip();
|
|
|
|
|
}
|
2014-06-25 16:39:09 +10:00
|
|
|
}
|
|
|
|
|
}
|