summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 20:50:52 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 20:50:52 +0000
commitd74cec8902c565f0045d2747a7091f4d2931f57b (patch)
tree0b62b664e5720e52b7680ac4411813d11b7f45aa /chrome/common
parent1040cb10711a7a19051576eb96f33fc3632088f3 (diff)
downloadchromium_src-d74cec8902c565f0045d2747a7091f4d2931f57b.zip
chromium_src-d74cec8902c565f0045d2747a7091f4d2931f57b.tar.gz
chromium_src-d74cec8902c565f0045d2747a7091f4d2931f57b.tar.bz2
RenderWidgetHost now only accepts a new NativeWebKeyboardEvent which owns a copy of the native os event.
Only the WebKeyboardEvent is sent over the IPC barrier, but the full structure passed to the unhandled key event handler. BUG=4772 Review URL: http://codereview.chromium.org/40065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/common.scons2
-rw-r--r--chrome/common/common.vcproj8
-rw-r--r--chrome/common/native_web_keyboard_event.h50
-rw-r--r--chrome/common/native_web_keyboard_event_linux.cc53
-rw-r--r--chrome/common/native_web_keyboard_event_mac.mm37
-rw-r--r--chrome/common/native_web_keyboard_event_win.cc41
6 files changed, 191 insertions, 0 deletions
diff --git a/chrome/common/common.scons b/chrome/common/common.scons
index 7ebad2e..b7fd21e 100644
--- a/chrome/common/common.scons
+++ b/chrome/common/common.scons
@@ -162,6 +162,8 @@ input_files = ChromeFileList([
'message_router.cc',
'message_router.h',
'mru_cache.h',
+ 'native_web_keyboard_event.h',
+ 'native_web_keyboard_event_linux.cc',
'navigation_types.h',
'notification_details.h',
'notification_registrar.cc',
diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj
index e409d1d..53ac35f 100644
--- a/chrome/common/common.vcproj
+++ b/chrome/common/common.vcproj
@@ -562,6 +562,14 @@
>
</File>
<File
+ RelativePath=".\native_web_keyboard_event.h"
+ >
+ </File>
+ <File
+ RelativePath=".\native_web_keyboard_event_win.cc"
+ >
+ </File>
+ <File
RelativePath=".\notification_details.h"
>
</File>
diff --git a/chrome/common/native_web_keyboard_event.h b/chrome/common/native_web_keyboard_event.h
new file mode 100644
index 0000000..f4c22c0
--- /dev/null
+++ b/chrome/common/native_web_keyboard_event.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2009 The Chromium 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 CHROME_COMMON_NATIVE_WEB_KEYBOARD_EVENT_H_
+#define CHROME_COMMON_NATIVE_WEB_KEYBOARD_EVENT_H_
+
+#include "base/basictypes.h"
+#include "webkit/glue/webinputevent.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#elif defined(OS_MACOSX)
+#ifdef __OBJC__
+@class NSEvent;
+#else
+class NSEvent;
+#endif // __OBJC__
+#elif defined(OS_LINUX)
+#include <gdk/gdk.h>
+#endif
+
+// Owns a platform specific event; used to pass own and pass event through
+// platform independent code.
+struct NativeWebKeyboardEvent : public WebKeyboardEvent {
+ NativeWebKeyboardEvent();
+
+#if defined(OS_WIN)
+ NativeWebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#elif defined(OS_MACOSX)
+ explicit NativeWebKeyboardEvent(NSEvent *event);
+#elif defined(OS_LINUX)
+ explicit NativeWebKeyboardEvent(const GdkEventKey* event);
+#endif
+
+ NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event);
+ ~NativeWebKeyboardEvent();
+
+ NativeWebKeyboardEvent& operator=(const NativeWebKeyboardEvent& event);
+
+#if defined(OS_WIN)
+ MSG os_event;
+#elif defined(OS_MACOSX)
+ NSEvent* os_event;
+#elif defined(OS_LINUX)
+ GdkEventKey* os_event;
+#endif
+};
+
+#endif // CHROME_COMMON_NATIVE_WEB_KEYBOARD_EVENT_H_
diff --git a/chrome/common/native_web_keyboard_event_linux.cc b/chrome/common/native_web_keyboard_event_linux.cc
new file mode 100644
index 0000000..744ba3d
--- /dev/null
+++ b/chrome/common/native_web_keyboard_event_linux.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2009 The Chromium 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 "chrome/common/native_web_keyboard_event.h"
+
+namespace {
+
+void CopyEventTo(const GdkEventKey* in, GdkEventKey** out) {
+ if (in) {
+ *out = reinterpret_cast<GdkEventKey*>(
+ gdk_event_copy(
+ reinterpret_cast<GdkEvent*>(const_cast<GdkEventKey*>(in))));
+ } else {
+ *out = NULL;
+ }
+}
+
+void FreeEvent(GdkEventKey* event) {
+ if (event) {
+ gdk_event_free(reinterpret_cast<GdkEvent*>(event));
+ }
+}
+
+} // namespace
+
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent()
+ : os_event(NULL) {
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(const GdkEventKey* native_event)
+ : WebKeyboardEvent(native_event) {
+ CopyEventTo(native_event, &os_event);
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(
+ const NativeWebKeyboardEvent& other) : WebKeyboardEvent(other) {
+ CopyEventTo(other.os_event, &os_event);
+}
+
+NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
+ const NativeWebKeyboardEvent& other) {
+ WebKeyboardEvent::operator=(other);
+
+ FreeEvent(os_event);
+ CopyEventTo(other.os_event, &os_event);
+ return *this;
+}
+
+NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
+ FreeEvent(os_event);
+}
diff --git a/chrome/common/native_web_keyboard_event_mac.mm b/chrome/common/native_web_keyboard_event_mac.mm
new file mode 100644
index 0000000..4e1b9b5
--- /dev/null
+++ b/chrome/common/native_web_keyboard_event_mac.mm
@@ -0,0 +1,37 @@
+// Copyright (c) 2009 The Chromium 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 "chrome/common/native_web_keyboard_event.h"
+
+#import <AppKit/AppKit.h>
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent()
+ : os_event(NULL) {
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(NSEvent* event)
+ : WebKeyboardEvent(event),
+ os_event([event retain]) {
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(
+ const NativeWebKeyboardEvent& other)
+ : WebKeyboardEvent(other),
+ os_event([other.os_event retain]) {
+}
+
+NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
+ const NativeWebKeyboardEvent& other) {
+ WebKeyboardEvent::operator=(other);
+
+ NSObject* previous = os_event;
+ os_event = [other.os_event retain];
+ [previous release];
+
+ return *this;
+}
+
+NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
+ [os_event release];
+}
diff --git a/chrome/common/native_web_keyboard_event_win.cc b/chrome/common/native_web_keyboard_event_win.cc
new file mode 100644
index 0000000..0e2e11f
--- /dev/null
+++ b/chrome/common/native_web_keyboard_event_win.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2009 The Chromium 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 "chrome/common/native_web_keyboard_event.h"
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent() {
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(
+ HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
+ : WebKeyboardEvent(hwnd, message, wparam, lparam) {
+ os_event.hwnd = hwnd;
+ os_event.message = message;
+ os_event.wParam = wparam;
+ os_event.lParam = lparam;
+}
+
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(
+ const NativeWebKeyboardEvent& other)
+ : WebKeyboardEvent(other) {
+ os_event.hwnd = other.os_event.hwnd;
+ os_event.message = other.os_event.message;
+ os_event.wParam = other.os_event.wParam;
+ os_event.lParam = other.os_event.lParam;
+}
+
+NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
+ const NativeWebKeyboardEvent& other) {
+ WebKeyboardEvent::operator=(other);
+
+ os_event.hwnd = other.os_event.hwnd;
+ os_event.message = other.os_event.message;
+ os_event.wParam = other.os_event.wParam;
+ os_event.lParam = other.os_event.lParam;
+ return *this;
+}
+
+NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
+ // Noop under windows
+}