-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
BrowserTabView.xaml.cs
87 lines (72 loc) · 3.09 KB
/
BrowserTabView.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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.Windows.Controls;
using System.Windows.Input;
using CefSharp.Example;
using CefSharp.Wpf.Example.Handlers;
namespace CefSharp.Wpf.Example.Views
{
public partial class BrowserTabView : UserControl
{
public BrowserTabView()
{
InitializeComponent();
browser.RequestHandler = new RequestHandler();
browser.RegisterJsObject("bound", new BoundObject());
browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject());
//browser.LifeSpanHandler = new LifespanHandler();
browser.MenuHandler = new MenuHandler();
browser.GeolocationHandler = new GeolocationHandler();
browser.DownloadHandler = new DownloadHandler();
//NOTE:This code is a workaround for https://github.com/cefsharp/CefSharp/issues/583
// The `upstream` issue has been flagged as resolved, so hopefully this can be removed
// in the future.
//browser.PreviewTextInput += (sender, args) =>
//{
// var host = browser.GetBrowser().GetHost();
// var keyEvent = new KeyEvent();
// foreach (var character in args.Text)
// {
// keyEvent.WindowsKeyCode = character;
// keyEvent.Type = KeyEventType.Char;
// host.SendKeyEvent(keyEvent);
// }
// args.Handled = true;
//};
browser.LoadError += (sender, args) =>
{
// Don't display an error for downloaded files.
if (args.ErrorCode == CefErrorCode.Aborted)
{
return;
}
// Don't display an error for external protocols that we allow the OS to
// handle. See OnProtocolExecution().
//if (args.ErrorCode == CefErrorCode.UnknownUrlScheme)
//{
// var url = args.Frame.Url;
// if (url.StartsWith("spotify:"))
// {
// return;
// }
//}
// Display a load error message.
var errorBody = string.Format("<html><body bgcolor=\"white\"><h2>Failed to load URL {0} with error {1} ({2}).</h2></body></html>",
args.FailedUrl, args.ErrorText, args.ErrorCode);
args.Frame.LoadStringForUrl(errorBody, args.FailedUrl);
};
CefExample.RegisterTestResources(browser);
}
private void OnTextBoxGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
var textBox = (TextBox)sender;
textBox.SelectAll();
}
private void OnTextBoxGotMouseCapture(object sender, MouseEventArgs e)
{
var textBox = (TextBox)sender;
textBox.SelectAll();
}
}
}