Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/devtools/protocol/input_handler.h" | 5 #include "content/browser/devtools/protocol/input_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "cc/output/compositor_frame_metadata.h" | 9 #include "cc/output/compositor_frame_metadata.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (!host_) | 207 if (!host_) |
| 208 return Response::ServerError("Could not connect to view"); | 208 return Response::ServerError("Could not connect to view"); |
| 209 | 209 |
| 210 host_->Focus(); | 210 host_->Focus(); |
| 211 host_->ForwardKeyboardEvent(event); | 211 host_->ForwardKeyboardEvent(event); |
| 212 return Response::OK(); | 212 return Response::OK(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 Response InputHandler::DispatchKeyEvent( | |
|
dgozman
2015/06/02 13:22:01
Please implement one of the methods using another
Habib Virji
2015/06/02 14:15:19
Done.
| |
| 216 const std::string& type, | |
| 217 const int* modifiers, | |
| 218 const double* timestamp, | |
| 219 const std::string* text, | |
| 220 const std::string* unmodified_text, | |
| 221 const std::string* key_identifier, | |
| 222 const std::string* code, | |
| 223 const std::string* key, | |
| 224 const int* windows_virtual_key_code, | |
| 225 const int* native_virtual_key_code, | |
| 226 const bool* auto_repeat, | |
| 227 const bool* is_keypad, | |
| 228 const bool* is_system_key) { | |
| 229 NativeWebKeyboardEvent event; | |
| 230 | |
| 231 if (type == dispatch_key_event::kTypeKeyDown) { | |
| 232 event.type = blink::WebInputEvent::KeyDown; | |
| 233 } else if (type == dispatch_key_event::kTypeKeyUp) { | |
| 234 event.type = blink::WebInputEvent::KeyUp; | |
| 235 } else if (type == dispatch_key_event::kTypeChar) { | |
| 236 event.type = blink::WebInputEvent::Char; | |
| 237 } else if (type == dispatch_key_event::kTypeRawKeyDown) { | |
| 238 event.type = blink::WebInputEvent::RawKeyDown; | |
| 239 } else { | |
| 240 return Response::InvalidParams( | |
| 241 base::StringPrintf("Unexpected event type '%s'", type.c_str())); | |
| 242 } | |
| 243 | |
| 244 SetEventModifiers(&event, modifiers); | |
| 245 SetEventTimestamp(&event, timestamp); | |
| 246 if (!SetKeyboardEventText(event.text, text)) | |
| 247 return Response::InvalidParams("Invalid 'text' parameter"); | |
| 248 if (!SetKeyboardEventText(event.unmodifiedText, unmodified_text)) | |
| 249 return Response::InvalidParams("Invalid 'unmodifiedText' parameter"); | |
| 250 | |
| 251 if (windows_virtual_key_code) | |
| 252 event.windowsKeyCode = *windows_virtual_key_code; | |
| 253 if (native_virtual_key_code) | |
| 254 event.nativeKeyCode = *native_virtual_key_code; | |
| 255 if (auto_repeat && *auto_repeat) | |
| 256 event.modifiers |= blink::WebInputEvent::IsAutoRepeat; | |
| 257 if (is_keypad && *is_keypad) | |
| 258 event.modifiers |= blink::WebInputEvent::IsKeyPad; | |
| 259 if (is_system_key) | |
| 260 event.isSystemKey = *is_system_key; | |
| 261 | |
| 262 if (key_identifier) { | |
| 263 if (key_identifier->size() > | |
| 264 blink::WebKeyboardEvent::keyIdentifierLengthCap) { | |
| 265 return Response::InvalidParams("Invalid 'keyIdentifier' parameter"); | |
| 266 } | |
| 267 for (size_t i = 0; i < key_identifier->size(); ++i) | |
| 268 event.keyIdentifier[i] = (*key_identifier)[i]; | |
| 269 } else if (event.type != blink::WebInputEvent::Char) { | |
| 270 event.setKeyIdentifierFromWindowsKeyCode(); | |
| 271 } | |
| 272 | |
| 273 if (code) { | |
| 274 event.domCode = static_cast<int>( | |
| 275 ui::KeycodeConverter::CodeStringToDomCode(code->c_str())); | |
| 276 } | |
| 277 | |
| 278 if (key) { | |
| 279 event.domKey = static_cast<int>( | |
| 280 ui::KeycodeConverter::KeyStringToDomKey(key->c_str())); | |
| 281 } | |
| 282 | |
| 283 if (!host_) | |
| 284 return Response::ServerError("Could not connect to view"); | |
| 285 | |
| 286 host_->Focus(); | |
| 287 host_->ForwardKeyboardEvent(event); | |
| 288 return Response::OK(); | |
| 289 } | |
| 290 | |
| 215 Response InputHandler::DispatchMouseEvent( | 291 Response InputHandler::DispatchMouseEvent( |
| 216 const std::string& type, | 292 const std::string& type, |
| 217 int x, | 293 int x, |
| 218 int y, | 294 int y, |
| 219 const int* modifiers, | 295 const int* modifiers, |
| 220 const double* timestamp, | 296 const double* timestamp, |
| 221 const std::string* button, | 297 const std::string* button, |
| 222 const int* click_count) { | 298 const int* click_count) { |
| 223 blink::WebMouseEvent event; | 299 blink::WebMouseEvent event; |
| 224 | 300 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 } else { | 533 } else { |
| 458 client_->SendError(command_id, | 534 client_->SendError(command_id, |
| 459 Response::InternalError(base::StringPrintf( | 535 Response::InternalError(base::StringPrintf( |
| 460 "Synthetic tap failed, result was %d", result))); | 536 "Synthetic tap failed, result was %d", result))); |
| 461 } | 537 } |
| 462 } | 538 } |
| 463 | 539 |
| 464 } // namespace input | 540 } // namespace input |
| 465 } // namespace devtools | 541 } // namespace devtools |
| 466 } // namespace content | 542 } // namespace content |
| OLD | NEW |