diff options
20 files changed, 332 insertions, 670 deletions
diff --git a/ash/accelerators/accelerator_dispatcher.cc b/ash/accelerators/accelerator_dispatcher.cc index c4c4f33..6088dfe 100644 --- a/ash/accelerators/accelerator_dispatcher.cc +++ b/ash/accelerators/accelerator_dispatcher.cc @@ -15,7 +15,6 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/shell.h" -#include "ash/wm/event_rewriter_event_filter.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/base/accelerators/accelerator.h" @@ -93,16 +92,7 @@ uint32_t AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) { return POST_DISPATCH_PERFORM_DEFAULT; if (IsKeyEvent(event)) { - // Modifiers can be changed by the user preference, so we need to rewrite - // the event explicitly. ui::KeyEvent key_event(event, false); - ui::EventHandler* event_rewriter = - ash::Shell::GetInstance()->event_rewriter_filter(); - DCHECK(event_rewriter); - event_rewriter->OnKeyEvent(&key_event); - if (key_event.stopped_propagation()) - return POST_DISPATCH_NONE; - if (IsPossibleAcceleratorNotForMenu(key_event)) { if (views::MenuController* menu_controller = views::MenuController::GetActiveInstance()) { diff --git a/ash/ash.gyp b/ash/ash.gyp index 1dbf6bc..e37d958 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -150,7 +150,6 @@ 'drag_drop/drag_drop_tracker.h', 'drag_drop/drag_image_view.cc', 'drag_drop/drag_image_view.h', - 'event_rewriter_delegate.h', 'first_run/desktop_cleaner.cc', 'first_run/desktop_cleaner.h', 'first_run/first_run_helper.cc', @@ -496,8 +495,6 @@ 'wm/drag_window_resizer.h', 'wm/event_client_impl.cc', 'wm/event_client_impl.h', - 'wm/event_rewriter_event_filter.cc', - 'wm/event_rewriter_event_filter.h', 'wm/frame_border_hit_test_controller.cc', 'wm/frame_border_hit_test_controller.h', 'wm/header_painter.cc', diff --git a/ash/event_rewriter_delegate.h b/ash/event_rewriter_delegate.h deleted file mode 100644 index c54c9a3..0000000 --- a/ash/event_rewriter_delegate.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -#ifndef ASH_EVENT_REWRITER_DELEGATE_H_ -#define ASH_EVENT_REWRITER_DELEGATE_H_ - -namespace ui { -class KeyEvent; -class LocatedEvent; -} // namespace aura - -namespace ash { - -// Delegate for rewriting or filtering an event. -class EventRewriterDelegate { - public: - enum Action { - ACTION_REWRITE_EVENT, - ACTION_DROP_EVENT, - }; - - virtual ~EventRewriterDelegate() {} - - // A derived class can do either of the following: - // 1) Just return ACTION_DROP_EVENT to drop the |event|. - // 2) Rewrite the |event| and return ACTION_REWRITE_EVENT. - virtual Action RewriteOrFilterKeyEvent(ui::KeyEvent* event) = 0; - virtual Action RewriteOrFilterLocatedEvent(ui::LocatedEvent* event) = 0; -}; - -} // namespace ash - -#endif // ASH_EVENT_REWRITER_DELEGATE_H_ diff --git a/ash/shell.cc b/ash/shell.cc index dfdb7b6..4789a88 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -58,7 +58,6 @@ #include "ash/wm/coordinate_conversion.h" #include "ash/wm/custom_frame_view_ash.h" #include "ash/wm/event_client_impl.h" -#include "ash/wm/event_rewriter_event_filter.h" #include "ash/wm/lock_state_controller.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/overlay_event_filter.h" @@ -627,7 +626,6 @@ Shell::~Shell() { RemovePreTargetHandler(speech_feedback_handler_.get()); speech_feedback_handler_.reset(); #endif - RemovePreTargetHandler(event_rewriter_filter_.get()); RemovePreTargetHandler(user_activity_detector_.get()); RemovePreTargetHandler(overlay_filter_.get()); RemovePreTargetHandler(input_method_filter_.get()); @@ -840,8 +838,6 @@ void Shell::Init() { #endif // The order in which event filters are added is significant. - event_rewriter_filter_.reset(new internal::EventRewriterEventFilter); - AddPreTargetHandler(event_rewriter_filter_.get()); #if defined(OS_CHROMEOS) // The StickyKeysController also rewrites events and must be added diff --git a/ash/shell.h b/ash/shell.h index 53a4aed..b9222a6 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -327,9 +327,6 @@ class ASH_EXPORT Shell views::corewm::TooltipController* tooltip_controller() { return tooltip_controller_.get(); } - internal::EventRewriterEventFilter* event_rewriter_filter() { - return event_rewriter_filter_.get(); - } internal::OverlayEventFilter* overlay_filter() { return overlay_filter_.get(); } @@ -658,9 +655,6 @@ class ASH_EXPORT Shell event_transformation_handler_; scoped_ptr<WindowTreeHostFactory> window_tree_host_factory_; - // An event filter that rewrites or drops an event. - scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_; - // An event filter that pre-handles key events while the partial // screenshot UI or the keyboard overlay is active. scoped_ptr<internal::OverlayEventFilter> overlay_filter_; diff --git a/ash/wm/event_rewriter_event_filter.cc b/ash/wm/event_rewriter_event_filter.cc deleted file mode 100644 index dd87e2a..0000000 --- a/ash/wm/event_rewriter_event_filter.cc +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -#include "ash/wm/event_rewriter_event_filter.h" - -#include "ash/event_rewriter_delegate.h" -#include "base/logging.h" -#include "ui/events/event.h" - -namespace ash { -namespace internal { - -EventRewriterEventFilter::EventRewriterEventFilter() {} - -EventRewriterEventFilter::~EventRewriterEventFilter() {} - -void EventRewriterEventFilter::SetEventRewriterDelegate( - scoped_ptr<EventRewriterDelegate> delegate) { - delegate_ = delegate.Pass(); -} - -void EventRewriterEventFilter::OnKeyEvent(ui::KeyEvent* event) { - if (!delegate_) - return; - - // Do not consume a translated key event which is generated by an IME. - if (event->type() == ui::ET_TRANSLATED_KEY_PRESS || - event->type() == ui::ET_TRANSLATED_KEY_RELEASE) { - return; - } - - switch (delegate_->RewriteOrFilterKeyEvent(event)) { - case EventRewriterDelegate::ACTION_REWRITE_EVENT: - break; - case EventRewriterDelegate::ACTION_DROP_EVENT: - event->StopPropagation(); - break; - } -} - -void EventRewriterEventFilter::OnMouseEvent(ui::MouseEvent* event) { - if (!delegate_) - return; - - switch (delegate_->RewriteOrFilterLocatedEvent(event)) { - case EventRewriterDelegate::ACTION_REWRITE_EVENT: - break; - case EventRewriterDelegate::ACTION_DROP_EVENT: - event->StopPropagation(); - break; - } -} - -} // namespace internal -} // namespace ash diff --git a/ash/wm/event_rewriter_event_filter.h b/ash/wm/event_rewriter_event_filter.h deleted file mode 100644 index 86f7f53..0000000 --- a/ash/wm/event_rewriter_event_filter.h +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -#ifndef ASH_WM_EVENT_REWRITER_EVENT_FILTER_ -#define ASH_WM_EVENT_REWRITER_EVENT_FILTER_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/events/event_handler.h" - -namespace ash { - -class EventRewriterDelegate; - -namespace internal { - -// An event filter that rewrites or drops an event. -class ASH_EXPORT EventRewriterEventFilter : public ui::EventHandler { - public: - EventRewriterEventFilter(); - virtual ~EventRewriterEventFilter(); - - void SetEventRewriterDelegate(scoped_ptr<EventRewriterDelegate> delegate); - - private: - // Overridden from ui::EventHandler: - virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; - - scoped_ptr<EventRewriterDelegate> delegate_; - - DISALLOW_COPY_AND_ASSIGN(EventRewriterEventFilter); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_WM_EVENT_REWRITER_EVENT_FILTER_ diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager.cc b/chrome/browser/chromeos/accessibility/accessibility_manager.cc index 9274012..064699b 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_manager.cc +++ b/chrome/browser/chromeos/accessibility/accessibility_manager.cc @@ -12,7 +12,6 @@ #include "ash/shell.h" #include "ash/sticky_keys/sticky_keys_controller.h" #include "ash/system/tray/system_tray_notifier.h" -#include "ash/wm/event_rewriter_event_filter.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/metrics/histogram.h" diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index d1f76ce..63fea22 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -32,6 +32,7 @@ #include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/contacts/contact_manager.h" #include "chrome/browser/chromeos/dbus/cros_dbus_service.h" +#include "chrome/browser/chromeos/event_rewriter.h" #include "chrome/browser/chromeos/extensions/default_app_order.h" #include "chrome/browser/chromeos/extensions/extension_system_event_observer.h" #include "chrome/browser/chromeos/external_metrics.h" @@ -702,6 +703,8 @@ void ChromeBrowserMainPartsChromeos::PreBrowserStart() { DeviceUMA::GetInstance(); #endif + event_rewriter_.reset(new EventRewriter()); + // -- This used to be in ChromeBrowserMainParts::PreMainMessageLoopRun() // -- immediately after ChildProcess::WaitForDebugger(). @@ -766,6 +769,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { retail_mode_power_save_blocker_.reset(); peripheral_battery_observer_.reset(); power_prefs_.reset(); + event_rewriter_.reset(); // The XInput2 event listener needs to be shut down earlier than when // Singletons are finally destroyed in AtExitManager. diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index 4a6038c..462d319 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -21,6 +21,7 @@ class PowerSaveBlocker; namespace chromeos { class DataPromoNotification; +class EventRewriter; class ExtensionSystemEventObserver; class IdleActionWarningObserver; class MagnificationManager; @@ -71,6 +72,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { scoped_ptr<DataPromoNotification> data_promo_notification_; scoped_ptr<internal::DBusServices> dbus_services_; + scoped_ptr<EventRewriter> event_rewriter_; VersionLoader cros_version_loader_; base::CancelableTaskTracker tracker_; diff --git a/chrome/browser/ui/ash/event_rewriter.cc b/chrome/browser/chromeos/event_rewriter.cc index 5912b1e..029d9af 100644 --- a/chrome/browser/ui/ash/event_rewriter.cc +++ b/chrome/browser/chromeos/event_rewriter.cc @@ -1,51 +1,47 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. -#include "chrome/browser/ui/ash/event_rewriter.h" +#include "chrome/browser/chromeos/event_rewriter.h" -#include <vector> - -#include "ash/shell.h" -#include "base/logging.h" -#include "base/prefs/pref_service.h" -#include "base/strings/string_util.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "ui/aura/root_window.h" -#include "ui/events/event.h" -#include "ui/events/event_utils.h" -#include "ui/events/keycodes/keyboard_code_conversion.h" - -#if defined(OS_CHROMEOS) #include <X11/extensions/XInput2.h> #include <X11/keysym.h> #include <X11/XF86keysym.h> #include <X11/Xlib.h> - -// Get rid of a macro from Xlib.h that conflicts with OwnershipService class. +// Get rid of macros from Xlib.h that conflicts with other parts of the code. +#undef RootWindow #undef Status +#include <vector> + +#include "ash/shell.h" #include "ash/wm/window_state.h" +#include "ash/wm/window_util.h" #include "base/command_line.h" +#include "base/logging.h" +#include "base/prefs/pref_service.h" +#include "base/strings/string_util.h" #include "base/sys_info.h" #include "chrome/browser/chromeos/keyboard_driven_event_rewriter.h" #include "chrome/browser/chromeos/login/login_display_host_impl.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/pref_names.h" #include "chromeos/chromeos_switches.h" #include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/xkeyboard.h" +#include "ui/aura/root_window.h" #include "ui/base/x/x11_util.h" +#include "ui/events/event.h" +#include "ui/events/event_utils.h" #include "ui/events/keycodes/keyboard_code_conversion_x.h" #include "ui/views/corewm/window_util.h" -#endif namespace { const int kBadDeviceId = -1; -#if defined(OS_CHROMEOS) const char kNeo2LayoutId[] = "xkb:de:neo:ger"; const char kCaMultixLayoutId[] = "xkb:ca:multix:fra"; @@ -136,43 +132,36 @@ bool IsMod3UsedByCurrentInputMethod() { manager->GetCurrentInputMethod().id() == kCaMultixLayoutId; } -#endif // defined(OS_CHROMEOS) - } // namespace +namespace chromeos { + EventRewriter::EventRewriter() : last_device_id_(kBadDeviceId), -#if defined(OS_CHROMEOS) xkeyboard_for_testing_(NULL), - keyboard_driven_event_rewriter_( - new chromeos::KeyboardDrivenEventRewriter), -#endif + keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter), pref_service_for_testing_(NULL) { // The ash shell isn't instantiated for our unit tests. if (ash::Shell::HasInstance()) { ash::Shell::GetPrimaryRootWindow()->GetDispatcher()-> AddRootWindowObserver(this); } -#if defined(OS_CHROMEOS) + base::MessageLoopForUI::current()->AddObserver(this); if (base::SysInfo::IsRunningOnChromeOS()) { - chromeos::XInputHierarchyChangedEventListener::GetInstance() - ->AddObserver(this); + XInputHierarchyChangedEventListener::GetInstance()->AddObserver(this); } RefreshKeycodes(); -#endif } EventRewriter::~EventRewriter() { + base::MessageLoopForUI::current()->RemoveObserver(this); if (ash::Shell::HasInstance()) { ash::Shell::GetPrimaryRootWindow()->GetDispatcher()-> RemoveRootWindowObserver(this); } -#if defined(OS_CHROMEOS) if (base::SysInfo::IsRunningOnChromeOS()) { - chromeos::XInputHierarchyChangedEventListener::GetInstance() - ->RemoveObserver(this); + XInputHierarchyChangedEventListener::GetInstance()->RemoveObserver(this); } -#endif } EventRewriter::DeviceType EventRewriter::DeviceAddedForTesting( @@ -203,31 +192,27 @@ EventRewriter::DeviceType EventRewriter::GetDeviceType( return kDeviceUnknown; } -void EventRewriter::RewriteForTesting(ui::KeyEvent* event) { +void EventRewriter::RewriteForTesting(XEvent* event) { Rewrite(event); } -ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterKeyEvent( - ui::KeyEvent* event) { - if (event->HasNativeEvent()) - Rewrite(event); - return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; +void EventRewriter::OnKeyboardMappingChanged(const aura::RootWindow* root) { + RefreshKeycodes(); } -ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterLocatedEvent( - ui::LocatedEvent* event) { - if (event->HasNativeEvent()) - RewriteLocatedEvent(event); - return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; +base::EventStatus EventRewriter::WillProcessEvent( + const base::NativeEvent& event) { + XEvent* xevent = event; + if (xevent->type == KeyPress || xevent->type == KeyRelease) + Rewrite(xevent); + else if (xevent->type == GenericEvent) + RewriteLocatedEvent(xevent); + return base::EVENT_CONTINUE; } -void EventRewriter::OnKeyboardMappingChanged(const aura::RootWindow* root) { -#if defined(OS_CHROMEOS) - RefreshKeycodes(); -#endif +void EventRewriter::DidProcessEvent(const base::NativeEvent& event) { } -#if defined(OS_CHROMEOS) void EventRewriter::DeviceAdded(int device_id) { DCHECK_NE(XIAllDevices, device_id); DCHECK_NE(XIAllMasterDevices, device_id); @@ -288,19 +273,15 @@ KeyCode EventRewriter::NativeKeySymToNativeKeycode(KeySym keysym) { return keycode; } -bool EventRewriter::TopRowKeysAreFunctionKeys(ui::KeyEvent* event) const { +bool EventRewriter::TopRowKeysAreFunctionKeys(XEvent* event) const { const PrefService* prefs = GetPrefService(); if (prefs && prefs->FindPreference(prefs::kLanguageSendFunctionKeys) && prefs->GetBoolean(prefs::kLanguageSendFunctionKeys)) return true; - aura::Window* target = static_cast<aura::Window*>(event->target()); - if (!target) - return false; - aura::Window* top_level = views::corewm::GetToplevelWindow(target); - return top_level && - ash::wm::GetWindowState(top_level)->top_row_keys_are_function_keys(); + ash::wm::WindowState* state = ash::wm::GetActiveWindowState(); + return state ? state->top_row_keys_are_function_keys() : false; } bool EventRewriter::RewriteWithKeyboardRemappingsByKeySym( @@ -308,11 +289,8 @@ bool EventRewriter::RewriteWithKeyboardRemappingsByKeySym( size_t num_remappings, KeySym keysym, unsigned int native_mods, - unsigned int mods, KeySym* remapped_native_keysym, - unsigned int* remapped_native_mods, - ui::KeyboardCode* remapped_keycode, - unsigned int* remapped_mods) { + unsigned int* remapped_native_mods) { for (size_t i = 0; i < num_remappings; ++i) { const KeyboardRemapping& map = remappings[i]; @@ -323,10 +301,8 @@ bool EventRewriter::RewriteWithKeyboardRemappingsByKeySym( continue; *remapped_native_keysym = map.output_keysym; - *remapped_keycode = map.output_keycode; *remapped_native_mods = (native_mods & ~map.input_native_mods) | map.output_native_mods; - *remapped_mods = (mods & ~map.input_mods) | map.output_mods; return true; } @@ -338,11 +314,8 @@ bool EventRewriter::RewriteWithKeyboardRemappingsByKeyCode( size_t num_remappings, KeyCode keycode, unsigned int native_mods, - unsigned int mods, KeySym* remapped_native_keysym, - unsigned int* remapped_native_mods, - ui::KeyboardCode* remapped_keycode, - unsigned int* remapped_mods) { + unsigned int* remapped_native_mods) { for (size_t i = 0; i < num_remappings; ++i) { const KeyboardRemapping& map = remappings[i]; @@ -354,16 +327,13 @@ bool EventRewriter::RewriteWithKeyboardRemappingsByKeyCode( continue; *remapped_native_keysym = map.output_keysym; - *remapped_keycode = map.output_keycode; *remapped_native_mods = (native_mods & ~map.input_native_mods) | map.output_native_mods; - *remapped_mods = (mods & ~map.input_mods) | map.output_mods; return true; } return false; } -#endif // defined(OS_CHROMEOS) const PrefService* EventRewriter::GetPrefService() const { if (pref_service_for_testing_) @@ -372,11 +342,10 @@ const PrefService* EventRewriter::GetPrefService() const { return profile ? profile->GetPrefs() : NULL; } -void EventRewriter::Rewrite(ui::KeyEvent* event) { -#if defined(OS_CHROMEOS) +void EventRewriter::Rewrite(XEvent* event) { // Do not rewrite an event sent by ui_controls::SendKeyPress(). See // crbug.com/136465. - if (event->native_event()->xkey.send_event) + if (event->xkey.send_event) return; // Keyboard driven rewriting happen first. Skip further processing if event is @@ -385,7 +354,7 @@ void EventRewriter::Rewrite(ui::KeyEvent* event) { event)) { return; } -#endif + RewriteModifiers(event); RewriteNumPadKeys(event); RewriteExtendedKeys(event); @@ -409,15 +378,12 @@ bool EventRewriter::IsAppleKeyboard() const { } void EventRewriter::GetRemappedModifierMasks( - int original_flags, unsigned int original_native_modifiers, - int* remapped_flags, unsigned int* remapped_native_modifiers) const { -#if defined(OS_CHROMEOS) // TODO(glotov): remove the following condition when we do not restart chrome // when user logs in as guest. See Rewrite() for details. - if (chromeos::UserManager::Get()->IsLoggedInAsGuest() && - chromeos::LoginDisplayHostImpl::default_host()) { + if (UserManager::Get()->IsLoggedInAsGuest() && + LoginDisplayHostImpl::default_host()) { return; } @@ -448,20 +414,14 @@ void EventRewriter::GetRemappedModifierMasks( remapped_key = kModifierRemappingCtrl; } if (remapped_key) { - *remapped_flags |= remapped_key->flag; *remapped_native_modifiers |= remapped_key->native_modifier; } else { - *remapped_flags |= kModifierFlagToPrefName[i].flag; *remapped_native_modifiers |= kModifierFlagToPrefName[i].native_modifier; } } } - *remapped_flags = - (original_flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) | - *remapped_flags; - unsigned int native_mask = Mod4Mask | ControlMask | Mod1Mask; if (!skip_mod2) native_mask |= Mod2Mask; @@ -470,11 +430,10 @@ void EventRewriter::GetRemappedModifierMasks( *remapped_native_modifiers = (original_native_modifiers & ~native_mask) | *remapped_native_modifiers; -#endif } -bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { -#if defined(OS_CHROMEOS) +bool EventRewriter::RewriteModifiers(XEvent* event) { + DCHECK(event->type == KeyPress || event->type == KeyRelease); // Do nothing if we have just logged in as guest but have not restarted chrome // process yet (so we are still on the login screen). In this situations we // have no user profile so can not do anything useful. @@ -482,22 +441,20 @@ bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { // restart chrome process. In future this is to be changed. // TODO(glotov): remove the following condition when we do not restart chrome // when user logs in as guest. - if (chromeos::UserManager::Get()->IsLoggedInAsGuest() && - chromeos::LoginDisplayHostImpl::default_host()) + if (UserManager::Get()->IsLoggedInAsGuest() && + LoginDisplayHostImpl::default_host()) return false; const PrefService* pref_service = GetPrefService(); if (!pref_service) return false; - DCHECK_EQ(chromeos::input_method::kControlKey, - kModifierRemappingCtrl->remap_to); + DCHECK_EQ(input_method::kControlKey, kModifierRemappingCtrl->remap_to); - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); + XKeyEvent* xkey = &event->xkey; KeySym keysym = XLookupKeysym(xkey, 0); - - ui::KeyboardCode remapped_keycode = event->key_code(); + ui::KeyboardCode original_keycode = ui::KeyboardCodeFromNative(event); + ui::KeyboardCode remapped_keycode = original_keycode; KeyCode remapped_native_keycode = xkey->keycode; // First, remap |keysym|. @@ -552,113 +509,93 @@ bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { } if (remapped_key) { + int flags = ui::EventFlagsFromNative(event); remapped_keycode = remapped_key->keycode; - const size_t level = (event->IsShiftDown() ? (1 << 1) : 0) + + const size_t level = ((flags & ui::EF_SHIFT_DOWN) ? (1 << 1) : 0) + (IsRight(keysym) ? (1 << 0) : 0); const KeySym native_keysym = remapped_key->native_keysyms[level]; remapped_native_keycode = NativeKeySymToNativeKeycode(native_keysym); } // Next, remap modifier bits. - int remapped_flags = 0; unsigned int remapped_native_modifiers = 0U; - GetRemappedModifierMasks(event->flags(), xkey->state, - &remapped_flags, &remapped_native_modifiers); + GetRemappedModifierMasks(xkey->state, &remapped_native_modifiers); // Toggle Caps Lock if the remapped key is ui::VKEY_CAPITAL, but do nothing if // the original key is ui::VKEY_CAPITAL (i.e. a Caps Lock key on an external // keyboard is pressed) since X can handle that case. - if ((event->type() == ui::ET_KEY_PRESSED) && - (event->key_code() != ui::VKEY_CAPITAL) && - (remapped_keycode == ui::VKEY_CAPITAL)) { - chromeos::input_method::XKeyboard* xkeyboard = xkeyboard_for_testing_ ? + if (event->type == KeyPress && + original_keycode != ui::VKEY_CAPITAL && + remapped_keycode == ui::VKEY_CAPITAL) { + input_method::XKeyboard* xkeyboard = xkeyboard_for_testing_ ? xkeyboard_for_testing_ : - chromeos::input_method::InputMethodManager::Get()->GetXKeyboard(); + input_method::InputMethodManager::Get()->GetXKeyboard(); xkeyboard->SetCapsLockEnabled(!xkeyboard->CapsLockIsEnabled()); } - OverwriteEvent(event, - remapped_native_keycode, remapped_native_modifiers, - remapped_keycode, remapped_flags); + OverwriteEvent(event, remapped_native_keycode, remapped_native_modifiers); return true; -#else - // TODO(yusukes): Support Ash on other platforms if needed. - return false; -#endif } -bool EventRewriter::RewriteNumPadKeys(ui::KeyEvent* event) { +bool EventRewriter::RewriteNumPadKeys(XEvent* event) { + DCHECK(event->type == KeyPress || event->type == KeyRelease); bool rewritten = false; -#if defined(OS_CHROMEOS) - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); - + XKeyEvent* xkey = &event->xkey; const KeySym keysym = XLookupKeysym(xkey, 0); switch (keysym) { case XK_KP_Insert: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_0), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD0, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Delete: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_Decimal), - xkey->state | Mod2Mask, - ui::VKEY_DECIMAL, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_End: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_1), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD1, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Down: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_2), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD2, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Next: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_3), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD3, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Left: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_4), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD4, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Begin: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_5), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD5, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Right: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_6), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD6, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Home: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_7), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD7, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Up: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_8), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD8, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Prior: OverwriteEvent(event, NativeKeySymToNativeKeycode(XK_KP_9), - xkey->state | Mod2Mask, - ui::VKEY_NUMPAD9, event->flags()); + xkey->state | Mod2Mask); rewritten = true; break; case XK_KP_Divide: @@ -667,199 +604,145 @@ bool EventRewriter::RewriteNumPadKeys(ui::KeyEvent* event) { case XK_KP_Add: case XK_KP_Enter: // Add Mod2Mask for consistency. - OverwriteEvent(event, xkey->keycode, xkey->state | Mod2Mask, - event->key_code(), event->flags()); + OverwriteEvent(event, xkey->keycode, xkey->state | Mod2Mask); rewritten = true; break; default: break; } -#else - // TODO(yusukes): Support Ash on other platforms if needed. -#endif return rewritten; } -bool EventRewriter::RewriteExtendedKeys(ui::KeyEvent* event) { -#if defined(OS_CHROMEOS) - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); +bool EventRewriter::RewriteExtendedKeys(XEvent* event) { + DCHECK(event->type == KeyPress || event->type == KeyRelease); + XKeyEvent* xkey = &event->xkey; const KeySym keysym = XLookupKeysym(xkey, 0); KeySym remapped_native_keysym = 0; unsigned int remapped_native_mods = 0; - ui::KeyboardCode remapped_keycode = ui::VKEY_UNKNOWN; - unsigned int remapped_mods = 0; + bool rewritten = false; if (xkey->state & Mod4Mask) { // Allow Search to avoid rewriting extended keys. static const KeyboardRemapping kAvoidRemappings[] = { { // Alt+Backspace - XK_BackSpace, - ui::EF_ALT_DOWN, Mod1Mask | Mod4Mask, - XK_BackSpace, ui::VKEY_BACK, - ui::EF_ALT_DOWN, Mod1Mask, + XK_BackSpace, Mod1Mask | Mod4Mask, + XK_BackSpace, Mod1Mask, }, { // Control+Alt+Up - XK_Up, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, - Mod1Mask | ControlMask | Mod4Mask, - XK_Up, ui::VKEY_UP, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, + XK_Up, Mod1Mask | ControlMask | Mod4Mask, + XK_Up, Mod1Mask | ControlMask, }, { // Alt+Up - XK_Up, - ui::EF_ALT_DOWN, Mod1Mask | Mod4Mask, - XK_Up, ui::VKEY_UP, - ui::EF_ALT_DOWN, Mod1Mask, + XK_Up, Mod1Mask | Mod4Mask, + XK_Up, Mod1Mask, }, { // Control+Alt+Down - XK_Down, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, - Mod1Mask | ControlMask | Mod4Mask, - XK_Down, ui::VKEY_DOWN, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, + XK_Down, Mod1Mask | ControlMask | Mod4Mask, + XK_Down, Mod1Mask | ControlMask, }, { // Alt+Down - XK_Down, - ui::EF_ALT_DOWN, Mod1Mask | Mod4Mask, - XK_Down, ui::VKEY_DOWN, - ui::EF_ALT_DOWN, Mod1Mask, + XK_Down, Mod1Mask | Mod4Mask, + XK_Down, Mod1Mask, } }; - RewriteWithKeyboardRemappingsByKeySym(kAvoidRemappings, - arraysize(kAvoidRemappings), - keysym, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kAvoidRemappings, + arraysize(kAvoidRemappings), + keysym, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } - if (remapped_keycode == ui::VKEY_UNKNOWN) { + if (!rewritten) { static const KeyboardRemapping kSearchRemappings[] = { { // Search+BackSpace -> Delete - XK_BackSpace, - 0, Mod4Mask, - XK_Delete, ui::VKEY_DELETE, - 0, 0 + XK_BackSpace, Mod4Mask, + XK_Delete, 0 }, { // Search+Left -> Home - XK_Left, - 0, Mod4Mask, - XK_Home, ui::VKEY_HOME, - 0, 0 + XK_Left, Mod4Mask, + XK_Home, 0 }, { // Search+Up -> Prior (aka PageUp) - XK_Up, - 0, Mod4Mask, - XK_Prior, ui::VKEY_PRIOR, - 0, 0 + XK_Up, Mod4Mask, + XK_Prior, 0 }, { // Search+Right -> End - XK_Right, - 0, Mod4Mask, - XK_End, ui::VKEY_END, - 0, 0 + XK_Right, Mod4Mask, + XK_End, 0 }, { // Search+Down -> Next (aka PageDown) - XK_Down, - 0, Mod4Mask, - XK_Next, ui::VKEY_NEXT, - 0, 0 + XK_Down, Mod4Mask, + XK_Next, 0 }, { // Search+Period -> Insert - XK_period, - 0, Mod4Mask, - XK_Insert, ui::VKEY_INSERT, - 0, 0 + XK_period, Mod4Mask, + XK_Insert, 0 } }; - RewriteWithKeyboardRemappingsByKeySym(kSearchRemappings, - arraysize(kSearchRemappings), - keysym, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kSearchRemappings, + arraysize(kSearchRemappings), + keysym, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } - if (remapped_keycode == ui::VKEY_UNKNOWN) { + if (!rewritten) { static const KeyboardRemapping kNonSearchRemappings[] = { { // Alt+BackSpace -> Delete - XK_BackSpace, - ui::EF_ALT_DOWN, Mod1Mask, - XK_Delete, ui::VKEY_DELETE, - 0, 0 + XK_BackSpace, Mod1Mask, + XK_Delete, 0 }, { // Control+Alt+Up -> Home - XK_Up, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, - XK_Home, ui::VKEY_HOME, - 0, 0 + XK_Up, Mod1Mask | ControlMask, + XK_Home, 0 }, { // Alt+Up -> Prior (aka PageUp) - XK_Up, - ui::EF_ALT_DOWN, Mod1Mask, - XK_Prior, ui::VKEY_PRIOR, - 0, 0 + XK_Up, Mod1Mask, + XK_Prior, 0 }, { // Control+Alt+Down -> End - XK_Down, - ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, - XK_End, ui::VKEY_END, - 0, 0 + XK_Down, Mod1Mask | ControlMask, + XK_End, 0 }, { // Alt+Down -> Next (aka PageDown) - XK_Down, - ui::EF_ALT_DOWN, Mod1Mask, - XK_Next, ui::VKEY_NEXT, - 0, 0 + XK_Down, Mod1Mask, + XK_Next, 0 } }; - RewriteWithKeyboardRemappingsByKeySym(kNonSearchRemappings, - arraysize(kNonSearchRemappings), - keysym, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kNonSearchRemappings, + arraysize(kNonSearchRemappings), + keysym, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } - if (remapped_keycode == ui::VKEY_UNKNOWN) + if (!rewritten) return false; OverwriteEvent(event, NativeKeySymToNativeKeycode(remapped_native_keysym), - remapped_native_mods, - remapped_keycode, - remapped_mods); + remapped_native_mods); return true; -#else - // TODO(yusukes): Support Ash on other platforms if needed. - return false; -#endif } -bool EventRewriter::RewriteFunctionKeys(ui::KeyEvent* event) { -#if defined(OS_CHROMEOS) - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); +bool EventRewriter::RewriteFunctionKeys(XEvent* event) { + DCHECK(event->type == KeyPress || event->type == KeyRelease); + XKeyEvent* xkey = &event->xkey; const KeySym keysym = XLookupKeysym(xkey, 0); KeySym remapped_native_keysym = 0; unsigned int remapped_native_mods = 0; - ui::KeyboardCode remapped_keycode = ui::VKEY_UNKNOWN; - unsigned int remapped_mods = 0; + bool rewritten = false; // By default the top row (F1-F12) keys are special keys for back, forward, // brightness, volume, etc. However, windows for v2 apps can optionally @@ -869,71 +752,65 @@ bool EventRewriter::RewriteFunctionKeys(ui::KeyEvent* event) { if ((xkey->state & Mod4Mask) && top_row_keys_are_special_keys) { // Allow Search to avoid rewriting F1-F12. static const KeyboardRemapping kFkeysToFkeys[] = { - { XK_F1, 0, Mod4Mask, XK_F1, ui::VKEY_F1, }, - { XK_F2, 0, Mod4Mask, XK_F2, ui::VKEY_F2, }, - { XK_F3, 0, Mod4Mask, XK_F3, ui::VKEY_F3, }, - { XK_F4, 0, Mod4Mask, XK_F4, ui::VKEY_F4, }, - { XK_F5, 0, Mod4Mask, XK_F5, ui::VKEY_F5, }, - { XK_F6, 0, Mod4Mask, XK_F6, ui::VKEY_F6, }, - { XK_F7, 0, Mod4Mask, XK_F7, ui::VKEY_F7, }, - { XK_F8, 0, Mod4Mask, XK_F8, ui::VKEY_F8, }, - { XK_F9, 0, Mod4Mask, XK_F9, ui::VKEY_F9, }, - { XK_F10, 0, Mod4Mask, XK_F10, ui::VKEY_F10, }, - { XK_F11, 0, Mod4Mask, XK_F11, ui::VKEY_F11, }, - { XK_F12, 0, Mod4Mask, XK_F12, ui::VKEY_F12, }, + { XK_F1, Mod4Mask, XK_F1, }, + { XK_F2, Mod4Mask, XK_F2, }, + { XK_F3, Mod4Mask, XK_F3, }, + { XK_F4, Mod4Mask, XK_F4, }, + { XK_F5, Mod4Mask, XK_F5, }, + { XK_F6, Mod4Mask, XK_F6, }, + { XK_F7, Mod4Mask, XK_F7, }, + { XK_F8, Mod4Mask, XK_F8, }, + { XK_F9, Mod4Mask, XK_F9, }, + { XK_F10, Mod4Mask, XK_F10, }, + { XK_F11, Mod4Mask, XK_F11, }, + { XK_F12, Mod4Mask, XK_F12, }, }; - RewriteWithKeyboardRemappingsByKeySym(kFkeysToFkeys, - arraysize(kFkeysToFkeys), - keysym, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kFkeysToFkeys, + arraysize(kFkeysToFkeys), + keysym, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } - if (remapped_keycode == ui::VKEY_UNKNOWN) { + if (!rewritten) { static const KeyboardRemapping kFkeysToSpecialKeys[] = { - { XK_F1, 0, 0, XF86XK_Back, ui::VKEY_BROWSER_BACK, 0, 0 }, - { XK_F2, 0, 0, XF86XK_Forward, ui::VKEY_BROWSER_FORWARD, 0, 0 }, - { XK_F3, 0, 0, XF86XK_Reload, ui::VKEY_BROWSER_REFRESH, 0, 0 }, - { XK_F4, 0, 0, XF86XK_LaunchB, ui::VKEY_MEDIA_LAUNCH_APP2, 0, 0 }, - { XK_F5, 0, 0, XF86XK_LaunchA, ui::VKEY_MEDIA_LAUNCH_APP1, 0, 0 }, - { XK_F6, 0, 0, XF86XK_MonBrightnessDown, ui::VKEY_BRIGHTNESS_DOWN, 0, 0 }, - { XK_F7, 0, 0, XF86XK_MonBrightnessUp, ui::VKEY_BRIGHTNESS_UP, 0, 0 }, - { XK_F8, 0, 0, XF86XK_AudioMute, ui::VKEY_VOLUME_MUTE, 0, 0 }, - { XK_F9, 0, 0, XF86XK_AudioLowerVolume, ui::VKEY_VOLUME_DOWN, 0, 0 }, - { XK_F10, 0, 0, XF86XK_AudioRaiseVolume, ui::VKEY_VOLUME_UP, 0, 0 }, + { XK_F1, 0, XF86XK_Back, 0 }, + { XK_F2, 0, XF86XK_Forward, 0 }, + { XK_F3, 0, XF86XK_Reload, 0 }, + { XK_F4, 0, XF86XK_LaunchB, 0 }, + { XK_F5, 0, XF86XK_LaunchA, 0 }, + { XK_F6, 0, XF86XK_MonBrightnessDown, 0 }, + { XK_F7, 0, XF86XK_MonBrightnessUp, 0 }, + { XK_F8, 0, XF86XK_AudioMute, 0 }, + { XK_F9, 0, XF86XK_AudioLowerVolume, 0 }, + { XK_F10, 0, XF86XK_AudioRaiseVolume, 0 }, }; if (top_row_keys_are_special_keys) { // Rewrite the F1-F12 keys on a Chromebook keyboard to special keys. - RewriteWithKeyboardRemappingsByKeySym(kFkeysToSpecialKeys, - arraysize(kFkeysToSpecialKeys), - keysym, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kFkeysToSpecialKeys, + arraysize(kFkeysToSpecialKeys), + keysym, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } else if (xkey->state & Mod4Mask) { // Use Search + F1-F12 for the special keys. - RewriteWithKeyboardRemappingsByKeySym(kFkeysToSpecialKeys, - arraysize(kFkeysToSpecialKeys), - keysym, - xkey->state & !Mod4Mask, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeySym( + kFkeysToSpecialKeys, + arraysize(kFkeysToSpecialKeys), + keysym, + xkey->state & !Mod4Mask, + &remapped_native_keysym, + &remapped_native_mods); } } - if (remapped_keycode == ui::VKEY_UNKNOWN && xkey->state & Mod4Mask) { + if (!rewritten && (xkey->state & Mod4Mask)) { // Remap Search+<number> to F<number>. // We check the keycode here instead of the keysym, as these keys have // different keysyms when modifiers are pressed, such as shift. @@ -942,64 +819,47 @@ bool EventRewriter::RewriteFunctionKeys(ui::KeyEvent* event) { // should make layout-specific choices here. For eg. on a french keyboard // "-" and "6" are the same key, so F11 will not be accessible. static const KeyboardRemapping kNumberKeysToFkeys[] = { - { XK_1, 0, Mod4Mask, XK_F1, ui::VKEY_F1, 0, 0 }, - { XK_2, 0, Mod4Mask, XK_F2, ui::VKEY_F2, 0, 0 }, - { XK_3, 0, Mod4Mask, XK_F3, ui::VKEY_F3, 0, 0 }, - { XK_4, 0, Mod4Mask, XK_F4, ui::VKEY_F4, 0, 0 }, - { XK_5, 0, Mod4Mask, XK_F5, ui::VKEY_F5, 0, 0 }, - { XK_6, 0, Mod4Mask, XK_F6, ui::VKEY_F6, 0, 0 }, - { XK_7, 0, Mod4Mask, XK_F7, ui::VKEY_F7, 0, 0 }, - { XK_8, 0, Mod4Mask, XK_F8, ui::VKEY_F8, 0, 0 }, - { XK_9, 0, Mod4Mask, XK_F9, ui::VKEY_F9, 0, 0 }, - { XK_0, 0, Mod4Mask, XK_F10, ui::VKEY_F10, 0, 0 }, - { XK_minus, 0, Mod4Mask, XK_F11, ui::VKEY_F11, 0, 0 }, - { XK_equal, 0, Mod4Mask, XK_F12, ui::VKEY_F12, 0, 0 } + { XK_1, Mod4Mask, XK_F1, 0 }, + { XK_2, Mod4Mask, XK_F2, 0 }, + { XK_3, Mod4Mask, XK_F3, 0 }, + { XK_4, Mod4Mask, XK_F4, 0 }, + { XK_5, Mod4Mask, XK_F5, 0 }, + { XK_6, Mod4Mask, XK_F6, 0 }, + { XK_7, Mod4Mask, XK_F7, 0 }, + { XK_8, Mod4Mask, XK_F8, 0 }, + { XK_9, Mod4Mask, XK_F9, 0 }, + { XK_0, Mod4Mask, XK_F10, 0 }, + { XK_minus, Mod4Mask, XK_F11, 0 }, + { XK_equal, Mod4Mask, XK_F12, 0 } }; - RewriteWithKeyboardRemappingsByKeyCode(kNumberKeysToFkeys, - arraysize(kNumberKeysToFkeys), - xkey->keycode, - xkey->state, - event->flags(), - &remapped_native_keysym, - &remapped_native_mods, - &remapped_keycode, - &remapped_mods); + rewritten = RewriteWithKeyboardRemappingsByKeyCode( + kNumberKeysToFkeys, + arraysize(kNumberKeysToFkeys), + xkey->keycode, + xkey->state, + &remapped_native_keysym, + &remapped_native_mods); } - if (remapped_keycode == ui::VKEY_UNKNOWN) + if (!rewritten) return false; OverwriteEvent(event, NativeKeySymToNativeKeycode(remapped_native_keysym), - remapped_native_mods, - remapped_keycode, - remapped_mods); + remapped_native_mods); return true; -#else - // TODO(danakj): Support Ash on other platforms if needed. - return false; -#endif } -void EventRewriter::RewriteLocatedEvent(ui::LocatedEvent* event) { -#if defined(OS_CHROMEOS) - if (event->flags() & ui::EF_IS_SYNTHESIZED) - return; - - XEvent* xevent = event->native_event(); - if (!xevent || xevent->type != GenericEvent) - return; - - XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); +void EventRewriter::RewriteLocatedEvent(XEvent* event) { + DCHECK_EQ(GenericEvent, event->type); + XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); if (xievent->evtype != XI_ButtonPress && xievent->evtype != XI_ButtonRelease) return; // First, remap modifier masks. - int remapped_flags = 0; unsigned int remapped_native_modifiers = 0U; - GetRemappedModifierMasks(event->flags(), xievent->mods.effective, - &remapped_flags, &remapped_native_modifiers); + GetRemappedModifierMasks(xievent->mods.effective, &remapped_native_modifiers); xievent->mods.effective = remapped_native_modifiers; // Then, remap Alt+Button1 to Button3. @@ -1019,34 +879,15 @@ void EventRewriter::RewriteLocatedEvent(ui::LocatedEvent* event) { pressed_device_ids_.insert(xievent->sourceid); } } - - const int mouse_event_flags = event->flags() & - (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK | ui::EF_IS_NON_CLIENT | - ui::EF_IS_SYNTHESIZED | ui::EF_FROM_TOUCH); - event->set_flags(mouse_event_flags | ui::EventFlagsFromNative(xevent)); -#else - // TODO(yusukes): Support Ash on other platforms if needed. -#endif } -void EventRewriter::OverwriteEvent(ui::KeyEvent* event, +void EventRewriter::OverwriteEvent(XEvent* event, unsigned int new_native_keycode, - unsigned int new_native_state, - ui::KeyboardCode new_keycode, - int new_flags) { -#if defined(OS_CHROMEOS) - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); + unsigned int new_native_state) { + DCHECK(event->type == KeyPress || event->type == KeyRelease); + XKeyEvent* xkey = &event->xkey; xkey->keycode = new_native_keycode; xkey->state = new_native_state; - event->set_key_code(new_keycode); - event->set_character(ui::GetCharacterFromKeyCode(event->key_code(), - new_flags)); - event->set_flags(new_flags); - event->NormalizeFlags(); -#else - // TODO(yusukes): Support Ash on other platforms if needed. -#endif } EventRewriter::DeviceType EventRewriter::DeviceAddedInternal( @@ -1062,3 +903,5 @@ EventRewriter::DeviceType EventRewriter::DeviceAddedInternal( device_id_to_type_[device_id] = type; return type; } + +} // namespace chromeos diff --git a/chrome/browser/ui/ash/event_rewriter.h b/chrome/browser/chromeos/event_rewriter.h index f085075..396911a 100644 --- a/chrome/browser/ui/ash/event_rewriter.h +++ b/chrome/browser/chromeos/event_rewriter.h @@ -1,49 +1,39 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. -#ifndef CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ -#define CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ +#ifndef CHROME_BROWSER_CHROMEOS_EVENT_REWRITER_H_ +#define CHROME_BROWSER_CHROMEOS_EVENT_REWRITER_H_ #include <map> #include <set> #include <string> -#include "ash/event_rewriter_delegate.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/containers/hash_tables.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_pump_observer.h" +#include "chrome/browser/chromeos/device_hierarchy_observer.h" #include "ui/aura/root_window_observer.h" #include "ui/events/keycodes/keyboard_codes.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/device_hierarchy_observer.h" -#endif - class PrefService; +typedef union _XEvent XEvent; namespace aura { class RootWindow; } -#if defined(OS_CHROMEOS) namespace chromeos { - class KeyboardDrivenEventRewriter; - namespace input_method { class XKeyboard; } -} -#endif - -class EventRewriter : public ash::EventRewriterDelegate, - public aura::RootWindowObserver -#if defined(OS_CHROMEOS) - , public chromeos::DeviceHierarchyObserver -#endif -{ + +class EventRewriter : public aura::RootWindowObserver, + public DeviceHierarchyObserver, + public base::MessagePumpObserver { public: enum DeviceType { kDeviceUnknown = 0, @@ -57,7 +47,7 @@ class EventRewriter : public ash::EventRewriterDelegate, DeviceType DeviceAddedForTesting(int device_id, const std::string& device_name); // Calls Rewrite. - void RewriteForTesting(ui::KeyEvent* event); + void RewriteForTesting(XEvent* event); const std::map<int, DeviceType>& device_id_to_type_for_testing() const { return device_id_to_type_; @@ -68,11 +58,9 @@ class EventRewriter : public ash::EventRewriterDelegate, void set_pref_service_for_testing(const PrefService* pref_service) { pref_service_for_testing_ = pref_service; } -#if defined(OS_CHROMEOS) - void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { + void set_xkeyboard_for_testing(input_method::XKeyboard* xkeyboard) { xkeyboard_for_testing_ = xkeyboard; } -#endif // Gets DeviceType from the |device_name|. static DeviceType GetDeviceType(const std::string& device_name); @@ -81,17 +69,15 @@ class EventRewriter : public ash::EventRewriterDelegate, friend class EventRewriterAshTest; friend class EventRewriterTest; - // ash::EventRewriterDelegate overrides: - virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent( - ui::KeyEvent* event) OVERRIDE; - virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent( - ui::LocatedEvent* event) OVERRIDE; - // aura::RootWindowObserver overrides: virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; -#if defined(OS_CHROMEOS) - // chromeos::DeviceHierarchyObserver overrides: + // base::MessagePumpObserver overrides: + virtual base::EventStatus WillProcessEvent( + const base::NativeEvent& event) OVERRIDE; + virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; + + // DeviceHierarchyObserver overrides: virtual void DeviceHierarchyChanged() OVERRIDE {} virtual void DeviceAdded(int device_id) OVERRIDE; virtual void DeviceRemoved(int device_id) OVERRIDE; @@ -109,11 +95,8 @@ class EventRewriter : public ash::EventRewriterDelegate, struct KeyboardRemapping { KeySym input_keysym; - unsigned int input_mods; unsigned int input_native_mods; KeySym output_keysym; - ui::KeyboardCode output_keycode; - unsigned int output_mods; unsigned int output_native_mods; }; @@ -121,7 +104,7 @@ class EventRewriter : public ash::EventRewriterDelegate, // keys instead of having them rewritten into back, forward, brightness, // volume, etc. or if the user has specified that they desire top-row keys to // be treated as function keys globally. - bool TopRowKeysAreFunctionKeys(ui::KeyEvent* event) const; + bool TopRowKeysAreFunctionKeys(XEvent* event) const; // Given a set of KeyboardRemapping structs, it finds a matching struct // if possible, and updates the remapped event values. Returns true if a @@ -131,11 +114,8 @@ class EventRewriter : public ash::EventRewriterDelegate, size_t num_remappings, KeySym keysym, unsigned int native_mods, - unsigned int mods, KeySym* remapped_native_keysym, - unsigned int* remapped_native_mods, - ui::KeyboardCode* remapped_keycode, - unsigned int* remapped_mods); + unsigned int* remapped_native_mods); // Given a set of KeyboardRemapping structs, it finds a matching struct // if possible, and updates the remapped event values. This function converts @@ -147,31 +127,27 @@ class EventRewriter : public ash::EventRewriterDelegate, size_t num_remappings, KeyCode keycode, unsigned int native_mods, - unsigned int mods, KeySym* remapped_native_keysym, - unsigned int* remapped_native_mods, - ui::KeyboardCode* remapped_keycode, - unsigned int* remapped_mods); -#endif + unsigned int* remapped_native_mods); // Returns the PrefService that should be used. const PrefService* GetPrefService() const; // Rewrites the |event| by applying all RewriteXXX functions as needed. - void Rewrite(ui::KeyEvent* event); + void Rewrite(XEvent* event); // Rewrites a modifier key press/release following the current user // preferences. - bool RewriteModifiers(ui::KeyEvent* event); + bool RewriteModifiers(XEvent* event); // Rewrites Fn key press/release to Control. In some cases, Fn key is not // intercepted by the EC, but generates a key event like "XK_F15 + Mod3Mask" // as shown in crosbug.com/p/14339. - bool RewriteFnKey(ui::KeyEvent* event); + bool RewriteFnKey(XEvent* event); // Rewrites a NumPad key press/release without Num Lock to a corresponding key // press/release with the lock. Returns true when |event| is rewritten. - bool RewriteNumPadKeys(ui::KeyEvent* event); + bool RewriteNumPadKeys(XEvent* event); // Rewrites Backspace and Arrow keys following the Chrome OS keyboard spec. // * Alt+Backspace -> Delete @@ -187,22 +163,20 @@ class EventRewriter : public ash::EventRewriterDelegate, // * Search+Right -> End // * Search+. -> Insert // Returns true when the |event| is rewritten. - bool RewriteExtendedKeys(ui::KeyEvent* event); + bool RewriteExtendedKeys(XEvent* event); // When the Search key acts as a function key, it remaps Search+1 // through Search+= to F1 through F12. Returns true when the |event| is // rewritten. - bool RewriteFunctionKeys(ui::KeyEvent* event); + bool RewriteFunctionKeys(XEvent* event); // Rewrites the located |event|. - void RewriteLocatedEvent(ui::LocatedEvent* event); + void RewriteLocatedEvent(XEvent* event); // Overwrites |event| with the keycodes and flags. - void OverwriteEvent(ui::KeyEvent* event, + void OverwriteEvent(XEvent* event, unsigned int new_native_keycode, - unsigned int new_native_state, - ui::KeyboardCode new_keycode, - int new_flags); + unsigned int new_native_state); // Checks the type of the |device_name|, and inserts a new entry to // |device_id_to_type_|. @@ -211,32 +185,30 @@ class EventRewriter : public ash::EventRewriterDelegate, // Returns true if |last_device_id_| is Apple's. bool IsAppleKeyboard() const; - // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers| - // to |remapped_native_modifiers| following the current user prefs. - void GetRemappedModifierMasks(int original_flags, - unsigned int original_native_modifiers, - int* remapped_flags, + // Remaps |original_native_modifiers| to |remapped_native_modifiers| following + // the current user prefs. + void GetRemappedModifierMasks(unsigned int original_native_modifiers, unsigned int* remapped_native_modifiers) const; std::map<int, DeviceType> device_id_to_type_; int last_device_id_; -#if defined(OS_CHROMEOS) // A mapping from X11 KeySym keys to KeyCode values. base::hash_map<unsigned long, unsigned long> keysym_to_keycode_map_; // A set of device IDs whose press event has been rewritten. std::set<int> pressed_device_ids_; - chromeos::input_method::XKeyboard* xkeyboard_for_testing_; + input_method::XKeyboard* xkeyboard_for_testing_; - scoped_ptr<chromeos::KeyboardDrivenEventRewriter> + scoped_ptr<KeyboardDrivenEventRewriter> keyboard_driven_event_rewriter_; -#endif const PrefService* pref_service_for_testing_; DISALLOW_COPY_AND_ASSIGN(EventRewriter); }; -#endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_EVENT_REWRITER_H_ diff --git a/chrome/browser/ui/ash/event_rewriter_unittest.cc b/chrome/browser/chromeos/event_rewriter_unittest.cc index c22d9ce..54d3eb6 100644 --- a/chrome/browser/ui/ash/event_rewriter_unittest.cc +++ b/chrome/browser/chromeos/event_rewriter_unittest.cc @@ -1,40 +1,41 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. -#include "chrome/browser/ui/ash/event_rewriter.h" +#include "chrome/browser/chromeos/event_rewriter.h" -#include "base/basictypes.h" -#include "base/command_line.h" -#include "base/prefs/pref_member.h" -#include "base/strings/stringprintf.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/testing_pref_service_syncable.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/events/event.h" - -#if defined(OS_CHROMEOS) #include <X11/keysym.h> #include <X11/XF86keysym.h> #include <X11/Xlib.h> +#undef Bool +#undef None +#undef RootWindow #include "ash/test/ash_test_base.h" #include "ash/wm/window_state.h" +#include "base/basictypes.h" +#include "base/command_line.h" +#include "base/prefs/pref_member.h" +#include "base/strings/stringprintf.h" #include "chrome/browser/chromeos/input_method/input_method_configuration.h" #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" #include "chrome/browser/chromeos/login/mock_user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/preferences.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/testing_pref_service_syncable.h" #include "chromeos/chromeos_switches.h" #include "chromeos/ime/fake_xkeyboard.h" +#include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/window.h" +#include "ui/events/event.h" #include "ui/events/test/events_test_utils_x11.h" #include "ui/events/x/touch_factory_x11.h" #include "ui/gfx/x/x11_types.h" namespace { -std::string GetRewrittenEventAsString(EventRewriter* rewriter, +std::string GetRewrittenEventAsString(chromeos::EventRewriter* rewriter, ui::KeyboardCode ui_keycode, int ui_flags, ui::EventType ui_type, @@ -45,8 +46,8 @@ std::string GetRewrittenEventAsString(EventRewriter* rewriter, XEvent* xevent = xev; xevent->xkey.keycode = x_keycode; xevent->xkey.state = x_state; - ui::KeyEvent keyevent(xev, false /* is_char */); - rewriter->RewriteForTesting(&keyevent); + rewriter->RewriteForTesting(xevent); + ui::KeyEvent keyevent(xevent, false /* is_char */); return base::StringPrintf( "ui_keycode=%d ui_flags=%d ui_type=%d x_keycode=%u x_state=%u x_type=%d", keyevent.key_code(), keyevent.flags(), keyevent.type(), @@ -66,7 +67,9 @@ std::string GetExpectedResultAsString(ui::KeyboardCode ui_keycode, } // namespace -class EventRewriterTest : public testing::Test { +namespace chromeos { + +class EventRewriterTest : public ash::test::AshTestBase { public: EventRewriterTest() : display_(gfx::GetXDisplay()), @@ -172,9 +175,12 @@ class EventRewriterTest : public testing::Test { new chromeos::input_method::MockInputMethodManager; chromeos::input_method::InitializeForTesting( input_method_manager_mock_); // pass ownership + + AshTestBase::SetUp(); } virtual void TearDown() { + AshTestBase::TearDown(); // Shutdown() deletes the IME mock object. chromeos::input_method::Shutdown(); } @@ -183,9 +189,11 @@ class EventRewriterTest : public testing::Test { void TestRewriteNumPadKeys(); void TestRewriteNumPadKeysOnAppleKeyboard(); - void RewriteLocatedEvent(EventRewriter* rewriter, - ui::LocatedEvent* event) { - rewriter->RewriteLocatedEvent(event); + void RewriteMouseEvent(EventRewriter* rewriter, + ui::MouseEvent* event) { + XEvent* xevent = event->native_event(); + rewriter->RewriteLocatedEvent(xevent); + *event = ui::MouseEvent(xevent); } Display* display_; @@ -278,14 +286,6 @@ class EventRewriterTest : public testing::Test { chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; }; -#else -class EventRewriterTest : public testing::Test { - public: - EventRewriterTest() {} - virtual ~EventRewriterTest() {} -}; -#endif - TEST_F(EventRewriterTest, TestGetDeviceType) { // This is the typical string which an Apple keyboard sends. EXPECT_EQ(EventRewriter::kDeviceAppleKeyboard, @@ -339,7 +339,6 @@ TEST_F(EventRewriterTest, TestDeviceAddedOrRemoved) { EXPECT_EQ(2U, rewriter.device_id_to_type_for_testing().size()); } -#if defined(OS_CHROMEOS) TEST_F(EventRewriterTest, TestRewriteCommandToControl) { // First, test with a PC keyboard. TestingPrefServiceSyncable prefs; @@ -2225,6 +2224,9 @@ TEST_F(EventRewriterTest, TestRewriteFunctionKeys) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { + // XKeysymToKeycode returns zero for unknown keys. So ignore those. + if (tests[i].output_native == 0) + continue; EXPECT_EQ(GetExpectedResultAsString(tests[i].output, tests[i].output_mods, ui::ET_KEY_PRESSED, @@ -2306,8 +2308,8 @@ TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { XEvent* xevent = xev; xevent->xkey.keycode = keycode_control_l_; xevent->xkey.send_event = True; // XSendEvent() always does this. + rewriter.RewriteForTesting(xevent); ui::KeyEvent keyevent(xev, false /* is_char */); - rewriter.RewriteForTesting(&keyevent); rewritten_event = base::StringPrintf( "ui_keycode=%d ui_flags=%d ui_type=%d " "x_keycode=%u x_state=%u x_type=%d", @@ -2335,7 +2337,7 @@ class EventRewriterAshTest : public ash::test::AshTestBase { } virtual ~EventRewriterAshTest() {} - bool RewriteFunctionKeys(ui::KeyEvent* event) { + bool RewriteFunctionKeys(XEvent* event) { return rewriter_.RewriteFunctionKeys(event); } @@ -2359,14 +2361,12 @@ TEST_F(EventRewriterAshTest, TopRowKeysAreFunctionKeys) { xev_f1.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_F1, 0); XEvent* xevent = xev_f1; xevent->xkey.keycode = keycode_f1; - ui::KeyEvent press_f1(xev_f1, false); - ui::Event::DispatcherApi dispatch_helper(&press_f1); - dispatch_helper.set_target(window.get()); // Simulate an apps v2 window that has requested top row keys as function // keys. The event should not be rewritten. window_state->set_top_row_keys_are_function_keys(true); - ASSERT_FALSE(RewriteFunctionKeys(&press_f1)); + ASSERT_FALSE(RewriteFunctionKeys(xevent)); + ui::KeyEvent press_f1(xev_f1, false); ASSERT_EQ(ui::VKEY_F1, press_f1.key_code()); // The event should also not be rewritten if the send-function-keys pref is @@ -2374,16 +2374,19 @@ TEST_F(EventRewriterAshTest, TopRowKeysAreFunctionKeys) { BooleanPrefMember send_function_keys_pref; send_function_keys_pref.Init(prefs::kLanguageSendFunctionKeys, &prefs_); send_function_keys_pref.SetValue(true); - ASSERT_FALSE(RewriteFunctionKeys(&press_f1)); + ASSERT_FALSE(RewriteFunctionKeys(xevent)); + press_f1 = ui::KeyEvent(xev_f1, false); ASSERT_EQ(ui::VKEY_F1, press_f1.key_code()); window_state->set_top_row_keys_are_function_keys(false); - ASSERT_FALSE(RewriteFunctionKeys(&press_f1)); + ASSERT_FALSE(RewriteFunctionKeys(xevent)); + press_f1 = ui::KeyEvent(xev_f1, false); ASSERT_EQ(ui::VKEY_F1, press_f1.key_code()); // If the pref isn't set when an event is sent to a regular window, F1 is // rewritten to the back key. send_function_keys_pref.SetValue(false); - ASSERT_TRUE(RewriteFunctionKeys(&press_f1)); + ASSERT_TRUE(RewriteFunctionKeys(xevent)); + press_f1 = ui::KeyEvent(xev_f1, false); ASSERT_EQ(ui::VKEY_BROWSER_BACK, press_f1.key_code()); } @@ -2404,7 +2407,7 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { EXPECT_EQ(ui::ET_MOUSE_PRESSED, press.type()); EXPECT_EQ(kLeftAndAltFlag, press.flags()); - RewriteLocatedEvent(&rewriter, &press); + RewriteMouseEvent(&rewriter, &press); EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & press.flags()); } @@ -2412,7 +2415,7 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { ui::ScopedXI2Event xev; xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); ui::MouseEvent release(xev); - RewriteLocatedEvent(&rewriter, &release); + RewriteMouseEvent(&rewriter, &release); EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & release.flags()); } @@ -2422,14 +2425,14 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { xev.InitGenericButtonEvent( 10, ui::ET_MOUSE_PRESSED, ui::EF_LEFT_MOUSE_BUTTON); ui::MouseEvent press(xev); - RewriteLocatedEvent(&rewriter, &press); + RewriteMouseEvent(&rewriter, &press); EXPECT_TRUE(ui::EF_LEFT_MOUSE_BUTTON & press.flags()); } { ui::ScopedXI2Event xev; xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); ui::MouseEvent release(xev); - RewriteLocatedEvent(&rewriter, &release); + RewriteMouseEvent(&rewriter, &release); EXPECT_TRUE((ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN) & release.flags()); } @@ -2439,14 +2442,14 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { ui::ScopedXI2Event xev; xev.InitGenericButtonEvent(11, ui::ET_MOUSE_PRESSED, kLeftAndAltFlag); ui::MouseEvent press(xev); - RewriteLocatedEvent(&rewriter, &press); + RewriteMouseEvent(&rewriter, &press); EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & press.flags()); } { ui::ScopedXI2Event xev; xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); ui::MouseEvent release(xev); - RewriteLocatedEvent(&rewriter, &release); + RewriteMouseEvent(&rewriter, &release); EXPECT_TRUE((ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN) & release.flags()); } @@ -2454,9 +2457,9 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { ui::ScopedXI2Event xev; xev.InitGenericButtonEvent(11, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); ui::MouseEvent release(xev); - RewriteLocatedEvent(&rewriter, &release); + RewriteMouseEvent(&rewriter, &release); EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & release.flags()); } } -#endif // OS_CHROMEOS +} // namespace chromeos diff --git a/chrome/browser/chromeos/keyboard_driven_event_rewriter.cc b/chrome/browser/chromeos/keyboard_driven_event_rewriter.cc index 389757f..9f9ef78 100644 --- a/chrome/browser/chromeos/keyboard_driven_event_rewriter.cc +++ b/chrome/browser/chromeos/keyboard_driven_event_rewriter.cc @@ -8,7 +8,7 @@ #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/system/input_device_settings.h" -#include "ui/events/event.h" +#include "ui/events/event_utils.h" namespace chromeos { @@ -35,35 +35,34 @@ KeyboardDrivenEventRewriter::KeyboardDrivenEventRewriter() {} KeyboardDrivenEventRewriter::~KeyboardDrivenEventRewriter() {} bool KeyboardDrivenEventRewriter::RewriteIfKeyboardDrivenOnLoginScreen( - ui::KeyEvent* event) { + XEvent* event) { if (!ShouldStripModifiersForArrowKeysAndEnter()) return false; return RewriteEvent(event); } -bool KeyboardDrivenEventRewriter::RewriteForTesting(ui::KeyEvent* event) { +bool KeyboardDrivenEventRewriter::RewriteForTesting(XEvent* event) { return RewriteEvent(event); } -bool KeyboardDrivenEventRewriter::RewriteEvent(ui::KeyEvent* event) { - if ((event->flags() & kModifierMask) != kModifierMask) +bool KeyboardDrivenEventRewriter::RewriteEvent(XEvent* event) { + int flags = ui::EventFlagsFromNative(event); + if ((flags & kModifierMask) != kModifierMask) return false; - - if (event->key_code() != ui::VKEY_LEFT && - event->key_code() != ui::VKEY_RIGHT && - event->key_code() != ui::VKEY_UP && - event->key_code() != ui::VKEY_DOWN && - event->key_code() != ui::VKEY_RETURN && - event->key_code() != ui::VKEY_F6) { + ui::KeyboardCode key_code = ui::KeyboardCodeFromNative(event); + + if (key_code != ui::VKEY_LEFT && + key_code != ui::VKEY_RIGHT && + key_code != ui::VKEY_UP && + key_code != ui::VKEY_DOWN && + key_code != ui::VKEY_RETURN && + key_code != ui::VKEY_F6) { return false; } - XEvent* xev = event->native_event(); - XKeyEvent* xkey = &(xev->xkey); + XKeyEvent* xkey = &(event->xkey); xkey->state &= ~(ControlMask | Mod1Mask | ShiftMask); - event->set_flags(event->flags() & ~kModifierMask); - event->NormalizeFlags(); return true; } diff --git a/chrome/browser/chromeos/keyboard_driven_event_rewriter.h b/chrome/browser/chromeos/keyboard_driven_event_rewriter.h index d55aeab..96e053d 100644 --- a/chrome/browser/chromeos/keyboard_driven_event_rewriter.h +++ b/chrome/browser/chromeos/keyboard_driven_event_rewriter.h @@ -7,9 +7,7 @@ #include "base/basictypes.h" -namespace ui { -class KeyEvent; -} +typedef union _XEvent XEvent; namespace chromeos { @@ -24,13 +22,13 @@ class KeyboardDrivenEventRewriter { // Calls RewriteEvent to modify |event| if it is on login screen and the // keyboard driven flag is enabled. Returns true if the event is changed // and no further changes should happen. - bool RewriteIfKeyboardDrivenOnLoginScreen(ui::KeyEvent* event); + bool RewriteIfKeyboardDrivenOnLoginScreen(XEvent* event); // Calls RewriteEvent for testing. - bool RewriteForTesting(ui::KeyEvent* event); + bool RewriteForTesting(XEvent* event); private: - bool RewriteEvent(ui::KeyEvent* event); + bool RewriteEvent(XEvent* event); DISALLOW_COPY_AND_ASSIGN(KeyboardDrivenEventRewriter); }; diff --git a/chrome/browser/chromeos/keyboard_driven_event_rewriter_unittest.cc b/chrome/browser/chromeos/keyboard_driven_event_rewriter_unittest.cc index 151bbab..dc807ef 100644 --- a/chrome/browser/chromeos/keyboard_driven_event_rewriter_unittest.cc +++ b/chrome/browser/chromeos/keyboard_driven_event_rewriter_unittest.cc @@ -42,8 +42,8 @@ class KeyboardDrivenEventRewriterTest : public testing::Test { XEvent* xevent = xev; xevent->xkey.keycode = x_keycode; xevent->xkey.state = x_state; + bool changed = rewriter_.RewriteForTesting(xevent); ui::KeyEvent keyevent(xev, false /* is_char */); - bool changed = rewriter_.RewriteForTesting(&keyevent); return base::StringPrintf("ui_flags=%d x_state=%u changed=%d", keyevent.flags(), xevent->xkey.state, diff --git a/chrome/browser/ui/ash/ash_init.cc b/chrome/browser/ui/ash/ash_init.cc index 8551ef4..4ba1425 100644 --- a/chrome/browser/ui/ash/ash_init.cc +++ b/chrome/browser/ui/ash/ash_init.cc @@ -10,14 +10,12 @@ #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" #include "ash/shell.h" -#include "ash/wm/event_rewriter_event_filter.h" #include "base/command_line.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/ui/ash/chrome_shell_delegate.h" -#include "chrome/browser/ui/ash/event_rewriter.h" #include "chrome/browser/ui/ash/screenshot_taker.h" #include "chrome/common/chrome_switches.h" #include "ui/aura/env.h" @@ -58,8 +56,6 @@ void OpenAsh() { // Shell takes ownership of ChromeShellDelegate. ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate); - shell->event_rewriter_filter()->SetEventRewriterDelegate( - scoped_ptr<ash::EventRewriterDelegate>(new EventRewriter).Pass()); shell->accelerator_controller()->SetScreenshotDelegate( scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass()); #if defined(OS_CHROMEOS) diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index ad90a0e..95a2851 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -309,6 +309,8 @@ 'browser/chromeos/drive/write_on_cache_file.h', 'browser/chromeos/enrollment_dialog_view.cc', 'browser/chromeos/enrollment_dialog_view.h', + 'browser/chromeos/event_rewriter.cc', + 'browser/chromeos/event_rewriter.h', 'browser/chromeos/extensions/default_app_order.cc', 'browser/chromeos/extensions/default_app_order.h', 'browser/chromeos/extensions/device_local_account_external_policy_loader.cc', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index f4478b9..95c5682 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -287,8 +287,6 @@ 'browser/ui/ash/chrome_shell_delegate.h', 'browser/ui/ash/chrome_shell_delegate_chromeos.cc', 'browser/ui/ash/chrome_shell_delegate_views.cc', - 'browser/ui/ash/event_rewriter.cc', - 'browser/ui/ash/event_rewriter.h', 'browser/ui/ash/ime_controller_chromeos.cc', 'browser/ui/ash/ime_controller_chromeos.h', 'browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 256af0d..c30fcfc 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -694,6 +694,7 @@ 'browser/chromeos/drive/test_util.cc', 'browser/chromeos/drive/test_util.h', 'browser/chromeos/drive/write_on_cache_file_unittest.cc', + 'browser/chromeos/event_rewriter_unittest.cc', 'browser/chromeos/extensions/default_app_order_unittest.cc', 'browser/chromeos/extensions/device_local_account_external_policy_loader_unittest.cc', 'browser/chromeos/extensions/external_cache_unittest.cc', @@ -1425,7 +1426,6 @@ 'browser/thumbnails/thumbnail_service_unittest.cc', 'browser/translate/translate_manager_unittest.cc', 'browser/ui/android/tab_model/tab_model_unittest.cc', - 'browser/ui/ash/event_rewriter_unittest.cc', 'browser/ui/ash/ime_controller_chromeos_unittest.cc', 'browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc', 'browser/ui/ash/launcher/launcher_context_menu_unittest.cc', |