Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

synchronous binding - how?

1 view
Skip to first unread message

Atte Kemppilä

unread,
Apr 1, 2009, 1:05:30 PM4/1/09
to dev-te...@lists.mozilla.org

I have trouble getting binding to be synchronous.

https://developer.mozilla.org/en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment

What I understood from the link above, using loadBindingDocument() and
style.MozBinding should work.

Below is my test code. I would expect it to dump "bar" on load event and when
button is clicked. But because binding doesn't seem to be synchronous, I
get "undefined" on load. dump on button click works so there's nothing wrong
with binding itself.

So, what am I doing wrong, or is synchronous binding just not possible?


XBL:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl">
<binding
id="button-foo"
extends="chrome://global/content/bindings/button.xml#button">
<implementation>
<field name="foo" readonly="true">"bar"</field>
</implementation>
</binding>
</bindings>


XUL:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad()">

<script type="text/javascript">

var xblUrl = "..."
document.loadBindingDocument(xblUrl);

function onLoad()
{
var button = document.getElementById('button');
button.style.MozBinding = "url(" + xblUrl "#button-foo)";
dump(button.foo + "\n");
}

</script>

<button id="button" label="Click me!" oncommand="dump(this.foo + '\n')" />
</window>

--
Atte Kemppilä

Boris Zbarsky

unread,
Apr 1, 2009, 2:18:31 PM4/1/09
to
Atte Kemppilä wrote:
> document.loadBindingDocument(xblUrl);

This is synchronous.

> button.style.MozBinding = "url(" + xblUrl "#button-foo)";

But this is not. It posts an event to do the restyle. Property lookups
on the node don't trigger restyles.

Does adding a layout flush here (eg. getting the boxobject size for one
of the elements involved) help?

-Boris

Atte Kemppilä

unread,
Apr 4, 2009, 5:19:18 AM4/4/09
to dev-te...@lists.mozilla.org

Yes, adding "button.boxObject.width" solved the problem. Thank you.

--
Atte Kemppilä

0 new messages