Bug 1303241 part 1 - Move visited-dependent style fields into a list file. r=dbaron draft
authorXidorn Quan <me@upsuper.org>
Thu, 05 Jan 2017 11:22:36 +1100
changeset 456099 0225be937ea2706ec43f56211550b966859afc8c
parent 455179 24f14c72eaa7c4923971be91f05f5c10f0443086
child 456100 8925ae4b2f6eef99023a0e2ea8c84084ebd7e39e
child 456102 8a11879bb4a702e4982565901bd3c53993a704d4
child 456106 ac80eaea2474b9ec4b47b1cc9a5bdd2e61f6ec4d
push id40397
push userxquan@mozilla.com
push dateThu, 05 Jan 2017 00:24:05 +0000
reviewersdbaron
bugs1303241
milestone53.0a1
Bug 1303241 part 1 - Move visited-dependent style fields into a list file. r=dbaron MozReview-Commit-ID: K4kc8ByNGoT
layout/style/nsCSSVisitedDependentPropList.h
layout/style/nsStyleContext.cpp
new file mode 100644
--- /dev/null
+++ b/layout/style/nsCSSVisitedDependentPropList.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* a list of style struct's member variables which can be visited-dependent */
+
+/* This file contains the list of all style structs and fields that can
+ * be visited-dependent. Each entry is defined as a STYLE_STRUCT macro
+ * with the following parameters:
+ * - 'name_' the name of the style struct
+ * - 'fields_' the list of member variables in the style struct that can
+ *   be visited-dependent
+ *
+ * Users of this list should define a macro STYLE_STRUCT(name_, fields_)
+ * before including this file.
+ *
+ * Note that, currently, there is a restriction that all fields in a
+ * style struct must have the same type.
+ */
+
+STYLE_STRUCT(Color, (mColor))
+STYLE_STRUCT(Background, (mBackgroundColor))
+STYLE_STRUCT(Border, (mBorderTopColor,
+                      mBorderRightColor,
+                      mBorderBottomColor,
+                      mBorderLeftColor))
+STYLE_STRUCT(Outline, (mOutlineColor))
+STYLE_STRUCT(Column, (mColumnRuleColor))
+STYLE_STRUCT(Text, (mTextEmphasisColor,
+                    mWebkitTextFillColor,
+                    mWebkitTextStrokeColor))
+STYLE_STRUCT(TextReset, (mTextDecorationColor))
+STYLE_STRUCT(SVG, (mFill, mStroke))
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -1164,92 +1164,28 @@ nsStyleContext::CalcStyleDifferenceInter
     // Both style contexts have a style-if-visited.
     bool change = false;
 
     // NB: Calling Peek on |this|, not |thisVis|, since callers may look
     // at a struct on |this| without looking at the same struct on
     // |thisVis| (including this function if we skip one of these checks
     // due to change being true already or due to the old style context
     // not having a style-if-visited), but not the other way around.
-    if (PeekStyleColor()) {
-      if (thisVis->StyleColor()->mColor !=
-          otherVis->StyleColor()->mColor) {
-        change = true;
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleBackground()) {
-      if (thisVis->StyleBackground()->mBackgroundColor !=
-          otherVis->StyleBackground()->mBackgroundColor) {
-        change = true;
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleBorder()) {
-      const nsStyleBorder *thisVisBorder = thisVis->StyleBorder();
-      const nsStyleBorder *otherVisBorder = otherVis->StyleBorder();
-      NS_FOR_CSS_SIDES(side) {
-        if (thisVisBorder->mBorderColor[side] !=
-            otherVisBorder->mBorderColor[side]) {
-          change = true;
-          break;
-        }
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleOutline()) {
-      const nsStyleOutline *thisVisOutline = thisVis->StyleOutline();
-      const nsStyleOutline *otherVisOutline = otherVis->StyleOutline();
-      if (thisVisOutline->mOutlineColor != otherVisOutline->mOutlineColor) {
-        change = true;
-      }
+#define STYLE_FIELD(name_) thisVisStruct->name_ != otherVisStruct->name_ ||
+#define STYLE_STRUCT(name_, fields_)                                    \
+    if (!change && PeekStyle##name_()) {                                \
+      const nsStyle##name_* thisVisStruct = thisVis->Style##name_();    \
+      const nsStyle##name_* otherVisStruct = otherVis->Style##name_();  \
+      if (MOZ_FOR_EACH(STYLE_FIELD, (), fields_) false) {               \
+        change = true;                                                  \
+      }                                                                 \
     }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleColumn()) {
-      const nsStyleColumn *thisVisColumn = thisVis->StyleColumn();
-      const nsStyleColumn *otherVisColumn = otherVis->StyleColumn();
-      if (thisVisColumn->mColumnRuleColor != otherVisColumn->mColumnRuleColor) {
-        change = true;
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleText()) {
-      const nsStyleText* thisVisText = thisVis->StyleText();
-      const nsStyleText* otherVisText = otherVis->StyleText();
-      if (thisVisText->mTextEmphasisColor != otherVisText->mTextEmphasisColor ||
-          thisVisText->mWebkitTextFillColor != otherVisText->mWebkitTextFillColor ||
-          thisVisText->mWebkitTextStrokeColor != otherVisText->mWebkitTextStrokeColor) {
-        change = true;
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleTextReset()) {
-      const nsStyleTextReset *thisVisTextReset = thisVis->StyleTextReset();
-      const nsStyleTextReset *otherVisTextReset = otherVis->StyleTextReset();
-      if (thisVisTextReset->mTextDecorationColor !=
-          otherVisTextReset->mTextDecorationColor) {
-        change = true;
-      }
-    }
-
-    // NB: Calling Peek on |this|, not |thisVis| (see above).
-    if (!change && PeekStyleSVG()) {
-      const nsStyleSVG *thisVisSVG = thisVis->StyleSVG();
-      const nsStyleSVG *otherVisSVG = otherVis->StyleSVG();
-      if (thisVisSVG->mFill != otherVisSVG->mFill ||
-          thisVisSVG->mStroke != otherVisSVG->mStroke) {
-        change = true;
-      }
-    }
+#include "nsCSSVisitedDependentPropList.h"
+#undef STYLE_STRUCT
+#undef STYLE_FIELD
 
     if (change) {
       hint |= nsChangeHint_RepaintFrame;
     }
   }
 
   if (hint & nsChangeHint_UpdateContainingBlock) {
     // If a struct returned nsChangeHint_UpdateContainingBlock, that