Skip to content

Commit ba2f430

Browse files
committed
Added GetIdentifier() method to the Browser object.
Added new methods to the RenderHandler: GetViewRect(), GetScreenRect(), GetScreenPoint(), OnPopupShow(), OnPopupSize(), OnCursorChange(). Added new methods to the Browser object: SendKeyEvent(), SendMouseClickEvent(), SendMouseMoveEvent(), SendMouseWheelEvent(), SendFocusEvent(), SendCaptureLostEvent().
1 parent 1843a0a commit ba2f430

15 files changed

Lines changed: 228 additions & 37 deletions

File tree

cefpython/browser.pyx

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# License: New BSD License.
33
# Website: http://code.google.com/p/cefpython/
44

5+
# cef_key_type_t, SendKeyEvent().
6+
KEYTYPE_KEYUP = cef_types.KT_KEYUP
7+
KEYTYPE_KEYDOWN = cef_types.KT_KEYDOWN
8+
KEYTYPE_CHAR = cef_types.KT_CHAR
9+
10+
# cef_mouse_button_type_t, SendMouseClickEvent().
11+
MOUSEBUTTON_LEFT = cef_types.MBT_LEFT
12+
MOUSEBUTTON_MIDDLE = cef_types.MBT_MIDDLE
13+
MOUSEBUTTON_RIGHT = cef_types.MBT_RIGHT
14+
515
# If you try to keep PyBrowser() objects inside cpp_vector you will
616
# get segmentation faults, as they will be garbage collected.
717

@@ -272,6 +282,9 @@ cdef class PyBrowser:
272282
preinc(iterator)
273283
return names
274284

285+
cpdef int GetIdentifier(self) except *:
286+
return self.GetCefBrowser().get().GetIdentifier()
287+
275288
cpdef PyFrame GetMainFrame(self):
276289
return GetPyFrame(self.GetCefBrowser().get().GetMainFrame())
277290

@@ -512,20 +525,44 @@ cdef class PyBrowser:
512525

513526
IF CEF_VERSION == 1:
514527

515-
cpdef py_void SendKeyEvent(self):
516-
pass
528+
cpdef py_void SendKeyEvent(self, cef_types.cef_key_type_t keyType,
529+
tuple keyInfo, int modifiers):
530+
cdef CefKeyInfo cefKeyInfo
531+
IF UNAME_SYSNAME == "Windows":
532+
assert len(keyInfo) == 3, "Invalid keyInfo param"
533+
cefKeyInfo.key = keyInfo[0]
534+
cefKeyInfo.sysChar = keyInfo[1]
535+
cefKeyInfo.imeChar = keyInfo[2]
536+
ELIF UNAME_SYSNAME == "Darwin":
537+
cefKeyInfo.keyCode = keyInfo[0]
538+
cefKeyInfo.character = keyInfo[1]
539+
cefKeyInfo.characterNoModifiers = keyInfo[2]
540+
ELIF UNAME_SYSNAME == "Linux":
541+
cefKeyInfo.key = keyInfo[0]
542+
ELSE:
543+
raise Exception("Invalid UNAME_SYSNAME")
544+
545+
self.GetCefBrowser().get().SendKeyEvent(keyType, cefKeyInfo,
546+
modifiers)
517547

518-
cpdef py_void SendMouseClickEvent(self):
519-
pass
548+
cpdef py_void SendMouseClickEvent(self, int x, int y,
549+
cef_types.cef_mouse_button_type_t mouseButtonType,
550+
py_bool mouseUp, int clickCount):
551+
self.GetCefBrowser().get().SendMouseClickEvent(x, y,
552+
mouseButtonType, bool(mouseUp), clickCount)
520553

521-
cpdef py_void SendMouseMoveEvent(self):
522-
pass
554+
cpdef py_void SendMouseMoveEvent(self, int x, int y,
555+
py_bool mouseLeave):
556+
self.GetCefBrowser().get().SendMouseMoveEvent(x, y,
557+
bool(mouseLeave))
523558

524-
cpdef py_void SendMouseWheelEvent(self):
525-
pass
559+
cpdef py_void SendMouseWheelEvent(self, int x, int y,
560+
int deltaX, int deltaY):
561+
self.GetCefBrowser().get().SendMouseWheelEvent(x, y,
562+
deltaX, deltaY)
526563

527-
cpdef py_void SendFocusEvent(self):
528-
pass
564+
cpdef py_void SendFocusEvent(self, py_bool setFocus):
565+
self.GetCefBrowser().get().SendFocusEvent(bool(setFocus))
529566

530567
cpdef py_void SendCaptureLostEvent(self):
531-
pass
568+
self.GetCefBrowser().get().SendCaptureLostEvent()

cefpython/cef1/windows/binaries/panda3d_.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#
1515
# This will enable your copy of python to find the panda libraries.
1616

