| 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 #include "ui/base/accelerators/accelerator.h" | 5 #include "ui/base/accelerators/accelerator.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 #include "ui/strings/grit/ui_strings.h" | 16 #include "ui/strings/grit/ui_strings.h" |
| 17 | 17 |
| 18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 19 #include <windows.h> | 19 #include <windows.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX)) | 22 #if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX)) |
| 23 #include "ui/events/keycodes/keyboard_code_conversion.h" | 23 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace ui { | 26 namespace ui { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const int kEventFlagsMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 30 const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | |
| 31 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN; | 31 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN; |
| 32 | 32 |
| 33 const int kEventFlagsWithRepeatMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 33 const int kInterestingFlagsMask = |
| 34 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | 34 kModifierMask | ui::EF_IS_SYNTHESIZED | ui::EF_IS_REPEAT; |
| 35 ui::EF_IS_REPEAT; | |
| 36 | 35 |
| 37 } // namespace | 36 } // namespace |
| 38 | 37 |
| 39 Accelerator::Accelerator() | 38 Accelerator::Accelerator() |
| 40 : key_code_(ui::VKEY_UNKNOWN), type_(ui::ET_KEY_PRESSED), modifiers_(0) {} | 39 : key_code_(ui::VKEY_UNKNOWN), type_(ui::ET_KEY_PRESSED), modifiers_(0) {} |
| 41 | 40 |
| 42 Accelerator::Accelerator(KeyboardCode keycode, int modifiers) | 41 Accelerator::Accelerator(KeyboardCode keycode, int modifiers) |
| 43 : key_code_(keycode), | 42 : key_code_(keycode), |
| 44 type_(ui::ET_KEY_PRESSED), | 43 type_(ui::ET_KEY_PRESSED), |
| 45 modifiers_(modifiers & kEventFlagsWithRepeatMask) {} | 44 modifiers_(modifiers & kInterestingFlagsMask) {} |
| 46 | 45 |
| 47 Accelerator::Accelerator(const KeyEvent& key_event) | 46 Accelerator::Accelerator(const KeyEvent& key_event) |
| 48 : key_code_(key_event.key_code()), | 47 : key_code_(key_event.key_code()), |
| 49 type_(key_event.type()), | 48 type_(key_event.type()), |
| 50 // |modifiers_| may include the repeat flag. | 49 // |modifiers_| may include the repeat flag. |
| 51 modifiers_(key_event.flags() & kEventFlagsWithRepeatMask) {} | 50 modifiers_(key_event.flags() & kInterestingFlagsMask) {} |
| 52 | 51 |
| 53 Accelerator::Accelerator(const Accelerator& accelerator) { | 52 Accelerator::Accelerator(const Accelerator& accelerator) { |
| 54 key_code_ = accelerator.key_code_; | 53 key_code_ = accelerator.key_code_; |
| 55 type_ = accelerator.type_; | 54 type_ = accelerator.type_; |
| 56 modifiers_ = accelerator.modifiers_; | 55 modifiers_ = accelerator.modifiers_; |
| 57 if (accelerator.platform_accelerator_.get()) | 56 if (accelerator.platform_accelerator_.get()) |
| 58 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); | 57 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 Accelerator::~Accelerator() { | 60 Accelerator::~Accelerator() { |
| 62 } | 61 } |
| 63 | 62 |
| 64 // static | 63 // static |
| 65 int Accelerator::MaskOutKeyEventFlags(int flags) { | 64 int Accelerator::MaskOutKeyEventFlags(int flags) { |
| 66 return flags & kEventFlagsMask; | 65 return flags & kModifierMask; |
| 67 } | 66 } |
| 68 | 67 |
| 69 Accelerator& Accelerator::operator=(const Accelerator& accelerator) { | 68 Accelerator& Accelerator::operator=(const Accelerator& accelerator) { |
| 70 if (this != &accelerator) { | 69 if (this != &accelerator) { |
| 71 key_code_ = accelerator.key_code_; | 70 key_code_ = accelerator.key_code_; |
| 72 type_ = accelerator.type_; | 71 type_ = accelerator.type_; |
| 73 modifiers_ = accelerator.modifiers_; | 72 modifiers_ = accelerator.modifiers_; |
| 74 if (accelerator.platform_accelerator_.get()) | 73 if (accelerator.platform_accelerator_.get()) |
| 75 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); | 74 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); |
| 76 else | 75 else |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 286 |
| 288 // Subtracting the size of the shortcut key and 1 for the '+' sign. | 287 // Subtracting the size of the shortcut key and 1 for the '+' sign. |
| 289 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); | 288 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); |
| 290 shortcut.swap(shortcut_rtl); | 289 shortcut.swap(shortcut_rtl); |
| 291 } | 290 } |
| 292 | 291 |
| 293 return shortcut; | 292 return shortcut; |
| 294 } | 293 } |
| 295 | 294 |
| 296 } // namespace ui | 295 } // namespace ui |
| OLD | NEW |