Bug 1342874 - (Part 8) DocGroup labeling for timer callbacks in nsTreeSelection. r?dholbert draft
authorKuoE0 <kuoe0.tw@gmail.com>
Mon, 20 Mar 2017 16:13:24 +0800
changeset 552305 30ddf8ca95fc1c7301f7eb9be8fe580862ffab27
parent 552304 bbcbf065bdbe61e2ec08b3878ee53ac81f8498c0
child 621773 8f51fe9328f0d19f2d0d224fb7a03e3aea89dad6
push id51307
push userbmo:kuoe0@mozilla.com
push dateTue, 28 Mar 2017 08:11:36 +0000
reviewersdholbert
bugs1342874
milestone55.0a1
Bug 1342874 - (Part 8) DocGroup labeling for timer callbacks in nsTreeSelection. r?dholbert MozReview-Commit-ID: IkRIFfkVt9J
layout/xul/tree/nsTreeSelection.cpp
layout/xul/tree/nsTreeSelection.h
--- a/layout/xul/tree/nsTreeSelection.cpp
+++ b/layout/xul/tree/nsTreeSelection.cpp
@@ -286,29 +286,24 @@ NS_IMETHODIMP nsTreeSelection::SetTree(n
   nsCOMPtr<nsIBoxObject> bo = do_QueryInterface(aTree);
   mTree = do_QueryInterface(bo);
   NS_ENSURE_STATE(mTree == aTree);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsTreeSelection::GetSingle(bool* aSingle)
 {
-  if (!mTree)
-    return NS_ERROR_NULL_POINTER;
-
-  nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mTree);
-
-  nsCOMPtr<nsIDOMElement> element;
-  boxObject->GetElement(getter_AddRefs(element));
-
-  nsCOMPtr<nsIContent> content = do_QueryInterface(element);
-
   static nsIContent::AttrValuesArray strings[] =
     {&nsGkAtoms::single, &nsGkAtoms::cell, &nsGkAtoms::text, nullptr};
 
+  nsCOMPtr<nsIContent> content = GetContent();
+  if (!content) {
+    return NS_ERROR_NULL_POINTER;
+  }
+
   *aSingle = content->FindAttrValueIn(kNameSpaceID_None,
                                       nsGkAtoms::seltype,
                                       strings, eCaseMatters) >= 0;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsTreeSelection::IsSelected(int32_t aIndex, bool* aResult)
@@ -333,18 +328,24 @@ NS_IMETHODIMP nsTreeSelection::TimedSele
 
   if (aMsec != -1) {
     mSuppressed = suppressSelect;
     if (!mSuppressed) {
       if (mSelectTimer)
         mSelectTimer->Cancel();
 
       mSelectTimer = do_CreateInstance("@mozilla.org/timer;1");
-      mSelectTimer->InitWithFuncCallback(SelectCallback, this, aMsec, 
-                                         nsITimer::TYPE_ONE_SHOT);
+      nsCOMPtr<nsIContent> content = GetContent();
+      if (content) {
+        mSelectTimer->SetTarget(
+            content->OwnerDoc()->EventTargetFor(TaskCategory::Other));
+      }
+      mSelectTimer->InitWithNamedFuncCallback(SelectCallback, this, aMsec,
+                                              nsITimer::TYPE_ONE_SHOT,
+                                              "nsTreeSelection::SelectCallback");
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsTreeSelection::Select(int32_t aIndex)
 {
@@ -848,16 +849,32 @@ nsTreeSelection::SelectCallback(nsITimer
   RefPtr<nsTreeSelection> self = static_cast<nsTreeSelection*>(aClosure);
   if (self) {
     self->FireOnSelectHandler();
     aTimer->Cancel();
     self->mSelectTimer = nullptr;
   }
 }
 
+already_AddRefed<nsIContent>
+nsTreeSelection::GetContent()
+{
+  if (!mTree) {
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mTree);
+
+  nsCOMPtr<nsIDOMElement> element;
+  boxObject->GetElement(getter_AddRefs(element));
+
+  nsCOMPtr<nsIContent> content = do_QueryInterface(element);
+  return content.forget();
+}
+
 ///////////////////////////////////////////////////////////////////////////////////
 
 nsresult
 NS_NewTreeSelection(nsITreeBoxObject* aTree, nsITreeSelection** aResult)
 {
   *aResult = new nsTreeSelection(aTree);
   if (!*aResult)
     return NS_ERROR_OUT_OF_MEMORY;
--- a/layout/xul/tree/nsTreeSelection.h
+++ b/layout/xul/tree/nsTreeSelection.h
@@ -32,16 +32,19 @@ public:
 
 protected:
   ~nsTreeSelection();
 
   nsresult FireOnSelectHandler();
   static void SelectCallback(nsITimer *aTimer, void *aClosure);
 
 protected:
+  // Helper function to get the content node associated with mTree.
+  already_AddRefed<nsIContent> GetContent();
+
   // Members
   nsCOMPtr<nsITreeBoxObject> mTree; // The tree will hold on to us through the view and let go when it dies.
 
   bool mSuppressed; // Whether or not we should be firing onselect events.
   int32_t mCurrentIndex; // The item to draw the rect around. The last one clicked, etc.
   nsCOMPtr<nsITreeColumn> mCurrentColumn;
   int32_t mShiftSelectPivot; // Used when multiple SHIFT+selects are performed to pivot on.