Commit dec10236 authored by yoichio@chromium.org's avatar yoichio@chromium.org

Editing: Let Selection.collapse with null clears selection.

The current spec says Selection.collapse(null) raises exception and the 
implementation follows.
However, many web apps assume that chrome clears selection when 
Selection.collapse(null) calls.
Thus we revert the behavior.

BUG=395318

Review URL: https://codereview.chromium.org/546703003

git-svn-id: svn://svn.chromium.org/blink/trunk@181487 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f34d7210
Ensure that collapse with null clears selection
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS selection.rangeCount is 1
PASS selection.rangeCount is 0
PASS selection.rangeCount is 1
PASS selection.rangeCount is 0
PASS successfullyParsed is true
TEST COMPLETE
hello
<!DOCTYPE HTML>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<div id="div" contenteditable="true">hello</div>
<script>
description("Ensure that collapse with null clears selection");
var selection = getSelection();
selection.selectAllChildren(div);
selection.rangeCount
shouldBe("selection.rangeCount", "1");
selection.collapse(null);
shouldBe("selection.rangeCount", "0");
selection.collapse(div.firstChild, 2);
shouldBe("selection.rangeCount", "1");
selection.collapse(null);
shouldBe("selection.rangeCount", "0");
</script>
</body>
</html>
......@@ -197,10 +197,14 @@ int DOMSelection::rangeCount() const
void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionState)
{
ASSERT(node);
if (!m_frame)
return;
if (!node) {
m_frame->selection().clear();
return;
}
if (offset < 0) {
exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
return;
......
......@@ -45,7 +45,7 @@
readonly attribute long focusOffset;
readonly attribute boolean isCollapsed;
[RaisesException, TypeChecking=Interface] void collapse(Node node, optional long offset = 0);
[RaisesException] void collapse(Node? node, optional long offset = 0);
[RaisesException] void collapseToStart();
[RaisesException] void collapseToEnd();
......@@ -85,8 +85,7 @@
[Default=Undefined] optional long baseOffset,
[Default=Undefined] optional Node extentNode,
[Default=Undefined] optional long extentOffset);
[ImplementedAs=collapse, MeasureAs=SelectionSetPosition, RaisesException, TypeChecking=Interface] void setPosition(Node node,
optional long offset = 0);
[ImplementedAs=collapse, MeasureAs=SelectionSetPosition, RaisesException] void setPosition(Node? node, optional long offset = 0);
// IE extensions
// http://msdn.microsoft.com/en-us/library/ms535869(VS.85).aspx
......
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