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

Multiple bindings on an Element with XBL (1)?

6 views
Skip to first unread message

StefanoC

unread,
Jun 4, 2009, 12:24:02 PM6/4/09
to
Hello!

is there any way to attach multiple bindings to one single element
with XBL 1?

examples all start from very modular bindings, eg.

two different behaviors on a mouse click
one binding for 'aesthetic' behavior, the other for logic, possibility
to switch one of them only
etc.etc.

The spec says it should be possible (https://developer.mozilla.org/En/
XBL/XBL_1.0_Reference/Anonymous_Content) but I know there's quite a
difference from that spec to FF implementation, and I simply couldn't
find a way to do it.

Any idea?
thanks a lot,
Stefano

Boris Zbarsky

unread,
Jun 4, 2009, 12:49:19 PM6/4/09
to
StefanoC wrote:
> is there any way to attach multiple bindings to one single element
> with XBL 1?

Only if they extend each other or are attached from script via
document.addBinding.

-Boris

StefanoC

unread,
Jun 4, 2009, 8:31:35 PM6/4/09
to

Thanks Boris for your prompt answer.
'extends' is not an option, since i'd like the bindings to be
independent one from each other.

addBinding is giving me some headaches, in particular it does not add
the <content> template!!!
When i attach the same binding to the same element using MozBinding or
a style it does work.

Also, removeBinding does not work at all, giving me an error:

uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIDOMDocumentXBL.removeBinding]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://js.mixendo.local/html/test.html :: onclick :: line 1" data: no]
[Break on this error]


Any idea?
thanks a lot,

Stefano

My JS code:

element=$('#elID')[0]; //using jQuery or any other method
document.addBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind1')
document.addBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind2')
[...]
document.removeBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind1')
document.removeBinding(element,'chrome://testmultibindings/content/
bindings.xml#bind2')

and 2 simple almost identical bindings:

<binding id="bind1" inheritstyle ="false">
<content>
<children/>
<span>bind1</span>
</content>
<implementation>
<constructor>
<![CDATA[
console.log('bind1')
]]>
</constructor>
<destructor>
<![CDATA[
console.log('destructor bind1')
]]>
</destructor>
</implementation>
<handlers>
<handler event="click">
<![CDATA[
console.log('click bind1')
]]>
</handler>
</handlers>
</binding>

Boris Zbarsky

unread,
Jun 4, 2009, 8:42:16 PM6/4/09
to
StefanoC wrote:
> addBinding is giving me some headaches, in particular it does not add
> the <content> template!!!
> When i attach the same binding to the same element using MozBinding or
> a style it does work.

Odd. Do you have a testcase in the form of an extension, just to make
sure we're looking at the same thing? Nothing I see in the code should
obviously keep that from working. That said, if you have multiple
bindings that all have <content>, behavior will of course be odd (e.g.
depend on the order you called addBinding in).

> Also, removeBinding does not work at all, giving me an error:
>
> uncaught exception: [Exception... "Component returned failure code:
> 0x80004005 (NS_ERROR_FAILURE) [nsIDOMDocumentXBL.removeBinding]"
> nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
> http://js.mixendo.local/html/test.html :: onclick :: line 1" data: no]
> [Break on this error]

Presumably due to this:

// For now we can only handle removing a binding if it's the only one
NS_ENSURE_FALSE(binding->GetBaseBinding(), NS_ERROR_FAILURE);

Basically, what you're trying to do is not very well supported.

-Boris

StefanoC

unread,
Jun 6, 2009, 11:47:37 AM6/6/09
to

Boris,
thanks a lot for your answer and time.
Indeed, it sounds like we better wait for XBL2 to use multiple
bindings!

For the not-showing content problem i'll clean up and send you a
sample extension if you care.

thanks,
Stefano

Boris Zbarsky

unread,
Jun 6, 2009, 2:19:31 PM6/6/09
to
StefanoC wrote:
> For the not-showing content problem i'll clean up and send you a
> sample extension if you care.

Please do.

-Boris

L. David Baron

unread,
Jun 7, 2009, 12:09:29 PM6/7/09
to dev-te...@lists.mozilla.org
On Thursday 2009-06-04 20:42 -0400, Boris Zbarsky wrote:
> StefanoC wrote:
>> addBinding is giving me some headaches, in particular it does not add
>> the <content> template!!!
>> When i attach the same binding to the same element using MozBinding or
>> a style it does work.
>
> Odd. Do you have a testcase in the form of an extension, just to make

I thought that was how it was supposed to work (using <content> only
for bindings attached via -moz-binding), but I'm not particularly
sure I know what I'm talking about here.

-David

--
L. David Baron http://dbaron.org/
Mozilla Corporation http://www.mozilla.com/

Boris Zbarsky

unread,
Jun 7, 2009, 10:12:31 PM6/7/09
to
L. David Baron wrote:
> I thought that was how it was supposed to work (using <content> only
> for bindings attached via -moz-binding)

That's what I seemed to recall, but I just don't see where the code
enforces that....

-Boris

StefanoC

unread,
Jun 17, 2009, 11:53:26 AM6/17/09
to

Sorry I took some time to clean up the code and my tests.

I can confirm the following practical findings:

1. removeBinding does not work seem to work (NS_ERROR_FAILURE)
2. in order to remove a binding set with -moz-binding (or
style.MozBinding), an 'empty' binding must be used (eg. * { -moz-
binding: url('bindings.xml#empty') } ). Any other way?
3. addBinding only works with bindings in the chrome://
4. addBinding does allow to add multiple bindings to one element
5. <content> of bindings added with addBinding is not used!!

Though probably you all knew this already, it's hard to find this kind
of information somewhere - the MDC doc is often out of date or
incomplete, unluckily (yes I know, it's extremely hard to keep a doc
up to date!!!)

Boris, I'll send you a zip file with some test files - if that's
redundant just drop it altogether :-)

Thanks a lot for your support,
Stefano

Boris Zbarsky

unread,
Jul 2, 2009, 7:59:24 PM7/2/09
to
StefanoC wrote:
> 5. <content> of bindings added with addBinding is not used!!

That's not quite right. It _is_ used if the layout objects for the node
are ever recreated. Bug addBinding on its own doesn't trigger such
recreation (probably a bug, really).

For example, if I change your code that adds the binding to look like this:

document.addBinding($('#tobind')[0],

'chrome://multibindings/content/bindings.xml#bind1');
$('#tobind')[0].style.display = 'none';
document.body.offsetWidth;
$('#tobind')[0].style.display = '';

Then the <content> works just fine...

-Boris

stefano

unread,
Jul 3, 2009, 5:52:52 AM7/3/09
to

Very true!
thanks Boris.

the latest <content> apparently overrides the previous one, which
might be acceptable.

Now if i had a pattern to remove these multiple bindings knowing that
removeBinding does not work that woudl be great!
hopefully Jonas's XBL2 is coming soon ;-)

stefano

0 new messages