mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Cleanup position and make use of generic Position for its users
This commit is contained in:
parent
3f53fb148d
commit
61a17993eb
10 changed files with 277 additions and 677 deletions
|
@ -376,17 +376,17 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
<%def name="impl_position(ident, gecko_ffi_name, need_clone=False)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
${set_gecko_property("%s.mXPosition" % gecko_ffi_name, "v.horizontal.into()")}
|
||||
${set_gecko_property("%s.mYPosition" % gecko_ffi_name, "v.vertical.into()")}
|
||||
${set_gecko_property("%s.mXPosition" % gecko_ffi_name, "v.horizontal.0.into()")}
|
||||
${set_gecko_property("%s.mYPosition" % gecko_ffi_name, "v.vertical.0.into()")}
|
||||
}
|
||||
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||
% if need_clone:
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
use values::computed::Position;
|
||||
use values::generics::position::{HorizontalPosition, Position, VerticalPosition};
|
||||
Position {
|
||||
horizontal: self.gecko.${gecko_ffi_name}.mXPosition.into(),
|
||||
vertical: self.gecko.${gecko_ffi_name}.mYPosition.into(),
|
||||
horizontal: HorizontalPosition(self.gecko.${gecko_ffi_name}.mXPosition.into()),
|
||||
vertical: VerticalPosition(self.gecko.${gecko_ffi_name}.mYPosition.into()),
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
@ -1947,8 +1947,8 @@ fn static_assert() {
|
|||
for (gecko, servo) in self.gecko.mScrollSnapCoordinate
|
||||
.iter_mut()
|
||||
.zip(v.0.iter()) {
|
||||
gecko.mXPosition = servo.horizontal.into();
|
||||
gecko.mYPosition = servo.vertical.into();
|
||||
gecko.mXPosition = servo.horizontal.0.into();
|
||||
gecko.mYPosition = servo.vertical.0.into();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2600,7 +2600,7 @@ fn static_assert() {
|
|||
|
||||
pub fn clone_${shorthand}_position_${orientation[0]}(&self)
|
||||
-> longhands::${shorthand}_position_${orientation[0]}::computed_value::T {
|
||||
use values::computed::position::${orientation[1]}Position;
|
||||
use values::generics::position::${orientation[1]}Position;
|
||||
longhands::${shorthand}_position_${orientation[0]}::computed_value::T(
|
||||
self.gecko.${image_layers_field}.mLayers.iter()
|
||||
.take(self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count as usize)
|
||||
|
|
|
@ -36,9 +36,9 @@ use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone
|
|||
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone};
|
||||
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
|
||||
use values::computed::{MaxLength, MinLength};
|
||||
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
|
||||
use values::computed::position::{HorizontalPosition, VerticalPosition};
|
||||
use values::computed::ToComputedValue;
|
||||
|
||||
use values::generics::position as generic_position;
|
||||
|
||||
|
||||
/// A given transition property, that is either `All`, or an animatable
|
||||
|
@ -957,23 +957,24 @@ impl Interpolate for FontWeight {
|
|||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||
impl Interpolate for Position {
|
||||
impl<H: Interpolate, V: Interpolate> Interpolate for generic_position::Position<H, V> {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
Ok(Position {
|
||||
Ok(generic_position::Position {
|
||||
horizontal: try!(self.horizontal.interpolate(&other.horizontal, progress)),
|
||||
vertical: try!(self.vertical.interpolate(&other.vertical, progress)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatableListInterpolate for Position {}
|
||||
impl<H, V> RepeatableListInterpolate for generic_position::Position<H, V>
|
||||
where H: RepeatableListInterpolate, V: RepeatableListInterpolate {}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||
impl Interpolate for HorizontalPosition {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
Ok(HorizontalPosition(try!(self.0.interpolate(&other.0, progress))))
|
||||
self.0.interpolate(&other.0, progress).map(generic_position::HorizontalPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -983,7 +984,7 @@ impl RepeatableListInterpolate for HorizontalPosition {}
|
|||
impl Interpolate for VerticalPosition {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
Ok(VerticalPosition(try!(self.0.interpolate(&other.0, progress))))
|
||||
self.0.interpolate(&other.0, progress).map(generic_position::VerticalPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2607,7 +2608,9 @@ impl ComputeDistance for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for Position {
|
||||
impl<H, V> ComputeDistance for generic_position::Position<H, V>
|
||||
where H: ComputeDistance, V: ComputeDistance
|
||||
{
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
|
|
@ -111,26 +111,27 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
|||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::HorizontalPosition;
|
||||
use values::generics::position::HorizontalPosition;
|
||||
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
HorizontalPosition {
|
||||
use values::generics::position::{HorizontalPosition, Keyword, PositionValue};
|
||||
HorizontalPosition(PositionValue {
|
||||
keyword: Some(Keyword::Left),
|
||||
position: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::generics::position::{HorizontalPosition, PositionValue};
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
HorizontalPosition {
|
||||
HorizontalPosition(PositionValue {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
|
@ -162,26 +163,27 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
|||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::VerticalPosition;
|
||||
use values::generics::position::VerticalPosition;
|
||||
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
VerticalPosition {
|
||||
use values::generics::position::{Keyword, PositionValue, VerticalPosition};
|
||||
VerticalPosition(PositionValue {
|
||||
keyword: Some(Keyword::Top),
|
||||
position: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::generics::position::{PositionValue, VerticalPosition};
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
VerticalPosition {
|
||||
VerticalPosition(PositionValue {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1113,7 +1113,6 @@ ${helpers.predefined_type("scroll-snap-coordinate",
|
|||
delegate_animate=True)}
|
||||
|
||||
|
||||
|
||||
<%helpers:longhand name="transform" extra_prefixes="webkit"
|
||||
animation_value_type="ComputedValue"
|
||||
flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
|
||||
|
@ -2096,83 +2095,13 @@ ${helpers.predefined_type("perspective",
|
|||
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
|
||||
animation_value_type="ComputedValue")}
|
||||
|
||||
<%helpers:longhand name="perspective-origin" boxed="True"
|
||||
animation_value_type="ComputedValue"
|
||||
extra_prefixes="moz webkit"
|
||||
spec="https://drafts.csswg.org/css-transforms/#perspective-origin-property">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
|
||||
pub mod computed_value {
|
||||
use properties::animated_properties::Interpolate;
|
||||
use values::computed::LengthOrPercentage;
|
||||
use values::computed::Position;
|
||||
|
||||
pub type T = Position;
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.horizontal.has_viewport_percentage() || self.vertical.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue {
|
||||
horizontal: LengthOrPercentage,
|
||||
vertical: LengthOrPercentage,
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T {
|
||||
horizontal: computed::LengthOrPercentage::Percentage(0.5),
|
||||
vertical: computed::LengthOrPercentage::Percentage(0.5),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
let result = try!(super::parse_origin(context, input));
|
||||
match result.depth {
|
||||
Some(_) => Err(()),
|
||||
None => Ok(SpecifiedValue {
|
||||
horizontal: result.horizontal.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))),
|
||||
vertical: result.vertical.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
computed_value::T {
|
||||
horizontal: self.horizontal.to_computed_value(context),
|
||||
vertical: self.vertical.to_computed_value(context),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue {
|
||||
horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
|
||||
vertical: ToComputedValue::from_computed_value(&computed.vertical),
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("perspective-origin",
|
||||
"position::OriginPosition",
|
||||
"computed::position::OriginPosition::center()",
|
||||
boxed="True",
|
||||
extra_prefixes="moz webkit",
|
||||
spec="https://drafts.csswg.org/css-transforms/#perspective-origin-property",
|
||||
animation_value_type="ComputedValue")}
|
||||
|
||||
${helpers.single_keyword("backface-visibility",
|
||||
"visible hidden",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue