Closed Bug 386310 Opened 15 years ago Closed 14 years ago

attaching anonymous element to HTML via XBL prevents display of elements attached via javascript

Categories

(Core :: XBL, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: tal_buzilla_mozilla_org, Assigned: bzbarsky)

References

Details

Attachments

(3 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)

Using XBL binding: Appending (prepending/prefixing) and anonymous html element before the <children/> of a bound HTML element in an HTML document makes it impossible to insert/wrap via javascript text contents of the bound element. 

The post-load javascript inserted element (e.g. a <span> element) is properly added to the HTML DOM, but is not displayed. Checking the calculated display and visibility rules for the 'disappeared' element do not show any reason why it is not displayed..

Reproducible: Always

Steps to Reproduce:
1. Copy following HTML to a file - e.g. bindme.html:
<script type="text/javascript">
  function onLoad() {
  var elm = document.getElementById("bound");
  var r = document.createRange();
  r.setStart(elm.lastChild, 14);
  r.setEnd(elm.lastChild, 14 + 4);
  r.surroundContents(document.createElement("span"));
  }
  window.addEventListener("load", onLoad, false);
</script>
<div id="bound" style="-moz-binding: url('bindme.xml#bindme')">one two three four</div>

2. copy following to a file named bindme.xml, under same directory as bindme.html created in step 1 above:
<bindings xmlns="http://www.mozilla.org/xbl"
         xmlns:html="http://www.w3.org/1999/xhtml">

  <binding id="bindme">
    <content>
      <html:img src="chrome://browser/skin/Throbber.gif"/>
      <children/>
    </content>
  </binding>
</bindings>
3. open the file bindme.html in firefox (make sure javascript is enabled)
4. notice how the word 'four' is not displayed?
Actual Results:  
[IMG]one two three

Expected Results:  
[IMG]one two three four

If the javascript code in the above example was to run before XBL binding takes effect (i.e. before the document completed loading), the SPAN element and its contents will be displayed properly.
Attached file XBL binding
BL binding for attached bug-recreation case
Attached file HTML example
HTML source for attached bug-recreation case
Attached file CSS source
CSS source for attached bug-recreation case
There is some kind of workaround this problem:
Creating and appending as first child a non-anonymous comment element to 'this' from withing the <constructor> of the binding rule will result in the proper display of the later-inserted SPAN element (see the workaround rule in the attached XBL binding exampe)
This somehow got fixed on the trunk by the checkin for bug 323098, I think (at least it got fixed that day, and that's the most likely-looking change there).  Not sure how.  In any case, the problem is not present on trunk. 

I'll get the test checked into the regression tests.
I spoke too soon.  The text is there, but not in the right place.  I've added the tests, anyway, but I suspect that fixing bug 307394 will be needed to fix this.
Status: UNCONFIRMED → NEW
Component: General → XBL
Depends on: 307394
Ever confirmed: true
Flags: in-testsuite+
Product: Firefox → Core
QA Contact: general → xbl
Version: unspecified → Trunk
Fixed by checkin for bug 307394.  Flagged the tests as passing now.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Assignee: nobody → bzbarsky
You need to log in before you can comment on or make changes to this bug.