Commit ac637289 authored by justing's avatar justing

LayoutTests:

        Reviewed by oliver
        
        <rdar://problem/5156401> 
        Crash when dragging text into a link inside a table cell

        Test for the crash:
        * editing/pasteboard/5156401-1-expected.checksum: Added.
        * editing/pasteboard/5156401-1-expected.png: Added.
        * editing/pasteboard/5156401-1-expected.txt: Added.
        * editing/pasteboard/5156401-1.html: Added.
        
        Test inserting at the end of a link where we would previously
        insert in the wrong paragraph:
        * editing/inserting/5156401-2-expected.checksum: Added.
        * editing/inserting/5156401-2-expected.png: Added.
        * editing/inserting/5156401-2-expected.txt: Added.
        * editing/inserting/5156401-2.html: Added.

WebCore:

        Reviewed by oliver
        
        <rdar://problem/5156401> 
        Crash when dragging text into a link inside a table cell

        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary):
        Don't avoid the anchor if doing so would skip over a line break, that
        would put content in the wrong paragraph, which can throw ReplaceSelectionCommand,
        which relies on moveParagraphs into infinite recursion.
        Renamed the input position.
        Don't need to re-fetch the enclosing anchor when preparing to push it down,
        since it hasn't changed since the top of the function.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21078 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bd9361b8
