Bug 1417824 - Query theme for attribute change on element with appearance. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Wed, 22 Nov 2017 15:35:12 -0600
changeset 702172 daa868080b2a940377c79a7cd7ddea8a438779a7
parent 702065 4affa6e0a8c622e4c4152872ffc14b73103830ac
child 741400 788bf9cd37e7bbcd1a3a41f61b165daf3acd8814
push id90413
push userxquan@mozilla.com
push dateWed, 22 Nov 2017 21:42:44 +0000
reviewersheycam
bugs1417824
milestone59.0a1
Bug 1417824 - Query theme for attribute change on element with appearance. r?heycam The change is mostly copied from GeckoRestyleManager::AttributeChanged. It is not clear to me whether it's worth moving it to the superclass so that we don't duplicate the code. If we are removing the Gecko code in short term, it probably doesn't matter. It is also not clear whether we should port other code from that method to ServoRestyleManager. MozReview-Commit-ID: Fd1nbwgLGa1
layout/base/ServoRestyleManager.cpp
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -1443,33 +1443,48 @@ AttributeChangeRequiresSubtreeRestyle(co
 
 void
 ServoRestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
                                       nsAtom* aAttribute, int32_t aModType,
                                       const nsAttrValue* aOldValue)
 {
   MOZ_ASSERT(!mInStyleRefresh);
 
-  if (nsIFrame* primaryFrame = aElement->GetPrimaryFrame()) {
-    primaryFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
-  }
-
   auto changeHint = nsChangeHint(0);
   auto restyleHint = nsRestyleHint(0);
 
   changeHint |= aElement->GetAttributeChangeHint(aAttribute, aModType);
 
   if (aAttribute == nsGkAtoms::style) {
     restyleHint |= eRestyle_StyleAttribute;
   } else if (AttributeChangeRequiresSubtreeRestyle(*aElement, aAttribute)) {
     restyleHint |= eRestyle_Subtree;
   } else if (aElement->IsAttributeMapped(aAttribute)) {
     restyleHint |= eRestyle_Self;
   }
 
+  if (nsIFrame* primaryFrame = aElement->GetPrimaryFrame()) {
+    // See if we have appearance information for a theme.
+    const nsStyleDisplay* disp = primaryFrame->StyleDisplay();
+    if (disp->mAppearance) {
+      nsITheme* theme = PresContext()->GetTheme();
+      if (theme && theme->ThemeSupportsWidget(PresContext(), primaryFrame,
+                                              disp->mAppearance)) {
+        bool repaint = false;
+        theme->WidgetStateChanged(primaryFrame, disp->mAppearance,
+                                  aAttribute, &repaint, aOldValue);
+        if (repaint) {
+          changeHint |= nsChangeHint_RepaintFrame;
+        }
+      }
+    }
+
+    primaryFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
+  }
+
   if (restyleHint || changeHint) {
     Servo_NoteExplicitHints(aElement, restyleHint, changeHint);
   }
 
   if (restyleHint) {
     // Assuming we need to invalidate cached style in getComputedStyle for
     // undisplayed elements, since we don't know if it is needed.
     IncrementUndisplayedRestyleGeneration();