mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move clip resolution code into style
This commit is contained in:
parent
d0670d4845
commit
433b653f70
2 changed files with 33 additions and 25 deletions
|
@ -22,11 +22,12 @@ use crate::properties;
|
|||
use crate::properties::{ComputedValues, LonghandId, StyleBuilder};
|
||||
use crate::rule_cache::RuleCacheConditions;
|
||||
use crate::{ArcSlice, Atom, One};
|
||||
use euclid::default::Size2D;
|
||||
use euclid::{default, Point2D, Rect, Size2D};
|
||||
use servo_arc::Arc;
|
||||
use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
use std::f32;
|
||||
use std::ops::{Add, Sub};
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::align::{
|
||||
|
@ -208,7 +209,7 @@ impl<'a> Context<'a> {
|
|||
}
|
||||
|
||||
/// The current viewport size, used to resolve viewport units.
|
||||
pub fn viewport_size_for_viewport_unit_resolution(&self) -> Size2D<Au> {
|
||||
pub fn viewport_size_for_viewport_unit_resolution(&self) -> default::Size2D<Au> {
|
||||
self.builder
|
||||
.device
|
||||
.au_viewport_size_for_viewport_unit_resolution()
|
||||
|
@ -353,11 +354,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> ToComputedValue for Size2D<T>
|
||||
impl<T> ToComputedValue for default::Size2D<T>
|
||||
where
|
||||
T: ToComputedValue,
|
||||
{
|
||||
type ComputedValue = Size2D<<T as ToComputedValue>::ComputedValue>;
|
||||
type ComputedValue = default::Size2D<<T as ToComputedValue>::ComputedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
|
@ -814,3 +815,29 @@ pub type GridLine = GenericGridLine<Integer>;
|
|||
|
||||
/// `<grid-template-rows> | <grid-template-columns>`
|
||||
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
|
||||
|
||||
impl ClipRect {
|
||||
/// Given a border box, resolves the clip rect against the border box
|
||||
/// in the same space the border box is in
|
||||
pub fn for_border_rect<T: Copy + From<Length> + Add<Output = T> + Sub<Output = T>, U>(
|
||||
&self,
|
||||
border_box: Rect<T, U>,
|
||||
) -> Rect<T, U> {
|
||||
fn extract_clip_component<T: From<Length>>(p: &LengthOrAuto, or: T) -> T {
|
||||
match *p {
|
||||
LengthOrAuto::Auto => or,
|
||||
LengthOrAuto::LengthPercentage(ref length) => T::from(*length),
|
||||
}
|
||||
}
|
||||
|
||||
let clip_origin = Point2D::new(
|
||||
From::from(self.left.auto_is(|| Length::new(0.))),
|
||||
From::from(self.top.auto_is(|| Length::new(0.))),
|
||||
);
|
||||
let right = extract_clip_component(&self.right, border_box.size.width);
|
||||
let bottom = extract_clip_component(&self.bottom, border_box.size.height);
|
||||
let clip_size = Size2D::new(right - clip_origin.x, bottom - clip_origin.y);
|
||||
|
||||
Rect::new(clip_origin, clip_size).translate(border_box.origin.to_vector())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue