Fix bug in collapsed line break definition
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Sun, 19 Jun 2011 15:49:44 -0600
changeset 299 ffcb5ceacab0
parent 298 7ce14572f0b5
child 300 f654c59dd768
Fix bug in collapsed line break definition

In <span>foo<br></span>bar, the <br> was showing as collapsed because
its height wasn't counted as part of the <span>. Fix it by going up to
the nearest non-inline ancestor.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Sun Jun 19 15:39:27 2011 -0600
+++ b/editcommands.html	Sun Jun 19 15:49:44 2011 -0600
@@ -441,9 +441,10 @@
 <p class=XXX>Is this a good definition at all?  I mean things like
 &lt;p&gt;foo&lt;br&gt;&lt;/p&gt;, or the second one in &lt;p&gt;foo&lt;br&gt;&lt;br&gt;&lt;/p&gt;.
 The way I test it is by adding a text node after it containing a zwsp; if that
-changes the offsetHeight, I deem it collapsed.  But what if it happens to be
-display: none right now, for instance?  Would it be better to use some
-DOM-based definition?
+changes the offsetHeight of its nearest non-inline ancestor, I deem it
+collapsed.  But what if it happens to be display: none right now, for instance?
+Or its ancestor has a fixed height?  Would it be better to use some DOM-based
+definition?
 
 <p>Each <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/html/#htmldocument>HTMLDocument</a></code> has a boolean <dfn id=css-styling-flag>CSS styling flag</dfn> associated
 with it, which must initially be false.  (<a href=#the-stylewithcss-command>The <code title="">styleWithCSS</code> command</a> can be used to modify or query it, by
--- a/implementation.js	Sun Jun 19 15:39:27 2011 -0600
+++ b/implementation.js	Sun Jun 19 15:49:44 2011 -0600
@@ -667,11 +667,17 @@
 		return false;
 	}
 
-	// Add a zwsp after it and see if that changes the height.
+	// Add a zwsp after it and see if that changes the height of the nearest
+	// non-inline parent.  Note: this is not actually reliable, because the
+	// parent might have a fixed height or something.
+	var ref = br.parentNode;
+	while (getComputedStyle(ref).display == "inline") {
+		ref = ref.parentNode;
+	}
 	var space = document.createTextNode("\u200b");
-	var origHeight = br.parentNode.offsetHeight;
+	var origHeight = ref.offsetHeight;
 	br.parentNode.insertBefore(space, br.nextSibling);
-	var finalHeight = br.parentNode.offsetHeight;
+	var finalHeight = ref.offsetHeight;
 	space.parentNode.removeChild(space);
 
 	return origHeight != finalHeight;
--- a/source.html	Sun Jun 19 15:39:27 2011 -0600
+++ b/source.html	Sun Jun 19 15:49:44 2011 -0600
@@ -383,9 +383,10 @@
 <p class=XXX>Is this a good definition at all?  I mean things like
 &lt;p>foo&lt;br>&lt;/p>, or the second one in &lt;p>foo&lt;br>&lt;br>&lt;/p>.
 The way I test it is by adding a text node after it containing a zwsp; if that
-changes the offsetHeight, I deem it collapsed.  But what if it happens to be
-display: none right now, for instance?  Would it be better to use some
-DOM-based definition?
+changes the offsetHeight of its nearest non-inline ancestor, I deem it
+collapsed.  But what if it happens to be display: none right now, for instance?
+Or its ancestor has a fixed height?  Would it be better to use some DOM-based
+definition?
 
 <p>Each [[htmldocument]] has a boolean <dfn>CSS styling flag</dfn> associated
 with it, which must initially be false.  (<span>The <code