diff options
author | Pyfisch <pyfisch@gmail.com> | 2018-01-17 23:17:39 +0100 |
---|---|---|
committer | Pyfisch <pyfisch@gmail.com> | 2018-01-17 23:29:57 +0100 |
commit | af52233ae57af8c05eab1f60f208cf5b42a832bd (patch) | |
tree | a63d1f9a157595244252aff28e06319539e3e025 | |
parent | 8c7c5f6e79c4709807d254a6367fb546f6f8e186 (diff) | |
download | servo-af52233ae57af8c05eab1f60f208cf5b42a832bd.tar.gz servo-af52233ae57af8c05eab1f60f208cf5b42a832bd.zip |
Introduce MaxRect trait
It is implemented for LayoutRect and Rect<Au>.
Replaces the max_rect() function from servo_geometry.
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | components/geometry/Cargo.toml | 1 | ||||
-rw-r--r-- | components/geometry/lib.rs | 27 | ||||
-rw-r--r-- | components/gfx/display_list/mod.rs | 13 | ||||
-rw-r--r-- | components/layout/block.rs | 4 | ||||
-rw-r--r-- | components/layout/display_list/builder.rs | 22 | ||||
-rw-r--r-- | components/layout/flow.rs | 4 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 4 | ||||
-rw-r--r-- | components/script/dom/window.rs | 8 |
9 files changed, 56 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock index ee393f4d852..109bda5891c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2959,6 +2959,7 @@ dependencies = [ "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.0.1", + "webrender_api 0.56.1 (git+https://github.com/servo/webrender)", ] [[package]] diff --git a/components/geometry/Cargo.toml b/components/geometry/Cargo.toml index 4dcc2d89fc9..d860ae213f0 100644 --- a/components/geometry/Cargo.toml +++ b/components/geometry/Cargo.toml @@ -14,3 +14,4 @@ app_units = "0.6" euclid = "0.16" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = { path = "../malloc_size_of_derive" } +webrender_api = { git = "https://github.com/servo/webrender" } diff --git a/components/geometry/lib.rs b/components/geometry/lib.rs index 61ded7c67d3..c22c9d16055 100644 --- a/components/geometry/lib.rs +++ b/components/geometry/lib.rs @@ -6,9 +6,12 @@ extern crate app_units; extern crate euclid; extern crate malloc_size_of; #[macro_use] extern crate malloc_size_of_derive; +extern crate webrender_api; use app_units::{Au, MAX_AU, MIN_AU}; use euclid::{Point2D, Rect, Size2D}; +use std::f32; +use webrender_api::{LayoutPoint, LayoutRect, LayoutSize}; // Units for use with euclid::length and euclid::scale_factor. @@ -32,9 +35,27 @@ pub enum DeviceIndependentPixel {} // originally proposed in 2002 as a standard unit of measure in Gecko. // See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info. -#[inline(always)] -pub fn max_rect() -> Rect<Au> { - Rect::new(Point2D::new(MIN_AU / 2, MIN_AU / 2), Size2D::new(MAX_AU, MAX_AU)) +pub trait MaxRect { + #[inline(always)] + fn max_rect() -> Self; +} + +impl MaxRect for Rect<Au> { + fn max_rect() -> Rect<Au> { + Rect::new( + Point2D::new(MIN_AU / 2, MIN_AU / 2), + Size2D::new(MAX_AU, MAX_AU) + ) + } +} + +impl MaxRect for LayoutRect { + fn max_rect() -> LayoutRect { + LayoutRect::new( + LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0), + LayoutSize::new(f32::MAX, f32::MAX), + ) + } } /// A helper function to convert a rect of `f32` pixels to a rect of app units. diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 1dbf7e5f97e..edde7e118f7 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -23,7 +23,7 @@ use ipc_channel::ipc::IpcSharedMemory; use msg::constellation_msg::PipelineId; use net_traits::image::base::{Image, PixelFormat}; use range::Range; -use servo_geometry::max_rect; +use servo_geometry::MaxRect; use std::cmp::{self, Ordering}; use std::collections::HashMap; use std::f32; @@ -445,10 +445,7 @@ impl BaseDisplayItem { pointing: None, }, // Create a rectangle of maximal size. - local_clip: LocalClip::from(LayoutRect::new( - LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0), - LayoutSize::new(f32::MAX, f32::MAX), - )), + local_clip: LocalClip::from(LayoutRect::max_rect()), section: DisplayListSection::Content, stacking_context_id: StackingContextId::root(), clipping_and_scrolling: ClippingAndScrolling::simple(ClipScrollNodeIndex(0)), @@ -495,7 +492,7 @@ impl ClippingRegion { #[inline] pub fn max() -> ClippingRegion { ClippingRegion { - main: max_rect(), + main: Rect::max_rect(), complex: Vec::new(), } } @@ -606,7 +603,7 @@ impl ClippingRegion { #[inline] pub fn is_max(&self) -> bool { - self.main == max_rect() && self.complex.is_empty() + self.main == Rect::max_rect() && self.complex.is_empty() } } @@ -616,7 +613,7 @@ impl fmt::Debug for ClippingRegion { write!(f, "ClippingRegion::Max") } else if *self == ClippingRegion::empty() { write!(f, "ClippingRegion::Empty") - } else if self.main == max_rect() { + } else if self.main == Rect::max_rect() { write!(f, "ClippingRegion(Complex={:?})", self.complex) } else { write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex) diff --git a/components/layout/block.rs b/components/layout/block.rs index 1d9f85b4672..7a846f50485 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -44,7 +44,7 @@ use layout_debug; use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto}; use sequential; use serde::{Serialize, Serializer}; -use servo_geometry::max_rect; +use servo_geometry::MaxRect; use std::cmp::{max, min}; use std::fmt; use std::sync::Arc; @@ -1955,7 +1955,7 @@ impl Flow for BlockFlow { let container_size = Size2D::new(self.base.block_container_inline_size, Au(0)); if self.is_root() { - self.base.clip = max_rect(); + self.base.clip = Rect::max_rect(); } if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 6d663bb420b..33daf270ccc 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -46,7 +46,7 @@ use net_traits::image::base::PixelFormat; use net_traits::image_cache::UsePlaceholder; use range::Range; use servo_config::opts; -use servo_geometry::max_rect; +use servo_geometry::MaxRect; use std::{cmp, f32}; use std::default::Default; use std::mem; @@ -2381,7 +2381,7 @@ impl SavedStackingContextCollectionState { .containing_block_clip_stack .last() .cloned() - .unwrap_or_else(max_rect); + .unwrap_or_else(MaxRect::max_rect); state.clip_stack.push(clip); self.clips_pushed += 1; } @@ -2447,7 +2447,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { let origin = &border_box.origin; let transform_clip = |clip: &Rect<Au>| { - if *clip == max_rect() { + if *clip == Rect::max_rect() { return *clip; } @@ -2458,7 +2458,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { // clip region. Here we don't have enough information to detect when that is // happening. For the moment we just punt on trying to optimize the display // list for those cases. - max_rect() + Rect::max_rect() }, Some(transform) => { let clip = Rect::new( @@ -2573,7 +2573,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { state.containing_block_clipping_and_scrolling }, StylePosition::Fixed => { - preserved_state.push_clip(state, &max_rect(), StylePosition::Fixed); + preserved_state.push_clip(state, &Rect::max_rect(), StylePosition::Fixed); state.current_clipping_and_scrolling }, _ => state.current_clipping_and_scrolling, @@ -2599,7 +2599,11 @@ impl BlockFlowDisplayListBuilding for BlockFlow { &stacking_relative_border_box, ); } - self.base.clip = state.clip_stack.last().cloned().unwrap_or_else(max_rect); + self.base.clip = state + .clip_stack + .last() + .cloned() + .unwrap_or_else(Rect::max_rect); // We keep track of our position so that any stickily positioned elements can // properly determine the extent of their movement relative to scrolling containers. @@ -2969,7 +2973,11 @@ impl InlineFlowDisplayListBuilding for InlineFlow { fn collect_stacking_contexts_for_inline(&mut self, state: &mut StackingContextCollectionState) { self.base.stacking_context_id = state.current_stacking_context_id; self.base.clipping_and_scrolling = Some(state.current_clipping_and_scrolling); - self.base.clip = state.clip_stack.last().cloned().unwrap_or_else(max_rect); + self.base.clip = state + .clip_stack + .last() + .cloned() + .unwrap_or_else(Rect::max_rect); for fragment in self.fragments.fragments.iter_mut() { let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling; diff --git a/components/layout/flow.rs b/components/layout/flow.rs index c16dd37ebf0..b145aef0ad6 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -43,7 +43,7 @@ use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo}; use multicol::MulticolFlow; use parallel::FlowParallelInfo; use serde::ser::{Serialize, SerializeStruct, Serializer}; -use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, max_rect}; +use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, MaxRect}; use std::fmt; use std::iter::Zip; use std::slice::IterMut; @@ -1062,7 +1062,7 @@ impl BaseFlow { absolute_cb: ContainingBlockLink::new(), early_absolute_position_info: EarlyAbsolutePositionInfo::new(writing_mode), late_absolute_position_info: LateAbsolutePositionInfo::new(), - clip: max_rect(), + clip: MaxRect::max_rect(), flags: flags, writing_mode: writing_mode, thread_id: 0, diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index c37d3ada351..ca231ffc698 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -108,7 +108,7 @@ use servo_atoms::Atom; use servo_config::opts; use servo_config::prefs::PREFS; use servo_config::resource_files::read_resource_file; -use servo_geometry::max_rect; +use servo_geometry::MaxRect; use servo_url::ServoUrl; use std::borrow::ToOwned; use std::cell::{Cell, RefCell}; @@ -1467,7 +1467,7 @@ impl LayoutThread { if let Some(mut root_flow) = self.root_flow.borrow().clone() { let reflow_info = Reflow { - page_clip_rect: max_rect(), + page_clip_rect: Rect::max_rect(), }; // Unwrap here should not panic since self.root_flow is only ever set to Some(_) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 71d13e8e8f7..21713696f82 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -84,7 +84,7 @@ use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use selectors::attr::CaseSensitivity; use servo_config::opts; use servo_config::prefs::PREFS; -use servo_geometry::{f32_rect_to_au_rect, max_rect}; +use servo_geometry::{f32_rect_to_au_rect, MaxRect}; use servo_url::{Host, MutableOrigin, ImmutableOrigin, ServoUrl}; use std::borrow::ToOwned; use std::cell::Cell; @@ -1606,7 +1606,7 @@ impl Window { return false; } - let had_clip_rect = clip_rect != max_rect(); + let had_clip_rect = clip_rect != MaxRect::max_rect(); if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) { return false; } @@ -1614,7 +1614,7 @@ impl Window { self.page_clip_rect.set(proposed_clip_rect); // If we didn't have a clip rect, the previous display doesn't need rebuilding - // because it was built for infinite clip (max_rect()). + // because it was built for infinite clip (MaxRect::amax_rect()). had_clip_rect } @@ -1835,7 +1835,7 @@ impl Window { js_runtime: DomRefCell::new(Some(runtime.clone())), bluetooth_thread, bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(), - page_clip_rect: Cell::new(max_rect()), + page_clip_rect: Cell::new(MaxRect::max_rect()), resize_event: Default::default(), layout_chan, layout_rpc, |