Commit bc157d8b authored by mrowe@apple.com's avatar mrowe@apple.com

Fix <https://bugs.webkit.org/show_bug.cgi?id=15106>.

Bug 15106: REGRESSION: Can't drag text as element when user-select is set to none

Reviewed by Dan Bernstein.

We allow selections to begin within an element that has -webkit-user-select: none set,
unless the element is draggable as dragging should take priority over starting a selection.

Test: editing/selection/user-drag-element-and-user-select-none.html

* dom/Node.cpp:
(WebCore::Node::canStartSelection):

Test for <https://bugs.webkit.org/show_bug.cgi?id=15106>.
Bug 15106: REGRESSION: Can't drag text as element when user-select is set to none

* editing/selection/user-drag-element-and-user-select-none-expected.txt: Added.
* editing/selection/user-drag-element-and-user-select-none.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44902 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e2948901
2009-06-20 Mark Rowe <mrowe@apple.com>
Reviewed by Dan Bernstein.
Test for <https://bugs.webkit.org/show_bug.cgi?id=15106>.
Bug 15106: REGRESSION: Can't drag text as element when user-select is set to none
* editing/selection/user-drag-element-and-user-select-none-expected.txt: Added.
* editing/selection/user-drag-element-and-user-select-none.html: Added.
2009-06-20 Darin Adler <darin@apple.com>
Reviewed by Dan Bernstein.
......
Test for WebKit bug 15106: Dragging text inside an element with "user-drag: element" and "user-select: none" should initiate a drag
SUCCESS Expected 'mousedown' and got it.
SUCCESS Expected 'mouseup' and got it.
SUCCESS Expected 'Selection' and got it.
This element should be draggable, but initiating a drag from within the text should begin a selection.
SUCCESS Expected 'mousedown' and got it.
SUCCESS Expected 'mouseup' and got it.
SUCCESS Expected 'No selection' and got it.
This element should not be draggable, and initiating a drag from within the text should not begin a selection.
SUCCESS Expected 'mousedown' and got it.
SUCCESS Expected 'dragstart' and got it.
SUCCESS Expected 'mouseup' and got it.
SUCCESS Expected 'No selection' and got it.
SUCCESS Expected 'mouseup' and got it.
SUCCESS Expected 'No selection' and got it.
This element should be draggable, and initiating a drag from within the text should drag the element.
<html>
<head>
<title>Test for WebKit bug 15106: Dragging text inside an element with "user-drag: element" and "user-select: none" should initiate a drag</title>
<style type="text/css">
.test {
background-color: #ccc;
border: 1px solid #333;
width: 200px;
text-align: center;
margin: 10px;
}
.result {
float: right;
}
body > div {
clear: both;
padding-top: 15px;
}
#draggable {
-webkit-user-drag: element;
}
#unselectable {
-webkit-user-select: none;
}
#draggable-unselectable {
-webkit-user-drag: element;
-webkit-user-select: none;
}
.fail {
color: red;
}
.success {
color: green;
}
</style>
<script type="text/javascript">
function shouldBe(resultElement, expected, actual) {
var msg = document.createElement('p');
if (expected == actual) {
msg.innerHTML = "<span class='success'>SUCCESS</span> Expected '" + expected + "' and got it.";
} else {
msg.innerHTML = "<span class='fail'>FAIL</span> Expected '" + expected + "' but got '" + actual + "'.";
}
resultElement.appendChild(msg);
}
function compareResults(id, expectedResult, actualResult) {
var resultElement = document.getElementById(id + '-result');
for (var i = 0; i < expectedResult.length; i++) {
shouldBe(resultElement, expectedResult[i], actualResult[i]);
}
}
function registerEventListenersWithResults(resultArray) {
document.ondragstart = function() {
resultArray.push('dragstart');
}
document.onmousedown = function(event) {
resultArray.push('mousedown');
}
document.onmouseup = function(event) {
resultArray.push('mouseup');
resultArray.push(window.getSelection().toString() == '' ? 'No selection' : 'Selection');
}
}
function dragFromTopOfElement(element, dragOffset) {
var startX = element.offsetLeft + element.offsetWidth / 2;
var startY = element.offsetTop + 1.0;
eventSender.mouseMoveTo(startX, startY);
eventSender.mouseDown();
eventSender.mouseMoveTo(startX, startY);
var endX = startX + dragOffset.x;
var endY = startY + dragOffset.y;
eventSender.mouseMoveTo(endX, endY);
eventSender.mouseUp()
}
function runTest() {
if (!window.eventSender)
return;
if (window.layoutTestController)
layoutTestController.dumpAsText();
var draggableResults = [];
registerEventListenersWithResults(draggableResults);
var draggable = document.getElementById('draggable');
dragFromTopOfElement(draggable, {x: 0, y: draggable.offsetHeight / 2});
compareResults("draggable", ["mousedown", "mouseup", "Selection"], draggableResults);
var unselectableResults = [];
registerEventListenersWithResults(unselectableResults);
var unselectable = document.getElementById('unselectable');
dragFromTopOfElement(unselectable, {x: 0, y: unselectable.offsetHeight / 2});
compareResults("unselectable", ["mousedown", "mouseup", "No selection"], unselectableResults);
var draggableUnselectableResults = [];
registerEventListenersWithResults(draggableUnselectableResults);
var draggableUnselectable = document.getElementById('draggable-unselectable');
dragFromTopOfElement(draggableUnselectable, {x: 0, y: draggableUnselectable.offsetHeight / 2});
// The second "mouseup" event that is fired here is something of a mystery, but doesn't appear relevant to what this is testing
compareResults("draggable-unselectable", ["mousedown", "dragstart", "mouseup", "No selection", "mouseup", "No selection"], draggableUnselectableResults);
}
</script>
</head>
<body onload="runTest()">
<h3>Test for <a href='https://bugs.webkit.org/show_bug.cgi?id=15106'>WebKit bug 15106</a>: Dragging text inside an element with "user-drag: element" and "user-select: none" should initiate a drag</h3>
<div>
<div id="draggable-result" class="result"></div>
<div id="draggable" class="test">
This element should be draggable, but initiating a drag from within the text should begin a selection.
</div>
</div>
<div>
<div id="unselectable-result" class="result"></div>
<div id="unselectable" class="test">
This element should not be draggable, and initiating a drag from within the text should not begin a selection.
</div>
</div>
<div>
<div id="draggable-unselectable-result" class="result"></div>
<div id="draggable-unselectable" class="test">
This element should be draggable, and initiating a drag from within the text should drag the element.
</div>
</div>
</body>
</html>
2009-06-20 Mark Rowe <mrowe@apple.com>
Reviewed by Dan Bernstein.
Fix <https://bugs.webkit.org/show_bug.cgi?id=15106>.
Bug 15106: REGRESSION: Can't drag text as element when user-select is set to none
We allow selections to begin within an element that has -webkit-user-select: none set,
unless the element is draggable as dragging should take priority over starting a selection.
Test: editing/selection/user-drag-element-and-user-select-none.html
* dom/Node.cpp:
(WebCore::Node::canStartSelection):
2009-06-20 Darin Adler <darin@apple.com>
Reviewed by Dan Bernstein.
......
......@@ -1359,6 +1359,14 @@ bool Node::canStartSelection() const
{
if (isContentEditable())
return true;
if (renderer()) {
RenderStyle* style = renderer()->style();
// We allow selections to begin within an element that has -webkit-user-select: none set,
// but if the element is draggable then dragging should take priority over selection.
if (style->userDrag() == DRAG_ELEMENT && style->userSelect() == SELECT_NONE)
return false;
}
return parent() ? parent()->canStartSelection() : 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