Commit f28fa1b0 authored by darin@apple.com's avatar darin@apple.com

WebCore:

        Reviewed by Sam.

        - fix http://bugs.webkit.org/show_bug.cgi?id=11997
          Ranges are not fixed after mutation (affects Acid3 test 13)

        Test: fast/dom/Range/mutation.html

        * WebCore.xcodeproj/project.pbxproj: Added NodeWithIndex.h, NodeWithIndexAfter.h,
        and NodeWithIndexBefore.h.

        * dom/CharacterData.cpp:
        (WebCore::CharacterData::setData): Replaced call to Document::removeMarkers
        with call to Document::textRemoved.
        (WebCore::CharacterData::insertData): Replaced call to Document::shiftMarkers
        with call to Document::textInserted.
        (WebCore::CharacterData::deleteData): Replaced call to Document::removeMarkers
        and Document::shiftMarkers with call to Document::textRemoved.
        (WebCore::CharacterData::replaceData): Replaced call to Document::removeMarkers
        and Document::shiftMarkers with call to Document::textRemoved and
        Document::textInserted.
        (WebCore::CharacterData::containsOnlyWhitespace): Tweaked a bit.

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::childrenChanged): Added a call to
        Document::nodeChildrenChanged when the nmber of children was changed (and not
        by the parser).
        (WebCore::dispatchChildRemovalEvents): Updated for name change.

        * dom/Document.cpp:
        (WebCore::Document::~Document): Assert that all ranges are gone.
        (WebCore::Document::nodeChildrenChanged): Added. Calls nodeChildrenChanged on
        all ranges.
        (WebCore::Document::nodeWillBeRemoved): Renamed from notifyBeforeNodeRemoval.
        Added code to call nodeWillBeRemoved on all ranges.
        (WebCore::Document::textInserted): Added. Calls textInserted on all ranges and
        also calls shiftMarkers.
        (WebCore::Document::textRemoved): Added. Calls textRemoved on all ranges and also
        calls removeMarkers and shiftMarkers.
        (WebCore::Document::textNodesMerged): Added. Calls textNodesMerged on all ranges.
        (WebCore::Document::textNodeSplit): Added. Calls textNodeSplit on all ranges.
        (WebCore::Document::attachRange): Added. Adds range to the HashSet of all ranges
        for this document.
        (WebCore::Document::detachRange): Added. Removes range from the HashSet.
        * dom/Document.h: Added the new functions and the data member.

        * dom/Element.cpp:
        (WebCore::Element::normalizeAttributes): Added. Contains the part of the
        normalize function that's specific to Element. Better encapsulation to have it
        here rather than in Node::normalize.
        * dom/Element.h: Added the new function.

        * dom/Node.cpp:
        (WebCore::Node::normalize): Rewrote so it's no longer recursive. Also added
        a call to textNodesMerged after each pair of nodes is merged but before the
        second node is removed.
        (WebCore::Node::traverseNextNodePostOrder): Added. Helper function used by
        normalize, but also useful elsewhere.
        * dom/Node.h: Added the new function.

        * dom/NodeIterator.cpp:
        (WebCore::NodeIterator::nodeWillBeRemoved): Renamed from notifyBeforeNodeRemoval.
        * dom/NodeIterator.h: Ditto.

        * dom/ProcessingInstruction.cpp:
        (WebCore::ProcessingInstruction::setData): Call textRemoved.

        * dom/Range.cpp:
        (WebCore::NodeWithIndex::index): Added. Computes and stores index.
        (WebCore::NodeWithIndexBefore::indexBefore): Added. Computes and stores index.
        (WebCore::NodeWithIndexAfter::indexAfter): Added. Computes and stores index.
        (WebCore::Range::Range): Call attachRange.
        (WebCore::Range::~Range): Call detachRange unless the range is already detached.
        (WebCore::Range::commonAncestorContainer): Removed check for WRONG_DOCUMENT_ERR.
        It's no longer possible to create a range where the two containers are non-zero
        and have no common ancestor.
        (WebCore::Range::isPointInRange): Rewrote expression to be more readable.
        (WebCore::Range::compareNode): Changed local variable to use int for consistency.
        (WebCore::Range::compareBoundaryPoints): Replaced ASSERT with ASSERT_NOT_REACHED.
        (WebCore::Range::deleteContents): Removed check for INVALID_STATE_ERR and
        initialization of ec to 0; both are now inside checkDeleteExtract.
        (WebCore::Range::intersectsNode): Changed local variable to use int for consistency.
        Also changed comparison to use < 0 and >= 0 rather than checking explicitly for 1
        and -1.
        (WebCore::Range::processContents): Changed code to not get the nodeType multiple
        times on the same node, and tweaked formatting. Removed code to update the range
        on deletion, because the normal delete logic will take care of that now.
        (WebCore::Range::extractContents): Removed check for INVALID_STATE_ERR and
        initialization of ec to 0; both are now inside checkDeleteExtract.
        (WebCore::Range::insertNode): Changed local variable to use int for consistency.
        (WebCore::Range::toString): Changed variable name to pastLast.
        (WebCore::Range::detach): Call detachRange.
        (WebCore::Range::checkDeleteExtract): Added check for detached range and code to
        set ec to 0; moved here from the two callers. Also changed variable name to pastLast.
        (WebCore::endpointNodeChildrenChanged): Added.
        (WebCore::Range::nodeChildrenChanged): Added.
        (WebCore::endpointNodeWillBeRemoved): Added.
        (WebCore::Range::nodeWillBeRemoved): Added.
        (WebCore::endpointTextInserted): Added.
        (WebCore::Range::textInserted): Added.
        (WebCore::endpointTextRemoved): Added.
        (WebCore::Range::textRemoved): Added.
        (WebCore::endpointTextNodesMerged): Added.
        (WebCore::Range::textNodesMerged): Added.
        (WebCore::endpointTextNodesSplit): Added.
        (WebCore::Range::textNodeSplit): Added.

        * dom/Range.h: Added new member functions.

        * dom/NodeWithIndex.h: Added. Makes it so we won't find the index for the same
        node more than once.
        * dom/NodeWithIndexAfter.h: Added. Similar to NodeWithIndex but gives the index after a
        node and treats a node pointer of 0 as meaning "before first node in parent container".
        * dom/NodeWithIndexBefore.h: Added.  Similar to NodeWithIndex but treats a node pointer of 0
        as meaning "after last node in parent container".

        * dom/Text.cpp:
        (WebCore::Text::splitText): Call textNodeSplit.

        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::applyInlineStyle): Changed variable name to pastLast.

