Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_ACCELERATOR_H_ | 11 #ifndef VIEWS_ACCELERATOR_H_ |
| 12 #define VIEWS_ACCELERATOR_H_ | 12 #define VIEWS_ACCELERATOR_H_ |
| 13 #pragma once | 13 #pragma once |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "ui/base/models/accelerator.h" | 18 #include "ui/base/models/accelerator.h" |
| 19 #include "views/events/event.h" | 19 #include "views/events/event.h" |
| 20 #include "views/views_export.h" | 20 #include "views/views_export.h" |
| 21 | 21 |
| 22 namespace views { | 22 namespace views { |
| 23 | 23 |
| 24 class VIEWS_EXPORT Accelerator : public ui::Accelerator { | 24 class VIEWS_EXPORT Accelerator : public ui::Accelerator { |
|
Ben Goodger (Google)
2011/11/10 22:02:26
can you just delete this file now?
just add GetSh
mazda
2011/11/11 13:09:06
Done.
| |
| 25 public: | 25 public: |
| 26 Accelerator() : ui::Accelerator() {} | 26 Accelerator() : ui::Accelerator() {} |
| 27 | 27 |
| 28 Accelerator(ui::KeyboardCode keycode, int modifiers) | 28 Accelerator(ui::KeyboardCode keycode, int modifiers) |
| 29 : ui::Accelerator(keycode, modifiers) {} | 29 : ui::Accelerator(keycode, modifiers) {} |
| 30 | 30 |
| 31 Accelerator(ui::KeyboardCode keycode, | 31 Accelerator(ui::KeyboardCode keycode, |
| 32 bool shift_pressed, bool ctrl_pressed, bool alt_pressed) { | 32 bool shift_pressed, bool ctrl_pressed, bool alt_pressed) |
| 33 key_code_ = keycode; | 33 : ui::Accelerator(keycode, shift_pressed, ctrl_pressed, alt_pressed) {} |
| 34 modifiers_ = 0; | |
| 35 if (shift_pressed) | |
| 36 modifiers_ |= ui::EF_SHIFT_DOWN; | |
| 37 if (ctrl_pressed) | |
| 38 modifiers_ |= ui::EF_CONTROL_DOWN; | |
| 39 if (alt_pressed) | |
| 40 modifiers_ |= ui::EF_ALT_DOWN; | |
| 41 } | |
| 42 | 34 |
| 43 virtual ~Accelerator() {} | 35 virtual ~Accelerator() {} |
| 44 | 36 |
| 45 bool IsShiftDown() const { | |
| 46 return (modifiers_ & ui::EF_SHIFT_DOWN) == ui::EF_SHIFT_DOWN; | |
| 47 } | |
| 48 | |
| 49 bool IsCtrlDown() const { | |
| 50 return (modifiers_ & ui::EF_CONTROL_DOWN) == ui::EF_CONTROL_DOWN; | |
| 51 } | |
| 52 | |
| 53 bool IsAltDown() const { | |
| 54 return (modifiers_ & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN; | |
| 55 } | |
| 56 | |
| 57 // Returns a string with the localized shortcut if any. | 37 // Returns a string with the localized shortcut if any. |
| 58 string16 GetShortcutText() const; | 38 string16 GetShortcutText() const; |
| 59 }; | 39 }; |
| 60 | 40 |
| 61 // An interface that classes that want to register for keyboard accelerators | |
| 62 // should implement. | |
| 63 class VIEWS_EXPORT AcceleratorTarget { | |
| 64 public: | |
| 65 // This method should return true if the accelerator was processed. | |
| 66 virtual bool AcceleratorPressed(const Accelerator& accelerator) = 0; | |
| 67 | |
| 68 protected: | |
| 69 virtual ~AcceleratorTarget() {} | |
| 70 }; | |
| 71 } | 41 } |
| 72 | 42 |
| 73 #endif // VIEWS_ACCELERATOR_H_ | 43 #endif // VIEWS_ACCELERATOR_H_ |
| OLD | NEW |