Chromium Code Reviews| Index: chrome/browser/ui/views/unhandled_keyboard_event_handler_aurax11.cc |
| diff --git a/chrome/browser/ui/views/unhandled_keyboard_event_handler_aurax11.cc b/chrome/browser/ui/views/unhandled_keyboard_event_handler_aurax11.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..209dda2204482baf5f9cdbae24dd55ab14d89b37 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/unhandled_keyboard_event_handler_aurax11.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright (c) 2011 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 "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" |
| + |
| +#include "base/logging.h" |
| +#include "content/public/browser/native_web_keyboard_event.h" |
| +#include "ui/aura/event.h" |
| +#include "ui/views/focus/focus_manager.h" |
| + |
| +namespace { |
| + |
| +using WebKit::WebInputEvent; |
| + |
| +// TODO(oshima): Use NativeWebKeyboardEvent.os_event to convert to Views event |
| +// and remove the following functions. |
| + |
| +// Convert WebKi'ts event type to Views event type. |
| +ui::EventType GetEventType(const NativeWebKeyboardEvent& event) { |
| + switch (event.type) { |
| + case WebInputEvent::RawKeyDown: |
| + case WebInputEvent::KeyDown: |
| + case WebInputEvent::Char: |
| + return ui::ET_KEY_PRESSED; |
| + case WebInputEvent::KeyUp: |
| + return ui::ET_KEY_RELEASED; |
| + default: |
| + NOTREACHED() << "Unknown event type:" << event.type; |
| + return ui::ET_UNKNOWN; |
| + } |
| +} |
| + |
| +// Converts WebKit's modifiers to View's event flag. |
| +ui::EventFlags ConvertModifier(const NativeWebKeyboardEvent& event, |
| + WebInputEvent::Modifiers modifier, |
| + ui::EventFlags flag) { |
| + return event.modifiers & modifier ? flag : static_cast<ui::EventFlags>(0); |
| +} |
| + |
| +int GetEventFlag(const NativeWebKeyboardEvent& event) { |
| + return |
| + ConvertModifier(event, WebInputEvent::ShiftKey, ui::EF_SHIFT_DOWN) | |
| + ConvertModifier(event, WebInputEvent::ControlKey, ui::EF_CONTROL_DOWN) | |
| + ConvertModifier(event, WebInputEvent::AltKey, ui::EF_ALT_DOWN) | |
| + ConvertModifier( |
| + event, WebInputEvent::LeftButtonDown, ui::EF_LEFT_BUTTON_DOWN) | |
| + ConvertModifier( |
| + event, WebInputEvent::MiddleButtonDown, ui::EF_MIDDLE_BUTTON_DOWN) | |
| + ConvertModifier( |
| + event, WebInputEvent::RightButtonDown, ui::EF_RIGHT_BUTTON_DOWN) | |
| + ConvertModifier(event, WebInputEvent::CapsLockOn, ui::EF_CAPS_LOCK_DOWN); |
| +} |
| + |
| +} // namespace |
| + |
| +UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() { |
| +} |
| + |
| +void UnhandledKeyboardEventHandler::HandleKeyboardEvent( |
| + const NativeWebKeyboardEvent& event, |
| + views::FocusManager* focus_manager) { |
| + if (!focus_manager) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + if (event.os_event && !event.skip_in_browser) { |
| + // The instance of event.os_event is not copied right now and |
| + // cannot be used here. Convert NativeWebKeyboardEvent for now. |
| + // TODO(oshima): Fix NativeWebKeyboardEvent so that we can |
| + // use |KeyEvent(const NativeEvent)| constructor. |
|
oshima
2011/12/16 00:34:37
I'm working on NativeWebKeyboard fix in separate C
|
| + views::KeyEvent views_event( |
| + GetEventType(event), |
| + static_cast<ui::KeyboardCode>(event.windowsKeyCode), |
| + GetEventFlag(event)); |
| + focus_manager->OnKeyEvent(views_event); |
| + } |
| +} |