mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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)",
|
||||
"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]]
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(_)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue