<?xml version="1.0"?>

<!DOCTYPE window [
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
%textcontextDTD;
]>

<bindings id="xulBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/1999/xhtml"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  
  <binding id="thumb" extends="xul:box">
    <content>
      <xul:spring flex="1"/>
      <xul:image inherits="src"/>
      <xul:spring flex="1"/>
    </content>
  </binding>

  <binding id="slider">
    <content>
      <xul:thumb inherits="align,src" flex="1"/>
    </content>
  </binding>

  <binding id="tab">
    <content>
      <xul:image inherits="src" class="tab-left"/>
      <xul:text flex="1" inherits="value=label,crop,accesskey" crop="right" class="tab-text"/>
    </content>
  </binding>


  <binding id="menu-menubar">
    <content>
      <xul:text class="menubar-text" inherits="value=label,accesskey,crop" crop="right"/>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="menu-menubar-iconic">
    <content>
      <xul:image class="menubar-left"/>
      <xul:text class="menubar-text" inherits="value=label,accesskey,crop" crop="right"/>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="menu">
    <content autostretch="never">
      <xul:text class="menu-text" flex="1" align="left" inherits="value=label,accesskey,crop" crop="right"/>
      <xul:text class="menu-accel" inherits="value=acceltext"/>
      <xul:box autostretch="never" class="menu-right" inherits="menuactive,disabled">
        <xul:image/>
      </xul:box>
      <children includes="menupopup"/>
    </content>
    <implementation>
      <property name="value" onset="this.setAttribute('value',val); return val;"
                            onget="return this.getAttribute('value');"/>
    </implementation>  
  </binding>

  <binding id="menuitem">
    <content autostretch="never">
      <xul:text class="menu-text" flex="1" align="left" inherits="value=label,accesskey,crop" crop="right"/>
      <xul:text class="menu-accel" inherits="value=acceltext"/>
    </content>
    <implementation>
      <property name="value" onset="this.setAttribute('value',val); return val;"
                            onget="return this.getAttribute('value');"/>
    </implementation>  
  </binding>

  <binding id="menuitem-iconic">
    <content>
      <xul:box class="menu-iconic-left" orient="vertical" autostretch="never" inherits="selected,menuactive,disabled,checked">
        <xul:image inherits="src"/>
      </xul:box>
      <xul:text class="menu-iconic-text" flex="1" align="left" inherits="value=label,accesskey,crop" crop="right"/>
      <xul:text class="menu-iconic-accel" inherits="value=acceltext"/>
    </content>
    <implementation>
      <property name="value" onset="this.setAttribute('value',val); return val;"
                            onget="return this.getAttribute('value');"/>
    </implementation>  
  </binding>

  <binding id="menu-iconic">
    <content autostretch="never">
      <xul:box class="menu-iconic-left" orient="vertical" autostretch="never">
        <xul:image inherits="src"/>
      </xul:box>
      <xul:text class="menu-iconic-text" flex="1" align="left" inherits="value=label,accesskey,crop" crop="right"/>
      <xul:text class="menu-iconic-accel" inherits="value=acceltext"/>
      <xul:box orient="vertical" autostretch="never" class="menu-right" inherits="menuactive,disabled">
        <xul:image/>
      </xul:box>
      <children includes="menupopup|template"/>
    </content>
    <implementation>
      <property name="value" onset="this.setAttribute('value',val); return val;"
                            onget="return this.getAttribute('value');"/>
    </implementation>  
  </binding>
  
  <binding id="basetext">
    <implementation>
      <!-- public implementation -->
      <property name="label"      onset="return this.setAttribute('label',val);"
                                  onget="return this.getAttribute('label');"/>
      <property name="crop"       onset="return this.setAttribute('crop',val);"
                                  onget="return this.getAttribute('crop');"/>
      <property name="disabled"   onset="if (val) this.setAttribute('disabled', 'true');
                                         else this.removeAttribute('disabled');
                                         return val;"
                                  onget="var v = this.getAttribute('disabled');
                                         if (v == 'true') return true; return false;"/>                                  
      <property name="src"        onset="return this.setAttribute('src',val);"
                                  onget="return this.getAttribute('src');"/>
      <property name="accesskey"  onset="return this.setAttribute('accesskey',val);"
                                  onget="return this.getAttribute('accesskey');"/>
      <property name="imgalign"   onset="return this.setAttribute('imgalign',val);"
                                  onget="return this.getAttribute('imgalign');"/>
    </implementation>      
  </binding>
  
  <binding id="checkbox" extends="chrome://global/content/xulBindings.xml#basetext">
    <content>
      <xul:box flex="1" class="internal-box" autostretch="never" valign="top">
        <xul:box class="checkmark-box" autostretch="never">
          <xul:image class="checkbox-check"/>
        </xul:box>
        <xul:image class="checkbox-icon" inherits="src"/>
        <xul:html class="checkbox-label" inherits="value=label,accesskey,crop" flex="1">
          <children/>
        </xul:html>
      </xul:box>
    </content>
    <implementation>
      <!-- public implementation -->
      <property name="checked"    onset="if (val) this.setAttribute('checked', 'true');
                                         else this.removeAttribute('checked');
                                         return val;"
                                  onget="var v = this.getAttribute('checked');
                                         if (v == 'true') return true; return false;"/>
    </implementation>
    <handlers>
      <handler event="click" button="0" action="if (!this.disabled) this.checked = !this.checked;"/>
      <handler event="keypress" key=" " action="if (!this.disabled) this.checked = !this.checked;"/>
    </handlers>
  </binding>

  <!-- XUL <button>s -->
  <binding id="buttonleft" extends="chrome://global/content/xulBindings.xml#basetext">
    <content>
      <xul:box class="button-internal-box" autostretch="never" flex="1">
        <xul:image class="button-icon" inherits="src"/>
        <xul:box orient="vertical" class="button-text-container" autostretch="never" flex="1">
          <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top"/>
        </xul:box>
      </xul:box>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="buttontop" extends="chrome://global/content/xulBindings.xml#basetext">
    <content>
      <xul:box class="button-internal-box" orient="vertical" autostretch="never" flex="1">
        <xul:image class="button-icon" inherits="src"/>
        <xul:box orient="vertical" class="button-text-container" autostretch="never" flex="1">
          <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top"/>
        </xul:box>
      </xul:box>
      <children includes="menupopup"/>
    </content>
  </binding>
  
  <binding id="buttonright" extends="chrome://global/content/xulBindings.xml#basetext">
    <content>
      <xul:box class="button-internal-box" inherits="orient" autostretch="never" flex="1">
        <xul:box orient="vertical" class="button-text-container" autostretch="never" flex="1">
          <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top"/>
        </xul:box>
        <xul:image class="button-icon" inherits="src"/>
      </xul:box>
      <children includes="menupopup"/>
    </content>
  </binding>

  <binding id="buttonbottom" extends="chrome://global/content/xulBindings.xml#basetext">
    <content>
      <xul:box class="button-internal-box" orient="vertical" autostretch="never" flex="1">
        <xul:box orient="vertical" class="button-text-container" autostretch="never" flex="1">
          <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top"/>
        </xul:box>
        <xul:image class="button-icon" inherits="src"/>
      </xul:box>
      <children includes="menupopup"/>
    </content>
  </binding>
  
  <binding id="separator" extends="xul:spring"/>

  <!-- appending to the end so we don't make hyatt cry -->
  <binding id="progressmeter" extends="xul:box">
    <content>
      <xul:box class="progressmeter-internal-box" flex="1">
        <xul:stack class="progressmeter-stack" flex="1">
          <xul:progressbar class="progressmeter-progressbar" inherits="value,statusbar">
            <xul:box class="progress-bar"/>
            <xul:box class="progress-remainder"/>
          </xul:progressbar>
          <xul:box>
            <xul:spring flex="1"/>
            <xul:text class="progress-text" inherits="value=label"/>
            <xul:spring flex="1"/>
          </xul:box>
        </xul:stack>
      </xul:box>
    </content>
    <implementation>
      <property name="label"   onset="if (this.label != val) this.setAttribute('label',val); return val;"
                                      onget="return this.getAttribute('label');"/>
      <property name="value" onget="return this.getAttribute('value');">
      <setter>
      <![CDATA[
        var p = Math.round(val);
      var c = this.value; 
      if (p != c) {
        var delta = p - c;
        if (delta < 0) delta = -delta;
        if (delta > 3 || p == 0 || p == 100) {
          this.setAttribute('value',p); 
        }
        }
      return p;
      ]]>
    </setter>
    </property>
      <property name="mode"           onset="if (this.mode != val) this.setAttribute('mode', val); return val;"
                                      onget="return this.getAttribute('mode');"/>
    </implementation>
  </binding>

  <binding id="textbox" extends="xul:box">
    <content context="_child">
      <xul:box class="textbox-internal-box" flex="1">
        <html:input class="textbox-input" flex="1" inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly"/>
      </xul:box>
      <xul:popupset>
        <xul:popup oncreate="this.parentNode.parentNode.doPopupItemEnabling(this); this.focus();">
          <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_undo');              
            controller.doCommand('cmd_undo');"/>
          <xul:menuseparator/>
          <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_cut');
            controller.doCommand('cmd_cut');"/>
          <xul:menuitem label="&copyCmd.label;" accesskey="&copyCmd.accesskey;" cmd="cmd_copy" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_copy');
            controller.doCommand('cmd_copy');"/>
          <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_paste');
            controller.doCommand('cmd_paste');"/>
          <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_delete');
            controller.doCommand('cmd_delete');"/>
           <xul:menuseparator/>
          <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_selectAll');
            controller.doCommand('cmd_selectAll');"/>
        </xul:popup>
      </xul:popupset>
    </content>
    <implementation>
      <property name="inputField" readonly="true">
       <![CDATA[
        var v = document.getAnonymousNodes(this);
        var input = null;
        for (var i = 0; i < v.length; i++) {
          try {
            var l = v[i].getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "input");
            if (l.length > 0) {
              input = l[0];
              break;
            }
          } catch (e) {} 
        }
        input;
      ]]>
      </property>
      <property name="value"      onset="this.inputField.value = val; return val;"
                                  onget="return this.inputField.value;"/>
      <property name="type"       onset="this.inputField.type = val; return val;"
                                  onget="return this.inputField.type;"/>
      <property name="maxlength"  onset="this.inputField.maxlength = val; return val;"
                                  onget="return this.inputField.maxlength;"/>
      <property name="disabled"   onset="this.inputField.disabled = val; return val;"
                                  onget="return this.inputField.disabled;"/>
      <property name="size"       onset="this.inputField.size = val; return val;"
                                  onget="return this.inputField.size;"/>
      <property name="readonly"   onset="this.inputField.readonly = val; return val;"
                                  onget="return this.inputField.readonly;"/>

      <method name="select">
        <body>
          this.inputField.select();
        </body>
      </method>

      <method name="doPopupItemEnabling">
        <parameter name="popupNode"/> 
        <body>
          <![CDATA[
            var children = popupNode.childNodes;
            for (var i = 0; i < children.length; i++) {              
              var command = children[i].getAttribute("cmd");
              if (command) {
                var controller = document.commandDispatcher.getControllerForCommand(command);
                var enabled = controller.isCommandEnabled(command);
                if (enabled)
                  children[i].removeAttribute('disabled');
                else
                  children[i].setAttribute('disabled','true');               
              }
            }
          ]]>
        </body>
      </method>
                             
      
      <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
      <property name="textLength"     readonly="true" onget="return this.inputField.textLength;"/>
      <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
                                      onget="return this.inputField.selectionStart;"/>
      <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
                                      onget="return this.inputField.selectionEnd;"/>
     
      <property name="suppressFocusBlur">
        false
      </property>

      <method name="setSelectionRange">
        <parameter name="aSelectionStart"/>
        <parameter name="aSelectionEnd"/>
        <body>
          this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
        </body>
      </method>

      <constructor action="var str = this.boxObject.getProperty('value'); 
                                                if (str) {
                                                  this.inputField.value=str;
                                                  this.boxObject.removeProperty('value');
                                                }"/>
      <destructor action="if (this.inputField.value) this.boxObject.setProperty('value', this.inputField.value);"/>
   
    </implementation>
    <handlers>
      <handler event="focus" phase="capturing">
      <![CDATA[
        if (this.getAttribute('focused') != 'true') {
          this.setAttribute('focused','true');
          this.suppressFocusBlur = true;
          if (document.commandDispatcher.focusedElement != this.inputField) 
            this.inputField.focus();
          this.suppressFocusBlur = false;
        }
      ]]>
      </handler>
      <handler event="blur" phase="capturing">
      <![CDATA[
        if (!this.suppressFocusBlur && this.getAttribute('focused') == 'true') {
          this.removeAttribute('focused');
        }
      ]]>
      </handler>
    </handlers>    
  </binding>

  <binding id="textarea" extends="chrome://global/content/xulBindings.xml#textbox">
    <content context="_child">
      <xul:box class="textarea-internal-box" flex="1">
        <html:textarea class="textbox-textarea" flex="1" inherits="onfocus,onblur,value,disabled,rows,cols,readonly"/>
      </xul:box>
      <xul:popupset>
        <xul:popup oncreate="this.parentNode.parentNode.doPopupItemEnabling(this); this.focus();">
          <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_undo');              
            controller.doCommand('cmd_undo');"/>
          <xul:menuseparator/>
          <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_cut');
            controller.doCommand('cmd_cut');"/>
          <xul:menuitem label="&copyCmd.label;" accesskey="&copyCmd.accesskey;" cmd="cmd_copy" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_copy');
            controller.doCommand('cmd_copy');"/>
          <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_paste');
            controller.doCommand('cmd_paste');"/>
          <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_delete');
            controller.doCommand('cmd_delete');"/>
           <xul:menuseparator/>
          <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll" oncommand="
            var controller = document.commandDispatcher.getControllerForCommand('cmd_selectAll');
            controller.doCommand('cmd_selectAll');"/>
        </xul:popup>
      </xul:popupset>
    </content>
    <implementation>
      <property name="inputField" readonly="true">
       <![CDATA[
        var v = document.getAnonymousNodes(this);
        var input = null;
        for (var i = 0; i < v.length; i++) {
          try {
            var l = v[i].getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "textarea");
            if (l.length > 0) {
              input = l[0];
              break;
            }
          } catch (e) {} 
        }
        input;
      ]]>
      </property>
    </implementation>
  </binding>

  <binding id="text-label">
    <handlers>
      <handler event="click" action="var forElementID = this.getAttribute('for'); if(forElementID) var forElement = document.getElementById(forElementID); if(forElement) forElement.focus();"/>
    </handlers>
  </binding>
  
  <binding id="text-editable-display" extends="chrome://global/content/xulBindings.xml#text"/>
  
  <binding id="text-editable-edit" extends="xul:box">
    <content>
      <xul:box flex="1">
        <html:input type="text" inherits="value,type,maxlength,disabled,size,readonly"/>
      </xul:box>
    </content>
    <handlers>
      <handler event="blur" action="this.setAttribute('mode','display');"/>
    </handlers>
  </binding>

  <binding id="tooltips" extends="chrome://global/content/xulBindings.xml#popups">
    <content>
      <xul:box class="popup-internal-box" orient="vertical" flex="1">
        <children/>
      </xul:box>
    </content>
  </binding>

  <binding id="popups">
    <content>
      <!--xul:box class="popup-internal-box" orient="vertical" flex="1" style="overflow: auto">
        <children/>
      </xul:box-->

      <xul:arrowscrollbox class="popup-internal-box" flex="1" orient="vertical">
      <!--xul:box class="popup-internal-box" orient="vertical"-->
      <children/>
      <!--/xul:box-->
      </xul:arrowscrollbox>

    </content>
    <implementation>
      <method name="openPopup">
        <parameter name="element"/>
        <parameter name="xpos"/>
        <parameter name="ypos"/>
        <parameter name="popuptype"/>
        <parameter name="anchoralignment"/>
        <parameter name="popupalignment"/>
        <body>
        <![CDATA[
          try {
            var popupSetBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIPopupSetBoxObject);
          } catch(e) {}
          try {
            var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
          } catch(e) {}
          if (popupSetBox)
            popupSetBox.createPopup(element, this, xpos, ypos, popuptype, anchoralignment, popupalignment);
          else if (menuBox)
            menuBox.openMenu(true);
        ]]>
        </body>
      </method>
      <method name="closePopup">
        <body>
        <![CDATA[
          try {
            var popupSetBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIPopupSetBoxObject);
          } catch(e) {}
          try {
            var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
          } catch(e) {}
          if (popupSetBox)
            popupSetBox.destroyPopup();
          else if (menuBox)
            menuBox.openMenu(false);
        ]]>
        </body>
      </method>
      <property name="activeChild">
        <getter>
          <![CDATA[
            try {
              var popupSetBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIPopupSetBoxObject);
            } catch(e) {}
            try {
              var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
            } catch(e) {}
            if (popupSetBox)
              return popupSetBox.activeChild;
            else if (menuBox)
              return menuBox.activeChild;
            throw Components.results.NS_ERROR_FAILURE;
          ]]>
        </getter>
        <setter>
          <![CDATA[
            try {
              var popupSetBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIPopupSetBoxObject);
            } catch(e) {}
            try {
              var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
            } catch(e) {}
            if (popupSetBox)
              return popupSetBox.activeChild = val;
            else if (menuBox)
              return menuBox.activeChild = val;
            throw Components.results.NS_ERROR_FAILURE;
          ]]>
        </setter>
      </property>
    </implementation>     
    <handlers>
      <handler event="contextmenu" action="event.preventDefault();"/>
    </handlers>
  </binding>
  
  
  <!-- XUL <statusbar> -->
  <binding id="statusbar" extends="xul:box"/>
    
  <binding id="statusbar-panel" extends="xul:button">
    <content autostretch="never" valign="middle">
      <xul:image class="statusbar-panel-icon" inherits="src"/>
      <xul:text class="statusbar-panel-text" inherits="value=label,crop" crop="right" flex="1"/>
    </content>
    <implementation>
      <property name="label"
                onget="return this.getAttribute('label');"
                onset="this.setAttribute('label',val); return val;"/>
      <property name="src"
                onget="return this.getAttribute('src');"
                onset="this.setAttribute('src',val); return val;"/>
    </implementation>
  </binding>
  
  <binding id="browser">
    <implementation>
      <property name="docShell"
                readonly="true"
                onget="return this.boxObject.QueryInterface(Components.interfaces.nsIBrowserBoxObject).docShell;"/>
      <property name="webNavigation"
                readonly="true"
                onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"/>
      <property name="markupDocumentViewer"
                readonly="true"
                onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);"/>
      <property name="contentViewerEdit"
                readonly="true"
                onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerEdit);"/>
      <property name="contentViewerFile"
                readonly="true"
                onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerFile);"/>
      <property name="documentCharsetInfo"
                readonly="true"
                onget="return this.docShell.documentCharsetInfo;"/>
    </implementation>
  </binding>

  <binding id="editor">
    <implementation>
      <property name="editorShell"
                readonly="true"
                onget="return this.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).editorShell"/>
    </implementation>
  </binding>

  <binding id="iframe">
    <implementation>
      <property name="docShell"
                readonly="true"
                onget="return this.boxObject.QueryInterface(Components.interfaces.nsIIFrameBoxObject).docShell"/>
    </implementation>
  </binding>

  <binding id="titledbox">
    <content>
      <xul:box class="titledbox-title" autostretch="never" orient="vertical">
        <children includes="label"/>
      </xul:box>
      <xul:box flex="1" class="titledbox-body" inherits="orient,autostretch,align,valign">
        <children/>
      </xul:box>
    </content>    
  </binding>
    
  <binding id="label" extends="xul:box">
    <content>
      <xul:text inherits="value"/>
    </content>
  </binding>

  <binding id="autorepeatbutton-up">
     <content>
      <xul:image class="autorepeatbutton-up"/>
   </content>
  </binding>

  <binding id="autorepeatbutton-down">
     <content>
      <xul:image class="autorepeatbutton-down"/>
   </content>
  </binding>

  <binding id="scrollbox">
    <content>
    <xul:box class="scrollbox-innerbox" inherits="orient,autostretch,align,valign">
      <children/>
    </xul:box>
  </content>
  </binding>

  <binding id="arrowscrollbox">
    <content>
    <xul:vbox 
    onunderflow="
      var button1 = this.firstChild;
      var button2 = this.childNodes[2];
      button1.setAttribute('collapsed', 'true');
      button2.setAttribute('collapsed', 'true');
      " 
    onoverflow="
      var button1 = this.firstChild;
      var button2 = this.childNodes[2];
      button1.removeAttribute('collapsed');
      button2.removeAttribute('collapsed');
      ">
    <xul:autorepeatbutton autostretch="never" class="up" collapsed="true" 
        oncommand="parentNode.childNodes[1].boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject).scrollByIndex(-1);"/>
    <xul:scrollbox orient="vertical" flex="1">
     <children/>
    </xul:scrollbox>
    <xul:autorepeatbutton autostretch="never" class="down" collapsed="true" 
        oncommand="parentNode.childNodes[1].boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject).scrollByIndex(1);"/>
    </xul:vbox>
    </content>
  </binding>

  <!--
    Inline Editable UI Element
    - This binding forms the basis of the inline edit treecell and the inline edit
    - buttons. 
    - TODO: investigate creating extensions to the wrapper widgets (tree, toolbar)
    -       to make them provide some object implementing an interface similar to
    -       outliner's so we can build in some of the ile behavior (such as going
    -       in and out of the mode, asking isEditable etc) so as to remove some of
    -       the burden from the implementor. 
    -
    - Note that this widget will be no longer used in the bookmarks window once 
    - outliner is extended to have this functionality built in. 
    -->
  <binding id="inline-edit-base" extends="chrome://global/content/xulBindings.xml#basetext">
    <implementation>
      <property name="_mode">0</property>
      <method name="setMode">
        <parameter name="val"/>
        <body>
        <![CDATA[
          var ctr = document.getAnonymousElementByAttribute(this, "ileattr", "text-container");
          var txt = document.getAnonymousElementByAttribute(this, "ileattr", "text");
          this.setAttribute("mode", val);
          if (val == "edit") {
            var nodes = document.getAnonymousNodes(this);

            if (txt.getAttribute("hidden") != "true") {
              ctr.setAttribute("mode", "edit");
              var width = ctr.boxObject.width;
              txt.setAttribute("hidden", "true");
              const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
              var field = document.createElementNS(kXULNS, "textbox");
              field.className = "textbox-inline-edit";
              field.setAttribute("flex", "1");
              field.setAttribute("value", txt.getAttribute("value"));
              field.setAttribute("ileattr", "field");
              field.setAttribute("rootcontent", txt.getAttribute("rootcontent"));
              field.setAttribute("style", "width: " + width + "px");
              ctr.appendChild(field);
              field.addEventListener("keydown", this.fieldKeyDown, false);
              field.addEventListener("change", this.fieldChange, false);
              field.select();
            }
          }
          else {
            nodes = document.getAnonymousNodes(this);
            var fld = document.getAnonymousElementByAttribute(this, "ileattr", "field");
            if (fld && txt.getAttribute("hidden") == "true") {
              ctr.removeAttribute("mode");
              fld.blur();
              ctr.removeChild(fld);
              txt.removeAttribute("hidden");
            }
          }
        ]]>
        </body>
      </method>
      <property name="_observers">
      <![CDATA[
        ({
          reject: [], 
          accept: []
        })
      ]]>
      </property>
      <property name="valueIsRejected">false</property>
      <method name="addObserver">
        <parameter name="aObserver"/>
        <parameter name="aTopic"/>
        <parameter name="aParams"/>
        <body>
          this._observers[aTopic].push({ callback: aObserver, params: aParams });
        </body>
      </method>
      <method name="fieldKeyDown">
        <parameter name="aEvent"/>
        <body>
        <![CDATA[
          var rootLocalName = aEvent.target.getAttribute("rootcontent");
          if (rootLocalName) {
            // Root content is the bound element. 
            var rootContent = aEvent.target;
            while (rootContent && rootContent.localName != rootLocalName) 
              rootContent = rootContent.parentNode;
            
            if (rootContent) {
              var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
              if (aEvent.keyCode == 13) {
                rootContent.valueIsRejected = false;
                rootContent.fieldChange(aEvent);
              }
              if (aEvent.keyCode == 27) {
                rootContent.valueIsRejected = true;
                var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
                for (i = 0; i < rootContent._observers["reject"].length; ++i) 
                  rootContent._observers["reject"][i].callback(rootContent._observers["reject"][i].params.concat(fld.value), "reject");
                if ("setMode" in rootContent) 
                  rootContent.setMode("normal");
              }
            }
          }
          aEvent.preventBubble();
        ]]>
        </body>
      </method>
      <property name="valueIsAccepted">false</property>
      <method name="fieldChange">
        <parameter name="aEvent"/>
        <body>
        <![CDATA[
          var rootLocalName = this.getAttribute("rootcontent");
          if (rootLocalName) {
            // Root content is the bound element. 
            var rootContent = this;
            while (rootContent && rootContent.localName != rootLocalName) 
              rootContent = rootContent.parentNode;
            
            if (rootContent) {
              var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
              if (!rootContent.valueIsRejected) {
                var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
                for (var i = 0; i < rootContent._observers["accept"].length; ++i)
                  rootContent._observers["accept"][i].callback(rootContent._observers["accept"][i].params.concat(fld.value), "accept");
                if ("setMode" in rootContent)
                  rootContent.setMode("normal");
              }
            }
          }
        ]]>
        </body>
      </method>
    </implementation>
  </binding>

  <!-- inline editable buttons -->
  <binding id="buttonleft-ile" extends="chrome://global/content/xulBindings.xml#inline-edit-base">
    <content>
      <xul:hbox class="button-internal-box" autostretch="never" flex="1">
        <xul:image class="button-icon" inherits="src"/>
        <xul:vbox class="button-text-container" autostretch="never" flex="1" ileattr="text-container">
          <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top" ileattr="text" rootcontent="button"/>
        </xul:vbox>
      </xul:hbox>
      <children includes="menupopup"/>
    </content>
  </binding>
  

</bindings>

