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

Side by Side Diff: chrome/test/chromedriver/key_converter.cc

Issue 113403006: Update some uses of char16 to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/key_converter.h" 5 #include "chrome/test/chromedriver/key_converter.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/test/chromedriver/chrome/status.h" 10 #include "chrome/test/chromedriver/chrome/status.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ui::VKEY_F4, 84 ui::VKEY_F4,
85 ui::VKEY_F5, 85 ui::VKEY_F5,
86 ui::VKEY_F6, 86 ui::VKEY_F6,
87 ui::VKEY_F7, 87 ui::VKEY_F7,
88 ui::VKEY_F8, 88 ui::VKEY_F8,
89 ui::VKEY_F9, 89 ui::VKEY_F9,
90 ui::VKEY_F10, 90 ui::VKEY_F10,
91 ui::VKEY_F11, 91 ui::VKEY_F11,
92 ui::VKEY_F12}; 92 ui::VKEY_F12};
93 93
94 const char16 kWebDriverNullKey = 0xE000U; 94 const base::char16 kWebDriverNullKey = 0xE000U;
95 const char16 kWebDriverShiftKey = 0xE008U; 95 const base::char16 kWebDriverShiftKey = 0xE008U;
96 const char16 kWebDriverControlKey = 0xE009U; 96 const base::char16 kWebDriverControlKey = 0xE009U;
97 const char16 kWebDriverAltKey = 0xE00AU; 97 const base::char16 kWebDriverAltKey = 0xE00AU;
98 const char16 kWebDriverCommandKey = 0xE03DU; 98 const base::char16 kWebDriverCommandKey = 0xE03DU;
99 99
100 // Returns whether the given key code has a corresponding printable char. 100 // Returns whether the given key code has a corresponding printable char.
101 // Notice: The given key code should be a special WebDriver key code. 101 // Notice: The given key code should be a special WebDriver key code.
102 bool IsSpecialKeyPrintable(ui::KeyboardCode key_code) { 102 bool IsSpecialKeyPrintable(ui::KeyboardCode key_code) {
103 return key_code == ui::VKEY_TAB || key_code == ui::VKEY_SPACE || 103 return key_code == ui::VKEY_TAB || key_code == ui::VKEY_SPACE ||
104 key_code == ui::VKEY_OEM_1 || key_code == ui::VKEY_OEM_PLUS || 104 key_code == ui::VKEY_OEM_1 || key_code == ui::VKEY_OEM_PLUS ||
105 key_code == ui::VKEY_OEM_COMMA || 105 key_code == ui::VKEY_OEM_COMMA ||
106 (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_DIVIDE); 106 (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_DIVIDE);
107 } 107 }
108 108
109 // Returns whether the given key is a WebDriver key modifier. 109 // Returns whether the given key is a WebDriver key modifier.
110 bool IsModifierKey(char16 key) { 110 bool IsModifierKey(base::char16 key) {
111 switch (key) { 111 switch (key) {
112 case kWebDriverShiftKey: 112 case kWebDriverShiftKey:
113 case kWebDriverControlKey: 113 case kWebDriverControlKey:
114 case kWebDriverAltKey: 114 case kWebDriverAltKey:
115 case kWebDriverCommandKey: 115 case kWebDriverCommandKey:
116 return true; 116 return true;
117 default: 117 default:
118 return false; 118 return false;
119 } 119 }
120 } 120 }
121 121
122 // Gets the key code associated with |key|, if it is a special WebDriver key. 122 // Gets the key code associated with |key|, if it is a special WebDriver key.
123 // Returns whether |key| is a special WebDriver key. If true, |key_code| will 123 // Returns whether |key| is a special WebDriver key. If true, |key_code| will
124 // be set. 124 // be set.
125 bool KeyCodeFromSpecialWebDriverKey(char16 key, ui::KeyboardCode* key_code) { 125 bool KeyCodeFromSpecialWebDriverKey(base::char16 key,
126 ui::KeyboardCode* key_code) {
126 int index = static_cast<int>(key) - 0xE000U; 127 int index = static_cast<int>(key) - 0xE000U;
127 bool is_special_key = index >= 0 && 128 bool is_special_key = index >= 0 &&
128 index < static_cast<int>(arraysize(kSpecialWebDriverKeys)); 129 index < static_cast<int>(arraysize(kSpecialWebDriverKeys));
129 if (is_special_key) 130 if (is_special_key)
130 *key_code = kSpecialWebDriverKeys[index]; 131 *key_code = kSpecialWebDriverKeys[index];
131 return is_special_key; 132 return is_special_key;
132 } 133 }
133 134
134 // Gets the key code associated with |key_utf16|, if it is a special shorthand 135 // Gets the key code associated with |key_utf16|, if it is a special shorthand
135 // key. Shorthand keys are common text equivalents for keys, such as the newline 136 // key. Shorthand keys are common text equivalents for keys, such as the newline
136 // character, which is shorthand for the return key. Returns whether |key| is 137 // character, which is shorthand for the return key. Returns whether |key| is
137 // a shorthand key. If true, |key_code| will be set and |client_should_skip| 138 // a shorthand key. If true, |key_code| will be set and |client_should_skip|
138 // will be set to whether the key should be skipped. 139 // will be set to whether the key should be skipped.
139 bool KeyCodeFromShorthandKey(char16 key_utf16, 140 bool KeyCodeFromShorthandKey(base::char16 key_utf16,
140 ui::KeyboardCode* key_code, 141 ui::KeyboardCode* key_code,
141 bool* client_should_skip) { 142 bool* client_should_skip) {
142 base::string16 key_str_utf16; 143 base::string16 key_str_utf16;
143 key_str_utf16.push_back(key_utf16); 144 key_str_utf16.push_back(key_utf16);
144 std::string key_str_utf8 = base::UTF16ToUTF8(key_str_utf16); 145 std::string key_str_utf8 = base::UTF16ToUTF8(key_str_utf16);
145 if (key_str_utf8.length() != 1) 146 if (key_str_utf8.length() != 1)
146 return false; 147 return false;
147 bool should_skip = false; 148 bool should_skip = false;
148 char key = key_str_utf8[0]; 149 char key = key_str_utf8[0];
149 if (key == '\n') { 150 if (key == '\n') {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 std::list<KeyEvent> key_events; 194 std::list<KeyEvent> key_events;
194 195
195 base::string16 keys = client_keys; 196 base::string16 keys = client_keys;
196 // Add an implicit NULL character to the end of the input to depress all 197 // Add an implicit NULL character to the end of the input to depress all
197 // modifiers. 198 // modifiers.
198 if (release_modifiers) 199 if (release_modifiers)
199 keys.push_back(kWebDriverNullKey); 200 keys.push_back(kWebDriverNullKey);
200 201
201 int sticky_modifiers = *modifiers; 202 int sticky_modifiers = *modifiers;
202 for (size_t i = 0; i < keys.size(); ++i) { 203 for (size_t i = 0; i < keys.size(); ++i) {
203 char16 key = keys[i]; 204 base::char16 key = keys[i];
204 205
205 if (key == kWebDriverNullKey) { 206 if (key == kWebDriverNullKey) {
206 // Release all modifier keys and clear |stick_modifiers|. 207 // Release all modifier keys and clear |stick_modifiers|.
207 if (sticky_modifiers & kShiftKeyModifierMask) 208 if (sticky_modifiers & kShiftKeyModifierMask)
208 key_events.push_back(CreateKeyUpEvent(ui::VKEY_SHIFT, 0)); 209 key_events.push_back(CreateKeyUpEvent(ui::VKEY_SHIFT, 0));
209 if (sticky_modifiers & kControlKeyModifierMask) 210 if (sticky_modifiers & kControlKeyModifierMask)
210 key_events.push_back(CreateKeyUpEvent(ui::VKEY_CONTROL, 0)); 211 key_events.push_back(CreateKeyUpEvent(ui::VKEY_CONTROL, 0));
211 if (sticky_modifiers & kAltKeyModifierMask) 212 if (sticky_modifiers & kAltKeyModifierMask)
212 key_events.push_back(CreateKeyUpEvent(ui::VKEY_MENU, 0)); 213 key_events.push_back(CreateKeyUpEvent(ui::VKEY_MENU, 0));
213 if (sticky_modifiers & kMetaKeyModifierMask) 214 if (sticky_modifiers & kMetaKeyModifierMask)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (necessary_modifiers[i]) { 332 if (necessary_modifiers[i]) {
332 key_events.push_back( 333 key_events.push_back(
333 CreateKeyUpEvent(kModifiers[i].key_code, sticky_modifiers)); 334 CreateKeyUpEvent(kModifiers[i].key_code, sticky_modifiers));
334 } 335 }
335 } 336 }
336 } 337 }
337 client_key_events->swap(key_events); 338 client_key_events->swap(key_events);
338 *modifiers = sticky_modifiers; 339 *modifiers = sticky_modifiers;
339 return Status(kOk); 340 return Status(kOk);
340 } 341 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_worditerator.cc ('k') | chrome/test/chromedriver/key_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698