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

Side by Side Diff: chrome/browser/automation/ui_controls_win.cc

Issue 3337006: Revert 58388 - Revert 58215 - Revert 58186 - Move the keyboard files from bas... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 3 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 | « chrome/browser/automation/ui_controls_mac.mm ('k') | chrome/browser/browser_focus_uitest.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser/automation/ui_controls.h" 5 #include "chrome/browser/automation/ui_controls.h"
6 6
7 #include "app/keyboard_code_conversion_win.h" 7 #include "base/keyboard_codes.h"
8 #include "app/keyboard_codes.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "base/message_loop.h" 9 #include "base/message_loop.h"
11 #include "base/win_util.h" 10 #include "base/win_util.h"
12 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
13 #include "base/task.h" 12 #include "base/task.h"
14 #include "views/view.h" 13 #include "views/view.h"
15 14
16 namespace ui_controls { 15 namespace ui_controls {
17 16
18 namespace { 17 namespace {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 130
132 void InputDispatcher::NotifyTask() { 131 void InputDispatcher::NotifyTask() {
133 task_->Run(); 132 task_->Run();
134 Release(); 133 Release();
135 } 134 }
136 135
137 // Private functions ---------------------------------------------------------- 136 // Private functions ----------------------------------------------------------
138 137
139 // Populate the INPUT structure with the appropriate keyboard event 138 // Populate the INPUT structure with the appropriate keyboard event
140 // parameters required by SendInput 139 // parameters required by SendInput
141 bool FillKeyboardInput(app::KeyboardCode key, INPUT* input, bool key_up) { 140 bool FillKeyboardInput(base::KeyboardCode key, INPUT* input, bool key_up) {
142 memset(input, 0, sizeof(INPUT)); 141 memset(input, 0, sizeof(INPUT));
143 input->type = INPUT_KEYBOARD; 142 input->type = INPUT_KEYBOARD;
144 input->ki.wVk = app::WindowsKeyCodeForKeyboardCode(key); 143 input->ki.wVk = win_util::KeyboardCodeToWin(key);
145 input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP : 144 input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP :
146 KEYEVENTF_EXTENDEDKEY; 145 KEYEVENTF_EXTENDEDKEY;
147 146
148 return true; 147 return true;
149 } 148 }
150 149
151 // Send a key event (up/down) 150 // Send a key event (up/down)
152 bool SendKeyEvent(app::KeyboardCode key, bool up) { 151 bool SendKeyEvent(base::KeyboardCode key, bool up) {
153 INPUT input = { 0 }; 152 INPUT input = { 0 };
154 153
155 if (!FillKeyboardInput(key, &input, up)) 154 if (!FillKeyboardInput(key, &input, up))
156 return false; 155 return false;
157 156
158 if (!::SendInput(1, &input, sizeof(INPUT))) 157 if (!::SendInput(1, &input, sizeof(INPUT)))
159 return false; 158 return false;
160 159
161 return true; 160 return true;
162 } 161 }
163 162
164 bool SendKeyPressImpl(app::KeyboardCode key, 163 bool SendKeyPressImpl(base::KeyboardCode key,
165 bool control, bool shift, bool alt, 164 bool control, bool shift, bool alt,
166 Task* task) { 165 Task* task) {
167 scoped_refptr<InputDispatcher> dispatcher( 166 scoped_refptr<InputDispatcher> dispatcher(
168 task ? new InputDispatcher(task, WM_KEYUP) : NULL); 167 task ? new InputDispatcher(task, WM_KEYUP) : NULL);
169 168
170 // If a pop-up menu is open, it won't receive events sent using SendInput. 169 // If a pop-up menu is open, it won't receive events sent using SendInput.
171 // Check for a pop-up menu using its window class (#32768) and if one 170 // Check for a pop-up menu using its window class (#32768) and if one
172 // exists, send the key event directly there. 171 // exists, send the key event directly there.
173 HWND popup_menu = ::FindWindow(L"#32768", 0); 172 HWND popup_menu = ::FindWindow(L"#32768", 0);
174 if (popup_menu != NULL && popup_menu == ::GetTopWindow(NULL)) { 173 if (popup_menu != NULL && popup_menu == ::GetTopWindow(NULL)) {
175 WPARAM w_param = app::WindowsKeyCodeForKeyboardCode(key); 174 WPARAM w_param = win_util::KeyboardCodeToWin(key);
176 LPARAM l_param = 0; 175 LPARAM l_param = 0;
177 ::SendMessage(popup_menu, WM_KEYDOWN, w_param, l_param); 176 ::SendMessage(popup_menu, WM_KEYDOWN, w_param, l_param);
178 ::SendMessage(popup_menu, WM_KEYUP, w_param, l_param); 177 ::SendMessage(popup_menu, WM_KEYUP, w_param, l_param);
179 178
180 if (dispatcher.get()) 179 if (dispatcher.get())
181 dispatcher->AddRef(); 180 dispatcher->AddRef();
182 return true; 181 return true;
183 } 182 }
184 183
185 INPUT input[8] = { 0 }; // 8, assuming all the modifiers are activated 184 INPUT input[8] = { 0 }; // 8, assuming all the modifiers are activated
186 185
187 UINT i = 0; 186 UINT i = 0;
188 if (control) { 187 if (control) {
189 if (!FillKeyboardInput(app::VKEY_CONTROL, &input[i], false)) 188 if (!FillKeyboardInput(base::VKEY_CONTROL, &input[i], false))
190 return false; 189 return false;
191 i++; 190 i++;
192 } 191 }
193 192
194 if (shift) { 193 if (shift) {
195 if (!FillKeyboardInput(app::VKEY_SHIFT, &input[i], false)) 194 if (!FillKeyboardInput(base::VKEY_SHIFT, &input[i], false))
196 return false; 195 return false;
197 i++; 196 i++;
198 } 197 }
199 198
200 if (alt) { 199 if (alt) {
201 if (!FillKeyboardInput(app::VKEY_MENU, &input[i], false)) 200 if (!FillKeyboardInput(base::VKEY_MENU, &input[i], false))
202 return false; 201 return false;
203 i++; 202 i++;
204 } 203 }
205 204
206 if (!FillKeyboardInput(key, &input[i], false)) 205 if (!FillKeyboardInput(key, &input[i], false))
207 return false; 206 return false;
208 i++; 207 i++;
209 208
210 if (!FillKeyboardInput(key, &input[i], true)) 209 if (!FillKeyboardInput(key, &input[i], true))
211 return false; 210 return false;
212 i++; 211 i++;
213 212
214 if (alt) { 213 if (alt) {
215 if (!FillKeyboardInput(app::VKEY_MENU, &input[i], true)) 214 if (!FillKeyboardInput(base::VKEY_MENU, &input[i], true))
216 return false; 215 return false;
217 i++; 216 i++;
218 } 217 }
219 218
220 if (shift) { 219 if (shift) {
221 if (!FillKeyboardInput(app::VKEY_SHIFT, &input[i], true)) 220 if (!FillKeyboardInput(base::VKEY_SHIFT, &input[i], true))
222 return false; 221 return false;
223 i++; 222 i++;
224 } 223 }
225 224
226 if (control) { 225 if (control) {
227 if (!FillKeyboardInput(app::VKEY_CONTROL, &input[i], true)) 226 if (!FillKeyboardInput(base::VKEY_CONTROL, &input[i], true))
228 return false; 227 return false;
229 i++; 228 i++;
230 } 229 }
231 230
232 if (::SendInput(i, input, sizeof(INPUT)) != i) 231 if (::SendInput(i, input, sizeof(INPUT)) != i)
233 return false; 232 return false;
234 233
235 if (dispatcher.get()) 234 if (dispatcher.get())
236 dispatcher->AddRef(); 235 dispatcher->AddRef();
237 return true; 236 return true;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (dispatcher.get()) 315 if (dispatcher.get())
317 dispatcher->AddRef(); 316 dispatcher->AddRef();
318 317
319 return true; 318 return true;
320 } 319 }
321 320
322 } // namespace 321 } // namespace
323 322
324 // public functions ----------------------------------------------------------- 323 // public functions -----------------------------------------------------------
325 324
326 bool SendKeyPress(gfx::NativeWindow window, app::KeyboardCode key, 325 bool SendKeyPress(gfx::NativeWindow window, base::KeyboardCode key,
327 bool control, bool shift, bool alt, bool command) { 326 bool control, bool shift, bool alt, bool command) {
328 DCHECK(command == false); // No command key on Windows 327 DCHECK(command == false); // No command key on Windows
329 return SendKeyPressImpl(key, control, shift, alt, NULL); 328 return SendKeyPressImpl(key, control, shift, alt, NULL);
330 } 329 }
331 330
332 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, 331 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
333 app::KeyboardCode key, 332 base::KeyboardCode key,
334 bool control, bool shift, bool alt, 333 bool control, bool shift, bool alt,
335 bool command, 334 bool command,
336 Task* task) { 335 Task* task) {
337 DCHECK(command == false); // No command key on Windows 336 DCHECK(command == false); // No command key on Windows
338 return SendKeyPressImpl(key, control, shift, alt, task); 337 return SendKeyPressImpl(key, control, shift, alt, task);
339 } 338 }
340 339
341 bool SendMouseMove(long x, long y) { 340 bool SendMouseMove(long x, long y) {
342 return SendMouseMoveImpl(x, y, NULL); 341 return SendMouseMoveImpl(x, y, NULL);
343 } 342 }
(...skipping 18 matching lines...) Expand all
362 int state, Task* task) { 361 int state, Task* task) {
363 DCHECK(view); 362 DCHECK(view);
364 DCHECK(view->GetWidget()); 363 DCHECK(view->GetWidget());
365 gfx::Point view_center(view->width() / 2, view->height() / 2); 364 gfx::Point view_center(view->width() / 2, view->height() / 2);
366 views::View::ConvertPointToScreen(view, &view_center); 365 views::View::ConvertPointToScreen(view, &view_center);
367 SendMouseMove(view_center.x(), view_center.y()); 366 SendMouseMove(view_center.x(), view_center.y());
368 SendMouseEventsNotifyWhenDone(button, state, task); 367 SendMouseEventsNotifyWhenDone(button, state, task);
369 } 368 }
370 369
371 } // ui_controls 370 } // ui_controls
OLDNEW
« no previous file with comments | « chrome/browser/automation/ui_controls_mac.mm ('k') | chrome/browser/browser_focus_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698