Bug 1015644 - Clean up ActiveElementManager r=botond
authorDavid Zbarsky <dzbarsky@gmail.com>
Mon, 16 Jun 2014 18:50:16 -0400
changeset 188961 8222bfcd04fb53b33e3315a96039dff5c5a57076
parent 188960 c872e8a9529fba732d9e4fd21102d9e6c1148b37
child 188962 6bfb8e486881cedce6c23ddcbcb846fdca6354df
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbotond
bugs1015644
milestone33.0a1
Bug 1015644 - Clean up ActiveElementManager r=botond
gfx/layers/apz/util/ActiveElementManager.cpp
gfx/layers/apz/util/ActiveElementManager.h
--- a/gfx/layers/apz/util/ActiveElementManager.cpp
+++ b/gfx/layers/apz/util/ActiveElementManager.cpp
@@ -3,21 +3,19 @@
  * 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 "ActiveElementManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "inIDOMUtils.h"
-#include "nsIDOMDocument.h"
-#include "nsIDOMElement.h"
-#include "nsIDOMEventTarget.h"
 #include "base/message_loop.h"
 #include "base/task.h"
+#include "mozilla/dom/Element.h"
 
 #define AEM_LOG(...)
 // #define AEM_LOG(...) printf_stderr("AEM: " __VA_ARGS__)
 
 namespace mozilla {
 namespace layers {
 
 static int32_t sActivationDelayMs = 100;
@@ -35,17 +33,17 @@ ActiveElementManager::ActiveElementManag
                                 sActivationDelayMs);
     sActivationDelayMsSet = true;
   }
 }
 
 ActiveElementManager::~ActiveElementManager() {}
 
 void
-ActiveElementManager::SetTargetElement(nsIDOMEventTarget* aTarget)
+ActiveElementManager::SetTargetElement(dom::EventTarget* aTarget)
 {
   if (mTarget) {
     // Multiple fingers on screen (since HandleTouchEnd clears mTarget).
     AEM_LOG("Multiple fingers on-screen, clearing target element\n");
     CancelTask();
     ResetActive();
     ResetTouchBlockState();
     return;
@@ -121,53 +119,49 @@ ActiveElementManager::HandleTouchEnd(boo
   if (aWasClick) {
     SetActive(mTarget);
   }
 
   ResetTouchBlockState();
 }
 
 void
-ActiveElementManager::SetActive(nsIDOMElement* aTarget)
+ActiveElementManager::SetActive(dom::Element* aTarget)
 {
   AEM_LOG("Setting active %p\n", aTarget);
   if (mDomUtils) {
-    mDomUtils->SetContentState(aTarget, NS_EVENT_STATE_ACTIVE.GetInternalValue());
+    nsCOMPtr<nsIDOMElement> target = do_QueryInterface(aTarget);
+    mDomUtils->SetContentState(target, NS_EVENT_STATE_ACTIVE.GetInternalValue());
   }
 }
 
 void
 ActiveElementManager::ResetActive()
 {
   AEM_LOG("Resetting active from %p\n", mTarget.get());
 
   // Clear the :active flag from mTarget by setting it on the document root.
   if (mTarget) {
-    nsCOMPtr<nsIDOMDocument> doc;
-    mTarget->GetOwnerDocument(getter_AddRefs(doc));
-    if (doc) {
-      nsCOMPtr<nsIDOMElement> root;
-      doc->GetDocumentElement(getter_AddRefs(root));
-      if (root) {
-        AEM_LOG("Found root %p, making active\n", root.get());
-        SetActive(root);
-      }
+    dom::Element* root = mTarget->OwnerDoc()->GetDocumentElement();
+    if (root) {
+      AEM_LOG("Found root %p, making active\n", root.get());
+      SetActive(root);
     }
   }
 }
 
 void
 ActiveElementManager::ResetTouchBlockState()
 {
   mTarget = nullptr;
   mCanBePanSet = false;
 }
 
 void
-ActiveElementManager::SetActiveTask(nsIDOMElement* aTarget)
+ActiveElementManager::SetActiveTask(dom::Element* aTarget)
 {
   AEM_LOG("mSetActiveTask %p running\n", mSetActiveTask);
 
   // This gets called from mSetActiveTask's Run() method. The message loop
   // deletes the task right after running it, so we need to null out
   // mSetActiveTask to make sure we're not left with a dangling pointer.
   mSetActiveTask = nullptr;
   SetActive(aTarget);
--- a/gfx/layers/apz/util/ActiveElementManager.h
+++ b/gfx/layers/apz/util/ActiveElementManager.h
@@ -5,21 +5,24 @@
 
 #ifndef mozilla_layers_ActiveElementManager_h
 #define mozilla_layers_ActiveElementManager_h
 
 #include "nsCOMPtr.h"
 #include "nsISupportsImpl.h"
 
 class inIDOMUtils;
-class nsIDOMEventTarget;
-class nsIDOMElement;
 class CancelableTask;
 
 namespace mozilla {
+namespace dom {
+class Element;
+class EventTarget;
+}
+
 namespace layers {
 
 /**
  * Manages setting and clearing the ':active' CSS pseudostate in the presence
  * of touch input.
  */
 class ActiveElementManager {
 public:
@@ -30,17 +33,17 @@ public:
 
   /**
    * Specify the target of a touch. Typically this should be called right
    * before HandleTouchStart(), but we give callers the flexibility to specify
    * the target later if they don't know it at the time they call
    * HandleTouchStart().
    * |aTarget| may be nullptr.
    */
-  void SetTargetElement(nsIDOMEventTarget* aTarget);
+  void SetTargetElement(dom::EventTarget* aTarget);
   /**
    * Handle a touch-start event.
    * @param aCanBePan whether the touch can be a pan
    */
   void HandleTouchStart(bool aCanBePan);
   /**
    * Handle the start of panning.
    */
@@ -50,17 +53,17 @@ public:
    * @param aWasClick whether the touch was a click
    */
   void HandleTouchEnd(bool aWasClick);
 private:
   nsCOMPtr<inIDOMUtils> mDomUtils;
   /**
    * The target of the first touch point in the current touch block.
    */
-  nsCOMPtr<nsIDOMElement> mTarget;
+  nsCOMPtr<dom::Element> mTarget;
   /**
    * Whether the current touch block can be a pan. Set in HandleTouchStart().
    */
   bool mCanBePan;
   /**
    * Whether mCanBePan has been set for the current touch block.
    * We need to keep track of this to allow HandleTouchStart() and
    * SetTargetElement() to be called in either order.
@@ -68,19 +71,19 @@ private:
   bool mCanBePanSet;
   /**
    * A task for calling SetActive() after a timeout.
    */
   CancelableTask* mSetActiveTask;
 
   // Helpers
   void TriggerElementActivation();
-  void SetActive(nsIDOMElement* aTarget);
+  void SetActive(dom::Element* aTarget);
   void ResetActive();
   void ResetTouchBlockState();
-  void SetActiveTask(nsIDOMElement* aTarget);
+  void SetActiveTask(dom::Element* aTarget);
   void CancelTask();
 };
 
 }
 }
 
 #endif /* mozilla_layers_ActiveElementManager_h */