17+
# TODO: implement forwarding key/mouse events to the CEF browser.
18+
# Browser object has following methods: SendKeyEvent(),
19+
# SendMouseClickEvent(), SendMouseMoveEvent(),
20+
# SendMouseWheelEvent(), SendFocusEvent(),
21+
# SendCaptureLostEvent().
22+
1723
import platform
1824
if platform.architecture()[0] != "32bit":
1925
raise Exception("Unsupported architecture: %s" % (

cefpython/cef1/windows/setup/cefpython.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ __PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetScreenPoint(CefRefPtr<CefBrowser
4141
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPopupShow(CefRefPtr<CefBrowser>, bool);
4242
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPopupSize(CefRefPtr<CefBrowser>, CefRect &);
4343
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPaint(CefRefPtr<CefBrowser>, cef_paint_element_type_t, std::vector<CefRect> &, void *);
44-
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_OnCursorChange(CefRefPtr<CefBrowser>, CefCursorHandle);
44+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnCursorChange(CefRefPtr<CefBrowser>, CefCursorHandle);
4545
__PYX_EXTERN_C DL_IMPORT(void) V8ContextHandler_OnContextCreated(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context>);
4646
__PYX_EXTERN_C DL_IMPORT(void) V8ContextHandler_OnContextReleased(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context>);
4747
__PYX_EXTERN_C DL_IMPORT(void) V8ContextHandler_OnUncaughtException(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context>, CefRefPtr<CefV8Exception>, CefRefPtr<CefV8StackTrace>);

cefpython/cpp_utils/PaintBuffer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ void SwapBufferFromBgraToRgba(void* _dest, void* _src, int width, int height) {
2929
int length = width*height;
3030
for (int i = 0; i < length; i++) {
3131
bgra = src[i];
32-
rgba = (bgra & 0x00ff0000) >> 16
33-
| (bgra & 0xff00ff00)
34-
| (bgra & 0x000000ff) << 16;
32+
// BGRA in hex = 0xAARRGGBB.
33+
rgba = (bgra & 0x00ff0000) >> 16 // Red >> Blue.
34+
| (bgra & 0xff00ff00) // Green Alpha.
35+
| (bgra & 0x000000ff) << 16; // Blue >> Red.
3536
dest[i] = rgba;
3637
}
3738
}

cefpython/cython_includes/cef_browser.pxd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ from cef_client cimport CefClient
1111
from libcpp cimport bool as cpp_bool
1212
from libcpp.vector cimport vector as cpp_vector
1313
from cef_frame cimport CefFrame
14-
from cef_types cimport cef_paint_element_type_t
14+
cimport cef_types
1515
from cef_types_wrappers cimport CefRect
16+
from cef_platform cimport CefKeyInfo
1617

1718
IF UNAME_SYSNAME == "Windows":
1819
from cef_win cimport CefWindowHandle, CefWindowInfo
@@ -54,15 +55,28 @@ cdef extern from "include/cef_browser.h":
5455
cpp_bool IsPopupVisible()
5556
int GetIdentifier()
5657

57-
# off-screen rendering.
58-
cpp_bool GetSize(cef_paint_element_type_t type,
58+
# Off-screen rendering.
59+
60+
cpp_bool GetSize(cef_types.cef_paint_element_type_t type,
5961
int& width, int& height)
60-
void SetSize(cef_paint_element_type_t type,
62+
void SetSize(cef_types.cef_paint_element_type_t type,
6163
int width, int height)
6264
void Invalidate(CefRect& dirtyRect)
63-
cpp_bool GetImage(cef_paint_element_type_t type,
65+
cpp_bool GetImage(cef_types.cef_paint_element_type_t type,
6466
int width, int height, void* buffer)
6567

68+
# Sending mouse/key events.
69+
70+
void SendKeyEvent(cef_types.cef_key_type_t type,
71+
CefKeyInfo& keyInfo, int modifiers)
72+
void SendMouseClickEvent(int x, int y,
73+
cef_types.cef_mouse_button_type_t type,
74+
cpp_bool mouseUp, int clickCount)
75+
void SendMouseMoveEvent(int x, int y, cpp_bool mouseLeave)
76+
void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY)
77+
void SendFocusEvent(cpp_bool setFocus)
78+
void SendCaptureLostEvent()
79+
6680
# virtual CefRefPtr<CefClient> GetClient() =0;
6781

6882
ELIF CEF_VERSION == 3:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
from cef_types_linux cimport _cef_key_info_t
6+
7+
cdef extern from "include/internal/cef_linux.h":
8+
9+
ctypedef _cef_key_info_t CefKeyInfo
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
from cef_types_mac cimport _cef_key_info_t
6+
7+
cdef extern from "include/internal/cef_mac.h":
8+
9+
ctypedef _cef_key_info_t CefKeyInfo
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
IF UNAME_SYSNAME == "Windows":
6+
from cef_win cimport *
7+
ELIF UNAME_SYSNAME == "Darwin":
8+
from cef_mac cimport *
9+
ELIF UNAME_SYSNAME == "Linux":
10+
from cef_linux cimport *

cefpython/cython_includes/cef_types.pxd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,21 @@ cdef extern from "include/internal/cef_types.h":
151151
PID_RENDERER,
152152

153153
IF CEF_VERSION == 1:
154+
155+
# Browser > GetImage(), RenderHandler > OnPaint().
154156
ctypedef enum cef_paint_element_type_t:
155157
PET_VIEW = 0,
156158
PET_POPUP,
157159

160+
# Browser > SendKeyEvent().
161+
ctypedef enum cef_key_type_t:
162+
KT_KEYUP = 0,
163+
KT_KEYDOWN,
164+
KT_CHAR,
165+
166+
# Browser > SendMouseClickEvent().
167+
ctypedef enum cef_mouse_button_type_t:
168+
MBT_LEFT = 0,
169+
MBT_MIDDLE,
170+
MBT_RIGHT,
171+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
cdef extern from "include/internal/cef_types_win.h":
6+
7+
ctypedef struct _cef_key_info_t:
8+
int key

0 commit comments

Comments
 (0)