Define indeterm for fontFace, fontSize, foreColor
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 28 Jun 2011 15:29:19 -0600
changeset 340 b2c785beb965
parent 339 178bf9301a87
child 341 b83b7d617b9b
Define indeterm for fontFace, fontSize, foreColor
editcommands.html
implementation.js
source.html
tests.js
--- a/editcommands.html	Tue Jun 28 14:50:46 2011 -0600
+++ b/editcommands.html	Tue Jun 28 15:29:19 2011 -0600
@@ -2185,6 +2185,12 @@
 understand CSS font-family syntax?), so I don't think such usability concerns
 apply. -->
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: True if among <a href=#editable>editable</a>
+<code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> nodes that are <a href=#effectively-contained>effectively contained</a> in the <a href=#active-range>active
+range</a>, there are two that have distinct <a href=#effective-value title="effective
+value">effective values</a>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><a href=#value>Value</a>: The <a href=#effective-value>effective value</a> of the <a href=#active-range>active
 range</a>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>.
 
@@ -2314,6 +2320,12 @@
   value</a> of each returned <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> to <var title="">value</var>.
 </ol>
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: True if among <a href=#editable>editable</a>
+<code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> nodes that are <a href=#effectively-contained>effectively contained</a> in the <a href=#active-range>active
+range</a>, there are two that have distinct <a href=#effective-value title="effective
+value">effective values</a>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><a href=#value>Value</a>:
 <!--
 IE9: Seems to return a number based on the computed font-size, but only if it's
@@ -2451,6 +2463,12 @@
 not state.  Firefox 4b11 throws an exception, which is an interesting approach,
 but I'll go with IE/WebKit, which makes at least as much sense. -->
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: True if among <a href=#editable>editable</a>
+<code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> nodes that are <a href=#effectively-contained>effectively contained</a> in the <a href=#active-range>active
+range</a>, there are two that have distinct <a href=#effective-value title="effective
+value">effective values</a>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><a href=#value>Value</a>: The <a href=#effective-value>effective value</a> of the <a href=#active-range>active
 range</a>'s <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range-start title=concept-range-start>start</a> <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point-node title=concept-boundary-point-node>node</a>.
 
@@ -5781,6 +5799,10 @@
 <p><a href=#action>Action</a>: <a href=#toggle-lists>Toggle lists</a> with <var title="">tag name</var>
 "ol".
 
+<p class=XXX>Consider defining indeterminate flag.
+<!-- Gecko sort of supports it, but unreliably, and no one else does.  Ditto
+insertUnorderedList, obviously. -->
+
 <p><a href=#state>State</a>:
 <!--
 Logically, this should return true if running the command would remove ordered
--- a/implementation.js	Tue Jun 28 14:50:46 2011 -0600
+++ b/implementation.js	Tue Jun 28 15:29:19 2011 -0600
@@ -2724,6 +2724,17 @@
 		for (var i = 0; i < nodeList.length; i++) {
 			setNodeValue(nodeList[i], "fontname", value);
 		}
+	}, indeterm: function() {
+		// "True if among editable Text nodes that are effectively contained in
+		// the active range, there are two that have distinct effective values.
+		// Otherwise false."
+		return collectAllEffectivelyContainedNodes(getActiveRange(), function(node) {
+			return isEditable(node) && node.nodeType == Node.TEXT_NODE;
+		}).map(function(node) {
+			return getEffectiveValue(node, "fontname");
+		}).filter(function(value, i, arr) {
+			return arr.slice(0, i).indexOf(value) == -1;
+		}).length >= 2;
 	}, value: function() {
 		// "The effective value of the active range's start node."
 		return getEffectiveValue(getActiveRange().startContainer, "fontname");
@@ -2822,6 +2833,17 @@
 		for (var i = 0; i < nodeList.length; i++) {
 			setNodeValue(nodeList[i], "fontsize", value);
 		}
+	}, indeterm: function() {
+		// "True if among editable Text nodes that are effectively contained in
+		// the active range, there are two that have distinct effective values.
+		// Otherwise false."
+		return collectAllEffectivelyContainedNodes(getActiveRange(), function(node) {
+			return isEditable(node) && node.nodeType == Node.TEXT_NODE;
+		}).map(function(node) {
+			return getEffectiveValue(node, "fontsize");
+		}).filter(function(value, i, arr) {
+			return arr.slice(0, i).indexOf(value) == -1;
+		}).length >= 2;
 	}, value: function() {
 		// "Let pixel size be the effective value of the active range's start
 		// node, as a number of pixels."
@@ -2895,6 +2917,17 @@
 		for (var i = 0; i < nodeList.length; i++) {
 			setNodeValue(nodeList[i], "forecolor", value);
 		}
+	}, indeterm: function() {
+		// "True if among editable Text nodes that are effectively contained in
+		// the active range, there are two that have distinct effective values.
+		// Otherwise false."
+		return collectAllEffectivelyContainedNodes(getActiveRange(), function(node) {
+			return isEditable(node) && node.nodeType == Node.TEXT_NODE;
+		}).map(function(node) {
+			return getEffectiveValue(node, "forecolor");
+		}).filter(function(value, i, arr) {
+			return arr.slice(0, i).indexOf(value) == -1;
+		}).length >= 2;
 	}, value: function() {
 		// "The effective value of the active range's start node."
 		//
--- a/source.html	Tue Jun 28 14:50:46 2011 -0600
+++ b/source.html	Tue Jun 28 15:29:19 2011 -0600
@@ -2161,6 +2161,12 @@
 understand CSS font-family syntax?), so I don't think such usability concerns
 apply. -->
 
