mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-03 04:27:43 +01:00
Add support for intercepting key events (Issue #63, patch by cpinfold.joinerysoft)
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@70 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
bd0c16ae31
commit
606b342147
@ -619,6 +619,24 @@ public:
|
||||
/*--cef()--*/
|
||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
|
||||
bool isWidget) =0;
|
||||
|
||||
// Supported keyboard event types.
|
||||
typedef cef_handler_keyevent_type_t KeyEventType;
|
||||
|
||||
// Called when the browser component receives a keyboard event.
|
||||
// |type| is the type of keyboard event (see |KeyEventType|).
|
||||
// |code| is the windows scan-code for the event.
|
||||
// |modifiers| is a set of bit-flags describing any pressed modifier keys.
|
||||
// |isSystemKey| is set if Windows considers this a 'system key' message;
|
||||
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx)
|
||||
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE
|
||||
// to allow the browser component to handle the event.
|
||||
/*--cef()--*/
|
||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type,
|
||||
int code,
|
||||
int modifiers,
|
||||
bool isSystemKey) =0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -482,6 +482,19 @@ typedef struct _cef_handler_t
|
||||
struct _cef_handler_t* self, struct _cef_browser_t* browser,
|
||||
int isWidget);
|
||||
|
||||
// Called when the browser component receives a keyboard event. |type| is the
|
||||
// type of keyboard event (see |KeyEventType|). |code| is the windows scan-
|
||||
// code for the event. |modifiers| is a set of bit-flags describing any
|
||||
// pressed modifier keys. |isSystemKey| is set if Windows considers this a
|
||||
// 'system key' message;
|
||||
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx)
|
||||
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE to allow
|
||||
// the browser component to handle the event.
|
||||
enum cef_retval_t (CEF_CALLBACK *handle_key_event)(
|
||||
struct _cef_handler_t* self, struct _cef_browser_t* browser,
|
||||
enum cef_handler_keyevent_type_t type, int code, int modifiers,
|
||||
int isSystemKey);
|
||||
|
||||
} cef_handler_t;
|
||||
|
||||
|
||||
|
@ -202,6 +202,23 @@ enum cef_postdataelement_type_t
|
||||
PDE_TYPE_FILE,
|
||||
};
|
||||
|
||||
// Key event types.
|
||||
enum cef_handler_keyevent_type_t
|
||||
{
|
||||
KEYEVENT_RAWKEYDOWN = 0,
|
||||
KEYEVENT_KEYDOWN,
|
||||
KEYEVENT_KEYUP,
|
||||
KEYEVENT_CHAR
|
||||
};
|
||||
|
||||
// Key event modifiers.
|
||||
enum cef_handler_keyevent_modifiers_t
|
||||
{
|
||||
KEY_SHIFT = 1 << 0,
|
||||
KEY_CTRL = 1 << 1,
|
||||
KEY_ALT = 1 << 2,
|
||||
KEY_META = 1 << 3
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ using WebKit::WebView;
|
||||
using WebKit::WebWidget;
|
||||
using WebKit::WebWorker;
|
||||
using WebKit::WebWorkerClient;
|
||||
using WebKit::WebKeyboardEvent;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -223,6 +224,35 @@ bool BrowserWebViewDelegate::isSelectTrailingWhitespaceEnabled() {
|
||||
}
|
||||
|
||||
bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() {
|
||||
CefHandler::RetVal rv = RV_CONTINUE;
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if (handler.get()) {
|
||||
WebWidgetHost* host = GetWidgetHost();
|
||||
if (host) {
|
||||
WebKeyboardEvent event = host->GetLastKeyEvent();
|
||||
switch (event.type)
|
||||
{
|
||||
case WebKeyboardEvent::RawKeyDown:
|
||||
rv = handler->HandleKeyEvent(browser_,
|
||||
KEYEVENT_RAWKEYDOWN, event.windowsKeyCode,
|
||||
event.modifiers, event.isSystemKey?true:false);
|
||||
break;
|
||||
case WebKeyboardEvent::KeyUp:
|
||||
rv = handler->HandleKeyEvent(browser_,
|
||||
KEYEVENT_KEYUP, event.windowsKeyCode,
|
||||
event.modifiers, event.isSystemKey?true:false);
|
||||
break;
|
||||
case WebKeyboardEvent::Char:
|
||||
rv = handler->HandleKeyEvent(browser_,
|
||||
KEYEVENT_CHAR, event.windowsKeyCode,
|
||||
event.modifiers, event.isSystemKey?true:false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rv == RV_HANDLED)
|
||||
return true;
|
||||
|
||||
if (edit_command_name_.empty())
|
||||
return false;
|
||||
|
||||
|
@ -318,6 +318,7 @@ void WebWidgetHost::WheelEvent(WPARAM wparam, LPARAM lparam) {
|
||||
void WebWidgetHost::KeyEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
const WebKeyboardEvent& event = WebInputEventFactory::keyboardEvent(
|
||||
view_, message, wparam, lparam);
|
||||
last_key_event_ = event;
|
||||
webwidget_->handleInputEvent(event);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "base/gfx/rect.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "skia/ext/platform_canvas.h"
|
||||
#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
|
||||
|
||||
namespace gfx {
|
||||
class Size;
|
||||
@ -18,6 +19,7 @@ class Size;
|
||||
namespace WebKit {
|
||||
class WebWidget;
|
||||
class WebWidgetClient;
|
||||
class WebKeyboardEvent;
|
||||
struct WebScreenInfo;
|
||||
}
|
||||
|
||||
@ -53,6 +55,8 @@ class WebWidgetHost {
|
||||
|
||||
WebKit::WebScreenInfo GetScreenInfo();
|
||||
|
||||
WebKit::WebKeyboardEvent GetLastKeyEvent() const { return last_key_event_; }
|
||||
|
||||
void PaintRect(const gfx::Rect& rect);
|
||||
|
||||
protected:
|
||||
@ -119,6 +123,8 @@ class WebWidgetHost {
|
||||
|
||||
bool track_mouse_leave_;
|
||||
|
||||
WebKit::WebKeyboardEvent last_key_event_;
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool painting_;
|
||||
#endif
|
||||
|
@ -459,6 +459,21 @@ enum cef_retval_t CEF_CALLBACK handler_handle_set_focus(
|
||||
CefBrowserCToCpp::Wrap(browser), isWidget?true:false);
|
||||
}
|
||||
|
||||
enum cef_retval_t CEF_CALLBACK handler_handle_key_event(
|
||||
struct _cef_handler_t* self, cef_browser_t* browser,
|
||||
enum cef_handler_keyevent_type_t type, int code, int modifiers,
|
||||
int isSystemKey)
|
||||
{
|
||||
DCHECK(self);
|
||||
DCHECK(browser);
|
||||
if(!self || !browser)
|
||||
return RV_CONTINUE;
|
||||
|
||||
return CefHandlerCppToC::Get(self)->HandleKeyEvent(
|
||||
CefBrowserCToCpp::Wrap(browser), type, code,
|
||||
modifiers, isSystemKey?true:false);
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
@ -488,6 +503,7 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
|
||||
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
||||
struct_.struct_.handle_jsbinding = handler_handle_jsbinding;
|
||||
struct_.struct_.handle_set_focus = handler_handle_set_focus;
|
||||
struct_.struct_.handle_key_event = handler_handle_key_event;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -349,6 +349,17 @@ CefHandler::RetVal CefHandlerCToCpp::HandleSetFocus(
|
||||
isWidget);
|
||||
}
|
||||
|
||||
CefHandler::RetVal CefHandlerCToCpp::HandleKeyEvent(
|
||||
CefRefPtr<CefBrowser> browser, KeyEventType type, int code, int modifiers,
|
||||
bool isSystemKey)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, handle_key_event))
|
||||
return RV_CONTINUE;
|
||||
|
||||
return struct_->handle_key_event(struct_, CefBrowserCppToC::Wrap(browser),
|
||||
type, code, modifiers, isSystemKey);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Value> object);
|
||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, bool isWidget);
|
||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type, int code, int modifiers, bool isSystemKey);
|
||||
};
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
|
@ -520,6 +520,23 @@ public:
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called when the browser component receives a keyboard event.
|
||||
// |type| is the type of keyboard event (see |KeyEventType|).
|
||||
// |code| is the windows scan-code for the event.
|
||||
// |modifiers| is a set of bit-flags describing any pressed modifier keys.
|
||||
// |isSystemKey| is set if Windows considers this a 'system key' message;
|
||||
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx)
|
||||
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE
|
||||
// to allow the browser component to handle the event.
|
||||
RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type,
|
||||
int code,
|
||||
int modifiers,
|
||||
bool isSystemKey)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Retrieve the current navigation state flags
|
||||
void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward)
|
||||
{
|
||||
|
@ -202,6 +202,13 @@ public:
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type, int code,
|
||||
int modifiers, bool isSystemKey)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> GetBrowser()
|
||||
{
|
||||
return browser_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user