Skip to content

Commit 7b2b8f5

Browse files
committed
Support for drag&drop in OSR Kivy on Linux (not yet working).
Add --no-cef-update flag to automate.py .
1 parent a0c9394 commit 7b2b8f5

File tree

16 files changed

+809
-287
lines changed

16 files changed

+809
-287
lines changed

api/API-index.md

Lines changed: 299 additions & 284 deletions
Large diffs are not rendered by default.

api/Browser.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Table of contents:
1111
* [CanGoForward](#cangoforward)
1212
* [CloseBrowser](#closebrowser)
1313
* [CloseDevTools](#closedevtools)
14+
* [DragTargetDragEnter](#dragtargetdragenter)
15+
* [DragTargetDragOver](#dragtargetdragover)
16+
* [DragTargetDragLeave](#dragtargetdragleave)
17+
* [DragTargetDrop](#dragtargetdrop)
18+
* [DragSourceEndedAt](#dragsourceendedat)
19+
* [DragSourceSystemDragEnded](#dragsourcesystemdragended)
1420
* [ExecuteFunction](#executefunction)
1521
* [ExecuteJavascript](#executejavascript)
1622
* [Find](#find)
@@ -131,6 +137,116 @@ information.
131137
Explicitly close the associated DevTools browser, if any.
132138

133139

140+
### DragTargetDragEnter
141+
142+
| | |
143+
| --- | --- |
144+
| drag_data | [DragData](DragData.md) |
145+
| x | int |
146+
| y | int |
147+
| allowed_ops | int |
148+
| __Return__ | void |
149+
150+
Description from upstream CEF:
151+
> Call this method when the user drags the mouse into the web view (before
152+
> calling DragTargetDragOver/DragTargetLeave/DragTargetDrop).
153+
> |drag_data| should not contain file contents as this type of data is not
154+
> allowed to be dragged into the web view. File contents can be removed using
155+
> CefDragData::ResetFileContents (for example, if |drag_data| comes from
156+
> CefRenderHandler::StartDragging).
157+
> This method is only used when window rendering is disabled.
158+
159+
160+
### DragTargetDragOver
161+
162+
| | |
163+
| --- | --- |
164+
| x | int |
165+
| y | int |
166+
| allowed_ops | int |
167+
| __Return__ | void |
168+
169+
Description from upstream CEF:
170+
> Call this method each time the mouse is moved across the web view during
171+
> a drag operation (after calling DragTargetDragEnter and before calling
172+
> DragTargetDragLeave/DragTargetDrop).
173+
> This method is only used when window rendering is disabled.
174+
175+
176+
### DragTargetDragLeave
177+
178+
| | |
179+
| --- | --- |
180+
| __Return__ | void |
181+
182+
Description from upstream CEF:
183+
> Call this method when the user drags the mouse out of the web view (after
184+
> calling DragTargetDragEnter).
185+
> This method is only used when window rendering is disabled.
186+
187+
188+
### DragTargetDrop
189+
190+
| | |
191+
| --- | --- |
192+
| x | int |
193+
| y | int |
194+
| __Return__ | void |
195+
196+
Description from upstream CEF:
197+
> Call this method when the user completes the drag operation by dropping
198+
> the object onto the web view (after calling DragTargetDragEnter).
199+
> The object being dropped is |drag_data|, given as an argument to
200+
> the previous DragTargetDragEnter call.
201+
> This method is only used when window rendering is disabled.
202+
203+
204+
### DragSourceEndedAt
205+
206+
| | |
207+
| --- | --- |
208+
| x | int |
209+
| y | int |
210+
| operation | int |
211+
| __Return__ | void |
212+
213+
Description from upstream CEF:
214+
> Call this method when the drag operation started by a
215+
> CefRenderHandler::StartDragging call has ended either in a drop or
216+
> by being cancelled. |x| and |y| are mouse coordinates relative to the
217+
> upper-left corner of the view. If the web view is both the drag source
218+
> and the drag target then all DragTarget* methods should be called before
219+
> DragSource* mthods.
220+
> This method is only used when window rendering is disabled.
221+
222+
Operation enum from upstream CEF - these constants are declared in the
223+
`cefpython` module:
224+
> DRAG_OPERATION_NONE = 0,
225+
> DRAG_OPERATION_COPY = 1,
226+
> DRAG_OPERATION_LINK = 2,
227+
> DRAG_OPERATION_GENERIC = 4,
228+
> DRAG_OPERATION_PRIVATE = 8,
229+
> DRAG_OPERATION_MOVE = 16,
230+
> DRAG_OPERATION_DELETE = 32,
231+
> DRAG_OPERATION_EVERY = UINT_MAX
232+
233+
234+
### DragSourceSystemDragEnded
235+
236+
| | |
237+
| --- | --- |
238+
| __Return__ | void |
239+
240+
Description from upstream CEF:
241+
> Call this method when the drag operation started by a
242+
> CefRenderHandler::StartDragging call has completed. This method may be
243+
> called immediately without first calling DragSourceEndedAt to cancel a
244+
> drag operation. If the web view is both the drag source and the drag
245+
> target then all DragTarget* methods should be called before DragSource*
246+
> mthods.
247+
> This method is only used when window rendering is disabled.
248+
249+
134250
### ExecuteFunction
135251

136252
| Parameter | Type |

api/DragData.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[API categories](API-categories.md) | [API index](API-index.md)
2+
3+
# DragData (object)
4+
5+
6+
Table of contents:
7+
* [Methods](#methods)
8+
* [IsLink](#islink)
9+
* [IsFragment](#isfragment)
10+
* [GetLinkUrl](#getlinkurl)
11+
* [GetLinkTitle](#getlinktitle)
12+
* [GetFragmentText](#getfragmenttext)
13+
* [GetFragmentHtml](#getfragmenthtml)
14+
15+
16+
## Methods
17+
18+
19+
### IsLink
20+
21+
| | |
22+
| --- | --- |
23+
| __Return__ | bool |
24+
25+
Returns true if the drag data is a link.
26+
27+
28+
### IsFragment
29+
30+
| | |
31+
| --- | --- |
32+
| __Return__ | bool |
33+
34+
Returns true if the drag data is a text or html fragment.
35+
36+
37+
### GetLinkUrl
38+
39+
| | |
40+
| --- | --- |
41+
| __Return__ | string |
42+
43+
44+
Return the link URL that is being dragged.
45+
46+
47+
### GetLinkTitle
48+
49+
| | |
50+
| --- | --- |
51+
| __Return__ | string |
52+
53+
Return the title associated with the link being dragged.
54+
55+
56+
### GetFragmentText
57+
58+
| | |
59+
| --- | --- |
60+
| __Return__ | string |
61+
62+
Return the plain text fragment that is being dragged.
63+
64+
65+
### GetFragmentHtml
66+
67+
| | |
68+
| --- | --- |
69+
| __Return__ | string |
70+
71+
Return the text/html fragment that is being dragged.
72+

api/RenderHandler.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Table of contents:
3131
* [OnPaint](#onpaint)
3232
* [OnCursorChange](#oncursorchange)
3333
* [OnScrollOffsetChanged](#onscrolloffsetchanged)
34+
* [StartDragging](#startdragging)
35+
* [UpdateDragCursor](#updatedragcursor)
3436

3537

3638
## Callbacks
@@ -162,3 +164,48 @@ Called when the browser's cursor has changed. If |type| is CT_CUSTOM then
162164
| __Return__ | void |
163165

164166
Called when the scroll offset has changed.
167+
168+
169+
### StartDragging
170+
171+
| Parameter | Type |
172+
| --- | --- |
173+
| browser | [Browser](Browser.md) |
174+
| drag_data | [DragData](DragData.md) |
175+
| allowed_ops | int |
176+
| x | int |
177+
| y | int |
178+
| __Return__ | void |
179+
180+
Description from upstream CEF:
181+
> Called when the user starts dragging content in the web view. Contextual
182+
> information about the dragged content is supplied by |drag_data|.
183+
> (|x|, |y|) is the drag start location in screen coordinates.
184+
> OS APIs that run a system message loop may be used within the
185+
> StartDragging call.
186+
>
187+
> Return false to abort the drag operation. Don't call any of
188+
> CefBrowserHost::DragSource*Ended* methods after returning false.
189+
>
190+
> Return true to handle the drag operation. Call
191+
> CefBrowserHost::DragSourceEndedAt and DragSourceSystemDragEnded either
192+
> synchronously or asynchronously to inform the web view that the drag
193+
> operation has ended.
194+
195+
196+
### UpdateDragCursor
197+
198+
| Parameter | Type |
199+
| --- | --- |
200+
| browser | [Browser](Browser.md) |
201+
| operation | int |
202+
| __Return__ | void |
203+
204+
Description from upstream CEF:
205+
> Called when the web view wants to update the mouse cursor during a
206+
> drag & drop operation. |operation| describes the allowed operation
207+
> (none, move, copy, link).
208+
209+
See Browser.[DragSourceEndedAt](Browser.md#dragsourceendedat) for a list
210+
of values for the operation enum.
211+

src/browser.pyx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ cdef class PyBrowser:
196196
# RenderHandler
197197
self.allowedClientCallbacks += ["GetRootScreenRect",
198198
"GetViewRect", "GetScreenPoint", "GetScreenInfo",
199+
"GetScreenRect",
199200
"OnPopupShow", "OnPopupSize", "OnPaint", "OnCursorChange",
200-
"OnScrollOffsetChanged"]
201+
"OnScrollOffsetChanged",
202+
"StartDragging", "UpdateDragCursor"]
201203
# JavascriptDialogHandler
202204
self.allowedClientCallbacks += ["OnJavascriptDialog",
203205
"OnBeforeUnloadJavascriptDialog",
@@ -614,3 +616,40 @@ cdef class PyBrowser:
614616
if not success:
615617
raise Exception("Browser.SendProcessMessage() failed: "\
616618
"messageName=%s" % messageName)
619+
620+
# -------------------------------------------------------------------------
621+
# OSR drag & drop
622+
# -------------------------------------------------------------------------
623+
624+
cpdef py_void DragTargetDragEnter(self, DragData drag_data, int x, int y,
625+
long long allowed_ops):
626+
cdef CefMouseEvent mouse_event
627+
mouse_event.x = x
628+
mouse_event.y = y
629+
self.GetCefBrowserHost().get().DragTargetDragEnter(
630+
drag_data.cef_drag_data, mouse_event,
631+
<cef_types.cef_drag_operations_mask_t>allowed_ops)
632+
633+
cpdef py_void DragTargetDragOver(self, int x, int y, long long allowed_ops):
634+
cdef CefMouseEvent mouse_event
635+
mouse_event.x = x
636+
mouse_event.y = y
637+
self.GetCefBrowserHost().get().DragTargetDragOver(
638+
mouse_event, <cef_types.cef_drag_operations_mask_t>allowed_ops)
639+
640+
cpdef py_void DragTargetDragLeave(self):
641+
self.GetCefBrowserHost().get().DragTargetDragLeave()
642+
643+
cpdef py_void DragTargetDrop(self, int x, int y):
644+
cdef CefMouseEvent mouse_event
645+
mouse_event.x = x
646+
mouse_event.y = y
647+
self.GetCefBrowserHost().get().DragTargetDrop(mouse_event)
648+
649+
cpdef py_void DragSourceEndedAt(self, int x, int y, long long operation):
650+
self.GetCefBrowserHost().get().DragSourceEndedAt(
651+
x, y, <cef_types.cef_drag_operations_mask_t>operation)
652+
653+
cpdef py_void DragSourceSystemDragEnded(self):
654+
self.GetCefBrowserHost().get().DragSourceSystemDragEnded()
655+

src/cefpython.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ from cef_types cimport (
387387
CefSettings, CefBrowserSettings, CefRect, CefPoint,
388388
CefRequestContextSettings,
389389
CefKeyEvent, CefMouseEvent, CefScreenInfo,
390-
PathKey, PK_DIR_EXE, PK_DIR_MODULE
390+
PathKey, PK_DIR_EXE, PK_DIR_MODULE,
391391
)
392392

393393
from cef_task cimport *
@@ -425,6 +425,7 @@ from cef_request_context_handler cimport *
425425
from request_context_handler cimport *
426426
from cef_jsdialog_handler cimport *
427427
from cef_path_util cimport *
428+
from cef_drag_data cimport *
428429

429430

430431
# -----------------------------------------------------------------------------
@@ -502,6 +503,7 @@ include "web_request.pyx"
502503
include "command_line.pyx"
503504
include "app.pyx"
504505
include "javascript_dialog_handler.pyx"
506+
include "drag_data.pyx"
505507

506508
# -----------------------------------------------------------------------------
507509
# Utility functions to provide settings to the C++ browser process code.

src/client_handler/client_handler.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,21 @@ void ClientHandler::OnScrollOffsetChanged(CefRefPtr<CefBrowser> browser,
456456
RenderHandler_OnScrollOffsetChanged(browser);
457457
}
458458

459+
bool ClientHandler::StartDragging(CefRefPtr<CefBrowser> browser,
460+
CefRefPtr<CefDragData> drag_data,
461+
DragOperationsMask allowed_ops,
462+
int x, int y) {
463+
REQUIRE_UI_THREAD();
464+
return RenderHandler_StartDragging(browser, drag_data,
465+
static_cast<long>(allowed_ops), x, y);
466+
}
467+
468+
void ClientHandler::UpdateDragCursor(CefRefPtr<CefBrowser> browser,
469+
DragOperation operation) {
470+
REQUIRE_UI_THREAD();
471+
RenderHandler_UpdateDragCursor(browser, static_cast<long>(operation));
472+
}
473+
459474

460475
// ----------------------------------------------------------------------------
461476
// CefJSDialogHandler

src/client_handler/client_handler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// needs to be forward declared otherwise compile error
1616
typedef cef_return_value_t ReturnValue;
17+
typedef cef_drag_operations_mask_t DragOperationsMask;
18+
typedef cef_drag_operations_mask_t DragOperation;
1719

1820
class ClientHandler :
1921
public CefClient,
@@ -273,6 +275,14 @@ class ClientHandler :
273275
double x,
274276
double y) OVERRIDE;
275277

278+
virtual bool StartDragging(CefRefPtr<CefBrowser> browser,
279+
CefRefPtr<CefDragData> drag_data,
280+
cef_drag_operations_mask_t allowed_ops,
281+
int x, int y) OVERRIDE;
282+
283+
virtual void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
284+
cef_drag_operations_mask_t operation) OVERRIDE;
285+
276286
// --------------------------------------------------------------------------
277287
// CefJSDialogHandler
278288
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)