Bug 1359371 - Update Selection.webidl to match spec draft
authorAryeh Gregor <ayg@aryeh.name>
Tue, 25 Apr 2017 14:55:31 +0300
changeset 568041 a3dd9cf536609e79a607929694e79bd6b3c058ac
parent 567252 62a2d3693579fc77b1c510984ae471a860d03302
child 568044 c3f74762f56080c649ba8739f1857aaf5d5c59a6
push id55735
push userbmo:ayg@aryeh.name
push dateTue, 25 Apr 2017 17:39:01 +0000
bugs1359371
milestone55.0a1
Bug 1359371 - Update Selection.webidl to match spec Practical changes: 1) Some additional method arguments are nullable or optional, which matches Chrome/WebKit. They make more sense non-nullable and non-optional, but Chrome is afraid of the compat impact of changing. 2) Added [CEReactions] to deleteFromDocument(). MozReview-Commit-ID: Kg9EDubnEui
dom/webidl/Selection.webidl
layout/generic/Selection.h
layout/generic/nsSelection.cpp
testing/web-platform/meta/selection/interfaces.html.ini
testing/web-platform/tests/selection/interfaces.html
--- a/dom/webidl/Selection.webidl
+++ b/dom/webidl/Selection.webidl
@@ -6,57 +6,54 @@
  * The origin of this IDL file is
  * https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#concept-selection
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface Selection {
-  readonly attribute Node? anchorNode;
+  readonly attribute Node?         anchorNode;
   readonly attribute unsigned long anchorOffset;
-  readonly attribute Node? focusNode;
+  readonly attribute Node?         focusNode;
   readonly attribute unsigned long focusOffset;
-
-  readonly attribute boolean isCollapsed;
-  [Throws, BinaryName="collapseJS"]
-  void               collapse(Node node, unsigned long offset);
-  [Throws, BinaryName="collapseToStartJS"]
-  void               collapseToStart();
-  [Throws, BinaryName="collapseToEndJS"]
-  void               collapseToEnd();
-
-  [Throws, BinaryName="extendJS"]
-  void               extend(Node node, unsigned long offset);
-
-  [Throws, BinaryName="selectAllChildrenJS"]
-  void               selectAllChildren(Node node);
+  readonly attribute boolean       isCollapsed;
+  readonly attribute unsigned long rangeCount;
+  //readonly attribute DOMString     type;
+  [Throws]
+  Range     getRangeAt(unsigned long index);
+  [Throws, BinaryName="addRangeJS"]
+  void      addRange(Range range);
+  [Throws]
+  void      removeRange(Range range);
   [Throws]
-  void               deleteFromDocument();
-
-  readonly attribute unsigned long rangeCount;
-  [Throws]
-  Range              getRangeAt(unsigned long index);
-  [Throws, BinaryName="addRangeJS"]
-  void               addRange(Range range);
-  [Throws]
-  void               removeRange(Range range);
+  void      removeAllRanges();
+  //void      empty();
+  [Throws, BinaryName="collapseJS"]
+  void      collapse(Node? node, optional unsigned long offset = 0);
+  //void      setPosition(Node? node, optional unsigned long offset = 0);
+  [Throws, BinaryName="collapseToStartJS"]
+  void      collapseToStart();
+  [Throws, BinaryName="collapseToEndJS"]
+  void      collapseToEnd();
+  [Throws, BinaryName="extendJS"]
+  void      extend(Node node, optional unsigned long offset = 0);
+  [Throws, BinaryName="setBaseAndExtentJS"]
+  void      setBaseAndExtent(Node anchorNode,
+                             unsigned long anchorOffset,
+                             Node focusNode,
+                             unsigned long focusOffset);
+  [Throws, BinaryName="selectAllChildrenJS"]
+  void      selectAllChildren(Node node);
+  [CEReactions, Throws]
+  void      deleteFromDocument();
   [Throws]
-  void               removeAllRanges();
-
-  [Throws]
-  boolean            containsNode(Node node, boolean allowPartialContainment);
-
-  [Throws, BinaryName="setBaseAndExtentJS"]
-  void               setBaseAndExtent(Node anchorNode,
-                                      unsigned long anchorOffset,
-                                      Node focusNode,
-                                      unsigned long focusOffset);
-
-  stringifier;
+  boolean   containsNode(Node node,
+                         optional boolean allowPartialContainment = false);
+  stringifier DOMString ();
 };
 
 // Additional methods not currently in the spec
 partial interface Selection {
   [Throws]
   void modify(DOMString alter, DOMString direction,
               DOMString granularity);
 };
