Define indeterminate for justify*
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 28 Jun 2011 14:33:05 -0600
changeset 338 8963fd7c4a1f
parent 337 82989e38ad2e
child 339 178bf9301a87
Define indeterminate for justify*
editcommands.html
implementation.js
source.html
tests.js
--- a/editcommands.html	Tue Jun 28 14:06:43 2011 -0600
+++ b/editcommands.html	Tue Jun 28 14:33:05 2011 -0600
@@ -6296,6 +6296,13 @@
 <p><a href=#action>Action</a>: <a href=#justify-the-selection>Justify the selection</a> with
 <var title="">alignment</var> "center".
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: <a href=#block-extend>Block-extend</a> the <a href=#active-range>active
+range</a>.  Return true if among <a href=#editable>editable</a> nodes <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a>
+in the result, at least one has <a href=#alignment-value>alignment value</a> "center" and at
+least one does not.  Otherwise return false.
+<!-- This roughly matches Chrome 14 dev, although not exactly.  Firefox 6.0a2
+always returns false. -->
+
 <p><a href=#state>State</a>: True if the <a href="#selection's-alignment-value">selection's alignment value</a> is
 "center", otherwise false.
 
@@ -6308,6 +6315,11 @@
 <p><a href=#action>Action</a>: <a href=#justify-the-selection>Justify the selection</a> with
 <var title="">alignment</var> "justify".
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: <a href=#block-extend>Block-extend</a> the <a href=#active-range>active
+range</a>.  Return true if among <a href=#editable>editable</a> nodes <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a>
+in the result, at least one has <a href=#alignment-value>alignment value</a> "justify" and at
+least one does not.  Otherwise return false.
+
 <p><a href=#state>State</a>: True if the <a href="#selection's-alignment-value">selection's alignment value</a> is
 "justify", otherwise false.
 
@@ -6320,6 +6332,11 @@
 <p><a href=#action>Action</a>: <a href=#justify-the-selection>Justify the selection</a> with
 <var title="">alignment</var> "left".
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: <a href=#block-extend>Block-extend</a> the <a href=#active-range>active
+range</a>.  Return true if among <a href=#editable>editable</a> nodes <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a>
+in the result, at least one has <a href=#alignment-value>alignment value</a> "left" and at
+least one does not.  Otherwise return false.
+
 <p><a href=#state>State</a>: True if the <a href="#selection's-alignment-value">selection's alignment value</a> is
 "left", otherwise false.
 
@@ -6332,6 +6349,11 @@
 <p><a href=#action>Action</a>: <a href=#justify-the-selection>Justify the selection</a> with
 <var title="">alignment</var> "right".
 
+<p><a href=#indeterminate-flag>Indeterminate flag</a>: <a href=#block-extend>Block-extend</a> the <a href=#active-range>active
+range</a>.  Return true if among <a href=#editable>editable</a> nodes <a class=external data-anolis-spec=domrange href=http://html5.org/specs/dom-range.html#contained>contained</a>
+in the result, at least one has <a href=#alignment-value>alignment value</a> "right" and at
+least one does not.  Otherwise return false.
+
 <p><a href=#state>State</a>: True if the <a href="#selection's-alignment-value">selection's alignment value</a> is
 "right", otherwise false.
 
