<?xml version="1.0"?>

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

  <binding id="scrollbox-base">
    <resources>
      <stylesheet src="chrome://global/skin/scrollbox.css"/>
    </resources>
  </binding>

  <binding id="scrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content>
      <xul:box class="box-inherit scrollbox-innerbox" xbl:inherits="orient,align,pack,dir">
        <children/>
      </xul:box>
    </content>
  </binding>

  <binding id="arrowscrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content>
      <xul:autorepeatbutton class="autorepeatbutton-up" collapsed="true"
                            oncommand="this.parentNode.scrollByIndex(-1); event.preventBubble();"/>
      <xul:scrollbox xbl:inherits="orient,align,pack,dir" flex="1">
        <children/>
      </xul:scrollbox>
      <xul:autorepeatbutton class="autorepeatbutton-down" collapsed="true"
                            oncommand="this.parentNode.scrollByIndex(1); event.preventBubble();"/>
    </content>
    
    <implementation>
      <method name="scrollByIndex">
        <parameter name="lines"/>
        <body><![CDATA[
          if (!("mScrollBoxObject" in this)) {
            var kids = document.getAnonymousNodes(this);
            this.mScrollBoxObject = kids[1].boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
          }

          this.mScrollBoxObject.scrollByIndex(lines);
        ]]></body>
      </method>            
    </implementation>    

    <handlers>
      <handler event="DOMMouseScroll" action="this.scrollByIndex(event.detail); event.preventBubble();"/>

      <handler event="underflow"><![CDATA[
        var kids = document.getAnonymousNodes(this);
        kids[0].collapsed = true;
        kids[2].collapsed = true;
        event.preventBubble();
      ]]></handler>

      <handler event="overflow"><![CDATA[
        var kids = document.getAnonymousNodes(this);
        kids[0].collapsed = false;
        kids[2].collapsed = false;
        event.preventBubble();
      ]]></handler>
    </handlers>
  </binding>

  <binding id="autorepeatbutton" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content>
      <xul:image class="autorepeatbutton-icon"/>
    </content>
  </binding>

</bindings>
