diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 412463a14..53a68b757 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -22,6 +22,7 @@ #include "base/bind_helpers.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/web_contents/web_contents_impl.h" +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" @@ -798,6 +799,15 @@ bool CefBrowserHostImpl::HandleContextMenu( return menu_creator_->CreateContextMenu(params); } +void CefBrowserHostImpl::HandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + // Check to see if event should be ignored. + if (event.skip_in_browser) + return; + + PlatformHandleKeyboardEvent(event); +} + bool CefBrowserHostImpl::ShouldCreateWebContents( content::WebContents* web_contents, int route_id, diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 5259f61e2..5a25dcb2d 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -30,6 +30,10 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +namespace content { +struct NativeWebKeyboardEvent; +} + namespace net { class URLRequest; } @@ -195,6 +199,8 @@ class CefBrowserHostImpl : public CefBrowserHost, virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; virtual bool HandleContextMenu(const content::ContextMenuParams& params) OVERRIDE; + virtual void HandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) OVERRIDE; virtual bool ShouldCreateWebContents( content::WebContents* web_contents, int route_id, @@ -211,7 +217,7 @@ class CefBrowserHostImpl : public CefBrowserHost, OVERRIDE; virtual void RunFileChooser( content::WebContents* tab, - const content::FileChooserParams& params) OVERRIDE; + const content::FileChooserParams& params) OVERRIDE; virtual void UpdatePreferredSize(content::WebContents* source, const gfx::Size& pref_size) OVERRIDE; @@ -295,6 +301,10 @@ class CefBrowserHostImpl : public CefBrowserHost, CefWindowHandle PlatformGetWindowHandle(); // Open the specified text in the default text editor. bool PlatformViewText(const std::string& text); + // Forward the keyboard event to the application or frame window to allow + // processing of shortcut keys. + void PlatformHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event); void OnAddressChange(CefRefPtr frame, const GURL& url); diff --git a/libcef/browser/browser_host_impl_gtk.cc b/libcef/browser/browser_host_impl_gtk.cc index d759e6ffe..965b9019e 100644 --- a/libcef/browser/browser_host_impl_gtk.cc +++ b/libcef/browser/browser_host_impl_gtk.cc @@ -27,40 +27,6 @@ void window_destroyed(GtkWidget* widget, CefBrowserHostImpl* browser) { } // namespace -bool CefBrowserHostImpl::PlatformViewText(const std::string& text) { - CEF_REQUIRE_UIT(); - - char buff[] = "/tmp/CEFSourceXXXXXX"; - int fd = mkstemp(buff); - - if (fd == -1) - return false; - - FILE* srcOutput = fdopen(fd, "w+"); - if (!srcOutput) - return false; - - if (fputs(text.c_str(), srcOutput) < 0) { - fclose(srcOutput); - return false; - } - - fclose(srcOutput); - - std::string newName(buff); - newName.append(".txt"); - if (rename(buff, newName.c_str()) != 0) - return false; - - std::string openCommand("xdg-open "); - openCommand += newName; - - if (system(openCommand.c_str()) != 0) - return false; - - return true; -} - bool CefBrowserHostImpl::PlatformCreateWindow() { GtkWidget* window; GtkWidget* parentView = window_info_.parent_widget; @@ -126,3 +92,42 @@ void CefBrowserHostImpl::PlatformSizeTo(int width, int height) { CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() { return window_info_.widget; } + +bool CefBrowserHostImpl::PlatformViewText(const std::string& text) { + CEF_REQUIRE_UIT(); + + char buff[] = "/tmp/CEFSourceXXXXXX"; + int fd = mkstemp(buff); + + if (fd == -1) + return false; + + FILE* srcOutput = fdopen(fd, "w+"); + if (!srcOutput) + return false; + + if (fputs(text.c_str(), srcOutput) < 0) { + fclose(srcOutput); + return false; + } + + fclose(srcOutput); + + std::string newName(buff); + newName.append(".txt"); + if (rename(buff, newName.c_str()) != 0) + return false; + + std::string openCommand("xdg-open "); + openCommand += newName; + + if (system(openCommand.c_str()) != 0) + return false; + + return true; +} + +void CefBrowserHostImpl::PlatformHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + // TODO(cef): Is something required here to handle shortcut keys? +} diff --git a/libcef/browser/browser_host_impl_mac.mm b/libcef/browser/browser_host_impl_mac.mm index c578aaae5..58025f09c 100644 --- a/libcef/browser/browser_host_impl_mac.mm +++ b/libcef/browser/browser_host_impl_mac.mm @@ -7,6 +7,7 @@ #import +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/rect.h" @@ -124,3 +125,10 @@ void CefBrowserHostImpl::PlatformSizeTo(int width, int height) { CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() { return window_info_.view; } + +void CefBrowserHostImpl::PlatformHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + // Give the top level menu equivalents a chance to handle the event. + if ([event.os_event type] == NSKeyDown) + [[NSApp mainMenu] performKeyEquivalent:event.os_event]; +} diff --git a/libcef/browser/browser_host_impl_win.cc b/libcef/browser/browser_host_impl_win.cc index b968e0965..870475f20 100644 --- a/libcef/browser/browser_host_impl_win.cc +++ b/libcef/browser/browser_host_impl_win.cc @@ -14,6 +14,7 @@ #include "libcef/browser/thread_util.h" #include "base/win/windows_version.h" +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents_view.h" #include "ui/base/win/hwnd_util.h" @@ -254,3 +255,11 @@ bool CefBrowserHostImpl::PlatformViewText(const std::string& text) { return true; } + +void CefBrowserHostImpl::PlatformHandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + // Any unhandled keyboard/character messages are sent to DefWindowProc so that + // shortcut keys work correctly. + DefWindowProc(event.os_event.hwnd, event.os_event.message, + event.os_event.wParam, event.os_event.lParam); +}