Bug 1334330 - Part 9: stylo: Use GenericSpecifiedValue abstraction for <hr>; r?emilio draft
authorManish Goregaokar <manishearth@gmail.com>
Thu, 26 Jan 2017 16:51:01 -0800
changeset 480664 89debdadc27470674fc910ff91bf8e72db05ab9f
parent 480663 9722e0276e4f8c470622df139807ba76474ed11a
child 480665 bdf7251100c9455bd23bd7eb3337f21106c35dcb
push id44619
push userbmo:manishearth@gmail.com
push dateWed, 08 Feb 2017 19:34:01 +0000
reviewersemilio
bugs1334330
milestone54.0a1
Bug 1334330 - Part 9: stylo: Use GenericSpecifiedValue abstraction for <hr>; r?emilio MozReview-Commit-ID: CvKYf9To9mD
dom/html/HTMLHRElement.cpp
--- a/dom/html/HTMLHRElement.cpp
+++ b/dom/html/HTMLHRElement.cpp
@@ -62,94 +62,75 @@ HTMLHRElement::ParseAttribute(int32_t aN
   }
 
   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
                                               aResult);
 }
 
 void
 HTMLHRElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
-                                     GenericSpecifiedValues* aGenericData)
+                                     GenericSpecifiedValues* aData)
 {
-  nsRuleData* aData = aGenericData->AsRuleData();
   bool noshade = false;
 
   const nsAttrValue* colorValue = aAttributes->GetAttr(nsGkAtoms::color);
   nscolor color;
   bool colorIsSet = colorValue && colorValue->GetColorValue(color);
 
-  if (aData->mSIDs & (NS_STYLE_INHERIT_BIT(Position) |
-                      NS_STYLE_INHERIT_BIT(Border))) {
+  if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position) |
+                                      NS_STYLE_INHERIT_BIT(Border))) {
     if (colorIsSet) {
       noshade = true;
     } else {
       noshade = !!aAttributes->GetAttr(nsGkAtoms::noshade);
     }
   }
 
-  if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) {
+  if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Margin))) {
     // align: enum
     const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
     if (value && value->Type() == nsAttrValue::eEnum) {
       // Map align attribute into auto side margins
-      nsCSSValue* marginLeft = aData->ValueForMarginLeft();
-      nsCSSValue* marginRight = aData->ValueForMarginRight();
       switch (value->GetEnumValue()) {
       case NS_STYLE_TEXT_ALIGN_LEFT:
-        if (marginLeft->GetUnit() == eCSSUnit_Null)
-          marginLeft->SetFloatValue(0.0f, eCSSUnit_Pixel);
-        if (marginRight->GetUnit() == eCSSUnit_Null)
-          marginRight->SetAutoValue();
+        aData->SetPixelValueIfUnset(eCSSProperty_margin_left, 0.0f);
+        aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
         break;
       case NS_STYLE_TEXT_ALIGN_RIGHT:
-        if (marginLeft->GetUnit() == eCSSUnit_Null)
-          marginLeft->SetAutoValue();
-        if (marginRight->GetUnit() == eCSSUnit_Null)
-          marginRight->SetFloatValue(0.0f, eCSSUnit_Pixel);
+        aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
+        aData->SetPixelValueIfUnset(eCSSProperty_margin_right, 0.0f);
         break;
       case NS_STYLE_TEXT_ALIGN_CENTER:
-        if (marginLeft->GetUnit() == eCSSUnit_Null)
-          marginLeft->SetAutoValue();
-        if (marginRight->GetUnit() == eCSSUnit_Null)
-          marginRight->SetAutoValue();
+        aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
+        aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
         break;
       }
     }
   }
-  if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
-    // width: integer, percent
-    nsCSSValue* width = aData->ValueForWidth();
-    if (width->GetUnit() == eCSSUnit_Null) {
-      const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
-      if (value && value->Type() == nsAttrValue::eInteger) {
-        width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
-      } else if (value && value->Type() == nsAttrValue::ePercent) {
-        width->SetPercentValue(value->GetPercentValue());
-      }
-    }
-
-    nsCSSValue* height = aData->ValueForHeight();
-    if (height->GetUnit() == eCSSUnit_Null) {
+  if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position))) {
+    if (!aData->PropertyIsSet(eCSSProperty_height)) {
       // size: integer
       if (noshade) {
         // noshade case: size is set using the border
-        height->SetAutoValue();
+        aData->SetAutoValue(eCSSProperty_height);
       } else {
         // normal case
         // the height includes the top and bottom borders that are initially 1px.
         // for size=1, html.css has a special case rule that makes this work by
         // removing all but the top border.
         const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
         if (value && value->Type() == nsAttrValue::eInteger) {
-          height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
+          aData->SetPixelValue(eCSSProperty_height, (float)value->GetIntegerValue());
         } // else use default value from html.css
       }
     }
   }
