Commit 94fbb1f9 authored by oliver's avatar oliver

2007-03-11 Oliver Hunt <oliver@apple.com>

        Reviewed by hyatt.

        Fix for <rdar://problem/5055690> ASSERTION failure on drop into 
        editable element with content changed on drop 

        After setting the selection for a drop into an editable region 
        we make sure the we succeeded.  If we didn't we assume a focus handler
        or similar altered the element contents and try again, if the second
        attempt fails we bail out.

        * page/DragController.cpp:
        (WebCore::setSelectionToDragCaret):
        (WebCore::DragController::concludeDrag):

LayoutTests:
        <rdar://problem/5055690> ASSERTION failure on drop into editable element with content changed on drop

        * fast/events/content-changed-during-drop-expected.txt: Added.
        * fast/events/content-changed-during-drop.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20109 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7bb7dc3d
2007-03-11 Oliver Hunt <oliver@apple.com>
Reviewed by hyatt.
<rdar://problem/5055690> ASSERTION failure on drop into editable element with content changed on drop
* fast/events/content-changed-during-drop-expected.txt: Added.
* fast/events/content-changed-during-drop.html: Added.
2007-03-11 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
This tests that we don't lose data dropped onto an input field that changes its content during a drop event
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS dragTarget.value is elementToDrag.href
PASS Didn't crash.
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<script>
var successfullyParsed = false;
function resetField()
{
event.target.value = '';
}
function runTest()
{
if (window.layoutTestController) {
layoutTestController.dumpAsText();
elementToDrag = document.getElementById("elementToDrag");
x1 = elementToDrag.offsetLeft + elementToDrag.offsetWidth / 2;
y1 = elementToDrag.offsetTop + elementToDrag.offsetHeight / 2;
dragTarget = document.getElementById("dragTarget");
x2 = dragTarget.offsetLeft + dragTarget.offsetWidth / 2;
y2 = dragTarget.offsetTop + dragTarget.offsetHeight / 2;
eventSender.mouseMoveTo(x1,y1);
eventSender.mouseDown();
eventSender.leapForward(400);
eventSender.mouseMoveTo(x2, y2);
eventSender.mouseUp();
shouldBe("dragTarget.value", "elementToDrag.href");
testPassed("Didn't crash.");
//clean up output
elementToDrag.parentNode.removeChild(elementToDrag);
dragTarget.parentNode.removeChild(dragTarget);
} else {
debug('<br>To test this manually drag the link into the text field.')
}
}
</script>
</head>
<body>
<p id="description"></p>
<a id="elementToDrag" href="http://example.com">A link!</a>
<input id="dragTarget" type="text" value="Original Text" onfocus="resetField()" />
<div id="console"></div>
<script>
description("This tests that we don't lose data dropped onto an input field that changes its content during a drop event");
runTest();
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
\ No newline at end of file
2007-03-11 Oliver Hunt <oliver@apple.com>
Reviewed by hyatt.
Fix for <rdar://problem/5055690> ASSERTION failure on drop into
editable element with content changed on drop
After setting the selection for a drop into an editable region
we make sure the we succeeded. If we didn't we assume a focus handler
or similar altered the element contents and try again, if the second
attempt fails we bail out.
* page/DragController.cpp:
(WebCore::setSelectionToDragCaret):
(WebCore::DragController::concludeDrag):
2007-03-11 Oliver Hunt <oliver@apple.com>
Reviewed by Adele.
......
......@@ -298,6 +298,17 @@ DragOperation DragController::operationForLoad(DragData* dragData)
return dragOperation(dragData);
}
static bool setSelectionToDragCaret(Frame* frame, Selection& dragCaret, RefPtr<Range>& range, const IntPoint& point)
{
frame->selectionController()->setSelection(dragCaret);
if (frame->selectionController()->isNone()) {
dragCaret = visiblePositionForPoint(frame, point);
frame->selectionController()->setSelection(dragCaret);
range = dragCaret.toRange();
}
return !frame->selectionController()->isNone();
}
bool DragController::concludeDrag(DragData* dragData, DragDestinationAction actionMask)
{
ASSERT(dragData);
......@@ -351,8 +362,8 @@ bool DragController::concludeDrag(DragData* dragData, DragDestinationAction acti
&& dragData->canSmartReplace();
applyCommand(new MoveSelectionCommand(fragment, dragCaret.base(), smartMove));
} else {
innerFrame->selectionController()->setSelection(dragCaret);
applyCommand(new ReplaceSelectionCommand(m_document, fragment, true, dragData->canSmartReplace(), chosePlainText));
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
applyCommand(new ReplaceSelectionCommand(m_document, fragment, true, dragData->canSmartReplace(), chosePlainText));
}
} else {
String text = dragData->asPlainText();
......@@ -360,8 +371,8 @@ bool DragController::concludeDrag(DragData* dragData, DragDestinationAction acti
return false;
m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
innerFrame->selectionController()->setSelection(dragCaret);
applyCommand(new ReplaceSelectionCommand(m_document, createFragmentFromText(range.get(), text), true, false, true));
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
applyCommand(new ReplaceSelectionCommand(m_document, createFragmentFromText(range.get(), text), true, false, true));
}
return true;
......
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