aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-09-05 06:20:33 -0500
committerGitHub <noreply@github.com>2017-09-05 06:20:33 -0500
commit449ffb23acdd0098193458856de88ec4198724fc (patch)
tree337b1e7b0e784e5859d5a7c652e82f9b008b66bb
parente97f28e2a6db24b5cedb7f075fbab2f3a9f62ff2 (diff)
parent3ed71c4283b2a5afb9782ecbe47ba86a89fdde13 (diff)
downloadservo-449ffb23acdd0098193458856de88ec4198724fc.tar.gz
servo-449ffb23acdd0098193458856de88ec4198724fc.zip
Auto merge of #18380 - dadaa:make-font-variation-settings-animatable, r=birtles
Make font-variation-settings animatable <!-- Please describe your changes on the following line: --> https://bugzilla.mozilla.org/show_bug.cgi?id=1390702 r=birtles --- <!-- 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 build-geckolib` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] `./mach test-tidy --stylo` does not report any errors - [X] `./mach test-unit -p style` does not report any errors <!-- Either: --> - [X] There are tests for these changes. The test codes are patch part 4 in https://bugzilla.mozilla.org/show_bug.cgi?id=1390702 <!-- 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/18380) <!-- Reviewable:end -->
-rw-r--r--components/style/properties/gecko.mako.rs157
-rw-r--r--components/style/properties/helpers/animated_properties.mako.rs176
-rw-r--r--components/style/properties/longhand/font.mako.rs3
-rw-r--r--components/style/values/generics/mod.rs1
4 files changed, 243 insertions, 94 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 3eae30f6f9e..de1503ad5fa 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -5,7 +5,7 @@
// `data` comes from components/style/properties.mako.rs; see build.rs for more details.
<%!
- from data import to_rust_ident, to_camel_case
+ from data import to_rust_ident, to_camel_case, to_camel_case_lower
from data import Keyword
%>
<%namespace name="helpers" file="/helpers.mako.rs" />
@@ -1070,6 +1070,67 @@ impl Clone for ${style_struct.gecko_struct_name} {
}
</%def>
+<%def name="impl_font_settings(ident, tag_type)">
+ <%
+ gecko_ffi_name = to_camel_case_lower(ident)
+ %>
+
+ pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
+ use values::generics::FontSettings;
+
+ let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
+ current_settings.clear_pod();
+
+ match v {
+ FontSettings::Normal => (), // do nothing, length is already 0
+
+ FontSettings::Tag(other_settings) => {
+ unsafe { current_settings.set_len_pod(other_settings.len() as u32) };
+
+ for (current, other) in current_settings.iter_mut().zip(other_settings) {
+ current.mTag = other.tag;
+ current.mValue = other.value.0;
+ }
+ }
+ };
+ }
+
+ pub fn copy_${ident}_from(&mut self, other: &Self) {
+ let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
+ let other_settings = &other.gecko.mFont.${gecko_ffi_name};
+ let settings_length = other_settings.len() as u32;
+
+ current_settings.clear_pod();
+ unsafe { current_settings.set_len_pod(settings_length) };
+
+ for (current, other) in current_settings.iter_mut().zip(other_settings.iter()) {
+ current.mTag = other.mTag;
+ current.mValue = other.mValue;
+ }
+ }
+
+ pub fn reset_${ident}(&mut self, other: &Self) {
+ self.copy_${ident}_from(other)
+ }
+
+ pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
+ use values::generics::{FontSettings, FontSettingTag, ${tag_type}} ;
+
+ if self.gecko.mFont.${gecko_ffi_name}.len() == 0 {
+ FontSettings::Normal
+ } else {
+ FontSettings::Tag(
+ self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| {
+ FontSettingTag {
+ tag: gecko_font_setting.mTag,
+ value: ${tag_type}(gecko_font_setting.mValue),
+ }
+ }).collect()
+ )
+ }
+ }
+</%def>
+
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
<%
longhands = [x for x in style_struct.longhands
@@ -2069,98 +2130,8 @@ fn static_assert() {
skip_longhands="${skip_font_longhands}"
skip_additionals="*">
- pub fn set_font_feature_settings(&mut self, v: longhands::font_feature_settings::computed_value::T) {
- use values::generics::FontSettings;
-
- let current_settings = &mut self.gecko.mFont.fontFeatureSettings;
- current_settings.clear_pod();
-
- match v {
- FontSettings::Normal => (), // do nothing, length is already 0
-
- FontSettings::Tag(feature_settings) => {
- unsafe { current_settings.set_len_pod(feature_settings.len() as u32) };
-
- for (current, feature) in current_settings.iter_mut().zip(feature_settings) {
- current.mTag = feature.tag;
- current.mValue = feature.value.0;
- }
- }
- };
- }
-
- pub fn copy_font_feature_settings_from(&mut self, other: &Self) {
- let current_settings = &mut self.gecko.mFont.fontFeatureSettings;
- let feature_settings = &other.gecko.mFont.fontFeatureSettings;
- let settings_length = feature_settings.len() as u32;
-
- current_settings.clear_pod();
- unsafe { current_settings.set_len_pod(settings_length) };
-
- for (current, feature) in current_settings.iter_mut().zip(feature_settings.iter()) {
- current.mTag = feature.mTag;
- current.mValue = feature.mValue;
- }
- }
-
- pub fn reset_font_feature_settings(&mut self, other: &Self) {
- self.copy_font_feature_settings_from(other)
- }
-
- pub fn clone_font_feature_settings(&self) -> longhands::font_feature_settings::computed_value::T {
- use values::generics::{FontSettings, FontSettingTag, FontSettingTagInt} ;
-
- if self.gecko.mFont.fontFeatureSettings.len() == 0 {
- FontSettings::Normal
- } else {
- FontSettings::Tag(
- self.gecko.mFont.fontFeatureSettings.iter().map(|gecko_font_feature_setting| {
- FontSettingTag {
- tag: gecko_font_feature_setting.mTag,
- value: FontSettingTagInt(gecko_font_feature_setting.mValue),
- }
- }).collect()
- )
- }
- }
-
- pub fn set_font_variation_settings(&mut self, v: longhands::font_variation_settings::computed_value::T) {
- use values::generics::FontSettings;
-
- let current_settings = &mut self.gecko.mFont.fontVariationSettings;
- current_settings.clear_pod();
-
- match v {
- FontSettings::Normal => (), // do nothing, length is already 0
-
- FontSettings::Tag(feature_settings) => {
- unsafe { current_settings.set_len_pod(feature_settings.len() as u32) };
-
- for (current, feature) in current_settings.iter_mut().zip(feature_settings) {
- current.mTag = feature.tag;
- current.mValue = feature.value.0;
- }
- }
- };
- }
-
- pub fn copy_font_variation_settings_from(&mut self, other: &Self ) {
- let current_settings = &mut self.gecko.mFont.fontVariationSettings;
- let feature_settings = &other.gecko.mFont.fontVariationSettings;
- let settings_length = feature_settings.len() as u32;
-
- current_settings.clear_pod();
- unsafe { current_settings.set_len_pod(settings_length) };
-
- for (current, feature) in current_settings.iter_mut().zip(feature_settings.iter()) {
- current.mTag = feature.mTag;
- current.mValue = feature.mValue;
- }
- }
-
- pub fn reset_font_variation_settings(&mut self, other: &Self) {
- self.copy_font_variation_settings_from(other)
- }
+ <% impl_font_settings("font_feature_settings", "FontSettingTagInt") %>
+ <% impl_font_settings("font_variation_settings", "FontSettingTagFloat") %>
pub fn fixup_none_generic(&mut self, device: &Device) {
self.gecko.mFont.systemFont = false;
diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs
index 7cf4da4646d..0bbadbf4cba 100644
--- a/components/style/properties/helpers/animated_properties.mako.rs
+++ b/components/style/properties/helpers/animated_properties.mako.rs
@@ -20,6 +20,8 @@ use properties::longhands::background_size::computed_value::T as BackgroundSizeL
use properties::longhands::border_spacing::computed_value::T as BorderSpacing;
use properties::longhands::font_weight::computed_value::T as FontWeight;
use properties::longhands::font_stretch::computed_value::T as FontStretch;
+#[cfg(feature = "gecko")]
+use properties::longhands::font_variation_settings::computed_value::T as FontVariationSettings;
use properties::longhands::line_height::computed_value::T as LineHeight;
use properties::longhands::transform::computed_value::ComputedMatrix;
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
@@ -54,6 +56,9 @@ use values::computed::length::{NonNegativeLengthOrAuto, NonNegativeLengthOrNorma
use values::computed::length::NonNegativeLengthOrPercentage;
use values::computed::transform::DirectionVector;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
+#[cfg(feature = "gecko")] use values::generics::FontSettings as GenericFontSettings;
+#[cfg(feature = "gecko")] use values::generics::FontSettingTag as GenericFontSettingTag;
+#[cfg(feature = "gecko")] use values::generics::FontSettingTagFloat;
use values::generics::NonNegative;
use values::generics::effects::Filter;
use values::generics::position as generic_position;
@@ -915,6 +920,177 @@ impl Into<FontStretch> for f64 {
}
}
+/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
+#[cfg(feature = "gecko")]
+impl Animate for FontVariationSettings {
+ #[inline]
+ fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
+ FontSettingTagIter::new(self, other)?
+ .map(|r| r.and_then(|(st, ot)| st.animate(&ot, procedure)))
+ .collect::<Result<Vec<FontSettingTag>, ()>>()
+ .map(GenericFontSettings::Tag)
+ }
+}
+
+#[cfg(feature = "gecko")]
+impl ComputeSquaredDistance for FontVariationSettings {
+ #[inline]
+ fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
+ FontSettingTagIter::new(self, other)?
+ .map(|r| r.and_then(|(st, ot)| st.compute_squared_distance(&ot)))
+ .sum()
+ }
+}
+
+#[cfg(feature = "gecko")]
+impl ToAnimatedZero for FontVariationSettings {
+ #[inline]
+ fn to_animated_zero(&self) -> Result<Self, ()> {
+ Err(())
+ }
+}
+
+#[cfg(feature = "gecko")]
+impl Animate for FontSettingTag {
+ #[inline]
+ fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
+ if self.tag != other.tag {
+ return Err(());
+ }
+ let value = self.value.animate(&other.value, procedure)?;
+ Ok(FontSettingTag {
+ tag: self.tag,
+ value,
+ })
+ }
+}
+
+#[cfg(feature = "gecko")]
+impl ComputeSquaredDistance for FontSettingTag {
+ #[inline]
+ fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
+ if self.tag != other.tag {
+ return Err(());
+ }
+ self.value.compute_squared_distance(&other.value)
+ }
+}
+
+#[cfg(feature = "gecko")]
+type FontSettingTag = GenericFontSettingTag<FontSettingTagFloat>;
+
+#[cfg(feature = "gecko")]
+struct FontSettingTagIterState<'a> {
+ tags: Vec<(&'a FontSettingTag)>,
+ index: usize,
+ prev_tag: u32,
+}
+
+#[cfg(feature = "gecko")]
+impl<'a> FontSettingTagIterState<'a> {
+ fn new(tags: Vec<(&'a FontSettingTag)>) -> FontSettingTagIterState<'a> {
+ FontSettingTagIterState {
+ index: tags.len(),
+ tags,
+ prev_tag: 0,
+ }
+ }
+}
+
+/// Iterator for font-variation-settings tag lists
+///
+/// [CSS fonts level 4](https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-variation-settings)
+/// defines the animation of font-variation-settings as follows:
+///
+/// Two declarations of font-feature-settings[sic] can be animated between if they are "like".
+/// "Like" declarations are ones where the same set of properties appear (in any order).
+/// Because succesive[sic] duplicate properties are applied instead of prior duplicate
+/// properties, two declarations can be "like" even if they have differing number of
+/// properties. If two declarations are "like" then animation occurs pairwise between
+/// corresponding values in the declarations.
+///
+/// In other words if we have the following lists:
+///
+/// "wght" 1.4, "wdth" 5, "wght" 2
+/// "wdth" 8, "wght" 4, "wdth" 10
+///
+/// We should animate between:
+///
+/// "wdth" 5, "wght" 2
+/// "wght" 4, "wdth" 10
+///
+/// This iterator supports this by sorting the two lists, then iterating them in reverse,
+/// and skipping entries with repeated tag names. It will return Some(Err()) if it reaches the
+/// end of one list before the other, or if the tag names do not match.
+///
+/// For the above example, this iterator would return:
+///
+/// Some(Ok("wght" 2, "wght" 4))
+/// Some(Ok("wdth" 5, "wdth" 10))
+/// None
+///
+#[cfg(feature = "gecko")]
+struct FontSettingTagIter<'a> {
+ a_state: FontSettingTagIterState<'a>,
+ b_state: FontSettingTagIterState<'a>,
+}
+
+#[cfg(feature = "gecko")]
+impl<'a> FontSettingTagIter<'a> {
+ fn new(
+ a_settings: &'a FontVariationSettings,
+ b_settings: &'a FontVariationSettings,
+ ) -> Result<FontSettingTagIter<'a>, ()> {
+ if let (&GenericFontSettings::Tag(ref a_tags), &GenericFontSettings::Tag(ref b_tags)) = (a_settings, b_settings)
+ {
+ fn as_new_sorted_tags(tags: &Vec<FontSettingTag>) -> Vec<(&FontSettingTag)> {
+ use std::iter::FromIterator;
+ let mut sorted_tags: Vec<(&FontSettingTag)> = Vec::from_iter(tags.iter());
+ sorted_tags.sort_by_key(|k| k.tag);
+ sorted_tags
+ };
+
+ Ok(FontSettingTagIter {
+ a_state: FontSettingTagIterState::new(as_new_sorted_tags(a_tags)),
+ b_state: FontSettingTagIterState::new(as_new_sorted_tags(b_tags)),
+ })
+ } else {
+ Err(())
+ }
+ }
+
+ fn next_tag(state: &mut FontSettingTagIterState<'a>) -> Option<(&'a FontSettingTag)> {
+ if state.index == 0 {
+ return None;
+ }
+
+ state.index -= 1;
+ let tag = state.tags[state.index];
+ if tag.tag == state.prev_tag {
+ FontSettingTagIter::next_tag(state)
+ } else {
+ state.prev_tag = tag.tag;
+ Some(tag)
+ }
+ }
+}
+
+#[cfg(feature = "gecko")]
+impl<'a> Iterator for FontSettingTagIter<'a> {
+ type Item = Result<(&'a FontSettingTag, &'a FontSettingTag), ()>;
+
+ fn next(&mut self) -> Option<Result<(&'a FontSettingTag, &'a FontSettingTag), ()>> {
+ match (
+ FontSettingTagIter::next_tag(&mut self.a_state),
+ FontSettingTagIter::next_tag(&mut self.b_state),
+ ) {
+ (Some(at), Some(bt)) if at.tag == bt.tag => Some(Ok((at, bt))),
+ (None, None) => None,
+ _ => Some(Err(())), // Mismatch number of unique tags or tag names.
+ }
+ }
+}
+
impl<H, V> RepeatableListAnimatable for generic_position::Position<H, V>
where H: RepeatableListAnimatable, V: RepeatableListAnimatable {}
diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs
index 9ced9950015..6418a0c8215 100644
--- a/components/style/properties/longhand/font.mako.rs
+++ b/components/style/properties/longhand/font.mako.rs
@@ -1995,7 +1995,8 @@ variation_spec = """\
https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-the-font-variation-settings-property\
"""
%>
-<%helpers:longhand name="font-variation-settings" products="gecko" animation_value_type="none"
+<%helpers:longhand name="font-variation-settings" products="gecko"
+ animation_value_type="ComputedValue"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
spec="${variation_spec}">
use values::computed::ComputedValueAsSpecified;
diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs
index 239b104d49d..ba39c19bd6a 100644
--- a/components/style/values/generics/mod.rs
+++ b/components/style/values/generics/mod.rs
@@ -219,6 +219,7 @@ pub struct FontSettingTagInt(pub u32);
/// because it serializes with the preceding space
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+#[cfg_attr(feature = "gecko", derive(Animate, ComputeSquaredDistance))]
pub struct FontSettingTagFloat(pub f32);
impl ToCss for FontSettingTagInt {