From d8caf27e3b86da51577ff676245b364cc2c48839 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 11 Jun 2012 15:52:49 +0000 Subject: [PATCH] - Add keyboard and focus notifications (issue #508). - Add CefDOMNode::IsEditable method. - List interfaces alphabetically in CefClient. - Correct error checking for code and command input. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@680 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef_paths.gypi | 12 + cef_paths2.gypi | 4 + include/capi/cef_client_capi.h | 66 +++-- include/capi/cef_dom_capi.h | 5 + include/capi/cef_focus_handler_capi.h | 87 +++++++ include/capi/cef_keyboard_handler_capi.h | 83 ++++++ .../capi/cef_render_process_handler_capi.h | 13 + include/cef_client.h | 88 ++++--- include/cef_dom.h | 6 + include/cef_focus_handler.h | 81 ++++++ include/cef_keyboard_handler.h | 74 ++++++ include/cef_render_process_handler.h | 14 + include/internal/cef_linux.h | 3 +- include/internal/cef_mac.h | 9 +- include/internal/cef_types.h | 97 +++++++ include/internal/cef_types_linux.h | 5 +- include/internal/cef_types_mac.h | 11 +- include/internal/cef_types_win.h | 5 +- include/internal/cef_types_wrappers.h | 25 ++ include/internal/cef_win.h | 3 +- libcef/browser/browser_host_impl.cc | 150 ++++++++++- libcef/browser/browser_host_impl.h | 14 + libcef/browser/browser_host_impl_mac.mm | 11 + libcef/browser/browser_host_impl_win.cc | 7 +- libcef/browser/frame_host_impl.cc | 5 + libcef/renderer/browser_impl.cc | 27 +- libcef/renderer/browser_impl.h | 2 +- libcef/renderer/dom_node_impl.cc | 26 ++ libcef/renderer/dom_node_impl.h | 1 + libcef/renderer/frame_impl.cc | 5 + libcef_dll/cpptoc/client_cpptoc.cc | 172 ++++++++----- libcef_dll/cpptoc/domnode_cpptoc.cc | 15 ++ libcef_dll/cpptoc/focus_handler_cpptoc.cc | 90 +++++++ libcef_dll/cpptoc/focus_handler_cpptoc.h | 37 +++ libcef_dll/cpptoc/keyboard_handler_cpptoc.cc | 110 ++++++++ libcef_dll/cpptoc/keyboard_handler_cpptoc.h | 37 +++ .../cpptoc/render_process_handler_cpptoc.cc | 24 ++ libcef_dll/ctocpp/client_ctocpp.cc | 136 ++++++---- libcef_dll/ctocpp/client_ctocpp.h | 10 +- libcef_dll/ctocpp/domnode_ctocpp.cc | 13 + libcef_dll/ctocpp/domnode_ctocpp.h | 1 + libcef_dll/ctocpp/focus_handler_ctocpp.cc | 79 ++++++ libcef_dll/ctocpp/focus_handler_ctocpp.h | 45 ++++ libcef_dll/ctocpp/keyboard_handler_ctocpp.cc | 81 ++++++ libcef_dll/ctocpp/keyboard_handler_ctocpp.h | 46 ++++ .../ctocpp/render_process_handler_ctocpp.cc | 22 ++ .../ctocpp/render_process_handler_ctocpp.h | 2 + libcef_dll/libcef_dll.cc | 4 + libcef_dll/wrapper/libcef_dll_wrapper.cc | 4 + tests/cefclient/client_app.cpp | 9 + tests/cefclient/client_app.h | 10 + tests/cefclient/client_app_delegates.cpp | 2 + tests/cefclient/client_handler.cpp | 239 ++++++++++-------- tests/cefclient/client_handler.h | 110 ++++---- tests/cefclient/client_handler_gtk.cpp | 12 - tests/cefclient/client_handler_mac.mm | 13 - tests/cefclient/client_handler_win.cpp | 11 - tests/cefclient/client_renderer.cpp | 52 ++++ tests/cefclient/client_renderer.h | 22 ++ tools/cef_parser.py | 1 + 60 files changed, 1940 insertions(+), 408 deletions(-) create mode 100644 include/capi/cef_focus_handler_capi.h create mode 100644 include/capi/cef_keyboard_handler_capi.h create mode 100644 include/cef_focus_handler.h create mode 100644 include/cef_keyboard_handler.h create mode 100644 libcef_dll/cpptoc/focus_handler_cpptoc.cc create mode 100644 libcef_dll/cpptoc/focus_handler_cpptoc.h create mode 100644 libcef_dll/cpptoc/keyboard_handler_cpptoc.cc create mode 100644 libcef_dll/cpptoc/keyboard_handler_cpptoc.h create mode 100644 libcef_dll/ctocpp/focus_handler_ctocpp.cc create mode 100644 libcef_dll/ctocpp/focus_handler_ctocpp.h create mode 100644 libcef_dll/ctocpp/keyboard_handler_ctocpp.cc create mode 100644 libcef_dll/ctocpp/keyboard_handler_ctocpp.h create mode 100644 tests/cefclient/client_renderer.cpp create mode 100644 tests/cefclient/client_renderer.h diff --git a/cef_paths.gypi b/cef_paths.gypi index 16db5184f..a23b47bde 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -21,9 +21,11 @@ 'include/cef_cookie.h', 'include/cef_display_handler.h', 'include/cef_dom.h', + 'include/cef_focus_handler.h', 'include/cef_frame.h', 'include/cef_geolocation_handler.h', 'include/cef_jsdialog_handler.h', + 'include/cef_keyboard_handler.h', 'include/cef_life_span_handler.h', 'include/cef_load_handler.h', 'include/cef_menu_model.h', @@ -57,9 +59,11 @@ 'include/capi/cef_cookie_capi.h', 'include/capi/cef_display_handler_capi.h', 'include/capi/cef_dom_capi.h', + 'include/capi/cef_focus_handler_capi.h', 'include/capi/cef_frame_capi.h', 'include/capi/cef_geolocation_handler_capi.h', 'include/capi/cef_jsdialog_handler_capi.h', + 'include/capi/cef_keyboard_handler_capi.h', 'include/capi/cef_life_span_handler_capi.h', 'include/capi/cef_load_handler_capi.h', 'include/capi/cef_menu_model_capi.h', @@ -122,6 +126,8 @@ 'libcef_dll/cpptoc/dictionary_value_cpptoc.h', 'libcef_dll/ctocpp/display_handler_ctocpp.cc', 'libcef_dll/ctocpp/display_handler_ctocpp.h', + 'libcef_dll/ctocpp/focus_handler_ctocpp.cc', + 'libcef_dll/ctocpp/focus_handler_ctocpp.h', 'libcef_dll/cpptoc/frame_cpptoc.cc', 'libcef_dll/cpptoc/frame_cpptoc.h', 'libcef_dll/cpptoc/geolocation_callback_cpptoc.cc', @@ -132,6 +138,8 @@ 'libcef_dll/cpptoc/jsdialog_callback_cpptoc.h', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.cc', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.h', + 'libcef_dll/ctocpp/keyboard_handler_ctocpp.cc', + 'libcef_dll/ctocpp/keyboard_handler_ctocpp.h', 'libcef_dll/ctocpp/life_span_handler_ctocpp.cc', 'libcef_dll/ctocpp/life_span_handler_ctocpp.h', 'libcef_dll/cpptoc/list_value_cpptoc.cc', @@ -234,6 +242,8 @@ 'libcef_dll/ctocpp/dictionary_value_ctocpp.h', 'libcef_dll/cpptoc/display_handler_cpptoc.cc', 'libcef_dll/cpptoc/display_handler_cpptoc.h', + 'libcef_dll/cpptoc/focus_handler_cpptoc.cc', + 'libcef_dll/cpptoc/focus_handler_cpptoc.h', 'libcef_dll/ctocpp/frame_ctocpp.cc', 'libcef_dll/ctocpp/frame_ctocpp.h', 'libcef_dll/ctocpp/geolocation_callback_ctocpp.cc', @@ -244,6 +254,8 @@ 'libcef_dll/ctocpp/jsdialog_callback_ctocpp.h', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.cc', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.h', + 'libcef_dll/cpptoc/keyboard_handler_cpptoc.cc', + 'libcef_dll/cpptoc/keyboard_handler_cpptoc.h', 'libcef_dll/cpptoc/life_span_handler_cpptoc.cc', 'libcef_dll/cpptoc/life_span_handler_cpptoc.h', 'libcef_dll/ctocpp/list_value_ctocpp.cc', diff --git a/cef_paths2.gypi b/cef_paths2.gypi index 6bde9ac58..a6fe2ba65 100644 --- a/cef_paths2.gypi +++ b/cef_paths2.gypi @@ -89,6 +89,8 @@ 'tests/cefclient/client_app_delegates.cpp', 'tests/cefclient/client_handler.cpp', 'tests/cefclient/client_handler.h', + 'tests/cefclient/client_renderer.cpp', + 'tests/cefclient/client_renderer.h', 'tests/cefclient/client_switches.cpp', 'tests/cefclient/client_switches.h', 'tests/cefclient/dom_test.cpp', @@ -130,6 +132,8 @@ 'tests/cefclient/client_handler.cpp', 'tests/cefclient/client_handler.h', 'tests/cefclient/client_handler_mac.mm', + 'tests/cefclient/client_renderer.cpp', + 'tests/cefclient/client_renderer.h', 'tests/cefclient/client_switches.cpp', 'tests/cefclient/client_switches.h', 'tests/cefclient/dom_test.cpp', diff --git a/include/capi/cef_client_capi.h b/include/capi/cef_client_capi.h index b38e63156..adccbeb7b 100644 --- a/include/capi/cef_client_capi.h +++ b/include/capi/cef_client_capi.h @@ -54,6 +54,45 @@ typedef struct _cef_client_t { /// cef_base_t base; + /// + // Return the handler for context menus. If no handler is provided the default + // implementation will be used. + /// + struct _cef_context_menu_handler_t* (CEF_CALLBACK *get_context_menu_handler)( + struct _cef_client_t* self); + + /// + // Return the handler for browser display state events. + /// + struct _cef_display_handler_t* (CEF_CALLBACK *get_display_handler)( + struct _cef_client_t* self); + + /// + // Return the handler for focus events. + /// + struct _cef_focus_handler_t* (CEF_CALLBACK *get_focus_handler)( + struct _cef_client_t* self); + + /// + // Return the handler for geolocation permissions requests. If no handler is + // provided geolocation access will be denied by default. + /// + struct _cef_geolocation_handler_t* (CEF_CALLBACK *get_geolocation_handler)( + struct _cef_client_t* self); + + /// + // Return the handler for JavaScript dialogs. If no handler is provided the + // default implementation will be used. + /// + struct _cef_jsdialog_handler_t* (CEF_CALLBACK *get_jsdialog_handler)( + struct _cef_client_t* self); + + /// + // Return the handler for keyboard events. + /// + struct _cef_keyboard_handler_t* (CEF_CALLBACK *get_keyboard_handler)( + struct _cef_client_t* self); + /// // Return the handler for browser life span events. /// @@ -72,33 +111,6 @@ typedef struct _cef_client_t { struct _cef_request_handler_t* (CEF_CALLBACK *get_request_handler)( struct _cef_client_t* self); - /// - // Return the handler for browser display state events. - /// - struct _cef_display_handler_t* (CEF_CALLBACK *get_display_handler)( - struct _cef_client_t* self); - - /// - // Return the handler for geolocation permissions requests. If no handler is - // provided geolocation access will be denied by default. - /// - struct _cef_geolocation_handler_t* (CEF_CALLBACK *get_geolocation_handler)( - struct _cef_client_t* self); - - /// - // Return the handler for JavaScript dialogs. If no handler is provided the - // default implementation will be used. - /// - struct _cef_jsdialog_handler_t* (CEF_CALLBACK *get_jsdialog_handler)( - struct _cef_client_t* self); - - /// - // Return the handler for context menus. If no handler is provided the default - // implementation will be used. - /// - struct _cef_context_menu_handler_t* (CEF_CALLBACK *get_context_menu_handler)( - struct _cef_client_t* self); - /// // Called when a new message is received from a different process. Return true // (1) if the message was handled or false (0) otherwise. Do not keep a diff --git a/include/capi/cef_dom_capi.h b/include/capi/cef_dom_capi.h index 0f678ffed..8b5b752ec 100644 --- a/include/capi/cef_dom_capi.h +++ b/include/capi/cef_dom_capi.h @@ -205,6 +205,11 @@ typedef struct _cef_domnode_t { /// int (CEF_CALLBACK *is_element)(struct _cef_domnode_t* self); + /// + // Returns true (1) if this is an editable node. + /// + int (CEF_CALLBACK *is_editable)(struct _cef_domnode_t* self); + /// // Returns true (1) if this is a form control element node. /// diff --git a/include/capi/cef_focus_handler_capi.h b/include/capi/cef_focus_handler_capi.h new file mode 100644 index 000000000..04ee80d81 --- /dev/null +++ b/include/capi/cef_focus_handler_capi.h @@ -0,0 +1,87 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_FOCUS_HANDLER_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_FOCUS_HANDLER_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Implement this structure to handle events related to focus. The functions of +// this structure will be called on the UI thread. +/// +typedef struct _cef_focus_handler_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Called when the browser component is about to loose focus. For instance, if + // focus was on the last HTML element and the user pressed the TAB key. |next| + // will be true (1) if the browser is giving focus to the next component and + // false (0) if the browser is giving focus to the previous component. + /// + void (CEF_CALLBACK *on_take_focus)(struct _cef_focus_handler_t* self, + struct _cef_browser_t* browser, int next); + + /// + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false (0) to allow the + // focus to be set or true (1) to cancel setting the focus. + /// + int (CEF_CALLBACK *on_set_focus)(struct _cef_focus_handler_t* self, + struct _cef_browser_t* browser, enum cef_focus_source_t source); + + /// + // Called when the browser component has received focus. + /// + void (CEF_CALLBACK *on_got_focus)(struct _cef_focus_handler_t* self, + struct _cef_browser_t* browser); +} cef_focus_handler_t; + + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_FOCUS_HANDLER_CAPI_H_ diff --git a/include/capi/cef_keyboard_handler_capi.h b/include/capi/cef_keyboard_handler_capi.h new file mode 100644 index 000000000..abff51461 --- /dev/null +++ b/include/capi/cef_keyboard_handler_capi.h @@ -0,0 +1,83 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_KEYBOARD_HANDLER_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_KEYBOARD_HANDLER_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Implement this structure to handle events related to keyboard input. The +// functions of this structure will be called on the UI thread. +/// +typedef struct _cef_keyboard_handler_t { + /// + // Base structure. + /// + cef_base_t base; + + // Called before a keyboard event is sent to the renderer. |event| contains + // information about the keyboard event. |os_event| is the operating system + // event message, if any. Return true (1) if the event was handled or false + // (0) otherwise. If the event will be handled in on_key_event() as a keyboard + // shortcut set |is_keyboard_shortcut| to true (1) and return false (0). + int (CEF_CALLBACK *on_pre_key_event)(struct _cef_keyboard_handler_t* self, + struct _cef_browser_t* browser, const struct _cef_key_event_t* event, + cef_event_handle_t os_event, int* is_keyboard_shortcut); + + /// + // Called after the renderer and JavaScript in the page has had a chance to + // handle the event. |event| contains information about the keyboard event. + // |os_event| is the operating system event message, if any. Return true (1) + // if the keyboard event was handled or false (0) otherwise. + /// + int (CEF_CALLBACK *on_key_event)(struct _cef_keyboard_handler_t* self, + struct _cef_browser_t* browser, const struct _cef_key_event_t* event, + cef_event_handle_t os_event); +} cef_keyboard_handler_t; + + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_KEYBOARD_HANDLER_CAPI_H_ diff --git a/include/capi/cef_render_process_handler_capi.h b/include/capi/cef_render_process_handler_capi.h index cefa154ba..a937f73bc 100644 --- a/include/capi/cef_render_process_handler_capi.h +++ b/include/capi/cef_render_process_handler_capi.h @@ -100,6 +100,19 @@ typedef struct _cef_render_process_handler_t { struct _cef_browser_t* browser, struct _cef_frame_t* frame, struct _cef_v8context_t* context); + /// + // Called when a new node in the the browser gets focus. The |node| value may + // be NULL if no specific node has gained focus. The node object passed to + // this function represents a snapshot of the DOM at the time this function is + // executed. DOM objects are only valid for the scope of this function. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this function. + /// + void (CEF_CALLBACK *on_focused_node_changed)( + struct _cef_render_process_handler_t* self, + struct _cef_browser_t* browser, struct _cef_frame_t* frame, + struct _cef_domnode_t* node); + /// // Called when a new message is received from a different process. Return true // (1) if the message was handled or false (0) otherwise. Do not keep a diff --git a/include/cef_client.h b/include/cef_client.h index 183253cbc..381f60c7e 100644 --- a/include/cef_client.h +++ b/include/cef_client.h @@ -41,8 +41,10 @@ #include "include/cef_base.h" #include "include/cef_context_menu_handler.h" #include "include/cef_display_handler.h" +#include "include/cef_focus_handler.h" #include "include/cef_geolocation_handler.h" #include "include/cef_jsdialog_handler.h" +#include "include/cef_keyboard_handler.h" #include "include/cef_life_span_handler.h" #include "include/cef_load_handler.h" #include "include/cef_process_message.h" @@ -54,6 +56,57 @@ /*--cef(source=client,no_debugct_check)--*/ class CefClient : public virtual CefBase { public: + /// + // Return the handler for context menus. If no handler is provided the default + // implementation will be used. + /// + /*--cef()--*/ + virtual CefRefPtr GetContextMenuHandler() { + return NULL; + } + + /// + // Return the handler for browser display state events. + /// + /*--cef()--*/ + virtual CefRefPtr GetDisplayHandler() { + return NULL; + } + + /// + // Return the handler for focus events. + /// + /*--cef()--*/ + virtual CefRefPtr GetFocusHandler() { + return NULL; + } + + /// + // Return the handler for geolocation permissions requests. If no handler is + // provided geolocation access will be denied by default. + /// + /*--cef()--*/ + virtual CefRefPtr GetGeolocationHandler() { + return NULL; + } + + /// + // Return the handler for JavaScript dialogs. If no handler is provided the + // default implementation will be used. + /// + /*--cef()--*/ + virtual CefRefPtr GetJSDialogHandler() { + return NULL; + } + + /// + // Return the handler for keyboard events. + /// + /*--cef()--*/ + virtual CefRefPtr GetKeyboardHandler() { + return NULL; + } + /// // Return the handler for browser life span events. /// @@ -78,41 +131,6 @@ class CefClient : public virtual CefBase { return NULL; } - /// - // Return the handler for browser display state events. - /// - /*--cef()--*/ - virtual CefRefPtr GetDisplayHandler() { - return NULL; - } - - /// - // Return the handler for geolocation permissions requests. If no handler is - // provided geolocation access will be denied by default. - /// - /*--cef()--*/ - virtual CefRefPtr GetGeolocationHandler() { - return NULL; - } - - /// - // Return the handler for JavaScript dialogs. If no handler is provided the - // default implementation will be used. - /// - /*--cef()--*/ - virtual CefRefPtr GetJSDialogHandler() { - return NULL; - } - - /// - // Return the handler for context menus. If no handler is provided the default - // implementation will be used. - /// - /*--cef()--*/ - virtual CefRefPtr GetContextMenuHandler() { - return NULL; - } - /// // Called when a new message is received from a different process. Return true // if the message was handled or false otherwise. Do not keep a reference to diff --git a/include/cef_dom.h b/include/cef_dom.h index f069f416f..f155e2f31 100644 --- a/include/cef_dom.h +++ b/include/cef_dom.h @@ -200,6 +200,12 @@ class CefDOMNode : public virtual CefBase { /*--cef()--*/ virtual bool IsElement() =0; + /// + // Returns true if this is an editable node. + /// + /*--cef()--*/ + virtual bool IsEditable() =0; + /// // Returns true if this is a form control element node. /// diff --git a/include/cef_focus_handler.h b/include/cef_focus_handler.h new file mode 100644 index 000000000..1d91c42ab --- /dev/null +++ b/include/cef_focus_handler.h @@ -0,0 +1,81 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_FOCUS_HANDLER_H_ +#define CEF_INCLUDE_CEF_FOCUS_HANDLER_H_ +#pragma once + +#include "include/cef_base.h" +#include "include/cef_browser.h" +#include "include/cef_dom.h" +#include "include/cef_frame.h" + +/// +// Implement this interface to handle events related to focus. The methods of +// this class will be called on the UI thread. +/// +/*--cef(source=client)--*/ +class CefFocusHandler : public virtual CefBase { + public: + typedef cef_focus_source_t FocusSource; + + /// + // Called when the browser component is about to loose focus. For instance, if + // focus was on the last HTML element and the user pressed the TAB key. |next| + // will be true if the browser is giving focus to the next component and false + // if the browser is giving focus to the previous component. + /// + /*--cef()--*/ + virtual void OnTakeFocus(CefRefPtr browser, + bool next) {} + + /// + // Called when the browser component is requesting focus. |source| indicates + // where the focus request is originating from. Return false to allow the + // focus to be set or true to cancel setting the focus. + /// + /*--cef()--*/ + virtual bool OnSetFocus(CefRefPtr browser, + FocusSource source) { return false; } + + /// + // Called when the browser component has received focus. + /// + /*--cef()--*/ + virtual void OnGotFocus(CefRefPtr browser) {} +}; + +#endif // CEF_INCLUDE_CEF_FOCUS_HANDLER_H_ diff --git a/include/cef_keyboard_handler.h b/include/cef_keyboard_handler.h new file mode 100644 index 000000000..55cb57ef8 --- /dev/null +++ b/include/cef_keyboard_handler.h @@ -0,0 +1,74 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_KEYBOARD_HANDLER_H_ +#define CEF_INCLUDE_CEF_KEYBOARD_HANDLER_H_ +#pragma once + +#include "include/cef_base.h" +#include "include/cef_browser.h" + +/// +// Implement this interface to handle events related to keyboard input. The +// methods of this class will be called on the UI thread. +/// +/*--cef(source=client)--*/ +class CefKeyboardHandler : public virtual CefBase { + public: + // Called before a keyboard event is sent to the renderer. |event| contains + // information about the keyboard event. |os_event| is the operating system + // event message, if any. Return true if the event was handled or false + // otherwise. If the event will be handled in OnKeyEvent() as a keyboard + // shortcut set |is_keyboard_shortcut| to true and return false. + /*--cef()--*/ + virtual bool OnPreKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, + CefEventHandle os_event, + bool* is_keyboard_shortcut) { return false; } + + /// + // Called after the renderer and JavaScript in the page has had a chance to + // handle the event. |event| contains information about the keyboard event. + // |os_event| is the operating system event message, if any. Return true if + // the keyboard event was handled or false otherwise. + /// + /*--cef()--*/ + virtual bool OnKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, + CefEventHandle os_event) { return false; } +}; + +#endif // CEF_INCLUDE_CEF_KEYBOARD_HANDLER_H_ diff --git a/include/cef_render_process_handler.h b/include/cef_render_process_handler.h index 1521fee4d..56c0952f3 100644 --- a/include/cef_render_process_handler.h +++ b/include/cef_render_process_handler.h @@ -40,6 +40,7 @@ #include "include/cef_base.h" #include "include/cef_browser.h" +#include "include/cef_dom.h" #include "include/cef_frame.h" #include "include/cef_process_message.h" #include "include/cef_v8.h" @@ -94,6 +95,19 @@ class CefRenderProcessHandler : public virtual CefBase { CefRefPtr frame, CefRefPtr context) {} + /// + // Called when a new node in the the browser gets focus. The |node| value may + // be empty if no specific node has gained focus. The node object passed to + // this method represents a snapshot of the DOM at the time this method is + // executed. DOM objects are only valid for the scope of this method. Do not + // keep references to or attempt to access any DOM objects outside the scope + // of this method. + /// + /*--cef(optional_param=frame,optional_param=node)--*/ + virtual void OnFocusedNodeChanged(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr node) {} + /// // Called when a new message is received from a different process. Return true // if the message was handled or false otherwise. Do not keep a reference to diff --git a/include/internal/cef_linux.h b/include/internal/cef_linux.h index 87bb51647..c7974bec2 100644 --- a/include/internal/cef_linux.h +++ b/include/internal/cef_linux.h @@ -69,8 +69,9 @@ class CefCriticalSection { }; // Handle types. -#define CefWindowHandle cef_window_handle_t #define CefCursorHandle cef_cursor_handle_t +#define CefEventHandle cef_event_handle_t +#define CefWindowHandle cef_window_handle_t struct CefMainArgsTraits { typedef cef_main_args_t struct_type; diff --git a/include/internal/cef_mac.h b/include/internal/cef_mac.h index 4145d42b0..ddedbce50 100644 --- a/include/internal/cef_mac.h +++ b/include/internal/cef_mac.h @@ -45,10 +45,6 @@ inline long CefAtomicDecrement(long volatile *pDest) { // NOLINT(runtime/int) return __sync_sub_and_fetch(pDest, 1); } -// Handle types. -#define CefWindowHandle cef_window_handle_t -#define CefCursorHandle cef_cursor_handle_t - // Critical section wrapper. class CefCriticalSection { public: @@ -72,6 +68,11 @@ class CefCriticalSection { pthread_mutexattr_t attr_; }; +// Handle types. +#define CefCursorHandle cef_cursor_handle_t +#define CefEventHandle cef_event_handle_t +#define CefWindowHandle cef_window_handle_t + struct CefMainArgsTraits { typedef cef_main_args_t struct_type; diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 38c8a6351..4f1be99c4 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -75,6 +75,15 @@ typedef int int32; typedef unsigned int uint32; #endif +// UTF-16 character type +#ifndef char16 +#if defined(WIN32) +typedef wchar_t char16; +#else +typedef unsigned short char16; +#endif +#endif + #ifdef __cplusplus extern "C" { #endif @@ -945,6 +954,94 @@ enum cef_context_menu_edit_state_flags_t { CM_EDITFLAG_CAN_TRANSLATE = 1 << 7, }; +/// +// Key event types. +/// +enum cef_key_event_type_t { + KEYEVENT_RAWKEYDOWN = 0, + KEYEVENT_KEYDOWN, + KEYEVENT_KEYUP, + KEYEVENT_CHAR +}; + +/// +// Key event modifiers. +/// +enum cef_key_event_modifiers_t { + KEY_SHIFT = 1 << 0, + KEY_CTRL = 1 << 1, + KEY_ALT = 1 << 2, + KEY_META = 1 << 3, + KEY_KEYPAD = 1 << 4, // Only used on Mac OS-X +}; + +/// +// Structure representing keyboard event information. +/// +typedef struct _cef_key_event_t { + /// + // The type of keyboard event. + /// + cef_key_event_type_t type; + + /// + // Bit flags describing any pressed modifier keys. See + // cef_key_event_modifiers_t for values. + /// + int modifiers; + + /// + // The Windows key code for the key event. This value is used by the DOM + // specification. Sometimes it comes directly from the event (i.e. on + // Windows) and sometimes it's determined using a mapping function. See + // WebCore/platform/chromium/KeyboardCodes.h for the list of values. + /// + int windows_key_code; + + /// + // The actual key code genenerated by the platform. + /// + int native_key_code; + + /// + // Indicates whether the event is considered a "system key" event (see + // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details). + // This value will always be false on non-Windows platforms. + /// + bool is_system_key; + + /// + // The character generated by the keystroke. + /// + char16 character; + + /// + // Same as |character| but unmodified by any concurrently-held modifiers + // (except shift). This is useful for working out shortcut keys. + /// + char16 unmodified_character; + + /// + // True if the focus is currently on an editable field on the page. This is + // useful for determining if standard key events should be intercepted. + /// + bool focus_on_editable_field; +} cef_key_event_t; + +/// +// Focus sources. +/// +enum cef_focus_source_t { + /// + // The source is explicit navigation via the API (LoadURL(), etc). + /// + FOCUS_SOURCE_NAVIGATION = 0, + /// + // The source is a system-generated focus event. + /// + FOCUS_SOURCE_SYSTEM, +}; + /// // Supported XML encoding types. The parser supports ASCII, ISO-8859-1, and // UTF16 (LE and BE) by default. All other types must be translated to UTF8 diff --git a/include/internal/cef_types_linux.h b/include/internal/cef_types_linux.h index 13c8482b4..38c8912c3 100644 --- a/include/internal/cef_types_linux.h +++ b/include/internal/cef_types_linux.h @@ -42,9 +42,10 @@ extern "C" { #endif -// Window handle. +// Handle types. +#define cef_cursor_handle_t GtkCursor* +#define cef_event_handle_t GdkEvent* #define cef_window_handle_t GtkWidget* -#define cef_cursor_handle_t void* /// // Structure representing CefExecuteProcess arguments. diff --git a/include/internal/cef_types_mac.h b/include/internal/cef_types_mac.h index e467081ef..6257f45c7 100644 --- a/include/internal/cef_types_mac.h +++ b/include/internal/cef_types_mac.h @@ -37,18 +37,25 @@ #if defined(OS_MACOSX) #include "include/internal/cef_string.h" -// Window handle. +// Handle types. #ifdef __cplusplus #ifdef __OBJC__ +@class NSCursor; +@class NSEvent; @class NSView; #else +class NSCursor; +class NSEvent; struct NSView; #endif +#define cef_cursor_handle_t NSCursor* +#define cef_event_handle_t NSEvent* #define cef_window_handle_t NSView* #else +#define cef_cursor_handle_t void* +#define cef_event_handle_t void* #define cef_window_handle_t void* #endif -#define cef_cursor_handle_t void* #ifdef __cplusplus extern "C" { diff --git a/include/internal/cef_types_win.h b/include/internal/cef_types_win.h index b15d99b92..bbe0bf5aa 100644 --- a/include/internal/cef_types_win.h +++ b/include/internal/cef_types_win.h @@ -42,9 +42,10 @@ extern "C" { #endif -// Window handle. -#define cef_window_handle_t HWND +// Handle types. #define cef_cursor_handle_t HCURSOR +#define cef_event_handle_t MSG* +#define cef_window_handle_t HWND /// // Structure representing CefExecuteProcess arguments. diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index b3c326ca0..463909113 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -174,6 +174,31 @@ inline bool operator!=(const CefRect& a, const CefRect& b) { return !(a == b); } +struct CefKeyEventTraits { + typedef cef_key_event_t struct_type; + + static inline void init(struct_type* s) {} + + static inline void clear(struct_type* s) {} + + static inline void set(const struct_type* src, struct_type* target, + bool copy) { + target->type = src->type; + target->modifiers = src->modifiers; + target->windows_key_code = src->windows_key_code; + target->native_key_code = src->native_key_code; + target->is_system_key = src->is_system_key; + target->character = src->character; + target->unmodified_character = src->unmodified_character; + target->focus_on_editable_field = src->focus_on_editable_field; + } +}; + +/// +// Class representing a a keyboard event. +/// +typedef CefStructBase CefKeyEvent; + struct CefPopupFeaturesTraits { typedef cef_popup_features_t struct_type; diff --git a/include/internal/cef_win.h b/include/internal/cef_win.h index a5c7dbc21..1115bd161 100644 --- a/include/internal/cef_win.h +++ b/include/internal/cef_win.h @@ -68,8 +68,9 @@ class CefCriticalSection { /// // Handle types. /// -#define CefWindowHandle cef_window_handle_t #define CefCursorHandle cef_cursor_handle_t +#define CefEventHandle cef_event_handle_t +#define CefWindowHandle cef_window_handle_t struct CefMainArgsTraits { typedef cef_main_args_t struct_type; diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 706f64e0c..1936f1d92 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -55,6 +55,47 @@ void CreateBrowserWithHelper(CreateBrowserHelper* helper) { delete helper; } +// Convert a NativeWebKeyboardEvent to a CefKeyEvent. +bool GetCefKeyEvent(const content::NativeWebKeyboardEvent& event, + CefKeyEvent& cef_event) { + switch (event.type) { + case WebKit::WebKeyboardEvent::RawKeyDown: + cef_event.type = KEYEVENT_RAWKEYDOWN; + break; + case WebKit::WebKeyboardEvent::KeyDown: + cef_event.type = KEYEVENT_KEYDOWN; + break; + case WebKit::WebKeyboardEvent::KeyUp: + cef_event.type = KEYEVENT_KEYUP; + break; + case WebKit::WebKeyboardEvent::Char: + cef_event.type = KEYEVENT_CHAR; + break; + default: + return false; + } + + cef_event.modifiers = 0; + if (event.modifiers & WebKit::WebKeyboardEvent::ShiftKey) + cef_event.modifiers |= KEY_SHIFT; + if (event.modifiers & WebKit::WebKeyboardEvent::ControlKey) + cef_event.modifiers |= KEY_CTRL; + if (event.modifiers & WebKit::WebKeyboardEvent::AltKey) + cef_event.modifiers |= KEY_ALT; + if (event.modifiers & WebKit::WebKeyboardEvent::MetaKey) + cef_event.modifiers |= KEY_META; + if (event.modifiers & WebKit::WebKeyboardEvent::IsKeyPad) + cef_event.modifiers |= KEY_KEYPAD; + + cef_event.windows_key_code = event.windowsKeyCode; + cef_event.native_key_code = event.nativeKeyCode; + cef_event.is_system_key = event.isSystemKey; + cef_event.character = event.text[0]; + cef_event.unmodified_character = event.unmodifiedText[0]; + + return true; +} + } // namespace @@ -268,8 +309,7 @@ void CefBrowserHostImpl::SetFocus(bool enable) { return; if (CEF_CURRENTLY_ON_UIT()) { - if (web_contents_.get()) - web_contents_->Focus(); + OnSetFocus(FOCUS_SOURCE_SYSTEM); } else { CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::SetFocus, this, enable)); @@ -572,8 +612,7 @@ void CefBrowserHostImpl::Navigate(const CefNavigateParams& params) { Send(new CefMsg_LoadRequest(routing_id(), request)); - if (web_contents_.get()) - web_contents_->Focus(); + OnSetFocus(FOCUS_SOURCE_NAVIGATION); } void CefBrowserHostImpl::LoadRequest(int64 frame_id, @@ -629,7 +668,7 @@ void CefBrowserHostImpl::LoadURL(int64 frame_id, const std::string& url) { content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); - web_contents_->Focus(); + OnSetFocus(FOCUS_SOURCE_NAVIGATION); } } else { CEF_POST_TASK(CEF_UIT, @@ -666,6 +705,7 @@ void CefBrowserHostImpl::SendCommand( CefRefPtr responseHandler) { // Only known frame ids are supported. DCHECK(frame_id > CefFrameHostImpl::kMainFrameId); + DCHECK(!command.empty()); // Execute on the UI thread because CefResponseManager is not thread safe. if (CEF_CURRENTLY_ON_UIT()) { @@ -702,6 +742,8 @@ void CefBrowserHostImpl::SendCode( CefRefPtr responseHandler) { // Only known frame ids are supported. DCHECK(frame_id >= CefFrameHostImpl::kMainFrameId); + DCHECK(!code.empty()); + DCHECK_GE(script_start_line, 0); // Execute on the UI thread because CefResponseManager is not thread safe. if (CEF_CURRENTLY_ON_UIT()) { @@ -792,6 +834,24 @@ void CefBrowserHostImpl::LoadingStateChanged(content::WebContents* source) { } } +bool CefBrowserHostImpl::TakeFocus(bool reverse) { + if (client_.get()) { + CefRefPtr handler = client_->GetFocusHandler(); + if (handler.get()) + handler->OnTakeFocus(this, !reverse); + } + + return false; +} + +void CefBrowserHostImpl::WebContentsFocused(content::WebContents* contents) { + if (client_.get()) { + CefRefPtr handler = client_->GetFocusHandler(); + if (handler.get()) + handler->OnGotFocus(this); + } +} + bool CefBrowserHostImpl::HandleContextMenu( const content::ContextMenuParams& params) { if (!menu_creator_.get()) @@ -799,12 +859,57 @@ bool CefBrowserHostImpl::HandleContextMenu( return menu_creator_->CreateContextMenu(params); } +bool CefBrowserHostImpl::PreHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut) { + if (client_.get()) { + CefRefPtr handler = client_->GetKeyboardHandler(); + if (handler.get()) { + CefKeyEvent cef_event; + if (!GetCefKeyEvent(event, cef_event)) + return false; + +#if defined(OS_WIN) + CefEventHandle os_event = const_cast(&event.os_event); +#else + CefEventHandle os_event = event.os_event; +#endif + + cef_event.focus_on_editable_field = focus_on_editable_field_; + + return handler->OnPreKeyEvent(this, cef_event, os_event, + is_keyboard_shortcut); + } + } + + return false; +} + void CefBrowserHostImpl::HandleKeyboardEvent( const content::NativeWebKeyboardEvent& event) { // Check to see if event should be ignored. if (event.skip_in_browser) return; + if (client_.get()) { + CefRefPtr handler = client_->GetKeyboardHandler(); + if (handler.get()) { + CefKeyEvent cef_event; + if (GetCefKeyEvent(event, cef_event)) { +#if defined(OS_WIN) + CefEventHandle os_event = const_cast(&event.os_event); +#else + CefEventHandle os_event = event.os_event; +#endif + + cef_event.focus_on_editable_field = focus_on_editable_field_; + + if (handler->OnKeyEvent(this, cef_event, os_event)) + return; + } + } + } + PlatformHandleKeyboardEvent(event); } @@ -1073,7 +1178,8 @@ void CefBrowserHostImpl::OnResponseAck(int request_id) { void CefBrowserHostImpl::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED); + DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED || + type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE); if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { std::pair* title = @@ -1094,6 +1200,8 @@ void CefBrowserHostImpl::Observe(int type, received_page_title_ = title->second; } + } else if (type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE) { + focus_on_editable_field_ = *content::Details(details).ptr(); } } @@ -1121,13 +1229,18 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info, has_document_(false), queue_messages_(true), main_frame_id_(CefFrameHostImpl::kInvalidFrameId), - focused_frame_id_(CefFrameHostImpl::kInvalidFrameId) { + focused_frame_id_(CefFrameHostImpl::kInvalidFrameId), + is_in_onsetfocus_(false), + focus_on_editable_field_(false) { web_contents_.reset(web_contents); web_contents->SetDelegate(this); registrar_.reset(new content::NotificationRegistrar); registrar_->Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, content::Source(web_contents)); + registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, + content::Source( + web_contents->GetRenderViewHost())); response_manager_.reset(new CefResponseManager); placeholder_frame_ = @@ -1290,3 +1403,26 @@ void CefBrowserHostImpl::OnLoadEnd(CefRefPtr frame, } } } + +void CefBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { + CEF_REQUIRE_UIT(); + + // SetFocus() might be called while inside the OnSetFocus() callback. If so, + // don't re-enter the callback. + if (!is_in_onsetfocus_) { + if (client_.get()) { + CefRefPtr handler = client_->GetFocusHandler(); + if (handler.get()) { + is_in_onsetfocus_ = true; + bool handled = handler->OnSetFocus(this, source); + is_in_onsetfocus_ = false; + + if (handled) + return; + } + } + } + + if (web_contents_.get()) + web_contents_->Focus(); +} diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index b098f6142..fd0628b4a 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -197,8 +197,13 @@ class CefBrowserHostImpl : public CefBrowserHost, content::WebContents* source, const content::OpenURLParams& params) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; + virtual bool TakeFocus(bool reverse) OVERRIDE; + virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; virtual bool HandleContextMenu(const content::ContextMenuParams& params) OVERRIDE; + virtual bool PreHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut) OVERRIDE; virtual void HandleKeyboardEvent( const content::NativeWebKeyboardEvent& event) OVERRIDE; virtual bool ShouldCreateWebContents( @@ -317,6 +322,7 @@ class CefBrowserHostImpl : public CefBrowserHost, const string16& error_description); void OnLoadEnd(CefRefPtr frame, const GURL& url); + void OnSetFocus(cef_focus_source_t source); CefWindowInfo window_info_; CefBrowserSettings settings_; @@ -367,6 +373,14 @@ class CefBrowserHostImpl : public CefBrowserHost, // Used when no other frame exists. Provides limited functionality. CefRefPtr placeholder_frame_; + // True if currently in the OnSetFocus callback. Only accessed on the UI + // thread. + bool is_in_onsetfocus_; + + // True if the focus is currently on an editable field on the page. Only + // accessed on the UI thread. + bool focus_on_editable_field_; + // Used for managing notification subscriptions. scoped_ptr registrar_; diff --git a/libcef/browser/browser_host_impl_mac.mm b/libcef/browser/browser_host_impl_mac.mm index 58025f09c..b652dae87 100644 --- a/libcef/browser/browser_host_impl_mac.mm +++ b/libcef/browser/browser_host_impl_mac.mm @@ -37,6 +37,17 @@ [super dealloc]; } +- (BOOL)acceptsFirstResponder { + return browser_ && browser_->GetWebContents(); +} + +- (BOOL)becomeFirstResponder { + if (browser_ && browser_->GetWebContents()) + browser_->OnSetFocus(FOCUS_SOURCE_SYSTEM); + + return YES; +} + @end diff --git a/libcef/browser/browser_host_impl_win.cc b/libcef/browser/browser_host_impl_win.cc index 870475f20..a21d40ef3 100644 --- a/libcef/browser/browser_host_impl_win.cc +++ b/libcef/browser/browser_host_impl_win.cc @@ -129,11 +129,8 @@ LRESULT CALLBACK CefBrowserHostImpl::WndProc(HWND hwnd, UINT message, return 0; case WM_SETFOCUS: - if (browser) { - content::WebContents* web_contents = browser->GetWebContents(); - if (web_contents) - web_contents->Focus(); - } + if (browser) + browser->OnSetFocus(FOCUS_SOURCE_SYSTEM); return 0; case WM_ERASEBKGND: diff --git a/libcef/browser/frame_host_impl.cc b/libcef/browser/frame_host_impl.cc index c909645a0..4618ca15a 100644 --- a/libcef/browser/frame_host_impl.cc +++ b/libcef/browser/frame_host_impl.cc @@ -153,6 +153,11 @@ void CefFrameHostImpl::LoadString(const CefString& string, void CefFrameHostImpl::ExecuteJavaScript(const CefString& jsCode, const CefString& scriptUrl, int startLine) { + if (jsCode.empty()) + return; + if (startLine < 0) + startLine = 0; + base::AutoLock lock_scope(state_lock_); if (browser_) { browser_->SendCode((is_main_frame_ ? kMainFrameId : frame_id_), true, diff --git a/libcef/renderer/browser_impl.cc b/libcef/renderer/browser_impl.cc index c548d0357..dc6e55dd4 100644 --- a/libcef/renderer/browser_impl.cc +++ b/libcef/renderer/browser_impl.cc @@ -13,6 +13,7 @@ #include "libcef/common/process_message_impl.h" #include "libcef/common/response_manager.h" #include "libcef/renderer/content_renderer_client.h" +#include "libcef/renderer/dom_document_impl.h" #include "libcef/renderer/thread_util.h" #include "libcef/renderer/webkit_glue.h" @@ -459,6 +460,29 @@ void CefBrowserImpl::FrameDetached(WebFrame* frame) { } void CefBrowserImpl::FocusedNodeChanged(const WebKit::WebNode& node) { + // Notify the handler. + CefRefPtr app = CefContentClient::Get()->application(); + if (app.get()) { + CefRefPtr handler = + app->GetRenderProcessHandler(); + if (handler.get()) { + if (node.isNull()) { + handler->OnFocusedNodeChanged(this, GetFocusedFrame(), NULL); + } else { + const WebKit::WebDocument& document = node.document(); + if (!document.isNull()) { + WebKit::WebFrame* frame = document.frame(); + CefRefPtr documentImpl = + new CefDOMDocumentImpl(this, frame); + handler->OnFocusedNodeChanged(this, + GetWebFrameImpl(frame).get(), + documentImpl->GetOrCreateNode(node)); + documentImpl->Detach(); + } + } + } + } + // TODO(cef): This method is being used as a work-around for identifying frame // focus changes. The ideal approach would be implementating delegation from // ChromeClientImpl::focusedFrameChanged(). @@ -582,7 +606,6 @@ void CefBrowserImpl::OnRequest(const Cef_Request_Params& params) { params.arguments.GetString(1, &code); DCHECK(!code.empty()); params.arguments.GetString(2, &script_url); - DCHECK(!script_url.empty()); params.arguments.GetInteger(3, &script_start_line); DCHECK_GE(script_start_line, 0); @@ -633,9 +656,7 @@ void CefBrowserImpl::OnRequest(const Cef_Request_Params& params) { string16 string, url; params.arguments.GetString(0, &string); - DCHECK(!string.empty()); params.arguments.GetString(1, &url); - DCHECK(!url.empty()); web_frame->loadHTMLString(UTF16ToUTF8(string), GURL(UTF16ToUTF8(url))); } diff --git a/libcef/renderer/browser_impl.h b/libcef/renderer/browser_impl.h index 7c1df8aa6..1dac457fd 100644 --- a/libcef/renderer/browser_impl.h +++ b/libcef/renderer/browser_impl.h @@ -81,7 +81,7 @@ class CefBrowserImpl : public CefBrowser, void LoadRequest(const CefMsg_LoadRequest_Params& params); - // Returns the matching WebFrameImpl reference or creates a new one. + // Returns the matching CefFrameImpl reference or creates a new one. CefRefPtr GetWebFrameImpl(WebKit::WebFrame* frame); CefRefPtr GetWebFrameImpl(int64 frame_id); diff --git a/libcef/renderer/dom_node_impl.cc b/libcef/renderer/dom_node_impl.cc index 4ab92e527..bc3b6b6d7 100644 --- a/libcef/renderer/dom_node_impl.cc +++ b/libcef/renderer/dom_node_impl.cc @@ -148,6 +148,32 @@ bool CefDOMNodeImpl::IsElement() { return node_.isElementNode(); } +// Logic copied from RenderViewImpl::IsEditableNode. +bool CefDOMNodeImpl::IsEditable() { + if (!VerifyContext()) + return false; + + if (node_.isContentEditable()) + return true; + + if (node_.isElementNode()) { + const WebElement& element = node_.toConst(); + if (element.isTextFormControlElement()) + return true; + + // Also return true if it has an ARIA role of 'textbox'. + for (unsigned i = 0; i < element.attributeCount(); ++i) { + if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { + if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) + return true; + break; + } + } + } + + return false; +} + bool CefDOMNodeImpl::IsFormControlElement() { if (!VerifyContext()) return false; diff --git a/libcef/renderer/dom_node_impl.h b/libcef/renderer/dom_node_impl.h index d65b627b5..4a641a9d8 100644 --- a/libcef/renderer/dom_node_impl.h +++ b/libcef/renderer/dom_node_impl.h @@ -21,6 +21,7 @@ class CefDOMNodeImpl : public CefDOMNode { virtual Type GetType() OVERRIDE; virtual bool IsText() OVERRIDE; virtual bool IsElement() OVERRIDE; + virtual bool IsEditable() OVERRIDE; virtual bool IsFormControlElement() OVERRIDE; virtual CefString GetFormControlElementType() OVERRIDE; virtual bool IsSame(CefRefPtr that) OVERRIDE; diff --git a/libcef/renderer/frame_impl.cc b/libcef/renderer/frame_impl.cc index fe5ca61cf..3be3c7f59 100644 --- a/libcef/renderer/frame_impl.cc +++ b/libcef/renderer/frame_impl.cc @@ -163,6 +163,11 @@ void CefFrameImpl::ExecuteJavaScript(const CefString& jsCode, int startLine) { CEF_REQUIRE_RT_RETURN_VOID(); + if (jsCode.empty()) + return; + if (startLine < 0) + startLine = 0; + if (frame_) { GURL gurl = GURL(scriptUrl.ToString()); frame_->executeScript( diff --git a/libcef_dll/cpptoc/client_cpptoc.cc b/libcef_dll/cpptoc/client_cpptoc.cc index e71c48b0c..c4a731f2d 100644 --- a/libcef_dll/cpptoc/client_cpptoc.cc +++ b/libcef_dll/cpptoc/client_cpptoc.cc @@ -13,8 +13,10 @@ #include "libcef_dll/cpptoc/client_cpptoc.h" #include "libcef_dll/cpptoc/context_menu_handler_cpptoc.h" #include "libcef_dll/cpptoc/display_handler_cpptoc.h" +#include "libcef_dll/cpptoc/focus_handler_cpptoc.h" #include "libcef_dll/cpptoc/geolocation_handler_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h" +#include "libcef_dll/cpptoc/keyboard_handler_cpptoc.h" #include "libcef_dll/cpptoc/life_span_handler_cpptoc.h" #include "libcef_dll/cpptoc/load_handler_cpptoc.h" #include "libcef_dll/cpptoc/request_handler_cpptoc.h" @@ -24,6 +26,102 @@ // MEMBER FUNCTIONS - Body may be edited by hand. +struct _cef_context_menu_handler_t* CEF_CALLBACK client_get_context_menu_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetContextMenuHandler(); + + // Return type: refptr_same + return CefContextMenuHandlerCppToC::Wrap(_retval); +} + +struct _cef_display_handler_t* CEF_CALLBACK client_get_display_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetDisplayHandler(); + + // Return type: refptr_same + return CefDisplayHandlerCppToC::Wrap(_retval); +} + +struct _cef_focus_handler_t* CEF_CALLBACK client_get_focus_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetFocusHandler(); + + // Return type: refptr_same + return CefFocusHandlerCppToC::Wrap(_retval); +} + +struct _cef_geolocation_handler_t* CEF_CALLBACK client_get_geolocation_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetGeolocationHandler(); + + // Return type: refptr_same + return CefGeolocationHandlerCppToC::Wrap(_retval); +} + +struct _cef_jsdialog_handler_t* CEF_CALLBACK client_get_jsdialog_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetJSDialogHandler(); + + // Return type: refptr_same + return CefJSDialogHandlerCppToC::Wrap(_retval); +} + +struct _cef_keyboard_handler_t* CEF_CALLBACK client_get_keyboard_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetKeyboardHandler(); + + // Return type: refptr_same + return CefKeyboardHandlerCppToC::Wrap(_retval); +} + struct _cef_life_span_handler_t* CEF_CALLBACK client_get_life_span_handler( struct _cef_client_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -72,70 +170,6 @@ struct _cef_request_handler_t* CEF_CALLBACK client_get_request_handler( return CefRequestHandlerCppToC::Wrap(_retval); } -struct _cef_display_handler_t* CEF_CALLBACK client_get_display_handler( - struct _cef_client_t* self) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return NULL; - - // Execute - CefRefPtr _retval = CefClientCppToC::Get( - self)->GetDisplayHandler(); - - // Return type: refptr_same - return CefDisplayHandlerCppToC::Wrap(_retval); -} - -struct _cef_geolocation_handler_t* CEF_CALLBACK client_get_geolocation_handler( - struct _cef_client_t* self) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return NULL; - - // Execute - CefRefPtr _retval = CefClientCppToC::Get( - self)->GetGeolocationHandler(); - - // Return type: refptr_same - return CefGeolocationHandlerCppToC::Wrap(_retval); -} - -struct _cef_jsdialog_handler_t* CEF_CALLBACK client_get_jsdialog_handler( - struct _cef_client_t* self) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return NULL; - - // Execute - CefRefPtr _retval = CefClientCppToC::Get( - self)->GetJSDialogHandler(); - - // Return type: refptr_same - return CefJSDialogHandlerCppToC::Wrap(_retval); -} - -struct _cef_context_menu_handler_t* CEF_CALLBACK client_get_context_menu_handler( - struct _cef_client_t* self) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return NULL; - - // Execute - CefRefPtr _retval = CefClientCppToC::Get( - self)->GetContextMenuHandler(); - - // Return type: refptr_same - return CefContextMenuHandlerCppToC::Wrap(_retval); -} - int CEF_CALLBACK client_on_process_message_recieved(struct _cef_client_t* self, cef_browser_t* browser, enum cef_process_id_t source_process, struct _cef_process_message_t* message) { @@ -168,13 +202,15 @@ int CEF_CALLBACK client_on_process_message_recieved(struct _cef_client_t* self, CefClientCppToC::CefClientCppToC(CefClient* cls) : CefCppToC(cls) { + struct_.struct_.get_context_menu_handler = client_get_context_menu_handler; + struct_.struct_.get_display_handler = client_get_display_handler; + struct_.struct_.get_focus_handler = client_get_focus_handler; + struct_.struct_.get_geolocation_handler = client_get_geolocation_handler; + struct_.struct_.get_jsdialog_handler = client_get_jsdialog_handler; + struct_.struct_.get_keyboard_handler = client_get_keyboard_handler; struct_.struct_.get_life_span_handler = client_get_life_span_handler; struct_.struct_.get_load_handler = client_get_load_handler; struct_.struct_.get_request_handler = client_get_request_handler; - struct_.struct_.get_display_handler = client_get_display_handler; - struct_.struct_.get_geolocation_handler = client_get_geolocation_handler; - struct_.struct_.get_jsdialog_handler = client_get_jsdialog_handler; - struct_.struct_.get_context_menu_handler = client_get_context_menu_handler; struct_.struct_.on_process_message_recieved = client_on_process_message_recieved; } diff --git a/libcef_dll/cpptoc/domnode_cpptoc.cc b/libcef_dll/cpptoc/domnode_cpptoc.cc index 209ae7a82..f38caee38 100644 --- a/libcef_dll/cpptoc/domnode_cpptoc.cc +++ b/libcef_dll/cpptoc/domnode_cpptoc.cc @@ -61,6 +61,20 @@ int CEF_CALLBACK domnode_is_element(struct _cef_domnode_t* self) { return _retval; } +int CEF_CALLBACK domnode_is_editable(struct _cef_domnode_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefDOMNodeCppToC::Get(self)->IsEditable(); + + // Return type: bool + return _retval; +} + int CEF_CALLBACK domnode_is_form_control_element(struct _cef_domnode_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -447,6 +461,7 @@ CefDOMNodeCppToC::CefDOMNodeCppToC(CefDOMNode* cls) struct_.struct_.get_type = domnode_get_type; struct_.struct_.is_text = domnode_is_text; struct_.struct_.is_element = domnode_is_element; + struct_.struct_.is_editable = domnode_is_editable; struct_.struct_.is_form_control_element = domnode_is_form_control_element; struct_.struct_.get_form_control_element_type = domnode_get_form_control_element_type; diff --git a/libcef_dll/cpptoc/focus_handler_cpptoc.cc b/libcef_dll/cpptoc/focus_handler_cpptoc.cc new file mode 100644 index 000000000..e33ff796b --- /dev/null +++ b/libcef_dll/cpptoc/focus_handler_cpptoc.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/focus_handler_cpptoc.h" +#include "libcef_dll/ctocpp/browser_ctocpp.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK focus_handler_on_take_focus(struct _cef_focus_handler_t* self, + cef_browser_t* browser, int next) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + + // Execute + CefFocusHandlerCppToC::Get(self)->OnTakeFocus( + CefBrowserCToCpp::Wrap(browser), + next?true:false); +} + +int CEF_CALLBACK focus_handler_on_set_focus(struct _cef_focus_handler_t* self, + cef_browser_t* browser, enum cef_focus_source_t source) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return 0; + + // Execute + bool _retval = CefFocusHandlerCppToC::Get(self)->OnSetFocus( + CefBrowserCToCpp::Wrap(browser), + source); + + // Return type: bool + return _retval; +} + +void CEF_CALLBACK focus_handler_on_got_focus(struct _cef_focus_handler_t* self, + cef_browser_t* browser) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + + // Execute + CefFocusHandlerCppToC::Get(self)->OnGotFocus( + CefBrowserCToCpp::Wrap(browser)); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefFocusHandlerCppToC::CefFocusHandlerCppToC(CefFocusHandler* cls) + : CefCppToC( + cls) { + struct_.struct_.on_take_focus = focus_handler_on_take_focus; + struct_.struct_.on_set_focus = focus_handler_on_set_focus; + struct_.struct_.on_got_focus = focus_handler_on_got_focus; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/focus_handler_cpptoc.h b/libcef_dll/cpptoc/focus_handler_cpptoc.h new file mode 100644 index 000000000..b88e246ec --- /dev/null +++ b/libcef_dll/cpptoc/focus_handler_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_FOCUS_HANDLER_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_FOCUS_HANDLER_CPPTOC_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_focus_handler.h" +#include "include/capi/cef_focus_handler_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed wrapper-side only. +class CefFocusHandlerCppToC + : public CefCppToC { + public: + explicit CefFocusHandlerCppToC(CefFocusHandler* cls); + virtual ~CefFocusHandlerCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_FOCUS_HANDLER_CPPTOC_H_ + diff --git a/libcef_dll/cpptoc/keyboard_handler_cpptoc.cc b/libcef_dll/cpptoc/keyboard_handler_cpptoc.cc new file mode 100644 index 000000000..95779c88b --- /dev/null +++ b/libcef_dll/cpptoc/keyboard_handler_cpptoc.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/keyboard_handler_cpptoc.h" +#include "libcef_dll/ctocpp/browser_ctocpp.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +int CEF_CALLBACK keyboard_handler_on_pre_key_event( + struct _cef_keyboard_handler_t* self, cef_browser_t* browser, + const struct _cef_key_event_t* event, cef_event_handle_t os_event, + int* is_keyboard_shortcut) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return 0; + // Verify param: event; type: struct_byref_const + DCHECK(event); + if (!event) + return 0; + // Verify param: is_keyboard_shortcut; type: bool_byaddr + DCHECK(is_keyboard_shortcut); + if (!is_keyboard_shortcut) + return 0; + + // Translate param: event; type: struct_byref_const + CefKeyEvent eventObj; + if (event) + eventObj.Set(*event, false); + // Translate param: is_keyboard_shortcut; type: bool_byaddr + bool is_keyboard_shortcutBool = ( + is_keyboard_shortcut && *is_keyboard_shortcut)?true:false; + + // Execute + bool _retval = CefKeyboardHandlerCppToC::Get(self)->OnPreKeyEvent( + CefBrowserCToCpp::Wrap(browser), + eventObj, + os_event, + &is_keyboard_shortcutBool); + + // Restore param: is_keyboard_shortcut; type: bool_byaddr + if (is_keyboard_shortcut) + *is_keyboard_shortcut = is_keyboard_shortcutBool?true:false; + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK keyboard_handler_on_key_event( + struct _cef_keyboard_handler_t* self, cef_browser_t* browser, + const struct _cef_key_event_t* event, cef_event_handle_t os_event) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return 0; + // Verify param: event; type: struct_byref_const + DCHECK(event); + if (!event) + return 0; + + // Translate param: event; type: struct_byref_const + CefKeyEvent eventObj; + if (event) + eventObj.Set(*event, false); + + // Execute + bool _retval = CefKeyboardHandlerCppToC::Get(self)->OnKeyEvent( + CefBrowserCToCpp::Wrap(browser), + eventObj, + os_event); + + // Return type: bool + return _retval; +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefKeyboardHandlerCppToC::CefKeyboardHandlerCppToC(CefKeyboardHandler* cls) + : CefCppToC(cls) { + struct_.struct_.on_pre_key_event = keyboard_handler_on_pre_key_event; + struct_.struct_.on_key_event = keyboard_handler_on_key_event; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/keyboard_handler_cpptoc.h b/libcef_dll/cpptoc/keyboard_handler_cpptoc.h new file mode 100644 index 000000000..4685a74ea --- /dev/null +++ b/libcef_dll/cpptoc/keyboard_handler_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_KEYBOARD_HANDLER_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_KEYBOARD_HANDLER_CPPTOC_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_keyboard_handler.h" +#include "include/capi/cef_keyboard_handler_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed wrapper-side only. +class CefKeyboardHandlerCppToC + : public CefCppToC { + public: + explicit CefKeyboardHandlerCppToC(CefKeyboardHandler* cls); + virtual ~CefKeyboardHandlerCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_KEYBOARD_HANDLER_CPPTOC_H_ + diff --git a/libcef_dll/cpptoc/render_process_handler_cpptoc.cc b/libcef_dll/cpptoc/render_process_handler_cpptoc.cc index 8363fc7da..8de0fd981 100644 --- a/libcef_dll/cpptoc/render_process_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/render_process_handler_cpptoc.cc @@ -12,6 +12,7 @@ #include "libcef_dll/cpptoc/render_process_handler_cpptoc.h" #include "libcef_dll/ctocpp/browser_ctocpp.h" +#include "libcef_dll/ctocpp/domnode_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" #include "libcef_dll/ctocpp/process_message_ctocpp.h" #include "libcef_dll/ctocpp/v8context_ctocpp.h" @@ -133,6 +134,27 @@ void CEF_CALLBACK render_process_handler_on_context_released( CefV8ContextCToCpp::Wrap(context)); } +void CEF_CALLBACK render_process_handler_on_focused_node_changed( + struct _cef_render_process_handler_t* self, cef_browser_t* browser, + cef_frame_t* frame, cef_domnode_t* node) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + // Unverified params: frame, node + + // Execute + CefRenderProcessHandlerCppToC::Get(self)->OnFocusedNodeChanged( + CefBrowserCToCpp::Wrap(browser), + CefFrameCToCpp::Wrap(frame), + CefDOMNodeCToCpp::Wrap(node)); +} + int CEF_CALLBACK render_process_handler_on_process_message_recieved( struct _cef_render_process_handler_t* self, cef_browser_t* browser, enum cef_process_id_t source_process, cef_process_message_t* message) { @@ -180,6 +202,8 @@ CefRenderProcessHandlerCppToC::CefRenderProcessHandlerCppToC( render_process_handler_on_context_created; struct_.struct_.on_context_released = render_process_handler_on_context_released; + struct_.struct_.on_focused_node_changed = + render_process_handler_on_focused_node_changed; struct_.struct_.on_process_message_recieved = render_process_handler_on_process_message_recieved; } diff --git a/libcef_dll/ctocpp/client_ctocpp.cc b/libcef_dll/ctocpp/client_ctocpp.cc index 09f97970b..51ea217b1 100644 --- a/libcef_dll/ctocpp/client_ctocpp.cc +++ b/libcef_dll/ctocpp/client_ctocpp.cc @@ -15,8 +15,10 @@ #include "libcef_dll/ctocpp/client_ctocpp.h" #include "libcef_dll/ctocpp/context_menu_handler_ctocpp.h" #include "libcef_dll/ctocpp/display_handler_ctocpp.h" +#include "libcef_dll/ctocpp/focus_handler_ctocpp.h" #include "libcef_dll/ctocpp/geolocation_handler_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h" +#include "libcef_dll/ctocpp/keyboard_handler_ctocpp.h" #include "libcef_dll/ctocpp/life_span_handler_ctocpp.h" #include "libcef_dll/ctocpp/load_handler_ctocpp.h" #include "libcef_dll/ctocpp/request_handler_ctocpp.h" @@ -24,6 +26,86 @@ // VIRTUAL METHODS - Body may be edited by hand. +CefRefPtr CefClientCToCpp::GetContextMenuHandler() { + if (CEF_MEMBER_MISSING(struct_, get_context_menu_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_context_menu_handler_t* _retval = struct_->get_context_menu_handler( + struct_); + + // Return type: refptr_same + return CefContextMenuHandlerCToCpp::Wrap(_retval); +} + +CefRefPtr CefClientCToCpp::GetDisplayHandler() { + if (CEF_MEMBER_MISSING(struct_, get_display_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_display_handler_t* _retval = struct_->get_display_handler(struct_); + + // Return type: refptr_same + return CefDisplayHandlerCToCpp::Wrap(_retval); +} + +CefRefPtr CefClientCToCpp::GetFocusHandler() { + if (CEF_MEMBER_MISSING(struct_, get_focus_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_focus_handler_t* _retval = struct_->get_focus_handler(struct_); + + // Return type: refptr_same + return CefFocusHandlerCToCpp::Wrap(_retval); +} + +CefRefPtr CefClientCToCpp::GetGeolocationHandler() { + if (CEF_MEMBER_MISSING(struct_, get_geolocation_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_geolocation_handler_t* _retval = struct_->get_geolocation_handler( + struct_); + + // Return type: refptr_same + return CefGeolocationHandlerCToCpp::Wrap(_retval); +} + +CefRefPtr CefClientCToCpp::GetJSDialogHandler() { + if (CEF_MEMBER_MISSING(struct_, get_jsdialog_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_jsdialog_handler_t* _retval = struct_->get_jsdialog_handler(struct_); + + // Return type: refptr_same + return CefJSDialogHandlerCToCpp::Wrap(_retval); +} + +CefRefPtr CefClientCToCpp::GetKeyboardHandler() { + if (CEF_MEMBER_MISSING(struct_, get_keyboard_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_keyboard_handler_t* _retval = struct_->get_keyboard_handler(struct_); + + // Return type: refptr_same + return CefKeyboardHandlerCToCpp::Wrap(_retval); +} + CefRefPtr CefClientCToCpp::GetLifeSpanHandler() { if (CEF_MEMBER_MISSING(struct_, get_life_span_handler)) return NULL; @@ -63,60 +145,6 @@ CefRefPtr CefClientCToCpp::GetRequestHandler() { return CefRequestHandlerCToCpp::Wrap(_retval); } -CefRefPtr CefClientCToCpp::GetDisplayHandler() { - if (CEF_MEMBER_MISSING(struct_, get_display_handler)) - return NULL; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_display_handler_t* _retval = struct_->get_display_handler(struct_); - - // Return type: refptr_same - return CefDisplayHandlerCToCpp::Wrap(_retval); -} - -CefRefPtr CefClientCToCpp::GetGeolocationHandler() { - if (CEF_MEMBER_MISSING(struct_, get_geolocation_handler)) - return NULL; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_geolocation_handler_t* _retval = struct_->get_geolocation_handler( - struct_); - - // Return type: refptr_same - return CefGeolocationHandlerCToCpp::Wrap(_retval); -} - -CefRefPtr CefClientCToCpp::GetJSDialogHandler() { - if (CEF_MEMBER_MISSING(struct_, get_jsdialog_handler)) - return NULL; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_jsdialog_handler_t* _retval = struct_->get_jsdialog_handler(struct_); - - // Return type: refptr_same - return CefJSDialogHandlerCToCpp::Wrap(_retval); -} - -CefRefPtr CefClientCToCpp::GetContextMenuHandler() { - if (CEF_MEMBER_MISSING(struct_, get_context_menu_handler)) - return NULL; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_context_menu_handler_t* _retval = struct_->get_context_menu_handler( - struct_); - - // Return type: refptr_same - return CefContextMenuHandlerCToCpp::Wrap(_retval); -} - bool CefClientCToCpp::OnProcessMessageRecieved(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { if (CEF_MEMBER_MISSING(struct_, on_process_message_recieved)) diff --git a/libcef_dll/ctocpp/client_ctocpp.h b/libcef_dll/ctocpp/client_ctocpp.h index 1104e5d34..b31886fee 100644 --- a/libcef_dll/ctocpp/client_ctocpp.h +++ b/libcef_dll/ctocpp/client_ctocpp.h @@ -32,13 +32,15 @@ class CefClientCToCpp virtual ~CefClientCToCpp() {} // CefClient methods + virtual CefRefPtr GetContextMenuHandler() OVERRIDE; + virtual CefRefPtr GetDisplayHandler() OVERRIDE; + virtual CefRefPtr GetFocusHandler() OVERRIDE; + virtual CefRefPtr GetGeolocationHandler() OVERRIDE; + virtual CefRefPtr GetJSDialogHandler() OVERRIDE; + virtual CefRefPtr GetKeyboardHandler() OVERRIDE; virtual CefRefPtr GetLifeSpanHandler() OVERRIDE; virtual CefRefPtr GetLoadHandler() OVERRIDE; virtual CefRefPtr GetRequestHandler() OVERRIDE; - virtual CefRefPtr GetDisplayHandler() OVERRIDE; - virtual CefRefPtr GetGeolocationHandler() OVERRIDE; - virtual CefRefPtr GetJSDialogHandler() OVERRIDE; - virtual CefRefPtr GetContextMenuHandler() OVERRIDE; virtual bool OnProcessMessageRecieved(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; diff --git a/libcef_dll/ctocpp/domnode_ctocpp.cc b/libcef_dll/ctocpp/domnode_ctocpp.cc index 1dfb6a90c..3a0abe7f4 100644 --- a/libcef_dll/ctocpp/domnode_ctocpp.cc +++ b/libcef_dll/ctocpp/domnode_ctocpp.cc @@ -57,6 +57,19 @@ bool CefDOMNodeCToCpp::IsElement() { return _retval?true:false; } +bool CefDOMNodeCToCpp::IsEditable() { + if (CEF_MEMBER_MISSING(struct_, is_editable)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_editable(struct_); + + // Return type: bool + return _retval?true:false; +} + bool CefDOMNodeCToCpp::IsFormControlElement() { if (CEF_MEMBER_MISSING(struct_, is_form_control_element)) return false; diff --git a/libcef_dll/ctocpp/domnode_ctocpp.h b/libcef_dll/ctocpp/domnode_ctocpp.h index 90311251d..6bedac7ba 100644 --- a/libcef_dll/ctocpp/domnode_ctocpp.h +++ b/libcef_dll/ctocpp/domnode_ctocpp.h @@ -35,6 +35,7 @@ class CefDOMNodeCToCpp virtual Type GetType() OVERRIDE; virtual bool IsText() OVERRIDE; virtual bool IsElement() OVERRIDE; + virtual bool IsEditable() OVERRIDE; virtual bool IsFormControlElement() OVERRIDE; virtual CefString GetFormControlElementType() OVERRIDE; virtual bool IsSame(CefRefPtr that) OVERRIDE; diff --git a/libcef_dll/ctocpp/focus_handler_ctocpp.cc b/libcef_dll/ctocpp/focus_handler_ctocpp.cc new file mode 100644 index 000000000..9b2176eef --- /dev/null +++ b/libcef_dll/ctocpp/focus_handler_ctocpp.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/browser_cpptoc.h" +#include "libcef_dll/ctocpp/focus_handler_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +void CefFocusHandlerCToCpp::OnTakeFocus(CefRefPtr browser, + bool next) { + if (CEF_MEMBER_MISSING(struct_, on_take_focus)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + + // Execute + struct_->on_take_focus(struct_, + CefBrowserCppToC::Wrap(browser), + next); +} + +bool CefFocusHandlerCToCpp::OnSetFocus(CefRefPtr browser, + FocusSource source) { + if (CEF_MEMBER_MISSING(struct_, on_set_focus)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return false; + + // Execute + int _retval = struct_->on_set_focus(struct_, + CefBrowserCppToC::Wrap(browser), + source); + + // Return type: bool + return _retval?true:false; +} + +void CefFocusHandlerCToCpp::OnGotFocus(CefRefPtr browser) { + if (CEF_MEMBER_MISSING(struct_, on_got_focus)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + + // Execute + struct_->on_got_focus(struct_, + CefBrowserCppToC::Wrap(browser)); +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/focus_handler_ctocpp.h b/libcef_dll/ctocpp/focus_handler_ctocpp.h new file mode 100644 index 000000000..978237e2b --- /dev/null +++ b/libcef_dll/ctocpp/focus_handler_ctocpp.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_FOCUS_HANDLER_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_FOCUS_HANDLER_CTOCPP_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_focus_handler.h" +#include "include/capi/cef_focus_handler_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed DLL-side only. +class CefFocusHandlerCToCpp + : public CefCToCpp { + public: + explicit CefFocusHandlerCToCpp(cef_focus_handler_t* str) + : CefCToCpp( + str) {} + virtual ~CefFocusHandlerCToCpp() {} + + // CefFocusHandler methods + virtual void OnTakeFocus(CefRefPtr browser, bool next) OVERRIDE; + virtual bool OnSetFocus(CefRefPtr browser, + FocusSource source) OVERRIDE; + virtual void OnGotFocus(CefRefPtr browser) OVERRIDE; +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_FOCUS_HANDLER_CTOCPP_H_ + diff --git a/libcef_dll/ctocpp/keyboard_handler_ctocpp.cc b/libcef_dll/ctocpp/keyboard_handler_ctocpp.cc new file mode 100644 index 000000000..f5d93cb32 --- /dev/null +++ b/libcef_dll/ctocpp/keyboard_handler_ctocpp.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/browser_cpptoc.h" +#include "libcef_dll/ctocpp/keyboard_handler_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +bool CefKeyboardHandlerCToCpp::OnPreKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, CefEventHandle os_event, + bool* is_keyboard_shortcut) { + if (CEF_MEMBER_MISSING(struct_, on_pre_key_event)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return false; + // Verify param: is_keyboard_shortcut; type: bool_byaddr + DCHECK(is_keyboard_shortcut); + if (!is_keyboard_shortcut) + return false; + + // Translate param: is_keyboard_shortcut; type: bool_byaddr + int is_keyboard_shortcutInt = is_keyboard_shortcut?*is_keyboard_shortcut:0; + + // Execute + int _retval = struct_->on_pre_key_event(struct_, + CefBrowserCppToC::Wrap(browser), + &event, + os_event, + &is_keyboard_shortcutInt); + + // Restore param:is_keyboard_shortcut; type: bool_byaddr + if (is_keyboard_shortcut) + *is_keyboard_shortcut = is_keyboard_shortcutInt?true:false; + + // Return type: bool + return _retval?true:false; +} + +bool CefKeyboardHandlerCToCpp::OnKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, CefEventHandle os_event) { + if (CEF_MEMBER_MISSING(struct_, on_key_event)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return false; + + // Execute + int _retval = struct_->on_key_event(struct_, + CefBrowserCppToC::Wrap(browser), + &event, + os_event); + + // Return type: bool + return _retval?true:false; +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/keyboard_handler_ctocpp.h b/libcef_dll/ctocpp/keyboard_handler_ctocpp.h new file mode 100644 index 000000000..32e0f9373 --- /dev/null +++ b/libcef_dll/ctocpp/keyboard_handler_ctocpp.h @@ -0,0 +1,46 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_KEYBOARD_HANDLER_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_KEYBOARD_HANDLER_CTOCPP_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_keyboard_handler.h" +#include "include/capi/cef_keyboard_handler_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed DLL-side only. +class CefKeyboardHandlerCToCpp + : public CefCToCpp { + public: + explicit CefKeyboardHandlerCToCpp(cef_keyboard_handler_t* str) + : CefCToCpp(str) {} + virtual ~CefKeyboardHandlerCToCpp() {} + + // CefKeyboardHandler methods + virtual bool OnPreKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, CefEventHandle os_event, + bool* is_keyboard_shortcut) OVERRIDE; + virtual bool OnKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, CefEventHandle os_event) OVERRIDE; +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_KEYBOARD_HANDLER_CTOCPP_H_ + diff --git a/libcef_dll/ctocpp/render_process_handler_ctocpp.cc b/libcef_dll/ctocpp/render_process_handler_ctocpp.cc index 83fdd7598..bc7bbaa22 100644 --- a/libcef_dll/ctocpp/render_process_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/render_process_handler_ctocpp.cc @@ -11,6 +11,7 @@ // #include "libcef_dll/cpptoc/browser_cpptoc.h" +#include "libcef_dll/cpptoc/domnode_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h" #include "libcef_dll/cpptoc/process_message_cpptoc.h" #include "libcef_dll/cpptoc/v8context_cpptoc.h" @@ -129,6 +130,27 @@ void CefRenderProcessHandlerCToCpp::OnContextReleased( CefV8ContextCppToC::Wrap(context)); } +void CefRenderProcessHandlerCToCpp::OnFocusedNodeChanged( + CefRefPtr browser, CefRefPtr frame, + CefRefPtr node) { + if (CEF_MEMBER_MISSING(struct_, on_focused_node_changed)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + // Unverified params: frame, node + + // Execute + struct_->on_focused_node_changed(struct_, + CefBrowserCppToC::Wrap(browser), + CefFrameCppToC::Wrap(frame), + CefDOMNodeCppToC::Wrap(node)); +} + bool CefRenderProcessHandlerCToCpp::OnProcessMessageRecieved( CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { diff --git a/libcef_dll/ctocpp/render_process_handler_ctocpp.h b/libcef_dll/ctocpp/render_process_handler_ctocpp.h index 06b84ed71..437e86c9d 100644 --- a/libcef_dll/ctocpp/render_process_handler_ctocpp.h +++ b/libcef_dll/ctocpp/render_process_handler_ctocpp.h @@ -42,6 +42,8 @@ class CefRenderProcessHandlerCToCpp CefRefPtr frame, CefRefPtr context) OVERRIDE; virtual void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; + virtual void OnFocusedNodeChanged(CefRefPtr browser, + CefRefPtr frame, CefRefPtr node) OVERRIDE; virtual bool OnProcessMessageRecieved(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index 581094844..72ab5b245 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -60,8 +60,10 @@ #include "libcef_dll/ctocpp/domevent_listener_ctocpp.h" #include "libcef_dll/ctocpp/domvisitor_ctocpp.h" #include "libcef_dll/ctocpp/display_handler_ctocpp.h" +#include "libcef_dll/ctocpp/focus_handler_ctocpp.h" #include "libcef_dll/ctocpp/geolocation_handler_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h" +#include "libcef_dll/ctocpp/keyboard_handler_ctocpp.h" #include "libcef_dll/ctocpp/life_span_handler_ctocpp.h" #include "libcef_dll/ctocpp/load_handler_ctocpp.h" #include "libcef_dll/ctocpp/proxy_handler_ctocpp.h" @@ -162,11 +164,13 @@ CEF_EXPORT void cef_shutdown() { DCHECK_EQ(CefDOMVisitorCToCpp::DebugObjCt, 0); DCHECK_EQ(CefDictionaryValueCppToC::DebugObjCt, 0); DCHECK_EQ(CefDisplayHandlerCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefFocusHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefFrameCppToC::DebugObjCt, 0); DCHECK_EQ(CefGeolocationCallbackCppToC::DebugObjCt, 0); DCHECK_EQ(CefGeolocationHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefJSDialogCallbackCppToC::DebugObjCt, 0); DCHECK_EQ(CefJSDialogHandlerCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefKeyboardHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefLifeSpanHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefListValueCppToC::DebugObjCt, 0); DCHECK_EQ(CefLoadHandlerCToCpp::DebugObjCt, 0); diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index 8ff703b80..44847a8e5 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -31,8 +31,10 @@ #include "libcef_dll/cpptoc/domevent_listener_cpptoc.h" #include "libcef_dll/cpptoc/domvisitor_cpptoc.h" #include "libcef_dll/cpptoc/display_handler_cpptoc.h" +#include "libcef_dll/cpptoc/focus_handler_cpptoc.h" #include "libcef_dll/cpptoc/geolocation_handler_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h" +#include "libcef_dll/cpptoc/keyboard_handler_cpptoc.h" #include "libcef_dll/cpptoc/life_span_handler_cpptoc.h" #include "libcef_dll/cpptoc/load_handler_cpptoc.h" #include "libcef_dll/cpptoc/proxy_handler_cpptoc.h" @@ -154,11 +156,13 @@ CEF_GLOBAL void CefShutdown() { DCHECK_EQ(CefDOMVisitorCppToC::DebugObjCt, 0); DCHECK_EQ(CefDictionaryValueCToCpp::DebugObjCt, 0); DCHECK_EQ(CefDisplayHandlerCppToC::DebugObjCt, 0); + DCHECK_EQ(CefFocusHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefFrameCToCpp::DebugObjCt, 0); DCHECK_EQ(CefGeolocationCallbackCToCpp::DebugObjCt, 0); DCHECK_EQ(CefGeolocationHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefJSDialogCallbackCToCpp::DebugObjCt, 0); DCHECK_EQ(CefJSDialogHandlerCppToC::DebugObjCt, 0); + DCHECK_EQ(CefKeyboardHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefLifeSpanHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefListValueCToCpp::DebugObjCt, 0); DCHECK_EQ(CefLoadHandlerCppToC::DebugObjCt, 0); diff --git a/tests/cefclient/client_app.cpp b/tests/cefclient/client_app.cpp index 2a8829a6e..569876207 100644 --- a/tests/cefclient/client_app.cpp +++ b/tests/cefclient/client_app.cpp @@ -269,6 +269,15 @@ void ClientApp::OnContextReleased(CefRefPtr browser, } } +void ClientApp::OnFocusedNodeChanged(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr node) { + // Execute delegate callbacks. + RenderDelegateSet::iterator it = render_delegates_.begin(); + for (; it != render_delegates_.end(); ++it) + (*it)->OnFocusedNodeChanged(this, browser, frame, node); +} + bool ClientApp::OnProcessMessageRecieved( CefRefPtr browser, CefProcessId source_process, diff --git a/tests/cefclient/client_app.h b/tests/cefclient/client_app.h index 1d219db18..c8a3d6796 100644 --- a/tests/cefclient/client_app.h +++ b/tests/cefclient/client_app.h @@ -43,6 +43,13 @@ class ClientApp : public CefApp, CefRefPtr context) { }; + // Called when the focused node in a frame has changed. + virtual void OnFocusedNodeChanged(CefRefPtr app, + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr node) { + } + // Called when a process message is received. Return true if the message was // handled and should not be passed on to other handlers. RenderDelegates // should check for unique message names to avoid interfering with each @@ -112,6 +119,9 @@ class ClientApp : public CefApp, virtual void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; + virtual void OnFocusedNodeChanged(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr node) OVERRIDE; virtual bool OnProcessMessageRecieved( CefRefPtr browser, CefProcessId source_process, diff --git a/tests/cefclient/client_app_delegates.cpp b/tests/cefclient/client_app_delegates.cpp index 1688a8df6..68009d3c0 100644 --- a/tests/cefclient/client_app_delegates.cpp +++ b/tests/cefclient/client_app_delegates.cpp @@ -3,11 +3,13 @@ // can be found in the LICENSE file. #include "cefclient/client_app.h" +#include "cefclient/client_renderer.h" #include "cefclient/dom_test.h" #include "cefclient/scheme_test.h" // static void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) { + client_renderer::CreateRenderDelegates(delegates); dom_test::CreateRenderDelegates(delegates); } diff --git a/tests/cefclient/client_handler.cpp b/tests/cefclient/client_handler.cpp index bf9cf17d1..4656af20b 100644 --- a/tests/cefclient/client_handler.cpp +++ b/tests/cefclient/client_handler.cpp @@ -11,6 +11,7 @@ #include "include/wrapper/cef_stream_resource_handler.h" #include "cefclient/binding_test.h" #include "cefclient/cefclient.h" +#include "cefclient/client_renderer.h" #include "cefclient/dom_test.h" #include "cefclient/resource_util.h" #include "cefclient/string_util.h" @@ -34,7 +35,7 @@ ClientHandler::ClientHandler() m_ForwardHwnd(NULL), m_StopHwnd(NULL), m_ReloadHwnd(NULL), - m_bFormElementHasFocus(false) { + m_bFocusOnEditableField(false) { CreateProcessMessageDelegates(process_message_delegates_); CreateRequestDelegates(request_delegates_); } @@ -46,6 +47,17 @@ bool ClientHandler::OnProcessMessageRecieved( CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { + // Check for messages from the client renderer. + std::string message_name = message->GetName(); + if (message_name == client_renderer::kFocusedNodeChangedMessage) { + // A message is sent from ClientRenderDelegate to tell us whether the + // currently focused DOM node is editable. Use of |m_bFocusOnEditableField| + // is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent + // but is useful for demonstration purposes. + m_bFocusOnEditableField = message->GetArgumentList()->GetBool(0); + return true; + } + bool handled = false; // Execute delegate callbacks. @@ -58,6 +70,129 @@ bool ClientHandler::OnProcessMessageRecieved( return handled; } +void ClientHandler::OnBeforeContextMenu( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr params, + CefRefPtr model) { + if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) { + // Add a separator if the menu already has items. + if (model->GetCount() > 0) + model->AddSeparator(); + + // Add a "Show DevTools" item to all context menus. + model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools"); + + CefString devtools_url = browser->GetHost()->GetDevToolsURL(true); + if (devtools_url.empty() || + m_OpenDevToolsURLs.find(devtools_url) != m_OpenDevToolsURLs.end()) { + // Disable the menu option if DevTools isn't enabled or if a window is + // already open for the current URL. + model->SetEnabled(CLIENT_ID_SHOW_DEVTOOLS, false); + } + + // Test context menu features. + BuildTestMenu(model); + } +} + +bool ClientHandler::OnContextMenuCommand( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr params, + int command_id, + EventFlags event_flags) { + switch (command_id) { + case CLIENT_ID_SHOW_DEVTOOLS: + ShowDevTools(browser); + return true; + default: // Allow default handling, if any. + return ExecuteTestMenu(command_id); + } +} + +void ClientHandler::OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) { + REQUIRE_UI_THREAD(); + SetLoading(isLoading); + SetNavState(canGoBack, canGoForward); +} + +bool ClientHandler::OnConsoleMessage(CefRefPtr browser, + const CefString& message, + const CefString& source, + int line) { + REQUIRE_UI_THREAD(); + + bool first_message; + std::string logFile; + + { + AutoLock lock_scope(this); + + first_message = m_LogFile.empty(); + if (first_message) { + std::stringstream ss; + ss << AppGetWorkingDirectory(); +#if defined(OS_WIN) + ss << "\\"; +#else + ss << "/"; +#endif + ss << "console.log"; + m_LogFile = ss.str(); + } + logFile = m_LogFile; + } + + FILE* file = fopen(logFile.c_str(), "a"); + if (file) { + std::stringstream ss; + ss << "Message: " << std::string(message) << "\r\nSource: " << + std::string(source) << "\r\nLine: " << line << + "\r\n-----------------------\r\n"; + fputs(ss.str().c_str(), file); + fclose(file); + + if (first_message) + SendNotification(NOTIFY_CONSOLE_MESSAGE); + } + + return false; +} + +void ClientHandler::OnRequestGeolocationPermission( + CefRefPtr browser, + const CefString& requesting_url, + int request_id, + CefRefPtr callback) { + // Allow geolocation access from all websites. + callback->Continue(true); +} + +bool ClientHandler::OnPreKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, + CefEventHandle os_event, + bool* is_keyboard_shortcut) { + ASSERT(m_bFocusOnEditableField == event.focus_on_editable_field); + if (!event.focus_on_editable_field && event.windows_key_code == 0x20) { + // Special handling for the space character when an input element does not + // have focus. Handling the event in OnPreKeyEvent() keeps the event from + // being processed in the renderer. If we instead handled the event in the + // OnKeyEvent() method the space key would cause the window to scroll in + // addition to showing the alert box. + if (event.type == KEYEVENT_RAWKEYDOWN) { + browser->GetMainFrame()->ExecuteJavaScript( + "alert('You pressed the space bar!');", "", 0); + } + return true; + } + + return false; +} + void ClientHandler::OnAfterCreated(CefRefPtr browser) { REQUIRE_UI_THREAD(); @@ -194,108 +329,6 @@ CefRefPtr ClientHandler::GetResourceHandler( return handler; } -void ClientHandler::OnLoadingStateChange(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) { - REQUIRE_UI_THREAD(); - SetLoading(isLoading); - SetNavState(canGoBack, canGoForward); -} - -bool ClientHandler::OnConsoleMessage(CefRefPtr browser, - const CefString& message, - const CefString& source, - int line) { - REQUIRE_UI_THREAD(); - - bool first_message; - std::string logFile; - - { - AutoLock lock_scope(this); - - first_message = m_LogFile.empty(); - if (first_message) { - std::stringstream ss; - ss << AppGetWorkingDirectory(); -#if defined(OS_WIN) - ss << "\\"; -#else - ss << "/"; -#endif - ss << "console.log"; - m_LogFile = ss.str(); - } - logFile = m_LogFile; - } - - FILE* file = fopen(logFile.c_str(), "a"); - if (file) { - std::stringstream ss; - ss << "Message: " << std::string(message) << "\r\nSource: " << - std::string(source) << "\r\nLine: " << line << - "\r\n-----------------------\r\n"; - fputs(ss.str().c_str(), file); - fclose(file); - - if (first_message) - SendNotification(NOTIFY_CONSOLE_MESSAGE); - } - - return false; -} - -void ClientHandler::OnRequestGeolocationPermission( - CefRefPtr browser, - const CefString& requesting_url, - int request_id, - CefRefPtr callback) { - // Allow geolocation access from all websites. - callback->Continue(true); -} - -void ClientHandler::OnBeforeContextMenu( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - CefRefPtr model) { - if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) { - // Add a separator if the menu already has items. - if (model->GetCount() > 0) - model->AddSeparator(); - - // Add a "Show DevTools" item to all context menus. - model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools"); - - CefString devtools_url = browser->GetHost()->GetDevToolsURL(true); - if (devtools_url.empty() || - m_OpenDevToolsURLs.find(devtools_url) != m_OpenDevToolsURLs.end()) { - // Disable the menu option if DevTools isn't enabled or if a window is - // already open for the current URL. - model->SetEnabled(CLIENT_ID_SHOW_DEVTOOLS, false); - } - - // Test context menu features. - BuildTestMenu(model); - } -} - -bool ClientHandler::OnContextMenuCommand( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - int command_id, - EventFlags event_flags) { - switch (command_id) { - case CLIENT_ID_SHOW_DEVTOOLS: - ShowDevTools(browser); - return true; - default: // Allow default handling, if any. - return ExecuteTestMenu(command_id); - } -} - void ClientHandler::SetMainHwnd(CefWindowHandle hwnd) { AutoLock lock_scope(this); m_MainHwnd = hwnd; diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index ac5846488..dd28f9def 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -20,12 +20,13 @@ // ClientHandler implementation. class ClientHandler : public CefClient, - public CefLifeSpanHandler, - public CefLoadHandler, - public CefRequestHandler, + public CefContextMenuHandler, public CefDisplayHandler, public CefGeolocationHandler, - public CefContextMenuHandler { + public CefKeyboardHandler, + public CefLifeSpanHandler, + public CefLoadHandler, + public CefRequestHandler { public: // Interface for process message delegates. Do not perform work in the // RenderDelegate constructor. @@ -67,6 +68,18 @@ class ClientHandler : public CefClient, virtual ~ClientHandler(); // CefClient methods + virtual CefRefPtr GetContextMenuHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetDisplayHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetGeolocationHandler() OVERRIDE { + return this; + } + virtual CefRefPtr GetKeyboardHandler() OVERRIDE { + return this; + } virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { return this; } @@ -76,48 +89,21 @@ class ClientHandler : public CefClient, virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } - virtual CefRefPtr GetDisplayHandler() OVERRIDE { - return this; - } - virtual CefRefPtr GetGeolocationHandler() OVERRIDE { - return this; - } - virtual CefRefPtr GetContextMenuHandler() OVERRIDE { - return this; - } virtual bool OnProcessMessageRecieved(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; - // CefLifeSpanHandler methods - virtual bool OnBeforePopup(CefRefPtr parentBrowser, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - const CefString& url, - CefRefPtr& client, - CefBrowserSettings& settings) OVERRIDE; - virtual void OnAfterCreated(CefRefPtr browser) OVERRIDE; - virtual bool DoClose(CefRefPtr browser) OVERRIDE; - virtual void OnBeforeClose(CefRefPtr browser) OVERRIDE; - - // CefLoadHandler methods - virtual void OnLoadStart(CefRefPtr browser, - CefRefPtr frame) OVERRIDE; - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) OVERRIDE; - virtual void OnLoadError(CefRefPtr browser, - CefRefPtr frame, - ErrorCode errorCode, - const CefString& errorText, - const CefString& failedUrl) OVERRIDE; - - // CefRequestHandler methods - virtual CefRefPtr GetResourceHandler( - CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) OVERRIDE; + // CefContextMenuHandler methods + virtual void OnBeforeContextMenu(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr params, + CefRefPtr model) OVERRIDE; + virtual bool OnContextMenuCommand(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr params, + int command_id, + EventFlags event_flags) OVERRIDE; // CefDisplayHandler methods virtual void OnLoadingStateChange(CefRefPtr browser, @@ -141,16 +127,34 @@ class ClientHandler : public CefClient, int request_id, CefRefPtr callback) OVERRIDE; - // CefContextMenuHandler methods - virtual void OnBeforeContextMenu(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - CefRefPtr model) OVERRIDE; - virtual bool OnContextMenuCommand(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - int command_id, - EventFlags event_flags) OVERRIDE; + // CefKeyboardHandler methods + virtual bool OnPreKeyEvent(CefRefPtr browser, + const CefKeyEvent& event, + CefEventHandle os_event, + bool* is_keyboard_shortcut) OVERRIDE; + + // CefLifeSpanHandler methods + virtual void OnAfterCreated(CefRefPtr browser) OVERRIDE; + virtual bool DoClose(CefRefPtr browser) OVERRIDE; + virtual void OnBeforeClose(CefRefPtr browser) OVERRIDE; + + // CefLoadHandler methods + virtual void OnLoadStart(CefRefPtr browser, + CefRefPtr frame) OVERRIDE; + virtual void OnLoadEnd(CefRefPtr browser, + CefRefPtr frame, + int httpStatusCode) OVERRIDE; + virtual void OnLoadError(CefRefPtr browser, + CefRefPtr frame, + ErrorCode errorCode, + const CefString& errorText, + const CefString& failedUrl) OVERRIDE; + + // CefRequestHandler methods + virtual CefRefPtr GetResourceHandler( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request) OVERRIDE; void SetMainHwnd(CefWindowHandle hwnd); CefWindowHandle GetMainHwnd() { return m_MainHwnd; } @@ -224,8 +228,8 @@ class ClientHandler : public CefClient, // Support for downloading files. std::string m_LastDownloadFile; - // True if a form element currently has focus - bool m_bFormElementHasFocus; + // True if an editable field currently has focus. + bool m_bFocusOnEditableField; // Registered delegates. ProcessMessageDelegateSet process_message_delegates_; diff --git a/tests/cefclient/client_handler_gtk.cpp b/tests/cefclient/client_handler_gtk.cpp index 8842d4380..1b60df7e6 100644 --- a/tests/cefclient/client_handler_gtk.cpp +++ b/tests/cefclient/client_handler_gtk.cpp @@ -8,18 +8,6 @@ #include "include/cef_browser.h" #include "include/cef_frame.h" -// ClientHandler::ClientLifeSpanHandler implementation -bool ClientHandler::OnBeforePopup(CefRefPtr parentBrowser, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - const CefString& url, - CefRefPtr& client, - CefBrowserSettings& settings) { - REQUIRE_UI_THREAD(); - - return false; -} - void ClientHandler::OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) { diff --git a/tests/cefclient/client_handler_mac.mm b/tests/cefclient/client_handler_mac.mm index 8ddb91290..8df19d0c7 100644 --- a/tests/cefclient/client_handler_mac.mm +++ b/tests/cefclient/client_handler_mac.mm @@ -9,19 +9,6 @@ #include "include/cef_frame.h" #include "cefclient/cefclient.h" -// ClientHandler::ClientLifeSpanHandler implementation - -bool ClientHandler::OnBeforePopup(CefRefPtr parentBrowser, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - const CefString& url, - CefRefPtr& client, - CefBrowserSettings& settings) { - REQUIRE_UI_THREAD(); - - return false; -} - void ClientHandler::OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) { diff --git a/tests/cefclient/client_handler_win.cpp b/tests/cefclient/client_handler_win.cpp index 49081804b..7be458666 100644 --- a/tests/cefclient/client_handler_win.cpp +++ b/tests/cefclient/client_handler_win.cpp @@ -8,17 +8,6 @@ #include "include/cef_frame.h" #include "cefclient/resource.h" -bool ClientHandler::OnBeforePopup(CefRefPtr parentBrowser, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - const CefString& url, - CefRefPtr& client, - CefBrowserSettings& settings) { - REQUIRE_UI_THREAD(); - - return false; -} - void ClientHandler::OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) { diff --git a/tests/cefclient/client_renderer.cpp b/tests/cefclient/client_renderer.cpp new file mode 100644 index 000000000..17b5a43f3 --- /dev/null +++ b/tests/cefclient/client_renderer.cpp @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +#include "cefclient/client_renderer.h" + +#include +#include + +#include "include/cef_dom.h" +#include "cefclient/util.h" + +namespace client_renderer { + +const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged"; + +namespace { + +class ClientRenderDelegate : public ClientApp::RenderDelegate { + public: + ClientRenderDelegate() + : last_node_is_editable_(false) { + } + + virtual void OnFocusedNodeChanged(CefRefPtr app, + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr node) OVERRIDE { + bool is_editable = (node.get() && node->IsEditable()); + if (is_editable != last_node_is_editable_) { + // Notify the browser of the change in focused element type. + last_node_is_editable_ = is_editable; + CefRefPtr message = + CefProcessMessage::Create(kFocusedNodeChangedMessage); + message->GetArgumentList()->SetBool(0, is_editable); + browser->SendProcessMessage(PID_BROWSER, message); + } + } + + private: + bool last_node_is_editable_; + + IMPLEMENT_REFCOUNTING(ClientRenderDelegate); +}; + +} // namespace + +void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) { + delegates.insert(new ClientRenderDelegate); +} + +} // namespace client_renderer diff --git a/tests/cefclient/client_renderer.h b/tests/cefclient/client_renderer.h new file mode 100644 index 000000000..37b08408d --- /dev/null +++ b/tests/cefclient/client_renderer.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +#ifndef CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ +#define CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ +#pragma once + +#include "include/cef_base.h" +#include "cefclient/client_app.h" + +namespace client_renderer { + +// Message sent when the focused node changes. +extern const char kFocusedNodeChangedMessage[]; + +// Create the render delegate. +void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates); + +} // namespace client_renderer + +#endif // CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ diff --git a/tools/cef_parser.py b/tools/cef_parser.py index 722ac4b19..4bc3a7940 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -372,6 +372,7 @@ _simpletypes = { 'bool' : ['int', '0'], 'char* const': ['char* const', 'NULL'], 'CefCursorHandle' : ['cef_cursor_handle_t', 'NULL'], + 'CefEventHandle' : ['cef_event_handle_t', 'NULL'], 'CefWindowHandle' : ['cef_window_handle_t', 'NULL'], 'CefRect' : ['cef_rect_t', 'CefRect()'], 'CefThreadId' : ['cef_thread_id_t', 'TID_UI'],