home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / global / bindings / textbox.xml < prev    next >
Encoding:
Extensible Markup Language  |  2008-02-20  |  21.9 KB  |  542 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  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.       <children/>
  21.       <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context,spellcheck">
  22.         <html:input class="textbox-input" flex="1" anonid="input"
  23.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex,accesskey"/>
  24.       </xul:hbox>
  25.     </content>
  26.  
  27.     <implementation implements="nsIAccessibleProvider, nsIDOMXULTextBoxElement, nsIDOMXULLabeledControlElement">
  28.       <property name="accessibleType" readonly="true">
  29.         <getter>
  30.           <![CDATA[
  31.             return Components.interfaces.nsIAccessibleProvider.XULTextBox;
  32.           ]]>
  33.         </getter>
  34.       </property>
  35.  
  36.       <!-- nsIDOMXULLabeledControlElement -->
  37.       <field name="crop">""</field>
  38.       <field name="image">""</field>
  39.       <field name="command">""</field>
  40.       <field name="accessKey">""</field>
  41.  
  42.       <field name="mInputField">null</field>
  43.       <field name="mIgnoreClick">false</field>
  44.       <field name="mIgnoreFocus">false</field>
  45.  
  46.       <property name="inputField" readonly="true">
  47.         <getter><![CDATA[
  48.           if (!this.mInputField)
  49.             this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
  50.           return this.mInputField;
  51.         ]]></getter>
  52.       </property>
  53.  
  54.       <property name="value"
  55.                 onget="return this.hasAttribute('empty') ? '' : this.inputField.value;">
  56.         <setter><![CDATA[
  57.           if (val) {
  58.             // clear the emptyText _before_ setting a new non-empty value
  59.             this._clearEmptyText();
  60.             this.inputField.value = val;
  61.           } else {
  62.             // display the emptyText _after_ setting a value that's an empty string
  63.             this.inputField.value = val;
  64.             this._updateVisibleText();
  65.           }
  66.           return val;
  67.         ]]></setter>
  68.       </property>
  69.       <property name="defaultValue" onset="this.inputField.defaultValue = val; return val;"
  70.                                   onget="return this.inputField.defaultValue;"/>
  71.       <property name="label"      onset="this.setAttribute('label', val); return val;"
  72.                                   onget="return this.getAttribute('label') ||
  73.                                                 (this.labelElement ? this.labelElement.value :
  74.                                                  this.emptyText);"/>
  75.       <property name="emptyText"  onget="return this.getAttribute('emptytext') || '';"
  76.                                   onset="this.setAttribute('emptytext', val);
  77.                                          this._updateVisibleText(); return val;" />
  78.       <property name="type"       onset="if (val) this.setAttribute('type', val);
  79.                                          else this.removeAttribute('type'); return val;"
  80.                                   onget="return this.getAttribute('type');"/>
  81.       <property name="maxLength"  onset="this.inputField.maxLength = val; return val;"
  82.                                   onget="return this.inputField.maxLength;"/>
  83.       <property name="disabled"   onset="this.inputField.disabled = val;
  84.                                          if (val) this.setAttribute('disabled', 'true');
  85.                                          else this.removeAttribute('disabled'); return val;"
  86.                                   onget="return this.inputField.disabled;"/>
  87.       <property name="tabIndex"   onget="return parseInt(this.getAttribute('tabindex'));"
  88.                                   onset="this.inputField.tabIndex = val;
  89.                                          if (val) this.setAttribute('tabindex', val);
  90.                                          else this.removeAttribute('tabindex'); return val;"/>
  91.       <property name="size"       onset="this.inputField.size = val; return val;"
  92.                                   onget="return this.inputField.size;"/>
  93.       <property name="readOnly"   onset="this.inputField.readOnly = val;
  94.                                          if (val) this.setAttribute('readonly', 'true');
  95.                                          else this.removeAttribute('readonly'); return val;"
  96.                                   onget="return this.inputField.readOnly;"/>
  97.       <property name="clickSelectsAll"
  98.                 onget="return this.getAttribute('clickSelectsAll') == 'true';"
  99.                 onset="if (val) this.setAttribute('clickSelectsAll', 'true');
  100.                        else this.removeAttribute('clickSelectsAll'); return val;" />
  101.  
  102.       <property name="editor" readonly="true">
  103.         <getter><![CDATA[
  104.           const nsIDOMNSEditableElement = Components.interfaces.nsIDOMNSEditableElement;
  105.           return this.inputField.QueryInterface(nsIDOMNSEditableElement).editor;
  106.         ]]></getter>
  107.       </property>
  108.  
  109.       <method name="reset">
  110.         <body><![CDATA[
  111.           this.value = this.defaultValue;
  112.           try {
  113.             this.editor.transactionManager.clear();
  114.             return true;
  115.           }
  116.           catch(e) {}
  117.           return false;
  118.         ]]></body>
  119.       </method>
  120.  
  121.       <method name="select">
  122.         <body>
  123.           this.inputField.select();
  124.         </body>
  125.       </method>
  126.  
  127.       <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
  128.       <property name="textLength"     readonly="true"
  129.                                       onget="return this.hasAttribute('empty') ?
  130.                                                     0 : this.inputField.textLength;"/>
  131.       <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
  132.                                       onget="return this.inputField.selectionStart;"/>
  133.       <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
  134.                                       onget="return this.inputField.selectionEnd;"/>
  135.  
  136.       <method name="setSelectionRange">
  137.         <parameter name="aSelectionStart"/>
  138.         <parameter name="aSelectionEnd"/>
  139.         <body>
  140.           this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
  141.         </body>
  142.       </method>
  143.  
  144.       <method name="_setNewlineHandling">
  145.         <body><![CDATA[
  146.           var str = this.getAttribute("newlines");
  147.           if (str) {
  148.             const nsIPlaintextEditor = Components.interfaces.nsIPlaintextEditor;
  149.             for (var x in nsIPlaintextEditor) {
  150.               if (/^eNewlines/.test(x)) {
  151.                 if (str == RegExp.rightContext.toLowerCase()) {
  152.                   this.editor.QueryInterface(nsIPlaintextEditor)
  153.                       .newlineHandling = nsIPlaintextEditor[x];
  154.                   break;
  155.                 }
  156.               }
  157.             }
  158.           }
  159.         ]]></body>
  160.       </method>
  161.  
  162.       <method name="_updateVisibleText">
  163.         <body><![CDATA[
  164.           if (!this.hasAttribute("focused") &&
  165.               !this.value &&
  166.               this.emptyText) {
  167.             // This section is a wee bit hacky; without the timeout, the CSS
  168.             // style corresponding to the "empty" attribute doesn't kick in
  169.             // until the text has changed, leading to an unpleasant moment
  170.             // where the emptyText flashes black before turning gray.
  171.             this.setAttribute("empty", true);
  172.  
  173.             setTimeout(function (textbox) {
  174.               if (textbox.hasAttribute("empty")) {
  175.                 try {
  176.                   textbox.editor.transactionManager.beginBatch();
  177.                 } catch (e) {}
  178.                 textbox.inputField.value = textbox.emptyText;
  179.               }
  180.             }, 0, this);
  181.           }
  182.         ]]></body>
  183.       </method>
  184.  
  185.       <method name="_clearEmptyText">
  186.         <body><![CDATA[
  187.           if (this.hasAttribute("empty")) {
  188.             this.inputField.value = "";
  189.             try {
  190.               this.editor.transactionManager.endBatch();
  191.             } catch (e) {}
  192.             this.removeAttribute("empty");
  193.           }
  194.         ]]></body>
  195.       </method>
  196.  
  197.       <constructor><![CDATA[
  198.         var str = this.boxObject.getProperty("value");
  199.         if (str) {
  200.           this.inputField.value = str;
  201.           this.boxObject.removeProperty("value");
  202.         }
  203.  
  204.         // this.editor may not be initialized yet in
  205.         // bindings that inherit from xul:textbox, so
  206.         // do this after construction
  207.         setTimeout(function (a) {
  208.           a._updateVisibleText();
  209.           a._setNewlineHandling();
  210.         }, 0, this);
  211.       ]]></constructor>
  212.  
  213.       <destructor>
  214.         <![CDATA[
  215.           if (this.inputField.value)
  216.             this.boxObject.setProperty('value', this.inputField.value);
  217.           this.mInputField = null;
  218.         ]]>
  219.       </destructor>
  220.  
  221.     </implementation>
  222.  
  223.     <handlers>
  224.       <handler event="focus" phase="capturing">
  225.         <![CDATA[
  226.           this._clearEmptyText();
  227.  
  228.           if (!this.hasAttribute("focused")) {
  229.             if (event.originalTarget == this)
  230.               this.inputField.focus(); // Forward focus to actual HTML input
  231.             else if (event.originalTarget != this.inputField)
  232.               return; // Allow other children (e.g. URL bar buttons) to get focus
  233.             else if (this.mIgnoreFocus)
  234.               this.mIgnoreFocus = false;
  235.             else if (this.clickSelectsAll) {
  236.               try {
  237.                 const nsIEditorIMESupport =
  238.                         Components.interfaces.nsIEditorIMESupport;
  239.                 var imeEditor = this.editor.QueryInterface(nsIEditorIMESupport);
  240.                 if (!imeEditor || !imeEditor.composing)
  241.                   this.editor.selectAll();
  242.               } catch (e) {}
  243.             }
  244.  
  245.             this.setAttribute("focused", "true");
  246.           }
  247.         ]]>
  248.       </handler>
  249.  
  250.       <handler event="blur" phase="capturing">
  251.         <![CDATA[
  252.           this.removeAttribute('focused');
  253.           this._updateVisibleText();
  254.         ]]>
  255.       </handler>
  256.  
  257.       <handler event="dragover" phase="capturing">
  258.         this._clearEmptyText();
  259.       </handler>
  260.  
  261.       <handler event="dragexit" phase="capturing">
  262.         this._updateVisibleText();
  263.       </handler>
  264.  
  265.       <handler event="mousedown">
  266.         <![CDATA[
  267.           this.mIgnoreClick = this.hasAttribute("focused");
  268.  
  269.           if (!this.mIgnoreClick) {
  270.             this.mIgnoreFocus = true;
  271.             this.inputField.setSelectionRange(0, 0);
  272.           }
  273.         ]]>
  274.       </handler>
  275.  
  276.       <handler event="click">
  277.         <![CDATA[
  278.           if (!this.mIgnoreClick && this.clickSelectsAll &&
  279.               this.inputField.selectionStart == this.inputField.selectionEnd) {
  280.             this.focus();
  281.             this.editor.selectAll();
  282.           }
  283.         ]]>
  284.       </handler>
  285.     </handlers>
  286.   </binding>
  287.  
  288.   <binding id="timed-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox">
  289.     <implementation>
  290.       <field name="_timer">null</field>
  291.       <property name="timeout"
  292.                 onset="this.setAttribute('timeout', val); return val;"
  293.                 onget="return parseInt(this.getAttribute('timeout')) || 0;"/>
  294.       <property name="value"
  295.                 onget="return this.hasAttribute('empty') ? '' : this.inputField.value;">
  296.         <setter><![CDATA[
  297.           if (val) {
  298.             // clear the emptyText _before_ setting a new non-empty value
  299.             this._clearEmptyText();
  300.             this.inputField.value = val;
  301.           } else {
  302.             // display the emptyText _after_ setting a value that's an empty string
  303.             this.inputField.value = val;
  304.             this._updateVisibleText();
  305.           }
  306.           if (this._timer)
  307.             clearTimeout(this._timer);
  308.           return val;
  309.         ]]></setter>
  310.       </property>
  311.       <method name="_fireCommand">
  312.         <parameter name="me"/>
  313.         <body>
  314.           <![CDATA[
  315.             me._timer = null;
  316.             me.doCommand();
  317.           ]]>
  318.         </body>
  319.       </method>
  320.     </implementation>
  321.     <handlers>
  322.       <handler event="input">
  323.         <![CDATA[
  324.           if (this._timer)
  325.             clearTimeout(this._timer);
  326.           this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this);
  327.         ]]>
  328.       </handler>
  329.       <handler event="keypress" keycode="VK_RETURN">
  330.         <![CDATA[
  331.           if (this._timer)
  332.             clearTimeout(this._timer);
  333.           this._fireCommand(this);
  334.           event.preventDefault();
  335.         ]]>
  336.       </handler>
  337.     </handlers>
  338.   </binding>
  339.  
  340.   <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox">
  341.     <content>
  342.       <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="context,spellcheck">
  343.         <html:textarea class="textbox-textarea" flex="1" anonid="input"
  344.                        xbl:inherits="onfocus,onblur,xbl:text=value,disabled,tabindex,rows,cols,readonly,wrap"><children/></html:textarea>
  345.       </xul:hbox>
  346.     </content>
  347.   </binding>
  348.  
  349.   <binding id="input-box">
  350.     <content context="_child">
  351.       <children/>
  352.       <xul:menupopup anonid="input-box-contextmenu"
  353.                      onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild)
  354.                                        this.parentNode.firstChild.focus();
  355.                                      this.parentNode._doPopupItemEnabling(this);"
  356.                      oncommand="var cmd = event.originalTarget.getAttribute('cmd'); if(cmd) { this.parentNode.doCommand(cmd); event.stopPropagation(); }">
  357.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
  358.         <xul:menuseparator/>
  359.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
  360.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/>
  361.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
  362.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
  363.         <xul:menuseparator/>
  364.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
  365.       </xul:menupopup>
  366.     </content>
  367.  
  368.     <implementation>
  369.       <method name="_doPopupItemEnabling">
  370.         <parameter name="popupNode"/>
  371.         <body>
  372.           <![CDATA[
  373.             var children = popupNode.childNodes;
  374.             for (var i = 0; i < children.length; i++) {
  375.               var command = children[i].getAttribute("cmd");
  376.               if (command) {
  377.                 var controller = document.commandDispatcher.getControllerForCommand(command);
  378.                 var enabled = controller.isCommandEnabled(command);
  379.                 if (enabled)
  380.                   children[i].removeAttribute("disabled");
  381.                 else
  382.                   children[i].setAttribute("disabled", "true");
  383.               }
  384.             }
  385.           ]]>
  386.         </body>
  387.       </method>
  388.  
  389.       <method name="_setMenuItemVisibility">
  390.         <parameter name="anonid"/>
  391.         <parameter name="visible"/>
  392.         <body><![CDATA[
  393.           document.getAnonymousElementByAttribute(this, "anonid", anonid).
  394.             hidden = ! visible;
  395.         ]]></body>
  396.       </method>
  397.  
  398.       <method name="doCommand">
  399.         <parameter name="command"/>
  400.         <body>
  401.           <![CDATA[
  402.             var controller = document.commandDispatcher.getControllerForCommand(command);
  403.             controller.doCommand(command);
  404.           ]]>
  405.         </body>
  406.       </method>
  407.     </implementation>
  408.   </binding>
  409.  
  410.   <binding id="input-box-spell" extends="chrome://global/content/bindings/textbox.xml#input-box">
  411.     <content context="_child">
  412.       <children/>
  413.       <xul:menupopup anonid="input-box-contextmenu"
  414.                      onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild)
  415.                                        this.parentNode.firstChild.focus();
  416.                                      this.parentNode._doPopupItemEnablingSpell(this);"
  417.                      onpopuphiding="this.parentNode._doPopupItemDisabling(this);"
  418.                      oncommand="var cmd = event.originalTarget.getAttribute('cmd'); if(cmd) { this.parentNode.doCommand(cmd); event.stopPropagation(); }">
  419.         <xul:menuitem label="&spellNoSuggestions.label;" anonid="spell-no-suggestions" disabled="true"/>
  420.         <xul:menuitem label="&spellAddToDictionary.label;" accesskey="&spellAddToDictionary.accesskey;" anonid="spell-add-to-dictionary"
  421.                       oncommand="this.parentNode.parentNode.spellCheckerUI.addToDictionary();"/>
  422.         <xul:menuseparator anonid="spell-suggestions-separator"/>
  423.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
  424.         <xul:menuseparator/>
  425.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
  426.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/>
  427.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
  428.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
  429.         <xul:menuseparator/>
  430.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
  431.         <xul:menuseparator anonid="spell-check-separator"/>
  432.         <xul:menuitem label="&spellCheckEnable.label;" type="checkbox" accesskey="&spellCheckEnable.accesskey;" anonid="spell-check-enabled"
  433.                       oncommand="this.parentNode.parentNode.spellCheckerUI.toggleEnabled();"/>
  434.         <xul:menu label="&spellDictionaries.label;" accesskey="&spellDictionaries.accesskey;" anonid="spell-dictionaries">
  435.           <xul:menupopup anonid="spell-dictionaries-menu"
  436.                          onpopupshowing="event.stopPropagation();"
  437.                          onpopuphiding="event.stopPropagation();"/>
  438.         </xul:menu>
  439.       </xul:menupopup>
  440.     </content>
  441.  
  442.     <implementation>
  443.       <field name="_spellCheckInitialized">false</field>
  444.       <field name="_enabledCheckbox">
  445.         document.getAnonymousElementByAttribute(this, "anonid", "spell-check-enabled");
  446.       </field>
  447.       <field name="_suggestionsSeparator">
  448.         document.getAnonymousElementByAttribute(this, "anonid", "spell-no-suggestions");
  449.       </field>
  450.       <field name="_dictionariesMenu">
  451.         document.getAnonymousElementByAttribute(this, "anonid", "spell-dictionaries-menu");
  452.       </field>
  453.  
  454.       <property name="spellCheckerUI" readonly="true">
  455.         <getter><![CDATA[
  456.           if (!this._spellCheckInitialized) {
  457.             this._spellCheckInitialized = true;
  458.  
  459.             const CI = Components.interfaces;
  460.             if (!(document instanceof CI.nsIDOMXULDocument))
  461.               return null;
  462.  
  463.             var textbox = document.getBindingParent(this);
  464.             if (!textbox || !(textbox instanceof CI.nsIDOMXULTextBoxElement))
  465.               return null;
  466.  
  467.             try {
  468.               var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
  469.                              getService(CI.mozIJSSubScriptLoader);
  470.               loader.loadSubScript("chrome://global/content/inlineSpellCheckUI.js", this);
  471.               if ("InlineSpellCheckerUI" in this)
  472.                 this.InlineSpellCheckerUI.init(textbox.editor);
  473.             } catch(ex) { }
  474.           }
  475.  
  476.           return this.InlineSpellCheckerUI;
  477.         ]]></getter>
  478.       </property>
  479.  
  480.       <constructor>
  481.         <![CDATA[
  482.           // can't initialize the spell checker in the constructor as not
  483.           // everything is initialized and the editor will fail to create the
  484.           // inline spell checker object
  485.           var _delayedInitSpellCheck = function delayedInitSpellCheck(self) {
  486.             var spellui = self.spellCheckerUI;
  487.             if (spellui)
  488.               spellui.enabled = true;
  489.           }
  490.           setTimeout(_delayedInitSpellCheck, 0, this)
  491.         ]]>
  492.       </constructor>
  493.       <method name="_doPopupItemEnablingSpell">
  494.         <parameter name="popupNode"/>
  495.         <body>
  496.           <![CDATA[
  497.             var spellui = this.spellCheckerUI;
  498.             if (!spellui || !spellui.canSpellCheck) {
  499.               this._setMenuItemVisibility("spell-no-suggestions", false);
  500.               this._setMenuItemVisibility("spell-check-enabled", false);
  501.               this._setMenuItemVisibility("spell-check-separator", false);
  502.               this._setMenuItemVisibility("spell-add-to-dictionary", false);
  503.               this._setMenuItemVisibility("spell-suggestions-separator", false);
  504.               this._setMenuItemVisibility("spell-dictionaries", false);
  505.               return;
  506.             }
  507.  
  508.             spellui.initFromEvent(document.popupRangeParent,
  509.                                   document.popupRangeOffset);
  510.  
  511.             var enabled = spellui.enabled;
  512.             this._enabledCheckbox.setAttribute("checked", enabled);
  513.  
  514.             var overMisspelling = spellui.overMisspelling;
  515.             this._setMenuItemVisibility("spell-add-to-dictionary", overMisspelling);
  516.             this._setMenuItemVisibility("spell-suggestions-separator", overMisspelling);
  517.  
  518.             // suggestion list
  519.             var numsug = spellui.addSuggestionsToMenu(popupNode, this._suggestionsSeparator, 5);
  520.             this._setMenuItemVisibility("spell-no-suggestions", overMisspelling && numsug == 0);
  521.  
  522.             // dictionary list
  523.             var numdicts = spellui.addDictionaryListToMenu(this._dictionariesMenu, null);
  524.             this._setMenuItemVisibility("spell-dictionaries", enabled && numdicts > 1);
  525.  
  526.             this._doPopupItemEnabling(popupNode);
  527.           ]]>
  528.         </body>
  529.       </method>
  530.       <method name="_doPopupItemDisabling">
  531.         <body><![CDATA[
  532.           if (this.spellCheckerUI) {
  533.             this.spellCheckerUI.clearSuggestionsFromMenu();
  534.             this.spellCheckerUI.clearDictionaryListFromMenu();
  535.           }
  536.         ]]></body>
  537.       </method>
  538.     </implementation>
  539.   </binding>
  540.  
  541. </bindings>
  542.