Bug 1468651: Make StyleStruct.name_lower snake case. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 19 Jun 2018 13:19:41 +0200
changeset 808379 2d4e1d82437f8f074d55271f91e2d0b76f0a8483
parent 808375 6299fe8c9c5cbc50863f8456a225b7b7bee9909d
child 808380 71df9d7aae877b2797b5b0f2a1e2eaee9c713f41
push id113372
push userbmo:emilio@crisal.io
push dateTue, 19 Jun 2018 11:45:29 +0000
reviewersheycam
bugs1468651
milestone62.0a1
Bug 1468651: Make StyleStruct.name_lower snake case. r?heycam MozReview-Commit-ID: A3TpDTmFgF
servo/components/style/properties/data.py
servo/components/style/properties/properties.mako.rs
servo/components/style/style_adjuster.rs
servo/components/style/values/computed/text.rs
servo/components/style/values/specified/text.rs
servo/tests/unit/style/lib.rs
--- a/servo/components/style/properties/data.py
+++ b/servo/components/style/properties/data.py
@@ -33,16 +33,20 @@ def maybe_moz_logical_alias(product, sid
 
 def to_rust_ident(name):
     name = name.replace("-", "_")
     if name in ["static", "super", "box", "move"]:  # Rust keywords
         name += "_"
     return name
 
 
+def to_snake_case(ident):
+    return re.sub("([A-Z]+)", lambda m: "_" + m.group(1).lower(), ident).strip("_")
+
+
 def to_camel_case(ident):
     return re.sub("(^|_|-)([a-z0-9])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))
 
 
 def to_camel_case_lower(ident):
     camel = to_camel_case(ident)
     return camel[0].lower() + camel[1:]
 
@@ -446,17 +450,17 @@ class Method(object):
     def stub(self):
         return self.signature() + "{ unimplemented!() }"
 
 
 class StyleStruct(object):
     def __init__(self, name, inherited, gecko_name=None, additional_methods=None):
         self.gecko_struct_name = "Gecko" + name
         self.name = name
-        self.name_lower = name.lower()
+        self.name_lower = to_snake_case(name)
         self.ident = to_rust_ident(self.name_lower)
         self.longhands = []
         self.inherited = inherited
         self.gecko_name = gecko_name or name
         self.gecko_ffi_name = "nsStyle" + self.gecko_name
         self.additional_methods = additional_methods or []
 
 
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -3872,17 +3872,17 @@ where
                 }
             % endif
 
             let discriminant = longhand_id as usize;
             (CASCADE_PROPERTY[discriminant])(&*declaration, &mut context);
         }
         % if category_to_cascade_now == "early":
             let writing_mode =
-                WritingMode::new(context.builder.get_inheritedbox());
+                WritingMode::new(context.builder.get_inherited_box());
             context.builder.writing_mode = writing_mode;
 
             let mut _skip_font_family = false;
 
             % if product == "gecko":
 
                 // <svg:text> is not affected by text zoom, and it uses a preshint to
                 // disable it. We fix up the struct when this happens by unzooming
--- a/servo/components/style/style_adjuster.rs
+++ b/servo/components/style/style_adjuster.rs
@@ -243,27 +243,27 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     ///
     /// FIXME(emilio): How does this play with logical properties? Doesn't
     /// mutating writing-mode change the potential physical sides chosen?
     #[cfg(feature = "gecko")]
     fn adjust_for_text_combine_upright(&mut self) {
         use computed_values::text_combine_upright::T as TextCombineUpright;
         use computed_values::writing_mode::T as WritingMode;
 
-        let writing_mode = self.style.get_inheritedbox().clone_writing_mode();
-        let text_combine_upright = self.style.get_inheritedtext().clone_text_combine_upright();
+        let writing_mode = self.style.get_inherited_box().clone_writing_mode();
+        let text_combine_upright = self.style.get_inherited_text().clone_text_combine_upright();
 
         if writing_mode != WritingMode::HorizontalTb &&
             text_combine_upright == TextCombineUpright::All
         {
             self.style
                 .flags
                 .insert(ComputedValueFlags::IS_TEXT_COMBINED);
             self.style
-                .mutate_inheritedbox()
+                .mutate_inherited_box()
                 .set_writing_mode(WritingMode::HorizontalTb);
         }
     }
 
     /// Unconditionally propagates the line break suppression flag to text, and
     /// additionally it applies it if it is in any ruby box.
     ///
     /// This is necessary because its parent may not itself have the flag set
