mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
servo: Merge #16962 - Prefixed intrinsic size value (from hiikezoe:prefixed-intrinsic-size-value); r=Manishearth
<!-- 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 Source-Repo: https://github.com/servo/servo Source-Revision: b428a94326322c88da4c32e56ee753ceeffca7d1 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 0cdc75fec1582bdcf69647c479528745a516e569
This commit is contained in:
parent
c145a6fb23
commit
01ba33f442
@ -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;
|
||||
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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;
|
||||
|
||||
@ -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(()),
|
||||
}
|
||||
@ -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(()),
|
||||
@ -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(()),
|
||||
}
|
||||
@ -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(()),
|
||||
|
@ -134,125 +134,54 @@ ${helpers.predefined_type("order", "Integer", "0",
|
||||
animation_value_type="ComputedValue",
|
||||
spec="https://drafts.csswg.org/css-flexbox/#order-property")}
|
||||
|
||||
// FIXME: Gecko doesn't support content value yet.
|
||||
// FIXME: This property should be animatable.
|
||||
${helpers.predefined_type("flex-basis",
|
||||
"LengthOrPercentageOrAuto" if product == "gecko" else
|
||||
"LengthOrPercentageOrAutoOrContent",
|
||||
"computed::LengthOrPercentageOrAuto::Auto" if product == "gecko" else
|
||||
"computed::LengthOrPercentageOrAutoOrContent::Auto",
|
||||
"parse_non_negative",
|
||||
spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
|
||||
extra_prefixes="webkit",
|
||||
animation_value_type="ComputedValue" if product == "gecko" else "none")}
|
||||
|
||||
% if product == "gecko":
|
||||
// FIXME: Gecko doesn't support content value yet.
|
||||
${helpers.gecko_size_type("flex-basis", "MozLength", "auto()",
|
||||
logical=False,
|
||||
spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
|
||||
extra_prefixes="webkit",
|
||||
animation_value_type="ComputedValue")}
|
||||
% else:
|
||||
// FIXME: This property should be animatable.
|
||||
${helpers.predefined_type("flex-basis",
|
||||
"LengthOrPercentageOrAutoOrContent",
|
||||
"computed::LengthOrPercentageOrAutoOrContent::Auto",
|
||||
"parse_non_negative",
|
||||
spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
|
||||
extra_prefixes="webkit",
|
||||
animation_value_type="none")}
|
||||
% endif
|
||||
% for (size, logical) in ALL_SIZES:
|
||||
<%
|
||||
spec = "https://drafts.csswg.org/css-box/#propdef-%s"
|
||||
if logical:
|
||||
spec = "https://drafts.csswg.org/css-logical-props/#propdef-%s"
|
||||
%>
|
||||
// width, height, block-size, inline-size
|
||||
${helpers.predefined_type("%s" % size,
|
||||
"LengthOrPercentageOrAuto",
|
||||
"computed::LengthOrPercentageOrAuto::Auto",
|
||||
"parse_non_negative",
|
||||
spec=spec % size,
|
||||
allow_quirks=not logical,
|
||||
animation_value_type="ComputedValue", logical = logical)}
|
||||
% if product == "gecko":
|
||||
% for min_max in ["min", "max"]:
|
||||
<%
|
||||
MinMax = min_max.title()
|
||||
initial = "None" if "max" == min_max else "Auto"
|
||||
%>
|
||||
|
||||
// min-width, min-height, min-block-size, min-inline-size,
|
||||
// max-width, max-height, max-block-size, max-inline-size
|
||||
//
|
||||
// Keyword values are only valid in the inline direction; they must
|
||||
// be replaced with auto/none in block.
|
||||
<%helpers:longhand name="${min_max}-${size}" spec="${spec % ('%s-%s' % (min_max, size))}"
|
||||
animation_value_type="ComputedValue"
|
||||
logical="${logical}" predefined_type="${MinMax}Length">
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
% if not logical:
|
||||
use values::specified::AllowQuirks;
|
||||
% endif
|
||||
use values::specified::${MinMax}Length;
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = ::values::computed::${MinMax}Length;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(${MinMax}Length);
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::${MinMax}Length;
|
||||
${MinMax}Length::${initial}
|
||||
}
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
% if logical:
|
||||
let ret = ${MinMax}Length::parse(context, input);
|
||||
% else:
|
||||
let ret = ${MinMax}Length::parse_quirky(context, input, AllowQuirks::Yes);
|
||||
% endif
|
||||
// Keyword values don't make sense in the block direction; don't parse them
|
||||
% if "block" in size:
|
||||
if let Ok(${MinMax}Length::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 size:
|
||||
use values::computed::${MinMax}Length;
|
||||
% endif
|
||||
let computed = self.0.to_computed_value(context);
|
||||
|
||||
// filter out keyword values in the block direction
|
||||
% if logical:
|
||||
% if "block" in size:
|
||||
if let ${MinMax}Length::ExtremumLength(..) = computed {
|
||||
return get_initial_value()
|
||||
}
|
||||
% endif
|
||||
% else:
|
||||
if let ${MinMax}Length::ExtremumLength(..) = computed {
|
||||
<% is_height = "true" if "height" in size 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))
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
% endfor
|
||||
// width, height, block-size, inline-size
|
||||
${helpers.gecko_size_type("%s" % size, "MozLength", "auto()",
|
||||
logical,
|
||||
spec=spec % size,
|
||||
animation_value_type="ComputedValue")}
|
||||
// min-width, min-height, min-block-size, min-inline-size,
|
||||
// max-width, max-height, max-block-size, max-inline-size
|
||||
${helpers.gecko_size_type("min-%s" % size, "MozLength", "auto()",
|
||||
logical,
|
||||
spec=spec % size,
|
||||
animation_value_type="ComputedValue")}
|
||||
${helpers.gecko_size_type("max-%s" % size, "MaxLength", "none()",
|
||||
logical,
|
||||
spec=spec % size,
|
||||
animation_value_type="ComputedValue")}
|
||||
% else:
|
||||
// servo versions (no keyword support)
|
||||
${helpers.predefined_type("%s" % size,
|
||||
"LengthOrPercentageOrAuto",
|
||||
"computed::LengthOrPercentageOrAuto::Auto",
|
||||
"parse_non_negative",
|
||||
spec=spec % size,
|
||||
allow_quirks=not logical,
|
||||
animation_value_type="ComputedValue", logical = logical)}
|
||||
${helpers.predefined_type("min-%s" % size,
|
||||
"LengthOrPercentage",
|
||||
"computed::LengthOrPercentage::Length(Au(0))",
|
||||
|
@ -78,7 +78,7 @@
|
||||
}
|
||||
}
|
||||
if basis.is_none() {
|
||||
if let Ok(value) = input.try(|input| longhands::flex_basis::parse(context, input)) {
|
||||
if let Ok(value) = input.try(|input| longhands::flex_basis::parse_specified(context, input)) {
|
||||
basis = Some(value);
|
||||
continue
|
||||
}
|
||||
|
@ -606,56 +606,56 @@ pub type LengthOrNumber = Either<Length, Number>;
|
||||
/// Either a computed `<length>` or the `normal` keyword.
|
||||
pub type LengthOrNormal = Either<Length, Normal>;
|
||||
|
||||
/// A value suitable for a `min-width` or `min-height` property.
|
||||
/// A value suitable for a `min-width`, `min-height`, `width` or `height` property.
|
||||
/// See specified/values/length.rs for more details.
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MinLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
Auto,
|
||||
pub enum MozLength {
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::MinLength {
|
||||
type ComputedValue = MinLength;
|
||||
impl MozLength {
|
||||
/// Returns the `auto` value.
|
||||
pub fn auto() -> Self {
|
||||
MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::MozLength {
|
||||
type ComputedValue = MozLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MinLength {
|
||||
fn to_computed_value(&self, context: &Context) -> MozLength {
|
||||
match *self {
|
||||
specified::MinLength::LengthOrPercentage(ref lop) => {
|
||||
MinLength::LengthOrPercentage(lop.to_computed_value(context))
|
||||
specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
|
||||
}
|
||||
specified::MinLength::Auto => {
|
||||
MinLength::Auto
|
||||
}
|
||||
specified::MinLength::ExtremumLength(ref ext) => {
|
||||
MinLength::ExtremumLength(ext.clone())
|
||||
specified::MozLength::ExtremumLength(ref ext) => {
|
||||
MozLength::ExtremumLength(ext.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &MinLength) -> Self {
|
||||
fn from_computed_value(computed: &MozLength) -> Self {
|
||||
match *computed {
|
||||
MinLength::Auto =>
|
||||
specified::MinLength::Auto,
|
||||
MinLength::LengthOrPercentage(ref lop) =>
|
||||
specified::MinLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)),
|
||||
MinLength::ExtremumLength(ref ext) =>
|
||||
specified::MinLength::ExtremumLength(ext.clone()),
|
||||
MozLength::LengthOrPercentageOrAuto(ref lopoa) =>
|
||||
specified::MozLength::LengthOrPercentageOrAuto(
|
||||
specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)),
|
||||
MozLength::ExtremumLength(ref ext) =>
|
||||
specified::MozLength::ExtremumLength(ext.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for MinLength {
|
||||
impl ToCss for MozLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(lop) =>
|
||||
lop.to_css(dest),
|
||||
MinLength::Auto =>
|
||||
dest.write_str("auto"),
|
||||
MinLength::ExtremumLength(ext) =>
|
||||
MozLength::LengthOrPercentageOrAuto(lopoa) =>
|
||||
lopoa.to_css(dest),
|
||||
MozLength::ExtremumLength(ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
}
|
||||
@ -667,22 +667,24 @@ impl ToCss for MinLength {
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
None,
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl MaxLength {
|
||||
/// Returns the `none` value.
|
||||
pub fn none() -> Self {
|
||||
MaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
}
|
||||
impl ToComputedValue for specified::MaxLength {
|
||||
type ComputedValue = MaxLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MaxLength {
|
||||
match *self {
|
||||
specified::MaxLength::LengthOrPercentage(ref lop) => {
|
||||
MaxLength::LengthOrPercentage(lop.to_computed_value(context))
|
||||
}
|
||||
specified::MaxLength::None => {
|
||||
MaxLength::None
|
||||
specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => {
|
||||
MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context))
|
||||
}
|
||||
specified::MaxLength::ExtremumLength(ref ext) => {
|
||||
MaxLength::ExtremumLength(ext.clone())
|
||||
@ -693,10 +695,9 @@ impl ToComputedValue for specified::MaxLength {
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &MaxLength) -> Self {
|
||||
match *computed {
|
||||
MaxLength::None =>
|
||||
specified::MaxLength::None,
|
||||
MaxLength::LengthOrPercentage(ref lop) =>
|
||||
specified::MaxLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)),
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) =>
|
||||
specified::MaxLength::LengthOrPercentageOrNone(
|
||||
specified::LengthOrPercentageOrNone::from_computed_value(&lopon)),
|
||||
MaxLength::ExtremumLength(ref ext) =>
|
||||
specified::MaxLength::ExtremumLength(ext.clone()),
|
||||
}
|
||||
@ -706,10 +707,8 @@ impl ToComputedValue for specified::MaxLength {
|
||||
impl ToCss for MaxLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MaxLength::LengthOrPercentage(lop) =>
|
||||
lop.to_css(dest),
|
||||
MaxLength::None =>
|
||||
dest.write_str("none"),
|
||||
MaxLength::LengthOrPercentageOrNone(lopon) =>
|
||||
lopon.to_css(dest),
|
||||
MaxLength::ExtremumLength(ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ pub use super::specified::{BorderStyle, GridLine, Percentage, UrlOrNone};
|
||||
pub use super::specified::url::SpecifiedUrl;
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
|
||||
pub use self::length::{MaxLength, MinLength};
|
||||
pub use self::length::{MaxLength, MozLength};
|
||||
pub use self::position::Position;
|
||||
|
||||
pub mod basic_shape;
|
||||
|
@ -1183,45 +1183,41 @@ impl LengthOrNumber {
|
||||
}
|
||||
|
||||
/// A value suitable for a `min-width` or `min-height` property.
|
||||
/// Unlike `max-width` or `max-height` properties, a MinLength can be
|
||||
/// Unlike `max-width` or `max-height` properties, a MozLength can be
|
||||
/// `auto`, and cannot be `none`.
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MinLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
Auto,
|
||||
pub enum MozLength {
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl ToCss for MinLength {
|
||||
impl ToCss for MozLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(ref lop) =>
|
||||
lop.to_css(dest),
|
||||
MinLength::Auto =>
|
||||
dest.write_str("auto"),
|
||||
MinLength::ExtremumLength(ref ext) =>
|
||||
MozLength::LengthOrPercentageOrAuto(ref lopoa) =>
|
||||
lopoa.to_css(dest),
|
||||
MozLength::ExtremumLength(ref ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for MinLength {
|
||||
impl Parse for MozLength {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
MinLength::parse_quirky(context, input, AllowQuirks::No)
|
||||
MozLength::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
||||
impl MinLength {
|
||||
impl MozLength {
|
||||
/// Parses, with quirks.
|
||||
pub fn parse_quirky(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ()> {
|
||||
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength)
|
||||
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MinLength::LengthOrPercentage))
|
||||
.or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto))
|
||||
input.try(ExtremumLength::parse).map(MozLength::ExtremumLength)
|
||||
.or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MozLength::LengthOrPercentageOrAuto))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1230,19 +1226,15 @@ impl MinLength {
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
None,
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
|
||||
impl ToCss for MaxLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MaxLength::LengthOrPercentage(ref lop) =>
|
||||
lop.to_css(dest),
|
||||
MaxLength::None =>
|
||||
dest.write_str("none"),
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) =>
|
||||
lopon.to_css(dest),
|
||||
MaxLength::ExtremumLength(ref ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
@ -1261,14 +1253,7 @@ impl MaxLength {
|
||||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ()> {
|
||||
input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
|
||||
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MaxLength::LengthOrPercentage))
|
||||
.or_else(|()| {
|
||||
match_ignore_ascii_case! { &try!(input.expect_ident()),
|
||||
"none" =>
|
||||
Ok(MaxLength::None),
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
.or_else(|()| input.try(|i| LengthOrPercentageOrNone::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MaxLength::LengthOrPercentageOrNone))
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ pub use self::length::AbsoluteLength;
|
||||
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
|
||||
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength};
|
||||
pub use self::length::{MaxLength, MinLength};
|
||||
pub use self::length::{MaxLength, MozLength};
|
||||
pub use self::position::{Position, PositionComponent};
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -1794,15 +1794,18 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations:
|
||||
value: f32) {
|
||||
use style::properties::{PropertyDeclaration, LonghandId};
|
||||
use style::properties::longhands::border_spacing::SpecifiedValue as BorderSpacing;
|
||||
use style::properties::longhands::height::SpecifiedValue as Height;
|
||||
use style::properties::longhands::width::SpecifiedValue as Width;
|
||||
use style::values::specified::BorderWidth;
|
||||
use style::values::specified::MozLength;
|
||||
use style::values::specified::length::{NoCalcLength, LengthOrPercentage};
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
let nocalc = NoCalcLength::from_px(value);
|
||||
|
||||
let prop = match_wrap_declared! { long,
|
||||
Height => nocalc.into(),
|
||||
Width => nocalc.into(),
|
||||
Height => Height(MozLength::LengthOrPercentageOrAuto(nocalc.into())),
|
||||
Width => Width(MozLength::LengthOrPercentageOrAuto(nocalc.into())),
|
||||
BorderTopWidth => BorderWidth::Width(nocalc.into()),
|
||||
BorderRightWidth => BorderWidth::Width(nocalc.into()),
|
||||
BorderBottomWidth => BorderWidth::Width(nocalc.into()),
|
||||
@ -1840,6 +1843,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(declarations:
|
||||
unit: structs::nsCSSUnit) {
|
||||
use style::properties::{PropertyDeclaration, LonghandId};
|
||||
use style::properties::longhands::_moz_script_min_size::SpecifiedValue as MozScriptMinSize;
|
||||
use style::properties::longhands::width::SpecifiedValue as Width;
|
||||
use style::values::specified::MozLength;
|
||||
use style::values::specified::length::{AbsoluteLength, FontRelativeLength, PhysicalLength};
|
||||
use style::values::specified::length::{LengthOrPercentage, NoCalcLength};
|
||||
|
||||
@ -1859,7 +1864,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(declarations:
|
||||
};
|
||||
|
||||
let prop = match_wrap_declared! { long,
|
||||
Width => nocalc.into(),
|
||||
Width => Width(MozLength::LengthOrPercentageOrAuto(nocalc.into())),
|
||||
FontSize => LengthOrPercentage::from(nocalc).into(),
|
||||
MozScriptMinSize => MozScriptMinSize(nocalc),
|
||||
};
|
||||
@ -1894,14 +1899,17 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations:
|
||||
property: nsCSSPropertyID,
|
||||
value: f32) {
|
||||
use style::properties::{PropertyDeclaration, LonghandId};
|
||||
use style::properties::longhands::height::SpecifiedValue as Height;
|
||||
use style::properties::longhands::width::SpecifiedValue as Width;
|
||||
use style::values::specified::MozLength;
|
||||
use style::values::specified::length::{LengthOrPercentage, Percentage};
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
let pc = Percentage(value);
|
||||
|
||||
let prop = match_wrap_declared! { long,
|
||||
Height => pc.into(),
|
||||
Width => pc.into(),
|
||||
Height => Height(MozLength::LengthOrPercentageOrAuto(pc.into())),
|
||||
Width => Width(MozLength::LengthOrPercentageOrAuto(pc.into())),
|
||||
MarginTop => pc.into(),
|
||||
MarginRight => pc.into(),
|
||||
MarginBottom => pc.into(),
|
||||
@ -1918,14 +1926,16 @@ pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations:
|
||||
RawServoDeclarationBlockBorrowed,
|
||||
property: nsCSSPropertyID) {
|
||||
use style::properties::{PropertyDeclaration, LonghandId};
|
||||
use style::properties::longhands::height::SpecifiedValue as Height;
|
||||
use style::properties::longhands::width::SpecifiedValue as Width;
|
||||
use style::values::specified::LengthOrPercentageOrAuto;
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
let auto = LengthOrPercentageOrAuto::Auto;
|
||||
|
||||
let prop = match_wrap_declared! { long,
|
||||
Height => auto,
|
||||
Width => auto,
|
||||
Height => Height::auto(),
|
||||
Width => Width::auto(),
|
||||
MarginTop => auto,
|
||||
MarginRight => auto,
|
||||
MarginBottom => auto,
|
||||
|
Loading…
Reference in New Issue
Block a user