LayoutTests:

        Reviewed by Sam.

        - test changes for http://bugs.webkit.org/show_bug.cgi?id=11997
          Ranges are not fixed after mutation (affects Acid3 test 13)

        * fast/dom/Range/mutation-expected.txt: Added.
        * fast/dom/Range/mutation.html: Added.
        * fast/dom/Range/resources/mutation.js: Added.

        * editing/execCommand/4920742-2-expected.txt: Updated.
        * editing/execCommand/4920742-2.html: Updated this test. It was testing for a crash in a
        case that's no longer possible -- you can't make a range where one endpoint is in the
        document and the other is not.

        * platform/mac/editing/execCommand/4920488-expected.txt: Removed WRONG_DOCUMENT_ERR.
        The fact that a test was getting this exception was a bug, similar to the case above.
        * platform/qt/editing/execCommand/4920488-expected.txt: Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31075 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f557a5a5
2008-03-15 Darin Adler <darin@apple.com>
Reviewed by Sam.
- test changes for http://bugs.webkit.org/show_bug.cgi?id=11997
Ranges are not fixed after mutation (affects Acid3 test 13)
* fast/dom/Range/mutation-expected.txt: Added.
* fast/dom/Range/mutation.html: Added.
* fast/dom/Range/resources/mutation.js: Added.
* editing/execCommand/4920742-2-expected.txt: Updated.
* editing/execCommand/4920742-2.html: Updated this test. It was testing for a crash in a
case that's no longer possible -- you can't make a range where one endpoint is in the
document and the other is not.
* platform/mac/editing/execCommand/4920488-expected.txt: Removed WRONG_DOCUMENT_ERR.
The fact that a test was getting this exception was a bug, similar to the case above.
* platform/qt/editing/execCommand/4920488-expected.txt: Ditto.
2008-03-15 Julien Chaffraix <julien.chaffraix@gmail.com>
Reviewed by Holger.
This tests for a crash when performing Range::extractContents on a range that has had the start or end removed from the document. When extractContents is called on this kind of invalid range, an exception should be thrown.
This tested for a crash when performing Range::extractContents on a range that has had the start or end removed from the document.
link
It's now impossible to create a range like this, but at one point with an earlier version of WebKit, it was possible.
link
No crash means success!
<p>This tests for a crash when performing Range::extractContents on a range that has had the start or end removed from the document. When extractContents is called on this kind of invalid range, an exception should be thrown.</p>
<p>This tested for a crash when performing Range::extractContents on a range that has had the start or end removed from the document.</p>
<p>It's now impossible to create a range like this, but at one point with an earlier version of WebKit, it was possible.</p>
<div id="div" contenteditable="true">text <a href="http://www.apple.com/">link</a></div>
<ul id="console"></ul>
......@@ -19,15 +20,7 @@ var link = div.lastChild;
var r = document.createRange();
r.setStart(text, 0);
r.setEnd(link, 0);
text.parentNode.removeChild(text);
try {
r.extractContents();
log("Failure. Expected an exception to be thrown.");
} catch (e) {
var expected = "Error: WRONG_DOCUMENT_ERR: DOM Exception 4";
if (e != expected)
log("Failure. Expected: " + expected);
}
r.extractContents();
log("No crash means success!");
</script>
PASS description(range) is "text,24 -> text,32: Y blah i"
PASS description(range) is "text,11 -> text,32: inserted textY blah i"
PASS description(range) is "text,11 -> text,32: Yinserted text blah i"
PASS description(range) is "text,11 -> text,32: Y blahinserted text i"
PASS description(range) is "text,11 -> text,32: Y blah inserted texti"
PASS description(range) is "text,11 -> text,19: Y blah i"
PASS description(range) is "text,5 -> text,13: Range i"
PASS description(range) is "text,5 -> text,5: "
PASS description(range) is "text1,5 -> text2,4: ange"
PASS description(range) is "text,5 -> text,15: he Range i"
PASS paragraph.childNodes.length is 2
PASS text1.length is 5
PASS description(range) is "paragraph,1 -> paragraph,1: "
PASS paragraph.childNodes.length is 1
PASS text1.length is 7
PASS description(range) is "text1,5 -> text1,5: "
PASS description(range) is "paragraph,2 -> paragraph,4: bc"
PASS description(range) is "paragraph,1 -> paragraph,4: ebc"
PASS description(range) is "paragraph,1 -> paragraph,4: bec"
PASS description(range) is "paragraph,1 -> paragraph,3: bc"
PASS description(range) is "paragraph,1 -> paragraph,3: bc"
PASS description(range) is "paragraph,1 -> d,1: cd"
PASS description(range) is "paragraph,1 -> d,0: c"
PASS description(range) is "b,0 -> paragraph,3: bc"
PASS description(range) is "b,1 -> paragraph,3: c"
PASS description(range) is "a,1 -> a,3: xb"
PASS description(range) is "a,1 -> b,2: bc"
PASS description(range) is "a,1 -> b,1: bc"
PASS description(range) is "a,1 -> a,3: bc"
PASS description(range) is "a,2 -> section,1: cde"
PASS description(range) is "section,0 -> section,0: "
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css">
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="resources/mutation.js"></script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
description(
"This test checks mutation of the DOM and how it affects Ranges."
);
var a;
var b;
var c;
var d;
var e;
var paragraph;
var section;
var text;
var text1;
var text2;
var text3;
function name(node)
{
if (node == a)
return "a";
if (node == b)
return "b";
if (node == c)
return "c";
if (node == d)
return "d";
if (node == e)
return "e";
if (node == paragraph)
return "paragraph";
if (node == section)
return "section";
if (node == text)
return "text";
if (node == text1)
return "text1";
if (node == text2)
return "text2";
if (node == text3)
return "text3";
return "???";
}
function description(range)
{
return name(range.startContainer) + "," + range.startOffset + " -> " + name(range.endContainer) + "," + range.endOffset + ": " + range.toString();
}
function makeRange(sc, so, ec, eo)
{
var newRange = document.createRange();
newRange.setStart(sc, so);
newRange.setEnd(ec, eo);
return newRange;
}
function setUp1()
{
paragraph = document.createElement("p");
text = document.createTextNode("Abcd efgh XY blah ijkl");
paragraph.appendChild(text);
range = makeRange(text, 11, text, 19);
}
function createTestElement(name)
{
var element = document.createElement("em");
var text = document.createTextNode(name);
element.appendChild(text);
return element;
}
function setUp2()
{
paragraph = document.createElement("p");
a = createTestElement("a");
b = createTestElement("b");
c = createTestElement("c");
d = createTestElement("d");
e = createTestElement("e");
paragraph.appendChild(a);
paragraph.appendChild(b);
paragraph.appendChild(c);
paragraph.appendChild(d);
range = makeRange(paragraph, 1, paragraph, 3);
}
function setUp3()
{
paragraph = document.createElement("p");
a = document.createTextNode("ax");
b = document.createTextNode("by");
paragraph.appendChild(a);
paragraph.appendChild(b);
range = makeRange(a, 1, b, 1);
}
function setUp4()
{
paragraph = document.createElement("p");
a = document.createTextNode("abcd");
paragraph.appendChild(a);
range = makeRange(a, 1, a, 3);
}
function setUp5()
{
section = document.createElement("div");
paragraph = document.createElement("p");
a = document.createTextNode("abcde");
section.appendChild(paragraph);
paragraph.appendChild(a);
range = makeRange(a, 2, section, 1);
}
// First, tests from the DOM Level 2 specification.
// DOM Level 2 Traversal Range, 2.12.1. Insertions, example 1.
setUp1();
text.insertData(10, "inserted text");
shouldBe('description(range)', '"text,24 -> text,32: Y blah i"');
// DOM Level 2 Traversal Range, 2.12.1. Insertions, example 2.
// Firefox does not match the DOM Level 2 specification on this one.
setUp1();
text.insertData(11, "inserted text");
shouldBe('description(range)', '"text,11 -> text,32: inserted textY blah i"');
// DOM Level 2 Traversal Range, 2.12.1. Insertions, example 3.
setUp1();
text.insertData(12, "inserted text");
shouldBe('description(range)', '"text,11 -> text,32: Yinserted text blah i"');
// DOM Level 2 Traversal Range, 2.12.1. Insertions, example 4.
setUp1();
text.insertData(17, "inserted text");
shouldBe('description(range)', '"text,11 -> text,32: Y blahinserted text i"');
// Similar test at the range end.
setUp1();
text.insertData(18, "inserted text");
shouldBe('description(range)', '"text,11 -> text,32: Y blah inserted texti"');
// Similar test at the range end.
setUp1();
text.insertData(19, "inserted text");
shouldBe('description(range)', '"text,11 -> text,19: Y blah i"');
// DOM Level 2 Traversal Range, 2.12.2. Deletions, example 1.
paragraph = document.createElement("p");
text = document.createTextNode("Abcd efgh The Range ijkl");
paragraph.appendChild(text);
range = makeRange(text, 11, text, 21);
text.deleteData(5, 8);
shouldBe('description(range)', '"text,5 -> text,13: Range i"');
// DOM Level 2 Traversal Range, 2.12.2. Deletions, example 2.
paragraph = document.createElement("p");
text = document.createTextNode("Abcd efgh The Range ijkl");
paragraph.appendChild(text);
range = makeRange(text, 11, text, 21);
text.deleteData(5, 17);
shouldBe('description(range)', '"text,5 -> text,5: "');
// DOM Level 2 Traversal Range, 2.12.2. Deletions, example 3.
// Firefox does not match the DOM Level 2 specification on this one.
// Or maybe I wrote the test wrong?
paragraph = document.createElement("p");
text1 = document.createTextNode("ABCD efgh The ");
paragraph.appendChild(text1);
em = document.createElement("em");
paragraph.appendChild(em);
text2 = document.createTextNode("Range");
em.appendChild(text2);
text3 = document.createTextNode(" ijkl");
paragraph.appendChild(text3);
range = makeRange(text1, 11, text2, 5);
makeRange(text1, 5, text2, 1).deleteContents();
shouldBe('description(range)', '"text1,5 -> text2,4: ange"');
// DOM Level 2 Traversal Range, 2.12.2. Deletions, example 4.
paragraph = document.createElement("p");
text = document.createTextNode("Abcd efgh The Range ijkl");
paragraph.appendChild(text);
range = makeRange(text, 11, text, 21);
text.deleteData(5, 6);
shouldBe('description(range)', '"text,5 -> text,15: he Range i"');
// DOM Level 2 Traversal Range, 2.12.2. Deletions, example 5.
paragraph = document.createElement("p");
text1 = document.createTextNode("Abcd ");
paragraph.appendChild(text1);
em = document.createElement("em");
paragraph.appendChild(em);
text2 = document.createTextNode("efgh The Range ij");
em.appendChild(text2);
text3 = document.createTextNode("kl");
paragraph.appendChild(text3);
range = makeRange(text2, 6, text2, 16);
makeRange(paragraph, 1, paragraph, 2).deleteContents();
shouldBe('paragraph.childNodes.length', '2');
shouldBe('text1.length', '5');
shouldBe('description(range)', '"paragraph,1 -> paragraph,1: "');
paragraph.normalize();
shouldBe('paragraph.childNodes.length', '1');
shouldBe('text1.length', '7');
shouldBe('description(range)', '"text1,5 -> text1,5: "');
// Inserting a node in the start container, before the range start offset.
setUp2();
paragraph.insertBefore(e, a);
shouldBe('description(range)', '"paragraph,2 -> paragraph,4: bc"');
// Inserting a node in the start container, at the range start offset.
setUp2();
paragraph.insertBefore(e, b);
shouldBe('description(range)', '"paragraph,1 -> paragraph,4: ebc"');
// Inserting a node in the start container, between start and end.
setUp2();
paragraph.insertBefore(e, c);
shouldBe('description(range)', '"paragraph,1 -> paragraph,4: bec"');
// Inserting a node in the end container, at the range end offset.
setUp2();
paragraph.insertBefore(e, d);
shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"');
// Inserting a node in the end container, after the range end offset.
setUp2();
paragraph.appendChild(e);
shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"');
// Removing the start container of a range.
setUp2();
range = makeRange(b, 0, d, 1);
paragraph.removeChild(b);
shouldBe('description(range)', '"paragraph,1 -> d,1: cd"');
setUp2();
range = makeRange(b, 1, d, 0);
paragraph.removeChild(b);
shouldBe('description(range)', '"paragraph,1 -> d,0: c"');
// Removing the end container of a range.
setUp2();
range = makeRange(b, 0, d, 1);
paragraph.removeChild(d);
shouldBe('description(range)', '"b,0 -> paragraph,3: bc"');
setUp2();
range = makeRange(b, 1, d, 0);
paragraph.removeChild(d);
shouldBe('description(range)', '"b,1 -> paragraph,3: c"');
// Calling normalize with a range that has an endpoint in a text node that gets merged into another.
// Firefox does not do what the DOM Level 2 specification seems to call for on this one.
setUp3();
paragraph.normalize();
shouldBe('description(range)', '"a,1 -> a,3: xb"');
// Calling splitText when a range has an endpoint on in the piece that gets made into a new text node.
// Firefox does not do what the DOM Level 2 specification seems to call for on this one.
setUp4();
b = a.splitText(1);
shouldBe('description(range)', '"a,1 -> b,2: bc"');
setUp4();
b = a.splitText(2);
shouldBe('description(range)', '"a,1 -> b,1: bc"');
setUp4();
b = a.splitText(3);
shouldBe('description(range)', '"a,1 -> a,3: bc"');
// Range test in Acid3.
setUp5();
shouldBe('description(range)', '"a,2 -> section,1: cde"');
section.removeChild(paragraph);
shouldBe('description(range)', '"section,0 -> section,0: "');
// Children in a range being removed, but by DOM mutation (not CharacterData mutation).
// Test CharacterData.replaceData cases?
// Test Element.innerHTML cases (setting it)?
// Test Element.innerText cases (setting it)?
// Test Element.outerHTML cases (setting it)?
// Test Element.outerText cases (setting it)?
// Test Node.replaceChild cases?
// Test cases where Node.insertBefore/appendChild has a side effect of deleting the node from a range.
// Test Range.deleteContents cases?
// Test Range.extractContents cases?
// Test Range.surroundContents cases?
// Test Text.replaceWholeText cases?
var successfullyParsed = true;
CONSOLE MESSAGE: line 17: Error: WRONG_DOCUMENT_ERR: DOM Exception 4
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
......
CONSOLE MESSAGE: line 17: Error: WRONG_DOCUMENT_ERR: DOM Exception 4
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
......
2008-03-15 Darin Adler <darin@apple.com>
Reviewed by Sam.
- fix http://bugs.webkit.org/show_bug.cgi?id=11997
Ranges are not fixed after mutation (affects Acid3 test 13)
Test: fast/dom/Range/mutation.html
* WebCore.xcodeproj/project.pbxproj: Added NodeWithIndex.h, NodeWithIndexAfter.h,
and NodeWithIndexBefore.h.
* dom/CharacterData.cpp:
(WebCore::CharacterData::setData): Replaced call to Document::removeMarkers
with call to Document::textRemoved.
(WebCore::CharacterData::insertData): Replaced call to Document::shiftMarkers
with call to Document::textInserted.
(WebCore::CharacterData::deleteData): Replaced call to Document::removeMarkers
and Document::shiftMarkers with call to Document::textRemoved.
(WebCore::CharacterData::replaceData): Replaced call to Document::removeMarkers
and Document::shiftMarkers with call to Document::textRemoved and
Document::textInserted.
(WebCore::CharacterData::containsOnlyWhitespace): Tweaked a bit.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::childrenChanged): Added a call to
Document::nodeChildrenChanged when the nmber of children was changed (and not
by the parser).
(WebCore::dispatchChildRemovalEvents): Updated for name change.
* dom/Document.cpp:
(WebCore::Document::~Document): Assert that all ranges are gone.
(WebCore::Document::nodeChildrenChanged): Added. Calls nodeChildrenChanged on
all ranges.
(WebCore::Document::nodeWillBeRemoved): Renamed from notifyBeforeNodeRemoval.
Added code to call nodeWillBeRemoved on all ranges.
(WebCore::Document::textInserted): Added. Calls textInserted on all ranges and
also calls shiftMarkers.
(WebCore::Document::textRemoved): Added. Calls textRemoved on all ranges and also
calls removeMarkers and shiftMarkers.
(WebCore::Document::textNodesMerged): Added. Calls textNodesMerged on all ranges.
(WebCore::Document::textNodeSplit): Added. Calls textNodeSplit on all ranges.
(WebCore::Document::attachRange): Added. Adds range to the HashSet of all ranges
for this document.
(WebCore::Document::detachRange): Added. Removes range from the HashSet.
* dom/Document.h: Added the new functions and the data member.
* dom/Element.cpp:
(WebCore::Element::normalizeAttributes): Added. Contains the part of the
normalize function that's specific to Element. Better encapsulation to have it
here rather than in Node::normalize.
* dom/Element.h: Added the new function.
* dom/Node.cpp:
(WebCore::Node::normalize): Rewrote so it's no longer recursive. Also added
a call to textNodesMerged after each pair of nodes is merged but before the
second node is removed.
(WebCore::Node::traverseNextNodePostOrder): Added. Helper function used by
normalize, but also useful elsewhere.
* dom/Node.h: Added the new function.
* dom/NodeIterator.cpp:
(WebCore::NodeIterator::nodeWillBeRemoved): Renamed from notifyBeforeNodeRemoval.
* dom/NodeIterator.h: Ditto.
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::setData): Call textRemoved.
* dom/Range.cpp:
(WebCore::NodeWithIndex::index): Added. Computes and stores index.
(WebCore::NodeWithIndexBefore::indexBefore): Added. Computes and stores index.
(WebCore::NodeWithIndexAfter::indexAfter): Added. Computes and stores index.
(WebCore::Range::Range): Call attachRange.
(WebCore::Range::~Range): Call detachRange unless the range is already detached.
(WebCore::Range::commonAncestorContainer): Removed check for WRONG_DOCUMENT_ERR.
It's no longer possible to create a range where the two containers are non-zero
and have no common ancestor.
(WebCore::Range::isPointInRange): Rewrote expression to be more readable.
(WebCore::Range::compareNode): Changed local variable to use int for consistency.
(WebCore::Range::compareBoundaryPoints): Replaced ASSERT with ASSERT_NOT_REACHED.
(WebCore::Range::deleteContents): Removed check for INVALID_STATE_ERR and
initialization of ec to 0; both are now inside checkDeleteExtract.
(WebCore::Range::intersectsNode): Changed local variable to use int for consistency.
Also changed comparison to use < 0 and >= 0 rather than checking explicitly for 1
and -1.
(WebCore::Range::processContents): Changed code to not get the nodeType multiple
times on the same node, and tweaked formatting. Removed code to update the range
on deletion, because the normal delete logic will take care of that now.
(WebCore::Range::extractContents): Removed check for INVALID_STATE_ERR and
initialization of ec to 0; both are now inside checkDeleteExtract.
(WebCore::Range::insertNode): Changed local variable to use int for consistency.
(WebCore::Range::toString): Changed variable name to pastLast.
(WebCore::Range::detach): Call detachRange.
(WebCore::Range::checkDeleteExtract): Added check for detached range and code to
set ec to 0; moved here from the two callers. Also changed variable name to pastLast.
(WebCore::endpointNodeChildrenChanged): Added.
(WebCore::Range::nodeChildrenChanged): Added.
(WebCore::endpointNodeWillBeRemoved): Added.
(WebCore::Range::nodeWillBeRemoved): Added.
(WebCore::endpointTextInserted): Added.
(WebCore::Range::textInserted): Added.
(WebCore::endpointTextRemoved): Added.
(WebCore::Range::textRemoved): Added.
(WebCore::endpointTextNodesMerged): Added.
(WebCore::Range::textNodesMerged): Added.
(WebCore::endpointTextNodesSplit): Added.
(WebCore::Range::textNodeSplit): Added.
* dom/Range.h: Added new member functions.
* dom/NodeWithIndex.h: Added. Makes it so we won't find the index for the same
node more than once.
* dom/NodeWithIndexAfter.h: Added. Similar to NodeWithIndex but gives the index after a
node and treats a node pointer of 0 as meaning "before first node in parent container".
* dom/NodeWithIndexBefore.h: Added. Similar to NodeWithIndex but treats a node pointer of 0
as meaning "after last node in parent container".
* dom/Text.cpp:
(WebCore::Text::splitText): Call textNodeSplit.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyInlineStyle): Changed variable name to pastLast.
2008-03-15 Julien Chaffraix <julien.chaffraix@gmail.com>
Reviewed by Holger.
......@@ -1611,6 +1611,9 @@
9380F47309A11AB4001FDB34 /* Widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47109A11AB4001FDB34 /* Widget.cpp */; };
9380F47409A11AB4001FDB34 /* Widget.h in Headers */ = {isa = PBXBuildFile; fileRef = 9380F47209A11AB4001FDB34 /* Widget.h */; settings = {ATTRIBUTES = (Private, ); }; };
9380F47809A11ACC001FDB34 /* WidgetMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47709A11ACC001FDB34 /* WidgetMac.mm */; };
9382AAB40D8C386100F357A6 /* NodeWithIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB10D8C386100F357A6 /* NodeWithIndex.h */; };
9382AAB50D8C386100F357A6 /* NodeWithIndexBefore.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */; };
9382AAB60D8C386100F357A6 /* NodeWithIndexAfter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */; };
93831B570D087D6000E5C984 /* ExceptionCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93831B560D087D6000E5C984 /* ExceptionCode.cpp */; };
938E65F109F09840008A48EC /* JSHTMLElementWrapperFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */; };
938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */; };
......@@ -5920,6 +5923,9 @@
9380F47109A11AB4001FDB34 /* Widget.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Widget.cpp; sourceTree = "<group>"; };
9380F47209A11AB4001FDB34 /* Widget.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Widget.h; sourceTree = "<group>"; };
9380F47709A11ACC001FDB34 /* WidgetMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetMac.mm; sourceTree = "<group>"; };
9382AAB10D8C386100F357A6 /* NodeWithIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndex.h; sourceTree = "<group>"; };
9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndexBefore.h; sourceTree = "<group>"; };
9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWithIndexAfter.h; sourceTree = "<group>"; };
93831B560D087D6000E5C984 /* ExceptionCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionCode.cpp; sourceTree = "<group>"; };
938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLElementWrapperFactory.h; sourceTree = "<group>"; };
938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLElementWrapperFactory.cpp; sourceTree = "<group>"; };
......@@ -12573,6 +12579,9 @@
1A750D870A90E394000FF215 /* NodeIterator.idl */,
A81872100977D3C0005826D9 /* NodeList.h */,
85ACA9FA0A9B631000671E90 /* NodeList.idl */,
9382AAB10D8C386100F357A6 /* NodeWithIndex.h */,
9382AAB20D8C386100F357A6 /* NodeWithIndexBefore.h */,
9382AAB30D8C386100F357A6 /* NodeWithIndexAfter.h */,
A8EA7EB70A1945D000A8EF5F /* Notation.cpp */,
A8EA7EB60A1945D000A8EF5F /* Notation.h */,
93EEC1F409C2877700C515D1 /* Notation.idl */,
......@@ -14545,6 +14554,9 @@
A9D248010D757E6900FDF959 /* JSPluginArray.h in Headers */,
A9D248070D757E7D00FDF959 /* JSMimeType.h in Headers */,
A9D248090D757E7D00FDF959 /* JSMimeTypeArray.h in Headers */,
9382AAB40D8C386100F357A6 /* NodeWithIndex.h in Headers */,
9382AAB50D8C386100F357A6 /* NodeWithIndexBefore.h in Headers */,
9382AAB60D8C386100F357A6 /* NodeWithIndexAfter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -38,10 +38,10 @@ CharacterData::CharacterData(Document *doc)
{
}
CharacterData::CharacterData(Document *doc, const String &_text)
: EventTargetNode(doc)
CharacterData::CharacterData(Document* document, const String& text)
: EventTargetNode(document)
{
m_data = _text.impl() ? _text.impl() : StringImpl::empty();
m_data = text.impl() ? text.impl() : StringImpl::empty();
}
CharacterData::~CharacterData()
......@@ -59,6 +59,7 @@ void CharacterData::setData(const String& data, ExceptionCode& ec)
if (equal(m_data.get(), data.impl()))
return;
int oldLength = length();
RefPtr<StringImpl> oldStr = m_data;
m_data = data.impl();
......@@ -70,10 +71,10 @@ void CharacterData::setData(const String& data, ExceptionCode& ec)
dispatchModifiedEvent(oldStr.get());
document()->removeMarkers(this);
document()->textRemoved(this, 0, oldLength);
}
String CharacterData::substringData( const unsigned offset, const unsigned count, ExceptionCode& ec)
String CharacterData::substringData(unsigned offset, unsigned count, ExceptionCode& ec)
{
ec = 0;