home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!DOCTYPE bindings [
- <!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/keycorrector/urlbarcorrector.dtd" >
- %yasearchDTD;
- ]>
- <bindings id="YaSearchUrlbarBindings"
- xmlns="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:xbl="http://www.mozilla.org/xbl">
- <binding id="urlbar-corrector-icon">
- <content>
- <xul:popupset>
- <xul:popup id="yasearchbar-urlbar-corrector-context">
- <xul:menuitem label="&yasearch.urlbar.corrector.enable.label;"
- class="menuitem-iconic" xbl:inherits="checked=runned"
- oncommand="switchRunned();"/>
- <xul:menuseparator/>
- <xul:menuitem label="&yasearch.urlbar.corrector.disable.label;"
- xbl:inherits="checked=disabled"
- oncommand="switchDisabled();"/>
- </xul:popup>
- </xul:popupset>
-
- <xul:tooltip orient="vertical" id="yasearchbar-urlbar-corrector-tooltip" noautohide="true">
- <xul:label value="&yasearch.urlbar.corrector.tooltiptext; &yasearch.urlbar.corrector.tooltiptext.enable;"/>
- <xul:label value="&yasearch.urlbar.corrector.tooltiptext; &yasearch.urlbar.corrector.tooltiptext.disable;"/>
- </xul:tooltip>
-
- <xul:image xbl:inherits="hidden" context="yasearchbar-urlbar-corrector-context"
- onclick="if (event.button != 2) switchRunned();"
- tooltip="yasearchbar-urlbar-corrector-tooltip"/>
- </content>
-
- <implementation implements="nsIDOMEventListener, nsIObserver">
- <field name="mDisabled">true</field>
- <field name="mRunned">false</field>
-
- <property name="runned">
- <getter><![CDATA[
- return this.mRunned;
- ]]></getter>
- <setter><![CDATA[
- if (val !== this.mRunned) {
- this.setAttribute("runned", val);
- this.mRunned = val;
- }
- return this.mRunned;
- ]]></setter>
- </property>
-
- <property name="disabled">
- <getter><![CDATA[
- return this.mDisabled;
- ]]></getter>
- <setter><![CDATA[
- if (val !== this.mDisabled) {
- this.setAttribute("hidden", val);
- this.mDisabled = val;
-
- val ? this._uninit() : this._init();
- }
- return this.mDisabled;
- ]]></setter>
- </property>
-
- <field name="__lastKey">null</field>
- <field name="nsKeyCorrector">null</field>
-
- <constructor><![CDATA[
- this.nsKeyCorrector = Cc["@yandex.ru/yasearch;1"]
- .getService(Ci.nsIYaSearch)
- .wrappedJSObject
- .KeyCorrector;
- this.checkState();
-
- Cc["@mozilla.org/observer-service;1"]
- .getService(Ci.nsIObserverService)
- .addObserver(this, "Ya-Refresh-Data", false);
- ]]></constructor>
-
- <destructor><![CDATA[
- Cc["@mozilla.org/observer-service;1"]
- .getService(Ci.nsIObserverService)
- .removeObserver(this, "Ya-Refresh-Data");
-
- this.nsKeyCorrector = null;
- this._uninit();
- ]]></destructor>
-
- <method name="handleEvent">
- <parameter name="aEvent"/>
- <body><![CDATA[
- if (aEvent.isTrusted === true && !(aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey)) {
- switch (aEvent.type) {
- case "keydown":
- this.__lastKey = aEvent.keyCode;
- break;
-
- case "keypress":
- if (aEvent.keyCode == aEvent.DOM_VK_PAUSE) {
- this.switchRunned();
- } else if (this.runned) {
- var res = false;
- var shiftKey = aEvent.shiftKey;
- var strFromCode = String.fromCharCode(aEvent.charCode);
-
- if (this._keyConvTable) {
- // Caps Lock
- if ((shiftKey && strFromCode.toUpperCase() != strFromCode) ||
- (!shiftKey && strFromCode.toLowerCase() != strFromCode))
- {
- shiftKey = !shiftKey;
- }
-
- var chCode = shiftKey ?
- this._keyConvTable.withShift[this.__lastKey]||null :
- this._keyConvTable.withoutShift[this.__lastKey]||null;
- res = (chCode && chCode != aEvent.charCode) ? String.fromCharCode(chCode) : false;
- } else {
- res = (shiftKey ? this._charConvTable.withShift[strFromCode.toLowerCase()]||null : null) ||
- this._charConvTable.withoutShift[strFromCode]||null;
- }
-
- if (res && this.fireInsertCommand(res)) {
- aEvent.preventDefault();
- aEvent.stopPropagation();
- }
- }
- break;
- }
- }
- ]]></body>
- </method>
-
- <method name="fireInsertCommand">
- <parameter name="aData"/>
- <body><![CDATA[
- try {
- var command = "cmd_insertText";
- var controller = document.commandDispatcher.getControllerForCommand(command);
- if (controller && controller.isCommandEnabled(command)) {
- controller = controller.QueryInterface(Ci.nsICommandController);
- var params = Cc["@mozilla.org/embedcomp/command-params;1"].createInstance(Ci.nsICommandParams);
- params.setStringValue("state_data", aData);
- controller.doCommandWithParams(command, params);
- return true;
- }
- } catch(e) {}
-
- return false;
- ]]></body>
- </method>
-
- <method name="checkState">
- <body><![CDATA[
- switch (this.nsKeyCorrector.currentState) {
- case this.nsKeyCorrector.STATE_DISABLED:
- this.runned = false;
- this.disabled = true;
- break;
-
- case this.nsKeyCorrector.STATE_RUNNED:
- this.runned = true;
- this.disabled = false;
- break;
-
- case this.nsKeyCorrector.STATE_STOPPED:
- this.runned = false;
- this.disabled = false;
- break;
- }
- ]]></body>
- </method>
-
- <method name="observe">
- <parameter name="aSubject"/>
- <parameter name="aTopic"/>
- <parameter name="aData"/>
- <body><![CDATA[
- if (aTopic == "Ya-Refresh-Data" && aData == "urlbar-corrector")
- this.checkState();
- ]]></body>
- </method>
-
- <method name="_init">
- <body><![CDATA[
- this._keyConvTable = this.nsKeyCorrector.keyConvTable;
- this._charConvTable = this.nsKeyCorrector.charConvTable;
- this._setListeners(true);
- ]]></body>
- </method>
-
- <method name="_uninit">
- <body><![CDATA[
- this._setListeners(false);
- this._keyConvTable = null;
- this._charConvTable = null;
- ]]></body>
- </method>
-
- <method name="_setListeners">
- <parameter name="aAdd"/>
- <body><![CDATA[
- var urlBar = document.getElementById("urlbar");
- if (urlBar) {
- var fn = aAdd ? "addEventListener" : "removeEventListener";
- for each (var ev in [["keypress", true], ["keydown", false]])
- urlBar[fn](ev[0], this, ev[1]);
- }
- ]]></body>
- </method>
-
- <method name="switchRunned">
- <body><![CDATA[
- this.nsKeyCorrector.currentState =
- this.runned ? this.nsKeyCorrector.STATE_STOPPED :
- this.nsKeyCorrector.STATE_RUNNED;
- ]]></body>
- </method>
-
- <method name="switchDisabled">
- <body><![CDATA[
- this.nsKeyCorrector.currentState =
- this.disabled ? this.nsKeyCorrector.STATE_RUNNED :
- this.nsKeyCorrector.STATE_DISABLED;
- ]]></body>
- </method>
- </implementation>
- </binding>
-
- </bindings>