@@ -292,18 +292,18 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     ///          computes to inline-block. [CSS21]
     ///
     /// This matches the adjustment that Gecko does, not exactly following
     /// the spec. See also:
     ///
     /// <https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html>
     /// <https://github.com/servo/servo/issues/15754>
     fn adjust_for_writing_mode(&mut self, layout_parent_style: &ComputedValues) {
-        let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode();
-        let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode();
+        let our_writing_mode = self.style.get_inherited_box().clone_writing_mode();
+        let parent_writing_mode = layout_parent_style.get_inherited_box().clone_writing_mode();
 
         if our_writing_mode != parent_writing_mode &&
             self.style.get_box().clone_display() == Display::Inline
         {
             // TODO(emilio): Figure out if we can just set the adjusted display
             // on Gecko too and unify this code path.
             if cfg!(feature = "servo") {
                 self.style
@@ -483,38 +483,38 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
     /// table.
     #[cfg(feature = "gecko")]
     fn adjust_for_table_text_align(&mut self) {
         use properties::longhands::text_align::computed_value::T as TextAlign;
         if self.style.get_box().clone_display() != Display::Table {
             return;
         }
 
-        match self.style.get_inheritedtext().clone_text_align() {
+        match self.style.get_inherited_text().clone_text_align() {
             TextAlign::MozLeft | TextAlign::MozCenter | TextAlign::MozRight => {},
             _ => return,
         }
 
         self.style
-            .mutate_inheritedtext()
+            .mutate_inherited_text()
             .set_text_align(TextAlign::Start)
     }
 
     /// Computes the used text decoration for Servo.
     ///
     /// FIXME(emilio): This is a layout tree concept, should move away from
     /// style, since otherwise we're going to have the same subtle bugs WebKit
     /// and Blink have with this very same thing.
     #[cfg(feature = "servo")]
     fn adjust_for_text_decorations_in_effect(&mut self) {
         use values::computed::text::TextDecorationsInEffect;
 
         let decorations_in_effect = TextDecorationsInEffect::from_style(&self.style);
-        if self.style.get_inheritedtext().text_decorations_in_effect != decorations_in_effect {
-            self.style.mutate_inheritedtext().text_decorations_in_effect = decorations_in_effect;
+        if self.style.get_inherited_text().text_decorations_in_effect != decorations_in_effect {
+            self.style.mutate_inherited_text().text_decorations_in_effect = decorations_in_effect;
         }
     }
 
     #[cfg(feature = "gecko")]
     fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool {
         // Line break suppression should only be propagated to in-flow children.
         if self.style.floated() || self.style.out_of_flow_positioned() {
             return false;
--- a/servo/components/style/values/computed/text.rs
+++ b/servo/components/style/values/computed/text.rs
@@ -102,17 +102,17 @@ impl TextDecorationsInEffect {
         use values::computed::Display;
 
         // Start with no declarations if this is an atomic inline-level box;
         // otherwise, start with the declarations in effect and add in the text
         // decorations that this block specifies.
         let mut result = match style.get_box().clone_display() {
             Display::InlineBlock | Display::InlineTable => Self::default(),
             _ => style
-                .get_parent_inheritedtext()
+                .get_parent_inherited_text()
                 .text_decorations_in_effect
                 .clone(),
         };
 
         let text_style = style.get_text();
 
         result.underline |= text_style.has_underline();
         result.overline |= text_style.has_overline();
--- a/servo/components/style/values/specified/text.rs
+++ b/servo/components/style/values/specified/text.rs
@@ -509,32 +509,32 @@ impl ToComputedValue for TextAlign {
                 // In that case, the default behavior here will set it to left,
                 // but we want to set it to right -- instead set it to the default (`start`),
                 // which will do the right thing in this case (but not the general case)
                 if _context.is_root_element {
                     return TextAlignKeyword::start();
                 }
                 let parent = _context
                     .builder
-                    .get_parent_inheritedtext()
+                    .get_parent_inherited_text()
                     .clone_text_align();
                 let ltr = _context.builder.inherited_writing_mode().is_bidi_ltr();
                 match (parent, ltr) {
                     (TextAlignKeyword::Start, true) => TextAlignKeyword::Left,
                     (TextAlignKeyword::Start, false) => TextAlignKeyword::Right,
                     (TextAlignKeyword::End, true) => TextAlignKeyword::Right,
                     (TextAlignKeyword::End, false) => TextAlignKeyword::Left,
                     _ => parent,
                 }
             },
             #[cfg(feature = "gecko")]
             TextAlign::MozCenterOrInherit => {
                 let parent = _context
                     .builder
-                    .get_parent_inheritedtext()
+                    .get_parent_inherited_text()
                     .clone_text_align();
                 if parent == TextAlignKeyword::Start {
                     TextAlignKeyword::Center
                 } else {
                     parent
                 }
             },
         }
@@ -648,17 +648,17 @@ impl TextEmphasisShapeKeyword {
 
 impl ToComputedValue for TextEmphasisStyle {
     type ComputedValue = ComputedTextEmphasisStyle;
 
     #[inline]
     fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
         match *self {
             TextEmphasisStyle::Keyword(ref keyword) => {
-                let default_shape = if context.style().get_inheritedbox().clone_writing_mode() ==
+                let default_shape = if context.style().get_inherited_box().clone_writing_mode() ==
                     SpecifiedWritingMode::HorizontalTb
                 {
                     TextEmphasisShapeKeyword::Circle
                 } else {
                     TextEmphasisShapeKeyword::Sesame
                 };
                 ComputedTextEmphasisStyle::Keyword(ComputedTextEmphasisKeywordValue {
                     fill: keyword.fill().unwrap_or(TextEmphasisFillMode::Filled),
--- a/servo/tests/unit/style/lib.rs
+++ b/servo/tests/unit/style/lib.rs
@@ -33,21 +33,8 @@ mod properties;
 mod rule_tree;
 mod size_of;
 #[path = "../../../ports/geckolib/tests/specified_values.rs"]
 mod specified_values;
 mod str;
 mod stylesheets;
 mod stylist;
 mod viewport;
-
-mod writing_modes {
-    use style::logical_geometry::WritingMode;
-    use style::properties::INITIAL_SERVO_VALUES;
-
-    #[test]
-    fn initial_writing_mode_is_empty() {
-        assert_eq!(
-            WritingMode::new(INITIAL_SERVO_VALUES.get_inheritedbox()),
-            WritingMode::empty(),
-        )
-    }
-}