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

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

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