mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Introduce MaxRect trait
It is implemented for LayoutRect and Rect<Au>. Replaces the max_rect() function from servo_geometry.
This commit is contained in:
parent
8c7c5f6e79
commit
af52233ae5
9 changed files with 56 additions and 28 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2959,6 +2959,7 @@ dependencies = [
|
||||||
"euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"malloc_size_of 0.0.1",
|
"malloc_size_of 0.0.1",
|
||||||
"malloc_size_of_derive 0.0.1",
|
"malloc_size_of_derive 0.0.1",
|
||||||
|
"webrender_api 0.56.1 (git+https://github.com/servo/webrender)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -14,3 +14,4 @@ app_units = "0.6"
|
||||||
euclid = "0.16"
|
euclid = "0.16"
|
||||||
malloc_size_of = { path = "../malloc_size_of" }
|
malloc_size_of = { path = "../malloc_size_of" }
|
||||||
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||||
|
webrender_api = { git = "https://github.com/servo/webrender" }
|
||||||
|
|
|
@ -6,9 +6,12 @@ extern crate app_units;
|
||||||
extern crate euclid;
|
extern crate euclid;
|
||||||
extern crate malloc_size_of;
|
extern crate malloc_size_of;
|
||||||
#[macro_use] extern crate malloc_size_of_derive;
|
#[macro_use] extern crate malloc_size_of_derive;
|
||||||
|
extern crate webrender_api;
|
||||||
|
|
||||||
use app_units::{Au, MAX_AU, MIN_AU};
|
use app_units::{Au, MAX_AU, MIN_AU};
|
||||||
use euclid::{Point2D, Rect, Size2D};
|
use euclid::{Point2D, Rect, Size2D};
|
||||||
|
use std::f32;
|
||||||
|
use webrender_api::{LayoutPoint, LayoutRect, LayoutSize};
|
||||||
|
|
||||||
// Units for use with euclid::length and euclid::scale_factor.
|
// 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.
|
// 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.
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
|
||||||
|
|
||||||
#[inline(always)]
|
pub trait MaxRect {
|
||||||
pub fn max_rect() -> Rect<Au> {
|
#[inline(always)]
|
||||||
Rect::new(Point2D::new(MIN_AU / 2, MIN_AU / 2), Size2D::new(MAX_AU, MAX_AU))
|
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.
|
/// A helper function to convert a rect of `f32` pixels to a rect of app units.
|
||||||
|
|
|
@ -23,7 +23,7 @@ use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use net_traits::image::base::{Image, PixelFormat};
|
use net_traits::image::base::{Image, PixelFormat};
|
||||||
use range::Range;
|
use range::Range;
|
||||||
use servo_geometry::max_rect;
|
use servo_geometry::MaxRect;
|
||||||
use std::cmp::{self, Ordering};
|
use std::cmp::{self, Ordering};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
@ -445,10 +445,7 @@ impl BaseDisplayItem {
|
||||||
pointing: None,
|
pointing: None,
|
||||||
},
|
},
|
||||||
// Create a rectangle of maximal size.
|
// Create a rectangle of maximal size.
|
||||||
local_clip: LocalClip::from(LayoutRect::new(
|
local_clip: LocalClip::from(LayoutRect::max_rect()),
|
||||||
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
|
|
||||||
LayoutSize::new(f32::MAX, f32::MAX),
|
|
||||||
)),
|
|
||||||
section: DisplayListSection::Content,
|
section: DisplayListSection::Content,
|
||||||
stacking_context_id: StackingContextId::root(),
|
stacking_context_id: StackingContextId::root(),
|
||||||
clipping_and_scrolling: ClippingAndScrolling::simple(ClipScrollNodeIndex(0)),
|
clipping_and_scrolling: ClippingAndScrolling::simple(ClipScrollNodeIndex(0)),
|
||||||
|
@ -495,7 +492,7 @@ impl ClippingRegion {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn max() -> ClippingRegion {
|
pub fn max() -> ClippingRegion {
|
||||||
ClippingRegion {
|
ClippingRegion {
|
||||||
main: max_rect(),
|
main: Rect::max_rect(),
|
||||||
complex: Vec::new(),
|
complex: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -606,7 +603,7 @@ impl ClippingRegion {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_max(&self) -> bool {
|
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")
|
write!(f, "ClippingRegion::Max")
|
||||||
} else if *self == ClippingRegion::empty() {
|
} else if *self == ClippingRegion::empty() {
|
||||||
write!(f, "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)
|
write!(f, "ClippingRegion(Complex={:?})", self.complex)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex)
|
write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex)
|
||||||
|
|
|
@ -44,7 +44,7 @@ use layout_debug;
|
||||||
use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
|
use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
|
||||||
use sequential;
|
use sequential;
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
use servo_geometry::max_rect;
|
use servo_geometry::MaxRect;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
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));
|
let container_size = Size2D::new(self.base.block_container_inline_size, Au(0));
|
||||||
|
|
||||||
if self.is_root() {
|
if self.is_root() {
|
||||||
self.base.clip = max_rect();
|
self.base.clip = Rect::max_rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) {
|
if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ use net_traits::image::base::PixelFormat;
|
||||||
use net_traits::image_cache::UsePlaceholder;
|
use net_traits::image_cache::UsePlaceholder;
|
||||||
use range::Range;
|
use range::Range;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_geometry::max_rect;
|
use servo_geometry::MaxRect;
|
||||||
use std::{cmp, f32};
|
use std::{cmp, f32};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -2381,7 +2381,7 @@ impl SavedStackingContextCollectionState {
|
||||||
.containing_block_clip_stack
|
.containing_block_clip_stack
|
||||||
.last()
|
.last()
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(max_rect);
|
.unwrap_or_else(MaxRect::max_rect);
|
||||||
state.clip_stack.push(clip);
|
state.clip_stack.push(clip);
|
||||||
self.clips_pushed += 1;
|
self.clips_pushed += 1;
|
||||||
}
|
}
|
||||||
|
@ -2447,7 +2447,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
||||||
|
|
||||||
let origin = &border_box.origin;
|
let origin = &border_box.origin;
|
||||||
let transform_clip = |clip: &Rect<Au>| {
|
let transform_clip = |clip: &Rect<Au>| {
|
||||||
if *clip == max_rect() {
|
if *clip == Rect::max_rect() {
|
||||||
return *clip;
|
return *clip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2458,7 +2458,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
||||||
// clip region. Here we don't have enough information to detect when that is
|
// 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
|
// happening. For the moment we just punt on trying to optimize the display
|
||||||
// list for those cases.
|
// list for those cases.
|
||||||
max_rect()
|
Rect::max_rect()
|
||||||
},
|
},
|
||||||
Some(transform) => {
|
Some(transform) => {
|
||||||
let clip = Rect::new(
|
let clip = Rect::new(
|
||||||
|
@ -2573,7 +2573,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
||||||
state.containing_block_clipping_and_scrolling
|
state.containing_block_clipping_and_scrolling
|
||||||
},
|
},
|
||||||
StylePosition::Fixed => {
|
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
|
||||||
},
|
},
|
||||||
_ => state.current_clipping_and_scrolling,
|
_ => state.current_clipping_and_scrolling,
|
||||||
|
@ -2599,7 +2599,11 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
||||||
&stacking_relative_border_box,
|
&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
|
// We keep track of our position so that any stickily positioned elements can
|
||||||
// properly determine the extent of their movement relative to scrolling containers.
|
// 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) {
|
fn collect_stacking_contexts_for_inline(&mut self, state: &mut StackingContextCollectionState) {
|
||||||
self.base.stacking_context_id = state.current_stacking_context_id;
|
self.base.stacking_context_id = state.current_stacking_context_id;
|
||||||
self.base.clipping_and_scrolling = Some(state.current_clipping_and_scrolling);
|
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() {
|
for fragment in self.fragments.fragments.iter_mut() {
|
||||||
let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling;
|
let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling;
|
||||||
|
|
|
@ -43,7 +43,7 @@ use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo};
|
||||||
use multicol::MulticolFlow;
|
use multicol::MulticolFlow;
|
||||||
use parallel::FlowParallelInfo;
|
use parallel::FlowParallelInfo;
|
||||||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
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::fmt;
|
||||||
use std::iter::Zip;
|
use std::iter::Zip;
|
||||||
use std::slice::IterMut;
|
use std::slice::IterMut;
|
||||||
|
@ -1062,7 +1062,7 @@ impl BaseFlow {
|
||||||
absolute_cb: ContainingBlockLink::new(),
|
absolute_cb: ContainingBlockLink::new(),
|
||||||
early_absolute_position_info: EarlyAbsolutePositionInfo::new(writing_mode),
|
early_absolute_position_info: EarlyAbsolutePositionInfo::new(writing_mode),
|
||||||
late_absolute_position_info: LateAbsolutePositionInfo::new(),
|
late_absolute_position_info: LateAbsolutePositionInfo::new(),
|
||||||
clip: max_rect(),
|
clip: MaxRect::max_rect(),
|
||||||
flags: flags,
|
flags: flags,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
thread_id: 0,
|
thread_id: 0,
|
||||||
|
|
|
@ -108,7 +108,7 @@ use servo_atoms::Atom;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use servo_config::resource_files::read_resource_file;
|
use servo_config::resource_files::read_resource_file;
|
||||||
use servo_geometry::max_rect;
|
use servo_geometry::MaxRect;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -1467,7 +1467,7 @@ impl LayoutThread {
|
||||||
|
|
||||||
if let Some(mut root_flow) = self.root_flow.borrow().clone() {
|
if let Some(mut root_flow) = self.root_flow.borrow().clone() {
|
||||||
let reflow_info = Reflow {
|
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(_)
|
// Unwrap here should not panic since self.root_flow is only ever set to Some(_)
|
||||||
|
|
|
@ -84,7 +84,7 @@ use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||||
use selectors::attr::CaseSensitivity;
|
use selectors::attr::CaseSensitivity;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::prefs::PREFS;
|
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 servo_url::{Host, MutableOrigin, ImmutableOrigin, ServoUrl};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -1606,7 +1606,7 @@ impl Window {
|
||||||
return false;
|
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) {
|
if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1614,7 +1614,7 @@ impl Window {
|
||||||
self.page_clip_rect.set(proposed_clip_rect);
|
self.page_clip_rect.set(proposed_clip_rect);
|
||||||
|
|
||||||
// If we didn't have a clip rect, the previous display doesn't need rebuilding
|
// 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
|
had_clip_rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1835,7 +1835,7 @@ impl Window {
|
||||||
js_runtime: DomRefCell::new(Some(runtime.clone())),
|
js_runtime: DomRefCell::new(Some(runtime.clone())),
|
||||||
bluetooth_thread,
|
bluetooth_thread,
|
||||||
bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(),
|
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(),
|
resize_event: Default::default(),
|
||||||
layout_chan,
|
layout_chan,
|
||||||
layout_rpc,
|
layout_rpc,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue