From 89327aa5bee97100b858cd33024418bd1d149940 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 6 Jun 2014 12:45:14 -0700 Subject: Outside of compositor, store window size in CSS px This fixes an issue where the CSS viewport was too large on high-DPI displays because it was set to the window size in device pixels, instead of px. This patch ensures that the window size is converted from device pixels to px before being passed to script/layout code. The Window trait now exposes the window size in both device pixels and density-independent screen coordinates, with clearer method names. --- src/components/script/script_task.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/components/script/script_task.rs') diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 1929449f9a7..e90e263fbd5 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -34,7 +34,7 @@ use layout_interface::UntrustedNodeAddress; use layout_interface; use geom::point::Point2D; -use geom::size::Size2D; +use geom::size::TypedSize2D; use js::jsapi::JS_CallFunctionValue; use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ, JS_GC}; use js::jsapi::{JSContext, JSRuntime}; @@ -49,7 +49,7 @@ use servo_msg::constellation_msg::{PipelineId, SubpageId, Failure, FailureMsg}; use servo_msg::constellation_msg; use servo_net::image_cache_task::ImageCacheTask; use servo_net::resource_task::ResourceTask; -use servo_util::geometry::to_frac_px; +use servo_util::geometry::{PagePx, to_frac_px}; use servo_util::task::send_on_failure; use servo_util::namespace::Null; use servo_util::str::DOMString; @@ -80,13 +80,13 @@ pub enum ScriptMsg { /// Sends a DOM event. SendEventMsg(PipelineId, Event_), /// Window resized. Sends a DOM event eventually, but first we combine events. - ResizeMsg(PipelineId, Size2D), + ResizeMsg(PipelineId, TypedSize2D), /// Fires a JavaScript timeout. FireTimerMsg(PipelineId, TimerId), /// Notifies script that reflow is finished. ReflowCompleteMsg(PipelineId, uint), /// Notifies script that window has been resized but to not take immediate action. - ResizeInactiveMsg(PipelineId, Size2D), + ResizeInactiveMsg(PipelineId, TypedSize2D), /// Notifies the script that a pipeline should be closed. ExitPipelineMsg(PipelineId), /// Notifies the script that a window associated with a particular pipeline should be closed. @@ -145,7 +145,7 @@ pub struct Page { damage: Traceable>>, /// The current size of the window, in pixels. - window_size: Untraceable>>, + window_size: Untraceable>>, js_info: Traceable>>, @@ -158,7 +158,7 @@ pub struct Page { next_subpage_id: Untraceable>, /// Pending resize event, if any. - resize_event: Untraceable>>>, + resize_event: Untraceable>>>, /// Pending scroll to fragment event, if any fragment_node: Cell>>, @@ -201,7 +201,7 @@ impl IterablePage for Rc { impl Page { fn new(id: PipelineId, subpage_id: Option, layout_chan: LayoutChan, - window_size: Size2D, resource_task: ResourceTask, + window_size: TypedSize2D, resource_task: ResourceTask, constellation_chan: ConstellationChan, js_context: Rc) -> Page { let js_info = JSPageInfo { @@ -609,7 +609,7 @@ impl ScriptTask { constellation_chan: ConstellationChan, resource_task: ResourceTask, img_cache_task: ImageCacheTask, - window_size: Size2D) + window_size: TypedSize2D) -> Rc { let (js_runtime, js_context) = ScriptTask::new_rt_and_cx(); let page = Page::new(id, None, layout_chan, window_size, @@ -690,7 +690,7 @@ impl ScriptTask { failure_msg: Failure, resource_task: ResourceTask, image_cache_task: ImageCacheTask, - window_size: Size2D) { + window_size: TypedSize2D) { let mut builder = TaskBuilder::new().named("ScriptTask"); let ConstellationChan(const_chan) = constellation_chan.clone(); send_on_failure(&mut builder, FailureMsg(failure_msg), const_chan); @@ -737,8 +737,8 @@ impl ScriptTask { } } - for (id, Size2D { width, height }) in resizes.move_iter() { - self.handle_event(id, ResizeEvent(width, height)); + for (id, size) in resizes.move_iter() { + self.handle_event(id, ResizeEvent(size)); } // Store new resizes, and gather all other events. @@ -868,7 +868,7 @@ impl ScriptTask { } /// Window was resized, but this script was not active, so don't reflow yet - fn handle_resize_inactive_msg(&self, id: PipelineId, new_size: Size2D) { + fn handle_resize_inactive_msg(&self, id: PipelineId, new_size: TypedSize2D) { let mut page = self.page.borrow_mut(); let page = page.find(id).expect("Received resize message for PipelineId not associated with a page in the page tree. This is a bug."); @@ -1063,12 +1063,12 @@ impl ScriptTask { /// TODO: Actually perform DOM event dispatch. fn handle_event(&self, pipeline_id: PipelineId, event: Event_) { match event { - ResizeEvent(new_width, new_height) => { - debug!("script got resize event: {:u}, {:u}", new_width, new_height); + ResizeEvent(new_size) => { + debug!("script got resize event: {:?}", new_size); let window = { let page = get_page(&*self.page.borrow(), pipeline_id); - page.window_size.deref().set(Size2D(new_width, new_height)); + page.window_size.deref().set(new_size); let frame = page.frame(); if frame.is_some() { -- cgit v1.2.3