Bug 1097499 part 2 - Add a macro to simplify usage of nsStyleContext::GetUniqueStyleData. r=heycam draft
authorXidorn Quan <quanxunzhen@gmail.com>
Fri, 26 Feb 2016 14:13:56 +0800
changeset 354597 5df302beee6d59745314ee15f8b3f7af191e13d2
parent 354596 c2715281ef6f92b5add2c6dc10d53f45bca4c221
child 354598 4737b1bd505cf0c7963ab98de887f3a4a9b46f26
push id16138
push userxquan@mozilla.com
push dateThu, 21 Apr 2016 11:18:53 +0000
reviewersheycam
bugs1097499
milestone48.0a1
Bug 1097499 part 2 - Add a macro to simplify usage of nsStyleContext::GetUniqueStyleData. r=heycam MozReview-Commit-ID: IS8KUbkXp8m
layout/style/nsStyleContext.cpp
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -634,16 +634,19 @@ ShouldBlockifyChildren(const nsStyleDisp
     NS_STYLE_DISPLAY_INLINE_FLEX == displayVal ||
     NS_STYLE_DISPLAY_GRID == displayVal ||
     NS_STYLE_DISPLAY_INLINE_GRID == displayVal;
 }
 
 void
 nsStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup)
 {
+#define GET_UNIQUE_STYLE_DATA(name_) \
+  static_cast<nsStyle##name_*>(GetUniqueStyleData(eStyleStruct_##name_))
+
   // See if we have any text decorations.
   // First see if our parent has text decorations.  If our parent does, then we inherit the bit.
   if (mParent && mParent->HasTextDecorationLines()) {
     mBits |= NS_STYLE_HAS_TEXT_DECORATION_LINES;
   } else {
     // We might have defined a decoration.
     if (StyleTextReset()->HasTextDecorationLines()) {
       mBits |= NS_STYLE_HAS_TEXT_DECORATION_LINES;
@@ -659,18 +662,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
   if (mPseudoTag == nsCSSAnonBoxes::viewport) {
     nsPresContext* presContext = PresContext();
     mozilla::dom::Element* docElement = presContext->Document()->GetRootElement();
     if (docElement) {
       RefPtr<nsStyleContext> rootStyle =
         presContext->StyleSet()->ResolveStyleFor(docElement, nullptr);
       auto dir = rootStyle->StyleVisibility()->mDirection;
       if (dir != StyleVisibility()->mDirection) {
-        nsStyleVisibility* uniqueVisibility =
-          (nsStyleVisibility*)GetUniqueStyleData(eStyleStruct_Visibility);
+        nsStyleVisibility* uniqueVisibility = GET_UNIQUE_STYLE_DATA(Visibility);
         uniqueVisibility->mDirection = dir;
       }
     }
   }
 
   // Correct tables.
   const nsStyleDisplay* disp = StyleDisplay();
   if (disp->mDisplay == NS_STYLE_DISPLAY_TABLE) {
@@ -678,17 +680,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
     // This is covering the <div align="right"><table>...</table></div> case.
     // In this case, we don't want to inherit the text alignment into the table.
     const nsStyleText* text = StyleText();
 
     if (text->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_LEFT ||
         text->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER ||
         text->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT)
     {
-      nsStyleText* uniqueText = (nsStyleText*)GetUniqueStyleData(eStyleStruct_Text);
+      nsStyleText* uniqueText = GET_UNIQUE_STYLE_DATA(Text);
       uniqueText->mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
     }
   }
 
   // CSS2.1 section 9.2.4 specifies fixups for the 'display' property of
   // the root element.  We can't implement them in nsRuleNode because we
   // don't want to store all display structs that aren't 'block',
   // 'inline', or 'table' in the style context tree on the off chance
@@ -701,18 +703,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
       nsRuleNode::EnsureBlockDisplay(displayVal, true);
     } else {
       // http://dev.w3.org/csswg/css-display/#transformations
       // "... a display-outside of 'contents' computes to block-level
       //  on the root element."
       displayVal = NS_STYLE_DISPLAY_BLOCK;
     }
     if (displayVal != disp->mDisplay) {
-      nsStyleDisplay* mutable_display =
-        static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
+      nsStyleDisplay* mutable_display = GET_UNIQUE_STYLE_DATA(Display);
       disp = mutable_display;
 
       // If we're in this code, then mOriginalDisplay doesn't matter
       // for purposes of the cascade (because this nsStyleDisplay
       // isn't living in the ruletree anyway), and for determining
       // hypothetical boxes it's better to have mOriginalDisplay
       // matching mDisplay here.
       mutable_display->mOriginalDisplay = mutable_display->mDisplay =
@@ -752,18 +753,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
       // anything. So we're OK.
       uint8_t displayVal = disp->mDisplay;
       nsRuleNode::EnsureBlockDisplay(displayVal);
       if (displayVal != disp->mDisplay) {
         NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle(),
                      "We shouldn't be changing the display value of "
                      "positioned content (and we should have already "
                      "converted its display value to be block-level...)");
-        nsStyleDisplay* mutable_display =
-          static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
+        nsStyleDisplay* mutable_display = GET_UNIQUE_STYLE_DATA(Display);
         disp = mutable_display;
         mutable_display->mDisplay = displayVal;
       }
     }
   }
 
   // Set the NS_STYLE_IN_DISPLAY_NONE_SUBTREE bit
   if ((mParent && mParent->IsInDisplayNoneSubtree()) ||
@@ -772,18 +772,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
   }
 
   if (mParent && ::ShouldSuppressLineBreak(this, disp, mParent,
                                            mParent->StyleDisplay())) {
     mBits |= NS_STYLE_SUPPRESS_LINEBREAK;
     uint8_t displayVal = disp->mDisplay;
     nsRuleNode::EnsureInlineDisplay(displayVal);
     if (displayVal != disp->mDisplay) {
-      nsStyleDisplay* mutable_display =
-        static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
+      nsStyleDisplay* mutable_display = GET_UNIQUE_STYLE_DATA(Display);
       disp = mutable_display;
       mutable_display->mDisplay = displayVal;
     }
   }
   // Suppress border/padding of ruby level containers
   if (disp->mDisplay == NS_STYLE_DISPLAY_RUBY_BASE_CONTAINER ||
       disp->mDisplay == NS_STYLE_DISPLAY_RUBY_TEXT_CONTAINER) {
     CreateEmptyStyleData(eStyleStruct_Border);
@@ -797,18 +796,17 @@ nsStyleContext::ApplyStyleFixups(bool aS
     uint8_t unicodeBidi = textReset->mUnicodeBidi;
     if (unicodeBidi == NS_STYLE_UNICODE_BIDI_NORMAL ||
         unicodeBidi == NS_STYLE_UNICODE_BIDI_EMBED) {
       unicodeBidi = NS_STYLE_UNICODE_BIDI_ISOLATE;
     } else if (unicodeBidi == NS_STYLE_UNICODE_BIDI_OVERRIDE) {
       unicodeBidi = NS_STYLE_UNICODE_BIDI_ISOLATE_OVERRIDE;
     }
     if (unicodeBidi != textReset->mUnicodeBidi) {
-      auto mutableTextReset = static_cast<nsStyleTextReset*>(
-        GetUniqueStyleData(eStyleStruct_TextReset));
+      nsStyleTextReset* mutableTextReset = GET_UNIQUE_STYLE_DATA(TextReset);
       mutableTextReset->mUnicodeBidi = unicodeBidi;
     }
   }
 
   /*
    * According to https://drafts.csswg.org/css-writing-modes-3/#block-flow:
    *
    * If a box has a different block flow direction than its containing block:
@@ -823,26 +821,26 @@ nsStyleContext::ApplyStyleFixups(bool aS
     while (cbContext->StyleDisplay()->mDisplay == NS_STYLE_DISPLAY_CONTENTS) {
       cbContext = cbContext->mParent;
     }
     MOZ_ASSERT(cbContext, "the root context can't have display:contents");
     // We don't need the full mozilla::WritingMode value (incorporating dir
     // and text-orientation) here; just the writing-mode property is enough.
     if (StyleVisibility()->mWritingMode !=
           cbContext->StyleVisibility()->mWritingMode) {
-      nsStyleDisplay* mutable_display =
-        static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
+      nsStyleDisplay* mutable_display = GET_UNIQUE_STYLE_DATA(Display);
       disp = mutable_display;
       mutable_display->mOriginalDisplay = mutable_display->mDisplay =
         NS_STYLE_DISPLAY_INLINE_BLOCK;
     }
   }
 
   // Compute User Interface style, to trigger loads of cursors
   StyleUserInterface();
+#undef GET_UNIQUE_STYLE_DATA
 }
 
 nsChangeHint
 nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
                                     nsChangeHint aParentHintsNotHandledForDescendants,
                                     uint32_t* aEqualStructs,
                                     uint32_t* aSamePointerStructs)
 {