Commit 87e62f7f authored by dcheng@chromium.org's avatar dcheng@chromium.org

Don't always select images during an image drag.

https://bugs.webkit.org/show_bug.cgi?id=62998

Reviewed by Tony Chang.

Source/WebCore:

Only select an image being dragged if it is contenteditable.

Test: fast/events/drag-selects-image.html

* dom/Node.cpp:
(WebCore::Node::isContentRichlyEditable):
* dom/Node.h:
* page/DragController.cpp:
(WebCore::prepareClipboardForImageDrag):

LayoutTests:

* fast/events/drag-selects-image-expected.txt: Added.
* fast/events/drag-selects-image.html: Added.
* platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt:
* platform/chromium/test_expectations.txt:
* platform/mac/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/mac/editing/selection/drag-to-contenteditable-iframe-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@97878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2619bfa6
2011-10-19 Daniel Cheng <dcheng@chromium.org>
Don't always select images during an image drag.
https://bugs.webkit.org/show_bug.cgi?id=62998
Reviewed by Tony Chang.
* fast/events/drag-selects-image-expected.txt: Added.
* fast/events/drag-selects-image.html: Added.
* platform/chromium-win/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/chromium-win/editing/selection/drag-to-contenteditable-iframe-expected.txt:
* platform/chromium/test_expectations.txt:
* platform/mac/editing/pasteboard/drag-image-to-contenteditable-in-iframe-expected.txt:
* platform/mac/editing/selection/drag-to-contenteditable-iframe-expected.txt:
2011-10-19 Chang Shu <cshu@webkit.org>
[Qt] Disable fullscreen api on Qt by default
Non-editable area
Editable area
This tests that images are properly left selected or unselected when an image drag is started. Only the image in the editable area should be selected when an image drag is started.
Starting test...
0 range(s) selected
Dragging image in non-editable area...
0 range(s) selected
Dragging image in editable area...
1 range(s) selected
imageTwo is selected
<!DOCTYPE html>
<html>
<head>
<script>
function log(str)
{
var result = document.getElementById('result');
result.appendChild(document.createTextNode(str));
result.appendChild(document.createElement('br'));
}
function dragNowhere(element)
{
eventSender.mouseMoveTo(element.offsetLeft + element.offsetWidth / 2,
element.offsetTop + element.offsetHeight / 2);
eventSender.mouseDown();
eventSender.leapForward(100);
eventSender.mouseMoveTo(element.offsetLeft + 1, element.offsetHeight + 1);
eventSender.mouseUp();
}
window.onload = function()
{
if (!window.layoutTestController)
return;
layoutTestController.dumpAsText();
log('Starting test...');
log(window.getSelection().rangeCount + ' range(s) selected');
log('Dragging image in non-editable area...');
dragNowhere(document.getElementById('imageOne'));
log(window.getSelection().rangeCount + ' range(s) selected');
log('Dragging image in editable area...');
dragNowhere(document.getElementById('imageTwo'));
log(window.getSelection().rangeCount + ' range(s) selected');
if (window.getSelection().rangeCount && window.getSelection().containsNode(document.getElementById('imageTwo')))
log('imageTwo is selected');
}
</script>
</head>
<body>
<div>
<h3>Non-editable area</h3>
<img id="imageOne" src="resources/abe.png">
</div>
<div contenteditable="true">
<h3>Editable area</h3>
<img id="imageTwo" src="resources/onload-image.png">
</div>
<p>This tests that images are properly left selected or unselected when an image drag is started.
Only the image in the editable area should be selected when an image drag is started.
<div id="result">
</div>
</body>
</html>
......@@ -22,5 +22,3 @@ layer at (0,0) size 800x600
RenderImage {IMG} at (21,1) size 76x103
RenderText {#text} at (0,0) size 0x0
RenderBlock {UL} at (0,231) size 784x0
selection start: position 0 of child 3 {IMG} of body
selection end: position 1 of child 3 {IMG} of body
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document givenAction:WebViewInsertActionDropped
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document toDOMRange:range from 0 of BODY > HTML > #document to 1 of BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
......@@ -27,5 +26,3 @@ layer at (0,0) size 800x600
RenderListMarker at (-18,0) size 7x19: bullet
RenderText {#text} at (0,0) size 274x19
text run at (0,0) width 274: "Abe should be outside the frame and inside it."
selection start: position 0 of child 3 {IMG} of body
selection end: position 1 of child 3 {IMG} of body
......@@ -3876,3 +3876,7 @@ BUGWK70382 LEOPARD CPU-CG : fast/dom/blur-contenteditable.html = IMAGE
BUGWK70383 LEOPARD CPU-CG : editing/pasteboard/4944770-1.html = IMAGE
BUGWK70386 SNOWLEOPARD DEBUG : storage/domstorage/events/documentURI.html = PASS CRASH
// Waiting on new results
BUG_DCHENG : editing/pasteboard/drag-image-to-contenteditable-in-iframe.html = FAIL
BUG_DCHENG : editing/selection/drag-to-contenteditable-iframe.html = FAIL
2011-10-19 Daniel Cheng <dcheng@chromium.org>
Don't always select images during an image drag.
https://bugs.webkit.org/show_bug.cgi?id=62998
Reviewed by Tony Chang.
Only select an image being dragged if it is contenteditable.
Test: fast/events/drag-selects-image.html
* dom/Node.cpp:
(WebCore::Node::isContentRichlyEditable):
* dom/Node.h:
* page/DragController.cpp:
(WebCore::prepareClipboardForImageDrag):
2011-10-19 Andreas Kling <kling@webkit.org>
HTMLBodyElement: Simplify link/alink/vlink attribute parsing.
......@@ -775,6 +775,12 @@ bool Node::isContentEditable()
return rendererIsEditable(Editable);
}
bool Node::isContentRichlyEditable()
{
document()->updateLayoutIgnorePendingStylesheets();
return rendererIsEditable(RichlyEditable);
}
bool Node::rendererIsEditable(EditableLevel editableLevel) const
{
if (document()->frame() && document()->frame()->page() && document()->frame()->page()->isEditable() && !shadowTreeRootNode())
......
......@@ -342,6 +342,7 @@ public:
virtual Node* focusDelegate();
bool isContentEditable();
bool isContentRichlyEditable();
bool rendererIsEditable() const { return rendererIsEditable(Editable); }
bool rendererIsRichlyEditable() const { return rendererIsEditable(RichlyEditable); }
......
......@@ -614,14 +614,16 @@ static Image* getImage(Element* element)
cachedImage->imageForRenderer(element->renderer()) : 0;
}
static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
{
RefPtr<Range> range = src->document()->createRange();
ExceptionCode ec = 0;
range->selectNode(node, ec);
ASSERT(!ec);
src->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, src);
static void prepareClipboardForImageDrag(Frame* source, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
{
if (node->isContentRichlyEditable()) {
RefPtr<Range> range = source->document()->createRange();
ExceptionCode ec = 0;
range->selectNode(node, ec);
ASSERT(!ec);
source->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
}
clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, source);
}
static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage)
......
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