Make value override work for backColor
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 18 Aug 2011 13:43:19 -0600
changeset 541 6eb58844702b
parent 540 11914cdcaec0
child 542 992829ab15c4
Make value override work for backColor

This adds still another hack for backColor/hiliteColor equivalence.
It's getting a little messy, but it still seems easier at this point
than centrally defining them to be equivalent.

I thought of testing this because of a WebKit bug:
https://bugs.webkit.org/show_bug.cgi?id=16049
editing.html
implementation.js
source.html
tests.js
--- a/editing.html	Thu Aug 18 12:52:22 2011 -0600
+++ b/editing.html	Thu Aug 18 13:43:19 2011 -0600
@@ -1160,7 +1160,11 @@
 <code class=external data-anolis-spec=domrange><a href=http://html5.org/specs/dom-range.html#selection>Selection</a></code> changes to something different, and whenever a <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-boundary-point title=concept-boundary-point>boundary point</a>
 of the <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#concept-range title=concept-range>range</a> at a given index in the <code class=external data-anolis-spec=domrange><a href=http://html5.org/specs/dom-range.html#selection>Selection</a></code> changes to something
 different, the <a href=#state-override>state override</a> and <a href=#value-override>value override</a> must
-be unset for every <a href=#command>command</a>.
+be unset for every <a href=#command>command</a>.  The <a href=#value-override>value override</a> for
+<a href=#the-backcolor-command>the <code title="">backColor</code> command</a> must be the same as the
+<a href=#value-override>value override</a> for <a href=#the-hilitecolor-command>the <code title="">hiliteColor</code>
+command</a>, such that setting one sets the other to the same thing and
+unsetting one unsets the other.
 
 <p class=note>The primary purpose of state and value overrides is that if the
 user runs a command like <a href=#the-bold-command><code title="">bold</code></a>
--- a/implementation.js	Thu Aug 18 12:52:22 2011 -0600
+++ b/implementation.js	Thu Aug 18 13:43:19 2011 -0600
@@ -1152,14 +1152,27 @@
 		return valueOverrides[command];
 	}
 
+	// "The value override for the backColor command must be the same as the
+	// value override for the hiliteColor command, such that setting one sets
+	// the other to the same thing and unsetting one unsets the other."
 	setValueOverride = function(command, newValue) {
 		resetOverrides();
 		valueOverrides[command] = newValue;
+		if (command == "backcolor") {
+			valueOverrides.hilitecolor = newValue;
+		} else if (command == "hilitecolor") {
+			valueOverrides.backcolor = newValue;
+		}
 	}
 
 	unsetValueOverride = function(command) {
 		resetOverrides();
 		delete valueOverrides[command];
+		if (command == "backcolor") {
+			delete valueOverrides.hilitecolor;
+		} else if (command == "hilitecolor") {
+			delete valueOverrides.backcolor;
+		}
 	}
 })();
 
--- a/source.html	Thu Aug 18 12:52:22 2011 -0600
+++ b/source.html	Thu Aug 18 13:43:19 2011 -0600
@@ -1119,7 +1119,11 @@
 [[selection]] changes to something different, and whenever a [[boundarypoint]]
 of the [[range]] at a given index in the [[selection]] changes to something
 different, the <span>state override</span> and <span>value override</span> must
-be unset for every <span>command</span>.
+be unset for every <span>command</span>.  The <span>value override</span> for
+<span>the <code title>backColor</code> command</span> must be the same as the
+<span>value override</span> for <span>the <code title>hiliteColor</code>
+command</span>, such that setting one sets the other to the same thing and
+unsetting one unsets the other.
 
 <p class=note>The primary purpose of state and value overrides is that if the
 user runs a command like <a href=#the-bold-command><code title>bold</code></a>
--- a/tests.js	Thu Aug 18 12:52:22 2011 -0600
+++ b/tests.js	Thu Aug 18 13:43:19 2011 -0600
@@ -3511,6 +3511,7 @@
 		['foo[]bar', 'underline', ['inserttext', 'a']],
 
 		// Insertion-affecting value
+		['foo[]bar', 'backcolor', ['inserttext', 'a']],
 		['foo[]bar', 'createlink', ['inserttext', 'a']],
 		['foo[]bar', 'fontname', ['inserttext', 'a']],
 		['foo[]bar', 'fontsize', ['inserttext', 'a']],
@@ -3539,6 +3540,9 @@
 		['foo[]bar', 'subscript', ['fontsize', '3'], ['inserttext', 'a']],
 		['foo[]bar', ['fontsize', '3'], 'subscript', ['inserttext', 'a']],
 
+		['foo[]bar', ['hilitecolor', 'aqua'], ['backcolor', 'tan'], ['inserttext', 'a']],
+		['foo[]bar', ['backcolor', 'tan'], ['hilitecolor', 'aqua'], ['inserttext', 'a']],
+
 
 		// The following are all just inserttext tests that we took from there,
 		// but we first backspace the selected text instead of letting