OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "ui/events/event_rewriter.h" |
| 13 |
| 14 class PrefService; |
| 15 |
| 16 namespace chromeos { |
| 17 namespace input_method { |
| 18 class ImeKeyboard; |
| 19 } |
| 20 } |
| 21 |
| 22 namespace chromeos { |
| 23 |
| 24 // KeyboardEventRewriter makes various changes to keyboard-related events, |
| 25 // including KeyEvents and some other events with keyboard modifier flags: |
| 26 // - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according |
| 27 // to user preferences; |
| 28 // - maps Command to Control on Apple keyboards; |
| 29 // - converts numeric pad editing keys to their numeric forms; |
| 30 // - converts top-row function keys to special keys where necessary; |
| 31 // - handles various key combinations like Search+Backspace -> Delete |
| 32 // and Search+number to Fnumber; |
| 33 // - handles key/pointer combinations like Alt+Button1 -> Button3. |
| 34 class KeyboardEventRewriter : public ui::EventRewriter { |
| 35 public: |
| 36 enum DeviceType { |
| 37 kDeviceUnknown = 0, |
| 38 kDeviceAppleKeyboard, |
| 39 }; |
| 40 |
| 41 KeyboardEventRewriter(); |
| 42 virtual ~KeyboardEventRewriter(); |
| 43 |
| 44 // Calls DeviceAddedInternal. |
| 45 DeviceType DeviceAddedForTesting(int device_id, |
| 46 const std::string& device_name); |
| 47 |
| 48 // Calls RewriteLocatedEvent(). |
| 49 bool RewriteLocatedEventForTesting(ui::Event* event); |
| 50 |
| 51 void set_last_device_id_for_testing(int device_id) { |
| 52 last_device_id_ = device_id; |
| 53 } |
| 54 void set_pref_service_for_testing(const PrefService* pref_service) { |
| 55 pref_service_for_testing_ = pref_service; |
| 56 } |
| 57 void set_ime_keyboard_for_testing( |
| 58 chromeos::input_method::ImeKeyboard* ime_keyboard) { |
| 59 ime_keyboard_for_testing_ = ime_keyboard; |
| 60 } |
| 61 |
| 62 // EventRewriter overrides: |
| 63 virtual ui::EventRewriteStatus RewriteEvent( |
| 64 ui::Event* event, |
| 65 scoped_ptr<ui::Event>* new_event) OVERRIDE; |
| 66 virtual ui::EventRewriteStatus NextDispatchEvent( |
| 67 const ui::Event& last_event, |
| 68 scoped_ptr<ui::Event>* new_event) OVERRIDE; |
| 69 |
| 70 private: |
| 71 // Returns the PrefService that should be used. |
| 72 const PrefService* GetPrefService() const; |
| 73 |
| 74 // Checks the type of the |device_name|, and inserts a new entry to |
| 75 // |device_id_to_type_|. |
| 76 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); |
| 77 |
| 78 // Returns true if |last_device_id_| is Apple's. |
| 79 bool IsAppleKeyboard(const ui::Event& event) const; |
| 80 |
| 81 // Returns true if the event comes from an Chrome keyboard with a Diamond key. |
| 82 bool HasDiamondKey(const ui::Event& event) const; |
| 83 |
| 84 // Returns true if the target for |event| would prefer to receive raw function |
| 85 // keys instead of having them rewritten into back, forward, brightness, |
| 86 // volume, etc. or if the user has specified that they desire top-row keys to |
| 87 // be treated as function keys globally. |
| 88 bool TopRowKeysAreFunctionKeys(const ui::Event& event) const; |
| 89 |
| 90 int GetRemappedModifierMasks(const PrefService& pref_service, |
| 91 const ui::Event& event, |
| 92 int original_flags) const; |
| 93 |
| 94 bool RewriteModifierKeys(ui::Event* event); |
| 95 bool RewriteNumPadKeys(ui::Event* event); |
| 96 bool RewriteExtendedKeys(ui::Event* event); |
| 97 bool RewriteFunctionKeys(ui::Event* event); |
| 98 bool RewriteLocatedEvent(ui::Event* event); |
| 99 |
| 100 // A set of device IDs whose press event has been rewritten. |
| 101 std::set<int> pressed_device_ids_; |
| 102 |
| 103 std::map<int, DeviceType> device_id_to_type_; |
| 104 int last_device_id_; |
| 105 |
| 106 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; |
| 107 const PrefService* pref_service_for_testing_; |
| 108 bool top_rows_are_function_keys_for_testing_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(KeyboardEventRewriter); |
| 111 }; |
| 112 |
| 113 } // namespace chromeos |
| 114 |
| 115 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_ |
OLD | NEW |