Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / native_web_keyboard_event_aura.cc
blob626d901f31fdbf37fccd0664758ecb8a2562df46
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/native_web_keyboard_event.h"
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/web_input_event_aura.h"
9 #include "ui/events/event.h"
11 namespace {
13 // We need to copy |os_event| in NativeWebKeyboardEvent because it is
14 // queued in RenderWidgetHost and may be passed and used
15 // RenderViewHostDelegate::HandledKeybardEvent after the original aura
16 // event is destroyed.
17 ui::Event* CopyEvent(const ui::Event* event) {
18 return event ? ui::Event::Clone(*event).release() : nullptr;
21 int EventFlagsToWebInputEventModifiers(int flags) {
22 return
23 (flags & ui::EF_SHIFT_DOWN ? blink::WebInputEvent::ShiftKey : 0) |
24 (flags & ui::EF_CONTROL_DOWN ? blink::WebInputEvent::ControlKey : 0) |
25 (flags & ui::EF_CAPS_LOCK_DOWN ? blink::WebInputEvent::CapsLockOn : 0) |
26 (flags & ui::EF_ALT_DOWN ? blink::WebInputEvent::AltKey : 0);
29 } // namespace
31 using blink::WebKeyboardEvent;
33 namespace content {
35 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
36 : os_event(NULL),
37 skip_in_browser(false),
38 match_edit_command(false) {
41 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event)
42 : NativeWebKeyboardEvent(static_cast<ui::KeyEvent&>(*native_event)) {
45 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent& key_event)
46 : WebKeyboardEvent(MakeWebKeyboardEvent(key_event)),
47 os_event(CopyEvent(&key_event)),
48 skip_in_browser(false),
49 match_edit_command(false) {
52 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
53 const NativeWebKeyboardEvent& other)
54 : WebKeyboardEvent(other),
55 os_event(CopyEvent(other.os_event)),
56 skip_in_browser(other.skip_in_browser),
57 match_edit_command(false) {
60 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
61 ui::EventType key_event_type,
62 bool is_char,
63 wchar_t character,
64 int state,
65 double time_stamp_seconds)
66 : os_event(NULL),
67 skip_in_browser(false),
68 match_edit_command(false) {
69 switch (key_event_type) {
70 case ui::ET_KEY_PRESSED:
71 type = is_char ? blink::WebInputEvent::Char :
72 blink::WebInputEvent::RawKeyDown;
73 break;
74 case ui::ET_KEY_RELEASED:
75 type = blink::WebInputEvent::KeyUp;
76 break;
77 default:
78 NOTREACHED();
81 modifiers = EventFlagsToWebInputEventModifiers(state);
82 timeStampSeconds = time_stamp_seconds;
83 windowsKeyCode = character;
84 nativeKeyCode = character;
85 text[0] = character;
86 unmodifiedText[0] = character;
87 isSystemKey =
88 (state & ui::EF_ALT_DOWN) != 0 && (state & ui::EF_ALTGR_DOWN) == 0;
89 setKeyIdentifierFromWindowsKeyCode();
92 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
93 const NativeWebKeyboardEvent& other) {
94 WebKeyboardEvent::operator=(other);
95 delete os_event;
96 os_event = CopyEvent(other.os_event);
97 skip_in_browser = other.skip_in_browser;
98 match_edit_command = other.match_edit_command;
99 return *this;
102 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
103 delete os_event;
106 } // namespace content