| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This class describe a keyboard accelerator (or keyboard shortcut). | 5 // This class describe a keyboard accelerator (or keyboard shortcut). |
| 6 // Keyboard accelerators are registered with the FocusManager. | 6 // Keyboard accelerators are registered with the FocusManager. |
| 7 // It has a copy constructor and assignment operator so that it can be copied. | 7 // It has a copy constructor and assignment operator so that it can be copied. |
| 8 // It also defines the < operator so that it can be used as a key in a std::map. | 8 // It also defines the < operator so that it can be used as a key in a std::map. |
| 9 // | 9 // |
| 10 | 10 |
| 11 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_H_ | 11 #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_H_ |
| 12 #define UI_BASE_ACCELERATORS_ACCELERATOR_H_ | 12 #define UI_BASE_ACCELERATORS_ACCELERATOR_H_ |
| 13 #pragma once | 13 #pragma once |
| 14 | 14 |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
| 17 #include "ui/base/events.h" | 17 #include "ui/base/events.h" |
| 18 #include "ui/base/ui_export.h" | 18 #include "ui/base/ui_export.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 21 | 21 |
| 22 // This is a cross-platform base class for accelerator keys used in menus. It is | 22 // This is a cross-platform base class for accelerator keys used in menus. It is |
| 23 // meant to be subclassed for concrete toolkit implementations. | 23 // meant to be subclassed for concrete toolkit implementations. |
| 24 class UI_EXPORT Accelerator { | 24 class UI_EXPORT Accelerator { |
| 25 public: | 25 public: |
| 26 Accelerator(); | 26 Accelerator(); |
| 27 Accelerator(ui::KeyboardCode keycode, int modifiers); | 27 Accelerator(ui::KeyboardCode keycode, int modifiers, ui::EventType type); |
| 28 Accelerator(const Accelerator& accelerator); | 28 Accelerator(const Accelerator& accelerator); |
| 29 ~Accelerator(); | 29 ~Accelerator(); |
| 30 | 30 |
| 31 Accelerator& operator=(const Accelerator& accelerator); | 31 Accelerator& operator=(const Accelerator& accelerator); |
| 32 | 32 |
| 33 // We define the < operator so that the KeyboardShortcut can be used as a key | 33 // We define the < operator so that the KeyboardShortcut can be used as a key |
| 34 // in a std::map. | 34 // in a std::map. |
| 35 bool operator <(const Accelerator& rhs) const; | 35 bool operator <(const Accelerator& rhs) const; |
| 36 | 36 |
| 37 bool operator ==(const Accelerator& rhs) const; | 37 bool operator ==(const Accelerator& rhs) const; |
| 38 | 38 |
| 39 bool operator !=(const Accelerator& rhs) const; | 39 bool operator !=(const Accelerator& rhs) const; |
| 40 | 40 |
| 41 ui::KeyboardCode key_code() const { return key_code_; } | 41 ui::KeyboardCode key_code() const { return key_code_; } |
| 42 | |
| 43 // Sets the event type if the accelerator should be processed on an event | |
| 44 // other than ui::ET_KEY_PRESSED. | |
| 45 void set_type(ui::EventType type) { type_ = type; } | |
| 46 ui::EventType type() const { return type_; } | 42 ui::EventType type() const { return type_; } |
| 47 | 43 |
| 48 int modifiers() const { return modifiers_; } | 44 int modifiers() const { return modifiers_; } |
| 49 | 45 |
| 50 bool IsShiftDown() const; | 46 bool IsShiftDown() const; |
| 51 bool IsCtrlDown() const; | 47 bool IsCtrlDown() const; |
| 52 bool IsAltDown() const; | 48 bool IsAltDown() const; |
| 53 | 49 |
| 54 // Returns a string with the localized shortcut if any. | 50 // Returns a string with the localized shortcut if any. |
| 55 string16 GetShortcutText() const; | 51 string16 GetShortcutText() const; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 virtual bool GetAcceleratorForCommandId(int command_id, | 87 virtual bool GetAcceleratorForCommandId(int command_id, |
| 92 ui::Accelerator* accelerator) = 0; | 88 ui::Accelerator* accelerator) = 0; |
| 93 | 89 |
| 94 protected: | 90 protected: |
| 95 virtual ~AcceleratorProvider() {} | 91 virtual ~AcceleratorProvider() {} |
| 96 }; | 92 }; |
| 97 | 93 |
| 98 } // namespace ui | 94 } // namespace ui |
| 99 | 95 |
| 100 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_H_ | 96 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_H_ |
| OLD | NEW |