mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Implement TakeElementScreenshot WebDriver command
This commit is contained in:
parent
a084997afe
commit
d3696baf27
12 changed files with 134 additions and 28 deletions
|
@ -2198,6 +2198,14 @@ impl ScriptThread {
|
|||
WebDriverScriptCommand::GetElementRect(node_id, reply) => {
|
||||
webdriver_handlers::handle_get_rect(&*documents, pipeline_id, node_id, reply)
|
||||
},
|
||||
WebDriverScriptCommand::GetBoundingClientRect(node_id, reply) => {
|
||||
webdriver_handlers::handle_get_bounding_client_rect(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
node_id,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::GetElementText(node_id, reply) => {
|
||||
webdriver_handlers::handle_get_text(&*documents, pipeline_id, node_id, reply)
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
|
||||
|
@ -776,6 +777,30 @@ pub fn handle_get_rect(
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_bounding_client_rect(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
element_id: String,
|
||||
reply: IpcSender<Result<Rect<f32>, ErrorStatus>>,
|
||||
) {
|
||||
reply
|
||||
.send(
|
||||
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| match node
|
||||
.downcast::<Element>(
|
||||
) {
|
||||
Some(element) => {
|
||||
let rect = element.GetBoundingClientRect();
|
||||
Ok(Rect::new(
|
||||
Point2D::new(rect.X() as f32, rect.Y() as f32),
|
||||
Size2D::new(rect.Width() as f32, rect.Height() as f32),
|
||||
))
|
||||
},
|
||||
None => Err(ErrorStatus::UnknownError),
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_text(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue