aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJames Graham <james@hoppipolla.co.uk>2015-06-16 17:32:42 +0100
committerJames Graham <james@hoppipolla.co.uk>2015-11-16 22:48:26 +0000
commit09b9293b092a89aaca651f3ce655e5a97878e52c (patch)
tree67cf816cd300717b8d5c8d3d364680db1ce230e9 /components/script
parentdb94fda10e3351c96a0df61099d2fdfa481cc62b (diff)
downloadservo-09b9293b092a89aaca651f3ce655e5a97878e52c.tar.gz
servo-09b9293b092a89aaca651f3ce655e5a97878e52c.zip
Implement support for WebDriver send keys command.
Supports sending keys to an element. The specification here is still rather unfinished so the error handling and so on in this code will need iteration as it becomes clearer what the expected behaviour is.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/script_task.rs2
-rw-r--r--components/script/webdriver_handlers.rs21
2 files changed, 23 insertions, 0 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index c3ddfdad6b3..d2fc0a93917 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -1086,6 +1086,8 @@ impl ScriptTask {
webdriver_handlers::handle_find_element_css(&page, pipeline_id, selector, reply),
WebDriverScriptCommand::FindElementsCSS(selector, reply) =>
webdriver_handlers::handle_find_elements_css(&page, pipeline_id, selector, reply),
+ WebDriverScriptCommand::FocusElement(element_id, reply) =>
+ webdriver_handlers::handle_focus_element(&page, pipeline_id, element_id, reply),
WebDriverScriptCommand::GetActiveElement(reply) =>
webdriver_handlers::handle_get_active_element(&page, pipeline_id, reply),
WebDriverScriptCommand::GetElementTagName(node_id, reply) =>
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index 8a2385ae0f4..cd49c8126f7 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -4,6 +4,7 @@
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
+use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
@@ -11,6 +12,7 @@ use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::element::Element;
+use dom::htmlelement::HTMLElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::node::Node;
use dom::window::ScriptHelpers;
@@ -147,6 +149,25 @@ pub fn handle_find_elements_css(page: &Rc<Page>,
}).unwrap();
}
+pub fn handle_focus_element(page: &Rc<Page>,
+ pipeline: PipelineId,
+ element_id: String,
+ reply: IpcSender<Result<(), ()>>) {
+ reply.send(match find_node_by_unique_id(page, pipeline, element_id) {
+ Some(ref node) => {
+ match node.downcast::<HTMLElement>() {
+ Some(ref elem) => {
+ // Need a way to find if this actually succeeded
+ elem.Focus();
+ Ok(())
+ }
+ None => Err(())
+ }
+ },
+ None => Err(())
+ }).unwrap();
+}
+
pub fn handle_get_active_element(page: &Rc<Page>,
_pipeline: PipelineId,
reply: IpcSender<Option<String>>) {