Bug 1162771 - Encapsulate the gCaptureTouchList so that it's not exposed outside of the TouchManager class. r=smaug
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 18 Aug 2016 07:13:28 -0400
changeset 310095 47b7bf339876337b4b9d4ccb292b81d466c0d92d
parent 310094 7d3e8cea2291576c15ce3aca91b2161dfa8941d3
child 310096 e2eed81cdcffe3157070b070e03c20d1c2468710
push id30576
push userryanvm@gmail.com
push dateFri, 19 Aug 2016 13:53:39 +0000
treeherdermozilla-central@74f332c38a69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1162771
milestone51.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 1162771 - Encapsulate the gCaptureTouchList so that it's not exposed outside of the TouchManager class. r=smaug MozReview-Commit-ID: FkaJxTvJOzQ
layout/base/TouchManager.cpp
layout/base/TouchManager.h
layout/base/nsPresShell.cpp
--- a/layout/base/TouchManager.cpp
+++ b/layout/base/TouchManager.cpp
@@ -2,17 +2,16 @@
  * vim: set ts=2 sw=2 et tw=78:
  * 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/.
  */
 
 #include "TouchManager.h"
 
-#include "mozilla/TouchEvents.h"
 #include "mozilla/dom/EventTarget.h"
 #include "nsIFrame.h"
 #include "nsPresShell.h"
 #include "nsView.h"
 
 namespace mozilla {
 
 nsRefPtrHashtable<nsUint32HashKey, dom::Touch>* TouchManager::gCaptureTouchList;
@@ -42,19 +41,19 @@ TouchManager::Init(PresShell* aPresShell
 void
 TouchManager::Destroy()
 {
   EvictTouches();
   mDocument = nullptr;
   mPresShell = nullptr;
 }
 
-static void
-EvictTouchPoint(RefPtr<dom::Touch>& aTouch,
-                nsIDocument* aLimitToDocument = nullptr)
+/*static*/ void
+TouchManager::EvictTouchPoint(RefPtr<dom::Touch>& aTouch,
+                              nsIDocument* aLimitToDocument)
 {
   nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->mTarget));
   if (node) {
     nsIDocument* doc = node->GetUncomposedDoc();
     if (doc && (!aLimitToDocument || aLimitToDocument == doc)) {
       nsIPresShell* presShell = doc->GetShell();
       if (presShell) {
         nsIFrame* frame = presShell->GetRootFrame();
@@ -68,24 +67,24 @@ EvictTouchPoint(RefPtr<dom::Touch>& aTou
             nsEventStatus status;
             widget->DispatchEvent(&event, status);
           }
         }
       }
     }
   }
   if (!node || !aLimitToDocument || node->OwnerDoc() == aLimitToDocument) {
-    TouchManager::gCaptureTouchList->Remove(aTouch->Identifier());
+    gCaptureTouchList->Remove(aTouch->Identifier());
   }
 }
 
-static void
-AppendToTouchList(WidgetTouchEvent::TouchArray* aTouchList)
+/*static*/ void
+TouchManager::AppendToTouchList(WidgetTouchEvent::TouchArray* aTouchList)
 {
-  for (auto iter = TouchManager::gCaptureTouchList->Iter();
+  for (auto iter = gCaptureTouchList->Iter();
        !iter.Done();
        iter.Next()) {
     RefPtr<dom::Touch>& touch = iter.Data();
     touch->mChanged = false;
     aTouchList->AppendElement(touch);
   }
 }
 
@@ -225,9 +224,42 @@ TouchManager::PreHandleEvent(WidgetEvent
       break;
     }
     default:
       break;
   }
   return true;
 }
 
+/*static*/ already_AddRefed<nsIContent>
+TouchManager::GetAnyCapturedTouchTarget()
+{
+  nsCOMPtr<nsIContent> result = nullptr;
+  if (gCaptureTouchList->Count() == 0) {
+    return result.forget();
+  }
+  for (auto iter = gCaptureTouchList->Iter(); !iter.Done(); iter.Next()) {
+    RefPtr<dom::Touch>& touch = iter.Data();
+    if (touch) {
+      dom::EventTarget* target = touch->GetTarget();
+      if (target) {
+        result = do_QueryInterface(target);
+        break;
+      }
+    }
+  }
+  return result.forget();
+}
+
+/*static*/ bool
+TouchManager::HasCapturedTouch(int32_t aId)
+{
+  return gCaptureTouchList->Contains(aId);
+}
+
+/*static*/ already_AddRefed<dom::Touch>
+TouchManager::GetCapturedTouch(int32_t aId)
+{
+  RefPtr<dom::Touch> touch = gCaptureTouchList->GetWeak(aId);
+  return touch.forget();
+}
+
 } // namespace mozilla