2007-04-24 Justin Garcia <justin.garcia@apple.com>
Reviewed by oliver
<rdar://problem/5156401>
Crash when dragging text into a link inside a table cell
Test for the crash:
* editing/pasteboard/5156401-1-expected.checksum: Added.
* editing/pasteboard/5156401-1-expected.png: Added.
* editing/pasteboard/5156401-1-expected.txt: Added.
* editing/pasteboard/5156401-1.html: Added.
Test inserting at the end of a link where we would previously
insert in the wrong paragraph:
* editing/inserting/5156401-2-expected.checksum: Added.
* editing/inserting/5156401-2-expected.png: Added.
* editing/inserting/5156401-2-expected.txt: Added.
* editing/inserting/5156401-2.html: Added.
2007-04-24 Darin Adler <darin@apple.com>
Reviewed by Justin.
......@@ -7,10 +7,12 @@ layer at (0,0) size 800x600
RenderListItem {LI} at (40,0) size 744x18
RenderListMarker at (-17,0) size 7x18: bullet
RenderInline {A} at (0,0) size 736x18 [color=#0000EE]
RenderText {#text} at (0,0) size 736x18
text run at (0,0) width 336: "This tests for a crash when creating a list from a link. "
text run at (336,0) width 400: "This paragraph should be a link and should be inside a list item."
RenderText {#text} at (0,0) size 0x0
RenderInline {SPAN} at (0,0) size 736x18 [color=#000000]
RenderInline {A} at (0,0) size 736x18 [color=#0000EE]
RenderText {#text} at (0,0) size 736x18
text run at (0,0) width 336: "This tests for a crash when creating a list from a link. "
text run at (336,0) width 400: "This paragraph should be a link and should be inside a list item."
RenderText {#text} at (0,0) size 0x0
RenderBlock (anonymous) at (0,34) size 784x0
selection start: position 0 of child 0 {#text} of child 0 {A} of child 0 {LI} of child 0 {UL} of child 0 {BODY} of child 0 {HTML} of document
selection end: position 123 of child 0 {#text} of child 0 {A} of child 0 {LI} of child 0 {UL} of child 0 {BODY} of child 0 {HTML} of document
selection start: position 0 of child 0 {#text} of child 0 {A} of child 0 {SPAN} of child 0 {A} of child 0 {LI} of child 0 {UL} of child 0 {BODY} of child 0 {HTML} of document
selection end: position 123 of child 0 {#text} of child 0 {A} of child 0 {SPAN} of child 0 {A} of child 0 {LI} of child 0 {UL} of child 0 {BODY} of child 0 {HTML} of document
e260b39f6f4aa054c0f78291f6191950
\ No newline at end of file
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 628x18
text run at (0,0) width 628: "This tests for a bug where inserting at the end of a link would place content in the wrong paragraph."
RenderBlock {DIV} at (0,34) size 784x18
RenderInline {A} at (0,0) size 420x18 [color=#0000EE]
RenderText {#text} at (0,0) size 420x18
text run at (0,0) width 420: "Everything in this editable region should be in the same paragraph."
RenderBR {BR} at (420,14) size 0x0
caret: position 67 of child 0 {#text} of child 0 {A} of child 3 {DIV} of child 0 {BODY} of child 0 {HTML} of document
<body>
<p>This tests for a bug where inserting at the end of a link would place content in the wrong paragraph.</p>
<div contenteditable="true"><a id="link" href="#">Everything&nbsp;<br></a></div>
<script>
var sel = window.getSelection();
var link = document.getElementById("link");
sel.setPosition(link, link.childNodes.length);
document.execCommand("InsertText", false, "in this editable region should be in the same paragraph.");
</script>
</body>
5b3fa8bff95996afa301fccaa74e1721
\ No newline at end of file
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 450x18
text run at (0,0) width 450: "This tests for a crash when pasting content into a link inside a table cell."
RenderBlock {DIV} at (0,34) size 784x28
RenderTable {TABLE} at (0,0) size 146x28 [border: (1px outset #808080)]
RenderTableSection {TBODY} at (1,1) size 144x26
RenderTableRow {TR} at (0,2) size 144x22
RenderTableCell {TD} at (2,2) size 140x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderInline {A} at (0,0) size 136x18 [color=#0000EE]
RenderText {#text} at (2,2) size 10x18
text run at (2,2) width 10: "T"
RenderText {#text} at (12,2) size 122x18
text run at (12,2) width 122: "his should be a link"
RenderInline {SPAN} at (0,0) size 4x18 [color=#000000]
RenderInline {A} at (0,0) size 4x18 [color=#0000EE]
RenderText {#text} at (134,2) size 4x18
text run at (134,2) width 4: "."
caret: position 20 of child 1 {#text} of child 0 {A} of child 0 {TD} of child 0 {TR} of child 0 {TBODY} of child 1 {TABLE} of child 3 {DIV} of child 0 {BODY} of child 0 {HTML} of document
<body>
<p>This tests for a crash when pasting content into a link inside a table cell.</p>
<div contenteditable="true">
<table border="1"><tr><td><a id="link" href="#">T.</a></td></tr></table>
</div>
<script>
var link = document.getElementById("link");
var text = link.firstChild;
var sel = window.getSelection();
sel.setPosition(text, 1);
document.execCommand("InsertHTML", false, "his should be a link");
</script>
</body>
2007-04-24 Justin Garcia <justin.garcia@apple.com>
Reviewed by oliver
<rdar://problem/5156401>
Crash when dragging text into a link inside a table cell
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary):
Don't avoid the anchor if doing so would skip over a line break, that
would put content in the wrong paragraph, which can throw ReplaceSelectionCommand,
which relies on moveParagraphs into infinite recursion.
Renamed the input position.
Don't need to re-fetch the enclosing anchor when preparing to push it down,
since it hasn't changed since the top of the function.
2007-04-24 Timothy Hatcher <timothy@apple.com>
Reviewed by Adam.
......@@ -835,14 +835,14 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
// that anchor, as in NSTextView.
// FIXME: This is only an approximation of NSTextViews insertion behavior, which varies depending on how
// the caret was made.
Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Position& p, bool alwaysAvoidAnchors)
Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Position& original, bool alwaysAvoidAnchors)
{
if (p.isNull())
return p;
if (original.isNull())
return original;
VisiblePosition visiblePos(p);
Node* enclosingAnchor = enclosingAnchorElement(p);
Position result = p;
VisiblePosition visiblePos(original);
Node* enclosingAnchor = enclosingAnchorElement(original);
Position result = original;
// Don't avoid block level anchors, because that would insert content into the wrong paragraph.
if (enclosingAnchor && !isBlock(enclosingAnchor)) {
VisiblePosition firstInAnchor(Position(enclosingAnchor, 0));
......@@ -852,11 +852,16 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
if (visiblePos == lastInAnchor && (isEndOfDocument(visiblePos) || alwaysAvoidAnchors)) {
// Make sure anchors are pushed down before avoiding them so that we don't
// also avoid structural elements like lists and blocks (5142012).
if (Node* anchor = enclosingAnchorElement(p))
if (p.node() != anchor && p.node()->parentNode() != anchor) {
pushAnchorElementDown(anchor);
enclosingAnchor = enclosingAnchorElement(p);
}
if (original.node() != enclosingAnchor && original.node()->parentNode() != enclosingAnchor) {
pushAnchorElementDown(enclosingAnchor);
enclosingAnchor = enclosingAnchorElement(original);
}
// Don't insert outside an anchor if doing so would skip over a line break. It would
// probably be safe to move the line break so that we could still avoid the anchor here.
Position downstream(visiblePos.deepEquivalent().downstream());
if (lineBreakExistsAtPosition(visiblePos) && downstream.node()->isDescendantOf(enclosingAnchor))
return original;
result = positionAfterNode(enclosingAnchor);
}
// If visually just before an anchor, insert *outside* the anchor unless it's the first
......@@ -864,17 +869,16 @@ Position CompositeEditCommand::positionAvoidingSpecialElementBoundary(const Posi
if (visiblePos == firstInAnchor && (!isStartOfParagraph(visiblePos) || alwaysAvoidAnchors)) {
// Make sure anchors are pushed down before avoiding them so that we don't
// also avoid structural elements like lists and blocks (5142012).
if (Node* anchor = enclosingAnchorElement(p))
if (p.node() != anchor && p.node()->parentNode() != anchor) {
pushAnchorElementDown(anchor);
enclosingAnchor = enclosingAnchorElement(p);
}
if (original.node() != enclosingAnchor && original.node()->parentNode() != enclosingAnchor) {
pushAnchorElementDown(enclosingAnchor);
enclosingAnchor = enclosingAnchorElement(original);
}
result = positionBeforeNode(enclosingAnchor);
}
}
if (result.isNull() || !editableRootForPosition(result))
result = p;
result = original;
return result;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment