summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 18:27:44 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-03 18:27:44 +0000
commit9958c8ab6f76da35fbf30272b2b82d26bf823230 (patch)
treecab2771b559c9c791e0e4afd0d55fbe218b58e38 /webkit
parentdf064db3c7284f8b3b7330dd332584e0aa462483 (diff)
downloadchromium_src-9958c8ab6f76da35fbf30272b2b82d26bf823230.zip
chromium_src-9958c8ab6f76da35fbf30272b2b82d26bf823230.tar.gz
chromium_src-9958c8ab6f76da35fbf30272b2b82d26bf823230.tar.bz2
Reverting 10794.
Review URL: http://codereview.chromium.org/40027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/SConscript1
-rw-r--r--webkit/glue/event_conversion.cc171
-rw-r--r--webkit/glue/glue.vcproj8
-rw-r--r--webkit/glue/webinputevent.h102
-rw-r--r--webkit/glue/webinputevent_linux.cc35
-rw-r--r--webkit/glue/webinputevent_mac.mm95
-rw-r--r--webkit/glue/webinputevent_util.cc120
-rw-r--r--webkit/glue/webinputevent_util.h18
-rw-r--r--webkit/glue/webinputevent_win.cc30
-rw-r--r--webkit/glue/webview_impl.cc48
-rw-r--r--webkit/glue/webwidget_impl.cc1
-rw-r--r--webkit/tools/test_shell/event_sending_controller.cc34
-rw-r--r--webkit/tools/test_shell/keyboard_unittest.cc15
-rw-r--r--webkit/tools/test_shell/mac/webwidget_host.mm10
-rw-r--r--webkit/tools/test_shell/test_shell.gyp14
-rw-r--r--webkit/tools/test_shell/webwidget_host_gtk.cc10
16 files changed, 314 insertions, 398 deletions
diff --git a/webkit/glue/SConscript b/webkit/glue/SConscript
index a06bfe1..8e2bdf3 100644
--- a/webkit/glue/SConscript
+++ b/webkit/glue/SConscript
@@ -127,7 +127,6 @@ elif env.Bit('linux'):
'plugins/webplugin_delegate_impl_gtk.cc',
'webcursor_gtk.cc',
'webinputevent_linux.cc',
- 'webinputevent_util.cc',
'webkit_glue_gtk.cc',
])
elif env.Bit('mac'):
diff --git a/webkit/glue/event_conversion.cc b/webkit/glue/event_conversion.cc
index 39cdc90..0902778 100644
--- a/webkit/glue/event_conversion.cc
+++ b/webkit/glue/event_conversion.cc
@@ -22,7 +22,6 @@ MSVC_POP_WARNING();
#include "base/gfx/point.h"
#include "base/logging.h"
#include "webkit/glue/event_conversion.h"
-#include "webkit/glue/glue_util.h"
#include "webkit/glue/webinputevent.h"
#include "webkit/glue/webkit_glue.h"
@@ -142,8 +141,6 @@ static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType(
return PlatformKeyboardEvent::KeyUp;
case WebInputEvent::KEY_DOWN:
return PlatformKeyboardEvent::KeyDown;
- case WebInputEvent::RAW_KEY_DOWN:
- return PlatformKeyboardEvent::RawKeyDown;
case WebInputEvent::CHAR:
return PlatformKeyboardEvent::Char;
default:
@@ -152,21 +149,175 @@ static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType(
return PlatformKeyboardEvent::KeyDown;
}
-MakePlatformKeyboardEvent::MakePlatformKeyboardEvent(
- const WebKeyboardEvent& e) {
+static inline String ToSingleCharacterString(UChar c) {
+ return String(&c, 1);
+}
+
+#if !defined(OS_MACOSX)
+// This function is not used on Mac OS X, and gcc complains.
+static String GetKeyIdentifierForWindowsKeyCode(unsigned short keyCode) {
+ switch (keyCode) {
+ case VKEY_MENU:
+ return "Alt";
+ case VKEY_CONTROL:
+ return "Control";
+ case VKEY_SHIFT:
+ return "Shift";
+ case VKEY_CAPITAL:
+ return "CapsLock";
+ case VKEY_LWIN:
+ case VKEY_RWIN:
+ return "Win";
+ case VKEY_CLEAR:
+ return "Clear";
+ case VKEY_DOWN:
+ return "Down";
+ // "End"
+ case VKEY_END:
+ return "End";
+ // "Enter"
+ case VKEY_RETURN:
+ return "Enter";
+ case VKEY_EXECUTE:
+ return "Execute";
+ case VKEY_F1:
+ return "F1";
+ case VKEY_F2:
+ return "F2";
+ case VKEY_F3:
+ return "F3";
+ case VKEY_F4:
+ return "F4";
+ case VKEY_F5:
+ return "F5";
+ case VKEY_F6:
+ return "F6";
+ case VKEY_F7:
+ return "F7";
+ case VKEY_F8:
+ return "F8";
+ case VKEY_F9:
+ return "F9";
+ case VKEY_F10:
+ return "F11";
+ case VKEY_F12:
+ return "F12";
+ case VKEY_F13:
+ return "F13";
+ case VKEY_F14:
+ return "F14";
+ case VKEY_F15:
+ return "F15";
+ case VKEY_F16:
+ return "F16";
+ case VKEY_F17:
+ return "F17";
+ case VKEY_F18:
+ return "F18";
+ case VKEY_F19:
+ return "F19";
+ case VKEY_F20:
+ return "F20";
+ case VKEY_F21:
+ return "F21";
+ case VKEY_F22:
+ return "F22";
+ case VKEY_F23:
+ return "F23";
+ case VKEY_F24:
+ return "F24";
+ case VKEY_HELP:
+ return "Help";
+ case VKEY_HOME:
+ return "Home";
+ case VKEY_INSERT:
+ return "Insert";
+ case VKEY_LEFT:
+ return "Left";
+ case VKEY_NEXT:
+ return "PageDown";
+ case VKEY_PRIOR:
+ return "PageUp";
+ case VKEY_PAUSE:
+ return "Pause";
+ case VKEY_SNAPSHOT:
+ return "PrintScreen";
+ case VKEY_RIGHT:
+ return "Right";
+ case VKEY_SCROLL:
+ return "Scroll";
+ case VKEY_SELECT:
+ return "Select";
+ case VKEY_UP:
+ return "Up";
+ // Standard says that DEL becomes U+007F.
+ case VKEY_DELETE:
+ return "U+007F";
+ default:
+ return String::format("U+%04X", toupper(keyCode));
+ }
+}
+#endif // !defined(OS_MACOSX)
+
+MakePlatformKeyboardEvent::MakePlatformKeyboardEvent(const WebKeyboardEvent& e)
+ {
m_type = ToPlatformKeyboardEventType(e.type);
- m_text = WebCore::String(e.text);
- m_unmodifiedText = WebCore::String(e.unmodified_text);
- m_keyIdentifier = WebCore::String(e.key_identifier);
+ if (m_type == Char || m_type == KeyDown) {
+#if defined(OS_MACOSX)
+ m_text = &e.text[0];
+ m_unmodifiedText = &e.unmodified_text[0];
+ m_keyIdentifier = &e.key_identifier[0];
+
+ // Always use 13 for Enter/Return -- we don't want to use AppKit's
+ // different character for Enter.
+ if (m_windowsVirtualKeyCode == '\r') {
+ m_text = "\r";
+ m_unmodifiedText = "\r";
+ }
+
+ // The adjustments below are only needed in backward compatibility mode,
+ // but we cannot tell what mode we are in from here.
+
+ // Turn 0x7F into 8, because backspace needs to always be 8.
+ if (m_text == "\x7F")
+ m_text = "\x8";
+ if (m_unmodifiedText == "\x7F")
+ m_unmodifiedText = "\x8";
+ // Always use 9 for tab -- we don't want to use AppKit's different character for shift-tab.
+ if (m_windowsVirtualKeyCode == 9) {
+ m_text = "\x9";
+ m_unmodifiedText = "\x9";
+ }
+#elif defined(OS_WIN)
+ m_text = m_unmodifiedText = ToSingleCharacterString(e.key_code);
+#elif defined(OS_LINUX)
+ m_text = m_unmodifiedText = ToSingleCharacterString(e.text);
+#endif
+ }
+#if defined(OS_WIN) || defined(OS_LINUX)
+ if (m_type != Char)
+ m_keyIdentifier = GetKeyIdentifierForWindowsKeyCode(e.key_code);
+#endif
+ if (m_type == Char || m_type == KeyDown || m_type == KeyUp ||
+ m_type == RawKeyDown) {
+ m_windowsVirtualKeyCode = e.key_code;
+ } else {
+ m_windowsVirtualKeyCode = 0;
+ }
m_autoRepeat = (e.modifiers & WebInputEvent::IS_AUTO_REPEAT) != 0;
- m_windowsVirtualKeyCode = e.windows_key_code;
- m_nativeVirtualKeyCode = e.native_key_code;
m_isKeypad = (e.modifiers & WebInputEvent::IS_KEYPAD) != 0;
m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0;
m_ctrlKey = (e.modifiers & WebInputEvent::CTRL_KEY) != 0;
m_altKey = (e.modifiers & WebInputEvent::ALT_KEY) != 0;
m_metaKey = (e.modifiers & WebInputEvent::META_KEY) != 0;
+#if defined(OS_WIN)
m_isSystemKey = e.system_key;
+// TODO(port): set this field properly for linux and mac.
+#elif defined(OS_LINUX)
+ m_isSystemKey = m_altKey;
+#else
+ m_isSystemKey = false;
+#endif
}
void MakePlatformKeyboardEvent::SetKeyType(Type type) {
diff --git a/webkit/glue/glue.vcproj b/webkit/glue/glue.vcproj
index c3f220c..4ce48b8 100644
--- a/webkit/glue/glue.vcproj
+++ b/webkit/glue/glue.vcproj
@@ -633,14 +633,6 @@
>
</File>
<File
- RelativePath=".\webinputevent_util.cc"
- >
- </File>
- <File
- RelativePath=".\webinputevent_util.h"
- >
- </File>
- <File
RelativePath=".\webkitclient_impl.cc"
>
</File>
diff --git a/webkit/glue/webinputevent.h b/webkit/glue/webinputevent.h
index c917dd1..5565478 100644
--- a/webkit/glue/webinputevent.h
+++ b/webkit/glue/webinputevent.h
@@ -6,11 +6,11 @@
#define WEBKIT_GLUE_WEBINPUTEVENT_H_
#include "base/basictypes.h"
-#include "base/string16.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
+#include <vector>
#ifdef __OBJC__
@class NSEvent;
@class NSView;
@@ -19,7 +19,6 @@ class NSEvent;
class NSView;
#endif // __OBJC__
#elif defined(OS_LINUX)
-#include <glib.h>
typedef struct _GdkEventButton GdkEventButton;
typedef struct _GdkEventMotion GdkEventMotion;
typedef struct _GdkEventScroll GdkEventScroll;
@@ -32,10 +31,6 @@ typedef struct _GdkEventKey GdkEventKey;
//
// The fields of these event classes roughly correspond to the fields required
// by WebCore's platform event classes.
-//
-// WARNING! These classes must remain PODs (plain old data). They will be
-// "serialized" by shipping their raw bytes across the wire, so they must not
-// contain any non-bit-copyable member variables!
// WebInputEvent --------------------------------------------------------------
@@ -43,17 +38,6 @@ class WebInputEvent {
public:
WebInputEvent() : modifiers(0) { }
- // There are two schemes used for keyboard input. On Windows (and,
- // interestingly enough, on Mac Carbon) there are two events for a keypress.
- // One is a raw keydown, which provides the keycode only. If the app doesn't
- // handle that, then the system runs key translation to create an event
- // containing the generated character and pumps that event. In such a scheme,
- // those two events are translated to RAW_KEY_DOWN and CHAR events
- // respectively. In Cocoa and Gtk, key events contain both the keycode and any
- // translation into actual text. In such a case, WebCore will eventually need
- // to split the events (see disambiguateKeyDownEvent and its callers) but we
- // don't worry about that here. We just use a different type (KEY_DOWN) to
- // indicate this.
enum Type {
// WebMouseEvent
MOUSE_DOWN,
@@ -66,7 +50,6 @@ class WebInputEvent {
MOUSE_WHEEL,
// WebKeyboardEvent
- RAW_KEY_DOWN,
KEY_DOWN,
KEY_UP,
CHAR
@@ -143,68 +126,53 @@ class WebMouseWheelEvent : public WebMouseEvent {
// WebKeyboardEvent -----------------------------------------------------------
-// Caps on string lengths so we can make them static arrays and keep them PODs.
-const size_t kTextLengthCap = 4;
-// http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the identifiers.
-// The longest is 18 characters, so we'll round up to the next multiple of 4.
-const size_t kIdentifierLengthCap = 20;
-
class WebKeyboardEvent : public WebInputEvent {
public:
- // |windows_key_code| is the Windows key code associated with this key event.
- // Sometimes it's direct from the event (i.e. on Windows), sometimes it's via
- // a mapping function. If you want a list, see
- // webkit/port/platform/chromium/KeyboardCodes* .
- int windows_key_code;
-
- // The actual key code genenerated by the platform. The DOM spec runs on
- // Windows-equivalent codes (thus |windows_key_code| above) but it doesn't
- // hurt to have this one around.
- int native_key_code;
-
- // |text| is the text generated by this keystroke. |unmodified_text| is
- // |text|, but unmodified by an concurrently-held modifiers (except shift).
- // This is useful for working out shortcut keys. Linux and Windows guarantee
- // one character per event. The Mac does not, but in reality that's all it
- // ever gives. We're generous, and cap it a bit longer.
- char16 text[kTextLengthCap];
- char16 unmodified_text[kTextLengthCap];
-
- // This is a string identifying the key pressed.
- char key_identifier[kIdentifierLengthCap];
-
- // This identifies whether this event was tagged by the system as being a
- // "system key" event (see
- // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
- // Other platforms don't have this concept, but it's just easier to leave it
- // always false than ifdef.
-
- bool system_key;
-
- // References to the original event.
-#if defined(OS_WIN)
- MSG actual_message; // Set to the current keyboard message. TODO(avi): remove
+ // The key_code field is the Windows key code associated with this key event.
+ // This sometimes matches the ASCII value of the key (for e.g. a-z) but
+ // officially ignores case, and has its own set of codes for control keys as
+ // well as other visible letters like punctuation.
+ // webkit/port/platform/chromium/KeyboardCodes* is an attempt at defining all
+ // of these keys, but it's not all the way there yet. (E.g., the Windows
+ // implementation there just passes through the code from the windows message
+ // directly.)
+ int key_code;
+
+#if defined(OS_MACOSX)
+ // text arrays extracted from the native event. On Mac, there may be
+ // multiple keys sent as a single event if the flags don't change.
+ std::vector<unsigned short> text;
+ std::vector<unsigned short> unmodified_text;
+ std::vector<unsigned short> key_identifier;
+#elif defined(OS_WIN)
+ bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message.
+ MSG actual_message; // Set to the current keyboard message.
+#elif defined(OS_LINUX)
+ // The unicode character, if available, corresponding to this key event.
+ // TODO(evanm): temporary hack for test_shell. Ideally we'd either manage
+ // to stuff everything into key_code, or make this field shared by all
+ // implementations, but this will have to do for now.
+ wchar_t text;
#endif
- WebKeyboardEvent() : windows_key_code(0),
- native_key_code(0),
- system_key(false) {
- memset(&text, 0, sizeof(text));
- memset(&unmodified_text, 0, sizeof(unmodified_text));
- memset(&key_identifier, 0, sizeof(key_identifier));
+ WebKeyboardEvent()
+ : key_code(0)
#if defined(OS_WIN)
+ , system_key(false) {
memset(&actual_message, 0, sizeof(actual_message));
-#endif
}
+#else
+ {}
+#endif
#if defined(OS_WIN)
- explicit WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam,
- LPARAM lparam);
+ WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
#elif defined(OS_MACOSX)
- explicit WebKeyboardEvent(NSEvent *event);
+ WebKeyboardEvent(NSEvent *event);
#elif defined(OS_LINUX)
explicit WebKeyboardEvent(const GdkEventKey* event);
#endif
};
+
#endif // WEBKIT_GLUE_WEBINPUTEVENT_H_
diff --git a/webkit/glue/webinputevent_linux.cc b/webkit/glue/webinputevent_linux.cc
index 6ef85aa..328dafe 100644
--- a/webkit/glue/webinputevent_linux.cc
+++ b/webkit/glue/webinputevent_linux.cc
@@ -9,9 +9,12 @@
#include "KeyboardCodes.h"
#include "KeyCodeConversion.h"
+#include "webkit/glue/event_conversion.h"
+
+// This header is out of alphabetical order, but event_conversion.h pulls
+// in more webkit headers that redefine LOG so I need to undef afterwards.
+#undef LOG
#include "base/logging.h"
-#include "base/string_util.h"
-#include "webkit/glue/webinputevent_util.h"
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
@@ -63,7 +66,7 @@ WebMouseEvent::WebMouseEvent(const GdkEventButton* event) {
break;
default:
- NOTREACHED();
+ ASSERT_NOT_REACHED();
};
button = BUTTON_NONE;
@@ -89,7 +92,7 @@ WebMouseEvent::WebMouseEvent(const GdkEventMotion* event) {
type = MOUSE_MOVE;
break;
default:
- NOTREACHED();
+ ASSERT_NOT_REACHED();
}
button = BUTTON_NONE;
@@ -146,9 +149,13 @@ WebMouseWheelEvent::WebMouseWheelEvent(const GdkEventScroll* event) {
}
WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) {
- system_key = false;
modifiers = GdkStateToWebEventModifiers(event->state);
+ // GDK only exposes key press and release events. By contrast,
+ // WebKeyboardEvent matches Windows and wants key down/up events along with a
+ // separate CHAR event.
+ // We require the caller to simulate the CHAR event manually. See
+ // test_shell's webwidget_host for an example.
switch (event->type) {
case GDK_KEY_RELEASE:
type = KEY_UP;
@@ -164,12 +171,7 @@ WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) {
// The key code tells us which physical key was pressed (for example, the
// A key went down or up). It does not determine whether A should be lower
// or upper case. This is what text does, which should be the keyval.
- windows_key_code = WebCore::windowsKeyCodeForKeyEvent(event->keyval);
- native_key_code = event->hardware_keycode;
-
- memset(&text, 0, sizeof(text));
- memset(&unmodified_text, 0, sizeof(unmodified_text));
- memset(&key_identifier, 0, sizeof(key_identifier));
+ key_code = WebCore::windowsKeyCodeForKeyEvent(event->keyval);
switch (event->keyval) {
// We need to treat the enter key as a key press of character \r. This
@@ -177,20 +179,13 @@ WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) {
case GDK_ISO_Enter:
case GDK_KP_Enter:
case GDK_Return:
- unmodified_text[0] = text[0] = static_cast<char16>('\r');
+ text = '\r';
break;
default:
// This should set text to 0 when it's not a real character.
- // TODO(avi): fix for non BMP chars
- unmodified_text[0] = text[0] =
- static_cast<char16>(gdk_keyval_to_unicode(event->keyval));
+ text = gdk_keyval_to_unicode(event->keyval);
break;
}
- std::string key_identifier_str =
- webkit_glue::GetKeyIdentifierForWindowsKeyCode(windows_key_code);
- base::strlcpy(key_identifier, key_identifier_str.c_str(),
- kIdentifierLengthCap);
-
// TODO(tc): Do we need to set IS_AUTO_REPEAT or IS_KEYPAD?
}
diff --git a/webkit/glue/webinputevent_mac.mm b/webkit/glue/webinputevent_mac.mm
index d553828..3090d96 100644
--- a/webkit/glue/webinputevent_mac.mm
+++ b/webkit/glue/webinputevent_mac.mm
@@ -1,28 +1,6 @@
-/*
- * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2006-2009 Google Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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.
- */
+// Copyright (c) 2006-2008 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.
#import <Cocoa/Cocoa.h>
@@ -163,7 +141,7 @@ WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event, NSView* view) {
// that. As a result we have to use NSString here exclusively and thus tweak
// the code so it's not re-usable as-is. One possiblity would be to make the
// upstream code only use NSString, but I'm not certain how far that change
-// would propagate.
+// would propageage
namespace WebCore {
@@ -945,8 +923,18 @@ static NSString* keyIdentifierForKeyEvent(NSEvent* event)
// End Apple code.
// ---------------------------------------------------------------------
+// Helper that copies the unichar characters of a NSString into a suitably
+// resized vector. The vector will be null terminated and thus even if the
+// string is empty or nil, it array will have a NUL.
+static void FillVectorFromNSString(std::vector<unsigned short>* v,
+ NSString* str) {
+ const unsigned int length = [str length];
+ v->reserve(length + 1);
+ [str getCharacters:&(*v)[0]];
+ (*v)[length] = '\0';
+}
+
WebKeyboardEvent::WebKeyboardEvent(NSEvent *event) {
- system_key = false;
type = WebCore::isKeyUpEvent(event) ? KEY_UP : KEY_DOWN;
if ([event modifierFlags] & NSControlKeyMask)
@@ -964,51 +952,12 @@ WebKeyboardEvent::WebKeyboardEvent(NSEvent *event) {
if (([event type] != NSFlagsChanged) && [event isARepeat])
modifiers |= IS_AUTO_REPEAT;
- windows_key_code = WebCore::windowsKeyCodeForKeyEvent(event);
- native_key_code = [event keyCode];
+ NSString* textString = WebCore::textFromEvent(event);
+ NSString* unmodifiedStr = WebCore::unmodifiedTextFromEvent(event);
+ NSString* identStr = WebCore::keyIdentifierForKeyEvent(event);
+ FillVectorFromNSString(&text, textString);
+ FillVectorFromNSString(&unmodified_text, unmodifiedStr);
+ FillVectorFromNSString(&key_identifier, identStr);
- NSString* text_str = WebCore::textFromEvent(event);
- NSString* unmodified_str = WebCore::unmodifiedTextFromEvent(event);
- NSString* identifier_str = WebCore::keyIdentifierForKeyEvent(event);
-
- // Begin Apple code, copied from KeyEventMac.mm
-
- // Always use 13 for Enter/Return -- we don't want to use AppKit's
- // different character for Enter.
- if (windows_key_code == '\r') {
- text_str = @"\r";
- unmodified_str = @"\r";
- }
-
- // The adjustments below are only needed in backward compatibility mode,
- // but we cannot tell what mode we are in from here.
-
- // Turn 0x7F into 8, because backspace needs to always be 8.
- if ([text_str isEqualToString:@"\x7F"])
- text_str = @"\x8";
- if ([unmodified_str isEqualToString:@"\x7F"])
- unmodified_str = @"\x8";
- // Always use 9 for tab -- we don't want to use AppKit's different character
- // for shift-tab.
- if (windows_key_code == 9) {
- text_str = @"\x9";
- unmodified_str = @"\x9";
- }
-
- // End Apple code.
-
- memset(&text, 0, sizeof(text));
- memset(&unmodified_text, 0, sizeof(unmodified_text));
- memset(&key_identifier, 0, sizeof(key_identifier));
-
- if ([text_str length] < kTextLengthCap &&
- [unmodified_str length] < kTextLengthCap) {
- [text_str getCharacters:&text[0]];
- [unmodified_str getCharacters:&unmodified_text[0]];
- } else {
- LOG(ERROR) << "Event had text too long; dropped";
- }
- [identifier_str getCString:&key_identifier[0]
- maxLength:kIdentifierLengthCap
- encoding:NSASCIIStringEncoding];
+ key_code = WebCore::windowsKeyCodeForKeyEvent(event);
}
diff --git a/webkit/glue/webinputevent_util.cc b/webkit/glue/webinputevent_util.cc
deleted file mode 100644
index 9f47429..0000000
--- a/webkit/glue/webinputevent_util.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-// 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 "config.h"
-
-#include "webkit/glue/webinputevent_util.h"
-
-#include "KeyboardCodes.h"
-
-#include "base/string_util.h"
-
-using namespace WebCore;
-
-namespace webkit_glue {
-
-std::string GetKeyIdentifierForWindowsKeyCode(unsigned short key_code) {
- switch (key_code) {
- case VKEY_MENU:
- return "Alt";
- case VKEY_CONTROL:
- return "Control";
- case VKEY_SHIFT:
- return "Shift";
- case VKEY_CAPITAL:
- return "CapsLock";
- case VKEY_LWIN:
- case VKEY_RWIN:
- return "Win";
- case VKEY_CLEAR:
- return "Clear";
- case VKEY_DOWN:
- return "Down";
- // "End"
- case VKEY_END:
- return "End";
- // "Enter"
- case VKEY_RETURN:
- return "Enter";
- case VKEY_EXECUTE:
- return "Execute";
- case VKEY_F1:
- return "F1";
- case VKEY_F2:
- return "F2";
- case VKEY_F3:
- return "F3";
- case VKEY_F4:
- return "F4";
- case VKEY_F5:
- return "F5";
- case VKEY_F6:
- return "F6";
- case VKEY_F7:
- return "F7";
- case VKEY_F8:
- return "F8";
- case VKEY_F9:
- return "F9";
- case VKEY_F10:
- return "F11";
- case VKEY_F12:
- return "F12";
- case VKEY_F13:
- return "F13";
- case VKEY_F14:
- return "F14";
- case VKEY_F15:
- return "F15";
- case VKEY_F16:
- return "F16";
- case VKEY_F17:
- return "F17";
- case VKEY_F18:
- return "F18";
- case VKEY_F19:
- return "F19";
- case VKEY_F20:
- return "F20";
- case VKEY_F21:
- return "F21";
- case VKEY_F22:
- return "F22";
- case VKEY_F23:
- return "F23";
- case VKEY_F24:
- return "F24";
- case VKEY_HELP:
- return "Help";
- case VKEY_HOME:
- return "Home";
- case VKEY_INSERT:
- return "Insert";
- case VKEY_LEFT:
- return "Left";
- case VKEY_NEXT:
- return "PageDown";
- case VKEY_PRIOR:
- return "PageUp";
- case VKEY_PAUSE:
- return "Pause";
- case VKEY_SNAPSHOT:
- return "PrintScreen";
- case VKEY_RIGHT:
- return "Right";
- case VKEY_SCROLL:
- return "Scroll";
- case VKEY_SELECT:
- return "Select";
- case VKEY_UP:
- return "Up";
- // Standard says that DEL becomes U+007F.
- case VKEY_DELETE:
- return "U+007F";
- default:
- return StringPrintf("U+%04X", toupper(key_code));
- }
-}
-
-} // namespace webkit_glue
diff --git a/webkit/glue/webinputevent_util.h b/webkit/glue/webinputevent_util.h
deleted file mode 100644
index 6452c77..0000000
--- a/webkit/glue/webinputevent_util.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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 WEBKIT_GLUE_WEBINPUTEVENT_UTIL_H_
-#define WEBKIT_GLUE_WEBINPUTEVENT_UTIL_H_
-
-#include <string>
-
-// The shared Linux and Windows keyboard event code lives here.
-
-namespace webkit_glue {
-
-std::string GetKeyIdentifierForWindowsKeyCode(unsigned short key_code);
-
-} // namespace webkit_glue
-
-#endif // WEBKIT_GLUE_WEBINPUTEVENT_UTIL_H_
diff --git a/webkit/glue/webinputevent_win.cc b/webkit/glue/webinputevent_win.cc
index 3588154..bcf573c 100644
--- a/webkit/glue/webinputevent_win.cc
+++ b/webkit/glue/webinputevent_win.cc
@@ -6,9 +6,10 @@
#include "webkit/glue/webinputevent.h"
+#include "webkit/glue/event_conversion.h"
+
+#undef LOG
#include "base/logging.h"
-#include "base/string_util.h"
-#include "webkit/glue/webinputevent_util.h"
static const unsigned long kDefaultScrollLinesPerWheelDelta = 3;
@@ -176,9 +177,9 @@ WebMouseWheelEvent::WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam,
// message == WM_HSCROLL, wparam == SB_LINELEFT (== SB_LINEUP).
// * Scrolling right
// message == WM_HSCROLL, wparam == SB_LINERIGHT (== SB_LINEDOWN).
- if (WM_HSCROLL == message) {
- key_state |= MK_SHIFT;
- wheel_delta = -wheel_delta;
+ if (WM_HSCROLL == message) {
+ key_state |= MK_SHIFT;
+ wheel_delta = -wheel_delta;
}
// Use GetAsyncKeyState for key state since we are synthesizing
@@ -309,13 +310,13 @@ WebKeyboardEvent::WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam,
actual_message.wParam = wparam;
actual_message.lParam = lparam;
- windows_key_code = native_key_code = static_cast<int>(wparam);
+ key_code = static_cast<int>(wparam);
switch (message) {
case WM_SYSKEYDOWN:
system_key = true;
case WM_KEYDOWN:
- type = RAW_KEY_DOWN;
+ type = KEY_DOWN;
break;
case WM_SYSKEYUP:
system_key = true;
@@ -335,21 +336,6 @@ WebKeyboardEvent::WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam,
NOTREACHED() << "unexpected native message: " << message;
}
- memset(&text, 0, sizeof(text));
- memset(&unmodified_text, 0, sizeof(unmodified_text));
- memset(&key_identifier, 0, sizeof(key_identifier));
-
- if (type == CHAR || type == RAW_KEY_DOWN) {
- text[0] = windows_key_code;
- unmodified_text[0] = windows_key_code;
- }
- if (type != CHAR) {
- std::string key_identifier_str =
- webkit_glue::GetKeyIdentifierForWindowsKeyCode(windows_key_code);
- base::strlcpy(key_identifier, key_identifier_str.c_str(),
- kIdentifierLengthCap);
- }
-
if (GetKeyState(VK_SHIFT) & 0x8000)
modifiers |= SHIFT_KEY;
if (GetKeyState(VK_CONTROL) & 0x8000)
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index 445979f..2fac917 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -480,8 +480,7 @@ void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) {
}
bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
- DCHECK((event.type == WebInputEvent::RAW_KEY_DOWN) ||
- (event.type == WebInputEvent::KEY_DOWN) ||
+ DCHECK((event.type == WebInputEvent::KEY_DOWN) ||
(event.type == WebInputEvent::KEY_UP));
// Please refer to the comments explaining the suppress_next_keypress_event_
@@ -506,9 +505,9 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
#if defined(OS_WIN)
// TODO(pinkerton): figure out these keycodes on non-windows
- if (((event.modifiers == 0) && (event.windows_key_code == VK_APPS)) ||
+ if (((event.modifiers == 0) && (event.key_code == VK_APPS)) ||
((event.modifiers == WebInputEvent::SHIFT_KEY) &&
- (event.windows_key_code == VK_F10))) {
+ (event.key_code == VK_F10))) {
SendContextMenuEvent(event);
return true;
}
@@ -516,8 +515,11 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
MakePlatformKeyboardEvent evt(event);
- if (WebInputEvent::RAW_KEY_DOWN == event.type) {
- if (handler->keyEvent(evt) && !evt.isSystemKey()) {
+#if !defined(OS_MACOSX)
+ if (WebInputEvent::KEY_DOWN == event.type) {
+ MakePlatformKeyboardEvent evt_rawkeydown = evt;
+ evt_rawkeydown.SetKeyType(WebCore::PlatformKeyboardEvent::RawKeyDown);
+ if (handler->keyEvent(evt_rawkeydown) && !evt_rawkeydown.isSystemKey()) {
suppress_next_keypress_event_ = true;
return true;
}
@@ -526,6 +528,19 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
return true;
}
}
+#else
+ // Windows and Cocoa handle events in rather different ways. On Windows,
+ // you get two events: WM_KEYDOWN/WM_KEYUP and WM_CHAR. In
+ // PlatformKeyboardEvent, RawKeyDown represents the raw messages. When
+ // processing them, we don't process text editing events, since we'll be
+ // getting the data soon enough. In Cocoa, we get one event with both the
+ // raw and processed data. Therefore we need to keep the type as KeyDown, so
+ // that we'll know that this is the only time we'll have the event and that
+ // we need to do our thing.
+ if (handler->keyEvent(evt)) {
+ return true;
+ }
+#endif
return KeyEventDefault(event);
}
@@ -533,19 +548,18 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) {
if (!autocomplete_popup_showing_ ||
// Home and End should be left to the text field to process.
- event.windows_key_code == base::VKEY_HOME ||
- event.windows_key_code == base::VKEY_END) {
+ event.key_code == base::VKEY_HOME || event.key_code == base::VKEY_END) {
return false;
}
- if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code))
+ if (!autocomplete_popup_->isInterestedInEventForKey(event.key_code))
return false;
if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) {
#if defined(OS_WIN)
// We need to ignore the next CHAR event after this otherwise pressing
// enter when selecting an item in the menu will go to the page.
- if (WebInputEvent::RAW_KEY_DOWN == event.type)
+ if (WebInputEvent::KEY_DOWN == event.type)
suppress_next_keypress_event_ = true;
#endif
return true;
@@ -679,7 +693,7 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
case WebInputEvent::CHAR: {
#if defined(OS_WIN)
// TODO(pinkerton): hook this up for non-win32
- if (event.windows_key_code == VK_SPACE) {
+ if (event.key_code == VK_SPACE) {
int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ?
VK_PRIOR : VK_NEXT);
return ScrollViewWithKeyboard(key_code);
@@ -688,9 +702,9 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
break;
}
- case WebInputEvent::RAW_KEY_DOWN: {
+ case WebInputEvent::KEY_DOWN: {
if (event.modifiers == WebInputEvent::CTRL_KEY) {
- switch (event.windows_key_code) {
+ switch (event.key_code) {
case 'A':
GetFocusedFrame()->SelectAll();
return true;
@@ -715,7 +729,7 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
}
#if defined(OS_WIN)
if (!event.system_key) {
- return ScrollViewWithKeyboard(event.windows_key_code);
+ return ScrollViewWithKeyboard(event.key_code);
}
#endif
break;
@@ -960,7 +974,6 @@ bool WebViewImpl::HandleInputEvent(const WebInputEvent* input_event) {
MouseUp(*static_cast<const WebMouseEvent*>(input_event));
break;
- case WebInputEvent::RAW_KEY_DOWN:
case WebInputEvent::KEY_DOWN:
case WebInputEvent::KEY_UP:
handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event));
@@ -1219,14 +1232,15 @@ void WebViewImpl::SetInitialFocus(bool reverse) {
// Since we don't have a keyboard event, we'll create one.
WebKeyboardEvent keyboard_event;
- keyboard_event.type = WebInputEvent::RAW_KEY_DOWN;
+ keyboard_event.type = WebInputEvent::KEY_DOWN;
if (reverse)
keyboard_event.modifiers = WebInputEvent::SHIFT_KEY;
// VK_TAB which is only defined on Windows.
- keyboard_event.windows_key_code = 0x09;
+ keyboard_event.key_code = 0x09;
MakePlatformKeyboardEvent platform_event(keyboard_event);
// We have to set the key type explicitly to avoid an assert in the
// KeyboardEvent constructor.
+ platform_event.SetKeyType(PlatformKeyboardEvent::RawKeyDown);
RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event,
NULL);
page()->focusController()->setInitialFocus(
diff --git a/webkit/glue/webwidget_impl.cc b/webkit/glue/webwidget_impl.cc
index b745a66..721bbd3 100644
--- a/webkit/glue/webwidget_impl.cc
+++ b/webkit/glue/webwidget_impl.cc
@@ -172,7 +172,6 @@ bool WebWidgetImpl::HandleInputEvent(const WebInputEvent* input_event) {
MouseUp(*static_cast<const WebMouseEvent*>(input_event));
return true;
- case WebInputEvent::RAW_KEY_DOWN:
case WebInputEvent::KEY_DOWN:
case WebInputEvent::KEY_UP:
return KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event));
diff --git a/webkit/tools/test_shell/event_sending_controller.cc b/webkit/tools/test_shell/event_sending_controller.cc
index 4438f17..76e8a06 100644
--- a/webkit/tools/test_shell/event_sending_controller.cc
+++ b/webkit/tools/test_shell/event_sending_controller.cc
@@ -29,7 +29,6 @@
#include "base/ref_counted.h"
#include "base/string_util.h"
#include "base/time.h"
-#include "webkit/glue/webinputevent_util.h"
#include "webkit/glue/webview.h"
#include "webkit/tools/test_shell/test_shell.h"
@@ -378,26 +377,22 @@ void EventSendingController::keyDown(
generate_char = true;
}
- // For one generated keyboard event, we need to generate a keyDown/keyUp
- // pair; refer to EventSender.cpp in WebKit/WebKitTools/DumpRenderTree/win.
- // On Windows, we might also need to generate a char event to mimic the
- // Windows event flow; on other platforms we create a merged event and test
- // the event flow that that platform provides.
+ // NOTE(jnd):For one keydown event, we need to generate
+ // keyDown/keyUp pair, refer EventSender.cpp in
+ // WebKit/WebKitTools/DumpRenderTree/win. We may also need
+ // to generate a keyChar event in certain cases.
WebKeyboardEvent event_down, event_up;
-#if defined(OS_WIN)
- event_down.type = WebInputEvent::RAW_KEY_DOWN;
-#else
event_down.type = WebInputEvent::KEY_DOWN;
-#endif
event_down.modifiers = 0;
- event_down.windows_key_code = code;
- event_down.text[0] = code;
- event_down.unmodified_text[0] = code;
- std::string key_identifier_str =
- webkit_glue::GetKeyIdentifierForWindowsKeyCode(code);
-
- base::strlcpy(event_down.key_identifier, key_identifier_str.c_str(),
- kIdentifierLengthCap);
+ event_down.key_code = code;
+#if defined(OS_LINUX)
+ // TODO(deanm): This code is a confusing mix of different platform key
+ // codes. Since we're not working with a GDK event, we can't use our
+ // GDK -> WebKit converter, which means the Linux specific extra |text|
+ // field goes uninitialized. I don't know how to correctly calculate this
+ // field, but for now we will at least initialize it, even if it's wrong.
+ event_down.text = code;
+#endif
if (args.size() >= 2 && (args[1].isObject() || args[1].isString()))
ApplyKeyModifiers(&(args[1]), &event_down);
@@ -413,14 +408,11 @@ void EventSendingController::keyDown(
webview()->HandleInputEvent(&event_down);
-#if defined(OS_WIN)
if (generate_char) {
WebKeyboardEvent event_char = event_down;
event_char.type = WebInputEvent::CHAR;
- event_char.key_identifier[0] = '\0';
webview()->HandleInputEvent(&event_char);
}
-#endif
webview()->HandleInputEvent(&event_up);
}
diff --git a/webkit/tools/test_shell/keyboard_unittest.cc b/webkit/tools/test_shell/keyboard_unittest.cc
index 03f1b15..673edd1 100644
--- a/webkit/tools/test_shell/keyboard_unittest.cc
+++ b/webkit/tools/test_shell/keyboard_unittest.cc
@@ -14,11 +14,9 @@ MSVC_POP_WARNING();
#undef LOG
-#include "base/string_util.h"
#include "webkit/glue/editor_client_impl.h"
#include "webkit/glue/event_conversion.h"
#include "webkit/glue/webinputevent.h"
-#include "webkit/glue/webinputevent_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using WebCore::PlatformKeyboardEvent;
@@ -48,14 +46,15 @@ class KeyboardTest : public testing::Test {
void SetupKeyDownEvent(WebKeyboardEvent* keyboard_event,
char key_code,
int modifiers) {
- keyboard_event->windows_key_code = key_code;
+ keyboard_event->key_code = key_code;
keyboard_event->modifiers = modifiers;
keyboard_event->type = WebInputEvent::KEY_DOWN;
- keyboard_event->text[0] = key_code;
- std::string key_identifier_str =
- webkit_glue::GetKeyIdentifierForWindowsKeyCode(key_code);
- base::strlcpy(keyboard_event->key_identifier, key_identifier_str.c_str(),
- kIdentifierLengthCap);
+#if defined(OS_LINUX)
+ keyboard_event->text = key_code;
+#elif defined(OS_MACOSX)
+ keyboard_event->text.clear();
+ keyboard_event->text.push_back(key_code);
+#endif
}
// Like InterpretKeyEvent, but with pressing down OSModifier+|key_code|.
diff --git a/webkit/tools/test_shell/mac/webwidget_host.mm b/webkit/tools/test_shell/mac/webwidget_host.mm
index b99aca7..dc1b6c6 100644
--- a/webkit/tools/test_shell/mac/webwidget_host.mm
+++ b/webkit/tools/test_shell/mac/webwidget_host.mm
@@ -221,7 +221,15 @@ void WebWidgetHost::MouseEvent(NSEvent *event) {
case WebInputEvent::MOUSE_LEAVE:
TrackMouseLeave(false);
break;
- default:
+ case WebInputEvent::MOUSE_DOWN:
+ break;
+ case WebInputEvent::MOUSE_UP:
+ break;
+ case WebInputEvent::MOUSE_DOUBLE_CLICK:
+ case WebInputEvent::MOUSE_WHEEL:
+ case WebInputEvent::KEY_DOWN:
+ case WebInputEvent::KEY_UP:
+ case WebInputEvent::CHAR:
break;
}
webwidget_->HandleInputEvent(&web_event);
diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp
index cefe517..ba4c145 100644
--- a/webkit/tools/test_shell/test_shell.gyp
+++ b/webkit/tools/test_shell/test_shell.gyp
@@ -82,15 +82,7 @@
],
'conditions': [
['OS!="linux"', {'sources/': [['exclude', '_gtk\\.cc$']]}],
- ['OS=="mac"', {
- 'sources': [
- # Windows/Linux use this code normally when constructing events, so
- # in test_shell they get it from glue. The Mac has its own code for
- # accomplishing it, so in test_shell, where events are constructed
- # from scratch, we need to pull this in.
- '../../glue/webinputevent_util.cc',
- ]
- }, { # else: OS!=mac
+ ['OS!="mac"', {
'sources/': [
['exclude', 'mac/[^/]*\\.(cc|mm?)$'],
['exclude', '_mac\\.(cc|mm?)$'],
@@ -106,7 +98,7 @@
'dependencies': [
'../../../breakpad/breakpad.gyp:breakpad_handler',
],
- }, { # else: OS!=win
+ }, { # OS!=win
'sources/': [
['exclude', '_win\\.cc$']
],
@@ -199,7 +191,7 @@
}],
['OS=="win"', {
'msvs_disabled_warnings': [ 4800 ],
- }, { # else: OS!=win
+ }, { # OS!=win
'sources!': [
'../../../skia/ext/vector_canvas_unittest.cc',
'../webcore_unit_tests/UniscribeHelper_unittest.cpp',
diff --git a/webkit/tools/test_shell/webwidget_host_gtk.cc b/webkit/tools/test_shell/webwidget_host_gtk.cc
index 57d88d8..c3b5cb6 100644
--- a/webkit/tools/test_shell/webwidget_host_gtk.cc
+++ b/webkit/tools/test_shell/webwidget_host_gtk.cc
@@ -148,6 +148,16 @@ class WebWidgetHostGtkWidget {
WebKeyboardEvent wke(event);
host->webwidget()->HandleInputEvent(&wke);
+ // The WebKeyboardEvent model, when holding down a key, is:
+ // KEY_DOWN, CHAR, (repeated CHAR as key repeats,) KEY_UP
+ // The GDK model for the same sequence is just:
+ // KEY_PRESS, (repeated KEY_PRESS as key repeats,) KEY_RELEASE
+ // So we must simulate a CHAR event for every key press.
+ if (event->type == GDK_KEY_PRESS) {
+ wke.type = WebKeyboardEvent::CHAR;
+ host->webwidget()->HandleInputEvent(&wke);
+ }
+
return FALSE;
}