forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_handler.pyx
More file actions
290 lines (269 loc) · 10.1 KB
/
render_handler.pyx
File metadata and controls
290 lines (269 loc) · 10.1 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Copyright (c) 2013 CEF Python, see the Authors file.
# All rights reserved. Licensed under BSD 3-clause license.
# Project website: https://github.com/cztomczak/cefpython
include "../cefpython.pyx"
include "../browser.pyx"
cimport cef_types
# cef_paint_element_type_t, PaintElementType
PET_VIEW = cef_types.PET_VIEW
PET_POPUP = cef_types.PET_POPUP
# cef_drag_operations_mask_t, DragOperation, DragOperationsMask
DRAG_OPERATION_NONE = cef_types.DRAG_OPERATION_NONE
DRAG_OPERATION_COPY = cef_types.DRAG_OPERATION_COPY
DRAG_OPERATION_LINK = cef_types.DRAG_OPERATION_LINK
DRAG_OPERATION_GENERIC = cef_types.DRAG_OPERATION_GENERIC
DRAG_OPERATION_PRIVATE = cef_types.DRAG_OPERATION_PRIVATE
DRAG_OPERATION_MOVE = cef_types.DRAG_OPERATION_MOVE
DRAG_OPERATION_DELETE = cef_types.DRAG_OPERATION_DELETE
DRAG_OPERATION_EVERY = cef_types.DRAG_OPERATION_EVERY
cdef public cpp_bool RenderHandler_GetRootScreenRect(
CefRefPtr[CefBrowser] cefBrowser,
CefRect& cefRect
) except * with gil:
cdef PyBrowser pyBrowser
cdef list pyRect = []
cdef py_bool ret
try:
pyBrowser = GetPyBrowser(cefBrowser, "GetRootScreenRect")
callback = pyBrowser.GetClientCallback("GetRootScreenRect")
if callback:
ret = callback(browser=pyBrowser, rect_out=pyRect)
if ret:
assert (pyRect and len(pyRect) == 4), "rectangle not provided"
cefRect.x = pyRect[0]
cefRect.y = pyRect[1]
cefRect.width = pyRect[2]
cefRect.height = pyRect[3]
return True
else:
return False
else:
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RenderHandler_GetViewRect(
CefRefPtr[CefBrowser] cefBrowser,
CefRect& cefRect
) except * with gil:
cdef PyBrowser pyBrowser
cdef list pyRect = []
cdef py_bool ret
try:
pyBrowser = GetPyBrowser(cefBrowser, "GetViewRect")
callback = pyBrowser.GetClientCallback("GetViewRect")
if callback:
ret = callback(browser=pyBrowser, rect_out=pyRect)
if ret:
assert (pyRect and len(pyRect) == 4), "rectangle not provided"
cefRect.x = pyRect[0]
cefRect.y = pyRect[1]
cefRect.width = pyRect[2]
cefRect.height = pyRect[3]
return True
else:
return False
else:
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RenderHandler_GetScreenRect(
CefRefPtr[CefBrowser] cefBrowser,
CefRect& cefRect
) except * with gil:
cdef PyBrowser pyBrowser
cdef list pyRect = []
cdef py_bool ret
try:
pyBrowser = GetPyBrowser(cefBrowser, "GetScreenRect")
callback = pyBrowser.GetClientCallback("GetScreenRect")
if callback:
ret = callback(browser=pyBrowser, rect_out=pyRect)
if ret:
assert (pyRect and len(pyRect) == 4), (
"rectangle not provided or invalid")
cefRect.x = pyRect[0]
cefRect.y = pyRect[1]
cefRect.width = pyRect[2]
cefRect.height = pyRect[3]
return True
else:
return False
else:
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RenderHandler_GetScreenPoint(
CefRefPtr[CefBrowser] cefBrowser,
int viewX, int viewY,
int& screenX, int& screenY
) except * with gil:
cdef PyBrowser pyBrowser
cdef list screenCoordinates = []
cdef py_bool ret
try:
pyBrowser = GetPyBrowser(cefBrowser, "GetScreenPoint")
callback = pyBrowser.GetClientCallback("GetScreenPoint")
if callback:
ret = callback(browser=pyBrowser,
view_x=viewX,
view_y=viewY,
screen_coordinates_out=screenCoordinates)
if ret:
assert (screenCoordinates and len(screenCoordinates) == 2), (
"screenCoordinates not provided or invalid")
(&screenX)[0] = int(screenCoordinates[0])
(&screenY)[0] = int(screenCoordinates[1])
return True
else:
return False
else:
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RenderHandler_GetScreenInfo(
CefRefPtr[CefBrowser] cefBrowser,
CefScreenInfo& cefScreenInfo
) except * with gil:
# Not yet implemented.
return False
cdef public void RenderHandler_OnPopupShow(
CefRefPtr[CefBrowser] cefBrowser,
cpp_bool show
) except * with gil:
cdef PyBrowser pyBrowser
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnPopupShow")
callback = pyBrowser.GetClientCallback("OnPopupShow")
if callback:
callback(browser=pyBrowser, show=show)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void RenderHandler_OnPopupSize(
CefRefPtr[CefBrowser] cefBrowser,
const CefRect& cefRect
) except * with gil:
cdef PyBrowser pyBrowser
cdef list pyRect
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnPopupSize")
callback = pyBrowser.GetClientCallback("OnPopupSize")
if callback:
pyRect = [cefRect.x, cefRect.y, cefRect.width, cefRect.height]
callback(browser=pyBrowser, rect_out=pyRect)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void RenderHandler_OnPaint(
CefRefPtr[CefBrowser] cefBrowser,
cef_types.cef_paint_element_type_t paintElementType,
cpp_vector[CefRect]& cefDirtyRects,
const void* cefBuffer,
int width,
int height
) except * with gil:
cdef PyBrowser pyBrowser
cdef list pyDirtyRects = []
cdef list pyRect
# TODO: cefDirtyRects should be const, but const_iterator is
# not yet implemented in libcpp.vector.
cdef cpp_vector[CefRect].iterator iterator
cdef CefRect cefRect
cdef PaintBuffer paintBuffer
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnPaint")
iterator = cefDirtyRects.begin()
while iterator != cefDirtyRects.end():
cefRect = deref(iterator)
pyRect = [cefRect.x, cefRect.y, cefRect.width, cefRect.height]
pyDirtyRects.append(pyRect)
preinc(iterator)
# In CEF 1 width and height were fetched using GetSize(),
# but in CEF 3 they are passed as arguments to OnPaint().
# OFF: | (width, height) = pyBrowser.GetSize(paintElementType)
paintBuffer = CreatePaintBuffer(cefBuffer, width, height)
callback = pyBrowser.GetClientCallback("OnPaint")
if callback:
callback(
browser=pyBrowser,
element_type=paintElementType,
dirty_rects=pyDirtyRects,
paint_buffer=paintBuffer,
width=width,
height=height)
else:
return
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void RenderHandler_OnCursorChange(
CefRefPtr[CefBrowser] cefBrowser,
CefCursorHandle cursor
) except * with gil:
cdef PyBrowser pyBrowser
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnCursorChange")
callback = pyBrowser.GetClientCallback("OnCursorChange")
if callback:
callback(browser=pyBrowser, cursor=<uintptr_t>cursor)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void RenderHandler_OnScrollOffsetChanged(
CefRefPtr[CefBrowser] cefBrowser
) except * with gil:
cdef PyBrowser pyBrowser
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnScrollOffsetChanged")
callback = pyBrowser.GetClientCallback("OnScrollOffsetChanged")
if callback:
callback(browser=pyBrowser)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RenderHandler_StartDragging(
CefRefPtr[CefBrowser] cef_browser,
CefRefPtr[CefDragData] cef_drag_data,
uint32 allowed_ops,
int x, int y
) except * with gil:
cdef PyBrowser browser
cdef DragData drag_data
cdef py_bool ret
try:
browser = GetPyBrowser(cef_browser, "StartDragging")
drag_data = DragData_Init(cef_drag_data)
callback = browser.GetClientCallback("StartDragging")
if callback:
ret = callback(
browser=browser,
drag_data=drag_data,
allowed_ops=allowed_ops,
x=x,
y=y)
if ret:
return True
else:
return False
else:
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void RenderHandler_UpdateDragCursor(
CefRefPtr[CefBrowser] cef_browser,
uint32 operation,
) except * with gil:
cdef PyBrowser browser
try:
browser = GetPyBrowser(cef_browser, "UpdateDragCursor")
callback = browser.GetClientCallback("UpdateDragCursor")
if callback:
callback(browser=browser, operation=operation)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)