home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / bindings / textbox.xml < prev    next >
Extensible Markup Language  |  2005-07-29  |  9KB  |  221 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" xbl:inherits="context">
  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 implements="nsIAccessibleProvider, nsIDOMXULTextboxElement">
  27.       <property name="accessible">
  28.         <getter>
  29.           <![CDATA[
  30.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  31.             return accService.createXULTextBoxAccessible(this);
  32.           ]]>
  33.         </getter>
  34.       </property>
  35.  
  36.       <field name="mInputField">null</field>
  37.       
  38.       <property name="inputField" readonly="true">
  39.         <getter><![CDATA[
  40.           if (!this.mInputField)    
  41.             this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
  42.           return this.mInputField;
  43.         ]]></getter>
  44.       </property>
  45.       
  46.       <property name="value"      onset="this.inputField.value = val; return val;"
  47.                                   onget="return this.inputField.value;"/>
  48.       <property name="type"       onset="this.inputField.type = val; return val;"
  49.                                   onget="return this.inputField.type;"/>
  50.       <property name="maxLength"  onset="this.inputField.maxlength = val; return val;"
  51.                                   onget="return this.inputField.maxlength;"/>
  52.       <property name="disabled"   onset="this.inputField.disabled = val;
  53.                                          if (val) this.setAttribute('disabled', 'true');
  54.                                          else this.removeAttribute('disabled'); return val;"
  55.                                   onget="return this.inputField.disabled;"/>
  56.       <property name="size"       onset="this.inputField.size = val; return val;"
  57.                                   onget="return this.inputField.size;"/>
  58.       <property name="readonly"   onset="this.inputField.readonly = val;
  59.                                          if (val) this.setAttribute('readonly', 'true');
  60.                                          else this.removeAttribute('readonly'); return val;"
  61.                                   onget="return this.inputField.readonly;"/>
  62.  
  63.       <method name="select">
  64.         <body>
  65.           this.inputField.select();
  66.         </body>
  67.       </method>
  68.  
  69.       <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
  70.       <property name="textLength"     readonly="true" onget="return this.inputField.textLength;"/>
  71.       <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
  72.                                       onget="return this.inputField.selectionStart;"/>
  73.       <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
  74.                                       onget="return this.inputField.selectionEnd;"/>
  75.      
  76.       <method name="setSelectionRange">
  77.         <parameter name="aSelectionStart"/>
  78.         <parameter name="aSelectionEnd"/>
  79.         <body>
  80.           this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
  81.         </body>
  82.       </method>
  83.  
  84.       <constructor action="var str = this.boxObject.getProperty('value'); 
  85.                                                 if (str) {
  86.                                                   this.inputField.value=str;
  87.                                                   this.boxObject.removeProperty('value');
  88.                                                 }"/>
  89.       <destructor action="if (this.inputField.value) this.boxObject.setProperty('value', this.inputField.value);"/>
  90.    
  91.     </implementation>
  92.     
  93.     <handlers>
  94.       <handler event="focus" phase="capturing">
  95.         <![CDATA[
  96.           if (!this.hasAttribute('focused')) {
  97.             if (document.commandDispatcher.focusedElement != this.inputField) 
  98.               this.inputField.focus();
  99.             this.setAttribute('focused','true');
  100.           }
  101.         ]]>
  102.       </handler>
  103.       
  104.       <handler event="blur" phase="capturing">
  105.         <![CDATA[
  106.           this.removeAttribute('focused');
  107.         ]]>
  108.       </handler>
  109.     </handlers>    
  110.   </binding>
  111.  
  112.   <binding id="timed-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox">
  113.     <implementation>
  114.       <field name="_timer">null</field>
  115.       <property name="timeout"
  116.                 onset="this.setAttribute('timeout', val); return val;"
  117.                 onget="return parseInt(this.getAttribute('timeout')) || 0;"/>
  118.       <property name="value">
  119.         <getter>
  120.           return this.inputField.value;
  121.         </getter>
  122.         <setter>
  123.           <![CDATA[
  124.             this.inputField.value = val;
  125.             if (this._timer)
  126.               clearTimeout(this._timer);
  127.             return val;
  128.           ]]>
  129.         </setter>
  130.       </property>
  131.       <method name="_fireCommand">
  132.         <parameter name="me"/>
  133.         <body>
  134.           <![CDATA[
  135.             me._timer = null;
  136.             me.doCommand();
  137.           ]]>
  138.         </body>
  139.       </method>
  140.     </implementation>    
  141.     <handlers>
  142.       <handler event="input">
  143.         <![CDATA[
  144.           if (this._timer)
  145.             clearTimeout(this._timer);
  146.           this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this);
  147.         ]]>
  148.       </handler>
  149.       <handler event="keypress" keycode="VK_RETURN">
  150.         <![CDATA[
  151.           if (this._timer)
  152.             clearTimeout(this._timer);
  153.           this._fireCommand(this);
  154.         ]]>
  155.       </handler>
  156.     </handlers>
  157.   </binding>
  158.  
  159.   <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox">
  160.     <content>
  161.       <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context">
  162.         <html:textarea class="textbox-textarea" flex="1" anonid="input"
  163.                        xbl:inherits="onfocus,onblur,xbl:text=value,disabled,rows,cols,readonly,wrap"><children/></html:textarea>
  164.       </xul:hbox>
  165.     </content>
  166.   </binding>
  167.  
  168.   <binding id="input-box">
  169.     <content context="_child">
  170.       <children/>
  171.       <xul:menupopup anonid="input-box-contextmenu"
  172.                      onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild) 
  173.                                        this.parentNode.firstChild.focus();
  174.                                      this.parentNode.doPopupItemEnabling(this);"
  175.                      oncommand="this.parentNode.doCommand(event.originalTarget.getAttribute('cmd'));event.preventBubble();">
  176.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
  177.         <xul:menuseparator/>
  178.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
  179.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/>
  180.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
  181.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
  182.         <xul:menuseparator/>
  183.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
  184.       </xul:menupopup>
  185.     </content>
  186.  
  187.     <implementation>
  188.       <method name="doPopupItemEnabling">
  189.         <parameter name="popupNode"/> 
  190.         <body>
  191.           <![CDATA[
  192.             var children = popupNode.childNodes;
  193.             for (var i = 0; i < children.length; i++) {
  194.               var command = children[i].getAttribute("cmd");
  195.               if (command) {
  196.                 var controller = document.commandDispatcher.getControllerForCommand(command);
  197.                 var enabled = controller.isCommandEnabled(command);
  198.                 if (enabled)
  199.                   children[i].removeAttribute("disabled");
  200.                 else
  201.                   children[i].setAttribute("disabled", "true");               
  202.               }
  203.             }
  204.           ]]>
  205.         </body>
  206.       </method>
  207.  
  208.       <method name="doCommand">
  209.         <parameter name="command"/>
  210.         <body>
  211.           <![CDATA[
  212.             var controller = document.commandDispatcher.getControllerForCommand(command);
  213.             controller.doCommand(command);
  214.           ]]>
  215.         </body>
  216.       </method>
  217.     </implementation>
  218.   </binding>
  219.   
  220. </bindings>
  221.