home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / bindings / textbox.xml < prev    next >
Extensible Markup Language  |  2002-11-11  |  8KB  |  200 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window [
  4.   <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
  5.   %textcontextDTD;
  6. ]>
  7.  
  8. <bindings id="textboxBindings"
  9.    xmlns="http://www.mozilla.org/xbl"
  10.    xmlns:html="http://www.w3.org/1999/xhtml"
  11.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  12.    xmlns:xbl="http://www.mozilla.org/xbl">
  13.  
  14.   <binding id="textbox" extends="xul:box">
  15.     <resources>
  16.       <stylesheet src="chrome://global/skin/textbox.css"/>
  17.     </resources>
  18.     
  19.     <content>
  20.       <xul:hbox class="textbox-input-box" flex="1">
  21.         <html:input class="textbox-input" flex="1" anonid="input"
  22.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex,accesskey"/>
  23.       </xul:hbox>
  24.     </content>
  25.     
  26.     <implementation>
  27.       <field name="mInputField">null</field>
  28.       
  29.       <property name="inputField" readonly="true">
  30.         <getter><![CDATA[
  31.           if (!this.mInputField)    
  32.             this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
  33.           return this.mInputField;
  34.         ]]></getter>
  35.       </property>
  36.       
  37.       <property name="value"      onset="this.inputField.value = val; return val;"
  38.                                   onget="return this.inputField.value;"/>
  39.       <property name="type"       onset="this.inputField.type = val; return val;"
  40.                                   onget="return this.inputField.type;"/>
  41.       <property name="maxlength"  onset="this.inputField.maxlength = val; return val;"
  42.                                   onget="return this.inputField.maxlength;"/>
  43.       <property name="disabled"   onset="this.inputField.disabled = val;
  44.                                          if (val) this.setAttribute('disabled', 'true');
  45.                                          else this.removeAttribute('disabled'); return val;"
  46.                                   onget="return this.inputField.disabled;"/>
  47.       <property name="size"       onset="this.inputField.size = val; return val;"
  48.                                   onget="return this.inputField.size;"/>
  49.       <property name="readonly"   onset="this.inputField.readonly = val;
  50.                                          if (val) this.setAttribute('readonly', 'true');
  51.                                          else this.removeAttribute('readonly'); return val;"
  52.                                   onget="return this.inputField.readonly;"/>
  53.                             
  54.       <method name="select">
  55.         <body>
  56.           this.inputField.select();
  57.         </body>
  58.       </method>
  59.  
  60.       <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
  61.       <property name="textLength"     readonly="true" onget="return this.inputField.textLength;"/>
  62.       <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
  63.                                       onget="return this.inputField.selectionStart;"/>
  64.       <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
  65.                                       onget="return this.inputField.selectionEnd;"/>
  66.      
  67.       <method name="setSelectionRange">
  68.         <parameter name="aSelectionStart"/>
  69.         <parameter name="aSelectionEnd"/>
  70.         <body>
  71.           this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
  72.         </body>
  73.       </method>
  74.  
  75.       <constructor action="var str = this.boxObject.getProperty('value'); 
  76.                                                 if (str) {
  77.                                                   this.inputField.value=str;
  78.                                                   this.boxObject.removeProperty('value');
  79.                                                 }"/>
  80.       <destructor action="if (this.inputField.value) this.boxObject.setProperty('value', this.inputField.value);"/>
  81.    
  82.     </implementation>
  83.     
  84.     <handlers>
  85.       <handler event="focus" phase="capturing">
  86.         <![CDATA[
  87.           if (!this.hasAttribute('focused')) {
  88.             if (document.commandDispatcher.focusedElement != this.inputField) 
  89.               this.inputField.focus();
  90.             this.setAttribute('focused','true');
  91.           }
  92.         ]]>
  93.       </handler>
  94.       
  95.       <handler event="blur" phase="capturing">
  96.         <![CDATA[
  97.           this.removeAttribute('focused');
  98.         ]]>
  99.       </handler>
  100.     </handlers>    
  101.   </binding>
  102.  
  103.   <binding id="timed-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox">
  104.     <content>
  105.       <xul:hbox class="textbox-input-box" flex="1">
  106.         <html:input class="textbox-input" flex="1" anonid="input"
  107.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex"/>
  108.       </xul:hbox>
  109.     </content>
  110.     <implementation>
  111.       <field name="_timer">null</field>
  112.       <property name="callback"
  113.                 onset="this.setAttribute('callback', val); return val;"
  114.                 onget="return this.getAttribute('callback');"/>
  115.       <property name="timeout"
  116.                 onset="this.setAttribute('timeout', val); return val;"
  117.                 onget="var t = parseInt(this.getAttribute('timeout')); return t ? t : 0;"/>
  118.     </implementation>    
  119.     <handlers>
  120.       <handler event="input">
  121.         <![CDATA[
  122.           if (this._timer)
  123.             clearTimeout(this._timer);
  124.           this._timer = setTimeout(this.callback, this.timeout);
  125.         ]]>
  126.       </handler>
  127.       <handler event="keypress">
  128.         <![CDATA[
  129.           if (event.keyCode == 13) {
  130.             if (this._timer)
  131.               clearTimeout(this._timer);
  132.             eval(this.callback);
  133.           }
  134.         ]]>
  135.       </handler>
  136.     </handlers>
  137.   </binding>
  138.  
  139.   <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox">
  140.     <content>
  141.       <xul:hbox class="textbox-input-box" flex="1">
  142.         <html:textarea class="textbox-textarea" flex="1" anonid="input"
  143.                        xbl:inherits="onfocus,onblur,value,disabled,rows,cols,readonly,wrap"/>
  144.       </xul:hbox>
  145.     </content>
  146.   </binding>
  147.  
  148.   <binding id="input-box">
  149.     <content context="_child">
  150.       <children/>
  151.       <xul:menupopup onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild) 
  152.                                        this.parentNode.firstChild.focus();
  153.                                      this.parentNode.doPopupItemEnabling(this);"
  154.                      oncommand="this.parentNode.doCommand(event.originalTarget.getAttribute('cmd'));">
  155.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
  156.         <xul:menuitem label="&redoCmd.label;" accesskey="&redoCmd.accesskey;" cmd="cmd_redo"/>
  157.         <xul:menuseparator/>
  158.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
  159.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/>
  160.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
  161.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
  162.         <xul:menuseparator/>
  163.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
  164.       </xul:menupopup>
  165.     </content>
  166.  
  167.     <implementation>
  168.       <method name="doPopupItemEnabling">
  169.         <parameter name="popupNode"/> 
  170.         <body>
  171.           <![CDATA[
  172.             var children = popupNode.childNodes;
  173.             for (var i = 0; i < children.length; i++) {              
  174.               var command = children[i].getAttribute("cmd");
  175.               if (command) {
  176.                 var controller = document.commandDispatcher.getControllerForCommand(command);
  177.                 var enabled = controller.isCommandEnabled(command);
  178.                 if (enabled)
  179.                   children[i].removeAttribute("disabled");
  180.                 else
  181.                   children[i].setAttribute("disabled", "true");               
  182.               }
  183.             }
  184.           ]]>
  185.         </body>
  186.       </method>
  187.  
  188.       <method name="doCommand">
  189.         <parameter name="command"/>
  190.         <body>
  191.           <![CDATA[
  192.             var controller = document.commandDispatcher.getControllerForCommand(command);
  193.             controller.doCommand(command);
  194.           ]]>
  195.         </body>
  196.       </method>
  197.     </implementation>
  198.   </binding>
  199.   
  200. </bindings>