Make only HTML elements editable
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 08 Nov 2011 12:17:45 -0700
changeset 668 f4f95c3f51d6
parent 667 fe389ca05561
child 669 e524fb46434e
Make only HTML elements editable

Plus non-element children of HTML elements, and <svg> and <math>
elements themselves (but not their children). SVG and MathML behave
differently, and it doesn't make sense for editing to mess with them.

I did rerun gentest.html, but there were no changes in the results.

Fixes: http://www.w3.org/Bugs/Public/show_bug.cgi?id=13893
editing.html
implementation.js
preprocess
source.html
--- a/editing.html	Tue Nov 08 12:17:22 2011 -0700
+++ b/editing.html	Tue Nov 08 12:17:45 2011 -0700
@@ -1635,15 +1635,16 @@
 <p>An <dfn id=inline-node>inline node</dfn> is a <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> that is not a <a href=#block-node>block
 node</a>.
 
-<p>An <dfn id=editing-host>editing host</dfn> is a <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> that is either an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with
-a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable>contenteditable</a></code>
-attribute set to the true state, or the <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> <a class=external data-anolis-spec=dom 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=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code>
-whose <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#designMode>designMode</a></code> is enabled.
-
-<p>Something is <dfn id=editable>editable</dfn> if it is a <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> which is not an
-<a href=#editing-host>editing host</a>, does not have a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable>contenteditable</a></code> attribute set to the false
-state, and whose <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a> is an <a href=#editing-host>editing host</a> or
-<a href=#editable>editable</a>.
+<p>An <dfn id=editing-host>editing host</dfn> is a <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> that is either an <a href=#html-element>HTML
+element</a> with a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable>contenteditable</a></code> attribute set to the true
+state, or the <a href=#html-element>HTML element</a> <a class=external data-anolis-spec=dom 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=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code> whose <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#designMode>designMode</a></code> is enabled.
+
+<p>Something is <dfn id=editable>editable</dfn> if it is a <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a>; it is not an
+<a href=#editing-host>editing host</a>; it does not have a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#attr-contenteditable>contenteditable</a></code> attribute set to the false
+state; its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a> is an <a href=#editing-host>editing host</a> or <a href=#editable>editable</a>;
+and either it is an <a href=#html-element>HTML element</a>, or it is an <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/the-map-element.html#svg>svg</a></code> or <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/the-map-element.html#math>math</a></code>
+element, or it is not an <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> and its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a> is an <a href=#html-element>HTML
+element</a>.
 
 <p class=note>An <a href=#editable>editable</a> node cannot be a <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code> or
 <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#documentfragment>DocumentFragment</a></code>, its <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a> cannot be null, and it must descend from
--- a/implementation.js	Tue Nov 08 12:17:22 2011 -0700
+++ b/implementation.js	Tue Nov 08 12:17:45 2011 -0700
@@ -716,28 +716,32 @@
 	return node && !isBlockNode(node);
 }
 
-// "An editing host is a node that is either an Element with a contenteditable
-// attribute set to the true state, or the Element child of a Document whose
-// designMode is enabled."
+// "An editing host is a node that is either an HTML element with a
+// contenteditable attribute set to the true state, or the HTML element child
+// of a Document whose designMode is enabled."
 function isEditingHost(node) {
 	return node
-		&& node.nodeType == Node.ELEMENT_NODE
+		&& isHtmlElement(node)
 		&& (node.contentEditable == "true"
 		|| (node.parentNode
 		&& node.parentNode.nodeType == Node.DOCUMENT_NODE
 		&& node.parentNode.designMode == "on"));
 }
 
