Skip to content

Commit

Permalink
Auto merge of #16294 - hiikezoe:make-word-spacing-animatable, r=emilio
Browse files Browse the repository at this point in the history
Make word spacing animatable

<!-- Please describe your changes on the following line: -->
This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1354053

---
<!-- 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

<!-- Either: -->
- [X] There are tests for these changes, a test case will be landed in web-platform-tests in https://bugzilla.mozilla.org/show_bug.cgi?id=1354053

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/16294)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 7, 2017
2 parents c87d0c6 + 933a5d2 commit 1b6c3e0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
24 changes: 19 additions & 5 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -2885,11 +2885,12 @@ fn static_assert() {

pub fn clone_letter_spacing(&self) -> longhands::letter_spacing::computed_value::T {
use properties::longhands::letter_spacing::computed_value::T;
match self.gecko.mLetterSpacing.as_value() {
CoordDataValue::Normal => T(None),
CoordDataValue::Coord(coord) => T(Some(Au(coord))),
_ => unreachable!("Unexpected computed value for letter-spacing"),
}
debug_assert!(
matches!(self.gecko.mLetterSpacing.as_value(),
CoordDataValue::Normal |
CoordDataValue::Coord(_)),
"Unexpected computed value for letter-spacing");
T(Au::from_gecko_style_coord(&self.gecko.mLetterSpacing))
}

<%call expr="impl_coord_copy('letter_spacing', 'mLetterSpacing')"></%call>
Expand All @@ -2902,6 +2903,19 @@ fn static_assert() {
}
}

pub fn clone_word_spacing(&self) -> longhands::word_spacing::computed_value::T {
use properties::longhands::word_spacing::computed_value::T;
use values::computed::LengthOrPercentage;
debug_assert!(
matches!(self.gecko.mWordSpacing.as_value(),
CoordDataValue::Normal |
CoordDataValue::Coord(_) |
CoordDataValue::Percent(_) |
CoordDataValue::Calc(_)),
"Unexpected computed value for word-spacing");
T(LengthOrPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing))
}

<%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"></%call>

fn clear_text_emphasis_style_if_string(&mut self) {
Expand Down
23 changes: 23 additions & 0 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -736,3 +736,26 @@
%>
</%def>

/// Macro for defining Interpolate trait for tuple struct which has Option<T>,
/// e.g. struct T(pub Option<Au>).
<%def name="impl_interpolate_for_option_tuple(value_for_none)">
impl Interpolate for T {
#[inline]
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
match (self, other) {
(&T(Some(ref this)), &T(Some(ref other))) => {
Ok(T(this.interpolate(other, progress).ok()))
},
(&T(Some(ref this)), &T(None)) => {
Ok(T(this.interpolate(&${value_for_none}, progress).ok()))
},
(&T(None), &T(Some(ref other))) => {
Ok(T(${value_for_none}.interpolate(other, progress).ok()))
},
(&T(None), &T(None)) => {
Ok(T(None))
},
}
}
}
</%def>
26 changes: 5 additions & 21 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -445,26 +445,7 @@ ${helpers.single_keyword("text-align-last",
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Au>);

impl Interpolate for T {
#[inline]
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
match (self, other) {
(&T(Some(ref this)), &T(Some(ref other))) => {
Ok(T(this.interpolate(other, progress).ok()))
},
(&T(Some(ref this)), &T(None)) => {
Ok(T(this.interpolate(&Au(0), progress).ok()))
},
(&T(None), &T(Some(ref other))) => {
Ok(T(Au(0).interpolate(other, progress).ok()))
},
(&T(None), &T(None)) => {
Ok(T(None))
},
}
}
}

${helpers.impl_interpolate_for_option_tuple('Au(0)')}
}

impl ToCss for computed_value::T {
Expand Down Expand Up @@ -510,7 +491,7 @@ ${helpers.single_keyword("text-align-last",
}
</%helpers:longhand>

<%helpers:longhand name="word-spacing" animation_type="none"
<%helpers:longhand name="word-spacing" animation_type="normal"
spec="https://drafts.csswg.org/css-text/#propdef-word-spacing">
use std::fmt;
use style_traits::ToCss;
Expand Down Expand Up @@ -542,10 +523,13 @@ ${helpers.single_keyword("text-align-last",
}

pub mod computed_value {
use properties::animated_properties::Interpolate;
use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<LengthOrPercentage>);

${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')}
}

impl ToCss for computed_value::T {
Expand Down

0 comments on commit 1b6c3e0

Please sign in to comment.