Hold a strong reference on the Selection while calling ScrollIntoView with SCROLL_DO_FLUSH.

This commit is contained in:
Pale Moon
2017-04-22 01:50:56 +02:00
committed by roytam1
parent 4930dcaf60
commit a17dc0d577
2 changed files with 13 additions and 9 deletions
+8 -5
View File
@@ -65,8 +65,8 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Selection, nsISelectionPrivate)
NS_DECL_NSISELECTION
NS_DECL_NSISELECTIONPRIVATE
virtual Selection* AsSelection() override { return this; }
virtual Selection* AsSelection() override { return this; }
nsIDocument* GetParentObject() const;
@@ -93,11 +93,14 @@ public:
enum {
SCROLL_SYNCHRONOUS = 1<<1,
SCROLL_FIRST_ANCESTOR_ONLY = 1<<2,
SCROLL_DO_FLUSH = 1<<3,
SCROLL_DO_FLUSH = 1<<3, // only matters if SCROLL_SYNCHRONOUS is passed too
SCROLL_OVERFLOW_HIDDEN = 1<<5
};
// aDoFlush only matters if aIsSynchronous is true. If not, we'll just flush
// when the scroll event fires so we make sure to scroll to the right place.
// If aFlags doesn't contain SCROLL_SYNCHRONOUS, then we'll flush when
// the scroll event fires so we make sure to scroll to the right place.
// Otherwise, if SCROLL_DO_FLUSH is also in aFlags, then this method will
// flush layout and you MUST hold a strong ref on 'this' for the duration
// of this call. This might destroy arbitrary layout objects.
nsresult ScrollIntoView(SelectionRegion aRegion,
nsIPresShell::ScrollAxis aVertical =
nsIPresShell::ScrollAxis(),
+5 -4
View File
@@ -1786,10 +1786,9 @@ nsFrameSelection::ScrollSelectionIntoView(SelectionType aType,
// After ScrollSelectionIntoView(), the pending notifications might be
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
return mDomSelections[index]->ScrollIntoView(aRegion,
verticalScroll,
nsIPresShell::ScrollAxis(),
flags);
nsRefPtr<Selection> sel = mDomSelections[index];
return sel->ScrollIntoView(aRegion, verticalScroll,
nsIPresShell::ScrollAxis(), flags);
}
nsresult
@@ -5651,6 +5650,8 @@ Selection::ScrollSelectionIntoViewEvent::Run()
int32_t flags = Selection::SCROLL_DO_FLUSH |
Selection::SCROLL_SYNCHRONOUS;
Selection* sel = mSelection; // workaround to satisfy static analysis
nsRefPtr<Selection> kungFuDeathGrip(sel);
mSelection->mScrollEvent.Forget();
mSelection->ScrollIntoView(mRegion, mVerticalScroll,
mHorizontalScroll, mFlags | flags);