 Chromium Code Reviews
 Chromium Code Reviews Issue 6630001:
  Allow webdriver users to choose between sending the key events when...  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/
    
  
    Issue 6630001:
  Allow webdriver users to choose between sending the key events when...  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/| Index: chrome/browser/automation/testing_automation_provider.cc | 
| =================================================================== | 
| --- chrome/browser/automation/testing_automation_provider.cc (revision 76851) | 
| +++ chrome/browser/automation/testing_automation_provider.cc (working copy) | 
| @@ -4655,9 +4655,56 @@ | 
| event.isSystemKey = is_system_key; | 
| event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 
| event.skip_in_browser = true; | 
| - new InputEventAckNotificationObserver(this, reply_message, event.type); | 
| - browser->GetSelectedTabContents()->render_view_host()-> | 
| - ForwardKeyboardEvent(event); | 
| + bool use_native_events = false; | 
| + // If useNativeEvents is true, this funciton will call | 
| 
Paweł Hajdan Jr.
2011/03/05 11:55:51
I'd strongly prefer to standardize on one way we i
 
timothe faudot
2011/03/07 02:45:26
I added some justifications in the associated bug
 | 
| + // ui_controls::endKeyPress to the native window handle of the browser, | 
| 
Jason Leyba
2011/03/04 19:25:12
ui_controls::SendKeyPress
 
timothe faudot
2011/03/07 02:45:26
Done.
 | 
| + // allowing events to be catched higher up; if false it will send an | 
| + // event directly to webkit. | 
| + if (args->GetBoolean("useNativeEvents", &use_native_events) && | 
| + use_native_events) { | 
| + // The ui_controls::SendKeyPress function will generate up and down events | 
| + // from one keycode for us so we only need to send one event to it. | 
| + // Filtering is done via the RawKeyDown type because it is the one sent by | 
| + // the current webdriver implementation of WebElement.SendKeys(...). | 
| + if (event.type == WebKit::WebInputEvent::RawKeyDown) { | 
| + BrowserWindow* browser_window = browser->window(); | 
| + if (!browser_window) { | 
| + AutomationJSONReply reply(this, reply_message); | 
| + reply.SendError("Could not get the browser window"); | 
| + return; | 
| + } | 
| + gfx::NativeWindow window = browser_window->GetNativeHandle(); | 
| + if (!window) { | 
| + AutomationJSONReply reply(this, reply_message); | 
| + reply.SendError("Could not get the browser window handle"); | 
| + return; | 
| + } | 
| + bool control = !!(event.modifiers & WebKit::WebInputEvent::ControlKey); | 
| + bool shift = !!(event.modifiers & WebKit::WebInputEvent::ShiftKey); | 
| + bool alt = !!(event.modifiers & WebKit::WebInputEvent::AltKey); | 
| + bool meta = !!(event.modifiers & WebKit::WebInputEvent::MetaKey); | 
| + if (!ui_controls::SendKeyPress( | 
| + window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), | 
| + control, shift, alt, meta)) { | 
| + AutomationJSONReply reply(this, reply_message); | 
| + reply.SendError("Could not send the native key event"); | 
| + return; | 
| + } else { | 
| + AutomationJSONReply reply(this, reply_message); | 
| + reply.SendSuccess(NULL); | 
| + } | 
| + } else { | 
| + // Skip this event by acknowledging it without doing nothing. | 
| + AutomationJSONReply reply(this, reply_message); | 
| + reply.SendSuccess(NULL); | 
| + return; | 
| + } | 
| + } else { | 
| + new InputEventAckNotificationObserver(this, reply_message, event.type); | 
| + browser->GetSelectedTabContents()->render_view_host()-> | 
| + ForwardKeyboardEvent(event); | 
| + return; | 
| + } | 
| } | 
| // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 
| @@ -4772,8 +4819,7 @@ | 
| section = MENU_THUMB; | 
| } else if (section_name.compare("recently_closed") == 0) { | 
| section = MENU_RECENT; | 
| - } | 
| - else { | 
| + } else { | 
| reply.SendError(StringPrintf("Unexpected section name: '%s'", | 
| section_name.c_str())); | 
| return; |