Auto merge of #14394 - jcdyer:jcdyer/either-column-width, r=Wafflespeanut

Convert column-width to use Either

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

* Converted column-width to use `Either<Length, Auto>`
* Added gecko glue code
* Cleaned up old column-width glue code

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14350 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already surround the refactored code.
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/14394)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-01 23:03:37 -08:00 committed by GitHub
commit a913815a4d
8 changed files with 38 additions and 97 deletions

View file

@ -493,6 +493,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
# Types used with predefined_type()-defined properties that we can auto-generate.
predefined_types = {
"length::LengthOrAuto": impl_style_coord,
"Length": impl_style_coord,
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
@ -2350,16 +2351,7 @@ clip-path
</%self:impl_trait>
<%self:impl_trait style_struct_name="Column"
skip_longhands="column-width column-count column-gap -moz-column-rule-width">
pub fn set_column_width(&mut self, v: longhands::column_width::computed_value::T) {
match v.0 {
Some(au) => self.gecko.mColumnWidth.set(au),
None => self.gecko.mColumnWidth.set_value(CoordDataValue::Auto),
}
}
${impl_coord_copy('column_width', 'mColumnWidth')}
skip_longhands="column-count column-gap -moz-column-rule-width">
#[allow(unused_unsafe)]
pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {

View file

@ -7,86 +7,13 @@
<% data.new_style_struct("Column", inherited=False) %>
// FIXME: This prop should be animatable.
<%helpers:longhand name="column-width" experimental="True" animatable="False">
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
${helpers.predefined_type("column-width",
"length::LengthOrAuto",
"Either::Second(Auto)",
parse_method="parse_non_negative_length",
animatable=False,
experimental=True)}
impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool {
match *self {
SpecifiedValue::Specified(length) => length.has_viewport_percentage(),
_ => false
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Auto,
Specified(specified::Length),
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Auto => dest.write_str("auto"),
SpecifiedValue::Specified(l) => l.to_css(dest),
}
}
}
pub mod computed_value {
use app_units::Au;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Au>);
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self.0 {
None => dest.write_str("auto"),
Some(l) => l.to_css(dest),
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(None)
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::Auto => computed_value::T(None),
SpecifiedValue::Specified(l) =>
computed_value::T(Some(l.to_computed_value(context)))
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
computed_value::T(None) => SpecifiedValue::Auto,
computed_value::T(Some(l)) =>
SpecifiedValue::Specified(ToComputedValue::from_computed_value(&l))
}
}
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
Ok(SpecifiedValue::Auto)
} else {
specified::Length::parse_non_negative(input).map(SpecifiedValue::Specified)
}
}
</%helpers:longhand>
// FIXME: This prop should be animatable.
<%helpers:longhand name="column-count" experimental="True" animatable="False">

View file

@ -1145,7 +1145,10 @@ impl ComputedValues {
#[inline]
pub fn is_multicol(&self) -> bool {
let style = self.get_column();
style.column_count.0.is_some() || style.column_width.0.is_some()
match style.column_width {
Either::First(_width) => true,
Either::Second(_auto) => style.column_count.0.is_some(),
}
}
/// Resolves the currentColor keyword.