Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ui/base/accelerators/accelerator.cc

Issue 308023002: Add EF_IS_REPEAT flag to KeyEvent to handle repeated accelerators correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use ui::EF_IS_REPEAT in test instead Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/accelerators/accelerator.h ('k') | ui/events/event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "grit/ui_strings.h" 15 #include "grit/ui_strings.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 #if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX)) 18 #if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX))
19 #include "ui/events/keycodes/keyboard_code_conversion.h" 19 #include "ui/events/keycodes/keyboard_code_conversion.h"
20 #endif 20 #endif
21 21
22 namespace ui { 22 namespace ui {
23 23
24 Accelerator::Accelerator() 24 Accelerator::Accelerator()
25 : key_code_(ui::VKEY_UNKNOWN), 25 : key_code_(ui::VKEY_UNKNOWN),
26 type_(ui::ET_KEY_PRESSED), 26 type_(ui::ET_KEY_PRESSED),
27 modifiers_(0) { 27 modifiers_(0),
28 is_repeat_(false) {
28 } 29 }
29 30
30 Accelerator::Accelerator(KeyboardCode keycode, int modifiers) 31 Accelerator::Accelerator(KeyboardCode keycode, int modifiers)
31 : key_code_(keycode), 32 : key_code_(keycode),
32 type_(ui::ET_KEY_PRESSED), 33 type_(ui::ET_KEY_PRESSED),
33 modifiers_(modifiers) { 34 modifiers_(modifiers),
35 is_repeat_(false) {
34 } 36 }
35 37
36 Accelerator::Accelerator(const Accelerator& accelerator) { 38 Accelerator::Accelerator(const Accelerator& accelerator) {
37 key_code_ = accelerator.key_code_; 39 key_code_ = accelerator.key_code_;
38 type_ = accelerator.type_; 40 type_ = accelerator.type_;
39 modifiers_ = accelerator.modifiers_; 41 modifiers_ = accelerator.modifiers_;
42 is_repeat_ = accelerator.is_repeat_;
40 if (accelerator.platform_accelerator_.get()) 43 if (accelerator.platform_accelerator_.get())
41 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); 44 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy();
42 } 45 }
43 46
44 Accelerator::~Accelerator() { 47 Accelerator::~Accelerator() {
45 } 48 }
46 49
47 Accelerator& Accelerator::operator=(const Accelerator& accelerator) { 50 Accelerator& Accelerator::operator=(const Accelerator& accelerator) {
48 if (this != &accelerator) { 51 if (this != &accelerator) {
49 key_code_ = accelerator.key_code_; 52 key_code_ = accelerator.key_code_;
50 type_ = accelerator.type_; 53 type_ = accelerator.type_;
51 modifiers_ = accelerator.modifiers_; 54 modifiers_ = accelerator.modifiers_;
55 is_repeat_ = accelerator.is_repeat_;
52 if (accelerator.platform_accelerator_.get()) 56 if (accelerator.platform_accelerator_.get())
53 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy(); 57 platform_accelerator_ = accelerator.platform_accelerator_->CreateCopy();
54 else 58 else
55 platform_accelerator_.reset(); 59 platform_accelerator_.reset();
56 } 60 }
57 return *this; 61 return *this;
58 } 62 }
59 63
60 bool Accelerator::operator <(const Accelerator& rhs) const { 64 bool Accelerator::operator <(const Accelerator& rhs) const {
61 if (key_code_ != rhs.key_code_) 65 if (key_code_ != rhs.key_code_)
(...skipping 28 matching lines...) Expand all
90 } 94 }
91 95
92 bool Accelerator::IsAltDown() const { 96 bool Accelerator::IsAltDown() const {
93 return (modifiers_ & EF_ALT_DOWN) != 0; 97 return (modifiers_ & EF_ALT_DOWN) != 0;
94 } 98 }
95 99
96 bool Accelerator::IsCmdDown() const { 100 bool Accelerator::IsCmdDown() const {
97 return (modifiers_ & EF_COMMAND_DOWN) != 0; 101 return (modifiers_ & EF_COMMAND_DOWN) != 0;
98 } 102 }
99 103
104 bool Accelerator::IsRepeat() const {
105 return is_repeat_;
106 }
107
100 base::string16 Accelerator::GetShortcutText() const { 108 base::string16 Accelerator::GetShortcutText() const {
101 int string_id = 0; 109 int string_id = 0;
102 switch (key_code_) { 110 switch (key_code_) {
103 case ui::VKEY_TAB: 111 case ui::VKEY_TAB:
104 string_id = IDS_APP_TAB_KEY; 112 string_id = IDS_APP_TAB_KEY;
105 break; 113 break;
106 case ui::VKEY_RETURN: 114 case ui::VKEY_RETURN:
107 string_id = IDS_APP_ENTER_KEY; 115 string_id = IDS_APP_ENTER_KEY;
108 break; 116 break;
109 case ui::VKEY_ESCAPE: 117 case ui::VKEY_ESCAPE:
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 256
249 // Subtracting the size of the shortcut key and 1 for the '+' sign. 257 // Subtracting the size of the shortcut key and 1 for the '+' sign.
250 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); 258 shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1);
251 shortcut.swap(shortcut_rtl); 259 shortcut.swap(shortcut_rtl);
252 } 260 }
253 261
254 return shortcut; 262 return shortcut;
255 } 263 }
256 264
257 } // namespace ui 265 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/accelerators/accelerator.h ('k') | ui/events/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698