--- a/layout/generic/Selection.h
+++ b/layout/generic/Selection.h
@@ -173,17 +173,17 @@ public:
   nsINode*     GetFocusNode();
   uint32_t     FocusOffset();
 
   bool IsCollapsed() const;
 
   // *JS() methods are mapped to Selection.*().
   // They may move focus only when the range represents normal selection.
   // These methods shouldn't be used by non-JS callers.
-  void CollapseJS(nsINode& aNode, uint32_t aOffset,
+  void CollapseJS(nsINode* aNode, uint32_t aOffset,
                   mozilla::ErrorResult& aRv);
   void CollapseToStartJS(mozilla::ErrorResult& aRv);
   void CollapseToEndJS(mozilla::ErrorResult& aRv);
 
   void ExtendJS(nsINode& aNode, uint32_t aOffset,
                 mozilla::ErrorResult& aRv);
 
   void SelectAllChildrenJS(nsINode& aNode, mozilla::ErrorResult& aRv);
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -5167,21 +5167,25 @@ Selection::Collapse(nsIDOMNode* aParentN
 
 NS_IMETHODIMP
 Selection::CollapseNative(nsINode* aParentNode, int32_t aOffset)
 {
   return Collapse(aParentNode, aOffset);
 }
 
 void
-Selection::CollapseJS(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
+Selection::CollapseJS(nsINode* aNode, uint32_t aOffset, ErrorResult& aRv)
 {
   AutoRestore<bool> calledFromJSRestorer(mCalledByJS);
   mCalledByJS = true;
-  Collapse(aNode, aOffset, aRv);
+  if (!aNode) {
+    RemoveAllRanges(aRv);
+    return;
+  }
+  Collapse(*aNode, aOffset, aRv);
 }
 
 nsresult
 Selection::Collapse(nsINode* aParentNode, int32_t aOffset)
 {
   if (!aParentNode)
     return NS_ERROR_INVALID_ARG;
 
--- a/testing/web-platform/meta/selection/interfaces.html.ini
+++ b/testing/web-platform/meta/selection/interfaces.html.ini
@@ -1,28 +1,19 @@
 [interfaces.html]
   type: testharness
   [Selection interface: attribute type]
     expected: FAIL
 
   [Selection interface: operation empty()]
     expected: FAIL
 
-  [Selection interface: operation collapse(Node,unsigned long)]
-    expected: FAIL
-
   [Selection interface: operation setPosition(Node,unsigned long)]
     expected: FAIL
 
-  [Selection interface: operation extend(Node,unsigned long)]
-    expected: FAIL
-
-  [Selection interface: operation containsNode(Node,boolean)]
-    expected: FAIL
-
   [Selection interface: getSelection() must inherit property "type" with the proper type (6)]
     expected: FAIL
 
   [Selection interface: getSelection() must inherit property "empty" with the proper type (11)]
     expected: FAIL
 
   [Selection interface: getSelection() must inherit property "setPosition" with the proper type (13)]
     expected: FAIL
--- a/testing/web-platform/tests/selection/interfaces.html
+++ b/testing/web-platform/tests/selection/interfaces.html
@@ -1,17 +1,17 @@
 <!doctype html>
 <title>Selection interface tests</title>
 <div id=log></div>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script src=/resources/WebIDLParser.js></script>
 <script src=/resources/idlharness.js></script>
 <script type=text/plain>
-// https://www.w3.org/TR/2016/WD-selection-api-20161206/
+// http://w3c.github.io/selection-api/#selection-interface
 interface Selection {
     readonly attribute Node?         anchorNode;
     readonly attribute unsigned long anchorOffset;
     readonly attribute Node?         focusNode;
     readonly attribute unsigned long focusOffset;
     readonly attribute boolean       isCollapsed;
     readonly attribute unsigned long rangeCount;
     readonly attribute DOMString     type;