+<p><span>Indeterminate flag</span>: True if among <span>editable</span>
+[[text]] nodes that are <span>effectively contained</span> in the <span>active
+range</span>, there are two that have distinct <span title="effective
+value">effective values</span>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><span>Value</span>: The <span>effective value</span> of the <span>active
 range</span>'s [[startnode]].
 
@@ -2290,6 +2296,12 @@
   value</span> of each returned [[node]] to <var>value</var>.
 </ol>
 
+<p><span>Indeterminate flag</span>: True if among <span>editable</span>
+[[text]] nodes that are <span>effectively contained</span> in the <span>active
+range</span>, there are two that have distinct <span title="effective
+value">effective values</span>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><span>Value</span>:
 <!--
 IE9: Seems to return a number based on the computed font-size, but only if it's
@@ -2427,6 +2439,12 @@
 not state.  Firefox 4b11 throws an exception, which is an interesting approach,
 but I'll go with IE/WebKit, which makes at least as much sense. -->
 
+<p><span>Indeterminate flag</span>: True if among <span>editable</span>
+[[text]] nodes that are <span>effectively contained</span> in the <span>active
+range</span>, there are two that have distinct <span title="effective
+value">effective values</span>.  Otherwise false.
+<!-- This follows Firefox 6.0a2.  Chrome 14 dev always returns false. -->
+
 <p><span>Value</span>: The <span>effective value</span> of the <span>active
 range</span>'s [[startnode]].
 
@@ -5793,6 +5811,10 @@
 <p><span>Action</span>: <span>Toggle lists</span> with <var>tag name</var>
 "ol".
 
+<p class=XXX>Consider defining indeterminate flag.
+<!-- Gecko sort of supports it, but unreliably, and no one else does.  Ditto
+insertUnorderedList, obviously. -->
+
 <p><span>State</span>:
 <!--
 Logically, this should return true if running the command would remove ordered
--- a/tests.js	Tue Jun 28 14:50:46 2011 -0600
+++ b/tests.js	Tue Jun 28 15:29:19 2011 -0600
@@ -575,6 +575,25 @@
 		'foo<tt>{}<br></tt>bar',
 		'foo<tt>{<br></tt>}bar',
 		'foo<tt>{<br></tt>b]ar',
+
+		// Tests for queryCommandIndeterm() and queryCommandState()
+		'fo[o<span style=font-family:monospace>b]ar</span>baz',
+		'foo<span style=font-family:monospace>ba[r</span>b]az',
+		'fo[o<span style=font-family:monospace>bar</span>b]az',
+		'foo[<span style=font-family:monospace>b]ar</span>baz',
+		'foo<span style=font-family:monospace>ba[r</span>]baz',
+		'foo[<span style=font-family:monospace>bar</span>]baz',
+		'foo<span style=font-family:monospace>[bar]</span>baz',
+		'foo{<span style=font-family:monospace>bar</span>}baz',
+		'fo[o<code>b]ar</code>',
+		'fo[o<kbd>b]ar</kbd>',
+		'fo[o<listing>b]ar</listing>',
+		'fo[o<pre>b]ar</pre>',
+		'fo[o<samp>b]ar</samp>',
+		'fo[o<tt>b]ar</tt>',
+		'<tt>fo[o</tt><code>b]ar</code>',
+		'<pre>fo[o</pre><samp>b]ar</samp>',
+		'<span style=font-family:monospace>fo[o</span><kbd>b]ar</kbd>',
 	],
 	//@}
 	fontsize: [
@@ -655,6 +674,22 @@
 		["3", 'foo<big>b[a]r</big>baz'],
 		["3", 'foo<small>[bar]</small>baz'],
 		["3", 'foo<small>b[a]r</small>baz'],
+
+		// Tests for queryCommandIndeterm() and queryCommandState()
+		'fo[o<font size=2>b]ar</font>baz',
+		'foo<font size=2>ba[r</font>b]az',
+		'fo[o<font size=2>bar</font>b]az',
+		'foo[<font size=2>b]ar</font>baz',
+		'foo<font size=2>ba[r</font>]baz',
+		'foo[<font size=2>bar</font>]baz',
+		'foo<font size=2>[bar]</font>baz',
+		'foo{<font size=2>bar</font>}baz',
+		'<font size=1>fo[o</font><span style=font-size:xx-small>b]ar</span>',
+		'<font size=2>fo[o</font><span style=font-size:small>b]ar</span>',
+		'<font size=3>fo[o</font><span style=font-size:medium>b]ar</span>',
+		'<font size=4>fo[o</font><span style=font-size:large>b]ar</span>',
+		'<font size=5>fo[o</font><span style=font-size:x-large>b]ar</span>',
+		'<font size=6>fo[o</font><span style=font-size:xx-large>b]ar</span>',
 	],
 	//@}
 	forecolor: [
@@ -726,6 +761,18 @@
 		'<span style="color: cornsilk">[foo]</span>',
 		'<span style="color: transparent">[foo]</span>',
 		'<span style="color: currentColor">[foo]</span>',
+
+		// Tests for queryCommandIndeterm() and queryCommandState()
+		'fo[o<font color=blue>b]ar</font>baz',
+		'foo<font color=blue>ba[r</font>b]az',
+		'fo[o<font color=blue>bar</font>b]az',
+		'foo[<font color=blue>b]ar</font>baz',
+		'foo<font color=blue>ba[r</font>]baz',
+		'foo[<font color=blue>bar</font>]baz',
+		'foo<font color=blue>[bar]</font>baz',
+		'foo{<font color=blue>bar</font>}baz',
+		'<font color=blue>fo[o</font><span style=color:blue>b]ar</span>',
+		'<span style=color:blue>fo[o</span><span style=color:#0000ff>b]ar</span>',
 	],
 	//@}
 	formatblock: [