-  if ((aData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) && noshade) { // if not noshade, border styles are dealt with by html.css
+
+  // if not noshade, border styles are dealt with by html.css
+  if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border)) && noshade) {
     // size: integer
     // if a size is set, use half of it per side, otherwise, use 1px per side
     float sizePerSide;
     bool allSides = true;
     const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
     if (value && value->Type() == nsAttrValue::eInteger) {
       sizePerSide = (float)value->GetIntegerValue() / 2.0f;
       if (sizePerSide < 1.0f) {
@@ -157,83 +138,56 @@ HTMLHRElement::MapAttributesIntoRule(con
         // subpixel borders should be removed.
         // In the meantime, this makes http://www.microsoft.com/ look right.
         sizePerSide = 1.0f;
         allSides = false;
       }
     } else {
       sizePerSide = 1.0f; // default to a 2px high line
     }
-    nsCSSValue* borderTopWidth = aData->ValueForBorderTopWidth();
-    if (borderTopWidth->GetUnit() == eCSSUnit_Null) {
-      borderTopWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
-    }
+    aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, sizePerSide);
     if (allSides) {
-      nsCSSValue* borderRightWidth = aData->ValueForBorderRightWidth();
-      if (borderRightWidth->GetUnit() == eCSSUnit_Null) {
-        borderRightWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
-      }
-      nsCSSValue* borderBottomWidth = aData->ValueForBorderBottomWidth();
-      if (borderBottomWidth->GetUnit() == eCSSUnit_Null) {
-        borderBottomWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
-      }
-      nsCSSValue* borderLeftWidth = aData->ValueForBorderLeftWidth();
-      if (borderLeftWidth->GetUnit() == eCSSUnit_Null) {
-        borderLeftWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
-      }
+      aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, sizePerSide);
+      aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, sizePerSide);
+      aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, sizePerSide);
     }
 
-    nsCSSValue* borderTopStyle = aData->ValueForBorderTopStyle();
-    if (borderTopStyle->GetUnit() == eCSSUnit_Null) {
-      borderTopStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
-                                  eCSSUnit_Enumerated);
-    }
+    if (!aData->PropertyIsSet(eCSSProperty_border_top_style))
+      aData->SetKeywordValue(eCSSProperty_border_top_style,
+                             NS_STYLE_BORDER_STYLE_SOLID);
     if (allSides) {
-      nsCSSValue* borderRightStyle = aData->ValueForBorderRightStyle();
-      if (borderRightStyle->GetUnit() == eCSSUnit_Null) {
-        borderRightStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
-                                      eCSSUnit_Enumerated);
-      }
-      nsCSSValue* borderBottomStyle = aData->ValueForBorderBottomStyle();
-      if (borderBottomStyle->GetUnit() == eCSSUnit_Null) {
-        borderBottomStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
-                                       eCSSUnit_Enumerated);
-      }
-      nsCSSValue* borderLeftStyle = aData->ValueForBorderLeftStyle();
-      if (borderLeftStyle->GetUnit() == eCSSUnit_Null) {
-        borderLeftStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
-                                     eCSSUnit_Enumerated);
-      }
+      aData->SetKeywordValueIfUnset(eCSSProperty_border_right_style,
+                                    NS_STYLE_BORDER_STYLE_SOLID);
+      aData->SetKeywordValueIfUnset(eCSSProperty_border_bottom_style,
+                                    NS_STYLE_BORDER_STYLE_SOLID);
+      aData->SetKeywordValueIfUnset(eCSSProperty_border_left_style,
+                                    NS_STYLE_BORDER_STYLE_SOLID);
 
       // If it would be noticeable, set the border radius to
       // 10000px on all corners; this triggers the clamping to make
       // circular ends.  This assumes the <hr> isn't larger than
       // that in *both* dimensions.
       for (const nsCSSPropertyID* props =
             nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_radius);
            *props != eCSSProperty_UNKNOWN; ++props) {
-        nsCSSValue* dimen = aData->ValueFor(*props);
-        if (dimen->GetUnit() == eCSSUnit_Null) {
-          dimen->SetFloatValue(10000.0f, eCSSUnit_Pixel);
-        }
+        aData->SetPixelValueIfUnset(*props, 10000.0f);
       }
     }
   }
-  if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
+  if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Color))) {
     // color: a color
     // (we got the color attribute earlier)
-    nsCSSValue* colorValue = aData->ValueForColor();
     if (colorIsSet &&
-        colorValue->GetUnit() == eCSSUnit_Null &&
-        aData->mPresContext->UseDocumentColors()) {
-      colorValue->SetColorValue(color);
+        aData->PresContext()->UseDocumentColors()) {
+      aData->SetColorValueIfUnset(eCSSProperty_color, color);
     }
   }
 
-  nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aGenericData);
+  nsGenericHTMLElement::MapWidthAttributeInto(aAttributes, aData);
+  nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
 }
 
 NS_IMETHODIMP_(bool)
 HTMLHRElement::IsAttributeMapped(const nsIAtom* aAttribute) const
 {
   static const MappedAttributeEntry attributes[] = {
     { &nsGkAtoms::align },
     { &nsGkAtoms::width },