Bug 1342874 - (Part 8) DocGroup labeling for timer callbacks in nsTreeSelection. r?dholbert
MozReview-Commit-ID: IkRIFfkVt9J
--- 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.