mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
4e24c5479b
Implement the webdriver Get Element Rect command. Originally I wrote out the algorithm for [Step 7](https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position) and then I found `GetBoundingClientRect`, and i thought it was probably best to use it instead. As always, feedback is very welcomed! Source-Repo: https://github.com/servo/servo Source-Revision: e5f3c5b6d1f09f1d86e63b1d37ab3d02f19a3be3
74 lines
2.3 KiB
Rust
74 lines
2.3 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use constellation_msg::{PipelineId, WindowSizeData};
|
|
use euclid::rect::Rect;
|
|
use ipc_channel::ipc::IpcSender;
|
|
use rustc_serialize::json::{Json, ToJson};
|
|
use url::Url;
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum WebDriverScriptCommand {
|
|
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
|
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
|
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
|
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
|
FocusElement(String, IpcSender<Result<(), ()>>),
|
|
GetActiveElement(IpcSender<Option<String>>),
|
|
GetElementAttribute(String, String, IpcSender<Result<Option<String>, ()>>),
|
|
GetElementCSS(String, String, IpcSender<Result<String, ()>>),
|
|
GetElementRect(String, IpcSender<Result<Rect<f64>, ()>>),
|
|
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
|
GetElementText(String, IpcSender<Result<String, ()>>),
|
|
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>),
|
|
GetUrl(IpcSender<Url>),
|
|
GetWindowSize(IpcSender<Option<WindowSizeData>>),
|
|
IsEnabled(String, IpcSender<Result<bool, ()>>),
|
|
IsSelected(String, IpcSender<Result<bool, ()>>),
|
|
GetTitle(IpcSender<String>)
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum WebDriverJSValue {
|
|
Undefined,
|
|
Null,
|
|
Boolean(bool),
|
|
Number(f64),
|
|
String(String),
|
|
// TODO: Object and WebElement
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum WebDriverJSError {
|
|
Timeout,
|
|
UnknownType
|
|
}
|
|
|
|
pub type WebDriverJSResult = Result<WebDriverJSValue, WebDriverJSError>;
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum WebDriverFrameId {
|
|
Short(u16),
|
|
Element(String),
|
|
Parent
|
|
}
|
|
|
|
impl ToJson for WebDriverJSValue {
|
|
fn to_json(&self) -> Json {
|
|
match *self {
|
|
WebDriverJSValue::Undefined => Json::Null,
|
|
WebDriverJSValue::Null => Json::Null,
|
|
WebDriverJSValue::Boolean(ref x) => x.to_json(),
|
|
WebDriverJSValue::Number(ref x) => x.to_json(),
|
|
WebDriverJSValue::String(ref x) => x.to_json()
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum LoadStatus {
|
|
LoadComplete,
|
|
LoadTimeout
|
|
}
|