--- a/layout/base/TouchManager.h
+++ b/layout/base/TouchManager.h
@@ -9,16 +9,17 @@
  * Incapsulate code related with work of touch events.
  */
 
 #ifndef TouchManager_h_
 #define TouchManager_h_
 
 #include "mozilla/BasicEvents.h"
 #include "mozilla/dom/Touch.h"
+#include "mozilla/TouchEvents.h"
 #include "nsRefPtrHashtable.h"
 
 class PresShell;
 class nsIDocument;
 
 namespace mozilla {
 
 class TouchManager {
@@ -31,20 +32,27 @@ public:
   void Destroy();
 
   bool PreHandleEvent(mozilla::WidgetEvent* aEvent,
                       nsEventStatus* aStatus,
                       bool& aTouchIsNew,
                       bool& aIsHandlingUserInput,
                       nsCOMPtr<nsIContent>& aCurrentEventContent);
 
-  static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch>* gCaptureTouchList;
+  static already_AddRefed<nsIContent> GetAnyCapturedTouchTarget();
+  static bool HasCapturedTouch(int32_t aId);
+  static already_AddRefed<dom::Touch> GetCapturedTouch(int32_t aId);
 
 private:
   void EvictTouches();
+  static void EvictTouchPoint(RefPtr<dom::Touch>& aTouch,
+                              nsIDocument* aLimitToDocument = nullptr);
+  static void AppendToTouchList(WidgetTouchEvent::TouchArray* aTouchList);
 
   RefPtr<PresShell>   mPresShell;
   nsCOMPtr<nsIDocument> mDocument;
+
+  static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch>* gCaptureTouchList;
 };
 
 } // namespace mozilla
 
 #endif /* !defined(TouchManager_h_) */
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -7834,38 +7834,26 @@ PresShell::HandleEvent(nsIFrame* aFrame,
       uint32_t flags = 0;
       if (aEvent->mMessage == eTouchStart) {
         flags |= INPUT_IGNORE_ROOT_SCROLL_FRAME;
         WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
         // if this is a continuing session, ensure that all these events are
         // in the same document by taking the target of the events already in
         // the capture list
         nsCOMPtr<nsIContent> anyTarget;
-        if (TouchManager::gCaptureTouchList->Count() > 0 &&
-            touchEvent->mTouches.Length() > 1) {
-          for (auto iter = TouchManager::gCaptureTouchList->Iter();
-               !iter.Done();
-               iter.Next()) {
-            RefPtr<dom::Touch>& touch = iter.Data();
-            if (touch) {
-              dom::EventTarget* target = touch->GetTarget();
-              if (target) {
-                anyTarget = do_QueryInterface(target);
-                break;
-              }
-            }
-          }
+        if (touchEvent->mTouches.Length() > 1) {
+          anyTarget = TouchManager::GetAnyCapturedTouchTarget();
         }
 
         for (int32_t i = touchEvent->mTouches.Length(); i; ) {
           --i;
           dom::Touch* touch = touchEvent->mTouches[i];
 
           int32_t id = touch->Identifier();
-          if (!TouchManager::gCaptureTouchList->Get(id, nullptr)) {
+          if (!TouchManager::HasCapturedTouch(id)) {
             // find the target for this touch
             eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
                                                               touch->mRefPoint,
                                                               frame);
             nsIFrame* target = FindFrameTargetedByInputEvent(aEvent,
                                                              frame,
                                                              eventPoint,
                                                              flags);
@@ -7909,17 +7897,17 @@ PresShell::HandleEvent(nsIFrame* aFrame,
               frame = target;
             }
           } else {
             // This touch is an old touch, we need to ensure that is not
             // marked as changed and set its target correctly
             touch->mChanged = false;
             int32_t id = touch->Identifier();
 
-            RefPtr<dom::Touch> oldTouch = TouchManager::gCaptureTouchList->GetWeak(id);
+            RefPtr<dom::Touch> oldTouch = TouchManager::GetCapturedTouch(id);
             if (oldTouch) {
               touch->SetTarget(oldTouch->mTarget);
             }
           }
         }
       } else {
         eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, frame);
       }
@@ -8027,17 +8015,17 @@ PresShell::HandleEvent(nsIFrame* aFrame,
         // get the correct shell to dispatch to
         WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
         for (dom::Touch* touch : touchEvent->mTouches) {
           if (!touch) {
             break;
           }
 
           RefPtr<dom::Touch> oldTouch =
-            TouchManager::gCaptureTouchList->GetWeak(touch->Identifier());
+            TouchManager::GetCapturedTouch(touch->Identifier());
           if (!oldTouch) {
             break;
           }
 
           nsCOMPtr<nsIContent> content =
             do_QueryInterface(oldTouch->GetTarget());
           if (!content) {
             break;