Don't strip wrappers in empty blocks
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 08 Nov 2011 09:40:24 -0700
changeset 665d461532af710
parent 664 b3afc97ff16e
child 666 0e6c95119654
Don't strip wrappers in empty blocks

See bug for info and reasoning. This changes the output of one
preexisting test for the better, as it happens. The new behavior more
closely matches WebKit, while the old behavior was more like Gecko.

Fixes: http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
conformancetest/data.js
editing.html
implementation.js
source.html
tests.js
     1.1 --- a/conformancetest/data.js	Tue Nov 08 08:56:11 2011 -0700
     1.2 +++ b/conformancetest/data.js	Tue Nov 08 09:40:24 2011 -0700
     1.3 @@ -4367,6 +4367,70 @@
     1.4  	[["stylewithcss","true"],["delete",""]],
     1.5  	"<ul><li>foo{}</li></ul><ol><li>bar</li></ol>",
     1.6  	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
     1.7 +["<p><b>[foo]</b>",
     1.8 +	[["stylewithcss","false"],["delete",""]],
     1.9 +	"<p><b>{}<br></b></p>",
    1.10 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.11 +["<p><b>[foo]</b>",
    1.12 +	[["stylewithcss","true"],["delete",""]],
    1.13 +	"<p><b>{}<br></b></p>",
    1.14 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.15 +["<p><quasit>[foo]</quasit>",
    1.16 +	[["stylewithcss","false"],["delete",""]],
    1.17 +	"<p><quasit>{}<br></quasit></p>",
    1.18 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.19 +["<p><quasit>[foo]</quasit>",
    1.20 +	[["stylewithcss","true"],["delete",""]],
    1.21 +	"<p><quasit>{}<br></quasit></p>",
    1.22 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.23 +["<p><b><i>[foo]</i></b>",
    1.24 +	[["stylewithcss","false"],["delete",""]],
    1.25 +	"<p><b><i>{}<br></i></b></p>",
    1.26 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.27 +["<p><b><i>[foo]</i></b>",
    1.28 +	[["stylewithcss","true"],["delete",""]],
    1.29 +	"<p><b><i>{}<br></i></b></p>",
    1.30 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.31 +["<p><b>{foo}</b>",
    1.32 +	[["stylewithcss","false"],["delete",""]],
    1.33 +	"<p><b>{}<br></b></p>",
    1.34 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.35 +["<p><b>{foo}</b>",
    1.36 +	[["stylewithcss","true"],["delete",""]],
    1.37 +	"<p><b>{}<br></b></p>",
    1.38 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.39 +["<p>{<b>foo</b>}",
    1.40 +	[["stylewithcss","false"],["delete",""]],
    1.41 +	"<p><b>{}<br></b></p>",
    1.42 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.43 +["<p>{<b>foo</b>}",
    1.44 +	[["stylewithcss","true"],["delete",""]],
    1.45 +	"<p><b>{}<br></b></p>",
    1.46 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.47 +["<p><b>f[]</b>",
    1.48 +	[["stylewithcss","false"],["delete",""]],
    1.49 +	"<p><b>{}<br></b></p>",
    1.50 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.51 +["<p><b>f[]</b>",
    1.52 +	[["stylewithcss","true"],["delete",""]],
    1.53 +	"<p><b>{}<br></b></p>",
    1.54 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.55 +["<b>[foo]</b>",
    1.56 +	[["stylewithcss","false"],["delete",""]],
    1.57 +	"<b>{}<br></b>",
    1.58 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.59 +["<b>[foo]</b>",
    1.60 +	[["stylewithcss","true"],["delete",""]],
    1.61 +	"<b>{}<br></b>",
    1.62 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.63 +["<div><b>[foo]</b></div>",
    1.64 +	[["stylewithcss","false"],["delete",""]],
    1.65 +	"<div><b>{}<br></b></div>",
    1.66 +	{"stylewithcss":[false,true,"",false,false,""],"delete":[false,false,"",false,false,""]}],
    1.67 +["<div><b>[foo]</b></div>",
    1.68 +	[["stylewithcss","true"],["delete",""]],
    1.69 +	"<div><b>{}<br></b></div>",
    1.70 +	{"stylewithcss":[false,false,"",false,true,""],"delete":[false,false,"",false,false,""]}],
    1.71  ["foo[]bar",
    1.72  	[["stylewithcss","false"],["fontname","sans-serif"]],
    1.73  	"foo[]bar",
    1.74 @@ -10719,6 +10783,70 @@
    1.75  	[["stylewithcss","true"],["forwarddelete",""]],
    1.76  	"<ul><li>foo</li></ul><p>{}bar</p>",
    1.77  	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.78 +["<p><b>[foo]</b>",
    1.79 +	[["stylewithcss","false"],["forwarddelete",""]],
    1.80 +	"<p><b>{}<br></b></p>",
    1.81 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.82 +["<p><b>[foo]</b>",
    1.83 +	[["stylewithcss","true"],["forwarddelete",""]],
    1.84 +	"<p><b>{}<br></b></p>",
    1.85 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.86 +["<p><quasit>[foo]</quasit>",
    1.87 +	[["stylewithcss","false"],["forwarddelete",""]],
    1.88 +	"<p><quasit>{}<br></quasit></p>",
    1.89 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.90 +["<p><quasit>[foo]</quasit>",
    1.91 +	[["stylewithcss","true"],["forwarddelete",""]],
    1.92 +	"<p><quasit>{}<br></quasit></p>",
    1.93 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.94 +["<p><b><i>[foo]</i></b>",
    1.95 +	[["stylewithcss","false"],["forwarddelete",""]],
    1.96 +	"<p><b><i>{}<br></i></b></p>",
    1.97 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
    1.98 +["<p><b><i>[foo]</i></b>",
    1.99 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.100 +	"<p><b><i>{}<br></i></b></p>",
   1.101 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.102 +["<p><b>{foo}</b>",
   1.103 +	[["stylewithcss","false"],["forwarddelete",""]],
   1.104 +	"<p><b>{}<br></b></p>",
   1.105 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.106 +["<p><b>{foo}</b>",
   1.107 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.108 +	"<p><b>{}<br></b></p>",
   1.109 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.110 +["<p>{<b>foo</b>}",
   1.111 +	[["stylewithcss","false"],["forwarddelete",""]],
   1.112 +	"<p><b>{}<br></b></p>",
   1.113 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.114 +["<p>{<b>foo</b>}",
   1.115 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.116 +	"<p><b>{}<br></b></p>",
   1.117 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.118 +["<p><b>[]f</b>",
   1.119 +	[["stylewithcss","false"],["forwarddelete",""]],
   1.120 +	"<p><b>{}<br></b></p>",
   1.121 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.122 +["<p><b>[]f</b>",
   1.123 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.124 +	"<p><b>{}<br></b></p>",
   1.125 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.126 +["<b>[foo]</b>",
   1.127 +	[["stylewithcss","false"],["forwarddelete",""]],
   1.128 +	"<b>{}<br></b>",
   1.129 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.130 +["<b>[foo]</b>",
   1.131 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.132 +	"<b>{}<br></b>",
   1.133 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.134 +["<div><b>[foo]</b></div>",
   1.135 +	[["stylewithcss","false"],["forwarddelete",""]],
   1.136 +	"<div><b>{}<br></b></div>",
   1.137 +	{"stylewithcss":[false,true,"",false,false,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.138 +["<div><b>[foo]</b></div>",
   1.139 +	[["stylewithcss","true"],["forwarddelete",""]],
   1.140 +	"<div><b>{}<br></b></div>",
   1.141 +	{"stylewithcss":[false,false,"",false,true,""],"forwarddelete":[false,false,"",false,false,""]}],
   1.142  ["foo[]bar",
   1.143  	[["stylewithcss","false"],["hilitecolor","#00FFFF"]],
   1.144  	"foo[]bar",
   1.145 @@ -28825,6 +28953,6 @@
   1.146  	{"delete":[false,false,"",false,false,""],"inserttext":[false,false,"",false,false,""]}],
   1.147  ["<blockquote><font color=blue>[foo]</font></blockquote>",
   1.148  	[["delete",""],["inserttext","a"]],
   1.149 -	"<blockquote><font color=\"#0000ff\">a[]</font></blockquote>",
   1.150 +	"<blockquote><font color=\"blue\">a[]</font></blockquote>",
   1.151  	{"delete":[false,false,"",false,false,""],"inserttext":[false,false,"",false,false,""]}]
   1.152  ]
     2.1 --- a/editing.html	Tue Nov 08 08:56:11 2011 -0700
     2.2 +++ b/editing.html	Tue Nov 08 09:40:24 2011 -0700
     2.3 @@ -5512,6 +5512,15 @@
     2.4      <li>Remove <var title="">node</var> from <var title="">parent</var>.
     2.5  
     2.6      <li>
     2.7 +    <p class=comments>Do this before stripping wrappers: see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831">bug 13831</a>.
     2.8 +
     2.9 +    <p>If the <a href=#block-node-of>block node of</a> <var title="">parent</var> has no
    2.10 +    <a href=#visible>visible</a> <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>, and <var title="">parent</var> is
    2.11 +    <a href=#editable>editable</a> or an <a href=#editing-host>editing host</a>, call
    2.12 +    <code class=external data-anolis-spec=dom title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("br")</a></code> on the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a> and append the result as
    2.13 +    the last <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of <var title="">parent</var>.
    2.14 +
    2.15 +    <li>
    2.16      <p class=comments>Taking insertText to test the case where strip wrappers
    2.17      is false, with value a: <code title="">&lt;p&gt;[foo&lt;b&gt;bar&lt;/b&gt;]baz</code> becomes
    2.18      <code title="">&lt;p&gt;a[]baz</code> per spec, in IE9, and in Chrome 14 dev.  Firefox 7.0a2
    2.19 @@ -5537,11 +5546,6 @@
    2.20      content right afterward, like text or an image, but that new content will
    2.21      be inserted at the start node.  Wrappers in other places still need to be
    2.22      removed, because they would otherwise remain empty.
    2.23 -
    2.24 -    <li>If <var title="">parent</var> is <a href=#editable>editable</a> or an <a href=#editing-host>editing
    2.25 -    host</a>, is not an <a href=#inline-node>inline node</a>, and has no <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a>,
    2.26 -    call <code class=external data-anolis-spec=dom title=dom-Document-createElement><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-createelement>createElement("br")</a></code> on the <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#context-object>context object</a> and append the result
    2.27 -    as the last <a class=external data-anolis-spec=dom href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>child</a> of <var title="">parent</var>.
    2.28    </ol>
    2.29  
    2.30    <li>If <var title="">end node</var> is an <a href=#editable>editable</a> <code class=external data-anolis-spec=dom><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#text>Text</a></code> node, call
     3.1 --- a/implementation.js	Tue Nov 08 08:56:11 2011 -0700
     3.2 +++ b/implementation.js	Tue Nov 08 09:40:24 2011 -0700
     3.3 @@ -4656,6 +4656,14 @@
     3.4  		// "Remove node from parent."
     3.5  		parent_.removeChild(node);
     3.6  
     3.7 +		// "If the block node of parent has no visible children, and parent is
     3.8 +		// editable or an editing host, call createElement("br") on the context
     3.9 +		// object and append the result as the last child of parent."
    3.10 +		if (![].some.call(getBlockNodeOf(parent_).childNodes, isVisible)
    3.11 +		&& (isEditable(parent_) || isEditingHost(parent_))) {
    3.12 +			parent_.appendChild(document.createElement("br"));
    3.13 +		}
    3.14 +
    3.15  		// "If strip wrappers is true or parent is not an ancestor container of
    3.16  		// start node, while parent is an editable inline node with length 0,
    3.17  		// let grandparent be the parent of parent, then remove parent from
    3.18 @@ -4670,15 +4678,6 @@
    3.19  				parent_ = grandparent;
    3.20  			}
    3.21  		}
    3.22 -
    3.23 -		// "If parent is editable or an editing host, is not an inline node,
    3.24 -		// and has no children, call createElement("br") on the context object
    3.25 -		// and append the result as the last child of parent."
    3.26 -		if ((isEditable(parent_) || isEditingHost(parent_))
    3.27 -		&& !isInlineNode(parent_)
    3.28 -		&& !parent_.hasChildNodes()) {
    3.29 -			parent_.appendChild(document.createElement("br"));
    3.30 -		}
    3.31  	}
    3.32  
    3.33  	// "If end node is an editable Text node, call deleteData(0, end offset) on
     4.1 --- a/source.html	Tue Nov 08 08:56:11 2011 -0700
     4.2 +++ b/source.html	Tue Nov 08 09:40:24 2011 -0700
     4.3 @@ -5563,6 +5563,16 @@
     4.4      <li>Remove <var>node</var> from <var>parent</var>.
     4.5  
     4.6      <li>
     4.7 +    <p class=comments>Do this before stripping wrappers: see <a
     4.8 +    href=http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831>bug 13831</a>.
     4.9 +
    4.10 +    <p>If the <span>block node of</span> <var>parent</var> has no
    4.11 +    <span>visible</span> [[children]], and <var>parent</var> is
    4.12 +    <span>editable</span> or an <span>editing host</span>, call
    4.13 +    [[createelement|"br"]] on the [[contextobject]] and append the result as
    4.14 +    the last [[child]] of <var>parent</var>.
    4.15 +
    4.16 +    <li>
    4.17      <p class=comments>Taking insertText to test the case where strip wrappers
    4.18      is false, with value a: {{code<|p>[foo<b>bar</b>]baz}} becomes
    4.19      {{code|<p>a[]baz}} per spec, in IE9, and in Chrome 14 dev.  Firefox 7.0a2
    4.20 @@ -5588,11 +5598,6 @@
    4.21      content right afterward, like text or an image, but that new content will
    4.22      be inserted at the start node.  Wrappers in other places still need to be
    4.23      removed, because they would otherwise remain empty.
    4.24 -
    4.25 -    <li>If <var>parent</var> is <span>editable</span> or an <span>editing
    4.26 -    host</span>, is not an <span>inline node</span>, and has no [[children]],
    4.27 -    call [[createelement|"br"]] on the [[contextobject]] and append the result
    4.28 -    as the last [[child]] of <var>parent</var>.
    4.29    </ol>
    4.30  
    4.31    <li>If <var>end node</var> is an <span>editable</span> [[text]] node, call
     5.1 --- a/tests.js	Tue Nov 08 08:56:11 2011 -0700
     5.2 +++ b/tests.js	Tue Nov 08 09:40:24 2011 -0700
     5.3 @@ -689,6 +689,16 @@
     5.4  		'<ol><li>foo</ol><p>{}<br></p><ul><li>bar</ul>',
     5.5  		'<ul><li>foo</ul>{}<br><ol><li>bar</ol>',
     5.6  		'<ul><li>foo</ul><p>{}<br></p><ol><li>bar</ol>',
     5.7 +
     5.8 +		// http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
     5.9 +		'<p><b>[foo]</b>',
    5.10 +		'<p><quasit>[foo]</quasit>',
    5.11 +		'<p><b><i>[foo]</i></b>',
    5.12 +		'<p><b>{foo}</b>',
    5.13 +		'<p>{<b>foo</b>}',
    5.14 +		'<p><b>f[]</b>',
    5.15 +		'<b>[foo]</b>',
    5.16 +		'<div><b>[foo]</b></div>',
    5.17  	],
    5.18  	//@}
    5.19  	fontname: [
    5.20 @@ -1617,6 +1627,16 @@
    5.21  		'<ol><li>foo</ol><p>{}<br></p><ul><li>bar</ul>',
    5.22  		'<ul><li>foo</ul>{}<br><ol><li>bar</ol>',
    5.23  		'<ul><li>foo</ul><p>{}<br></p><ol><li>bar</ol>',
    5.24 +
    5.25 +		// http://www.w3.org/Bugs/Public/show_bug.cgi?id=13831
    5.26 +		'<p><b>[foo]</b>',
    5.27 +		'<p><quasit>[foo]</quasit>',
    5.28 +		'<p><b><i>[foo]</i></b>',
    5.29 +		'<p><b>{foo}</b>',
    5.30 +		'<p>{<b>foo</b>}',
    5.31 +		'<p><b>[]f</b>',
    5.32 +		'<b>[foo]</b>',
    5.33 +		'<div><b>[foo]</b></div>',
    5.34  	],
    5.35  	//@}
    5.36  	hilitecolor: [