--- a/implementation.js	Tue Jun 28 14:06:43 2011 -0600
+++ b/implementation.js	Tue Jun 28 14:33:05 2011 -0600
@@ -6414,6 +6414,14 @@
 commands.justifycenter = {
 	// "Justify the selection with alignment "center"."
 	action: function() { justifySelection("center") },
+	indeterm: function() {
+		// "Block-extend the active range. Return true if among editable nodes
+		// contained in the result, at least one has alignment value "center"
+		// and at least one does not. Otherwise return false."
+		var nodes = collectAllContainedNodes(blockExtendRange(getActiveRange()), isEditable);
+		return nodes.some(function(node) { return getAlignmentValue(node) == "center" })
+			&& nodes.some(function(node) { return getAlignmentValue(node) != "center" });
+	},
 	// "True if the selection's alignment value is "center", otherwise false."
 	state: function() { return getSelectionAlignmentValue() == "center" },
 	// "The active range's start node's alignment value."
@@ -6426,6 +6434,14 @@
 commands.justifyfull = {
 	// "Justify the selection with alignment "justify"."
 	action: function() { justifySelection("justify") },
+	indeterm: function() {
+		// "Block-extend the active range. Return true if among editable nodes
+		// contained in the result, at least one has alignment value "justify"
+		// and at least one does not. Otherwise return false."
+		var nodes = collectAllContainedNodes(blockExtendRange(getActiveRange()), isEditable);
+		return nodes.some(function(node) { return getAlignmentValue(node) == "justify" })
+			&& nodes.some(function(node) { return getAlignmentValue(node) != "justify" });
+	},
 	// "True if the selection's alignment value is "justify", otherwise false."
 	state: function() { return getSelectionAlignmentValue() == "justify" },
 	// "The active range's start node's alignment value."
@@ -6438,6 +6454,14 @@
 commands.justifyleft = {
 	// "Justify the selection with alignment "left"."
 	action: function() { justifySelection("left") },
+	indeterm: function() {
+		// "Block-extend the active range. Return true if among editable nodes
+		// contained in the result, at least one has alignment value "left"
+		// and at least one does not. Otherwise return false."
+		var nodes = collectAllContainedNodes(blockExtendRange(getActiveRange()), isEditable);
+		return nodes.some(function(node) { return getAlignmentValue(node) == "left" })
+			&& nodes.some(function(node) { return getAlignmentValue(node) != "left" });
+	},
 	// "True if the selection's alignment value is "left", otherwise false."
 	state: function() { return getSelectionAlignmentValue() == "left" },
 	// "The active range's start node's alignment value."
@@ -6450,6 +6474,14 @@
 commands.justifyright = {
 	// "Justify the selection with alignment "right"."
 	action: function() { justifySelection("right") },
+	indeterm: function() {
+		// "Block-extend the active range. Return true if among editable nodes
+		// contained in the result, at least one has alignment value "right"
+		// and at least one does not. Otherwise return false."
+		var nodes = collectAllContainedNodes(blockExtendRange(getActiveRange()), isEditable);
+		return nodes.some(function(node) { return getAlignmentValue(node) == "right" })
+			&& nodes.some(function(node) { return getAlignmentValue(node) != "right" });
+	},
 	// "True if the selection's alignment value is "right", otherwise false."
 	state: function() { return getSelectionAlignmentValue() == "right" },
 	// "The active range's start node's alignment value."
--- a/source.html	Tue Jun 28 14:06:43 2011 -0600
+++ b/source.html	Tue Jun 28 14:33:05 2011 -0600
@@ -6316,6 +6316,13 @@
 <p><span>Action</span>: <span>Justify the selection</span> with
 <var>alignment</var> "center".
 
+<p><span>Indeterminate flag</span>: <span>Block-extend</span> the <span>active
+range</span>.  Return true if among <span>editable</span> nodes [[contained]]
+in the result, at least one has <span>alignment value</span> "center" and at
+least one does not.  Otherwise return false.
+<!-- This roughly matches Chrome 14 dev, although not exactly.  Firefox 6.0a2
+always returns false. -->
+
 <p><span>State</span>: True if the <span>selection's alignment value</span> is
 "center", otherwise false.
 
@@ -6328,6 +6335,11 @@
 <p><span>Action</span>: <span>Justify the selection</span> with
 <var>alignment</var> "justify".
 
+<p><span>Indeterminate flag</span>: <span>Block-extend</span> the <span>active
+range</span>.  Return true if among <span>editable</span> nodes [[contained]]
+in the result, at least one has <span>alignment value</span> "justify" and at
+least one does not.  Otherwise return false.
+
 <p><span>State</span>: True if the <span>selection's alignment value</span> is
 "justify", otherwise false.
 
@@ -6340,6 +6352,11 @@
 <p><span>Action</span>: <span>Justify the selection</span> with
 <var>alignment</var> "left".
 
+<p><span>Indeterminate flag</span>: <span>Block-extend</span> the <span>active
+range</span>.  Return true if among <span>editable</span> nodes [[contained]]
+in the result, at least one has <span>alignment value</span> "left" and at
+least one does not.  Otherwise return false.
+
 <p><span>State</span>: True if the <span>selection's alignment value</span> is
 "left", otherwise false.
 
@@ -6352,6 +6369,11 @@
 <p><span>Action</span>: <span>Justify the selection</span> with
 <var>alignment</var> "right".
 
+<p><span>Indeterminate flag</span>: <span>Block-extend</span> the <span>active
+range</span>.  Return true if among <span>editable</span> nodes [[contained]]
+in the result, at least one has <span>alignment value</span> "right" and at
+least one does not.  Otherwise return false.
+
 <p><span>State</span>: True if the <span>selection's alignment value</span> is
 "right", otherwise false.
 
--- a/tests.js	Tue Jun 28 14:06:43 2011 -0600
+++ b/tests.js	Tue Jun 28 14:33:05 2011 -0600
@@ -2345,6 +2345,13 @@
 		'<div align=nonsense><p>[foo]</div><p>extra',
 		'<div style=text-align:inherit><p>[foo]</div><p>extra',
 		'<quasit align=right><p>[foo]</p></quasit><p>extra',
+
+		'<div align=center>{<div align=left>foo</div>}</div>',
+		'<div align=left>{<div align=center>foo</div>}</div>',
+		'<div align=center>{<div align=left>foo</div>bar}</div>',
+		'<div align=left>{<div align=center>foo</div>bar}</div>',
+		'<div align=center>{<div align=left>foo</div><img src=/img/lion.svg>}</div>',
+		'<div align=left>{<div align=center>foo</div><img src=/img/lion.svg>}</div>',
 	],
 	//@}
 	justifyfull: [