-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWebViewWindowed.vala
123 lines (112 loc) · 5 KB
/
WebViewWindowed.vala
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace CefGtk {
private class WebViewWindowed : Gtk.Widget, WebViewWidget {
private Gdk.X11.Window? chromium_window = null;
private Gdk.X11.Window? cef_window = null;
private unowned WebView web_view;
public WebViewWindowed(WebView web_view) {
this.web_view = web_view;
set_has_window(true);
set_can_focus(false);
}
public override void get_preferred_width(out int minimum_width, out int natural_width) {
minimum_width = natural_width = 100;
}
public override void get_preferred_height(out int minimum_height, out int natural_height) {
minimum_height = natural_height = 100;
}
public override void realize() {
Gtk.Allocation allocation;
get_allocation(out allocation);
set_realized(true);
Gdk.WindowAttr attributes = {};
attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
attributes.window_type = Gdk.WindowType.CHILD;
attributes.visual = get_visual();
attributes.wclass = Gdk.WindowWindowClass.INPUT_OUTPUT;
attributes.event_mask = (get_events()
| Gdk.EventMask.BUTTON_MOTION_MASK
| Gdk.EventMask.BUTTON_PRESS_MASK
| Gdk.EventMask.BUTTON_RELEASE_MASK
| Gdk.EventMask.EXPOSURE_MASK
| Gdk.EventMask.ENTER_NOTIFY_MASK
| Gdk.EventMask.LEAVE_NOTIFY_MASK);
Gdk.WindowAttributesType attributes_mask = (
Gdk.WindowAttributesType.X | Gdk.WindowAttributesType.Y | Gdk.WindowAttributesType.VISUAL);
var window = new Gdk.Window (get_parent_window (), attributes, attributes_mask);
set_window(window);
register_window(window);
embed_cef();
}
public override void size_allocate (Gtk.Allocation allocation) {
Gtk.Allocation child_allocation = {};
set_allocation(allocation);
if (!get_has_window()) {
child_allocation.x = allocation.x;
child_allocation.y = allocation.y;
}
else {
child_allocation.x = 0;
child_allocation.y = 0;
}
child_allocation.width = allocation.width;
child_allocation.height = allocation.height;
if (get_realized() && get_has_window()) {
debug("allocation %d,%d+%d,%d child_allocation %d,%d+%d,%d",
allocation.x, allocation.y, allocation.width, allocation.height,
child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height);
get_window().move_resize(allocation.x, allocation.y, child_allocation.width, child_allocation.height);
cef_window.move_resize(child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height);
}
}
private void embed_cef() {
assert(CefGtk.is_initialized());
Cef.assert_browser_ui_thread();
var toplevel = get_toplevel();
assert(toplevel.is_toplevel());
CefGtk.override_system_visual(toplevel.get_visual());
var parent_window = get_window() as Gdk.X11.Window;
assert(parent_window != null);
Gtk.Allocation allocation;
get_allocation(out allocation);
Cef.WindowInfo window_info = {};
window_info.parent_window = (Cef.WindowHandle) parent_window.get_xid();
window_info.x = 0;
window_info.y = 0;
window_info.width = allocation.width;
window_info.height = allocation.height;
Cef.BrowserSettings browser_settings = {sizeof(Cef.BrowserSettings)};
browser_settings.javascript_access_clipboard = Cef.State.ENABLED;
browser_settings.javascript_dom_paste = Cef.State.ENABLED;
browser_settings.universal_access_from_file_urls = Cef.State.ENABLED;
browser_settings.file_access_from_file_urls = Cef.State.ENABLED;
var client = new Client(
web_view,
new FocusHandler(web_view),
new DisplayHandler(web_view),
new LoadHandler(web_view),
new JsdialogHandler(web_view),
new DownloadHandler(web_view.download_manager),
new KeyboardHandler(web_view),
new RequestHandler(web_view),
new LifeSpanHandler(web_view),
null);
Cef.String url = {};
Cef.set_string(&url, "about:blank");
Cef.Browser browser = Cef.browser_host_create_browser_sync(
window_info, client, &url, browser_settings, null, web_view.web_context.request_context);
var host = browser.get_host();
cef_window = wrap_xwindow(
parent_window.get_display() as Gdk.X11.Display, (X.Window) host.get_window_handle());
cef_window.ensure_native();
register_window(cef_window);
chromium_window = find_child_window(cef_window);
assert(chromium_window != null);
chromium_window.ensure_native();
register_window(chromium_window);
browser_created(client, browser);
}
}
} // namespace CefGtk