Bug 1567094 - Make GetVisitedDependentColor const-friendly. r=jrmuizel
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 15 Aug 2019 03:01:01 +0000
changeset 488243 32c8752fa896059ea7e18507e36eac8ccb0c5e42
parent 488242 04c2bfb6dbc67dc578f452a3c9b60b930790bb13
child 488244 10439459ebd638a97a6b2caffe4325a51efc36a0
push id113904
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:41:00 +0000
treeherdermozilla-inbound@b283a7ef186c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1567094
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1567094 - Make GetVisitedDependentColor const-friendly. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D41934
layout/style/ComputedStyle.cpp
layout/style/ComputedStyle.h
--- a/layout/style/ComputedStyle.cpp
+++ b/layout/style/ComputedStyle.cpp
@@ -259,24 +259,24 @@ void ComputedStyle::List(FILE* out, int3
     str.Append(nsPrintfCString("%s ", ToString(mPseudoType).c_str()));
   }
 
   fprintf_stderr(out, "%s{ServoComputedData}\n", str.get());
 }
 #endif
 
 template <typename Func>
-static nscolor GetVisitedDependentColorInternal(ComputedStyle* aSc,
+static nscolor GetVisitedDependentColorInternal(const ComputedStyle& aStyle,
                                                 Func aColorFunc) {
   nscolor colors[2];
-  colors[0] = aColorFunc(aSc);
-  if (ComputedStyle* visitedStyle = aSc->GetStyleIfVisited()) {
-    colors[1] = aColorFunc(visitedStyle);
+  colors[0] = aColorFunc(aStyle);
+  if (const ComputedStyle* visitedStyle = aStyle.GetStyleIfVisited()) {
+    colors[1] = aColorFunc(*visitedStyle);
     return ComputedStyle::CombineVisitedColors(colors,
-                                               aSc->RelevantLinkVisited());
+                                               aStyle.RelevantLinkVisited());
   }
   return colors[0];
 }
 
 static nscolor ExtractColor(const ComputedStyle& aStyle,
                             const StyleRGBA& aColor) {
   return aColor.ToColor();
 }
@@ -301,24 +301,24 @@ static nscolor ExtractColor(const Comput
   return aPaintServer.kind.IsColor()
              ? ExtractColor(aStyle, aPaintServer.kind.AsColor())
              : NS_RGBA(0, 0, 0, 0);
 }
 
 #define STYLE_FIELD(struct_, field_) aField == &struct_::field_ ||
 #define STYLE_STRUCT(name_, fields_)                                           \
   template <>                                                                  \
-  nscolor ComputedStyle::GetVisitedDependentColor(                             \
-      decltype(nsStyle##name_::MOZ_ARG_1 fields_) nsStyle##name_::*aField) {   \
+  nscolor ComputedStyle::GetVisitedDependentColor(decltype(                    \
+      nsStyle##name_::MOZ_ARG_1 fields_) nsStyle##name_::*aField) const {      \
     MOZ_ASSERT(MOZ_FOR_EACH(STYLE_FIELD, (nsStyle##name_, ), fields_) false,   \
                "Getting visited-dependent color for a field in nsStyle" #name_ \
                " which is not listed in nsCSSVisitedDependentPropList.h");     \
     return GetVisitedDependentColorInternal(                                   \
-        this, [aField](ComputedStyle* sc) {                                    \
-          return ExtractColor(*sc, sc->Style##name_()->*aField);               \
+        *this, [aField](const ComputedStyle& aStyle) {                         \
+          return ExtractColor(aStyle, aStyle.Style##name_()->*aField);         \
         });                                                                    \
   }
 #include "nsCSSVisitedDependentPropList.h"
 #undef STYLE_STRUCT
 #undef STYLE_FIELD
 
 struct ColorIndexSet {
   uint8_t colorIndex, alphaIndex;
--- a/layout/style/ComputedStyle.h
+++ b/layout/style/ComputedStyle.h
@@ -249,17 +249,17 @@ class ComputedStyle {
    * Get a color that depends on link-visitedness using this and
    * this->GetStyleIfVisited().
    *
    * @param aField A pointer to a member variable in a style struct.
    *               The member variable and its style struct must have
    *               been listed in nsCSSVisitedDependentPropList.h.
    */
   template <typename T, typename S>
-  nscolor GetVisitedDependentColor(T S::*aField);
+  nscolor GetVisitedDependentColor(T S::*aField) const;
 
   /**
    * aColors should be a two element array of nscolor in which the first
    * color is the unvisited color and the second is the visited color.
    *
    * Combine the R, G, and B components of whichever of aColors should
    * be used based on aLinkIsVisited with the A component of aColors[0].
    */