Commit 1125c116 authored by arv's avatar arv Committed by Commit bot

Revert of Removing X11 native_event uses for key events. (patchset #7...

Revert of Removing X11 native_event uses for key events. (patchset #7 id:180001 of https://codereview.chromium.org/479873002/)

Reason for revert:
Broke Android Tests (dbg)

C  427.575s Main  [FAIL] org.chromium.content.browser.input.ImeTest#testKeyCodesWhileComposingText:
C  427.575s Main  junit.framework.AssertionFailedError
C  427.575s Main  	at org.chromium.content.browser.input.ImeTest.assertUpdateStateCall(ImeTest.java:694)
C  427.575s Main  	at org.chromium.content.browser.input.ImeTest.testKeyCodesWhileComposingText(ImeTest.java:410)
C  427.575s Main  	at java.lang.reflect.Method.invokeNative(Native Method)
C  427.575s Main  	at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
C  427.575s Main  	at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
C  427.575s Main  	at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
C  427.575s Main  	at org.chromium.content_shell_apk.ContentShellTestBase.runTest(ContentShellTestBase.java:227)
C  427.575s Main  	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
C  427.575s Main  	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
C  427.575s Main  	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
C  427.575s Main  	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

Original issue's description:
> Removing uses of X11 native key events.
>
> BUG=380349
>
> Committed: https://chromium.googlesource.com/chromium/src/+/bbb7ea7c66f18298079eea4a6b24834986f4a822
>
> Committed: https://chromium.googlesource.com/chromium/src/+/13d90b146a400156427243d05159cadd8d72c0b9

TBR=sadrul@chromium.org,sky@chromium.org,erg@chromium.org,jamesr@chromium.org,boliu@chromium.org,kpschoedel@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=380349

Review URL: https://codereview.chromium.org/548303003

Cr-Commit-Position: refs/heads/master@{#293732}
parent 88aedae8
......@@ -55,6 +55,9 @@ content/browser/geolocation/osx_wifi.h
# Copyright The Chromium Authors, Apple Inc and Graham Dennis; BSD license. Not
# used on Android.
content/browser/renderer_host/render_widget_host_view_mac.mm
# Copyright The Chromium Authors and Google Inc; BSD license. Not used on
# Android.
content/browser/renderer_host/web_input_event_aurax11.cc
# Copyright Apple Inc and Torch Mobile Inc; BSD license. Moved from
# third_party/WebKit/.
content/renderer/history_controller.h
......
......@@ -19,30 +19,29 @@
namespace ash {
namespace {
void DispatchPressedEvent(const ui::KeyEvent& key_event,
void DispatchPressedEvent(XEvent native_event,
scoped_ptr<aura::WindowTracker> tracker) {
// The target window may be gone.
if (tracker->windows().empty())
return;
ui::KeyEvent event(key_event);
aura::Window* target = *(tracker->windows().begin());
ui::KeyEvent event(&native_event);
event.set_flags(event.flags() | ui::EF_IS_SYNTHESIZED);
ui::EventDispatchDetails result ALLOW_UNUSED =
target->GetHost()->event_processor()->OnEventFromSource(&event);
}
void PostPressedEvent(ui::KeyEvent* event) {
// Modify RELEASED event to PRESSED event.
const ui::KeyEvent pressed_event(
ui::ET_KEY_PRESSED,
event->key_code(),
event->code(),
event->flags() | ui::EF_SHIFT_DOWN | ui::EF_IS_SYNTHESIZED);
XEvent xkey = *(event->native_event());
xkey.xkey.type = KeyPress;
xkey.xkey.state |= ShiftMask;
scoped_ptr<aura::WindowTracker> tracker(new aura::WindowTracker);
tracker->Add(static_cast<aura::Window*>(event->target()));
base::MessageLoopForUI::current()->PostTask(
FROM_HERE,
base::Bind(&DispatchPressedEvent, pressed_event, base::Passed(&tracker)));
base::Bind(&DispatchPressedEvent, xkey, base::Passed(&tracker)));
}
} // namespace
......
......@@ -24,16 +24,20 @@ blink::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent(
const base::NativeEvent& native_event);
blink::WebGestureEvent MakeWebGestureEventFromNativeEvent(
const base::NativeEvent& native_event);
#endif
#if defined(USE_X11) || defined(USE_OZONE)
#elif defined(USE_X11)
blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::KeyEvent* event);
#elif defined(USE_OZONE)
blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::KeyEvent* event) {
const base::NativeEvent& native_event = event->native_event();
ui::EventType type = ui::EventTypeFromNative(native_event);
blink::WebKeyboardEvent webkit_event;
webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags());
switch (event->type()) {
switch (type) {
case ui::ET_KEY_PRESSED:
webkit_event.type = event->is_char() ? blink::WebInputEvent::Char :
blink::WebInputEvent::RawKeyDown;
......@@ -48,16 +52,31 @@ blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
if (webkit_event.modifiers & blink::WebInputEvent::AltKey)
webkit_event.isSystemKey = true;
webkit_event.windowsKeyCode = event->GetLocatedWindowsKeyboardCode();
webkit_event.nativeKeyCode = event->platform_keycode();
webkit_event.unmodifiedText[0] = event->GetUnmodifiedText();
webkit_event.text[0] = event->GetText();
wchar_t character = ui::KeyboardCodeFromNative(native_event);
webkit_event.windowsKeyCode = character;
webkit_event.nativeKeyCode = character;
if (webkit_event.windowsKeyCode == ui::VKEY_RETURN)
webkit_event.unmodifiedText[0] = '\r';
else
webkit_event.unmodifiedText[0] = ui::GetCharacterFromKeyCode(
ui::KeyboardCodeFromNative(native_event),
ui::EventFlagsFromNative(native_event));
if (webkit_event.modifiers & blink::WebInputEvent::ControlKey) {
webkit_event.text[0] = ui::GetControlCharacterForKeycode(
webkit_event.windowsKeyCode,
webkit_event.modifiers & blink::WebInputEvent::ShiftKey);
} else {
webkit_event.text[0] = webkit_event.unmodifiedText[0];
}
webkit_event.setKeyIdentifierFromWindowsKeyCode();
return webkit_event;
}
#endif
#if defined(USE_X11) || defined(USE_OZONE)
blink::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::ScrollEvent* event) {
blink::WebMouseWheelEvent webkit_event;
......@@ -221,6 +240,9 @@ blink::WebMouseWheelEvent MakeWebMouseWheelEvent(ui::ScrollEvent* event) {
}
blink::WebKeyboardEvent MakeWebKeyboardEvent(ui::KeyEvent* event) {
if (!event->HasNativeEvent())
return blink::WebKeyboardEvent();
// Windows can figure out whether or not to construct a RawKeyDown or a Char
// WebInputEvent based on the type of message carried in
// event->native_event(). X11 is not so fortunate, there is no separate
......@@ -228,9 +250,6 @@ blink::WebKeyboardEvent MakeWebKeyboardEvent(ui::KeyEvent* event) {
// is_char() == true. We need to pass the ui::KeyEvent to the X11 function
// to detect this case so the right event type can be constructed.
#if defined(OS_WIN)
if (!event->HasNativeEvent())
return blink::WebKeyboardEvent();
// Key events require no translation by the aura system.
return MakeWebKeyboardEventFromNativeEvent(event->native_event());
#else
......
// Copyright (c) 2012 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.
// Portions based heavily on:
// third_party/WebKit/public/web/gtk/WebInputEventFactory.cpp
//
/*
* Copyright (C) 2006-2011 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
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER 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.
*/
#include "content/browser/renderer_host/web_input_event_aura.h"
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <cstdlib>
#include "base/event_types.h"
#include "base/logging.h"
#include "content/browser/renderer_host/ui_events_helper.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content {
// chromium WebKit does not provide a WebInputEventFactory for X11, so we have
// to do the work here ourselves.
blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::KeyEvent* event) {
const base::NativeEvent& native_event = event->native_event();
blink::WebKeyboardEvent webkit_event;
XKeyEvent* native_key_event = &native_event->xkey;
webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags());
switch (native_event->type) {
case KeyPress:
webkit_event.type = event->is_char() ? blink::WebInputEvent::Char :
blink::WebInputEvent::RawKeyDown;
break;
case KeyRelease:
webkit_event.type = blink::WebInputEvent::KeyUp;
break;
default:
NOTREACHED();
}
if (webkit_event.modifiers & blink::WebInputEvent::AltKey)
webkit_event.isSystemKey = true;
webkit_event.windowsKeyCode = ui::WindowsKeycodeFromNative(native_event);
webkit_event.nativeKeyCode = native_key_event->keycode;
webkit_event.unmodifiedText[0] =
ui::UnmodifiedTextFromNative(native_event);
webkit_event.text[0] = ui::TextFromNative(native_event);
webkit_event.setKeyIdentifierFromWindowsKeyCode();
// TODO: IsKeyPad?
return webkit_event;
}
} // namespace content
......@@ -1099,6 +1099,7 @@
'browser/renderer_host/web_input_event_aura.cc',
'browser/renderer_host/web_input_event_aura.h',
'browser/renderer_host/web_input_event_aurawin.cc',
'browser/renderer_host/web_input_event_aurax11.cc',
'browser/renderer_host/webmenurunner_mac.h',
'browser/renderer_host/webmenurunner_mac.mm',
'browser/renderer_host/websocket_dispatcher_host.cc',
......
......@@ -236,8 +236,6 @@ class RenderViewImplTest : public RenderViewTest {
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent event2(xevent);
event2.set_character(GetCharacterFromKeyCode(event2.key_code(),
event2.flags()));
ui::KeyEventTestApi test_event2(&event2);
test_event2.set_is_char(true);
NativeWebKeyboardEvent char_event(&event2);
......@@ -257,21 +255,26 @@ class RenderViewImplTest : public RenderViewTest {
#elif defined(USE_OZONE)
const int flags = ConvertMockKeyboardModifier(modifiers);
ui::KeyEvent keydown_event(ui::ET_KEY_PRESSED,
static_cast<ui::KeyboardCode>(key_code),
flags);
// Ozone's native events are ui::Events. So first create the "native" event,
// then create the actual ui::KeyEvent with the native event.
ui::KeyEvent keydown_native_event(ui::ET_KEY_PRESSED,
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent keydown_event(&keydown_native_event);
NativeWebKeyboardEvent keydown_web_event(&keydown_event);
SendNativeKeyEvent(keydown_web_event);
ui::KeyEvent char_event(keydown_event.GetCharacter(),
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent char_native_event(static_cast<base::char16>(key_code),
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent char_event(&char_native_event);
NativeWebKeyboardEvent char_web_event(&char_event);
SendNativeKeyEvent(char_web_event);
ui::KeyEvent keyup_event(ui::ET_KEY_RELEASED,
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent keyup_native_event(ui::ET_KEY_RELEASED,
static_cast<ui::KeyboardCode>(key_code),
flags);
ui::KeyEvent keyup_event(&keyup_native_event);
NativeWebKeyboardEvent keyup_web_event(&keyup_event);
SendNativeKeyEvent(keyup_web_event);
......
......@@ -104,9 +104,9 @@ class PlatformViewportX11 : public PlatformViewport,
char_event.SetExtendedKeyEventData(scoped_ptr<ui::ExtendedKeyEventData>(
new MojoExtendedKeyEventData(
key_press_event->GetLocatedWindowsKeyboardCode(),
key_press_event->GetText(),
key_press_event->GetUnmodifiedText())));
ui::WindowsKeycodeFromNative(key_press_event->native_event()),
ui::TextFromNative(key_press_event->native_event()),
ui::UnmodifiedTextFromNative(key_press_event->native_event()))));
char_event.set_platform_keycode(key_press_event->platform_keycode());
delegate_->OnEvent(&char_event);
......
......@@ -119,12 +119,18 @@ EventPtr TypeConverter<EventPtr, ui::Event>::Convert(const ui::Event& input) {
} else if (input.IsKeyEvent()) {
const ui::KeyEvent* key_event = static_cast<const ui::KeyEvent*>(&input);
KeyDataPtr key_data(KeyData::New());
key_data->key_code = key_event->GetConflatedWindowsKeyCode();
key_data->key_code = key_event->key_code();
key_data->native_key_code = key_event->platform_keycode();
key_data->is_char = key_event->is_char();
key_data->character = key_event->GetCharacter();
if (key_event->extended_key_event_data()) {
if (key_event->HasNativeEvent()) {
key_data->windows_key_code = static_cast<mojo::KeyboardCode>(
ui::WindowsKeycodeFromNative(key_event->native_event()));
key_data->text = ui::TextFromNative(key_event->native_event());
key_data->unmodified_text =
ui::UnmodifiedTextFromNative(key_event->native_event());
} else if (key_event->extended_key_event_data()) {
const MojoExtendedKeyEventData* data =
static_cast<const MojoExtendedKeyEventData*>(
key_event->extended_key_event_data());
......@@ -133,10 +139,8 @@ EventPtr TypeConverter<EventPtr, ui::Event>::Convert(const ui::Event& input) {
key_data->text = data->text();
key_data->unmodified_text = data->unmodified_text();
} else {
key_data->windows_key_code = static_cast<mojo::KeyboardCode>(
key_event->GetLocatedWindowsKeyboardCode());
key_data->text = key_event->GetText();
key_data->unmodified_text = key_event->GetUnmodifiedText();
NOTREACHED() << "Synthesized event which never contained a native event "
"passed to mojo::TypeConverter.";
}
event->key_data = key_data.Pass();
......
......@@ -7,7 +7,6 @@
#if defined(USE_X11)
#include <X11/extensions/XInput2.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#endif
#include <cmath>
......@@ -626,11 +625,6 @@ KeyEvent::KeyEvent(const base::NativeEvent& native_event)
#if defined(USE_X11)
NormalizeFlags();
#endif
#if defined(OS_WIN)
// Only Windows has native character events.
if (is_char_)
character_ = native_event.wParam;
#endif
}
KeyEvent::KeyEvent(EventType type,
......@@ -640,7 +634,7 @@ KeyEvent::KeyEvent(EventType type,
key_code_(key_code),
is_char_(false),
platform_keycode_(0),
character_() {
character_(GetCharacterFromKeyCode(key_code, flags)) {
}
KeyEvent::KeyEvent(EventType type,
......@@ -652,7 +646,7 @@ KeyEvent::KeyEvent(EventType type,
code_(code),
is_char_(false),
platform_keycode_(0),
character_(0) {
character_(GetCharacterFromKeyCode(key_code, flags)) {
}
KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags)
......@@ -697,21 +691,15 @@ void KeyEvent::SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data) {
}
base::char16 KeyEvent::GetCharacter() const {
if (is_char_ || character_)
if (character_)
return character_;
// TODO(kpschoedel): streamline these cases after settling Ozone
// positional coding.
#if defined(OS_WIN)
// Native Windows character events always have is_char_ == true,
// so this is a synthetic or native keystroke event.
character_ = GetCharacterFromKeyCode(key_code_, flags());
return character_;
return (native_event().message == WM_CHAR) ? key_code_ :
GetCharacterFromKeyCode(key_code_, flags());
#elif defined(USE_X11)
if (!native_event()) {
character_ = GetCharacterFromKeyCode(key_code_, flags());
return character_;
}
if (!native_event())
return GetCharacterFromKeyCode(key_code_, flags());
DCHECK(native_event()->type == KeyPress ||
native_event()->type == KeyRelease ||
......@@ -736,20 +724,6 @@ base::char16 KeyEvent::GetCharacter() const {
#endif
}
base::char16 KeyEvent::GetText() const {
if ((flags() & EF_CONTROL_DOWN) != 0) {
return GetControlCharacterForKeycode(key_code_,
(flags() & EF_SHIFT_DOWN) != 0);
}
return GetUnmodifiedText();
}
base::char16 KeyEvent::GetUnmodifiedText() const {
if (!is_char_ && (key_code_ == VKEY_RETURN))
return '\r';
return GetCharacter();
}
bool KeyEvent::IsUnicodeKeyCode() const {
#if defined(OS_WIN)
if (!IsAltDown())
......@@ -823,83 +797,6 @@ void KeyEvent::SetTranslated(bool translated) {
}
}
bool KeyEvent::IsRightSideKey() const {
switch (key_code_) {
case VKEY_CONTROL:
case VKEY_SHIFT:
case VKEY_MENU:
case VKEY_LWIN:
#if defined(USE_X11)
// Under X11, setting code_ requires platform-dependent information, and
// currently assumes that X keycodes are based on Linux evdev keycodes.
// In certain test environments this is not the case, and code_ is not
// set accurately, so we need a different mechanism. Fortunately X11 key
// mapping preserves the left-right distinction, so testing keysyms works
// if the value is available (as it is for all X11 native-based events).
if (platform_keycode_) {
return (platform_keycode_ == XK_Shift_R) ||
(platform_keycode_ == XK_Control_R) ||
(platform_keycode_ == XK_Alt_R) ||
(platform_keycode_ == XK_Meta_R) ||
(platform_keycode_ == XK_Super_R) ||
(platform_keycode_ == XK_Hyper_R);
}
// Fall through to the generic code if we have no platform_keycode_.
// Under X11, this must be a synthetic event, so we can require that
// code_ be set correctly.
#endif
return ((code_.size() > 5) &&
(code_.compare(code_.size() - 5, 5, "Right", 5)) == 0);
default:
return false;
}
}
KeyboardCode KeyEvent::GetLocatedWindowsKeyboardCode() const {
switch (key_code_) {
case VKEY_SHIFT:
return IsRightSideKey() ? VKEY_RSHIFT : VKEY_LSHIFT;
case VKEY_CONTROL:
return IsRightSideKey() ? VKEY_RCONTROL : VKEY_LCONTROL;
case VKEY_MENU:
return IsRightSideKey() ? VKEY_RMENU : VKEY_LMENU;
case VKEY_LWIN:
return IsRightSideKey() ? VKEY_RWIN : VKEY_LWIN;
// TODO(kpschoedel): EF_NUMPAD_KEY is present only on X11. Currently this
// function is only called on X11. Likely the tests here will be replaced
// with a DOM-based code enumeration test in the course of Ozone
// platform-indpendent key event work.
case VKEY_0:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD0 : VKEY_0;
case VKEY_1:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD1 : VKEY_1;
case VKEY_2:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD2 : VKEY_2;
case VKEY_3:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD3 : VKEY_3;
case VKEY_4:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD4 : VKEY_4;
case VKEY_5:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD5 : VKEY_5;
case VKEY_6:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD6 : VKEY_6;
case VKEY_7:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD7 : VKEY_7;
case VKEY_8:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD8 : VKEY_8;
case VKEY_9:
return (flags() & EF_NUMPAD_KEY) ? VKEY_NUMPAD9 : VKEY_9;
default:
return key_code_;
}
}
uint16 KeyEvent::GetConflatedWindowsKeyCode() const {
if (is_char_)
return character_;
return key_code_;
}
////////////////////////////////////////////////////////////////////////////////
// ScrollEvent
......
......@@ -589,7 +589,7 @@ class EVENTS_EXPORT ExtendedKeyEventData {
// -- character_ is a UTF-16 character value.
// -- key_code_ is conflated with character_ by some code, because both
// arrive in the wParam field of a Windows event.
// -- code_ is the empty string.
// -- code_ is "".
//
class EVENTS_EXPORT KeyEvent : public Event {
public:
......@@ -638,24 +638,9 @@ class EVENTS_EXPORT KeyEvent : public Event {
// BMP characters.
base::char16 GetCharacter() const;
// If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r';
// otherwise returns the same as GetCharacter().
base::char16 GetUnmodifiedText() const;
// If the Control key is down in the event, returns a layout-independent
// character (corresponding to US layout); otherwise returns the same
// as GetUnmodifiedText().
base::char16 GetText() const;
// Gets the platform key code. For XKB, this is the xksym value.
void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; }
uint32 platform_keycode() const { return platform_keycode_; }
// Gets the associated (Windows-based) KeyboardCode for this key event.
// Historically, this has also been used to obtain the character associated
// with a character event, because both use the Window message 'wParam' field.
// This should be avoided; if necessary for backwards compatibility, use
// GetConflatedWindowsKeyCode().
KeyboardCode key_code() const { return key_code_; }
// True if this is a character event, false if this is a keystroke event.
......@@ -665,17 +650,6 @@ class EVENTS_EXPORT KeyEvent : public Event {
// events in an EventRewriter.
void set_key_code(KeyboardCode key_code) { key_code_ = key_code; }
// Returns the same value as key_code(), except that located codes are
// returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT
// instead of VKEY_SHIFT). This is a hybrid of semantic and physical
// for legacy DOM reasons.
KeyboardCode GetLocatedWindowsKeyboardCode() const;
// For a keystroke event, returns the same value as key_code().
// For a character event, returns the same value as GetCharacter().
// This exists for backwards compatibility with Windows key events.
uint16 GetConflatedWindowsKeyCode() const;
// Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
// TODO(msw): Additional work may be needed for analogues on other platforms.
bool IsUnicodeKeyCode() const;
......@@ -699,9 +673,6 @@ class EVENTS_EXPORT KeyEvent : public Event {
void set_is_char(bool is_char) { is_char_ = is_char; }
private:
// True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.).
bool IsRightSideKey() const;
KeyboardCode key_code_;
// String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space')
......@@ -724,7 +695,7 @@ class EVENTS_EXPORT KeyEvent : public Event {
// This value represents the text that the key event will insert to input
// field. For key with modifier key, it may have specifial text.
// e.g. CTRL+A has '\x01'.
mutable base::char16 character_;
base::char16 character_;
// Parts of our event handling require raw native events (see both the
// windows and linux implementations of web_input_event in content/). Because
......
......@@ -63,8 +63,9 @@ scoped_ptr<Event> EventFromNative(const base::NativeEvent& native_event) {
return event.Pass();
}
#if defined(OS_LINUX)
// From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp:
base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) {
uint16 GetControlCharacterForKeycode(int windows_key_code, bool shift) {
if (windows_key_code >= ui::VKEY_A &&
windows_key_code <= ui::VKEY_Z) {
// ctrl-A ~ ctrl-Z map to \x01 ~ \x1A
......@@ -107,6 +108,7 @@ base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) {
}
return 0;
}
#endif
int RegisterCustomEventType() {
return ++g_custom_event_types;
......
......@@ -5,10 +5,8 @@
#ifndef UI_EVENTS_EVENT_UTILS_H_
#define UI_EVENTS_EVENT_UTILS_H_
#include "base/basictypes.h"
#include "base/event_types.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/display.h"
......@@ -89,9 +87,26 @@ EVENTS_EXPORT const char* CodeFromNative(
EVENTS_EXPORT uint32 PlatformKeycodeFromNative(
const base::NativeEvent& native_event);
// Returns the windows key code. Note that this value is different from
// KeyboardCodeFromNative (there is a divergence between ui::KeyboardCode and
// windows key codes).
EVENTS_EXPORT uint32 WindowsKeycodeFromNative(
const base::NativeEvent& native_event);
// Returns the text generated by this keystroke. Used in the value we pass to
// blink.
EVENTS_EXPORT uint16 TextFromNative(const base::NativeEvent& native_event);
// Returns the unmodified text generated by this keystroke. Used in the value
// we pass to blink.
EVENTS_EXPORT uint16 UnmodifiedTextFromNative(
const base::NativeEvent& native_event);
#if defined(OS_LINUX)
// Returns a control character sequences from a |windows_key_code|.
EVENTS_EXPORT base::char16 GetControlCharacterForKeycode(int windows_key_code,
bool shift);
EVENTS_EXPORT uint16 GetControlCharacterForKeycode(int windows_key_code,
bool shift);
#endif
// Returns true if the keyboard event is a character event rather than
// a keystroke event.
......
......@@ -70,6 +70,21 @@ bool IsCharFromNative(const base::NativeEvent& native_event) {
return event->is_char();
}
uint32 WindowsKeycodeFromNative(const base::NativeEvent& native_event) {
NOTIMPLEMENTED();
return 0;
}
uint16 TextFromNative(const base::NativeEvent& native_event) {
NOTIMPLEMENTED();
return 0;
}
uint16 UnmodifiedTextFromNative(const base::NativeEvent& native_event) {
NOTIMPLEMENTED();
return 0;
}
gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
const ui::MouseWheelEvent* event =
static_cast<const ui::MouseWheelEvent*>(native_event);
......
......@@ -264,6 +264,18 @@ bool IsCharFromNative(const base::NativeEvent& native_event) {
return native_event.message == WM_CHAR;
}
uint32 WindowsKeycodeFromNative(const base::NativeEvent& native_event) {
return static_cast<uint32>(native_event.wParam);
}
uint16 TextFromNative(const base::NativeEvent& native_event) {
return static_cast<uint32>(native_event.wParam);
}
uint16 UnmodifiedTextFromNative(const base::NativeEvent& native_event) {
return static_cast<uint32>(native_event.wParam);
}
int GetChangedMouseButtonFlagsFromNative(
const base::NativeEvent& native_event) {
switch (GetNativeMouseKey(native_event)) {
......
......@@ -685,6 +685,54 @@ bool IsCharFromNative(const base::NativeEvent& native_event) {
return false;
}
uint32 WindowsKeycodeFromNative(const base::NativeEvent& native_event) {
int windows_key_code = ui::KeyboardCodeFromXKeyEvent(native_event);
if (windows_key_code == ui::VKEY_SHIFT ||
windows_key_code == ui::VKEY_CONTROL ||
windows_key_code == ui::VKEY_MENU) {
// To support DOM3 'location' attribute, we need to lookup an X KeySym and
// set ui::VKEY_[LR]XXX instead of ui::VKEY_XXX.
KeySym keysym = XK_VoidSymbol;
XLookupString(&native_event->xkey, NULL, 0, &keysym, NULL);
switch (keysym) {
case XK_Shift_L:
return ui::VKEY_LSHIFT;
case XK_Shift_R:
return ui::VKEY_RSHIFT;
case XK_Control_L:
return ui::VKEY_LCONTROL;
case XK_Control_R:
return ui::VKEY_RCONTROL;
case XK_Meta_L:
case XK_Alt_L:
return ui::VKEY_LMENU;
case XK_Meta_R:
case XK_Alt_R:
return ui::VKEY_RMENU;
}
}
return windows_key_code;
}
uint16 TextFromNative(const base::NativeEvent& native_event) {
int flags = EventFlagsFromNative(native_event);
if ((flags & ui::EF_CONTROL_DOWN) != 0) {
int windows_key_code = WindowsKeycodeFromNative(native_event);
return ui::GetControlCharacterForKeycode(windows_key_code,
flags & ui::EF_SHIFT_DOWN);
}
return UnmodifiedTextFromNative(native_event);
}
uint16 UnmodifiedTextFromNative(const base::NativeEvent& native_event) {
uint32 keycode = WindowsKeycodeFromNative(native_event);
if (keycode == ui::VKEY_RETURN)
return '\r';
else
return ui::GetCharacterFromXEvent(native_event);
}
int GetChangedMouseButtonFlagsFromNative(
const base::NativeEvent& native_event) {
switch (native_event->type) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment