Bug 602331 - selection addRange cannot select nodes that are being dynamically appended to the DOM. r=roc a=blocking2.0:final

This commit is contained in:
Mats Palmgren 2011-01-14 01:22:26 +01:00
parent 227698aa53
commit 418ee669d2
5 changed files with 71 additions and 6 deletions

View File

@ -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<nsIDOMRange> domRange = do_QueryInterface(aRange);
if (!domRange || !aPresContext)
return NS_ERROR_NULL_POINTER;
@ -4821,9 +4816,14 @@ nsTypedSelection::AddRange(nsIRange* aRange)
nsRefPtr<nsPresContext> 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

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Testcase #2 for bug 602331</title>
<script type="text/javascript" charset="utf-8">
function selectNewlyAdded() {
window.getSelection().removeAllRanges();
var newNode = document.createElement('span');
newNode.innerHTML = "Hello Kitty";
document.getElementById('new_nodes').appendChild(newNode);
var range = document.createRange();
range.selectNode(newNode);
window.getSelection().addRange(range);
}
</script>
</head>
<body onload="selectNewlyAdded()">
* <span id="new_nodes"></span> *
</body>
</html>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Testcase #3 for bug 602331</title>
<script type="text/javascript" charset="utf-8">
function selectAllOfNewNodes() {
window.getSelection().removeAllRanges();
var newNode = document.createElement('span');
newNode.innerHTML = "Kitty";
document.getElementById('new_nodes').appendChild(newNode);
var range = document.createRange();
range.selectNode(document.getElementById('new_nodes'));
window.getSelection().addRange(range);
}
</script>
</head>
<body onload="selectAllOfNewNodes()">
* <span id="new_nodes"><span>Hello</span> </span> *
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Testcase #1 for bug 602331</title>
<script type="text/javascript" charset="utf-8">
function selectExisting() {
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(document.getElementById('existing_node'));
window.getSelection().addRange(range);
}
</script>
</head>
<body onload="selectExisting()">
* <span id="existing_node">Hello Kitty</span> *
</body>
</html>

View File

@ -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