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
/
filA498F2EC89E811547297CEC985988237
< prev
next >
Wrap
Extensible Markup Language
|
2010-07-12
|
81KB
|
2,246 lines
<?xml version="1.0"?>
<!DOCTYPE bindings [
<!ENTITY % yasearchDTD SYSTEM "chrome://yasearch/locale/yasearch.dtd">
%yasearchDTD;
<!ENTITY % yaSearchboxDTD SYSTEM "chrome://yasearch/locale/searchbox/searchbox.dtd">
%yaSearchboxDTD;
]>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="searchbox-base">
<resources>
<stylesheet src="chrome://yasearch/skin/searchbox/searchbox.css"/>
</resources>
</binding>
<binding id="searchbox-resizer"
extends="chrome://yasearch/content/searchbox/searchbox.xml#searchbox-base">
<implementation implements="nsIDOMEventListener">
<field name="dragging"/>
<field name="lastX"/>
<method name="resizerMouseMove">
<parameter name="event"/>
<body><![CDATA[
if (!this.dragging)
return;
var xDiff = this.lastX - event.screenX;
if (xDiff == 0)
return;
var currWidth = parseInt(this.parentNode.boxObject.width, 10);
if (xDiff > 0) {
currWidth -= xDiff;
} else {
var toolbar = this.parentNode.parentNode.parentNode;
var toolbarWidth = parseInt(toolbar.boxObject.width, 10) - 150;
if (currWidth < toolbarWidth)
currWidth -= xDiff;
}
this.parentNode.setAttribute("width", currWidth);
this.lastX = event.screenX;
]]></body>
</method>
<method name="resizerMouseUp">
<parameter name="event"/>
<body><![CDATA[
this.dragging = false;
this.ownerDocument.documentElement.style.cursor = "";
window.removeEventListener("mouseup", this, true);
window.removeEventListener("mousemove", this, true);
var parent = document.getBindingParent(this);
parent.updateWidthOnResize();
]]></body>
</method>
<constructor><![CDATA[
this.dragging = false;
]]></constructor>
<method name="handleEvent">
<parameter name="aEvent"/>
<body><![CDATA[
switch (aEvent.type) {
case "mouseup":
this.resizerMouseUp(aEvent);
break;
case "mousemove":
this.resizerMouseMove(aEvent);
break;
default:
break;
}
]]></body>
</method>
</implementation>
<handlers>
<handler event="mousedown" button="0"><![CDATA[
this.dragging = true;
this.lastX = event.screenX;
this.ownerDocument.documentElement.style.cursor = "e-resize";
window.addEventListener("mouseup", this, true);
window.addEventListener("mousemove", this, true);
]]></handler>
</handlers>
</binding>
<binding id="searchbox"
extends="chrome://yasearch/content/searchbox/searchbox.xml#searchbox-base">
<content yaSHistoryHeight="230"
persist="yaSHistoryWidth,yaSHistoryHeight,searchengine,src,width,yaSButtonDisabled">
<xul:stringbundle src="chrome://yasearch/locale/searchbox/searchbox.properties"
anonid="yasearchbar-stringbundle"/>
<xul:popupset>
<xul:popup id="yasearchbar-search-button-context">
<xul:menuitem label="&yasearchox.button.context.label;"
oncommand="_textbox.yasearchbarController.doCommand('cmd_showsearchbutton')"/>
</xul:popup>
<xul:panel id="yasearch-popup-autocomplete-panel"
type="autocomplete"
class="autocomplete-history-popup"
anonid="autocomplete-history-popup"
noautofocus="true"
hidden="true"
yaEmptyResultList="true"
xbl:inherits="yaSHistoryWidth,yaSHistoryHeight"/>
</xul:popupset>
<xul:textbox class="yasearchbar-textbox"
anonid="yasearchbar-textbox"
type="autocomplete"
flex="1"
autocompletepopup="yasearch-popup-autocomplete-panel"
autocompletesearch="yasearch-autocomplete"
autocompletesearchparam="yasearch-history"
timeout="250"
maxrows="20"
completeselectedindex="true"
showcommentcolumn="true"
tabscrolling="true"
enablehistory="true"
newlines="replacewithspaces"
xbl:inherits="disabled,searchengine,src">
<xul:button class="yasearchbar-engine-button"
type="menu"
anonid="yasearchbar-engine-button">
<xul:image class="yasearchbar-engine-image" xbl:inherits="src"/>
<xul:image class="yasearchbar-dropmarker-image"/>
<xul:menupopup class="yasearchbar-popup"
anonid="yasearchbar-popup"
position="after_start">
<xul:menuseparator anonid="engines-list-separator-yandex"/>
<xul:menuseparator anonid="engines-list-separator-browser"/>
<xul:menuitem class="open-engine-manager"
anonid="open-engine-manager"
label="&cmd_engineManager.label;"
oncommand="openManager(event);"/>
</xul:menupopup>
</xul:button>
</xul:textbox>
<xul:toolbarbutton class="yasearchbar-search-button"
anonid="yasearchbar-search-button"
label="&yasearchox.button.label;"
disabled="false"
context="yasearchbar-search-button-context"
oncommand="handleSearchCommand(event)"/>
<xul:yasearchboxresizer tooltiptext="&yasearchox.resizer.tooltiptext;"/>
<xul:yasearchboxhighlighter anonid="highlighter" hidden="false"/>
</content>
<implementation implements="nsIObserver">
<method name="updateCursorVisibility">
<body><![CDATA[
if (!this._textbox.editor)
return;
const nsISelectionController = Components.interfaces.nsISelectionController;
this._textbox.editor.selectionController.scrollSelectionIntoView(
nsISelectionController.SELECTION_NORMAL,
nsISelectionController.SELECTION_FOCUS_REGION,
false
);
]]></body>
</method>
<method name="updateWidthOnResize">
<body><![CDATA[
var width = parseInt(this.ownerDocument.defaultView.getComputedStyle(this._textbox, "").width, 10);
this.setAttribute("yaSHistoryWidth", width);
this.updateCursorVisibility();
]]></body>
</method>
<method name="getElementByAnonid">
<parameter name="aAnonidAttr"/>
<body><![CDATA[
return document.getAnonymousElementByAttribute(this, "anonid", aAnonidAttr);
]]></body>
</method>
<property name="_isCanInit" readonly="true"
onget="return this.parentNode.parentNode.localName != 'toolbarpaletteitem';"/>
<constructor><![CDATA[
if (!this._isCanInit)
return;
setTimeout(function(me) { me.init(); }, 0, this);
]]></constructor>
<destructor><![CDATA[
if (!this._isInited)
return;
this._currentEngine = null;
YaProgressListener.removeListener(this.mLocationListener);
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "browser-search-engine-modified");
if (this._textbox.mController.input == this)
this._textbox.mController.input = null;
this._isInited = false;
]]></destructor>
<field name="_stringBundle">this.getElementByAnonid("yasearchbar-stringbundle")</field>
<field name="_textbox">this.getElementByAnonid("yasearchbar-textbox")</field>
<field name="_popup">this.getElementByAnonid("yasearchbar-popup")</field>
<field name="_engineButton">this.getElementByAnonid("yasearchbar-engine-button")</field>
<field name="_searchButton">this.getElementByAnonid("yasearchbar-search-button")</field>
<field name="_acompletepopup">this.getElementByAnonid("autocomplete-history-popup")</field>
<field name="_highlighter">this.getElementByAnonid("highlighter")</field>
<field name="_userTextInput">false</field>
<property name="value" onget="return this._textbox.value;"
onset="return this._textbox.value = val;"/>
<method name="focus">
<body><![CDATA[
this._textbox.focus();
]]></body>
</method>
<method name="select">
<body><![CDATA[
this._textbox.select();
]]></body>
</method>
<property name="nsIYa">
<getter><![CDATA[
if (!this._nsIYa)
this._nsIYa = Components.classes["@yandex.ru/yasearch;1"]
.getService(Components.interfaces.nsIYaSearch)
.wrappedJSObject;
return this._nsIYa;
]]></getter>
</property>
<method name="getYaTabHandlerData">
<parameter name="aBrowser"/>
<body><![CDATA[
var yaTabHandler = (aBrowser || gBrowser.mCurrentBrowser).yaSearchTHandler;
if (!(yaTabHandler && yaTabHandler.tabData))
return {};
if (!yaTabHandler.tabData.searchbox) {
yaTabHandler.tabData.searchbox = {
inputValue: "",
userTextInput: false,
lastLocationSpec: null
}
}
if (!yaTabHandler.tabData.highlighter) {
yaTabHandler.tabData.highlighter = {
enabled: false,
lastHighlightString: "",
lastHighlightWords: null,
serpText: null,
highlightDone: false,
keyListener: null,
keyDown: null
}
}
return yaTabHandler.tabData;
]]></body>
</method>
<field name="mLocationListener">
<![CDATA[({
_self: this,
observe: function() {
switch (arguments[0]) {
case "onWindowLocationChange":
var [, aWebProgress, aRequest, aLocation] = arguments;
let _self = this._self;
var serpText = _self.getYaTabHandlerData().highlighter.serpText;
if (serpText) {
_self.value = serpText;
var event = document.createEvent("Events");
event.initEvent("input", true, true);
_self.dispatchEvent(event);
return;
}
var tabSearchData = _self.getYaTabHandlerData().searchbox;
var inputValue = tabSearchData.inputValue;
var locationSpec = aLocation ? aLocation.spec : null;
if (locationSpec !== tabSearchData.lastLocationSpec) {
tabSearchData.lastLocationSpec = locationSpec;
if (locationSpec && /http(s)?/.test(aLocation.scheme)) {
if (aLocation.scheme == "http") {
var searchWord = YaUtils.getSearchTextFromLocation(aLocation, aWebProgress);
if (searchWord) {
_self.addSearchHistoryEntry(searchWord);
if (!tabSearchData.userTextInput) {
inputValue = searchWord;
tabSearchData.inputValue = searchWord;
}
}
}
}
_self._acompletepopup.updateAppendix();
}
_self.value = inputValue;
_self._userTextInput = tabSearchData.userTextInput;
break;
default:
break;
}
}
})]]>
</field>
<property name="searchableHost" readonly="true">
<getter><![CDATA[
var currentLocation = (gBrowser && gBrowser.currentURI) ? gBrowser.currentURI : null;
return (currentLocation && /http(s)?/.test(currentLocation.scheme) &&
this._currentEngine.searchSite && this.nsIYa.prefs.showSiteSearch) ?
currentLocation.host : false;
]]></getter>
</property>
<property name="searchService" readonly="true">
<getter><![CDATA[
return this.nsIYa.searchService;
]]></getter>
</property>
<method name="init">
<body><![CDATA[
if (this.hasAttribute("yaDefaultWidth") && !this.hasAttribute("width")) {
this.setAttribute("width", this.getAttribute("yaDefaultWidth"));
this.updateWidthOnResize();
}
YaProgressListener.addListener(this.mLocationListener);
this.rebuildPopupServices();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "browser-search-engine-modified", false);
if (BrowserSearch && !BrowserSearch.yaSearchBar && BrowserSearch.addEngine) {
var searchboxId = this.id;
BrowserSearch.__defineGetter__("yaSearchBar",
function() {return document.getElementById(searchboxId);}
);
eval("BrowserSearch.addEngine =" + BrowserSearch.addEngine.toString().replace(
"if (!this.searchBar)",
"if (!this.searchBar && !this.yaSearchBar)"
));
}
this._isInited = true;
]]></body>
</method>
<field name="_currentEngine">null</field>
<property name="currentEngine"
onget="return this.getAttribute('searchengine')">
<setter><![CDATA[
if (!val)
return;
val = val.replace(/yasearchbox\-engine\-/, "");
var engine = this.nsIYa.setCurrentSearchEngine(val);
if (engine) {
this.setAttribute("searchengine", val);
this.setAttribute("src", engine.image);
var toolTipText = this._stringBundle.getFormattedString("searchtip", [engine.label]);
this._textbox.setAttribute("tooltiptext", toolTipText);
this._currentEngine = engine;
}
if (this._textbox.focused)
this._acompletepopup.checkNeedRefreshOnEngineChanged();
]]></setter>
</property>
<property name="currentEngineId" readonly="true">
<getter><![CDATA[
var currentEngine = this.currentEngine;
return (/^__/.test(currentEngine) ? "" : "yasearchbox-engine-") + currentEngine;
]]></getter>
</property>
<method name="checkCurrentEngine">
<body><![CDATA[
var currentEngine = this.currentEngine;
if (currentEngine && !document.getAnonymousElementByAttribute(this, "id", this.currentEngineId))
currentEngine = null;
if (!currentEngine)
this.currentEngine = this.nsIYa.getDefaultSearchEngine();
this.currentEngine = this.currentEngine;
]]></body>
</method>
<method name="selectEngine">
<parameter name="aNewEngineId"/>
<parameter name="aEvent"/>
<parameter name="isNextEngine"/>
<body><![CDATA[
var newEngineId = aNewEngineId ||
this.getNeighbourEngineId(this.currentEngineId,
isNextEngine ? "next" : "previous");
if (newEngineId)
this.currentEngine = newEngineId;
aEvent.preventDefault();
aEvent.stopPropagation();
]]></body>
</method>
<method name="getNeighbourEngineId">
<parameter name="aId"/>
<parameter name="aDirection"/>
<body><![CDATA[
var searchEngineMenuitem = document.getAnonymousElementByAttribute(this, "id", aId);
if (!searchEngineMenuitem)
return false;
var newEngine = searchEngineMenuitem[aDirection + "Sibling"];
while (newEngine && newEngine.localName != "menuitem")
newEngine = newEngine[aDirection + "Sibling"];
if (!newEngine)
return false;
if (document.defaultView.getComputedStyle(newEngine, "").display == "none")
return this.getNeighbourEngineId(newEngine.id, aDirection);
return newEngine.id;
]]></body>
</method>
<method name="rebuildPopupServices">
<body>
<![CDATA[
var popup = this._popup;
var yandexSeparator = this.getElementByAnonid("engines-list-separator-yandex");
var nodeToRemove;
while ((nodeToRemove = popup.firstChild) && nodeToRemove != yandexSeparator)
popup.removeChild(nodeToRemove);
var menu = this.nsIYa.DOMUtils.adoptNode(this.nsIYa.getDOMDocContent("bar-search"), this.ownerDocument);
var menuItems = menu.childNodes;
for (var i = 0, len = menuItems.length; i < len; i++)
this._popup.insertBefore(menuItems[i].cloneNode(true), yandexSeparator);
this._needToBuildPopup = true;
this.rebuildPopup();
]]>
</body>
</method>
<method name="rebuildPopupDynamic">
<body><![CDATA[
if (this._needToBuildPopup)
this.rebuildPopup();
var popup = this._popup,
items = popup.childNodes;
for (var i = items.length; i-- > 0;) {
if (items[i].getAttribute("class").indexOf("addengine") != -1)
popup.removeChild(items[i]);
}
var addengines = getBrowser().mCurrentBrowser.engines;
if (addengines && addengines.length > 0) {
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var browserSeparator = this.getElementByAnonid("engines-list-separator-browser");
var addengineSeparator = document.createElementNS(kXULNS, "menuseparator");
addengineSeparator.setAttribute("class", "addengine-separator");
popup.insertBefore(addengineSeparator, browserSeparator);
addengines.forEach(function(engine) {
var menuitem = document.createElementNS(kXULNS, "menuitem");
menuitem.setAttribute("class", "menuitem-iconic addengine-item");
menuitem.setAttribute("label", this._stringBundle.getFormattedString("cmd_addFoundEngine", [engine.title]));
menuitem.setAttribute("title", engine.title);
menuitem.setAttribute("uri", engine.uri);
if (engine.icon)
menuitem.setAttribute("src", engine.icon);
popup.insertBefore(menuitem, browserSeparator);
}, this)
}
]]></body>
</method>
<method name="_popupFireKeyboardEvent">
<parameter name="aType"/>
<parameter name="aCount"/>
<body><![CDATA[
const kEvent = Components.interfaces.nsIDOMKeyEvent;
while (aCount-- > 0) {
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false, kEvent["DOM_VK_" + aType], 0);
this._popup.dispatchEvent(evt);
}
]]></body>
</method>
<method name="rebuildPopupOnShowing">
<parameter name="aEvent"/>
<body><![CDATA[
this.rebuildPopupDynamic();
setTimeout(function(_self) {
var keyMoveArray = [];
var currItem = document.getAnonymousElementByAttribute(_self, "id", _self.currentEngineId);
if (!currItem)
return;
var currPopup = currItem.parentNode;
while (currItem) {
var i = 0, prevItem = currItem.previousSibling;
while (prevItem) {
if ((prevItem.localName == "menuitem" || prevItem.localName == "menu") &&
prevItem.style.display != "none")
i++;
prevItem = prevItem.previousSibling;
}
keyMoveArray.push(i);
var parent = currItem.parentNode.parentNode;
currItem = parent.nodeName == "menu" ? parent : null;
}
for (var i = keyMoveArray.length; i-- > 0;) {
_self._popupFireKeyboardEvent("RIGHT", 1);
_self._popupFireKeyboardEvent("DOWN", keyMoveArray[i]);
}
_self.__bugCurrentPopup = keyMoveArray.length > 1 ? currPopup : null;
}, 0, this);
]]></body>
</method>
<method name="rebuildPopup">
<body><![CDATA[
var popup = this._popup;
var yandexSeparator = this.getElementByAnonid("engines-list-separator-yandex");
var browserSeparator = this.getElementByAnonid("engines-list-separator-browser");
while (yandexSeparator.nextSibling && yandexSeparator.nextSibling != browserSeparator)
popup.removeChild(yandexSeparator.nextSibling);
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var engines = this.searchService.getVisibleEngines({});
engines.forEach(function(engine) {
if (engine.name != "Яндекс") {
var menuitem = document.createElementNS(kXULNS, "menuitem");
menuitem.setAttribute("label", engine.name);
menuitem.setAttribute("id", "__" + engine.name);
menuitem.setAttribute("class", "menuitem-iconic searchbar-engine-menuitem");
if (engine.iconURI)
menuitem.setAttribute("src", engine.iconURI.spec);
popup.insertBefore(menuitem, browserSeparator);
}
})
this.checkCurrentEngine();
this._needToBuildPopup = false;
]]></body>
</method>
<method name="openManager">
<parameter name="aEvent"/>
<body><![CDATA[
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var window = wm.getMostRecentWindow("Browser:SearchManager");
if (window)
window.focus()
else {
setTimeout(function () {
openDialog("chrome://browser/content/search/engineManager.xul",
"_blank", "chrome,dialog,modal,centerscreen");
}, 0);
}
]]></body>
</method>
<method name="observe">
<parameter name="aEngine"/>
<parameter name="aTopic"/>
<parameter name="aVerb"/>
<body><![CDATA[
switch (aTopic) {
case "browser-search-engine-modified":
switch (aVerb) {
case "engine-removed":
this.offerNewEngine(aEngine);
break;
case "engine-added":
this.hideNewEngine(aEngine);
break;
case "engine-current":
this._popup.hidePopup();
break;
default:
break;
}
this.rebuildPopup();
break;
default:
break;
}
]]></body>
</method>
<method name="addSearchHistoryEntry">
<parameter name="aText"/>
<body><![CDATA[
if (!this.nsIYa.prefs.searchHistoryEnabled)
return;
var textBox = this._textbox,
textValue = arguments.length ? aText : textBox.value;
if (textValue)
textBox._formHistSvc.addEntry(textBox.getAttribute("autocompletesearchparam"), textValue);
]]></body>
</method>
<method name="offerNewEngine">
<parameter name="aEngine"/>
<body><![CDATA[
if (!BrowserSearch || BrowserSearch.searchBar)
return;
var allbrowsers = getBrowser().mPanelContainer.childNodes;
for (var tab = 0; tab < allbrowsers.length; tab++) {
var browser = getBrowser().getBrowserAtIndex(tab);
if (browser.hiddenEngines) {
var removeTitle = aEngine.wrappedJSObject.name;
for (var i = 0; i < browser.hiddenEngines.length; i++) {
if (browser.hiddenEngines[i].title == removeTitle) {
if (!browser.engines)
browser.engines = [];
browser.engines.push(browser.hiddenEngines[i]);
browser.hiddenEngines.splice(i, 1);
break;
}
}
}
}
]]></body>
</method>
<method name="hideNewEngine">
<parameter name="aEngine"/>
<body><![CDATA[
if (!BrowserSearch || BrowserSearch.searchBar)
return;
var allbrowsers = getBrowser().mPanelContainer.childNodes;
for (var tab = 0; tab < allbrowsers.length; tab++) {
var browser = getBrowser().getBrowserAtIndex(tab);
if (browser.engines) {
var removeTitle = aEngine.wrappedJSObject.name;
for (var i = 0; i < browser.engines.length; i++) {
if (browser.engines[i].title == removeTitle) {
if (!browser.hiddenEngines)
browser.hiddenEngines = [];
browser.hiddenEngines.push(browser.engines[i]);
browser.engines.splice(i, 1);
break;
}
}
}
}
]]></body>
</method>
<method name="handleSearchCommand">
<parameter name="aEvent"/>
<body><![CDATA[
var textBox = this._textbox,
textValue = textBox.value;
if (textValue.replace(/\s/g, "")) {
this.addSearchHistoryEntry(textValue);
var searchHost = this.searchableHost;
searchHost = searchHost && this._acompletepopup.isSiteSearchChecked ? searchHost : false;
var searchUrl = this.nsIYa.getSearchEngineUrl(this.currentEngine, textValue, searchHost);
if (searchUrl) {
if (aEvent && aEvent.altKey)
aEvent = "tab";
this._textbox.inputField.blur();
if (/^http:\/\/slovari\.yandex\.ru/.test(searchUrl.url))
this.nsIYa.getSearchSettingsForSlovari(textValue, aEvent, this.doSearch);
else
this.doSearch(searchUrl.url, aEvent, searchUrl.statData, searchUrl.postData);
}
}
]]></body>
</method>
<method name="doSearch">
<parameter name="aURL"/>
<parameter name="aEvent"/>
<parameter name="aStatData"/>
<parameter name="aPostData"/>
<body><![CDATA[
Ya.loadURI(aURL, aEvent, aStatData || null, aPostData || null);
]]></body>
</method>
</implementation>
<handlers>
<handler event="click" button="0" phase="capturing"><![CDATA[
if (event.originalTarget.localName == "div") {
setTimeout(function(aTextbox) {
if (!aTextbox.popup.mPopupOpen)
aTextbox.openPopup();
}, 0, this._textbox)
}
]]></handler>
<handler event="input"><![CDATA[
this._userTextInput = !(this.value == "");
var tabData = this.getYaTabHandlerData();
if (tabData) {
tabData.searchbox.userTextInput = this._userTextInput;
tabData.searchbox.inputValue = this.value;
if (tabData.highlighter.serpText)
tabData.highlighter.serpText = this.value;
this._highlighter.refreshHighlight(gBrowser.mCurrentBrowser);
}
]]></handler>
<handler event="command"><![CDATA[
const target = event.originalTarget;
if (target.getAttribute("class").indexOf("addengine-item") != -1) {
var type = Components.interfaces.nsISearchEngine.DATA_XML;
this.searchService.addEngine(target.getAttribute("uri"), type,
target.getAttribute("src"), false);
} else if (target.getAttribute("class").indexOf("searchbar-engine-menuitem") != -1) {
this.currentEngine = target.id;
} else {
return;
}
this.focus();
this.select();
]]></handler>
<handler event="popupshowing"><![CDATA[
var popup = event.originalTarget;
popup.yaPopupIsOpen = true;
if (popup == this._popup)
this.rebuildPopupOnShowing(event);
]]></handler>
<handler event="popuphiding"><![CDATA[
setTimeout(function(popup, me) {
popup.yaPopupIsOpen = false;
if (popup == me._popup || popup == me._textbox._contextmenu)
me._textbox.focus();
}, 0, event.originalTarget, this);
]]></handler>
<handler event="DOMMouseScroll"
phase="capturing"
action="if (event.ctrlKey) this.selectEngine(null, event, (event.detail > 0));"/>
<handler event="mouseover" phase="capturing">
<![CDATA[
var target = event.originalTarget;
if (this.__bugCurrentPopup && target.localName == "menuitem") {
if (target.parentNode != this.__bugCurrentPopup) {
this.__bugCurrentPopup.hidePopup();
}
delete this.__bugCurrentPopup;
}
]]>
</handler>
</handlers>
</binding>
<binding id="searchbox-search-button"
extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
<implementation>
<field name="_xulSearchbox">document.getBindingParent(this)</field>
<constructor><![CDATA[
if (this._xulSearchbox.hasAttribute("yaSButtonDisabled"))
this.setAttribute("hidden", this._xulSearchbox.getAttribute("yaSButtonDisabled"));
]]></constructor>
<property name="hidden">
<getter><![CDATA[
return this.getAttribute("hidden") == "true";
]]></getter>
<setter><![CDATA[
this.setAttribute("hidden", !!val);
this._xulSearchbox.setAttribute("yaSButtonDisabled", !!val);
]]></setter>
</property>
</implementation>
<handlers>
<handler event="click" button="1"><![CDATA[
this._xulSearchbox.handleSearchCommand(event);
]]></handler>
</handlers>
</binding>
<binding id="searchbox-textbox"
extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
<implementation implements="nsIAutoCompleteInput, nsIObserver, nsIDOMEventListener">
<constructor><![CDATA[
if (!document.getBindingParent(this)._isCanInit)
return;
setTimeout(function(me) {
if (me && "init" in me)
me.init();
}, 0, this);
]]></constructor>
<destructor><![CDATA[
try {
gBrowser.tabContainer.removeEventListener("TabSelect", this, false);
} catch(e) {}
try {
this.controllers.removeController(this.yasearchbarController);
} catch(e) {}
delete this.handleEvent;
]]></destructor>
<field name="_formHistSvc"/>
<field name="_contextmenu"/>
<field name="_lastTabSelectedTime">0</field>
<method name="init">
<body><![CDATA[
this._formHistSvc = Components.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory2);
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (prefBranch.getBoolPref("browser.urlbar.clickSelectsAll"))
this.setAttribute("clickSelectsAll", true);
var stringBundle = document.getBindingParent(this)._stringBundle;
var textbox = document.getAnonymousElementByAttribute(this, "anonid", "textbox-input-box");
var contextMenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu");
this._contextmenu = contextMenu;
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var element = document.createElementNS(XULNS, "menuseparator");
contextMenu.appendChild(element);
element = document.createElementNS(XULNS, "menuitem");
element.setAttribute("cmd", "cmd_clearhistory");
element.setAttribute("label", stringBundle.getString("cmd_clearHistory"));
element.setAttribute("accesskey", stringBundle.getString("cmd_clearHistory_accesskey"));
contextMenu.appendChild(element);
element = document.createElementNS(XULNS, "menuitem");
element.setAttribute("cmd", "cmd_showsearchbutton");
element.setAttribute("type", "checkbox");
element.setAttribute("label", stringBundle.getString("cmd_showSearchButton"));
element.setAttribute("accesskey", stringBundle.getString("cmd_showSearchButton_accesskey"));
contextMenu.appendChild(element);
this.controllers.appendController(this.yasearchbarController);
this.handleEvent = this.handleEvent;
var _gBrowser = document.getElementById("content");
if (_gBrowser && _gBrowser.tabContainer)
_gBrowser.tabContainer.addEventListener("TabSelect", this, false);
]]></body>
</method>
<method name="handleEvent">
<parameter name="aEvent"/>
<body><![CDATA[
switch (aEvent.type) {
case "TabSelect":
this.lastTabSelectedTime = true;
break;
default:
break;
}
]]></body>
</method>
<property name="lastTabSelectedTime">
<getter><![CDATA[
var res = false;
if (this._lastTabSelectedTime) {
res = (Date.now() - this._lastTabSelectedTime) < 10;
this._lastTabSelectedTime = 0;
}
return res;
]]></getter>
<setter><![CDATA[
this._lastTabSelectedTime = val ? Date.now() : 0;
]]></setter>
</property>
<method name="closePopup">
<body><![CDATA[
var popup = this.popup;
if (popup.mPopupOpen) {
popup.view = this.controller.QueryInterface(Components.interfaces.nsITreeView);
popup.invalidate();
var searchbox = document.getBindingParent(this);
var searchSiteEnabled = searchbox._currentEngine &&
searchbox._currentEngine.searchSite &&
searchbox.nsIYa.prefs.showSiteSearch;
if (this.mController.matchCount == 0 && !searchSiteEnabled)
this.realClosePopup();
}
]]></body>
</method>
<method name="realClosePopup">
<body><![CDATA[
var popup = this.popup;
if (popup.mPopupOpen) {
popup.hidePopup();
document.popupNode = null;
}
]]></body>
</method>
<method name="openPopup">
<body><![CDATA[
var popup = this.popup;
if (popup.mPopupOpen) {
popup.view = this.controller.QueryInterface(Components.interfaces.nsITreeView);
popup.invalidate();
} else {
popup.hidden = false;
popup.mInput = this;
popup.view = this.controller.QueryInterface(Components.interfaces.nsITreeView);
popup.invalidate();
popup.showCommentColumn = this.showCommentColumn;
popup.showImageColumn = this.showImageColumn;
document.popupNode = null;
var x = this.boxObject.screenX;
var y = this.boxObject.screenY + this.boxObject.height;
popup.showPopup(document.documentElement, x, y, "popup", null, null);
}
]]></body>
</method>
<method name="onSearchComplete">
<body><![CDATA[
var searchbox = document.getBindingParent(this);
var searchSiteEnabled = searchbox._currentEngine &&
searchbox._currentEngine.searchSite &&
searchbox.nsIYa.prefs.showSiteSearch;
if (this.mController.matchCount == 0) {
if (searchSiteEnabled) {
this.openPopup();
} else {
this.realClosePopup();
}
}
]]></body>
</method>
<method name="openSearch">
<body>
<![CDATA[
this.realClosePopup();
document.getBindingParent(this)._engineButton.open = true;
return false;
]]>
</body>
</method>
<!-- overload |onTextEntered| in autocomplete.xml -->
<method name="onTextEntered">
<parameter name="aEvent"/>
<body><![CDATA[
var evt = aEvent || this.mEnterEvent;
document.getBindingParent(this).handleSearchCommand(evt);
this.mEnterEvent = null;
this.realClosePopup();
]]></body>
</method>
<!-- nsIController -->
<field name="yasearchbarController" readonly="true">
<![CDATA[({
_self: this,
supportsCommand: function(aCommand) {
return aCommand === "cmd_clearhistory" ||
aCommand === "cmd_showsearchbutton";
},
isCommandEnabled: function(aCommand) {
switch (aCommand) {
case "cmd_clearhistory":
let param = this._self.getAttribute("autocompletesearchparam");
return this._self._formHistSvc.nameExists(param);
case "cmd_showsearchbutton":
let textbox = document.getAnonymousElementByAttribute(this._self, "anonid", "textbox-input-box");
let contextMenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu");
let contextMenuItem = contextMenu.getElementsByAttribute("cmd", aCommand)[0];
let searchButton = document.getBindingParent(this._self)._searchButton;
contextMenuItem.setAttribute("checked", !searchButton.hidden);
break;
}
return true;
},
doCommand: function (aCommand) {
switch (aCommand) {
case "cmd_showsearchbutton":
let parent = document.getBindingParent(this._self);
let searchButton = parent._searchButton;
searchButton.hidden = !searchButton.hidden;
parent.updateCursorVisibility();
break;
case "cmd_clearhistory":
let param = this._self.getAttribute("autocompletesearchparam");
this._self._formHistSvc.removeEntriesForName(param);
break;
}
}
})]]>
</field>
<!-- DND Observer -->
<field name="yasearchbarDNDObserver" readonly="true">
<![CDATA[({
mOuter: this,
onDrop: function (aEvent, aXferData, aDragSession) {
var data = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
if (data) {
this.mOuter.value = data;
this.mOuter.onTextEntered(aEvent);
}
},
getSupportedFlavours: function () {
var flavourSet = new FlavourSet();
flavourSet.appendFlavour("text/unicode");
flavourSet.appendFlavour("text/x-moz-url");
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
return flavourSet;
}
})]]>
</field>
</implementation>
<handlers>
<handler event="focus" phase="capturing">
<![CDATA[
if (event.originalTarget.localName == "input" &&
!this.popup.mPopupOpen &&
!document.getBindingParent(this)._popup.yaPopupIsOpen &&
!this._contextmenu.yaPopupIsOpen &&
!this.lastTabSelectedTime)
{
if (this.value) {
setTimeout(function(me) {
me.mConsumeRollupEvent = true;
me.attachController();
me.mController.startSearch(me.value);
}, 0, this)
} else {
this.onSearchComplete();
}
}
]]>
</handler>
<handler event="blur" phase="capturing">
<![CDATA[
if (this.popup.mPopupOpen)
this.realClosePopup();
document.commandDispatcher.focusedElement = null;
]]>
</handler>
<handler event="keypress" keycode="VK_UP" modifiers="accel"
phase="capturing"
action="document.getBindingParent(this).selectEngine(null, event, false);"/>
<handler event="keypress" keycode="VK_DOWN" modifiers="accel"
phase="capturing"
action="document.getBindingParent(this).selectEngine(null, event, true);"/>
<handler event="keypress" keycode="VK_DOWN" modifiers="alt"
phase="capturing"
action="return this.openSearch();"/>
<handler event="keypress" keycode="VK_UP" modifiers="alt"
phase="capturing"
action="return this.openSearch();"/>
<handler event="keypress" keycode="VK_F4"
phase="capturing"
action="return this.openSearch();"/>
<handler event="dragdrop" phase="capturing">
nsDragAndDrop.drop(event, this.yasearchbarDNDObserver);
</handler>
<handler event="keypress" phase="capturing">
<![CDATA[
if (event.keyCode === event.DOM_VK_TAB &&
this.popup.mPopupOpen &&
this.popup.isEmptyResultList) {
this.realClosePopup();
}
]]>
</handler>
</handlers>
</binding>
<binding id="searchbox-popup-autocomplete"
extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-result-popup">
<resources>
<stylesheet src="chrome://global/skin/tree.css"/>
<stylesheet src="chrome://global/skin/autocomplete.css"/>
<stylesheet src="chrome://yasearch/skin/searchbox/popup-autocomplete.css"/>
</resources>
<content ignorekeys="true">
<xul:tree anonid="tree" class="autocomplete-tree plain" flex="1"
hidescrollbar="true" hidecolumnpicker="true" seltype="single"
xbl:inherits="width=yaSHistoryWidth,height=yaSHistoryHeight,collapsed=yaEmptyResultList">
<xul:treecols anonid="treecols">
<xul:treecol id="treecolAutoCompleteValue" class="autocomplete-treecol" flex="2" overflow="true"/>
</xul:treecols>
<xul:treechildren class="autocomplete-treebody"/>
</xul:tree>
<xul:hbox anonid="popup-appendix" onmousedown="return false">
<xul:vbox flex="1">
<xul:hbox>
<xul:checkbox anonid="site-search-checkbox" label="&yasearchox.checkbox.site.label;"/>
</xul:hbox>
</xul:vbox>
<xul:vbox pack="end">
<xul:image anonid="popup-resizer"/>
</xul:vbox>
</xul:hbox>
</content>
<implementation>
<property name="isEmptyResultList"
readonly="true"
onget="return this.getAttribute('yaEmptyResultList') == 'true';"/>
<method name="adjustHeight">
<body><![CDATA[
var bx = this.tree.treeBoxObject;
var view = this.tree.view;
if (!view)
return;
var height = view.rowCount * bx.rowHeight;
if (height == 0) {
this.setAttribute("yaEmptyResultList", "true");
} else {
if (this.hasAttribute("yaEmptyResultList"))
this.removeAttribute("yaEmptyResultList");
}
this.tree.setAttribute("hidescrollbar", height <= bx.height);
]]></body>
</method>
<field name="_searchbox">document.getBindingParent(this)</field>
<field name="_siteSearchCheckbox">document.getAnonymousElementByAttribute(this, "anonid", "site-search-checkbox")</field>
<method name="resizeTo">
<parameter name="aSizeObject"/>
<body><![CDATA[
this._searchbox.setAttribute("yaSHistoryWidth", aSizeObject.width);
if (!this.isEmptyResultList)
this._searchbox.setAttribute("yaSHistoryHeight", aSizeObject.height);
this.adjustHeight();
]]></body>
</method>
<property name="isSiteSearchChecked"
readonly="true"
onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'site-search-checkbox').checked;"/>
<method name="updateAppendix">
<body><![CDATA[
var searchbox = this._searchbox;
var enabled = !!(searchbox._currentEngine &&
searchbox._currentEngine.searchSite &&
searchbox.nsIYa.prefs.showSiteSearch);
var curEnabled = this.hasAttribute("yaSiteSearchEnabled");
if (enabled != curEnabled) {
if (enabled) {
this.setAttribute("yaSiteSearchEnabled", "true");
} else {
this.removeAttribute("yaSiteSearchEnabled");
}
}
]]></body>
</method>
<method name="invalidate">
<parameter name="aScope"/>
<body><![CDATA[
var me = aScope || this;
me.updateAppendix();
me.adjustHeight();
me.tree.treeBoxObject.invalidate();
]]></body>
</method>
<method name="checkNeedRefreshOnEngineChanged">
<body><![CDATA[
let textbox = this._searchbox._textbox,
searchController = textbox.mController;
if (searchController) {
if (searchController.input)
textbox.onSearchComplete();
if (textbox.value)
searchController.startSearch(textbox.value);
}
]]></body>
</method>
</implementation>
<handlers>
<handler event="popupshowing"><![CDATA[
this.mPopupOpen = true;
this.updateAppendix();
]]></handler>
<handler event="popuphiding"><![CDATA[
this.mPopupOpen = false;
this.selectedIndex = -1;
]]></handler>
</handlers>
</binding>
<binding id="searchbox-popup-autocomplete-resizer"
extends="chrome://global/content/bindings/general.xml#image">
<implementation implements="nsIDOMEventListener">
<field name="_selectedIndexBeforeResize">-1</field>
<field name="dragging">false</field>
<constructor><![CDATA[
this.addEventListener("mousedown", this, true);
]]></constructor>
<destructor><![CDATA[
this.removeEventListener("mousedown", this, true);
]]></destructor>
<field name="popupNode">document.getBindingParent(this)</field>
<field name="mLastResizerMoveTime">Date.now()</field>
<property name="popupTreeSize">
<getter><![CDATA[
var treeBox = this.popupNode.tree.boxObject;
return treeBox && treeBox.width ?
{ width: treeBox.width, height: treeBox.height } :
{ width: this.popupNode.boxObject.width, height: 0 }
]]></getter>
</property>
<method name="onResizerMouseDown">
<parameter name="aEvent"/>
<body><![CDATA[
this.dragging = true;
this.lastX = aEvent.screenX;
this.lastY = aEvent.screenY;
window.addEventListener("mouseup", this, true);
window.addEventListener("mousemove", this, true);
this._selectedIndexBeforeResize = this.popupNode.selectedIndex;
return false;
]]></body>
</method>
<method name="onWindowMouseMove">
<parameter name="aEvent"/>
<body><![CDATA[
if (!this.dragging || (Date.now() - this.mLastResizerMoveTime < 60))
return;
var diffX = aEvent.screenX - this.lastX;
var diffY = aEvent.screenY - this.lastY;
if (!(diffX || diffY))
return;
this.lastX = aEvent.screenX;
this.lastY = aEvent.screenY;
this.mLastResizerMoveTime = Date.now();
var curSize = this.popupTreeSize;
curSize.width += diffX;
curSize.height += diffY;
this.popupNode.selectedIndex = -1;
this.popupNode.resizeTo(curSize);
]]></body>
</method>
<method name="onWindowMouseUp">
<parameter name="aEvent"/>
<body><![CDATA[
if (!this.dragging)
return;
window.removeEventListener("mouseup", this, true);
window.removeEventListener("mousemove", this, true);
this.popupNode.selectedIndex = this._selectedIndexBeforeResize;
this._selectedIndexBeforeResize = -1;
this.dragging = false;
]]></body>
</method>
<method name="handleEvent">
<parameter name="aEvent"/>
<body><![CDATA[
switch (aEvent.type) {
case "mousedown":
this.onResizerMouseDown(aEvent);
break;
case "mouseup":
this.onWindowMouseUp(aEvent);
aEvent.stopPropagation();
break;
case "mousemove":
this.onWindowMouseMove(aEvent);
aEvent.stopPropagation();
break;
}
]]></body>
</method>
</implementation>
</binding>
<binding id="searchbox-highlighter"
extends="chrome://yasearch/content/searchbox/searchbox.xml#searchbox-base">
<content>
<xul:toolbarbutton anonid="menu-button" type="menu-button"
tooltiptext="&yasearchbox.highlighter.tooltiptext;">
<xul:menupopup>
<xul:menuitem anonid="highlight" type="checkbox"
label="&yasearchbox.highlighter.highlight.label;"/>
<xul:menuseparator/>
<xul:menuitem anonid="teleport" type="checkbox"
label="&yasearchbox.highlighter.teleport.label;"/>
<xul:menuitem anonid="serp" type="checkbox"
label="&yasearchbox.highlighter.serp.label;"/>
</xul:menupopup>
</xul:toolbarbutton>
</content>
<implementation implements="nsIObserver">
<field name="mPrefsNamePrefix">"yasearch.general.ui.highlighter."</field>
<field name="_prefBranch">Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch2)</field>
<field name="_button">document.getAnonymousElementByAttribute(this, "anonid", "menu-button")</field>
<field name="_searchbox">document.getBindingParent(this)</field>
<field name="mHighlightNodeClassName">"__yasearchhighlighterclass" + Date.now()</field>
<field name="mHighBackColor">"yellow"</field>
<field name="mHighTextColor">"black"</field>
<field name="mMaxHighlightCount">100</field>
<field name="_isInited">false</field>
<property name="enabled">
<getter><![CDATA[
return this.getAttribute("hidden") != "true";
]]></getter>
<setter><![CDATA[
this.setAttribute("hidden", !val);
val ? this.init() : this.destroy();
return this.enabled;
]]></setter>
</property>
<method name="getElement">
<parameter name="aAnonymousID"/>
<body><![CDATA[
return document.getAnonymousElementByAttribute(this, "anonid", aAnonymousID);
]]></body>
</method>
<field name="_refreshHighlightTimeout">null</field>
<field name="_smoothScrollInterval">null</field>
<method name="setTimeout">
<body><![CDATA[
var args = Array.slice(arguments);
var timeoutName = "_" + args.shift() + "Timeout";
if (!(timeoutName in this))
return;
if (this[timeoutName])
window.clearTimeout(this[timeoutName]);
if (args.length)
this[timeoutName] = window.setTimeout.apply(null, args);
]]></body>
</method>
<constructor><![CDATA[
if (!this._searchbox._isCanInit)
return;
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.addObserver(this.mPrefsNamePrefix + "enabled", this, false);
this.enabled = this._prefBranch.getBoolPref(this.mPrefsNamePrefix + "enabled");
]]></constructor>
<destructor><![CDATA[
this.enabled = false;
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.removeObserver(this.mPrefsNamePrefix + "enabled", this, false);
this._isInited = false;
]]></destructor>
<method name="init">
<body><![CDATA[
if (this._isInited || !this._searchbox._isCanInit)
return;
this._highlightEnabled = false;
this.mTeleportEnabled = this._prefBranch.getBoolPref(this.mPrefsNamePrefix + "teleport");
this.mSerpEnabled = this._prefBranch.getBoolPref(this.mPrefsNamePrefix + "serp");
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.addObserver(this.mPrefsNamePrefix, this, false);
YaProgressListener.addListener(this.mLocationListener);
this._isInited = true;
]]></body>
</method>
<method name="destroy">
<body><![CDATA[
if (!this._isInited)
return;
YaProgressListener.removeListener(this.mLocationListener);
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal)
.removeObserver(this.mPrefsNamePrefix, this);
var l = gBrowser.mPanelContainer.childNodes.length;
for (var i = 0; i < l; i++) {
try {
var browser = gBrowser.getBrowserAtIndex(i);
var tabData = this.getYaHLTabHandlerData(browser);
if (!tabData)
continue;
this._refreshHighlight(browser, tabData, null);
} catch(e) {}
}
this._isInited = false;
]]></body>
</method>
<method name="getYaHLTabHandlerData">
<parameter name="aBrowser"/>
<body><![CDATA[
return this._searchbox.getYaTabHandlerData(aBrowser).highlighter || null;
]]></body>
</method>
<property name="mTeleportEnabled">
<getter><![CDATA[
return this._teleportEnabled;
]]></getter>
<setter><![CDATA[
var enabled = !!val;
if (enabled !== this._teleportEnabled) {
this.setAttribute("teleportEnabled", enabled);
this._teleportEnabled = enabled;
}
return this.mTeleportEnabled;
]]></setter>
</property>
<property name="mSerpEnabled">
<getter><![CDATA[
return this._serpEnabled;
]]></getter>
<setter><![CDATA[
var enabled = !!val;
if (enabled !== this._serpEnabled) {
this._serpEnabled = enabled;
}
return this.mSerpEnabled;
]]></setter>
</property>
<property name="mHighlightEnabled">
<getter><![CDATA[
return this._highlightEnabled;
]]></getter>
<setter><![CDATA[
var enabled = !!val;
var browser = gBrowser.mCurrentBrowser;
var tabData = this.getYaHLTabHandlerData(browser);
if (tabData) {
tabData.enabled = enabled;
this.checkHighlightState(browser);
}
return this.mHighlightEnabled;
]]></setter>
</property>
<method name="refreshHighlight">
<parameter name="aBrowser"/>
<body><![CDATA[
if (!this._isInited)
return;
var tabData = this.getYaHLTabHandlerData(aBrowser);
if (!tabData)
return;
var words = "",
serpAutoHighlight = false;
if (tabData.highlightDone === false && tabData.serpText && this.mSerpEnabled) {
words = tabData.serpText;
serpAutoHighlight = true;
} else {
words = tabData.enabled ? this._searchbox.value : "";
}
words = words.replace(/^\s+/, "")
.replace(/\s+$/, "")
.replace(/\s+/g, " ");
var wordsLength = words.length;
var refreshTimeout = !wordsLength ? 0 : (wordsLength > 2 ? 0.5 : (wordsLength > 1 ? 1 : 2))
this.setTimeout(
"refreshHighlight",
function(me, aBrowser, tabData, words, serpAutoHighlight) {
me._refreshHighlight(aBrowser, tabData, words, serpAutoHighlight);
},
refreshTimeout * 1000, this, aBrowser, tabData, words, serpAutoHighlight
)
]]></body>
</method>
<method name="_refreshHighlight">
<parameter name="aBrowser"/>
<parameter name="aTabData"/>
<parameter name="words"/>
<parameter name="serpAutoHighlight"/>
<body><![CDATA[
aTabData.highlightDone = true;
if (words != aTabData.lastHighlightString) {
if (aTabData.lastHighlightString)
this.toggleHighlight(null, aBrowser, aTabData);
if (words)
this.toggleHighlight(words, aBrowser, aTabData, serpAutoHighlight);
aTabData.lastHighlightString = words;
}
]]></body>
</method>
<method name="toggleHighlight">
<parameter name="aWords"/>
<parameter name="aBrowser"/>
<parameter name="aTabData"/>
<parameter name="aSerpAutoHighlight"/>
<body><![CDATA[
var contentWindow = aBrowser.contentWindow;
if (!contentWindow)
return;
if (this._smoothScrollInterval)
window.clearInterval(this._smoothScrollInterval);
aTabData._highlightedCount = 0;
if (aWords) {
aTabData._windowSizeProps = {
scrollX: contentWindow.scrollX,
scrollY: contentWindow.scrollY,
elemScrollX: contentWindow.scrollX,
elemScrollY: contentWindow.scrollY,
bottomScrollFound: false
}
if (this._highlightDoc(aTabData, this.mHighBackColor, this.mHighTextColor, aWords, contentWindow) &&
this.mTeleportEnabled)
{
window.setTimeout(function(me, aKeyDown, aWindowSizeProps) {
if (!aSerpAutoHighlight || !(aKeyDown || contentWindow.scrollX || contentWindow.scrollY)) {
me.smoothScrollToElement(contentWindow, {
x: aWindowSizeProps.elemScrollX,
y: aWindowSizeProps.elemScrollY
})
}
}, 10, this, aTabData.keyDown, aTabData._windowSizeProps);
}
} else {
this._highlightDoc(aTabData, null, null, null, contentWindow);
aTabData.lastHighlightString = "";
}
]]></body>
</method>
<method name="_setSearchRange">
<parameter name="aDocument"/>
<body><![CDATA[
let body = aDocument.body;
let count = body.childNodes.length;
this._searchRange = aDocument.createRange();
this._startPt = aDocument.createRange();
this._endPt = aDocument.createRange();
this._searchRange.setStart(body, 0);
this._searchRange.setEnd(body, count);
this._startPt.setStart(body, 0);
this._startPt.setEnd(body, 0);
this._endPt.setStart(body, count);
this._endPt.setEnd(body, count);
]]></body>
</method>
<method name="_highlightDoc">
<parameter name="aTabData"/>
<parameter name="aHighBackColor"/>
<parameter name="aHighTextColor"/>
<parameter name="aWord"/>
<parameter name="aWindow"/>
<body><![CDATA[
var win = aWindow;
var textFound = false;
for (var i = 0; win.frames && i < win.frames.length; i++) {
if (this._highlightDoc(aTabData, aHighBackColor, aHighTextColor, aWord, win.frames[i]))
textFound = true;
}
var doc = win.document;
if (!doc || !(doc instanceof HTMLDocument))
return textFound;
var body = doc.body;
if (!body)
return textFound;
if (!aHighBackColor) {
if (!aTabData.lastHighlightString)
return textFound;
if (aTabData.lastHighlightWords) {
let hlNodes = YaUtils.evaluateXPath(doc, "//xhtml:yabarhighlightertag[@class='" + this.mHighlightNodeClassName + "']");
textFound = !!hlNodes.length;
for (let i = hlNodes.length; --i >= 0;) {
let elem = hlNodes[i];
let child = null;
let docfrag = doc.createDocumentFragment();
let next = elem.nextSibling;
let parent = elem.parentNode;
while ((child = elem.firstChild))
docfrag.appendChild(child);
this._startPt = doc.createRange();
this._startPt.setStartAfter(elem);
parent.removeChild(elem);
parent.insertBefore(docfrag, next);
parent.normalize();
this._startPt.collapse(true);
}
}
return textFound;
}
let baseNode = doc.createElementNS("http://www.w3.org/1999/xhtml", "yabarhighlightertag");
baseNode.style.backgroundColor = aHighBackColor;
baseNode.style.color = aHighTextColor;
baseNode.style.display = "inline";
baseNode.style.fontSize = "inherit";
baseNode.style.padding = "0";
baseNode.className = this.mHighlightNodeClassName;
let wordRe = YaUtils.RegExp.escape(aWord).replace(/[её]/ig, "[её]");
wordRe = new RegExp(wordRe, "ig");
let matchedWords = body.textContent.match(wordRe);
if (matchedWords) {
function unique(aArray) {
let ret = [];
aArray.forEach(function(elem) {
elem = elem.toLowerCase();
if (ret.indexOf(elem) === -1)
ret.push(elem);
});
return ret;
};
matchedWords.unshift(aWord);
matchedWords = unique(matchedWords);
matchedWords.forEach(function(wrd) {
this._setSearchRange(doc);
textFound = this._highlightText(aTabData, wrd, baseNode) || textFound;
}, this);
aTabData.lastHighlightWords = matchedWords;
} else {
aTabData.lastHighlightWords = null;
}
return textFound;
]]></body>
</method>
<method name="_highlightText">
<parameter name="aTabData"/>
<parameter name="aWord"/>
<parameter name="aBaseNode"/>
<body><![CDATA[
let rangeOwnerDocument = this._searchRange.startContainer.ownerDocument;
let body = rangeOwnerDocument.body;
let bodyScroll = {
top: parseInt(Math.max(rangeOwnerDocument.documentElement.scrollTop, body.scrollTop),10),
left: parseInt(Math.max(rangeOwnerDocument.documentElement.scrollLeft, body.scrollLeft),10)
};
let retRange = null;
let finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"]
.createInstance()
.QueryInterface(Components.interfaces.nsIFind);
finder.caseSensitive = false;
let textFound = false;
let winSizeProps = aTabData._windowSizeProps;
let NBCR = null;
while (aTabData._highlightedCount++ < this.mMaxHighlightCount &&
(retRange = finder.Find(aWord, this._searchRange, this._startPt, this._endPt))) {
let nodeSurround = aBaseNode.cloneNode(true);
let node = this._highlight(retRange, nodeSurround);
if (!node) {
if (--aTabData._highlightedCount < 0)
aTabData._highlightedCount = 0;
this._startPt = retRange.endContainer.ownerDocument.createRange();
this._startPt.setStart(retRange.endContainer, retRange.endOffset);
this._startPt.setEnd(retRange.endContainer, retRange.endOffset);
} else {
let childNodesLength = node.childNodes.length;
this._startPt = node.ownerDocument.createRange();
this._startPt.setStart(node, childNodesLength);
this._startPt.setEnd(node, childNodesLength);
let nodeBCR = node.getBoundingClientRect();
let nodeScrollY = parseInt(nodeBCR.top,10) + bodyScroll.top;
if (aTabData._highlightedCount == 1) {
winSizeProps.elemScrollY = nodeScrollY;
NBCR = nodeBCR;
}
if (!winSizeProps.bottomScrollFound) {
if (nodeScrollY >= winSizeProps.scrollY || nodeScrollY < winSizeProps.elemScrollY) {
if (nodeScrollY >= winSizeProps.scrollY) {
winSizeProps.bottomScrollFound = true;
}
winSizeProps.elemScrollY = nodeScrollY;
NBCR = nodeBCR;
}
}
if (winSizeProps.bottomScrollFound &&
nodeScrollY >= winSizeProps.scrollY &&
nodeScrollY <= winSizeProps.elemScrollY)
{
winSizeProps.elemScrollY = nodeScrollY;
NBCR = nodeBCR;
}
textFound = true;
}
}
if (NBCR) {
let nodeBO = {
left: parseInt(NBCR.left,10),
right: parseInt(NBCR.right,10)
};
if (nodeBO.left <= 0) {
winSizeProps.elemScrollX = nodeBO.left + bodyScroll.left;
} else {
let clientWidth = parseInt(Math.max(rangeOwnerDocument.documentElement.clientWidth, body.clientWidth),10);
if (nodeBO.right > clientWidth) {
winSizeProps.elemScrollX = Math.min(nodeBO.left, nodeBO.right - clientWidth) + bodyScroll.left;
}
}
}
aTabData.lastHighlightString = aWord;
return textFound;
]]></body>
</method>
<method name="_getEditableNode">
<parameter name="aNode"/>
<body><![CDATA[
while (aNode) {
if (aNode instanceof Components.interfaces.nsIDOMNSEditableElement)
return aNode.editor ? aNode : null;
aNode = aNode.parentNode;
}
return null;
]]></body>
</method>
<method name="_highlight">
<parameter name="aRange"/>
<parameter name="aNode"/>
<body><![CDATA[
let startContainer = aRange.startContainer;
if (this._getEditableNode(startContainer))
return false;
let startOffset = aRange.startOffset;
let docfrag = aRange.extractContents();
let before = startContainer.splitText(startOffset);
let parent = before.parentNode;
aNode.appendChild(docfrag);
parent.insertBefore(aNode, before);
return aNode;
]]></body>
</method>
<method name="smoothScrollToElement">
<parameter name="aWindow"/>
<parameter name="aScrollData"/>
<body><![CDATA[
if (this._smoothScrollInterval)
window.clearInterval(this._smoothScrollInterval);
function sign(x) {
if (x > 0) return 1;
if (x < 0) return -1;
return 0;
}
let ox, oy,
dx, dy,
cx, cy;
let me = this;
function fx() {
ox = aWindow.scrollX;
oy = aWindow.scrollY;
dx = (aScrollData.x - ox) / 10;
dx = sign(dx) * Math.ceil(Math.abs(dx));
dy = (aScrollData.y - oy) / 10;
dy = sign(dy) * Math.ceil(Math.abs(dy));
aWindow.scrollBy(dx, dy);
cx = aWindow.scrollX;
cy = aWindow.scrollY;
if ((ox-cx) == 0 && (oy-cy) == 0)
window.clearInterval(me._smoothScrollInterval);
}
me._smoothScrollInterval = setInterval(fx, 20);
]]></body>
</method>
<method name="checkHighlightState">
<parameter name="aBrowser"/>
<body><![CDATA[
if (aBrowser !== gBrowser.mCurrentBrowser)
return;
var tabData = this.getYaHLTabHandlerData(aBrowser);
if (tabData) {
var enabled = !!tabData.enabled;
if (this._highlightEnabled !== enabled) {
this._highlightEnabled = enabled;
this._button.checked = enabled;
}
if (enabled && tabData.highlightDone === false)
this.refreshHighlight(aBrowser);
}
]]></body>
</method>
<method name="checkIsOnSerpLocation">
<parameter name="aBrowser"/>
<body><![CDATA[
var tabData = this.getYaHLTabHandlerData(aBrowser);
if (tabData && tabData.serpText === null &&
(tabData.serpText = YaUtils.getSearchTextFromWebProgress(aBrowser.webProgress)) &&
this.mSerpEnabled)
{
if (!tabData.keyListener) {
tabData.keyListener = function(e) {
if (e.isTrusted)
tabData.keyDown = true;
}
aBrowser.addEventListener("keydown", tabData.keyListener, false, true)
}
tabData.enabled = true;
this.checkHighlightState(aBrowser);
}
]]></body>
</method>
<field name="mLocationListener">
<![CDATA[({
_self: this,
observe: function() {
var [topic, browser] = arguments;
if (topic == "onWindowLocationChange")
browser = browser.chromeEventHandler.getTabBrowser().mCurrentTab.linkedBrowser;
switch (topic) {
case "onWindowLocationChange":
this._self.checkIsOnSerpLocation(browser);
this._self.checkHighlightState(browser);
break;
case "DOMContentLoaded":
var tabData = this._self.getYaHLTabHandlerData(browser);
tabData.highlightDone = false;
tabData.lastHighlightString = "";
this._self.checkHighlightState(browser);
break;
case "pagehide":
var tabData = this._self.getYaHLTabHandlerData(browser);
if (tabData) {
if (tabData.lastHighlightString != "") {
tabData.lastHighlightString = "";
this._self.toggleHighlight(null, browser, tabData);
}
if (tabData.keyListener) {
browser.removeEventListener("keydown", tabData.keyListener, false, true);
tabData.keyListener = null;
}
tabData.enabled = false;
tabData.highlightDone = null;
tabData.serpText = null;
tabData.keyDown = null;
}
break;
default:
break;
}
}
})]]>
</field>
<method name="observe">
<parameter name="aSubject"/>
<parameter name="aTopic"/>
<parameter name="aData"/>
<body><![CDATA[
switch (aTopic) {
case "nsPref:changed":
var prefName = aData.split(this.mPrefsNamePrefix)[1];
switch (prefName) {
case "teleport":
case "serp":
prefName = "m" + prefName.replace(/^./, function(s){return s.toUpperCase()}) + "Enabled";
this[prefName] = this._prefBranch.getBoolPref(aData);
break;
case "enabled":
this.enabled = this._prefBranch.getBoolPref(aData);
break;
default:
break;
}
break;
default:
break;
}
]]></body>
</method>
</implementation>
<handlers>
<handler event="command"><![CDATA[
var target = event.originalTarget;
if (target.hasAttribute("anonid")) {
var anonid = target.getAttribute("anonid");
switch (anonid) {
case "teleport":
case "serp":
this._prefBranch.setBoolPref(this.mPrefsNamePrefix + anonid,
(target.getAttribute("checked") == "true"));
event.stopPropagation();
break;
case "highlight":
default:
var browser = gBrowser.mCurrentBrowser;
var tabData = this.getYaHLTabHandlerData(browser);
if (tabData)
tabData.highlightDone = true;
this.mHighlightEnabled = !this.mHighlightEnabled;
this.refreshHighlight(browser);
break;
}
}
]]></handler>
<handler event="popupshowing"><![CDATA[
for each (var prop in ["highlight", "teleport", "serp"])
this.getElement(prop).setAttribute("checked", !!this["_" + prop + "Enabled"]);
]]></handler>
</handlers>
</binding>
</bindings>