mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +01:00
Made SetWindowSize synchronous.
This commit is contained in:
parent
5acf0f9a05
commit
e2203f81d3
6 changed files with 34 additions and 45 deletions
|
@ -292,13 +292,15 @@ impl<'a> Iterator for FrameTreeIterator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WebDriverData {
|
struct WebDriverData {
|
||||||
load_channel: Option<(PipelineId, IpcSender<webdriver_msg::LoadStatus>)>
|
load_channel: Option<(PipelineId, IpcSender<webdriver_msg::LoadStatus>)>,
|
||||||
|
resize_channel: Option<IpcSender<WindowSizeData>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebDriverData {
|
impl WebDriverData {
|
||||||
pub fn new() -> WebDriverData {
|
pub fn new() -> WebDriverData {
|
||||||
WebDriverData {
|
WebDriverData {
|
||||||
load_channel: None
|
load_channel: None,
|
||||||
|
resize_channel: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1484,6 +1486,13 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
|
||||||
// Find the script channel for the given parent pipeline,
|
// Find the script channel for the given parent pipeline,
|
||||||
// and pass the event to that script thread.
|
// and pass the event to that script thread.
|
||||||
match msg {
|
match msg {
|
||||||
|
WebDriverCommandMsg::GetWindowSize(_, reply) => {
|
||||||
|
let _ = reply.send(self.window_size);
|
||||||
|
},
|
||||||
|
WebDriverCommandMsg::SetWindowSize(_, size, reply) => {
|
||||||
|
self.webdriver.resize_channel = Some(reply);
|
||||||
|
self.compositor_proxy.send(ToCompositorMsg::ResizeTo(size));
|
||||||
|
},
|
||||||
WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, reply) => {
|
WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, reply) => {
|
||||||
self.load_url_for_webdriver(pipeline_id, load_data, reply);
|
self.load_url_for_webdriver(pipeline_id, load_data, reply);
|
||||||
},
|
},
|
||||||
|
@ -1703,6 +1712,10 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(resize_channel) = self.webdriver.resize_channel.take() {
|
||||||
|
let _ = resize_channel.send(new_size);
|
||||||
|
}
|
||||||
|
|
||||||
self.window_size = new_size;
|
self.window_size = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
//! reduce coupling between these two components.
|
//! reduce coupling between these two components.
|
||||||
|
|
||||||
use euclid::scale_factor::ScaleFactor;
|
use euclid::scale_factor::ScaleFactor;
|
||||||
use euclid::size::TypedSize2D;
|
use euclid::size::{Size2D, TypedSize2D};
|
||||||
use hyper::header::Headers;
|
use hyper::header::Headers;
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
||||||
|
@ -188,10 +188,12 @@ bitflags! {
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum WebDriverCommandMsg {
|
pub enum WebDriverCommandMsg {
|
||||||
|
GetWindowSize(PipelineId, IpcSender<WindowSizeData>),
|
||||||
LoadUrl(PipelineId, LoadData, IpcSender<LoadStatus>),
|
LoadUrl(PipelineId, LoadData, IpcSender<LoadStatus>),
|
||||||
Refresh(PipelineId, IpcSender<LoadStatus>),
|
Refresh(PipelineId, IpcSender<LoadStatus>),
|
||||||
ScriptCommand(PipelineId, WebDriverScriptCommand),
|
ScriptCommand(PipelineId, WebDriverScriptCommand),
|
||||||
SendKeys(PipelineId, Vec<(Key, KeyModifiers, KeyState)>),
|
SendKeys(PipelineId, Vec<(Key, KeyModifiers, KeyState)>),
|
||||||
|
SetWindowSize(PipelineId, Size2D<u32>, IpcSender<WindowSizeData>),
|
||||||
TakeScreenshot(PipelineId, IpcSender<Option<Image>>),
|
TakeScreenshot(PipelineId, IpcSender<Option<Image>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use constellation_msg::{PipelineId, WindowSizeData};
|
use constellation_msg::PipelineId;
|
||||||
use euclid::rect::Rect;
|
use euclid::rect::Rect;
|
||||||
use euclid::size::TypedSize2D;
|
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use rustc_serialize::json::{Json, ToJson};
|
use rustc_serialize::json::{Json, ToJson};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::geometry::ViewportPx;
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum WebDriverScriptCommand {
|
pub enum WebDriverScriptCommand {
|
||||||
|
@ -25,8 +23,6 @@ pub enum WebDriverScriptCommand {
|
||||||
GetElementText(String, IpcSender<Result<String, ()>>),
|
GetElementText(String, IpcSender<Result<String, ()>>),
|
||||||
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>),
|
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>),
|
||||||
GetUrl(IpcSender<Url>),
|
GetUrl(IpcSender<Url>),
|
||||||
GetWindowSize(IpcSender<Option<WindowSizeData>>),
|
|
||||||
SetWindowSize(TypedSize2D<ViewportPx, f32>, IpcSender<()>),
|
|
||||||
IsEnabled(String, IpcSender<Result<bool, ()>>),
|
IsEnabled(String, IpcSender<Result<bool, ()>>),
|
||||||
IsSelected(String, IpcSender<Result<bool, ()>>),
|
IsSelected(String, IpcSender<Result<bool, ()>>),
|
||||||
GetTitle(IpcSender<String>)
|
GetTitle(IpcSender<String>)
|
||||||
|
|
|
@ -1016,10 +1016,6 @@ impl ScriptThread {
|
||||||
webdriver_handlers::handle_get_frame_id(&context, pipeline_id, frame_id, reply),
|
webdriver_handlers::handle_get_frame_id(&context, pipeline_id, frame_id, reply),
|
||||||
WebDriverScriptCommand::GetUrl(reply) =>
|
WebDriverScriptCommand::GetUrl(reply) =>
|
||||||
webdriver_handlers::handle_get_url(&context, pipeline_id, reply),
|
webdriver_handlers::handle_get_url(&context, pipeline_id, reply),
|
||||||
WebDriverScriptCommand::GetWindowSize(reply) =>
|
|
||||||
webdriver_handlers::handle_get_window_size(&context, pipeline_id, reply),
|
|
||||||
WebDriverScriptCommand::SetWindowSize(size, reply) =>
|
|
||||||
webdriver_handlers::handle_set_window_size(&context, pipeline_id, size, reply),
|
|
||||||
WebDriverScriptCommand::IsEnabled(element_id, reply) =>
|
WebDriverScriptCommand::IsEnabled(element_id, reply) =>
|
||||||
webdriver_handlers::handle_is_enabled(&context, pipeline_id, element_id, reply),
|
webdriver_handlers::handle_is_enabled(&context, pipeline_id, element_id, reply),
|
||||||
WebDriverScriptCommand::IsSelected(element_id, reply) =>
|
WebDriverScriptCommand::IsSelected(element_id, reply) =>
|
||||||
|
|
|
@ -283,26 +283,6 @@ pub fn handle_get_url(context: &BrowsingContext,
|
||||||
reply.send((*url).clone()).unwrap();
|
reply.send((*url).clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_window_size(context: &BrowsingContext,
|
|
||||||
_pipeline: PipelineId,
|
|
||||||
reply: IpcSender<Option<WindowSizeData>>) {
|
|
||||||
let window = context.active_window();
|
|
||||||
let size = window.window_size();
|
|
||||||
reply.send(size).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_set_window_size(context: &BrowsingContext,
|
|
||||||
_pipeline: PipelineId,
|
|
||||||
size: TypedSize2D<ViewportPx, f32>,
|
|
||||||
reply: IpcSender<()>) {
|
|
||||||
let window = context.active_window();
|
|
||||||
// TODO: converting to a dimensionless size is error-prone
|
|
||||||
let untyped = size.to_untyped();
|
|
||||||
// TODO: when window puts in security checks for resize, we will need to rewrite this
|
|
||||||
window.ResizeTo(untyped.width as i32, untyped.height as i32);
|
|
||||||
reply.send(()).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_is_enabled(context: &BrowsingContext,
|
pub fn handle_is_enabled(context: &BrowsingContext,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
|
|
|
@ -357,27 +357,29 @@ impl Handler {
|
||||||
|
|
||||||
fn handle_window_size(&self) -> WebDriverResult<WebDriverResponse> {
|
fn handle_window_size(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
let pipeline_id = try!(self.root_pipeline());
|
||||||
|
let cmd_msg = WebDriverCommandMsg::GetWindowSize(pipeline_id, sender);
|
||||||
|
|
||||||
try!(self.root_script_command(WebDriverScriptCommand::GetWindowSize(sender)));
|
self.constellation_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
|
||||||
|
|
||||||
match receiver.recv().unwrap() {
|
let window_size = receiver.recv().unwrap();
|
||||||
Some(window_size) => {
|
let vp = window_size.visible_viewport;
|
||||||
let vp = window_size.visible_viewport;
|
let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64);
|
||||||
let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64);
|
Ok(WebDriverResponse::WindowSize(window_size_response))
|
||||||
Ok(WebDriverResponse::WindowSize(window_size_response))
|
|
||||||
},
|
|
||||||
None => Err(WebDriverError::new(ErrorStatus::NoSuchWindow, "Unable to determine window size"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_set_window_size(&self, params: &WindowSizeParameters) -> WebDriverResult<WebDriverResponse> {
|
fn handle_set_window_size(&self, params: &WindowSizeParameters) -> WebDriverResult<WebDriverResponse> {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let size = Size2D::from_untyped(&Size2D::new(params.width as f32, params.height as f32));
|
let size = Size2D::new(params.width as u32, params.height as u32);
|
||||||
|
let pipeline_id = try!(self.root_pipeline());
|
||||||
|
let cmd_msg = WebDriverCommandMsg::SetWindowSize(pipeline_id, size, sender);
|
||||||
|
|
||||||
try!(self.root_script_command(WebDriverScriptCommand::SetWindowSize(size, sender)));
|
self.constellation_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
|
||||||
receiver.recv().unwrap();
|
|
||||||
|
|
||||||
Ok(WebDriverResponse::Void)
|
let window_size = receiver.recv().unwrap();
|
||||||
|
let vp = window_size.visible_viewport;
|
||||||
|
let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64);
|
||||||
|
Ok(WebDriverResponse::WindowSize(window_size_response))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_is_enabled(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
|
fn handle_is_enabled(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue