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 702171 ebdf03ef37f2bddde204d03e6a21016a504d565c
parent 702065 4affa6e0a8c622e4c4152872ffc14b73103830ac
child 741399 7e17c3538205e0ed3631bebc9965ddea236edd5e
push id90412
push userxquan@mozilla.com
push dateWed, 22 Nov 2017 21:37:54 +0000
reviewersheycam
bugs1417824
milestone59.0a1
Bug 1417824 - Query theme for attribute change on element with appearance. r?heycam 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();