Skip to content

Commit

Permalink
Auto merge of #16962 - hiikezoe:prefixed-intrinsic-size-value, r=Mani…
Browse files Browse the repository at this point in the history
…shearth

Prefixed intrinsic size value

<!-- Please describe your changes on the following line: -->

This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1355402
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #16788
- [X] These changes do not require tests because it's for stylo

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16962)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 22, 2017
2 parents 8cd4330 + d06af89 commit b428a94
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 226 deletions.
26 changes: 8 additions & 18 deletions components/style/gecko/values.rs
Expand Up @@ -14,7 +14,7 @@ use std::cmp::max;
use values::{Auto, Either, ExtremumLength, None_, Normal};
use values::computed::{Angle, LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage};
use values::computed::{MaxLength, MinLength};
use values::computed::{MaxLength, MozLength};
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::basic_shape::ShapeRadius;
use values::specified::Percentage;
Expand Down Expand Up @@ -335,41 +335,31 @@ impl GeckoStyleCoordConvertible for ExtremumLength {
}
}

impl GeckoStyleCoordConvertible for MinLength {
impl GeckoStyleCoordConvertible for MozLength {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self {
MinLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord),
MinLength::Auto => coord.set_value(CoordDataValue::Auto),
MinLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
MozLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord),
MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
}
}

fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
LengthOrPercentage::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentage)
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MinLength::ExtremumLength))
.or_else(|| match coord.as_value() {
CoordDataValue::Auto => Some(MinLength::Auto),
_ => None,
})
LengthOrPercentageOrAuto::from_gecko_style_coord(coord).map(MozLength::LengthOrPercentageOrAuto)
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength))
}
}

impl GeckoStyleCoordConvertible for MaxLength {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self {
MaxLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord),
MaxLength::None => coord.set_value(CoordDataValue::None),
MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord),
MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
}
}

fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
LengthOrPercentage::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentage)
LengthOrPercentageOrNone::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentageOrNone)
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength))
.or_else(|| match coord.as_value() {
CoordDataValue::None => Some(MaxLength::None),
_ => None,
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/gecko.mako.rs
Expand Up @@ -675,7 +675,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"LengthOrNone": impl_style_coord,
"LengthOrNormal": impl_style_coord,
"MaxLength": impl_style_coord,
"MinLength": impl_style_coord,
"MozLength": impl_style_coord,
"Number": impl_simple,
"Integer": impl_simple,
"Opacity": impl_simple,
Expand Down
101 changes: 101 additions & 0 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -1067,3 +1067,104 @@
}
}
</%def>

// Define property that supports prefixed intrinsic size keyword values for gecko.
// E.g. -moz-max-content, -moz-min-content, etc.
<%def name="gecko_size_type(name, length_type, initial_value, logical, **kwargs)">
<%call expr="longhand(name,
predefined_type=length_type,
logical=logical,
**kwargs)">
use std::fmt;
use style_traits::ToCss;
% if not logical:
use values::specified::AllowQuirks;
% endif
use values::specified::${length_type};

pub mod computed_value {
pub type T = ::values::computed::${length_type};
}

#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue(pub ${length_type});

% if length_type == "MozLength":
impl SpecifiedValue {
/// Returns the `auto` value.
pub fn auto() -> Self {
use values::specified::length::LengthOrPercentageOrAuto;
SpecifiedValue(MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto))
}

/// Returns a value representing a `0` length.
pub fn zero() -> Self {
use values::specified::length::{LengthOrPercentageOrAuto, NoCalcLength};
SpecifiedValue(MozLength::LengthOrPercentageOrAuto(
LengthOrPercentageOrAuto::Length(NoCalcLength::zero())))
}
}
% endif

#[inline]
pub fn get_initial_value() -> computed_value::T {
use values::computed::${length_type};
${length_type}::${initial_value}
}
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
% if logical:
let ret = ${length_type}::parse(context, input);
% else:
let ret = ${length_type}::parse_quirky(context, input, AllowQuirks::Yes);
% endif
// Keyword values don't make sense in the block direction; don't parse them
% if "block" in name:
if let Ok(${length_type}::ExtremumLength(..)) = ret {
return Err(())
}
% endif
ret.map(SpecifiedValue)
}

impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}

impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
% if not logical or "block" in name:
use values::computed::${length_type};
% endif
let computed = self.0.to_computed_value(context);

// filter out keyword values in the block direction
% if logical:
% if "block" in name:
if let ${length_type}::ExtremumLength(..) = computed {
return get_initial_value()
}
% endif
% else:
if let ${length_type}::ExtremumLength(..) = computed {
<% is_height = "true" if "height" in name else "false" %>
if ${is_height} != context.style().writing_mode.is_vertical() {
return get_initial_value()
}
}
% endif
computed
}

#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
SpecifiedValue(ToComputedValue::from_computed_value(computed))
}
}
</%call>
</%def>

24 changes: 12 additions & 12 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -41,7 +41,7 @@ use values::{Auto, Either, generics};
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, ClipRect};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
use values::computed::{MaxLength, MinLength};
use values::computed::{MaxLength, MozLength};
use values::computed::ToComputedValue;
use values::generics::position as generic_position;

Expand Down Expand Up @@ -1237,14 +1237,14 @@ impl Animatable for LengthOrPercentageOrNone {
}

/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
impl Animatable for MinLength {
impl Animatable for MozLength {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (*self, *other) {
(MinLength::LengthOrPercentage(ref this),
MinLength::LengthOrPercentage(ref other)) => {
(MozLength::LengthOrPercentageOrAuto(ref this),
MozLength::LengthOrPercentageOrAuto(ref other)) => {
this.add_weighted(other, self_portion, other_portion)
.map(MinLength::LengthOrPercentage)
.map(MozLength::LengthOrPercentageOrAuto)
}
_ => Err(()),
}
Expand All @@ -1253,8 +1253,8 @@ impl Animatable for MinLength {
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) {
(MinLength::LengthOrPercentage(ref this),
MinLength::LengthOrPercentage(ref other)) => {
(MozLength::LengthOrPercentageOrAuto(ref this),
MozLength::LengthOrPercentageOrAuto(ref other)) => {
this.compute_distance(other)
},
_ => Err(()),
Expand All @@ -1267,10 +1267,10 @@ impl Animatable for MaxLength {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (*self, *other) {
(MaxLength::LengthOrPercentage(ref this),
MaxLength::LengthOrPercentage(ref other)) => {
(MaxLength::LengthOrPercentageOrNone(ref this),
MaxLength::LengthOrPercentageOrNone(ref other)) => {
this.add_weighted(other, self_portion, other_portion)
.map(MaxLength::LengthOrPercentage)
.map(MaxLength::LengthOrPercentageOrNone)
}
_ => Err(()),
}
Expand All @@ -1279,8 +1279,8 @@ impl Animatable for MaxLength {
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) {
(MaxLength::LengthOrPercentage(ref this),
MaxLength::LengthOrPercentage(ref other)) => {
(MaxLength::LengthOrPercentageOrNone(ref this),
MaxLength::LengthOrPercentageOrNone(ref other)) => {
this.compute_distance(other)
},
_ => Err(()),
Expand Down

0 comments on commit b428a94

Please sign in to comment.