Always output hex for <font color>
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Fri, 02 Sep 2011 15:44:00 -0600
changeset 557 0f91016d96a6
parent 556 1122684122f4
child 558 c990babdb668
Always output hex for <font color>

It makes sense to output stuff like <font color=blue> when the value is
actually provided by the author, maybe, but it causes interop problems
when the value is generated by the algorithms themselves, since the
format of computed styles is so poorly defined. In particular, the
delete test "<p style=color:blue>foo<p style=color:brown>[]bar" was
generating <font color=brown> in Gecko and <font color=#a52a2a> in
WebKit for the *expected* result, and differences in *expected* results
are bad.

This behavior is simpler anyway. It matches WebKit and Opera instead of
IE and Gecko.
editing.html
implementation.js
source.html
--- a/editing.html	Thu Sep 01 15:32:37 2011 -0600
+++ b/editing.html	Fri Sep 02 15:44:00 2011 -0600
@@ -65,7 +65,7 @@
 <body class=draft>
 <div class=head id=head>
 <h1>HTML Editing APIs</h1>
-<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-30-august-2011>Work in Progress &mdash; Last Update 30 August 2011</h2>
+<h2 class="no-num no-toc" id=work-in-progress-&mdash;-last-update-2-september-2011>Work in Progress &mdash; Last Update 2 September 2011</h2>
 <dl>
  <dt>Editor
  <dd>Aryeh Gregor &lt;<a href=mailto:[email protected]>[email protected]</a>&gt;
@@ -2486,14 +2486,10 @@
       <li>Let <var title="">new parent</var> be the result of calling <code class=external data-anolis-spec=domcore title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("font")</a></code> on the
       <code class=external data-anolis-spec=domcore title=dom-Node-ownerDocument><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-ownerdocument>ownerDocument</a></code> of <var title="">node</var>.
 
