Fix keyboard shortcut handling on Windows (issue #615) and Mac (issue #618).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@675 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-06-07 17:38:12 +00:00
parent f74e3f4bc9
commit a9449d612c
5 changed files with 77 additions and 35 deletions

View File

@ -22,6 +22,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_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_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
@ -798,6 +799,15 @@ bool CefBrowserHostImpl::HandleContextMenu(
return menu_creator_->CreateContextMenu(params); 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( bool CefBrowserHostImpl::ShouldCreateWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
int route_id, int route_id,

View File

@ -30,6 +30,10 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
namespace content {
struct NativeWebKeyboardEvent;
}
namespace net { namespace net {
class URLRequest; class URLRequest;
} }
@ -195,6 +199,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
virtual bool HandleContextMenu(const content::ContextMenuParams& params) virtual bool HandleContextMenu(const content::ContextMenuParams& params)
OVERRIDE; OVERRIDE;
virtual void HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual bool ShouldCreateWebContents( virtual bool ShouldCreateWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
int route_id, int route_id,
@ -211,7 +217,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
OVERRIDE; OVERRIDE;
virtual void RunFileChooser( virtual void RunFileChooser(
content::WebContents* tab, content::WebContents* tab,
const content::FileChooserParams& params) OVERRIDE; const content::FileChooserParams& params) OVERRIDE;
virtual void UpdatePreferredSize(content::WebContents* source, virtual void UpdatePreferredSize(content::WebContents* source,
const gfx::Size& pref_size) OVERRIDE; const gfx::Size& pref_size) OVERRIDE;
@ -295,6 +301,10 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefWindowHandle PlatformGetWindowHandle(); CefWindowHandle PlatformGetWindowHandle();
// Open the specified text in the default text editor. // Open the specified text in the default text editor.
bool PlatformViewText(const std::string& text); 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<CefFrame> frame, void OnAddressChange(CefRefPtr<CefFrame> frame,
const GURL& url); const GURL& url);

View File

@ -27,40 +27,6 @@ void window_destroyed(GtkWidget* widget, CefBrowserHostImpl* browser) {
} // namespace } // 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() { bool CefBrowserHostImpl::PlatformCreateWindow() {
GtkWidget* window; GtkWidget* window;
GtkWidget* parentView = window_info_.parent_widget; GtkWidget* parentView = window_info_.parent_widget;
@ -126,3 +92,42 @@ void CefBrowserHostImpl::PlatformSizeTo(int width, int height) {
CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() { CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() {
return window_info_.widget; 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?
}

View File

@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#import "ui/base/cocoa/underlay_opengl_hosting_window.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
@ -124,3 +125,10 @@ void CefBrowserHostImpl::PlatformSizeTo(int width, int height) {
CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() { CefWindowHandle CefBrowserHostImpl::PlatformGetWindowHandle() {
return window_info_.view; 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];
}

View File

@ -14,6 +14,7 @@
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "base/win/windows_version.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 "content/public/browser/web_contents_view.h"
#include "ui/base/win/hwnd_util.h" #include "ui/base/win/hwnd_util.h"
@ -254,3 +255,11 @@ bool CefBrowserHostImpl::PlatformViewText(const std::string& text) {
return true; 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);
}