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 |
| 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/device_hierarchy_observer.h" |
| 18 #endif |
| 19 |
| 20 class KeyRewriter : public ash::KeyRewriterDelegate |
| 21 #if defined(OS_CHROMEOS) |
| 22 , public chromeos::DeviceHierarchyObserver |
| 23 #endif |
| 24 { |
| 25 public: |
| 26 enum DeviceType { |
| 27 kDevicePcKeyboard = 0, |
| 28 kDeviceAppleKeyboard, |
| 29 }; |
| 30 |
| 31 KeyRewriter(); |
| 32 virtual ~KeyRewriter(); |
| 33 |
| 34 // Calls DeviceAddedInternal. |
| 35 DeviceType DeviceAddedForTesting(int device_id, |
| 36 const std::string& device_name); |
| 37 // Calls RewriteCommandToControl. |
| 38 void RewriteCommandToControlForTesting(aura::KeyEvent* event); |
| 39 |
| 40 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { |
| 41 return device_id_to_type_; |
| 42 } |
| 43 void set_last_device_id_for_testing(int device_id) { |
| 44 last_device_id_ = device_id; |
| 45 } |
| 46 |
| 47 // Gets DeviceType from the |device_name|. |
| 48 static DeviceType GetDeviceType(const std::string& device_name); |
| 49 |
| 50 private: |
| 51 // ash::KeyRewriterDelegate overrides: |
| 52 virtual ash::KeyRewriterDelegate::Action RewriteOrFilterKeyEvent( |
| 53 aura::KeyEvent* event) OVERRIDE; |
| 54 |
| 55 #if defined(OS_CHROMEOS) |
| 56 // chromeos::DeviceHierarchyObserver overrides: |
| 57 virtual void DeviceHierarchyChanged() OVERRIDE {} |
| 58 virtual void DeviceAdded(int device_id) OVERRIDE; |
| 59 virtual void KeyPressedOrReleased(int device_id) OVERRIDE; |
| 60 #endif |
| 61 |
| 62 // Rewrites Comment-L/R key presses on an Apple keyboard to Control-L/R. Only |
| 63 // OS_CHROMEOS implementation is available at this point. |
| 64 void RewriteCommandToControl(aura::KeyEvent* event); |
| 65 |
| 66 // Checks the type of the |device_name|, and inserts a new entry to |
| 67 // |device_id_to_type_|. |
| 68 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); |
| 69 |
| 70 std::map<int, DeviceType> device_id_to_type_; |
| 71 int last_device_id_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(KeyRewriter); |
| 74 }; |
| 75 |
| 76 #endif // CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
OLD | NEW |