<?xml version="1.0"?>

<bindings xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<binding id="counter">
  <content>
      <xul:vbox>
         <xul:groupbox>
            <!-- the value of label attribute of this caption tag, is equal to the value
            of caption attribute of the tag which is binding to our xbl component -->
            <xul:caption  xbl:inherits="label=caption" />
            <xul:textbox id="count" readonly="yes" value="" />
         </xul:groupbox>
         <xul:hbox pack="center">
            <xul:button label="Dec (-)"  oncommand="parentNode.parentNode.parentNode.decrement()"   />
            <xul:button label="Clear"    oncommand="parentNode.parentNode.parentNode.clear()" />
            <xul:button label="Inc (+)"   oncommand="parentNode.parentNode.parentNode.increment()"   />
         </xul:hbox>
      </xul:vbox>
  </content>
  <resources>
     <stylesheet src="counter.css" />
  </resources>
  <implementation>

    <constructor><![CDATA[
      /* on construction, our counter property is equal to the value
         of countvalue attribute of the tag which is binding to our xbl component */

      this.counter=parseInt(this.getAttribute('countvalue'));
      ]]>
    </constructor>

    <property name="counter"
          onget="return this.getAttribute('countvalue');"
          onset="return this.setCounter(val);"/>

    <method name="setCounter">
      <parameter name="count"/>
      <body>
        <![CDATA[
          document.getAnonymousNodes(this)[0].childNodes[0].childNodes[2].setAttribute('value',count);
          this.setAttribute('countvalue',count);
          return count;
        ]]>
      </body>
    </method>
    <method name="increment">
      <body>
          this.counter ++;
      </body>
    </method>
    <method name="decrement">
      <body>
         this.setCounter(this.counter-1); /* same as this.counter--;  ;-) */
      </body>
    </method>
    <method name="clear">
      <body>
           this.setCounter(0);
      </body>
    </method>

  </implementation>

</binding>
</bindings>