diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-22 14:25:51 -0700 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-22 14:25:51 -0700 |
commit | 47a0f58f98e1a6ddcf5db24347fc6bf890d4a7d6 (patch) | |
tree | 996fe771cd42d716f721943a8aa0f51213daae9a | |
parent | 0a3a50a1293e4e8f3e04161014d03802765140c7 (diff) | |
parent | 7940b22158d892293641aa25df7720316db7e573 (diff) | |
download | servo-47a0f58f98e1a6ddcf5db24347fc6bf890d4a7d6.tar.gz servo-47a0f58f98e1a6ddcf5db24347fc6bf890d4a7d6.zip |
Auto merge of #10654 - notriddle:no_resize_on_initial_load, r=asajeffrey
compositing/script: Do not dispatch the resize event when initially l…
…oading.
No bug report corresponds to this, but I noticed it while trying to
reduce #10593
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10654)
<!-- Reviewable:end -->
-rw-r--r-- | components/compositing/compositor.rs | 18 | ||||
-rw-r--r-- | components/compositing/constellation.rs | 36 | ||||
-rw-r--r-- | components/compositing/lib.rs | 4 | ||||
-rw-r--r-- | components/msg/constellation_msg.rs | 6 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 4 | ||||
-rw-r--r-- | components/script/dom/window.rs | 11 | ||||
-rw-r--r-- | components/script/script_thread.rs | 32 | ||||
-rw-r--r-- | components/script_traits/lib.rs | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/MANIFEST.json | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html | 28 |
10 files changed, 103 insertions, 48 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 2dddffe15a9..23c7bfe2926 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -31,7 +31,7 @@ use layers::scene::Scene; use layout_traits::LayoutControlChan; use msg::constellation_msg::{ConvertPipelineIdFromWebRender, ConvertPipelineIdToWebRender, Image, PixelFormat}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData}; -use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData}; +use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData, WindowSizeType}; use pipeline::CompositionPipeline; use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest}; use profile_traits::time::{self, ProfilerCategory, profile}; @@ -461,7 +461,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { compositor.update_zoom_transform(); // Tell the constellation about the initial window size. - compositor.send_window_size(); + compositor.send_window_size(WindowSizeType::Initial); compositor } @@ -822,7 +822,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { // Initialize the new constellation channel by sending it the root window size. self.constellation_chan = new_constellation_chan; - self.send_window_size(); + self.send_window_size(WindowSizeType::Initial); self.frame_tree_id.next(); self.composite_if_necessary(CompositingReason::NewFrameTree); @@ -1062,15 +1062,15 @@ impl<Window: WindowMethods> IOCompositor<Window> { self.pending_subpages.insert(subpage_pipeline_id); } - fn send_window_size(&self) { + fn send_window_size(&self, size_type: WindowSizeType) { let dppx = self.page_zoom * self.device_pixels_per_screen_px(); let initial_viewport = self.window_size.as_f32() / dppx; let visible_viewport = initial_viewport / self.viewport_zoom; - let msg = ConstellationMsg::ResizedWindow(WindowSizeData { + let msg = ConstellationMsg::WindowSize(WindowSizeData { device_pixel_ratio: dppx, initial_viewport: initial_viewport, visible_viewport: visible_viewport, - }); + }, size_type); if let Err(e) = self.constellation_chan.send(msg) { warn!("Sending window resize to constellation failed ({}).", e); @@ -1295,7 +1295,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { self.window_size = new_size; self.scene.set_root_layer_size(new_size.as_f32()); - self.send_window_size(); + self.send_window_size(WindowSizeType::Resize); } fn on_load_url_window_event(&mut self, url_string: String) { @@ -1725,14 +1725,14 @@ impl<Window: WindowMethods> IOCompositor<Window> { fn on_zoom_reset_window_event(&mut self) { self.page_zoom = ScaleFactor::new(1.0); self.update_zoom_transform(); - self.send_window_size(); + self.send_window_size(WindowSizeType::Resize); } fn on_zoom_window_event(&mut self, magnification: f32) { self.page_zoom = ScaleFactor::new((self.page_zoom.get() * magnification) .max(MIN_ZOOM).min(MAX_ZOOM)); self.update_zoom_transform(); - self.send_window_size(); + self.send_window_size(WindowSizeType::Resize); } /// Simulate a pinch zoom diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 4a4aec9d8c7..cbe0af88823 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -33,7 +33,7 @@ use msg::constellation_msg::WebDriverCommandMsg; use msg::constellation_msg::{FrameId, PipelineId}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData}; use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, NavigationDirection}; -use msg::constellation_msg::{SubpageId, WindowSizeData}; +use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType}; use msg::constellation_msg::{self, ConstellationChan, PanicMsg}; use msg::webdriver_msg; use net_traits::image_cache_thread::ImageCacheThread; @@ -639,9 +639,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> debug!("constellation got navigation message from compositor"); self.handle_navigate_msg(pipeline_info, direction); } - Request::Compositor(FromCompositorMsg::ResizedWindow(new_size)) => { + Request::Compositor(FromCompositorMsg::WindowSize(new_size, size_type)) => { debug!("constellation got window resize message"); - self.handle_resized_window_msg(new_size); + self.handle_window_size_msg(new_size, size_type); } Request::Compositor(FromCompositorMsg::TickAnimation(pipeline_id, tick_type)) => { self.handle_tick_animation(pipeline_id, tick_type) @@ -910,7 +910,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> visible_viewport: *size, initial_viewport: *size * ScaleFactor::new(1.0), device_pixel_ratio: self.window_size.device_pixel_ratio, - }); + }, WindowSizeType::Initial); // Store the new rect inside the pipeline let result = { @@ -1581,8 +1581,8 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> } /// Called when the window is resized. - fn handle_resized_window_msg(&mut self, new_size: WindowSizeData) { - debug!("handle_resized_window_msg: {:?} {:?}", new_size.initial_viewport.to_untyped(), + fn handle_window_size_msg(&mut self, new_size: WindowSizeData, size_type: WindowSizeType) { + debug!("handle_window_size_msg: {:?} {:?}", new_size.initial_viewport.to_untyped(), new_size.visible_viewport.to_untyped()); if let Some(root_frame_id) = self.root_frame_id { @@ -1597,14 +1597,23 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> None => return warn!("Pipeline {:?} resized after closing.", pipeline_id), Some(pipeline) => pipeline, }; - let _ = pipeline.script_chan.send(ConstellationControlMsg::Resize(pipeline.id, new_size)); + let _ = pipeline.script_chan.send(ConstellationControlMsg::Resize( + pipeline.id, + new_size, + size_type + )); for pipeline_id in frame.prev.iter().chain(&frame.next) { let pipeline = match self.pipelines.get(&pipeline_id) { - None => { warn!("Inactive pipeline {:?} resized after closing.", pipeline_id); continue; }, + None => { + warn!("Inactive pipeline {:?} resized after closing.", pipeline_id); + continue; + }, Some(pipeline) => pipeline, }; - let _ = pipeline.script_chan.send(ConstellationControlMsg::ResizeInactive(pipeline.id, - new_size)); + let _ = pipeline.script_chan.send(ConstellationControlMsg::ResizeInactive( + pipeline.id, + new_size + )); } } @@ -1616,8 +1625,11 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> Some(pipeline) => pipeline, }; if pipeline.parent_info.is_none() { - let _ = pipeline.script_chan.send(ConstellationControlMsg::Resize(pipeline.id, - new_size)); + let _ = pipeline.script_chan.send(ConstellationControlMsg::Resize( + pipeline.id, + new_size, + size_type + )); } } diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index eea4854b989..eafe95a272a 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -59,7 +59,7 @@ use gfx_traits::Epoch; use ipc_channel::ipc::{IpcSender}; use msg::constellation_msg::{FrameId, Key, KeyState, KeyModifiers, LoadData}; use msg::constellation_msg::{NavigationDirection, PipelineId, SubpageId}; -use msg::constellation_msg::{WebDriverCommandMsg, WindowSizeData}; +use msg::constellation_msg::{WebDriverCommandMsg, WindowSizeData, WindowSizeType}; use std::collections::HashMap; use url::Url; @@ -103,7 +103,7 @@ pub enum CompositorMsg { KeyEvent(Key, KeyState, KeyModifiers), LoadUrl(PipelineId, LoadData), Navigate(Option<(PipelineId, SubpageId)>, NavigationDirection), - ResizedWindow(WindowSizeData), + WindowSize(WindowSizeData, WindowSizeType), /// Requests that the constellation instruct layout to begin a new tick of the animation. TickAnimation(PipelineId, AnimationTickType), /// Dispatch a webdriver command diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index cfdcdfea1ab..51270ce95c2 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -50,6 +50,12 @@ pub struct WindowSizeData { pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>, } +#[derive(Deserialize, Eq, PartialEq, Serialize, Copy, Clone, HeapSizeOf)] +pub enum WindowSizeType { + Initial, + Resize, +} + #[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)] pub enum KeyState { Pressed, diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index b7dc3e2f663..acda028a834 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -56,7 +56,7 @@ use js::rust::Runtime; use layout_interface::{LayoutChan, LayoutRPC}; use libc; use msg::constellation_msg::ConstellationChan; -use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData}; +use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData, WindowSizeType}; use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread}; use net_traits::response::HttpsState; @@ -294,7 +294,7 @@ no_jsmanaged_fields!(PropertyDeclarationBlock); no_jsmanaged_fields!(HashSet<T>); // These three are interdependent, if you plan to put jsmanaged data // in one of these make sure it is propagated properly to containing structs -no_jsmanaged_fields!(SubpageId, WindowSizeData, PipelineId); +no_jsmanaged_fields!(SubpageId, WindowSizeData, WindowSizeType, PipelineId); no_jsmanaged_fields!(TimerEventId, TimerSource); no_jsmanaged_fields!(WorkerId); no_jsmanaged_fields!(QuirksMode); diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 82bfee7e279..d5abbfbcc3a 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -43,7 +43,8 @@ use js::rust::Runtime; use layout_interface::{ContentBoxResponse, ContentBoxesResponse, ResolvedStyleResponse, ScriptReflow}; use layout_interface::{LayoutChan, LayoutRPC, Msg, Reflow, ReflowQueryType, MarginStyleResponse}; use libc; -use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, SubpageId, WindowSizeData}; +use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, SubpageId}; +use msg::constellation_msg::{WindowSizeData, WindowSizeType}; use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use net_traits::ResourceThread; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread}; @@ -181,7 +182,7 @@ pub struct Window { next_subpage_id: Cell<SubpageId>, /// Pending resize event, if any. - resize_event: Cell<Option<WindowSizeData>>, + resize_event: Cell<Option<(WindowSizeData, WindowSizeType)>>, /// Pipeline id associated with this page. id: PipelineId, @@ -1280,11 +1281,11 @@ impl Window { self.pending_reflow_count.set(self.pending_reflow_count.get() + 1); } - pub fn set_resize_event(&self, event: WindowSizeData) { - self.resize_event.set(Some(event)); + pub fn set_resize_event(&self, event: WindowSizeData, event_type: WindowSizeType) { + self.resize_event.set(Some((event, event_type))); } - pub fn steal_resize_event(&self) -> Option<WindowSizeData> { + pub fn steal_resize_event(&self) -> Option<(WindowSizeData, WindowSizeType)> { let event = self.resize_event.get(); self.resize_event.set(None); event diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index c7a6f007154..22d1ddb0206 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -61,7 +61,7 @@ use layout_interface::{self, LayoutChan, NewLayoutThreadInfo, ScriptLayoutChan}; use mem::heap_size_of_self_and_children; use msg::constellation_msg::{ConstellationChan, LoadData}; use msg::constellation_msg::{PipelineId, PipelineNamespace}; -use msg::constellation_msg::{SubpageId, WindowSizeData}; +use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType}; use msg::webdriver_msg::WebDriverScriptCommand; use net_traits::LoadData as NetLoadData; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread}; @@ -635,8 +635,8 @@ impl ScriptThread { } } - for (id, size) in resizes { - self.handle_event(id, ResizeEvent(size)); + for (id, (size, size_type)) in resizes { + self.handle_event(id, ResizeEvent(size, size_type)); } // Store new resizes, and gather all other events. @@ -689,9 +689,9 @@ impl ScriptThread { self.handle_new_layout(new_layout_info); }) } - FromConstellation(ConstellationControlMsg::Resize(id, size)) => { + FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => { self.profile_event(ScriptThreadEventCategory::Resize, || { - self.handle_resize(id, size); + self.handle_resize(id, size, size_type); }) } FromConstellation(ConstellationControlMsg::Viewport(id, rect)) => { @@ -1020,10 +1020,10 @@ impl ScriptThread { } } - fn handle_resize(&self, id: PipelineId, size: WindowSizeData) { + fn handle_resize(&self, id: PipelineId, size: WindowSizeData, size_type: WindowSizeType) { if let Some(ref page) = self.find_subpage(id) { let window = page.window(); - window.set_resize_event(size); + window.set_resize_event(size, size_type); return; } let mut loads = self.incomplete_loads.borrow_mut(); @@ -1670,8 +1670,8 @@ impl ScriptThread { } match event { - ResizeEvent(new_size) => { - self.handle_resize_event(pipeline_id, new_size); + ResizeEvent(new_size, size_type) => { + self.handle_resize_event(pipeline_id, new_size, size_type); } MouseButtonEvent(event_type, button, point) => { @@ -1831,7 +1831,7 @@ impl ScriptThread { } } - fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData) { + fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData, size_type: WindowSizeType) { let page = get_page(&self.root_page(), pipeline_id); let window = page.window(); window.set_window_size(new_size); @@ -1849,11 +1849,13 @@ impl ScriptThread { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize - let uievent = UIEvent::new(window.r(), - DOMString::from("resize"), EventBubbles::DoesNotBubble, - EventCancelable::NotCancelable, Some(window.r()), - 0i32); - uievent.upcast::<Event>().fire(window.upcast()); + if size_type == WindowSizeType::Resize { + let uievent = UIEvent::new(window.r(), + DOMString::from("resize"), EventBubbles::DoesNotBubble, + EventCancelable::NotCancelable, Some(window.r()), + 0i32); + uievent.upcast::<Event>().fire(window.upcast()); + } } /// Initiate a non-blocking fetch for a specified resource. Stores the InProgressLoad diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index b8b0a34c77d..46c3e860643 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -41,7 +41,7 @@ use gfx_traits::Epoch; use gfx_traits::LayerId; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use libc::c_void; -use msg::constellation_msg::{ConstellationChan, PanicMsg, PipelineId, WindowSizeData}; +use msg::constellation_msg::{ConstellationChan, PanicMsg, PipelineId, WindowSizeData, WindowSizeType}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData}; use msg::constellation_msg::{PipelineNamespaceId, SubpageId}; use msg::webdriver_msg::WebDriverScriptCommand; @@ -109,7 +109,7 @@ pub enum ConstellationControlMsg { /// Gives a channel and ID to a layout thread, as well as the ID of that layout's parent AttachLayout(NewLayoutInfo), /// Window resized. Sends a DOM event eventually, but first we combine events. - Resize(PipelineId, WindowSizeData), + Resize(PipelineId, WindowSizeData, WindowSizeType), /// Notifies script that window has been resized but to not take immediate action. ResizeInactive(PipelineId, WindowSizeData), /// Notifies the script that a pipeline should be closed. @@ -220,7 +220,7 @@ pub enum MouseEventType { #[derive(Deserialize, Serialize)] pub enum CompositorEvent { /// The window was resized. - ResizeEvent(WindowSizeData), + ResizeEvent(WindowSizeData, WindowSizeType), /// A mouse button state changed. MouseButtonEvent(MouseEventType, MouseButton, Point2D<f32>), /// The mouse was moved over a point (or was moved out of the recognizable region). diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 98f8b14b52a..72b1a3c9946 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6682,6 +6682,12 @@ "url": "/_mozilla/mozilla/window_requestAnimationFrame2.html" } ], + "mozilla/window_resize_not_triggered_on_load.html": [ + { + "path": "mozilla/window_resize_not_triggered_on_load.html", + "url": "/_mozilla/mozilla/window_resize_not_triggered_on_load.html" + } + ], "mozilla/window_setInterval.html": [ { "path": "mozilla/window_setInterval.html", diff --git a/tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html b/tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html new file mode 100644 index 00000000000..f551f67ee91 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/window_resize_not_triggered_on_load.html @@ -0,0 +1,28 @@ +<!doctype html> +<meta charset="utf-8"> +<link rel="author" title="Mozilla" href="https://www.mozilla.org/"> +<link rel="author" title="Michael Howell" href="https://www.notriddle.com/"> +<link rel="help" href="https://drafts.csswg.org/cssom-view/#resizing-viewports"> +<script> +<!-- This event handler needs to be registered before the first layout --> +var resize_run = false; +window.onresize = function() { + resize_run = true; +}; +</script> +<title>window.onresize should not be called when the window first loads</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=d></div> +<script> +var t = async_test("window.onresize should not be called when the window first loads"); +var d = document.getElementById("d"); +window.getComputedStyle(d, null).getPropertyValue("width"); +d.style.width = "1px"; +window.onload = function() { + t.step(function() { + assert_true(!resize_run); + t.done(); + }); +}; +</script> |