Bug 1397434 - Remove the ActiveElementUsesStyle optimization in ActiveElementManager. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Mon, 11 Sep 2017 16:44:52 -0400
changeset 662547 1b7ce6eec77d0260b153bfcd93e81bccb3558107
parent 662474 02c78441c03d5d004e57596a130856861a30188a
child 730907 11b6b693cbd5a8905e8c0941cc47d63403b42acb
push id79123
push userbballo@mozilla.com
push dateMon, 11 Sep 2017 20:45:13 +0000
reviewerskats
bugs1397434
milestone57.0a1
Bug 1397434 - Remove the ActiveElementUsesStyle optimization in ActiveElementManager. r=kats The optimization avoided a 10ms delay in generating synthesized mouse events after a touch tap, if the tapped element wasn't styled differently when in the |:active| state. This dates back to the B2G days when the delay was in the critical path of app startup times. It's less important today, and determining whether the element is styled differently is an expensive operation in the style engine, so we are removing it. MozReview-Commit-ID: FYO1GlCR3gS
gfx/layers/apz/util/APZEventState.cpp
gfx/layers/apz/util/ActiveElementManager.cpp
gfx/layers/apz/util/ActiveElementManager.h
--- a/gfx/layers/apz/util/APZEventState.cpp
+++ b/gfx/layers/apz/util/APZEventState.cpp
@@ -200,26 +200,18 @@ APZEventState::ProcessSingleTap(const CS
     return;
   }
 
   if (mTouchEndCancelled) {
     return;
   }
 
   LayoutDevicePoint ldPoint = aPoint * aScale;
-  if (!mActiveElementManager->ActiveElementUsesStyle()) {
-    // If the active element isn't visually affected by the :active style, we
-    // have no need to wait the extra sActiveDurationMs to make the activation
-    // visually obvious to the user.
-    widget::nsAutoRollup rollup(touchRollup.get());
-    APZCCallbackHelper::FireSingleTapEvent(ldPoint, aModifiers, aClickCount, widget);
-    return;
-  }
 
-  APZES_LOG("Active element uses style, scheduling timer for click event\n");
+  APZES_LOG("Scheduling timer for click event\n");
   nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
   dom::TabChild* tabChild = widget->GetOwningTabChild();
 
   if (tabChild && XRE_IsContentProcess()) {
     timer->SetTarget(
       tabChild->TabGroup()->EventTargetFor(TaskCategory::Other));
   }
   RefPtr<DelayedFireSingleTapEvent> callback =
--- a/gfx/layers/apz/util/ActiveElementManager.cpp
+++ b/gfx/layers/apz/util/ActiveElementManager.cpp
@@ -22,18 +22,17 @@ namespace mozilla {
 namespace layers {
 
 static int32_t sActivationDelayMs = 100;
 static bool sActivationDelayMsSet = false;
 
 ActiveElementManager::ActiveElementManager()
   : mCanBePan(false),
     mCanBePanSet(false),
-    mSetActiveTask(nullptr),
-    mActiveElementUsesStyle(false)
+    mSetActiveTask(nullptr)
 {
   if (!sActivationDelayMsSet) {
     Preferences::AddIntVarCache(&sActivationDelayMs,
                                 "ui.touch_activation.delay_ms",
                                 sActivationDelayMs);
     sActivationDelayMsSet = true;
   }
 }
@@ -137,67 +136,36 @@ ActiveElementManager::HandleTouchEndEven
 
 void
 ActiveElementManager::HandleTouchEnd()
 {
   AEM_LOG("Touch end, clearing pan state\n");
   mCanBePanSet = false;
 }
 
-bool
-ActiveElementManager::ActiveElementUsesStyle() const
-{
-  return mActiveElementUsesStyle;
-}
-
 static nsPresContext*
 GetPresContextFor(nsIContent* aContent)
 {
   if (!aContent) {
     return nullptr;
   }
   nsIPresShell* shell = aContent->OwnerDoc()->GetShell();
   if (!shell) {
     return nullptr;
   }
   return shell->GetPresContext();
 }
 
-static bool
-ElementHasActiveStyle(dom::Element* aElement)
-{
-  nsPresContext* pc = GetPresContextFor(aElement);
-  if (!pc) {
-    return false;
-  }
-  nsStyleSet* styleSet = pc->StyleSet()->GetAsGecko();
-  if (!styleSet) {
-    // Bug 1397434 tracks making this optimization work for stylo.
-    AEM_LOG("Element %p uses Servo style backend, assuming dependence on active state\n", aElement);
-    return true;
-  }
-
-  for (dom::Element* e = aElement; e; e = e->GetParentElement()) {
-    if (styleSet->HasStateDependentStyle(e, NS_EVENT_STATE_ACTIVE)) {
-      AEM_LOG("Element %p's style is dependent on the active state\n", e);
-      return true;
-    }
-  }
-  AEM_LOG("Element %p doesn't use active styles\n", aElement);
-  return false;
-}
-
 void
 ActiveElementManager::SetActive(dom::Element* aTarget)
 {
   AEM_LOG("Setting active %p\n", aTarget);
 
   if (nsPresContext* pc = GetPresContextFor(aTarget)) {
     pc->EventStateManager()->SetContentState(aTarget, NS_EVENT_STATE_ACTIVE);
-    mActiveElementUsesStyle = ElementHasActiveStyle(aTarget);
   }
 }
 
 void
 ActiveElementManager::ResetActive()
 {
   AEM_LOG("Resetting active from %p\n", mTarget.get());
 
--- a/gfx/layers/apz/util/ActiveElementManager.h
+++ b/gfx/layers/apz/util/ActiveElementManager.h
@@ -54,22 +54,16 @@ public:
    * @param aWasClick whether the touch was a click
    */
   void HandleTouchEndEvent(bool aWasClick);
   /**
    * Handle a touch-end state notification from APZ. This notification may be
    * delayed until after touch listeners have responded to the APZ.
    */
   void HandleTouchEnd();
-  /**
-   * @return true iff the currently active element (or one of its ancestors)
-   * actually had a style for the :active pseudo-class. The currently active
-   * element is the root element if no other elements are active.
-   */
-  bool ActiveElementUsesStyle() const;
 private:
   /**
    * The target of the first touch point in the current touch block.
    */
   nsCOMPtr<dom::Element> mTarget;
   /**
    * Whether the current touch block can be a pan. Set in HandleTouchStart().
    */
@@ -79,20 +73,16 @@ private:
    * We need to keep track of this to allow HandleTouchStart() and
    * SetTargetElement() to be called in either order.
    */
   bool mCanBePanSet;
   /**
    * A task for calling SetActive() after a timeout.
    */
   RefPtr<CancelableRunnable> mSetActiveTask;
-  /**
-   * See ActiveElementUsesStyle() documentation.
-   */
-  bool mActiveElementUsesStyle;
 
   // Helpers
   void TriggerElementActivation();
   void SetActive(dom::Element* aTarget);
   void ResetActive();
   void ResetTouchBlockState();
   void SetActiveTask(const nsCOMPtr<dom::Element>& aTarget);
   void CancelTask();