-      <li>If <var title="">new value</var> is an <a href=http://www.w3.org/TR/css3-color/#svg-color>extended color
-      keyword</a>, set the <code class=external data-anolis-spec=html title=dom-font-color><a href=http://www.whatwg.org/html/#dom-font-color>color</a></code> attribute of <var title="">new parent</var> to
-      <var title="">new value</var>.
-
-      <li>Otherwise, set the <code class=external data-anolis-spec=html title=dom-font-color><a href=http://www.whatwg.org/html/#dom-font-color>color</a></code> attribute of <var title="">new parent</var>
-      to the result of applying the <a class=external data-anolis-spec=html href=http://www.whatwg.org/html/#rules-for-serializing-simple-color-values>rules for
-      serializing simple color values</a> to <var title="">new value</var>
-      (interpreted as a <a class=external data-anolis-spec=html href=http://www.whatwg.org/html/#simple-color>simple color</a>).
+      <li>Set the <code class=external data-anolis-spec=html title=dom-font-color><a href=http://www.whatwg.org/html/#dom-font-color>color</a></code> attribute of <var title="">new parent</var> to the
+      result of applying the <a class=external data-anolis-spec=html href=http://www.whatwg.org/html/#rules-for-serializing-simple-color-values>rules for serializing
+      simple color values</a> to <var title="">new value</var> (interpreted as a
+      <a class=external data-anolis-spec=html href=http://www.whatwg.org/html/#simple-color>simple color</a>).
     </ol>
 
     <li>If <var title="">command</var> is "fontName", let <var title="">new parent</var> be
@@ -3382,12 +3378,11 @@
 </ul>
 
 <p>What I'm going to say is that it either has to be a valid CSS color, or
-prefixing it with # must result in a valid CSS color.  For &lt;font&gt;, I'll say
-that the output color should be normalized to #xxxxxx form unless it's an SVG
-color keyword, in which case it's passed through intact.  If the color is not a
-simple color (fully opaque with all channels between 0 and 255), I'll force
-style="" even if styleWithCSS mode is off.  Some of this disagrees with all
-browsers, but it's unlikely to hurt and it makes sense.
+prefixing it with # must result in a valid CSS color.  For <code title="">&lt;font&gt;</code>,
+I'll say that the output color should be normalized to #xxxxxx form.  If the
+color is not a simple color (fully opaque with all channels between 0 and 255),
+I'll force <code title="">style=""</code> even if styleWithCSS mode is off.  Some of this
+disagrees with all browsers, but it's unlikely to hurt and it makes sense.
 </div>
 
 <p><a href=#action>Action</a>:
--- a/implementation.js	Thu Sep 01 15:32:37 2011 -0600
+++ b/implementation.js	Fri Sep 02 15:44:00 2011 -0600
@@ -442,41 +442,8 @@
 	return color;
 }
 
-// Returns either null, or something of the form #xxxxxx, or the color itself
-// if it's a valid keyword.
+// Returns either null, or something of the form #xxxxxx.
 function parseSimpleColor(color) {
-	color = color.toLowerCase();
-	if (["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
-	"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
-	"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
-	"cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
-	"darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki",
-	"darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred",
-	"darksalmon", "darkseagreen", "darkslateblue", "darkslategray",
-	"darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue",
-	"dimgray", "dimgrey", "dodgerblue", "firebrick", "floralwhite",
-	"forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod",
-	"gray", "green", "greenyellow", "grey", "honeydew", "hotpink", "indianred",
-	"indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen",
-	"lemonchiffon", "lightblue", "lightcoral", "lightcyan",
-	"lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey",
-	"lightpink", "lightsalmon", "lightseagreen", "lightskyblue",
-	"lightslategray", "lightslategrey", "lightsteelblue", "lightyellow",
-	"lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine",
-	"mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen",
-	"mediumslateblue", "mediumspringgreen", "mediumturquoise",
-	"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
-	"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange",
-	"orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise",
-	"palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum",
-	"powderblue", "purple", "red", "rosybrown", "royalblue", "saddlebrown",
-	"salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver",
-	"skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen",
-	"steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet",
-	"wheat", "white", "whitesmoke", "yellow", "yellowgreen"].indexOf(color) != -1) {
-		return color;
-	}
-
 	color = normalizeColor(color);
 	var matches = /^rgb\(([0-9]+), ([0-9]+), ([0-9]+)\)$/.exec(color);
 	if (matches) {
@@ -2793,12 +2760,9 @@
 			// on the ownerDocument of node."
 			newParent = node.ownerDocument.createElement("font");
 
-			// "If new value is an extended color keyword, set the color
-			// attribute of new parent to new value."
-			//
-			// "Otherwise, set the color attribute of new parent to the result
-			// of applying the rules for serializing simple color values to new
-			// value (interpreted as a simple color)."
+			// "Set the color attribute of new parent to the result of applying
+			// the rules for serializing simple color values to new value
+			// (interpreted as a simple color)."
 			newParent.setAttribute("color", parseSimpleColor(newValue));
 		}
 
--- a/source.html	Thu Sep 01 15:32:37 2011 -0600
+++ b/source.html	Fri Sep 02 15:44:00 2011 -0600
@@ -2482,15 +2482,10 @@
       title=dom-Document-createElement>createElement("font")</code> on the
       [[ownerdocument]] of <var>node</var>.
 
-      <li>If <var>new value</var> is an <a
-      href=http://www.w3.org/TR/css3-color/#svg-color>extended color
-      keyword</a>, set the [[fontcolor]] attribute of <var>new parent</var> to
-      <var>new value</var>.
-
-      <li>Otherwise, set the [[fontcolor]] attribute of <var>new parent</var>
-      to the result of applying the <span data-anolis-spec=html>rules for
-      serializing simple color values</span> to <var>new value</var>
-      (interpreted as a <span data-anolis-spec=html>simple color</span>).
+      <li>Set the [[fontcolor]] attribute of <var>new parent</var> to the
+      result of applying the <span data-anolis-spec=html>rules for serializing
+      simple color values</span> to <var>new value</var> (interpreted as a
+      <span data-anolis-spec=html>simple color</span>).
     </ol>
 
     <li>If <var>command</var> is "fontName", let <var>new parent</var> be
@@ -3388,12 +3383,11 @@
 </ul>
 
 <p>What I'm going to say is that it either has to be a valid CSS color, or
-prefixing it with # must result in a valid CSS color.  For &lt;font>, I'll say
-that the output color should be normalized to #xxxxxx form unless it's an SVG
-color keyword, in which case it's passed through intact.  If the color is not a
-simple color (fully opaque with all channels between 0 and 255), I'll force
-style="" even if styleWithCSS mode is off.  Some of this disagrees with all
-browsers, but it's unlikely to hurt and it makes sense.
+prefixing it with # must result in a valid CSS color.  For {{code|<font>}},
+I'll say that the output color should be normalized to #xxxxxx form.  If the
+color is not a simple color (fully opaque with all channels between 0 and 255),
+I'll force {{code|style=""}} even if styleWithCSS mode is off.  Some of this
+disagrees with all browsers, but it's unlikely to hurt and it makes sense.
 </div>
 
 <p><span>Action</span>: