Spec foreColor value
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 28 Jun 2011 10:49:22 -0600
changeset 332 6e74be75cba7
parent 331 9298159f0701
child 333 c10760dd0af0
Spec foreColor value
editcommands.html
implementation.js
source.html
tests.js
--- a/editcommands.html	Tue Jun 28 10:02:13 2011 -0600
+++ b/editcommands.html	Tue Jun 28 10:49:22 2011 -0600
@@ -2427,8 +2427,25 @@
 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=#value>Value</a>: ?
-<!-- IE 9 RC returns the number 0 always, which makes no sense at all. -->
+<p><a href=#value>Value</a>:
+<!--
+The spec essentially matches Firefox 6.0a2 and Chrome 14 dev.  IE9 seems to
+always return the number 0 for some bizarre reason.  There are some cases where
+Firefox returns the empty string for some reason, and it seems to select the
+active node a little differently.  Opera uses #xxxxxx format for
+getComputedStyle() but rgb() here, and also drops the transparent part of the
+color if there is any.
+-->
+<ol>
+  <li>Let <var title="">node</var> be 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>.
+
+  <li>If <var title="">node</var> is not an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code>, set <var title="">node</var> to its
+  <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>.
+
+  <li>If <var title="">node</var> is not an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code>, return "rgb(0, 0, 0)".
+
+  <li>Return the <a href=http://www.w3.org/TR/CSS21/cascade.html#computed-value>computed value</a> of "color" on <var title="">node</var>.
+</ol>
 
 <p><a href=#relevant-css-property>Relevant CSS property</a>: "color"
 
--- a/implementation.js	Tue Jun 28 10:02:13 2011 -0600
+++ b/implementation.js	Tue Jun 28 10:49:22 2011 -0600
@@ -2881,6 +2881,32 @@
 		for (var i = 0; i < nodeList.length; i++) {
 			setNodeValue(nodeList[i], "forecolor", value);
 		}
+	}, value: function() {
+		// "Let node be the active range's start node."
+		var node = getActiveRange().startContainer;
+
+		// "If node is not an Element, set node to its parent."
+		if (node.nodeType != Node.ELEMENT_NODE) {
+			node = node.parentNode;
+		}
+
+		// "If node is not an Element, return "rgb(0, 0, 0)"."
+		if (node.nodeType != Node.ELEMENT_NODE) {
+			return "rgb(0, 0, 0)";
+		}
+
+		// "Return the computed value of "color" on node."
+		//
+		// Opera uses a different format, so let's be nice and support that for
+		// the time being (since all this computed value stuff is underdefined
+		// anyway).
+		var computed = getComputedStyle(node).color;
+		if (/^#[0-9a-f]{6}$/.test(computed)) {
+			computed = "rgb(" + parseInt(computed.slice(1, 3), 16)
+				+ "," + parseInt(computed.slice(3, 5), 16)
+				+ "," + parseInt(computed.slice(5), 16) + ")";
+		}
+		return computed;
 	}, relevantCssProperty: "color"
 };
 //@}
--- a/source.html	Tue Jun 28 10:02:13 2011 -0600
+++ b/source.html	Tue Jun 28 10:49:22 2011 -0600
@@ -2403,8 +2403,25 @@
 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>Value</span>: ?
-<!-- IE 9 RC returns the number 0 always, which makes no sense at all. -->
+<p><span>Value</span>:
+<!--
+The spec essentially matches Firefox 6.0a2 and Chrome 14 dev.  IE9 seems to
+always return the number 0 for some bizarre reason.  There are some cases where
+Firefox returns the empty string for some reason, and it seems to select the
+active node a little differently.  Opera uses #xxxxxx format for
+getComputedStyle() but rgb() here, and also drops the transparent part of the
+color if there is any.
+-->
+<ol>
+  <li>Let <var>node</var> be the <span>active range</span>'s [[startnode]].
+
+  <li>If <var>node</var> is not an [[element]], set <var>node</var> to its
+  [[parent]].
+
+  <li>If <var>node</var> is not an [[element]], return "rgb(0, 0, 0)".
+
+  <li>Return the [[compval]] of "color" on <var>node</var>.
+</ol>
 
 <p><span>Relevant CSS property</span>: "color"
 <!-- @} -->
--- a/tests.js	Tue Jun 28 10:02:13 2011 -0600
+++ b/tests.js	Tue Jun 28 10:49:22 2011 -0600
@@ -683,6 +683,25 @@
 		'<span style="color: rgb(255, 0, 0)">foo<span style="color: blue">b[ar]</span>baz</span>',
 		'foo<span id=purple>ba[r</span>ba]z',
 		'<span style="color: rgb(255, 0, 0)">foo<span id=purple>b[a]r</span>baz</span>',
+
+		// Tests for queryCommandValue()
+		'<font color="red">[foo]</font>',
+		'<font color="ff0000">[foo]</font>',
+		'<font color="#ff0000">[foo]</font>',
+		'<span style="color: red">[foo]</span>',
+		'<span style="color: #ff0000">[foo]</span>',
+		'<span style="color: rgb(255, 0, 0)">[foo]</span>',
+		'<span style="color: rgb(100%, 0, 0)">[foo]</span>',
+		'<span style="color: rgb( 255 ,0 ,0)">[foo]</span>',
+		'<span style="color: rgba(255, 0, 0, 0.0)">[foo]</span>',
+		'<span style="color: rgb(375, -10, 15)">[foo]</span>',
+		'<span style="color: rgba(0, 0, 0, 1)">[foo]</span>',
+		'<span style="color: rgba(255, 255, 255, 1)">[foo]</span>',
+		'<span style="color: rgba(255, 0, 0, 0.5)">[foo]</span>',
+		'<span style="color: hsl(0%, 100%, 50%)">[foo]</span>',
+		'<span style="color: cornsilk">[foo]</span>',
+		'<span style="color: transparent">[foo]</span>',
+		'<span style="color: currentColor">[foo]</span>',
 	],
 	//@}
 	formatblock: [