2007-03-22 10:30:00 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<!-- ***** BEGIN LICENSE BLOCK *****
|
|
|
|
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
-
|
|
|
|
- The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
- 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
- the License. You may obtain a copy of the License at
|
|
|
|
- http://www.mozilla.org/MPL/
|
|
|
|
-
|
|
|
|
- Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
- for the specific language governing rights and limitations under the
|
|
|
|
- License.
|
|
|
|
-
|
|
|
|
- The Original Code is mozilla.org viewsource frontend.
|
|
|
|
-
|
|
|
|
- The Initial Developer of the Original Code is
|
|
|
|
- Netscape Communications Corporation.
|
|
|
|
- Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
- the Initial Developer. All Rights Reserved.
|
|
|
|
-
|
|
|
|
- Contributor(s):
|
|
|
|
- Blake Ross <blake@cs.stanford.edu> (Original Author)
|
|
|
|
- Masayuki Nakano <masayuki@d-toybox.com>
|
|
|
|
- Ben Basson <contact@cusser.net>
|
|
|
|
- Jason Barnabe <jason_barnabe@fastmail.fm>
|
|
|
|
- Asaf Romano <mano@mozilla.com>
|
2007-08-25 21:17:32 -07:00
|
|
|
- Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2008-07-30 13:48:56 -07:00
|
|
|
- Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
|
2007-03-22 10:30:00 -07:00
|
|
|
-
|
|
|
|
- Alternatively, the contents of this file may be used under the terms of
|
|
|
|
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
- in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
- of those above. If you wish to allow use of your version of this file only
|
|
|
|
- under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
- use your version of this file under the terms of the MPL, indicate your
|
|
|
|
- decision by deleting the provisions above and replace them with the notice
|
|
|
|
- and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
- the provisions above, a recipient may use your version of this file under
|
|
|
|
- the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
-
|
|
|
|
- ***** END LICENSE BLOCK ***** -->
|
|
|
|
|
|
|
|
<!DOCTYPE bindings [
|
|
|
|
<!ENTITY % findBarDTD SYSTEM "chrome://global/locale/findbar.dtd" >
|
|
|
|
%findBarDTD;
|
|
|
|
]>
|
|
|
|
|
|
|
|
<bindings id="findbarBindings"
|
|
|
|
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">
|
|
|
|
|
|
|
|
<!-- Private binding -->
|
|
|
|
<binding id="findbar-textbox"
|
|
|
|
extends="chrome://global/content/bindings/textbox.xml#textbox">
|
|
|
|
<implementation>
|
|
|
|
|
|
|
|
<field name="_findbar">null</field>
|
|
|
|
<property name="findbar" readonly="true">
|
|
|
|
<getter>
|
|
|
|
return this._findbar ?
|
|
|
|
this._findbar : this._findbar = document.getBindingParent(this);
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<method name="_handleEnter">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this.findbar._findMode == this.findbar.FIND_NORMAL) {
|
|
|
|
var findString = this.findbar._findField;
|
|
|
|
if (!findString.value)
|
|
|
|
return;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (aEvent.metaKey) {
|
|
|
|
#else
|
|
|
|
if (aEvent.ctrlKey) {
|
|
|
|
#endif
|
|
|
|
this.findbar.getElement("highlight").click();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.findbar.onFindAgainCommand(aEvent.shiftKey);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We need to keep a reference to _foundLink because
|
|
|
|
// _finishFAYT resets it to null.
|
|
|
|
var tmpLink = this._findbar._foundLink;
|
|
|
|
if (tmpLink && this.findbar._finishFAYT(aEvent))
|
|
|
|
this.findbar._dispatchKeypressEvent(tmpLink, aEvent);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_handleTab">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var shouldHandle = !aEvent.altKey && !aEvent.ctrlKey &&
|
|
|
|
!aEvent.metaKey;
|
|
|
|
if (shouldHandle &&
|
|
|
|
this.findbar._findMode != this.findbar.FIND_NORMAL &&
|
|
|
|
this.findbar._finishFAYT(aEvent)) {
|
|
|
|
if (aEvent.shiftKey)
|
|
|
|
document.commandDispatcher.rewindFocus();
|
|
|
|
else
|
|
|
|
document.commandDispatcher.advanceFocus();
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="input"><![CDATA[
|
2012-01-12 22:19:22 -08:00
|
|
|
// We should do nothing during composition. E.g., composing string
|
|
|
|
// before converting may matches a forward word of expected word.
|
|
|
|
// After that, even if user converts the composition string to the
|
|
|
|
// expected word, it may find second or later searching word in the
|
|
|
|
// document.
|
|
|
|
if (this.findbar._isIMEComposing) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
this.findbar._find(this.value);
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="keypress"><![CDATA[
|
|
|
|
var win = this.findbar._currentWindow ||
|
|
|
|
this.findbar.browser.contentWindow;
|
2012-03-26 10:42:28 -07:00
|
|
|
var controller = this.findbar._getSelectionController(win);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-22 01:59:56 -07:00
|
|
|
var shouldHandle = !event.altKey && !event.ctrlKey &&
|
|
|
|
!event.metaKey && !event.shiftKey;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (event.keyCode) {
|
|
|
|
case KeyEvent.DOM_VK_RETURN:
|
|
|
|
this._handleEnter(event);
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_TAB:
|
|
|
|
this._handleTab(event);
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_PAGE_UP:
|
2009-03-22 01:59:56 -07:00
|
|
|
if (shouldHandle) {
|
2012-03-26 10:42:28 -07:00
|
|
|
controller.scrollPage(false);
|
2009-03-22 01:59:56 -07:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_PAGE_DOWN:
|
2009-03-22 01:59:56 -07:00
|
|
|
if (shouldHandle) {
|
2012-03-26 10:42:28 -07:00
|
|
|
controller.scrollPage(true);
|
2009-03-22 01:59:56 -07:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_UP:
|
2012-03-26 10:42:28 -07:00
|
|
|
controller.scrollLine(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_DOWN:
|
2012-03-26 10:42:28 -07:00
|
|
|
controller.scrollLine(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="blur"><![CDATA[
|
|
|
|
var findbar = this.findbar;
|
|
|
|
var fastFind = findbar.browser.fastFind;
|
|
|
|
if (findbar._foundEditable)
|
|
|
|
fastFind.collapseSelection();
|
|
|
|
else {
|
|
|
|
fastFind.setSelectionModeAndRepaint
|
|
|
|
(findbar.nsISelectionController.SELECTION_ON);
|
|
|
|
}
|
|
|
|
findbar._setFoundLink(null);
|
|
|
|
findbar._foundEditable = null;
|
|
|
|
findbar._currentWindow = null;
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="compositionstart"><![CDATA[
|
|
|
|
// Don't close the find toolbar while IME is composing.
|
|
|
|
var findbar = this.findbar;
|
|
|
|
findbar._isIMEComposing = true;
|
|
|
|
if (findbar._quickFindTimeout) {
|
|
|
|
clearTimeout(findbar._quickFindTimeout);
|
|
|
|
findbar._quickFindTimeout = null;
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="compositionend"><![CDATA[
|
|
|
|
var findbar = this.findbar;
|
|
|
|
findbar._isIMEComposing = false;
|
|
|
|
if (findbar._findMode != findbar.FIND_NORMAL &&
|
|
|
|
!findbar.hidden)
|
|
|
|
findbar._setFindCloseTimeout();
|
|
|
|
]]></handler>
|
|
|
|
|
2010-05-13 06:42:57 -07:00
|
|
|
<handler event="dragover"><![CDATA[
|
|
|
|
if (event.dataTransfer.types.contains("text/plain"))
|
|
|
|
event.preventDefault();
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="drop"><![CDATA[
|
2009-06-20 17:04:07 -07:00
|
|
|
var value = event.dataTransfer.getData("text/plain");
|
|
|
|
this.value = value;
|
|
|
|
this.findbar._find(value);
|
|
|
|
event.stopPropagation();
|
2010-05-13 06:42:57 -07:00
|
|
|
event.preventDefault();
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></handler>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="findbar"
|
|
|
|
extends="chrome://global/content/bindings/toolbar.xml#toolbar">
|
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://global/skin/findBar.css"/>
|
|
|
|
</resources>
|
|
|
|
|
2008-04-09 15:03:09 -07:00
|
|
|
<content hidden="true">
|
2008-04-09 16:55:10 -07:00
|
|
|
<xul:hbox anonid="findbar-container" class="findbar-container" flex="1" align="center">
|
2007-03-22 10:30:00 -07:00
|
|
|
<xul:toolbarbutton anonid="find-closebutton"
|
|
|
|
class="findbar-closebutton"
|
|
|
|
tooltiptext="&findCloseButton.tooltip;"
|
|
|
|
oncommand="close();"/>
|
2007-05-13 19:23:02 -07:00
|
|
|
<xul:label anonid="find-label" class="findbar-find-fast" control="findbar-textbox"/>
|
2009-03-14 12:53:12 -07:00
|
|
|
<xul:textbox class="findbar-textbox findbar-find-fast" anonid="findbar-textbox"
|
|
|
|
xbl:inherits="flash"/>
|
2009-03-11 08:10:52 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
<xul:toolbarbutton anonid="find-previous"
|
|
|
|
class="findbar-find-previous tabbable"
|
|
|
|
label="&previous.label;"
|
|
|
|
accesskey="&previous.accesskey;"
|
|
|
|
tooltiptext="&previous.tooltip;"
|
|
|
|
oncommand="onFindAgainCommand(true);"
|
|
|
|
disabled="true"
|
|
|
|
xbl:inherits="accesskey=findpreviousaccesskey"/>
|
|
|
|
#endif
|
|
|
|
<xul:toolbarbutton anonid="find-next"
|
|
|
|
class="findbar-find-next tabbable"
|
|
|
|
label="&next.label;"
|
|
|
|
accesskey="&next.accesskey;"
|
|
|
|
tooltiptext="&next.tooltip;"
|
|
|
|
oncommand="onFindAgainCommand(false);"
|
|
|
|
disabled="true"
|
|
|
|
xbl:inherits="accesskey=findnextaccesskey"/>
|
|
|
|
#ifndef MOZ_WIDGET_GTK2
|
|
|
|
<xul:toolbarbutton anonid="find-previous"
|
|
|
|
class="findbar-find-previous tabbable"
|
|
|
|
label="&previous.label;"
|
|
|
|
accesskey="&previous.accesskey;"
|
|
|
|
tooltiptext="&previous.tooltip;"
|
|
|
|
oncommand="onFindAgainCommand(true);"
|
|
|
|
disabled="true"
|
|
|
|
xbl:inherits="accesskey=findpreviousaccesskey"/>
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
<xul:toolbarbutton anonid="highlight"
|
2007-05-13 08:53:53 -07:00
|
|
|
class="findbar-highlight tabbable"
|
2007-03-22 10:30:00 -07:00
|
|
|
label="&highlight.label;"
|
|
|
|
accesskey="&highlight.accesskey;"
|
|
|
|
tooltiptext="&highlight.tooltiptext;"
|
2007-11-12 07:23:13 -08:00
|
|
|
oncommand="toggleHighlight(this.checked);"
|
2007-03-22 10:30:00 -07:00
|
|
|
type="checkbox"
|
|
|
|
disabled="true"
|
|
|
|
xbl:inherits="accesskey=highlightaccesskey"/>
|
|
|
|
<xul:checkbox anonid="find-case-sensitive"
|
|
|
|
oncommand="_setCaseSensitivity(this.checked);"
|
|
|
|
label="&caseSensitiveCheckbox.label;"
|
|
|
|
accesskey="&caseSensitiveCheckbox.accesskey;"
|
|
|
|
xbl:inherits="accesskey=matchcaseaccesskey"/>
|
|
|
|
<xul:label anonid="match-case-status" class="findbar-find-fast"/>
|
|
|
|
<xul:image anonid="find-status-icon" class="findbar-find-fast find-status-icon"/>
|
2007-09-17 13:49:21 -07:00
|
|
|
<xul:description anonid="find-status" class="findbar-find-fast findbar-find-status"
|
|
|
|
control="findbar-textbox">
|
|
|
|
<!-- Do not use value, first child is used because it provides a11y with text change events -->
|
|
|
|
</xul:description>
|
2008-04-09 15:03:09 -07:00
|
|
|
</xul:hbox>
|
2007-03-22 10:30:00 -07:00
|
|
|
</content>
|
|
|
|
|
2009-05-19 16:51:22 -07:00
|
|
|
<implementation implements="nsIDOMEventListener, nsIEditActionListener">
|
2007-03-22 10:30:00 -07:00
|
|
|
<field name="FIND_NORMAL">0</field>
|
|
|
|
<field name="FIND_TYPEAHEAD">1</field>
|
|
|
|
<field name="FIND_LINKS">2</field>
|
|
|
|
|
|
|
|
<field name="_findMode">0</field>
|
|
|
|
<field name="_tmpOutline">null</field>
|
|
|
|
<field name="_tmpOutlineOffset">"0"</field>
|
|
|
|
<field name="_drawOutline">false</field>
|
|
|
|
<field name="_foundLink">null</field>
|
2009-04-06 09:02:32 -07:00
|
|
|
<field name="_editors">null</field>
|
|
|
|
<field name="_stateListeners">null</field>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<field name="_flashFindBar">0</field>
|
|
|
|
<field name="_initialFlashFindBarCount">6</field>
|
|
|
|
|
|
|
|
<property name="prefillWithSelection"
|
|
|
|
onget="return this.getAttribute('prefillwithselection') != 'false'"
|
|
|
|
onset="this.setAttribute('prefillwithselection', val); return val;"/>
|
|
|
|
<field name="_selectionMaxLen">150</field>
|
|
|
|
|
|
|
|
<method name="getElement">
|
|
|
|
<parameter name="aAnonymousID"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
return document.getAnonymousElementByAttribute(this,
|
|
|
|
"anonid",
|
|
|
|
aAnonymousID)
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<property name="findMode"
|
|
|
|
readonly="true"
|
|
|
|
onget="return this._findMode;"/>
|
|
|
|
|
|
|
|
<field name="_browser">null</field>
|
|
|
|
<property name="browser">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (!this._browser) {
|
|
|
|
this._browser =
|
|
|
|
document.getElementById(this.getAttribute("browserid"));
|
|
|
|
}
|
|
|
|
return this._browser;
|
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
|
|
|
if (this._browser) {
|
|
|
|
this._browser.removeEventListener("keypress", this, false);
|
|
|
|
this._browser.removeEventListener("mouseup", this, false);
|
|
|
|
this._foundLink = null;
|
|
|
|
this._foundEditable = null;
|
|
|
|
this._currentWindow = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._browser = val;
|
|
|
|
if (this._browser) {
|
|
|
|
this._browser.addEventListener("keypress", this, false);
|
|
|
|
this._browser.addEventListener("mouseup", this, false);
|
|
|
|
this._findField.value = this._browser.fastFind.searchString;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="_observer"><![CDATA[({
|
|
|
|
_self: this,
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIObserver) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aPrefName) {
|
|
|
|
if (aTopic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var prefsvc =
|
2012-01-16 17:18:29 -08:00
|
|
|
aSubject.QueryInterface(Components.interfaces.nsIPrefBranch);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aPrefName) {
|
|
|
|
case "accessibility.typeaheadfind":
|
|
|
|
this._self._useTypeAheadFind = prefsvc.getBoolPref(aPrefName);
|
|
|
|
break;
|
|
|
|
case "accessibility.typeaheadfind.linksonly":
|
|
|
|
this._self._typeAheadLinksOnly = prefsvc.getBoolPref(aPrefName);
|
|
|
|
break;
|
|
|
|
case "accessibility.typeaheadfind.casesensitive":
|
|
|
|
this._self._typeAheadCaseSensitive = prefsvc.getIntPref(aPrefName);
|
|
|
|
this._self._updateCaseSensitivity();
|
2007-12-17 21:28:05 -08:00
|
|
|
if (this._self.getElement("highlight").checked)
|
|
|
|
this._self._setHighlightTimeout();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})]]></field>
|
|
|
|
|
2009-07-13 04:34:22 -07:00
|
|
|
<field name="_destroyed">false</field>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<constructor><![CDATA[
|
|
|
|
// These elements are accessed frequently and are therefore cached
|
|
|
|
this._findField = this.getElement("findbar-textbox");
|
|
|
|
this._findStatusIcon = this.getElement("find-status-icon");
|
2007-09-17 13:49:21 -07:00
|
|
|
this._findStatusDesc = this.getElement("find-status");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var prefsvc =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
2012-01-16 17:18:29 -08:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
this._quickFindTimeoutLength =
|
|
|
|
prefsvc.getIntPref("accessibility.typeaheadfind.timeout");
|
|
|
|
this._flashFindBar =
|
|
|
|
prefsvc.getIntPref("accessibility.typeaheadfind.flashBar");
|
|
|
|
|
|
|
|
prefsvc.addObserver("accessibility.typeaheadfind",
|
|
|
|
this._observer, false);
|
|
|
|
prefsvc.addObserver("accessibility.typeaheadfind.linksonly",
|
|
|
|
this._observer, false);
|
|
|
|
prefsvc.addObserver("accessibility.typeaheadfind.casesensitive",
|
|
|
|
this._observer, false);
|
|
|
|
|
|
|
|
this._useTypeAheadFind =
|
|
|
|
prefsvc.getBoolPref("accessibility.typeaheadfind");
|
|
|
|
this._typeAheadLinksOnly =
|
|
|
|
prefsvc.getBoolPref("accessibility.typeaheadfind.linksonly");
|
|
|
|
this._typeAheadCaseSensitive =
|
|
|
|
prefsvc.getIntPref("accessibility.typeaheadfind.casesensitive");
|
|
|
|
|
|
|
|
// Convenience
|
|
|
|
this.nsITypeAheadFind = Components.interfaces.nsITypeAheadFind;
|
|
|
|
this.nsISelectionController = Components.interfaces.nsISelectionController;
|
2009-04-06 09:02:32 -07:00
|
|
|
this._findSelection = this.nsISelectionController.SELECTION_FIND;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
this._findResetTimeout = -1;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure the FAYT keypress listener is attached by initializing the
|
|
|
|
// browser property
|
2011-02-15 04:47:32 -08:00
|
|
|
if (this.getAttribute("browserid"))
|
|
|
|
setTimeout(function(aSelf) { aSelf.browser = aSelf.browser; }, 0, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
2009-07-13 04:34:22 -07:00
|
|
|
this.destroy();
|
|
|
|
]]></destructor>
|
2009-04-06 09:02:32 -07:00
|
|
|
|
2009-07-13 04:34:22 -07:00
|
|
|
<!-- This is necessary because the destructor isn't called when
|
|
|
|
we are removed from a document that is not destroyed. This
|
|
|
|
needs to be explicitly called in this case -->
|
|
|
|
<method name="destroy">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._destroyed)
|
|
|
|
return;
|
|
|
|
this._destroyed = true;
|
|
|
|
|
|
|
|
// It is possible that the findbar may be destroyed before any
|
|
|
|
// documents it is listening to (see nsIEditActionListener code below).
|
|
|
|
// Thus, to avoid leaking, if we are listening to any editors, unhook
|
|
|
|
// ourselves now, and remove our cached copies
|
|
|
|
if (this._editors) {
|
|
|
|
for (var x = this._editors.length - 1; x >= 0; --x)
|
|
|
|
this._unhookListenersAtIndex(x);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-13 04:34:22 -07:00
|
|
|
this.browser = null;
|
|
|
|
|
|
|
|
var prefsvc =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
2012-01-16 17:18:29 -08:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2009-07-13 04:34:22 -07:00
|
|
|
prefsvc.removeObserver("accessibility.typeaheadfind",
|
|
|
|
this._observer);
|
|
|
|
prefsvc.removeObserver("accessibility.typeaheadfind.linksonly",
|
|
|
|
this._observer);
|
|
|
|
prefsvc.removeObserver("accessibility.typeaheadfind.casesensitive",
|
|
|
|
this._observer);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<method name="_setFindCloseTimeout">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._quickFindTimeout)
|
|
|
|
clearTimeout(this._quickFindTimeout);
|
|
|
|
|
|
|
|
// Don't close the find toolbar while IME is composing.
|
|
|
|
if (this._isIMEComposing) {
|
|
|
|
this._quickFindTimeout = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._quickFindTimeout =
|
|
|
|
setTimeout(function(aSelf) {
|
|
|
|
if (aSelf._findMode != aSelf.FIND_NORMAL)
|
|
|
|
aSelf.close();
|
|
|
|
}, this._quickFindTimeoutLength, this);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2008-07-30 13:48:56 -07:00
|
|
|
<!--
|
2009-10-01 04:03:22 -07:00
|
|
|
- Gets the selection controller for the current browser
|
2008-07-30 13:48:56 -07:00
|
|
|
-->
|
|
|
|
<method name="_getSelectionController">
|
2008-09-25 09:37:44 -07:00
|
|
|
<parameter name="aWindow"/>
|
2008-07-30 13:48:56 -07:00
|
|
|
<body><![CDATA[
|
2009-05-20 16:15:36 -07:00
|
|
|
// display: none iframes don't have a selection controller, see bug 493658
|
|
|
|
if (!aWindow.innerWidth || !aWindow.innerHeight)
|
|
|
|
return null;
|
|
|
|
|
2008-07-30 13:48:56 -07:00
|
|
|
// Yuck. See bug 138068.
|
|
|
|
var Ci = Components.interfaces;
|
2008-09-25 09:37:44 -07:00
|
|
|
var docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
|
|
|
|
|
|
|
var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsISelectionDisplay)
|
|
|
|
.QueryInterface(Ci.nsISelectionController);
|
2008-07-30 13:48:56 -07:00
|
|
|
return controller;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
<!--
|
|
|
|
- For a given node, walk up it's parent chain, to try and find an
|
|
|
|
- editable node.
|
|
|
|
-
|
|
|
|
- @param aNode the node we want to check
|
|
|
|
- @returns the first node in the parent chain that is editable,
|
|
|
|
- null if there is no such node
|
|
|
|
-->
|
2008-07-30 13:48:56 -07:00
|
|
|
<method name="_getEditableNode">
|
|
|
|
<parameter name="aNode"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
while (aNode) {
|
|
|
|
if (aNode instanceof Components.interfaces.nsIDOMNSEditableElement) {
|
|
|
|
return aNode.editor ? aNode : null;
|
|
|
|
}
|
|
|
|
aNode = aNode.parentNode;
|
|
|
|
}
|
2009-10-01 04:03:22 -07:00
|
|
|
return null;
|
2008-07-30 13:48:56 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
<!--
|
|
|
|
- Helper method to unhook listeners, remove cached editors
|
|
|
|
- and keep the relevant arrays in sync
|
|
|
|
-
|
|
|
|
- @param aIndex the index into the array of editors/state listeners
|
|
|
|
- we wish to remove
|
|
|
|
-->
|
|
|
|
<method name="_unhookListenersAtIndex">
|
|
|
|
<parameter name="aIndex"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this._editors[aIndex].removeEditActionListener(this);
|
|
|
|
this._editors[aIndex]
|
|
|
|
.removeDocumentStateListener(this._stateListeners[aIndex]);
|
|
|
|
this._editors.splice(aIndex, 1);
|
|
|
|
this._stateListeners.splice(aIndex, 1);
|
|
|
|
if (this._editors.length == 0) {
|
|
|
|
delete this._editors;
|
|
|
|
delete this._stateListeners;
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Remove ourselves as an nsIEditActionListener and
|
|
|
|
- nsIDocumentStateListener from a given cached editor
|
2009-10-01 04:03:22 -07:00
|
|
|
-
|
2009-04-06 09:02:32 -07:00
|
|
|
- @param aEditor the editor we no longer wish to listen to
|
|
|
|
-->
|
|
|
|
<method name="_removeEditorListeners">
|
|
|
|
<parameter name="aEditor"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// aEditor is an editor that we listen to, so therefore must be
|
|
|
|
// cached. Find the index of this editor
|
|
|
|
var idx = 0;
|
|
|
|
while (this._editors[idx] != aEditor)
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
// Now unhook ourselves, and remove our cached copy
|
|
|
|
this._unhookListenersAtIndex(idx);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- nsIEditActionListener logic follows
|
2009-10-01 04:03:22 -07:00
|
|
|
-
|
2009-04-06 09:02:32 -07:00
|
|
|
- We implement this interface to allow us to catch the case where
|
|
|
|
- the findbar found a match in a HTML <input> or <textarea>. If the
|
|
|
|
- user adjusts the text in some way, it will no longer match, so we
|
|
|
|
- want to remove the highlight, rather than have it expand/contract
|
|
|
|
- when letters are added or removed.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Helper method used to check whether a selection intersects with
|
|
|
|
- some highlighting
|
|
|
|
-
|
|
|
|
- @param aSelectionRange the range from the selection to check
|
|
|
|
- @param aFindRange the highlighted range to check against
|
|
|
|
- @returns true if they intersect, false otherwise
|
|
|
|
-->
|
|
|
|
<method name="_checkOverlap">
|
|
|
|
<parameter name="aSelectionRange"/>
|
|
|
|
<parameter name="aFindRange"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// The ranges overlap if one of the following is true:
|
|
|
|
// 1) At least one of the endpoints of the deleted selection
|
|
|
|
// is in the find selection
|
|
|
|
// 2) At least one of the endpoints of the find selection
|
|
|
|
// is in the deleted selection
|
|
|
|
if (aFindRange.isPointInRange(aSelectionRange.startContainer,
|
|
|
|
aSelectionRange.startOffset))
|
|
|
|
return true;
|
|
|
|
if (aFindRange.isPointInRange(aSelectionRange.endContainer,
|
|
|
|
aSelectionRange.endOffset))
|
|
|
|
return true;
|
|
|
|
if (aSelectionRange.isPointInRange(aFindRange.startContainer,
|
|
|
|
aFindRange.startOffset))
|
|
|
|
return true;
|
|
|
|
if (aSelectionRange.isPointInRange(aFindRange.endContainer,
|
|
|
|
aFindRange.endOffset))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Helper method to determine if an edit occurred within a highlight
|
|
|
|
-
|
|
|
|
- @param aSelection the selection we wish to check
|
|
|
|
- @param aNode the node we want to check is contained in aSelection
|
|
|
|
- @param aOffset the offset into aNode that we want to check
|
|
|
|
- @returns the range containing (aNode, aOffset) or null if no ranges
|
|
|
|
- in the selection contain it
|
|
|
|
-->
|
|
|
|
<method name="_findRange">
|
|
|
|
<parameter name="aSelection"/>
|
|
|
|
<parameter name="aNode"/>
|
|
|
|
<parameter name="aOffset"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var rangeCount = aSelection.rangeCount;
|
|
|
|
var rangeidx = 0;
|
|
|
|
var foundContainingRange = false;
|
|
|
|
var range = null;
|
|
|
|
|
|
|
|
// Check to see if this node is inside one of the selection's ranges
|
|
|
|
while (!foundContainingRange && rangeidx < rangeCount) {
|
|
|
|
range = aSelection.getRangeAt(rangeidx);
|
|
|
|
if (range.isPointInRange(aNode, aOffset)) {
|
|
|
|
foundContainingRange = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rangeidx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundContainingRange)
|
|
|
|
return range;
|
2009-10-01 04:03:22 -07:00
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
return null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- Start of nsIEditActionListener implementations -->
|
|
|
|
|
|
|
|
<method name="WillDeleteText">
|
|
|
|
<parameter name="aTextNode"/>
|
|
|
|
<parameter name="aOffset"/>
|
|
|
|
<parameter name="aLength"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var editor = this._getEditableNode(aTextNode).editor;
|
|
|
|
var controller = editor.selectionController;
|
|
|
|
var fSelection = controller.getSelection(this._findSelection);
|
|
|
|
var range = this._findRange(fSelection, aTextNode, aOffset);
|
|
|
|
|
|
|
|
if (range) {
|
|
|
|
// Don't remove the highlighting if the deleted text is at the
|
|
|
|
// end of the range
|
|
|
|
if (aTextNode != range.endContainer ||
|
|
|
|
aOffset != range.endOffset) {
|
|
|
|
// Text within the highlight is being removed - the text can
|
|
|
|
// no longer be a match, so remove the highlighting
|
|
|
|
fSelection.removeRange(range);
|
|
|
|
if (fSelection.rangeCount == 0)
|
|
|
|
this._removeEditorListeners(editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidInsertText">
|
|
|
|
<parameter name="aTextNode"/>
|
|
|
|
<parameter name="aOffset"/>
|
|
|
|
<parameter name="aString"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var editor = this._getEditableNode(aTextNode).editor;
|
|
|
|
var controller = editor.selectionController;
|
|
|
|
var fSelection = controller.getSelection(this._findSelection);
|
|
|
|
var range = this._findRange(fSelection, aTextNode, aOffset);
|
|
|
|
|
|
|
|
if (range) {
|
|
|
|
// If the text was inserted before the highlight
|
|
|
|
// adjust the highlight's bounds accordingly
|
|
|
|
if (aTextNode == range.startContainer &&
|
|
|
|
aOffset == range.startOffset)
|
|
|
|
range.setStart(range.startContainer,
|
|
|
|
range.startOffset+aString.length);
|
|
|
|
else if (aTextNode != range.endContainer ||
|
|
|
|
aOffset != range.endOffset) {
|
|
|
|
// The edit occurred within the highlight - any addition of text
|
|
|
|
// will result in the text no longer being a match,
|
|
|
|
// so remove the highlighting
|
|
|
|
fSelection.removeRange(range);
|
|
|
|
if (fSelection.rangeCount == 0)
|
|
|
|
this._removeEditorListeners(editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillDeleteSelection">
|
|
|
|
<parameter name="aSelection"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var editor = this._getEditableNode(aSelection.getRangeAt(0)
|
|
|
|
.startContainer).editor;
|
|
|
|
var controller = editor.selectionController;
|
|
|
|
var fSelection = controller.getSelection(this._findSelection);
|
|
|
|
|
|
|
|
var selectionIndex = 0;
|
|
|
|
var findSelectionIndex = 0;
|
|
|
|
var shouldDelete = {};
|
|
|
|
var numberOfDeletedSelections = 0;
|
|
|
|
var numberOfMatches = fSelection.rangeCount;
|
|
|
|
|
|
|
|
// We need to test if any ranges in the deleted selection (aSelection)
|
|
|
|
// are in any of the ranges of the find selection
|
|
|
|
// Usually both selections will only contain one range, however
|
|
|
|
// either may contain more than one.
|
|
|
|
|
|
|
|
for (var fIndex = 0; fIndex < numberOfMatches; fIndex++) {
|
|
|
|
shouldDelete[fIndex] = false;
|
|
|
|
var fRange = fSelection.getRangeAt(fIndex);
|
|
|
|
|
|
|
|
for (var index = 0; index < aSelection.rangeCount; index++) {
|
|
|
|
if (!shouldDelete[fIndex]) {
|
|
|
|
var selRange = aSelection.getRangeAt(index);
|
|
|
|
var doesOverlap = this._checkOverlap(selRange, fRange);
|
|
|
|
if (doesOverlap) {
|
|
|
|
shouldDelete[fIndex] = true;
|
|
|
|
numberOfDeletedSelections++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK, so now we know what matches (if any) are in the selection
|
|
|
|
// that is being deleted. Time to remove them.
|
|
|
|
if (numberOfDeletedSelections == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (var i = numberOfMatches - 1; i >= 0; i--) {
|
|
|
|
if (shouldDelete[i]) {
|
|
|
|
var r = fSelection.getRangeAt(i);
|
|
|
|
fSelection.removeRange(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove listeners if no more highlights left
|
|
|
|
if (fSelection.rangeCount == 0)
|
|
|
|
this._removeEditorListeners(editor);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillInsertText">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidCreateNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidDeleteNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidDeleteSelection">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidDeleteText">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidInsertNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidJoinNodes">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="DidSplitNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillCreateNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillDeleteNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillInsertNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillJoinNodes">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="WillSplitNode">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Unimplemented
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- End of nsIEditActionListener implementations -->
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- nsIDocumentStateListener logic follows
|
|
|
|
-
|
|
|
|
- When attaching nsIEditActionListeners, there are no guarantees
|
|
|
|
- as to whether the findbar or the documents in the browser will get
|
|
|
|
- destructed first. This leads to the potential to either leak, or to
|
|
|
|
- hold on to a reference an editable element's editor for too long,
|
|
|
|
- preventing it from being destructed.
|
|
|
|
-
|
|
|
|
- However, when an editor's owning node is being destroyed, the editor
|
|
|
|
- sends out a DocumentWillBeDestroyed notification. We can use this to
|
|
|
|
- clean up our references to the object, to allow it to be destroyed in a
|
|
|
|
- timely fashion.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Unhook ourselves when one of our state listeners has been called.
|
|
|
|
- This can happen in 4 cases:
|
|
|
|
- 1) The document the editor belongs to is navigated away from, and
|
|
|
|
- the document is not being cached
|
|
|
|
-
|
|
|
|
- 2) The document the editor belongs to is expired from the cache
|
|
|
|
-
|
|
|
|
- 3) The tab containing the owning document is closed
|
|
|
|
-
|
|
|
|
- 4) The <input> or <textarea> that owns the editor is explicitly
|
|
|
|
- removed from the DOM
|
|
|
|
-
|
|
|
|
- @param the listener that was invoked
|
|
|
|
-->
|
|
|
|
<method name="_onEditorDestruction">
|
|
|
|
<parameter name="aListener"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// First find the index of the editor the given listener listens to.
|
|
|
|
// The listeners and editors arrays must always be in sync.
|
|
|
|
// The listener will be in our array of cached listeners, as this
|
|
|
|
// method could not have been called otherwise.
|
|
|
|
var idx = 0;
|
|
|
|
while (this._stateListeners[idx] != aListener)
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
// Unhook both listeners
|
|
|
|
this._unhookListenersAtIndex(idx);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Creates a unique document state listener for an editor.
|
|
|
|
-
|
|
|
|
- It is not possible to simply have the findbar implement the
|
|
|
|
- listener interface itself, as it wouldn't have sufficient information
|
|
|
|
- to work out which editor was being destroyed. Therefore, we create new
|
|
|
|
- listeners on the fly, and cache them in sync with the editors they
|
|
|
|
- listen to.
|
|
|
|
-->
|
|
|
|
<method name="_createStateListener">
|
|
|
|
<body><![CDATA[
|
|
|
|
return ({
|
|
|
|
findbar: this,
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIDocumentStateListener) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
NotifyDocumentWillBeDestroyed: function() {
|
|
|
|
this.findbar._onEditorDestruction(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Unimplemented
|
|
|
|
notifyDocumentCreated: function() {},
|
|
|
|
notifyDocumentStateChanged: function(aDirty) {}
|
|
|
|
});
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<!--
|
|
|
|
- Turns highlight on or off.
|
|
|
|
- @param aHighlight (boolean)
|
2008-07-30 13:48:56 -07:00
|
|
|
- Whether to turn the highlight on or off
|
2007-03-22 10:30:00 -07:00
|
|
|
-->
|
|
|
|
<method name="toggleHighlight">
|
|
|
|
<parameter name="aHighlight"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var word = this._findField.value;
|
2008-09-25 09:27:52 -07:00
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
// Bug 429723. Don't attempt to highlight ""
|
|
|
|
if (aHighlight && !word)
|
2008-09-25 09:27:52 -07:00
|
|
|
return;
|
2009-04-06 09:02:32 -07:00
|
|
|
|
2008-09-25 09:27:52 -07:00
|
|
|
// We have to update the status because we might still have the status
|
|
|
|
// of another tab
|
|
|
|
if (this._highlightDoc(aHighlight, word))
|
|
|
|
this._updateStatusUI(this.nsITypeAheadFind.FIND_FOUND);
|
|
|
|
else
|
|
|
|
this._updateStatusUI(this.nsITypeAheadFind.FIND_NOTFOUND);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- (Un)highlights each instance of the searched word in the passed
|
|
|
|
- window's content.
|
2008-07-30 13:48:56 -07:00
|
|
|
- @param aHighlight (boolean)
|
|
|
|
- Whether to turn on highlight
|
2007-03-22 10:30:00 -07:00
|
|
|
- @param aWord
|
|
|
|
- the word to search for
|
|
|
|
- @param aWindow
|
|
|
|
- the window to search in. Passing undefined will search the
|
|
|
|
- current content window.
|
|
|
|
- @returns true if aWord was found
|
|
|
|
-->
|
|
|
|
<method name="_highlightDoc">
|
2008-07-30 13:48:56 -07:00
|
|
|
<parameter name="aHighlight"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
<parameter name="aWord"/>
|
|
|
|
<parameter name="aWindow"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var win = aWindow || this.browser.contentWindow;
|
2009-04-05 20:56:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var textFound = false;
|
2008-07-30 13:48:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; win.frames && i < win.frames.length; i++) {
|
2008-07-30 13:48:56 -07:00
|
|
|
if (this._highlightDoc(aHighlight, aWord, win.frames[i]))
|
2007-03-22 10:30:00 -07:00
|
|
|
textFound = true;
|
|
|
|
}
|
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
var controller = this._getSelectionController(win);
|
|
|
|
if (!controller) {
|
|
|
|
// Without the selection controller,
|
|
|
|
// we are unable to (un)highlight any matches
|
2009-10-01 04:03:22 -07:00
|
|
|
return textFound;
|
2009-04-06 09:02:32 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var doc = win.document;
|
|
|
|
if (!doc || !(doc instanceof HTMLDocument))
|
|
|
|
return textFound;
|
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
if (aHighlight) {
|
|
|
|
this._searchRange = doc.createRange();
|
2009-10-01 04:03:22 -07:00
|
|
|
this._searchRange.selectNodeContents(doc.body);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-01 04:03:22 -07:00
|
|
|
this._startPt = this._searchRange.cloneRange();
|
|
|
|
this._startPt.collapse(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-01 04:03:22 -07:00
|
|
|
this._endPt = this._searchRange.cloneRange();
|
|
|
|
this._endPt.collapse(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
var retRange = null;
|
|
|
|
var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"]
|
|
|
|
.createInstance()
|
|
|
|
.QueryInterface(Components.interfaces.nsIFind);
|
2009-04-03 05:53:36 -07:00
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
finder.caseSensitive = this._shouldBeCaseSensitive(aWord);
|
|
|
|
|
|
|
|
while ((retRange = finder.Find(aWord, this._searchRange,
|
|
|
|
this._startPt, this._endPt))) {
|
|
|
|
this._highlight(retRange, controller);
|
2009-10-01 04:03:22 -07:00
|
|
|
this._startPt = retRange.cloneRange();
|
|
|
|
this._startPt.collapse(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-06 09:02:32 -07:00
|
|
|
textFound = true;
|
2008-07-30 13:48:56 -07:00
|
|
|
}
|
2009-04-06 09:02:32 -07:00
|
|
|
} else {
|
|
|
|
// First, attempt to remove highlighting from main document
|
|
|
|
var sel = controller.getSelection(this._findSelection);
|
|
|
|
sel.removeAllRanges();
|
|
|
|
|
|
|
|
// Next, check our editor cache, for editors belonging to this
|
|
|
|
// document
|
|
|
|
if (this._editors) {
|
|
|
|
for (var x = this._editors.length - 1; x >= 0; --x) {
|
|
|
|
if (this._editors[x].document == doc) {
|
|
|
|
sel = this._editors[x].selectionController
|
|
|
|
.getSelection(this._findSelection);
|
|
|
|
sel.removeAllRanges();
|
|
|
|
// We don't need to listen to this editor any more
|
|
|
|
this._unhookListenersAtIndex(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2008-07-30 13:48:56 -07:00
|
|
|
}
|
2009-10-01 04:03:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return textFound;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Highlights the word in the passed range.
|
|
|
|
-
|
|
|
|
- @param aRange
|
|
|
|
- the range that contains the word to highlight
|
2008-07-30 13:48:56 -07:00
|
|
|
- @param aController
|
|
|
|
- the current document's selection controller
|
2007-03-22 10:30:00 -07:00
|
|
|
-->
|
|
|
|
<method name="_highlight">
|
|
|
|
<parameter name="aRange"/>
|
2008-07-30 13:48:56 -07:00
|
|
|
<parameter name="aController"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
<body><![CDATA[
|
2008-07-30 13:48:56 -07:00
|
|
|
var node = aRange.startContainer;
|
|
|
|
var controller = aController;
|
2009-04-06 09:02:32 -07:00
|
|
|
var editableNode = this._getEditableNode(node);
|
|
|
|
if (editableNode)
|
|
|
|
controller = editableNode.editor.selectionController;
|
|
|
|
|
|
|
|
var findSelection = controller.getSelection(this._findSelection);
|
|
|
|
findSelection.addRange(aRange);
|
|
|
|
|
|
|
|
if (editableNode) {
|
|
|
|
// Highlighting added, so cache this editor, and hook up listeners
|
|
|
|
// to ensure we deal properly with edits within the highlighting
|
|
|
|
if (!this._editors) {
|
|
|
|
this._editors = [];
|
|
|
|
this._stateListeners = [];
|
|
|
|
}
|
|
|
|
|
2009-09-18 10:34:50 -07:00
|
|
|
var existingIndex = this._editors.indexOf(editableNode.editor);
|
|
|
|
if (existingIndex == -1) {
|
|
|
|
var x = this._editors.length;
|
|
|
|
this._editors[x] = editableNode.editor;
|
|
|
|
this._stateListeners[x] = this._createStateListener();
|
|
|
|
this._editors[x].addEditActionListener(this);
|
|
|
|
this._editors[x].addDocumentStateListener(this._stateListeners[x]);
|
|
|
|
}
|
2009-04-06 09:02:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Updates the case-sensitivity mode of the findbar and its UI.
|
|
|
|
- @param [optional] aString
|
|
|
|
- The string for which case sensitivity might be turned on.
|
|
|
|
- This only used when case-sensitivity is in auto mode,
|
|
|
|
- @see _shouldBeCaseSensitive. The default value for this
|
|
|
|
- parameter is the find-field value.
|
|
|
|
-->
|
|
|
|
<method name="_updateCaseSensitivity">
|
|
|
|
<parameter name="aString"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var val = aString || this._findField.value;
|
|
|
|
|
|
|
|
var caseSensitive = this._shouldBeCaseSensitive(val);
|
|
|
|
var checkbox = this.getElement("find-case-sensitive");
|
|
|
|
var statusLabel = this.getElement("match-case-status");
|
|
|
|
checkbox.checked = caseSensitive;
|
|
|
|
|
|
|
|
statusLabel.value = caseSensitive ? this._caseSensitiveStr : "";
|
|
|
|
|
|
|
|
// Show the checkbox on the full Find bar in non-auto mode.
|
|
|
|
// Show the label in all other cases.
|
|
|
|
var hideCheckbox = this._findMode != this.FIND_NORMAL ||
|
|
|
|
(this._typeAheadCaseSensitive != 0 &&
|
|
|
|
this._typeAheadCaseSensitive != 1);
|
|
|
|
checkbox.hidden = hideCheckbox;
|
|
|
|
statusLabel.hidden = !hideCheckbox;
|
|
|
|
|
|
|
|
var fastFind = this.browser.fastFind;
|
|
|
|
fastFind.caseSensitive = caseSensitive;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Sets the findbar case-sensitivity mode
|
|
|
|
- @param aCaseSensitive (boolean)
|
|
|
|
- Whether or not case-sensitivity should be turned on.
|
|
|
|
-->
|
|
|
|
<method name="_setCaseSensitivity">
|
|
|
|
<parameter name="aCaseSensitive"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var prefsvc =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
2012-01-16 17:18:29 -08:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Just set the pref; our observer will change the find bar behavior
|
|
|
|
prefsvc.setIntPref("accessibility.typeaheadfind.casesensitive",
|
|
|
|
aCaseSensitive ? 1 : 0);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Opens and displays the find bar.
|
|
|
|
-
|
|
|
|
- @param aMode
|
|
|
|
- the find mode to be used, which is either FIND_NORMAL,
|
|
|
|
- FIND_TYPEAHEAD or FIND_LINKS. If not passed, the last
|
|
|
|
- find mode if any or FIND_NORMAL.
|
|
|
|
- @returns true if the find bar wasn't previously open, false otherwise.
|
|
|
|
-->
|
|
|
|
<method name="open">
|
|
|
|
<parameter name="aMode"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aMode != undefined)
|
|
|
|
this._findMode = aMode;
|
|
|
|
|
|
|
|
if (!this._notFoundStr) {
|
|
|
|
var stringsBundle =
|
|
|
|
Components.classes["@mozilla.org/intl/stringbundle;1"]
|
|
|
|
.getService(Components.interfaces.nsIStringBundleService)
|
|
|
|
.createBundle("chrome://global/locale/findbar.properties");
|
|
|
|
this._notFoundStr = stringsBundle.GetStringFromName("NotFound");
|
|
|
|
this._wrappedToTopStr =
|
|
|
|
stringsBundle.GetStringFromName("WrappedToTop");
|
|
|
|
this._wrappedToBottomStr =
|
|
|
|
stringsBundle.GetStringFromName("WrappedToBottom");
|
|
|
|
this._normalFindStr =
|
|
|
|
stringsBundle.GetStringFromName("NormalFindLabel");
|
|
|
|
this._fastFindStr =
|
|
|
|
stringsBundle.GetStringFromName("FastFindLabel");
|
|
|
|
this._fastFindLinksStr =
|
|
|
|
stringsBundle.GetStringFromName("FastFindLinksLabel");
|
|
|
|
this._caseSensitiveStr =
|
|
|
|
stringsBundle.GetStringFromName("CaseSensitive");
|
|
|
|
}
|
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
this._findFailedString = null;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updateFindUI();
|
|
|
|
if (this.hidden) {
|
|
|
|
this.hidden = false;
|
|
|
|
|
|
|
|
this._updateStatusUI(this.nsITypeAheadFind.FIND_FOUND);
|
2011-03-02 16:48:58 -08:00
|
|
|
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("findbaropen", true, false);
|
|
|
|
this.dispatchEvent(event);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Closes the findbar.
|
|
|
|
-->
|
|
|
|
<method name="close">
|
|
|
|
<body><![CDATA[
|
2011-02-11 16:11:24 -08:00
|
|
|
if (this.hidden)
|
|
|
|
return;
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
var fm =
|
|
|
|
Components.classes["@mozilla.org/focus-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIFocusManager);
|
|
|
|
if (window == fm.focusedWindow) {
|
|
|
|
var focusedElement = fm.focusedElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (focusedElement) {
|
|
|
|
var bindingParent = document.getBindingParent(focusedElement);
|
|
|
|
if (bindingParent == this || bindingParent == this._findField) {
|
|
|
|
// block scrolling on focus since find already scrolls, further
|
|
|
|
// scrolling is due to user action, so don't override this
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
var element = this._foundLink || this._foundEditable;
|
|
|
|
if (element)
|
|
|
|
fm.setFocus(element, fm.FLAG_NOSCROLL);
|
|
|
|
else if (this._currentWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
this._currentWindow.focus();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
else
|
|
|
|
this.browser.contentWindow.focus();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hidden = true;
|
|
|
|
var fastFind = this.browser.fastFind;
|
|
|
|
fastFind.setSelectionModeAndRepaint
|
|
|
|
(this.nsISelectionController.SELECTION_ON);
|
|
|
|
this._setFoundLink(null);
|
|
|
|
this._foundEditable = null;
|
|
|
|
this._currentWindow = null;
|
|
|
|
if (this._quickFindTimeout) {
|
|
|
|
clearTimeout(this._quickFindTimeout);
|
|
|
|
this._quickFindTimeout = null;
|
|
|
|
}
|
2009-09-26 08:51:21 -07:00
|
|
|
|
|
|
|
this._findFailedString = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_dispatchKeypressEvent">
|
|
|
|
<parameter name="aTarget"/>
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!aTarget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var event = document.createEvent("KeyEvents");
|
|
|
|
event.initKeyEvent(aEvent.type, aEvent.bubbles, aEvent.cancelable,
|
|
|
|
aEvent.view, aEvent.ctrlKey, aEvent.altKey,
|
|
|
|
aEvent.shiftKey, aEvent.metaKey, aEvent.keyCode,
|
|
|
|
aEvent.charCode);
|
|
|
|
aTarget.dispatchEvent(event);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<field name="_xulBrowserWindow">null</field>
|
|
|
|
<method name="_updateStatusUIBar">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!this._xulBrowserWindow) {
|
|
|
|
try {
|
|
|
|
this._xulBrowserWindow =
|
|
|
|
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
|
|
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
|
|
|
|
.treeOwner
|
|
|
|
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIXULWindow)
|
|
|
|
.XULBrowserWindow;
|
|
|
|
}
|
|
|
|
catch(ex) { }
|
|
|
|
if (!this._xulBrowserWindow)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._foundLink || !this._foundLink.href ||
|
|
|
|
this._foundLink.href == "") {
|
|
|
|
this._xulBrowserWindow.setOverLink("", null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var docCharset = "";
|
|
|
|
var ownerDoc = this._foundLink.ownerDocument;
|
|
|
|
if (ownerDoc)
|
|
|
|
docCharset = ownerDoc.characterSet;
|
|
|
|
|
|
|
|
if (!this._textToSubURIService) {
|
|
|
|
this._textToSubURIService =
|
|
|
|
Components.classes["@mozilla.org/intl/texttosuburi;1"]
|
|
|
|
.getService(Components.interfaces.nsITextToSubURI);
|
|
|
|
}
|
|
|
|
var url =
|
|
|
|
this._textToSubURIService.unEscapeURIForUI(docCharset,
|
|
|
|
this._foundLink.href);
|
|
|
|
this._xulBrowserWindow.setOverLink(url, null);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_setFoundLink">
|
|
|
|
<parameter name="aFoundLink"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._foundLink == aFoundLink)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._foundLink && this._drawOutline) {
|
|
|
|
// restore original outline
|
|
|
|
this._foundLink.style.outline = this._tmpOutline;
|
|
|
|
this._foundLink.style.outlineOffset = this._tmpOutlineOffset;
|
|
|
|
}
|
|
|
|
this._drawOutline = (aFoundLink && this._findMode != this.FIND_NORMAL);
|
|
|
|
if (this._drawOutline) {
|
|
|
|
// backup original outline
|
|
|
|
this._tmpOutline = aFoundLink.style.outline;
|
|
|
|
this._tmpOutlineOffset = aFoundLink.style.outlineOffset;
|
|
|
|
|
|
|
|
// draw pseudo focus rect
|
|
|
|
// XXX Should we change the following style for FAYT pseudo focus?
|
|
|
|
// XXX Shouldn't we change default design if outline is visible
|
|
|
|
// already?
|
|
|
|
// Don't set the outline-color, we should always use initial value.
|
|
|
|
aFoundLink.style.outline = "1px dotted";
|
|
|
|
aFoundLink.style.outlineOffset = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
this._foundLink = aFoundLink;
|
|
|
|
|
|
|
|
// If the mouse cursor is on the document, the status bar text is
|
|
|
|
// changed by a mouse event which is dispatched by a scroll event.
|
|
|
|
// Thus we should change it only after the mouse event is dispatched.
|
|
|
|
if (this._findMode != this.FIND_NORMAL)
|
|
|
|
setTimeout(function(aSelf) { aSelf._updateStatusUIBar(); }, 0, this);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_finishFAYT">
|
|
|
|
<parameter name="aKeypressEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
try {
|
|
|
|
if (this._foundLink)
|
|
|
|
this._foundLink.focus();
|
|
|
|
else if (this._foundEditable) {
|
|
|
|
this._foundEditable.focus();
|
|
|
|
var fastFind = this.browser.fastFind;
|
|
|
|
fastFind.collapseSelection();
|
|
|
|
}
|
|
|
|
else if (this._currentWindow)
|
|
|
|
this._currentWindow.focus();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aKeypressEvent)
|
|
|
|
aKeypressEvent.preventDefault();
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
return true;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-08-25 21:17:32 -07:00
|
|
|
<!--
|
|
|
|
- Returns true if |aMimeType| is text-based, or false otherwise.
|
|
|
|
-
|
|
|
|
- @param aMimeType
|
|
|
|
- The MIME type to check.
|
2008-03-06 12:12:09 -08:00
|
|
|
-
|
|
|
|
- if adding types to this function, please see the similar function
|
|
|
|
- in browser/base/content/browser.js
|
2007-08-25 21:17:32 -07:00
|
|
|
-->
|
|
|
|
<method name="_mimeTypeIsTextBased">
|
|
|
|
<parameter name="aMimeType"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
return /^text\/|\+xml$/.test(aMimeType) ||
|
|
|
|
aMimeType == "application/x-javascript" ||
|
2008-03-06 12:12:09 -08:00
|
|
|
aMimeType == "application/javascript" ||
|
2007-08-25 21:17:32 -07:00
|
|
|
aMimeType == "application/xml";
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<!--
|
|
|
|
- Returns whether FAYT can be used for the given event in
|
|
|
|
- the current content state.
|
|
|
|
-->
|
|
|
|
<method name="_shouldFastFind">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey ||
|
2011-12-08 01:21:32 -08:00
|
|
|
aEvent.defaultPrevented)
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
var elt = document.commandDispatcher.focusedElement;
|
|
|
|
if (elt) {
|
2010-08-04 19:40:18 -07:00
|
|
|
if (elt instanceof HTMLInputElement && elt.mozIsTextField(false))
|
2010-06-15 14:42:36 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (elt instanceof HTMLTextAreaElement ||
|
|
|
|
elt instanceof HTMLSelectElement ||
|
|
|
|
elt instanceof HTMLObjectElement ||
|
|
|
|
elt instanceof HTMLEmbedElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-15 14:42:36 -07:00
|
|
|
var win = document.commandDispatcher.focusedWindow;
|
|
|
|
if (win && !this._mimeTypeIsTextBased(win.document.contentType))
|
|
|
|
return false;
|
|
|
|
|
2011-01-11 13:33:51 -08:00
|
|
|
// disable FAYT in about:blank to prevent FAYT opening unexpectedly.
|
|
|
|
var url = this.browser.currentURI;
|
|
|
|
if (url.spec == "about:blank")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// disable FAYT in documents that ask for it to be disabled.
|
|
|
|
if ((url.schemeIs("about") || url.schemeIs("chrome")) &&
|
|
|
|
(win.document.documentElement &&
|
|
|
|
win.document.documentElement.getAttribute("disablefastfind") == "true"))
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
try {
|
|
|
|
var editingSession = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
|
|
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIEditingSession);
|
|
|
|
if (editingSession.windowIsEditable(win))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// If someone built with composer disabled, we can't get an editing session.
|
|
|
|
}
|
2009-10-01 04:03:22 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_shouldBeCaseSensitive">
|
|
|
|
<parameter name="aString"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._typeAheadCaseSensitive == 0)
|
|
|
|
return false;
|
|
|
|
if (this._typeAheadCaseSensitive == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return aString != aString.toLowerCase();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_onBrowserKeypress">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
const TAF_LINKS_KEY = "'";
|
|
|
|
const TAF_TEXT_KEY = "/";
|
|
|
|
|
|
|
|
if (!this._shouldFastFind(aEvent))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._findMode != this.FIND_NORMAL && this._quickFindTimeout) {
|
|
|
|
if (!aEvent.charCode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._findField.select();
|
|
|
|
this._findField.focus();
|
|
|
|
this._dispatchKeypressEvent(this._findField.inputField, aEvent);
|
|
|
|
aEvent.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var key = aEvent.charCode ? String.fromCharCode(aEvent.charCode) : null;
|
|
|
|
var manualstartFAYT = (key == TAF_LINKS_KEY || key == TAF_TEXT_KEY);
|
|
|
|
var autostartFAYT = !manualstartFAYT && this._useTypeAheadFind &&
|
|
|
|
key && key != " ";
|
|
|
|
if (manualstartFAYT || autostartFAYT) {
|
|
|
|
var mode = (key == TAF_LINKS_KEY ||
|
|
|
|
(autostartFAYT && this._typeAheadLinksOnly)) ?
|
|
|
|
this.FIND_LINKS : this.FIND_TYPEAHEAD;
|
|
|
|
|
|
|
|
// Clear bar first, so that when openFindBar() calls setCaseSensitivity()
|
|
|
|
// it doesn't get confused by a lingering value
|
|
|
|
this._findField.value = "";
|
|
|
|
|
|
|
|
this.open(mode);
|
|
|
|
this._setFindCloseTimeout();
|
|
|
|
this._findField.select();
|
|
|
|
this._findField.focus();
|
|
|
|
|
|
|
|
if (autostartFAYT)
|
|
|
|
this._dispatchKeypressEvent(this._findField.inputField, aEvent);
|
|
|
|
else
|
|
|
|
this._updateStatusUI(this.nsITypeAheadFind.FIND_FOUND);
|
|
|
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!-- See nsIDOMEventListener -->
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "mouseup":
|
|
|
|
if (!this.hidden && this._findMode != this.FIND_NORMAL)
|
|
|
|
this.close();
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "keypress":
|
|
|
|
this._onBrowserKeypress(aEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_enableFindButtons">
|
|
|
|
<parameter name="aEnable"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this.getElement("find-next").disabled =
|
|
|
|
this.getElement("find-previous").disabled =
|
|
|
|
this.getElement("highlight").disabled = !aEnable;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Determines whether minimalist or general-purpose search UI is to be
|
|
|
|
- displayed when the find bar is activated.
|
|
|
|
-->
|
|
|
|
<method name="_updateFindUI">
|
|
|
|
<body><![CDATA[
|
|
|
|
var showMinimalUI = this._findMode != this.FIND_NORMAL;
|
|
|
|
|
2008-04-09 16:55:10 -07:00
|
|
|
var nodes = this.getElement("findbar-container").childNodes;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
if (nodes[i].className.indexOf("findbar-find-fast") != -1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nodes[i].hidden = showMinimalUI;
|
|
|
|
}
|
2007-05-12 23:27:11 -07:00
|
|
|
this._updateCaseSensitivity();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (this._findMode == this.FIND_TYPEAHEAD)
|
|
|
|
this.getElement("find-label").value = this._fastFindStr;
|
|
|
|
else if (this._findMode == this.FIND_LINKS)
|
|
|
|
this.getElement("find-label").value = this._fastFindLinksStr;
|
|
|
|
else
|
|
|
|
this.getElement("find-label").value = this._normalFindStr;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_updateFoundLink">
|
|
|
|
<parameter name="res"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var val = this._findField.value;
|
|
|
|
if (res == this.nsITypeAheadFind.FIND_NOTFOUND || !val) {
|
|
|
|
this._setFoundLink(null);
|
|
|
|
this._foundEditable = null;
|
|
|
|
this._currentWindow = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._setFoundLink(this.browser.fastFind.foundLink);
|
|
|
|
this._foundEditable = this.browser.fastFind.foundEditable;
|
|
|
|
this._currentWindow = this.browser.fastFind.currentWindow;
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_find">
|
|
|
|
<parameter name="aValue"/>
|
|
|
|
<body><![CDATA[
|
2009-09-01 22:52:05 -07:00
|
|
|
var val = aValue || this._findField.value;
|
|
|
|
var res = this.nsITypeAheadFind.FIND_NOTFOUND;
|
|
|
|
|
|
|
|
// Only search on input if we don't have a last-failed string,
|
|
|
|
// or if the current search string doesn't start with it.
|
|
|
|
if (this._findFailedString == null ||
|
|
|
|
val.indexOf(this._findFailedString) != 0)
|
|
|
|
{
|
|
|
|
this._enableFindButtons(val);
|
|
|
|
if (this.getElement("highlight").checked)
|
|
|
|
this._setHighlightTimeout();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
this._updateCaseSensitivity(val);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
var fastFind = this.browser.fastFind;
|
|
|
|
res = fastFind.find(val, this._findMode == this.FIND_LINKS);
|
2009-09-01 22:52:05 -07:00
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
this._updateFoundLink(res);
|
|
|
|
this._updateStatusUI(res, false);
|
|
|
|
|
|
|
|
if (res == this.nsITypeAheadFind.FIND_NOTFOUND)
|
|
|
|
this._findFailedString = val;
|
|
|
|
else
|
|
|
|
this._findFailedString = null;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (this._findMode != this.FIND_NORMAL)
|
|
|
|
this._setFindCloseTimeout();
|
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
if (this._findResetTimeout != -1)
|
|
|
|
clearTimeout(this._findResetTimeout);
|
|
|
|
|
|
|
|
// allow a search to happen on input again after a second has
|
|
|
|
// expired since the previous input, to allow for dynamic
|
|
|
|
// content and/or page loading
|
|
|
|
this._findResetTimeout = setTimeout(function(self) {
|
|
|
|
self._findFailedString = null;
|
|
|
|
self._findResetTimeout = -1; },
|
|
|
|
1000, this);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return res;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_flash">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._flashFindBarCount === undefined)
|
|
|
|
this._flashFindBarCount = this._initialFlashFindBarCount;
|
|
|
|
|
|
|
|
if (this._flashFindBarCount-- == 0) {
|
|
|
|
clearInterval(this._flashFindBarTimeout);
|
|
|
|
this.removeAttribute("flash");
|
|
|
|
this._flashFindBarCount = 6;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setAttribute("flash",
|
|
|
|
(this._flashFindBarCount % 2 == 0) ?
|
|
|
|
"false" : "true");
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_setHighlightTimeout">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._highlightTimeout)
|
|
|
|
clearTimeout(this._highlightTimeout);
|
|
|
|
this._highlightTimeout =
|
|
|
|
setTimeout(function(aSelf) {
|
|
|
|
aSelf.toggleHighlight(false);
|
|
|
|
aSelf.toggleHighlight(true);
|
|
|
|
}, 500, this);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_findAgain">
|
|
|
|
<parameter name="aFindPrevious"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var fastFind = this.browser.fastFind;
|
|
|
|
var res = fastFind.findAgain(aFindPrevious,
|
|
|
|
this._findMode == this.FIND_LINKS);
|
|
|
|
this._updateFoundLink(res);
|
|
|
|
this._updateStatusUI(res, aFindPrevious);
|
|
|
|
|
|
|
|
if (this._findMode != this.FIND_NORMAL && !this.hidden)
|
|
|
|
this._setFindCloseTimeout();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_updateStatusUI">
|
|
|
|
<parameter name="res"/>
|
|
|
|
<parameter name="aFindPrevious"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
switch (res) {
|
|
|
|
case this.nsITypeAheadFind.FIND_WRAPPED:
|
|
|
|
this._findStatusIcon.setAttribute("status", "wrapped");
|
2007-09-17 13:49:21 -07:00
|
|
|
this._findStatusDesc.textContent =
|
2007-03-22 10:30:00 -07:00
|
|
|
aFindPrevious ? this._wrappedToBottomStr : this._wrappedToTopStr;
|
|
|
|
this._findField.removeAttribute("status");
|
|
|
|
break;
|
|
|
|
case this.nsITypeAheadFind.FIND_NOTFOUND:
|
|
|
|
this._findStatusIcon.setAttribute("status", "notfound");
|
2007-09-17 13:49:21 -07:00
|
|
|
this._findStatusDesc.textContent = this._notFoundStr;
|
2007-03-22 10:30:00 -07:00
|
|
|
this._findField.setAttribute("status", "notfound");
|
|
|
|
break;
|
|
|
|
case this.nsITypeAheadFind.FIND_FOUND:
|
|
|
|
default:
|
|
|
|
this._findStatusIcon.removeAttribute("status");
|
2007-09-17 13:49:21 -07:00
|
|
|
this._findStatusDesc.textContent = "";
|
2007-03-22 10:30:00 -07:00
|
|
|
this._findField.removeAttribute("status");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_getInitialSelection">
|
|
|
|
<body><![CDATA[
|
|
|
|
var focusedElement = document.commandDispatcher.focusedElement;
|
|
|
|
var selText;
|
|
|
|
|
|
|
|
if (focusedElement instanceof Components.interfaces.nsIDOMNSEditableElement &&
|
2008-07-08 08:26:54 -07:00
|
|
|
focusedElement.editor &&
|
|
|
|
focusedElement.ownerDocument.defaultView.top == this._browser.contentWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// The user may have a selection in an input or textarea
|
|
|
|
selText = focusedElement.editor.selectionController
|
|
|
|
.getSelection(Components.interfaces.nsISelectionController.SELECTION_NORMAL)
|
|
|
|
.toString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Look for any selected text on the actual page
|
|
|
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
if (focusedWindow.top == this._browser.contentWindow)
|
|
|
|
selText = focusedWindow.getSelection().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selText)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// Process our text to get rid of unwanted characters
|
|
|
|
if (selText.length > this._selectionMaxLen) {
|
|
|
|
var pattern = new RegExp("^(?:\\s*.){0," + this._selectionMaxLen + "}");
|
|
|
|
pattern.test(selText);
|
|
|
|
selText = RegExp.lastMatch;
|
|
|
|
}
|
|
|
|
return selText.replace(/^\s+/, "")
|
|
|
|
.replace(/\s+$/, "")
|
|
|
|
.replace(/\s+/g, " ")
|
|
|
|
.substr(0, this._selectionMaxLen);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Opens the findbar, focuses the findfield and selects its contents.
|
|
|
|
- Also flashes the findbar the first time it's used.
|
|
|
|
- @param aMode
|
|
|
|
- the find mode to be used, which is either FIND_NORMAL,
|
|
|
|
- FIND_TYPEAHEAD or FIND_LINKS. If not passed, the last
|
|
|
|
- find mode if any or FIND_NORMAL.
|
|
|
|
-->
|
|
|
|
<method name="startFind">
|
|
|
|
<parameter name="aMode"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var prefsvc =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
2012-01-16 17:18:29 -08:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2007-03-22 10:30:00 -07:00
|
|
|
var userWantsPrefill = true;
|
|
|
|
this.open(aMode);
|
|
|
|
|
|
|
|
if (this._flashFindBar) {
|
|
|
|
this._flashFindBarTimeout =
|
|
|
|
setInterval(function(aSelf) { aSelf._flash(); }, 500, this);
|
|
|
|
prefsvc.setIntPref("accessibility.typeaheadfind.flashBar",
|
|
|
|
--this._flashFindBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.prefillWithSelection)
|
2009-10-01 04:03:22 -07:00
|
|
|
userWantsPrefill =
|
2007-03-22 10:30:00 -07:00
|
|
|
prefsvc.getBoolPref("accessibility.typeaheadfind.prefillwithselection");
|
|
|
|
|
|
|
|
var initialString = (this.prefillWithSelection && userWantsPrefill) ?
|
|
|
|
this._getInitialSelection() : null;
|
|
|
|
if (initialString) {
|
|
|
|
this._findField.value = initialString;
|
|
|
|
this._enableFindButtons(true);
|
|
|
|
}
|
|
|
|
else if (!this._findField.value)
|
|
|
|
this._enableFindButtons(false);
|
|
|
|
|
|
|
|
this._findField.select();
|
|
|
|
this._findField.focus();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Convenient alias to startFind(gFindBar.FIND_NORMAL);
|
|
|
|
-
|
|
|
|
- You should generally map the window's find command to this method.
|
|
|
|
- e.g. <command name="cmd_find" oncommand="gFindBar.onFindCommand();"/>
|
|
|
|
-->
|
|
|
|
<method name="onFindCommand">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.startFind(this.FIND_NORMAL);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
- Stub for find-next and find-previous commands
|
|
|
|
- @param aFindPrevious
|
|
|
|
- true for find-previous, false otherwise.
|
|
|
|
-->
|
|
|
|
<method name="onFindAgainCommand">
|
|
|
|
<parameter name="aFindPrevious"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var findString = this._browser.fastFind.searchString || this._findField.value;
|
|
|
|
if (!findString) {
|
|
|
|
this.startFind();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-01 22:52:05 -07:00
|
|
|
// user explicitly requested another search, so do it even if we think it'll fail
|
|
|
|
this._findFailedString = null;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var res;
|
|
|
|
// Ensure the stored SearchString is in sync with what we want to find
|
2009-09-26 08:51:21 -07:00
|
|
|
if (this._findField.value != this._browser.fastFind.searchString)
|
2007-03-22 10:30:00 -07:00
|
|
|
res = this._find(this._findField.value);
|
|
|
|
else
|
|
|
|
res = this._findAgain(aFindPrevious);
|
|
|
|
|
|
|
|
if (res == this.nsITypeAheadFind.FIND_NOTFOUND) {
|
|
|
|
if (this.open()) {
|
|
|
|
if (this._findMode != this.FIND_NORMAL)
|
|
|
|
this._setFindCloseTimeout();
|
|
|
|
this._findField.focus();
|
|
|
|
this._findField.focus();
|
|
|
|
this._updateStatusUI(res, aFindPrevious);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="keypress" keycode="VK_ESCAPE" phase="capturing" action="this.close();" preventdefault="true"/>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
</bindings>
|