Use "allowed child" definition in another place
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Mon, 30 May 2011 14:42:47 -0600
changeset 205 dcfd88b08738
parent 204 9e4fccc76232
child 206 aaf63021736a
Use "allowed child" definition in another place

Also use collectContainedNodes() in an extra place.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Mon May 30 14:42:15 2011 -0600
+++ b/editcommands.html	Mon May 30 14:42:47 2011 -0600
@@ -4121,11 +4121,10 @@
   <li>Let <var title="">node list</var> be a list of <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>nodes</a>, initially empty.
 
   <li>For each <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> <var title="">node</var> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a> in <var title="">new range</var>,
-  if <var title="">node</var> is <a href=#editable>editable</a> and can be the <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of a
-  <code class=external data-anolis-spec=html title="the div element"><a href=http://www.whatwg.org/html/#the-div-element>div</a></code> or <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code> or <code class=external data-anolis-spec=html title="the ul element"><a href=http://www.whatwg.org/html/#the-ul-element>ul</a></code> and if no <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestor</a> of <var title="">node</var> is in
-  <var title="">node list</var>, append <var title="">node</var> to <var title="">node list</var>.
-
-  <p class=XXX>Use "allowed child" definition here.
+  if <var title="">node</var> is <a href=#editable>editable</a> and is an <a href=#allowed-child>allowed
+  child</a> of "div" or "ol" and if the last member of <var title="">node list</var>
+  (if any) is not an <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-ancestor title=concept-tree-ancestor>ancestor</a> of <var title="">node</var>, append <var title="">node</var> to
+  <var title="">node list</var>.
 
   <li>If the first member of <var title="">node list</var> is an <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> whose <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>
   is an <code class=external data-anolis-spec=html title="the ol element"><a href=http://www.whatwg.org/html/#the-ol-element>ol</a></code> or <code class=external data-anolis-spec=html title="the ul element"><a href=http://www.whatwg.org/html/#the-ul-element>ul</a></code>, and its <code class=external data-anolis-spec=domcore title=dom-Node-previousSibling><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-previoussibling>previousSibling</a></code> is an <code class=external data-anolis-spec=html title="the li element"><a href=http://www.whatwg.org/html/#the-li-element>li</a></code> as well,
--- a/implementation.js	Mon May 30 14:42:15 2011 -0600
+++ b/implementation.js	Mon May 30 14:42:47 2011 -0600
@@ -3022,27 +3022,13 @@
 		var nodeList = [];
 
 		// "For each node node contained in new range, if node is editable and
-		// can be the child of a div or ol or ul and if no ancestor of node is
-		// in node list, append node to node list."
-		for (var node = newRange.startContainer; node != nextNodeDescendants(newRange.endContainer); node = nextNode(node)) {
-			if (!isContained(node, newRange) || !isEditable(node)) {
-				continue;
-			}
-
-			if (node.nodeType == Node.ELEMENT_NODE
-			&& ["TBODY", "THEAD", "TR", "TH", "TD"].indexOf(node.tagName) != -1) {
-				continue;
-			}
-
-			// We only need to check that the last member isn't an ancestor,
-			// because no ancestor of a member can be in the list.
-			if (nodeList.length
-			&& isAncestor(nodeList[nodeList.length - 1], node)) {
-				continue;
-			}
-
-			nodeList.push(node);
-		}
+		// is an allowed child of "div" or "ol" and if the last member of node
+		// list (if any) is not an ancestor of node, append node to node list."
+		nodeList = collectContainedNodes(newRange, function(node) {
+			return isEditable(node)
+				&& (isAllowedChild(node, "div")
+				|| isAllowedChild(node, "ol"));
+		});
 
 		// "If the first member of node list is an li whose parent is an ol or
 		// ul, and its previousSibling is an li as well, normalize sublists of
--- a/source.html	Mon May 30 14:42:15 2011 -0600
+++ b/source.html	Mon May 30 14:42:47 2011 -0600
@@ -4147,11 +4147,10 @@
   <li>Let <var>node list</var> be a list of [[nodes]], initially empty.
 
   <li>For each [[node]] <var>node</var> [[contained]] in <var>new range</var>,
-  if <var>node</var> is <span>editable</span> and can be the [[child]] of a
-  [[div]] or [[ol]] or [[ul]] and if no [[ancestor]] of <var>node</var> is in
-  <var>node list</var>, append <var>node</var> to <var>node list</var>.
-
-  <p class=XXX>Use "allowed child" definition here.
+  if <var>node</var> is <span>editable</span> and is an <span>allowed
+  child</span> of "div" or "ol" and if the last member of <var>node list</var>
+  (if any) is not an [[ancestor]] of <var>node</var>, append <var>node</var> to
+  <var>node list</var>.
 
   <li>If the first member of <var>node list</var> is an [[li]] whose [[parent]]
   is an [[ol]] or [[ul]], and its [[previoussibling]] is an [[li]] as well,