OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "ash/key_rewriter_delegate.h" |
| 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" |
| 15 #include "ui/aura/root_window_observer.h" |
| 16 |
| 17 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/device_hierarchy_observer.h" |
| 19 #endif |
| 20 |
| 21 namespace aura { |
| 22 class RootWindow; |
| 23 } |
| 24 |
| 25 class KeyRewriter : public ash::KeyRewriterDelegate, |
| 26 public aura::RootWindowObserver |
| 27 #if defined(OS_CHROMEOS) |
| 28 , public chromeos::DeviceHierarchyObserver |
| 29 #endif |
| 30 { |
| 31 public: |
| 32 enum DeviceType { |
| 33 kDeviceUnknown = 0, |
| 34 kDeviceAppleKeyboard, |
| 35 }; |
| 36 |
| 37 KeyRewriter(); |
| 38 virtual ~KeyRewriter(); |
| 39 |
| 40 // Calls DeviceAddedInternal. |
| 41 DeviceType DeviceAddedForTesting(int device_id, |
| 42 const std::string& device_name); |
| 43 // Calls RewriteCommandToControl. |
| 44 void RewriteCommandToControlForTesting(aura::KeyEvent* event); |
| 45 |
| 46 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { |
| 47 return device_id_to_type_; |
| 48 } |
| 49 void set_last_device_id_for_testing(int device_id) { |
| 50 last_device_id_ = device_id; |
| 51 } |
| 52 |
| 53 // Gets DeviceType from the |device_name|. |
| 54 static DeviceType GetDeviceType(const std::string& device_name); |
| 55 |
| 56 private: |
| 57 // ash::KeyRewriterDelegate overrides: |
| 58 virtual ash::KeyRewriterDelegate::Action RewriteOrFilterKeyEvent( |
| 59 aura::KeyEvent* event) OVERRIDE; |
| 60 |
| 61 // aura::RootWindowObserver overrides: |
| 62 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; |
| 63 |
| 64 #if defined(OS_CHROMEOS) |
| 65 // chromeos::DeviceHierarchyObserver overrides: |
| 66 virtual void DeviceHierarchyChanged() OVERRIDE {} |
| 67 virtual void DeviceAdded(int device_id) OVERRIDE; |
| 68 virtual void DeviceRemoved(int device_id) OVERRIDE; |
| 69 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; |
| 70 |
| 71 // Updates |*_keycode_| in response to a keyboard map change. |
| 72 void RefreshKeycodes(); |
| 73 #endif |
| 74 |
| 75 // Rewrites Comment-L/R key presses on an Apple keyboard to Control-L/R. Only |
| 76 // OS_CHROMEOS implementation is available at this point. |
| 77 void RewriteCommandToControl(aura::KeyEvent* event); |
| 78 |
| 79 // Checks the type of the |device_name|, and inserts a new entry to |
| 80 // |device_id_to_type_|. |
| 81 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); |
| 82 |
| 83 std::map<int, DeviceType> device_id_to_type_; |
| 84 int last_device_id_; |
| 85 |
| 86 #if defined(OS_CHROMEOS) |
| 87 // X keycodes corresponding to various keysyms. |
| 88 unsigned int control_l_xkeycode_; |
| 89 unsigned int control_r_xkeycode_; |
| 90 #endif |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(KeyRewriter); |
| 93 }; |
| 94 |
| 95 #endif // CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
OLD | NEW |