forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibbrowser_cef_lnx.cpp
More file actions
237 lines (173 loc) · 5.49 KB
/
libbrowser_cef_lnx.cpp
File metadata and controls
237 lines (173 loc) · 5.49 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include "core.h"
#include "libbrowser_cef.h"
#include <X11/Xlib.h>
////////////////////////////////////////////////////////////////////////////////
class MCCefLinuxBrowser : public MCCefBrowserBase
{
public:
MCCefLinuxBrowser(Display *p_display, Window p_parent_window);
virtual ~MCCefLinuxBrowser(void);
bool GetXDisplay(Display *&r_display);
bool GetXWindow(Window &r_window);
virtual void PlatformConfigureWindow(CefWindowInfo &r_info);
virtual bool PlatformGetNativeLayer(void *&r_layer);
virtual bool PlatformSetVisible(bool p_visible);
virtual bool PlatformGetVisible(bool &r_visible);
virtual bool PlatformGetRect(MCBrowserRect &r_rect);
virtual bool PlatformSetRect(const MCBrowserRect &p_rect);
virtual bool PlatformGetWindowID(int32_t &r_id);
virtual bool PlatformGetAuthCredentials(bool p_is_proxy, const CefString &p_url, const CefString &p_realm, MCCefAuthScheme p_auth_scheme, CefString &r_user, CefString &r_password);
virtual bool PlatformGetAllowUserInteraction(bool &r_allow_interaction);
virtual bool PlatformSetAllowUserInteraction(bool p_allow_interaction);
private:
Display *m_display;
Window m_parent_window;
};
//////////
MCCefLinuxBrowser::MCCefLinuxBrowser(Display *p_display, Window p_parent_window)
{
m_display = p_display;
m_parent_window = p_parent_window;
}
MCCefLinuxBrowser::~MCCefLinuxBrowser()
{
}
//////////
bool MCCefLinuxBrowser::GetXDisplay(Display *&r_display)
{
r_display = m_display;
return true;
}
bool MCCefLinuxBrowser::GetXWindow(Window &r_window)
{
CefRefPtr<CefBrowser> t_browser;
t_browser = GetCefBrowser();
if (t_browser == nil)
return false;
Window t_window;
t_window = t_browser->GetHost()->GetWindowHandle();
if (t_window == None)
return false;
r_window = t_window;
return true;
}
//////////
bool MCCefLinuxBrowser::PlatformGetNativeLayer(void *&r_layer)
{
return GetXWindow((Window&)r_layer);
}
void MCCefLinuxBrowser::PlatformConfigureWindow(CefWindowInfo &r_info)
{
// Let CEF use DefaultRootWindow as the parent window so
// it is created with a visual it supports otherwise the content
// views will not be create causing a crash
//r_info.SetAsChild(m_parent_window, CefRect(0,0,1,1));
}
bool MCCefLinuxBrowser::PlatformGetRect(MCBrowserRect &r_rect)
{
Display *t_display;
if (!GetXDisplay(t_display))
return false;
Window t_window;
if (!GetXWindow(t_window))
return false;
Window t_root;
int32_t t_win_x, t_win_y;
uint32_t t_width, t_height, t_border_width, t_depth;
XGetGeometry(t_display, t_window, &t_root, &t_win_x, &t_win_y, &t_width, &t_height, &t_border_width, &t_depth);
r_rect.left = t_win_x;
r_rect.top = t_win_y;
r_rect.right = t_win_x + t_width;
r_rect.bottom = t_win_y + t_height;
return true;
}
bool MCCefLinuxBrowser::PlatformSetRect(const MCBrowserRect &p_rect)
{
Display *t_display;
if (!GetXDisplay(t_display))
return false;
Window t_window;
if (!GetXWindow(t_window))
return false;
XMoveResizeWindow(t_display, t_window, p_rect.left, p_rect.top, p_rect.right - p_rect.left, p_rect.bottom - p_rect.top);
return true;
}
bool MCCefLinuxBrowser::PlatformGetVisible(bool &r_visible)
{
Display *t_display;
if (!GetXDisplay(t_display))
return false;
Window t_window;
if (!GetXWindow(t_window))
return false;
XWindowAttributes t_attributes;
XGetWindowAttributes(t_display, t_window, &t_attributes);
r_visible = t_attributes.map_state != IsUnmapped;
return true;
}
bool MCCefLinuxBrowser::PlatformSetVisible(bool p_visible)
{
Display *t_display;
if (!GetXDisplay(t_display))
return false;
Window t_window;
if (!GetXWindow(t_window))
return false;
if (p_visible)
XMapWindow(t_display, t_window);
else
XUnmapWindow(t_display, t_window);
return true;
}
bool MCCefLinuxBrowser::PlatformGetWindowID(int32_t &r_id)
{
r_id = (int32_t) m_parent_window;
return true;
}
bool MCCefLinuxBrowser::PlatformGetAuthCredentials(bool p_is_proxy, const CefString &p_url, const CefString &p_realm, MCCefAuthScheme p_auth_scheme, CefString &r_user, CefString &r_password)
{
/* TODO - implement */
return false;
}
bool MCCefLinuxBrowser::PlatformGetAllowUserInteraction(bool &r_value)
{
/* TODO - implement */
r_value = true;
return false;
}
bool MCCefLinuxBrowser::PlatformSetAllowUserInteraction(bool p_value)
{
/* TODO - implement */
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool MCCefPlatformCreateBrowser(void *p_display, void *p_window_id, MCCefBrowserBase *&r_browser)
{
MCCefLinuxBrowser *t_browser;
t_browser = new (nothrow) MCCefLinuxBrowser((Display*)p_display, (Window)p_window_id);
if (t_browser == nil)
return false;
r_browser = t_browser;
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool MCCefPlatformEnableHiDPI()
{
return true;
}
bool MCCefPlatformGetHiDPIEnabled()
{
return false;
}
////////////////////////////////////////////////////////////////////////////////