Commit e15f915b authored by erg@chromium.org's avatar erg@chromium.org

mojo: Plumb through sufficient context to make real blink::WebInputEvents.

This adds members to mojo::Event that are needed to construct
a blink::WebInputEvent, as well as the boilerplate to carry
those members on a ui::KeyEvent object, because the events
aren't sent directly from the native event source to html
viewer, but pass through multiple systems.

BUG=403514

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

Cr-Commit-Position: refs/heads/master@{#291301}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291301 0039d316-1c4b-4281-b951-d872f2087c98
parent dd357e1e
......@@ -15,52 +15,6 @@
namespace content {
#if defined(USE_X11) || defined(USE_OZONE)
// From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp:
blink::WebUChar GetControlCharacter(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
return windows_key_code - ui::VKEY_A + 1;
}
if (shift) {
// following graphics chars require shift key to input.
switch (windows_key_code) {
// ctrl-@ maps to \x00 (Null byte)
case ui::VKEY_2:
return 0;
// ctrl-^ maps to \x1E (Record separator, Information separator two)
case ui::VKEY_6:
return 0x1E;
// ctrl-_ maps to \x1F (Unit separator, Information separator one)
case ui::VKEY_OEM_MINUS:
return 0x1F;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
break;
}
} else {
switch (windows_key_code) {
// ctrl-[ maps to \x1B (Escape)
case ui::VKEY_OEM_4:
return 0x1B;
// ctrl-\ maps to \x1C (File separator, Information separator four)
case ui::VKEY_OEM_5:
return 0x1C;
// ctrl-] maps to \x1D (Group separator, Information separator three)
case ui::VKEY_OEM_6:
return 0x1D;
// ctrl-Enter maps to \x0A (Line feed)
case ui::VKEY_RETURN:
return 0x0A;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
break;
}
}
return 0;
}
#endif
#if defined(OS_WIN)
blink::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent(
const base::NativeEvent& native_event);
......@@ -110,10 +64,9 @@ blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::EventFlagsFromNative(native_event));
if (webkit_event.modifiers & blink::WebInputEvent::ControlKey) {
webkit_event.text[0] =
GetControlCharacter(
webkit_event.windowsKeyCode,
webkit_event.modifiers & blink::WebInputEvent::ShiftKey);
webkit_event.text[0] = ui::GetControlCharacterForKeycode(
webkit_event.windowsKeyCode,
webkit_event.modifiers & blink::WebInputEvent::ShiftKey);
} else {
webkit_event.text[0] = webkit_event.unmodifiedText[0];
}
......
......@@ -22,10 +22,6 @@ namespace content {
// Used for scrolling. This matches Firefox behavior.
const int kPixelsPerTick = 53;
#if defined(USE_X11) || defined(USE_OZONE)
CONTENT_EXPORT blink::WebUChar GetControlCharacter(
int windows_key_code, bool shift);
#endif
CONTENT_EXPORT blink::WebMouseEvent MakeWebMouseEvent(
ui::MouseEvent* event);
CONTENT_EXPORT blink::WebMouseWheelEvent MakeWebMouseWheelEvent(
......
......@@ -47,6 +47,7 @@
#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"
......@@ -55,40 +56,6 @@ namespace content {
// chromium WebKit does not provide a WebInputEventFactory for X11, so we have
// to do the work here ourselves.
namespace {
int XKeyEventToWindowsKeyCode(XKeyEvent* event) {
int windows_key_code =
ui::KeyboardCodeFromXKeyEvent(reinterpret_cast<XEvent*>(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(event, 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;
}
} // namespace
blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::KeyEvent* event) {
const base::NativeEvent& native_event = event->native_event();
......@@ -113,22 +80,11 @@ blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
if (webkit_event.modifiers & blink::WebInputEvent::AltKey)
webkit_event.isSystemKey = true;
webkit_event.windowsKeyCode = XKeyEventToWindowsKeyCode(native_key_event);
webkit_event.windowsKeyCode = ui::WindowsKeycodeFromNative(native_event);
webkit_event.nativeKeyCode = native_key_event->keycode;
if (webkit_event.windowsKeyCode == ui::VKEY_RETURN)
webkit_event.unmodifiedText[0] = '\r';
else
webkit_event.unmodifiedText[0] = ui::GetCharacterFromXEvent(native_event);
if (webkit_event.modifiers & blink::WebInputEvent::ControlKey) {
webkit_event.text[0] =
GetControlCharacter(
webkit_event.windowsKeyCode,
webkit_event.modifiers & blink::WebInputEvent::ShiftKey);
} else {
webkit_event.text[0] = webkit_event.unmodifiedText[0];
}
webkit_event.unmodifiedText[0] =
ui::UnmodifiedTextFromNative(native_event);
webkit_event.text[0] = ui::TextFromNative(native_event);
webkit_event.setKeyIdentifierFromWindowsKeyCode();
......
......@@ -95,6 +95,7 @@
'sources': [
'services/public/interfaces/input_events/input_event_constants.mojom',
'services/public/interfaces/input_events/input_events.mojom',
'services/public/interfaces/input_events/input_key_codes.mojom',
],
'includes': [ 'public/tools/bindings/mojom_bindings_generator.gypi' ],
'dependencies': [
......
......@@ -4,6 +4,11 @@
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#if defined(USE_X11)
#include <X11/extensions/XInput2.h>
#include <X11/Xlib.h>
#endif
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "ui/events/event_utils.h"
......@@ -87,6 +92,35 @@ ui::EventType TypeConverter<EventType, ui::EventType>::ConvertTo(
return ui::ET_UNKNOWN;
}
class MojoExtendedKeyEventData : public ui::ExtendedKeyEventData {
public:
MojoExtendedKeyEventData(int32_t windows_key_code,
uint16_t text,
uint16_t unmodified_text)
: windows_key_code_(windows_key_code),
text_(text),
unmodified_text_(unmodified_text) {
}
virtual ~MojoExtendedKeyEventData() {}
int32_t windows_key_code() const { return windows_key_code_; }
uint16_t text() const { return text_; }
uint16_t unmodified_text() const { return unmodified_text_; }
// ui::ExtendedKeyEventData:
virtual ExtendedKeyEventData* Clone() const OVERRIDE {
return new MojoExtendedKeyEventData(windows_key_code_,
text_,
unmodified_text_);
}
private:
const int32_t windows_key_code_;
const uint16_t text_;
const uint16_t unmodified_text_;
DISALLOW_COPY_AND_ASSIGN(MojoExtendedKeyEventData);
};
// static
EventPtr TypeConverter<EventPtr, ui::Event>::ConvertFrom(
......@@ -125,6 +159,27 @@ EventPtr TypeConverter<EventPtr, ui::Event>::ConvertFrom(
KeyDataPtr key_data(KeyData::New());
key_data->key_code = key_event->key_code();
key_data->is_char = key_event->is_char();
key_data->native_key_code = key_event->platform_keycode();
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());
key_data->windows_key_code = static_cast<mojo::KeyboardCode>(
data->windows_key_code());
key_data->text = data->text();
key_data->unmodified_text = data->unmodified_text();
} else {
NOTREACHED() << "Synthesized event which never contained a native event "
"passed to mojo::TypeConverter.";
}
event->key_data = key_data.Pass();
} else if (input.IsMouseWheelEvent()) {
const ui::MouseWheelEvent* wheel_event =
......@@ -160,21 +215,30 @@ TypeConverter<EventPtr, scoped_ptr<ui::Event> >::ConvertTo(
switch (input->action) {
case ui::ET_KEY_PRESSED:
case ui::ET_KEY_RELEASED:
case ui::ET_KEY_RELEASED: {
scoped_ptr<ui::KeyEvent> key_event;
if (input->key_data->is_char) {
ui_event.reset(new ui::KeyEvent(
key_event.reset(new ui::KeyEvent(
static_cast<base::char16>(input->key_data->key_code),
static_cast<ui::KeyboardCode>(
input->key_data->key_code),
input->flags));
} else {
ui_event.reset(new ui::KeyEvent(
key_event.reset(new ui::KeyEvent(
ui_event_type,
static_cast<ui::KeyboardCode>(
input->key_data->key_code),
input->flags));
}
key_event->SetExtendedKeyEventData(scoped_ptr<ui::ExtendedKeyEventData>(
new MojoExtendedKeyEventData(
static_cast<int32_t>(input->key_data->windows_key_code),
input->key_data->text,
input->key_data->unmodified_text)));
key_event->set_platform_keycode(input->key_data->native_key_code);
ui_event = key_event.PassAs<ui::KeyEvent>();
break;
}
case EVENT_TYPE_MOUSE_PRESSED:
case EVENT_TYPE_MOUSE_DRAGGED:
case EVENT_TYPE_MOUSE_RELEASED:
......
......@@ -4,6 +4,7 @@
import "mojo/services/public/interfaces/geometry/geometry.mojom"
import "mojo/services/public/interfaces/input_events/input_event_constants.mojom"
import "mojo/services/public/interfaces/input_events/input_key_codes.mojom"
module mojo {
......@@ -13,8 +14,37 @@ struct LocationData {
};
struct KeyData {
// The chromium event key code; these values are from the ui/ KeyCode enum,
// which has the fun property of being neither consistently the Windows key
// code, nor the X11 keycodes. (This value is consistent across platforms
// for basic ASCII characters; it will differ for modifiers. We don't define
// this as a mojo enum because mojom doesn't appear to have a platform
// dependent preprocessor yet.)
//
// TODO(erg): Remove this, and declare Win32 keycodes correct by fiat. We can
// not do this until we remove ui::Event usage from within mojo.
int32 key_code;
bool is_char;
// The Win32 key code. Because of the web, this is the closest thing that we
// have to a cross platform key state.
KeyboardCode windows_key_code;
// The platform specific key code.
//
// TODO(erg): This exists only for NPAPI support, pepper USB keyboard support
// and IME on android support. Theoretically, we should be able to remove this
// in the medium to long term.
int32 native_key_code;
// The text generated by this keystroke. Corresponds to
// blink::WebKeyboardEvent::text.
uint16 text;
// Like |text|, but unmodified by concurrently held modifier keys (except
// shift). Corresponds to blink::WebKeyboardEvent::unmodifiedText.
uint16 unmodified_text;
};
struct TouchData {
......
// Copyright 2014 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.
module mojo {
// Cross platform keyboard codes.
//
// Because the web has standardized on Win32 keyboard codes, so does mojo.
enum KeyboardCode {
BACK = 0x08,
TAB = 0x09,
CLEAR = 0x0C,
RETURN = 0x0D,
SHIFT = 0x10,
CONTROL = 0x11,
MENU = 0x12, // a.k.a. ALT
PAUSE = 0x13,
CAPITAL = 0x14,
KANA = 0x15,
HANGUL = 0x15,
JUNJA = 0x17,
FINAL = 0x18,
HANJA = 0x19,
KANJI = 0x19,
ESCAPE = 0x1B,
CONVERT = 0x1C,
NONCONVERT = 0x1D,
ACCEPT = 0x1E,
MODECHANGE = 0x1F,
SPACE = 0x20,
PRIOR = 0x21,
NEXT = 0x22,
END = 0x23,
HOME = 0x24,
LEFT = 0x25,
UP = 0x26,
RIGHT = 0x27,
DOWN = 0x28,
SELECT = 0x29,
PRINT = 0x2A,
EXECUTE = 0x2D,
SNAPSHOT = 0x2C,
INSERT = 0x2D,
DELETE = 0x2E,
HELP = 0x2F,
NUM_0 = 0x30,
NUM_1 = 0x31,
NUM_2 = 0x32,
NUM_3 = 0x33,
NUM_4 = 0x34,
NUM_5 = 0x35,
NUM_6 = 0x36,
NUM_7 = 0x37,
NUM_8 = 0x38,
NUM_9 = 0x39,
A = 0x41,
B = 0x42,
C = 0x43,
D = 0x44,
E = 0x45,
F = 0x46,
G = 0x47,
H = 0x48,
I = 0x49,
J = 0x4A,
K = 0x4B,
L = 0x4C,
M = 0x4D,
N = 0x4E,
O = 0x4F,
P = 0x50,
Q = 0x51,
R = 0x52,
S = 0x53,
T = 0x54,
U = 0x55,
V = 0x56,
W = 0x57,
X = 0x58,
Y = 0x59,
Z = 0x5A,
LWIN = 0x5B,
COMMAND = 0x5B, // Provide the Mac name for convenience.
RWIN = 0x5C,
APPS = 0x5D,
SLEEP = 0x5F,
NUMPAD0 = 0x60,
NUMPAD1 = 0x61,
NUMPAD2 = 0x62,
NUMPAD3 = 0x63,
NUMPAD4 = 0x64,
NUMPAD5 = 0x65,
NUMPAD6 = 0x66,
NUMPAD7 = 0x67,
NUMPAD8 = 0x68,
NUMPAD9 = 0x69,
MULTIPLY = 0x6A,
ADD = 0x6B,
SEPARATOR = 0x6C,
SUBTRACT = 0x6D,
DECIMAL = 0x6E,
DIVIDE = 0x6F,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7A,
F12 = 0x7B,
F13 = 0x7C,
F14 = 0x7D,
F15 = 0x7E,
F16 = 0x7F,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87,
NUMLOCK = 0x90,
SCROLL = 0x91,
LSHIFT = 0xA0,
RSHIFT = 0xA1,
LCONTROL = 0xA2,
RCONTROL = 0xA3,
LMENU = 0xA4,
RMENU = 0xA5,
BROWSER_BACK = 0xA6,
BROWSER_FORWARD = 0xA7,
BROWSER_REFRESH = 0xA8,
BROWSER_STOP = 0xA9,
BROWSER_SEARCH = 0xAA,
BROWSER_FAVORITES = 0xAB,
BROWSER_HOME = 0xAC,
VOLUME_MUTE = 0xAD,
VOLUME_DOWN = 0xAE,
VOLUME_UP = 0xAF,
MEDIA_NEXT_TRACK = 0xB0,
MEDIA_PREV_TRACK = 0xB1,
MEDIA_STOP = 0xB2,
MEDIA_PLAY_PAUSE = 0xB3,
MEDIA_LAUNCH_MAIL = 0xB4,
MEDIA_LAUNCH_MEDIA_SELECT = 0xB5,
MEDIA_LAUNCH_APP1 = 0xB6,
MEDIA_LAUNCH_APP2 = 0xB7,
OEM_1 = 0xBA,
OEM_PLUS = 0xBB,
OEM_COMMA = 0xBC,
OEM_MINUS = 0xBD,
OEM_PERIOD = 0xBE,
OEM_2 = 0xBF,
OEM_3 = 0xC0,
OEM_4 = 0xDB,
OEM_5 = 0xDC,
OEM_6 = 0xDD,
OEM_7 = 0xDE,
OEM_8 = 0xDF,
OEM_102 = 0xE2,
PROCESSKEY = 0xE5,
PACKET = 0xE7,
DBE_SBCSCHAR = 0xF3,
DBE_DBCSCHAR = 0xF4,
ATTN = 0xF6,
CRSEL = 0xF7,
EXSEL = 0xF8,
EREOF = 0xF9,
PLAY = 0xFA,
ZOOM = 0xFB,
NONAME = 0xFC,
PA1 = 0xFD,
OEM_CLEAR = 0xFE,
UNKNOWN = 0,
// Windows does not have a specific key code for AltGr. We use the unused
// VK_OEM_AX to represent AltGr, matching the behaviour of Firefox on Linux.
ALTGR = 0xE1,
};
} // module mojo
......@@ -213,6 +213,48 @@ uint32 PlatformKeycodeFromNative(const base::NativeEvent& native_event) {
return native_event.keyCode;
}
uint32 WindowsKeycodeFromNative(const base::NativeEvent& native_event) {
return static_cast<uint32>(KeyboardCodeFromNSEvent(native_event));
}
uint16 TextFromNative(const base::NativeEvent& native_event) {
NSString* text = @"";
if ([native_event type] != NSFlagsChanged)
text = [native_event characters];
// These exceptions are based on WebInputEventFactoryMac.mm:
uint32 windows_keycode = WindowsKeycodeFromNative(native_event);
if (windows_keycode == '\r')
text = @"\r";
if ([text isEqualToString:@"\x7F"])
text = @"\x8";
if (windows_keycode == 9)
text = @"\x9";
uint16 return_value;
[text getCharacters:&return_value];
return return_value;
}
uint16 UnmodifiedTextFromNative(const base::NativeEvent& native_event) {
NSString* text = @"";
if ([native_event type] != NSFlagsChanged)
text = [native_event charactersIgnoringModifiers];
// These exceptions are based on WebInputEventFactoryMac.mm:
uint32 windows_keycode = WindowsKeycodeFromNative(native_event);
if (windows_keycode == '\r')
text = @"\r";
if ([text isEqualToString:@"\x7F"])
text = @"\x8";
if (windows_keycode == 9)
text = @"\x9";
uint16 return_value;
[text getCharacters:&return_value];
return return_value;
}
bool IsCharFromNative(const base::NativeEvent& native_event) {
return false;
}
......
......@@ -620,9 +620,42 @@ KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags)
key_code_(key_code),
code_(""),
is_char_(true),
platform_keycode_(0),
character_(character) {
}
KeyEvent::KeyEvent(const KeyEvent& rhs)
: Event(rhs),
key_code_(rhs.key_code_),
code_(rhs.code_),
is_char_(rhs.is_char_),
platform_keycode_(rhs.platform_keycode_),
character_(rhs.character_) {
if (rhs.extended_key_event_data_)
extended_key_event_data_.reset(rhs.extended_key_event_data_->Clone());
}
KeyEvent& KeyEvent::operator=(const KeyEvent& rhs) {
if (this != &rhs) {
Event::operator=(rhs);
key_code_ = rhs.key_code_;
code_ = rhs.code_;
is_char_ = rhs.is_char_;
platform_keycode_ = rhs.platform_keycode_;
character_ = rhs.character_;
if (rhs.extended_key_event_data_)
extended_key_event_data_.reset(rhs.extended_key_event_data_->Clone());
}
return *this;
}
KeyEvent::~KeyEvent() {}
void KeyEvent::SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data) {
extended_key_event_data_ = data.Pass();
}
base::char16 KeyEvent::GetCharacter() const {
if (character_)
return character_;
......
......@@ -10,6 +10,7 @@
#include "base/event_types.h"
#include "base/gtest_prod_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/events/event_constants.h"
#include "ui/events/gesture_event_details.h"
......@@ -546,6 +547,17 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent {
float force_;
};
// An interface that individual platforms can use to store additional data on
// KeyEvent.
//
// Currently only used in mojo.
class EVENTS_EXPORT ExtendedKeyEventData {
public:
virtual ~ExtendedKeyEventData() {}
virtual ExtendedKeyEventData* Clone() const = 0;
};
// A KeyEvent is really two distinct classes, melded together due to the
// DOM legacy of Windows key events: a keystroke event (is_char_ == false),
// or a character event (is_char_ == true).
......@@ -592,6 +604,23 @@ class EVENTS_EXPORT KeyEvent : public Event {
const std::string& code,
int flags);
KeyEvent(const KeyEvent& rhs);
KeyEvent& operator=(const KeyEvent& rhs);
virtual ~KeyEvent();
// TODO(erg): While we transition to mojo, we have to hack around a mismatch
// in our event types. Our ui::Events don't really have all the data we need
// to process key events, and we instead do per-platform conversions with
// native HWNDs or XEvents. And we can't reliably send those native data
// types across mojo types in a cross-platform way. So instead, we set the
// resulting data when read across IPC boundaries.
void SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data);
const ExtendedKeyEventData* extended_key_event_data() const {
return extended_key_event_data_.get();
}
// This bypasses the normal mapping from keystroke events to characters,
// which allows an I18N virtual keyboard to fabricate a keyboard event that
// does not have a corresponding KeyboardCode (example: U+00E1 Latin small
......@@ -603,6 +632,7 @@ class EVENTS_EXPORT KeyEvent : public Event {
base::char16 GetCharacter() 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_; }
KeyboardCode key_code() const { return key_code_; }
......@@ -660,6 +690,12 @@ class EVENTS_EXPORT KeyEvent : public Event {
// e.g. CTRL+A has '\x01'.
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
// mojo instead serializes and deserializes events in potentially different
// processes, we need to have a mechanism to keep track of this data.
scoped_ptr<ExtendedKeyEventData> extended_key_event_data_;
static bool IsRepeated(const KeyEvent& event);
static KeyEvent* last_key_event_;
......
......@@ -63,6 +63,53 @@ 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:
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
return windows_key_code - ui::VKEY_A + 1;
}
if (shift) {
// following graphics chars require shift key to input.
switch (windows_key_code) {
// ctrl-@ maps to \x00 (Null byte)
case ui::VKEY_2:
return 0;
// ctrl-^ maps to \x1E (Record separator, Information separator two)
case ui::VKEY_6:
return 0x1E;
// ctrl-_ maps to \x1F (Unit separator, Information separator one)
case ui::VKEY_OEM_MINUS:
return 0x1F;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
break;
}
} else {
switch (windows_key_code) {
// ctrl-[ maps to \x1B (Escape)
case ui::VKEY_OEM_4:
return 0x1B;
// ctrl-\ maps to \x1C (File separator, Information separator four)
case ui::VKEY_OEM_5:
return 0x1C;
// ctrl-] maps to \x1D (Group separator, Information separator three)
case ui::VKEY_OEM_6:
return 0x1D;
// ctrl-Enter maps to \x0A (Line feed)
case ui::VKEY_RETURN:
return 0x0A;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
break;
}
}
return 0;
}
#endif
int RegisterCustomEventType() {
return ++g_custom_event_types;
}
......
......@@ -87,6 +87,27 @@ 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 uint16 GetControlCharacterForKeycode(int windows_key_code,
bool shift);
#endif
// Returns true if the keyboard event is a character event rather than
// a keystroke event.
EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event);
......@@ -133,20 +154,20 @@ EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
// Gets the fling velocity from a native event. is_cancel is set to true if
// this was a tap down, intended to stop an ongoing fling.
EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
float* vx,
float* vy,
float* vx_ordinal,
float* vy_ordinal,
bool* is_cancel);
float* vx,
float* vy,
float* vx_ordinal,
float* vy_ordinal,
bool* is_cancel);
// Returns whether this is a scroll event and optionally gets the amount to be
// scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
float* x_offset,
float* y_offset,
float* x_offset_ordinal,
float* y_offset_ordinal,
int* finger_count);
float* x_offset,
float* y_offset,
float* x_offset_ordinal,
float* y_offset_ordinal,
int* finger_count);
// Returns whether natural scrolling should be used for touchpad.
EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
......
......@@ -142,4 +142,20 @@ bool IsCharFromNative(const base::NativeEvent& native_event) {
return false;
}
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;
}
} // namespace ui
......@@ -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)) {
......
......@@ -684,6 +684,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