-// "Something is editable if it is a node which is not an editing host, does
-// not have a contenteditable attribute set to the false state, and whose
-// parent is an editing host or editable."
+// "Something is editable if it is a node; it is not an editing host; it does
+// not have a contenteditable attribute set to the false state; its parent is
+// an editing host or editable; and either it is an HTML element, or it is an
+// svg or math element, or it is not an Element and its parent is an HTML
+// element."
 function isEditable(node) {
-	// This is slightly a lie, because we're excluding non-HTML elements with
-	// contentEditable attributes.
 	return node
 		&& !isEditingHost(node)
 		&& (node.nodeType != Node.ELEMENT_NODE || node.contentEditable != "false")
-		&& (isEditingHost(node.parentNode) || isEditable(node.parentNode));
+		&& (isEditingHost(node.parentNode) || isEditable(node.parentNode))
+		&& (isHtmlElement(node)
+		|| (node.nodeType == Node.ELEMENT_NODE && node.namespaceURI == "http://www.w3.org/2000/svg" && node.localName == "svg")
+		|| (node.nodeType == Node.ELEMENT_NODE && node.namespaceURI == "http://www.w3.org/1998/Math/MathML" && node.localName == "math")
+		|| (node.nodeType != Node.ELEMENT_NODE && isHtmlElement(node.parentNode)));
 }
 
 // Helper function, not defined in the spec
--- a/preprocess	Tue Nov 08 12:17:22 2011 -0700
+++ b/preprocess	Tue Nov 08 12:17:45 2011 -0700
@@ -71,6 +71,7 @@
     'li': '<code data-anolis-spec=html title="the li element">li</code>',
     'localname': '<span data-anolis-spec=dom title=concept-element-local-name>local name</span>',
     'looselyequivalent': '<span title="loosely equivalent values">loosely equivalent</span>',
+    'math': '<code data-anolis-spec=html>math</code>',
     'namespace': '<span data-anolis-spec=dom title=concept-element-namespace>namespace</span>',
     'nextsibling': '<code data-anolis-spec=dom title=dom-Node-nextSibling>nextSibling</code>',
     'node': '<span data-anolis-spec=dom title=concept-node>node</span>',
@@ -108,6 +109,7 @@
     'style': '<code data-anolis-spec=html title="the style attribute">style</code>',
     'sub': '<code data-anolis-spec=html title="the sub and sup elements">sub</code>',
     'sup': '<code data-anolis-spec=html title="the sub and sup elements">sup</code>',
+    'svg': '<code data-anolis-spec=html>svg</code>',
     'table': '<code data-anolis-spec=html title="the table element">table</code>',
     'tbody': '<code data-anolis-spec=html title="the tbody element">tbody</code>',
     'td': '<code data-anolis-spec=html title="the td element">td</code>',
--- a/source.html	Tue Nov 08 12:17:22 2011 -0700
+++ b/source.html	Tue Nov 08 12:17:45 2011 -0700
@@ -1610,16 +1610,19 @@
 <p>An <dfn>inline node</dfn> is a [[node]] that is not a <span>block
 node</span>.
 
-<p>An <dfn>editing host</dfn> is a [[node]] that is either an [[element]] with
-a <code data-anolis-spec=html title=attr-contenteditable>contenteditable</code>
-attribute set to the true state, or the [[element]] [[child]] of a [[document]]
-whose <code data-anolis-spec=html>designMode</code> is enabled.
-
-<p>Something is <dfn>editable</dfn> if it is a [[node]] which is not an
-<span>editing host</span>, does not have a <code data-anolis-spec=html
+<p>An <dfn>editing host</dfn> is a [[node]] that is either an <span>HTML
+element</span> with a <code data-anolis-spec=html
+title=attr-contenteditable>contenteditable</code> attribute set to the true
+state, or the <span>HTML element</span> [[child]] of a [[document]] whose <code
+data-anolis-spec=html>designMode</code> is enabled.
+
+<p>Something is <dfn>editable</dfn> if it is a [[node]]; it is not an
+<span>editing host</span>; it does not have a <code data-anolis-spec=html
 title=attr-contenteditable>contenteditable</code> attribute set to the false
-state, and whose [[parent]] is an <span>editing host</span> or
-<span>editable</span>.
+state; its [[parent]] is an <span>editing host</span> or <span>editable</span>;
+and either it is an <span>HTML element</span>, or it is an [[svg]] or [[math]]
+element, or it is not an [[element]] and its [[parent]] is an <span>HTML
+element</span>.
 
 <p class=note>An <span>editable</span> node cannot be a [[document]] or
 [[documentfragment]], its [[parent]] cannot be null, and it must descend from