From 418ee669d226565df1ab0046110e924a43110f15 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Fri, 14 Jan 2011 01:22:26 +0100 Subject: [PATCH] Bug 602331 - selection addRange cannot select nodes that are being dynamically appended to the DOM. r=roc a=blocking2.0:final --- layout/generic/nsSelection.cpp | 12 +++++------ layout/reftests/selection/addrange-1.html | 22 ++++++++++++++++++++ layout/reftests/selection/addrange-2.html | 23 +++++++++++++++++++++ layout/reftests/selection/addrange-ref.html | 18 ++++++++++++++++ layout/reftests/selection/reftest.list | 2 ++ 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 layout/reftests/selection/addrange-1.html create mode 100644 layout/reftests/selection/addrange-2.html create mode 100644 layout/reftests/selection/addrange-ref.html diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 4103c96cb675..60a8d09af376 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -4356,11 +4356,6 @@ nsTypedSelection::selectFrames(nsPresContext* aPresContext, nsIRange *aRange, PR if (!presShell) return NS_OK; - // Re-get shell because the flush might have destroyed it - presShell = aPresContext->GetPresShell(); - if (!presShell) - return NS_OK; - nsCOMPtr domRange = do_QueryInterface(aRange); if (!domRange || !aPresContext) return NS_ERROR_NULL_POINTER; @@ -4821,9 +4816,14 @@ nsTypedSelection::AddRange(nsIRange* aRange) nsRefPtr presContext; GetPresContext(getter_AddRefs(presContext)); + + // Ensure all frames are properly constructed for selectFrames, bug 602331. + nsIPresShell* presShell = presContext ? presContext->GetPresShell() : nsnull; + if (presShell) { + presShell->FlushPendingNotifications(Flush_Frames); + } selectFrames(presContext, aRange, PR_TRUE); - //ScrollIntoView(); this should not happen automatically if (!mFrameSelection) return NS_OK;//nothing to do diff --git a/layout/reftests/selection/addrange-1.html b/layout/reftests/selection/addrange-1.html new file mode 100644 index 000000000000..648d4214041e --- /dev/null +++ b/layout/reftests/selection/addrange-1.html @@ -0,0 +1,22 @@ + + + + Testcase #2 for bug 602331 + + + + * * + + diff --git a/layout/reftests/selection/addrange-2.html b/layout/reftests/selection/addrange-2.html new file mode 100644 index 000000000000..480e9367800e --- /dev/null +++ b/layout/reftests/selection/addrange-2.html @@ -0,0 +1,23 @@ + + + + Testcase #3 for bug 602331 + + + + * Hello * + + diff --git a/layout/reftests/selection/addrange-ref.html b/layout/reftests/selection/addrange-ref.html new file mode 100644 index 000000000000..4e6a70db2ff7 --- /dev/null +++ b/layout/reftests/selection/addrange-ref.html @@ -0,0 +1,18 @@ + + + + Testcase #1 for bug 602331 + + + + * Hello Kitty * + + diff --git a/layout/reftests/selection/reftest.list b/layout/reftests/selection/reftest.list index d75987065b55..443311b5c57a 100644 --- a/layout/reftests/selection/reftest.list +++ b/layout/reftests/selection/reftest.list @@ -28,3 +28,5 @@ # These tests uses Highlight and HighlightText color keywords, they are not same as text selection color on Mac. fails-if(cocoaWidget) == non-themed-widget.html non-themed-widget-ref.html fails-if(cocoaWidget) == themed-widget.html themed-widget-ref.html +== addrange-1.html addrange-ref.html +== addrange-2.html addrange-ref.html