diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 07:38:06 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 07:38:06 +0000 |
commit | f17709bbedbdc5cf3bdc88dc93d264e0191b8f2b (patch) | |
tree | 04e899a7dc1edaf1152f9419671338505a65ca06 /webkit/api | |
parent | fb6ec999c0d049c78b16ca6106d5e45624f94ac8 (diff) | |
download | chromium_src-f17709bbedbdc5cf3bdc88dc93d264e0191b8f2b.zip chromium_src-f17709bbedbdc5cf3bdc88dc93d264e0191b8f2b.tar.gz chromium_src-f17709bbedbdc5cf3bdc88dc93d264e0191b8f2b.tar.bz2 |
Implement the NSTextInput protocol.
This change implements the NSTextInput protocol to integrate dead-keys and IME support into Mac Chromium.
Same as Linux, to improve compatibility with Windows Chrome, this change emulates IPC messages sent on Windows when we input characters to fix Issue 11952 and Issue 11981.
Even though I notice we need more work for fixing edge cases (e.g. disabling IMEs on a password input) also on Mac, it is the good starting point. (Supporting edge-cases requires complicated code and it makes hard to review.)
BUG=11952 "IME support is not implemented"
BUG=11981 "Deadkeys do not work"
BUG=16393 "Mac: Not able to insert any letter using "Special Characters" pallet"
TEST=Open a web page which contains an <input> form (e.g. <http://www.google.com/>), type a '[{' key and an 'A' key on a Canadian-French keyboard, and see a Latin character "U+00E2" is displayed in the <input> form.
TEST=Open a web page which contains an <input> form (e.g. <http://www.google.com/>), enable an Chinese Pinyin IME, type a 'W' key, type an 'O' key, and see a Chinese character is displayed in the <input> form.
TEST=Open a web page which contains a <textarea> form, type a return key, and see a new line is inserted.
Review URL: http://codereview.chromium.org/150206
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api')
-rw-r--r-- | webkit/api/public/WebInputEvent.h | 35 | ||||
-rw-r--r-- | webkit/api/public/mac/WebInputEventFactory.h | 7 | ||||
-rw-r--r-- | webkit/api/src/mac/WebInputEventFactory.mm | 21 |
3 files changed, 47 insertions, 16 deletions
diff --git a/webkit/api/public/WebInputEvent.h b/webkit/api/public/WebInputEvent.h index dbb6602..a09cd37 100644 --- a/webkit/api/public/WebInputEvent.h +++ b/webkit/api/public/WebInputEvent.h @@ -55,18 +55,29 @@ namespace WebKit { , modifiers(0) , timeStampSeconds(0.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. + // When we use an input method (or an input method editor), we receive + // two events for a keypress. The former event is a keydown, which + // provides a keycode, and the latter is a textinput, which provides + // a character processed by an input method. (The mapping from a + // keycode to a character code is not trivial for non-English + // keyboards.) + // To support input methods, Safari sends keydown events to WebKit for + // filtering. WebKit sends filtered keydown events back to Safari, + // which sends them to input methods. + // Unfortunately, it is hard to apply this design to Chrome because of + // our multiprocess architecture. An input method is running in a + // browser process. On the other hand, WebKit is running in a renderer + // process. So, this design results in increasing IPC messages. + // To support input methods without increasing IPC messages, Chrome + // handles keyboard events in a browser process and send asynchronous + // input events (to be translated to DOM events) to a renderer + // process. + // This design is mostly the same as the one of Windows and Mac Carbon. + // So, for what it's worth, our Linux and Mac front-ends emulate our + // Windows front-end. To emulate our Windows front-end, we can share + // our back-end code among Windows, Linux, and Mac. + // TODO(hbono): Issue 18064: remove the KeyDown type since it isn't + // used in Chrome any longer. enum Type { Undefined = -1, diff --git a/webkit/api/public/mac/WebInputEventFactory.h b/webkit/api/public/mac/WebInputEventFactory.h index 5b55613c..bb02e38 100644 --- a/webkit/api/public/mac/WebInputEventFactory.h +++ b/webkit/api/public/mac/WebInputEventFactory.h @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google Inc. 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 @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. 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 @@ -50,6 +50,7 @@ namespace WebKit { class WebInputEventFactory { public: WEBKIT_API static WebKeyboardEvent keyboardEvent(NSEvent*); + WEBKIT_API static WebKeyboardEvent keyboardEvent(wchar_t character, int modifiers, double timeStampSeconds); WEBKIT_API static WebMouseEvent mouseEvent(NSEvent*, NSView*); WEBKIT_API static WebMouseWheelEvent mouseWheelEvent(NSEvent*, NSView*); }; diff --git a/webkit/api/src/mac/WebInputEventFactory.mm b/webkit/api/src/mac/WebInputEventFactory.mm index 02a85d2..b549c5f 100644 --- a/webkit/api/src/mac/WebInputEventFactory.mm +++ b/webkit/api/src/mac/WebInputEventFactory.mm @@ -846,7 +846,7 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event) WebKeyboardEvent result; result.type = - isKeyUpEvent(event) ? WebInputEvent::KeyUp : WebInputEvent::KeyDown; + isKeyUpEvent(event) ? WebInputEvent::KeyUp : WebInputEvent::RawKeyDown; result.modifiers = modifiersFromEvent(event); @@ -905,6 +905,25 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event) return result; } +WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, + int modifiers, + double timeStampSeconds) +{ + // keyboardEvent(NSEvent*) depends on the NSEvent object and + // it is hard to use it from methods of the NSTextInput protocol. For + // such methods, this function creates a WebInputEvent::Char event without + // using a NSEvent object. + WebKeyboardEvent result; + result.type = WebKit::WebInputEvent::Char; + result.timeStampSeconds = timeStampSeconds; + result.modifiers = modifiers; + result.windowsKeyCode = character; + result.nativeKeyCode = character; + result.text[0] = character; + result.unmodifiedText[0] = character; + return result; +} + // WebMouseEvent -------------------------------------------------------------- WebMouseEvent WebInputEventFactory::mouseEvent(NSEvent* event, NSView* view) |