home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / fil38B83070CEDE011FA925B3A892CC3F2E < prev    next >
Extensible Markup Language  |  2010-07-12  |  8KB  |  230 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings [
  3. <!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/keycorrector/urlbarcorrector.dtd" >
  4. %yasearchDTD;
  5. ]>
  6. <bindings id="YaSearchUrlbarBindings"
  7.           xmlns="http://www.mozilla.org/xbl"
  8.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.           xmlns:xbl="http://www.mozilla.org/xbl">
  10.   <binding id="urlbar-corrector-icon">
  11.     <content>
  12.       <xul:popupset>
  13.         <xul:popup id="yasearchbar-urlbar-corrector-context">
  14.           <xul:menuitem label="&yasearch.urlbar.corrector.enable.label;"
  15.                         class="menuitem-iconic" xbl:inherits="checked=runned"
  16.                         oncommand="switchRunned();"/>
  17.           <xul:menuseparator/>
  18.           <xul:menuitem label="&yasearch.urlbar.corrector.disable.label;"
  19.                         xbl:inherits="checked=disabled"
  20.                         oncommand="switchDisabled();"/>
  21.         </xul:popup>
  22.       </xul:popupset>
  23.       
  24.       <xul:tooltip orient="vertical" id="yasearchbar-urlbar-corrector-tooltip" noautohide="true">
  25.         <xul:label value="&yasearch.urlbar.corrector.tooltiptext; &yasearch.urlbar.corrector.tooltiptext.enable;"/>
  26.         <xul:label value="&yasearch.urlbar.corrector.tooltiptext; &yasearch.urlbar.corrector.tooltiptext.disable;"/>
  27.       </xul:tooltip>
  28.             
  29.       <xul:image xbl:inherits="hidden" context="yasearchbar-urlbar-corrector-context"
  30.                  onclick="if (event.button != 2) switchRunned();"
  31.                  tooltip="yasearchbar-urlbar-corrector-tooltip"/>
  32.     </content>
  33.     
  34.     <implementation implements="nsIDOMEventListener, nsIObserver">
  35.       <field name="mDisabled">true</field>
  36.       <field name="mRunned">false</field>
  37.       
  38.       <property name="runned">
  39.         <getter><![CDATA[
  40.           return this.mRunned;
  41.         ]]></getter>
  42.         <setter><![CDATA[
  43.           if (val !== this.mRunned) {
  44.             this.setAttribute("runned", val);
  45.             this.mRunned = val;
  46.           }
  47.           return this.mRunned;
  48.         ]]></setter>
  49.       </property>
  50.       
  51.       <property name="disabled">
  52.         <getter><![CDATA[
  53.           return this.mDisabled;
  54.         ]]></getter>
  55.         <setter><![CDATA[
  56.           if (val !== this.mDisabled) {
  57.             this.setAttribute("hidden", val);
  58.             this.mDisabled = val;
  59.             
  60.             val ? this._uninit() : this._init();
  61.           }
  62.           return this.mDisabled;
  63.         ]]></setter>
  64.       </property>
  65.       
  66.       <field name="__lastKey">null</field>
  67.       <field name="nsKeyCorrector">null</field>
  68.       
  69.       <constructor><![CDATA[
  70.         this.nsKeyCorrector = Cc["@yandex.ru/yasearch;1"]
  71.                                      .getService(Ci.nsIYaSearch)
  72.                                      .wrappedJSObject
  73.                                      .KeyCorrector;
  74.         this.checkState();
  75.         
  76.         Cc["@mozilla.org/observer-service;1"]
  77.             .getService(Ci.nsIObserverService)
  78.             .addObserver(this, "Ya-Refresh-Data", false);
  79.       ]]></constructor>
  80.       
  81.       <destructor><![CDATA[
  82.         Cc["@mozilla.org/observer-service;1"]
  83.             .getService(Ci.nsIObserverService)
  84.             .removeObserver(this, "Ya-Refresh-Data");
  85.  
  86.         this.nsKeyCorrector = null;
  87.         this._uninit();
  88.       ]]></destructor>
  89.       
  90.       <method name="handleEvent">
  91.         <parameter name="aEvent"/>
  92.         <body><![CDATA[
  93.           if (aEvent.isTrusted === true && !(aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey)) {
  94.             switch (aEvent.type) {
  95.               case "keydown":
  96.                 this.__lastKey = aEvent.keyCode;
  97.                 break;
  98.  
  99.               case "keypress":
  100.                 if (aEvent.keyCode == aEvent.DOM_VK_PAUSE) {
  101.                   this.switchRunned();
  102.                 } else if (this.runned) {
  103.                   var res = false;
  104.                   var shiftKey = aEvent.shiftKey;
  105.                   var strFromCode = String.fromCharCode(aEvent.charCode);
  106.                   
  107.                   if (this._keyConvTable) {
  108.                     if ((shiftKey && strFromCode.toUpperCase() != strFromCode) ||
  109.                         (!shiftKey && strFromCode.toLowerCase() != strFromCode))
  110.                     {
  111.                       shiftKey = !shiftKey;
  112.                     }
  113.                     
  114.                     var chCode = shiftKey ?
  115.                                      this._keyConvTable.withShift[this.__lastKey]||null :
  116.                                      this._keyConvTable.withoutShift[this.__lastKey]||null;
  117.                     res = (chCode && chCode != aEvent.charCode) ? String.fromCharCode(chCode) : false;
  118.                   } else {
  119.                     res = (shiftKey ? this._charConvTable.withShift[strFromCode.toLowerCase()]||null : null) ||
  120.                           this._charConvTable.withoutShift[strFromCode]||null;
  121.                   }
  122.  
  123.                   if (res && this.fireInsertCommand(res)) {
  124.                     aEvent.preventDefault();
  125.                     aEvent.stopPropagation();
  126.                   }
  127.                 }
  128.                 break;
  129.             }
  130.           }
  131.         ]]></body>
  132.       </method>
  133.       
  134.       <method name="fireInsertCommand">
  135.         <parameter name="aData"/>
  136.         <body><![CDATA[
  137.           try {
  138.             var command = "cmd_insertText";
  139.             var controller = document.commandDispatcher.getControllerForCommand(command);
  140.             if (controller && controller.isCommandEnabled(command)) {
  141.               controller = controller.QueryInterface(Ci.nsICommandController);
  142.               var params = Cc["@mozilla.org/embedcomp/command-params;1"].createInstance(Ci.nsICommandParams);
  143.               params.setStringValue("state_data", aData);
  144.               controller.doCommandWithParams(command, params);
  145.               return true;
  146.             }
  147.           } catch(e) {}
  148.  
  149.           return false;
  150.         ]]></body>
  151.       </method>
  152.       
  153.       <method name="checkState">
  154.         <body><![CDATA[
  155.           switch (this.nsKeyCorrector.currentState) {
  156.             case this.nsKeyCorrector.STATE_DISABLED:
  157.               this.runned = false;
  158.               this.disabled = true;
  159.               break;
  160.  
  161.             case this.nsKeyCorrector.STATE_RUNNED:
  162.               this.runned = true;
  163.               this.disabled = false;
  164.               break;
  165.  
  166.             case this.nsKeyCorrector.STATE_STOPPED:
  167.               this.runned = false;
  168.               this.disabled = false;
  169.               break;
  170.           }
  171.         ]]></body>
  172.       </method>
  173.       
  174.       <method name="observe">
  175.         <parameter name="aSubject"/>
  176.         <parameter name="aTopic"/>
  177.         <parameter name="aData"/>
  178.         <body><![CDATA[
  179.           if (aTopic == "Ya-Refresh-Data" && aData == "urlbar-corrector")
  180.             this.checkState();
  181.         ]]></body>
  182.       </method>
  183.       
  184.       <method name="_init">
  185.         <body><![CDATA[
  186.           this._keyConvTable = this.nsKeyCorrector.keyConvTable;
  187.           this._charConvTable = this.nsKeyCorrector.charConvTable;
  188.           this._setListeners(true);
  189.         ]]></body>
  190.       </method>
  191.       
  192.       <method name="_uninit">
  193.         <body><![CDATA[
  194.           this._setListeners(false);
  195.           this._keyConvTable = null;
  196.           this._charConvTable = null;
  197.         ]]></body>
  198.       </method>
  199.       
  200.       <method name="_setListeners">
  201.         <parameter name="aAdd"/>
  202.         <body><![CDATA[
  203.           var urlBar = document.getElementById("urlbar");
  204.           if (urlBar) {
  205.             var fn = aAdd ? "addEventListener" : "removeEventListener";
  206.             for each (var ev in [["keypress", true], ["keydown", false]])
  207.               urlBar[fn](ev[0], this, ev[1]);
  208.           }
  209.         ]]></body>
  210.       </method>
  211.       
  212.       <method name="switchRunned">
  213.         <body><![CDATA[
  214.           this.nsKeyCorrector.currentState =
  215.               this.runned ? this.nsKeyCorrector.STATE_STOPPED :
  216.                             this.nsKeyCorrector.STATE_RUNNED;
  217.         ]]></body>
  218.       </method>
  219.       
  220.       <method name="switchDisabled">
  221.         <body><![CDATA[
  222.           this.nsKeyCorrector.currentState =
  223.               this.disabled ? this.nsKeyCorrector.STATE_RUNNED :
  224.                               this.nsKeyCorrector.STATE_DISABLED;
  225.         ]]></body>
  226.       </method>
  227.     </implementation>
  228.   </binding>
  229.   
  230. </bindings>