2014-06-25 09:12:07 +04:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2012-06-26 03:11:16 +04:00
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-03-22 03:52:24 +04:00
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2002-11-03 00:14:22 +03:00
|
|
|
var gFindBundle;
|
|
|
|
|
2003-11-20 12:48:16 +03:00
|
|
|
function nsFindInstData() {}
|
|
|
|
nsFindInstData.prototype =
|
|
|
|
{
|
|
|
|
// set the next three attributes on your object to override the defaults
|
2017-03-21 21:29:43 +03:00
|
|
|
browser: null,
|
2003-11-20 12:48:16 +03:00
|
|
|
|
|
|
|
get rootSearchWindow() { return this._root || this.window.content; },
|
|
|
|
set rootSearchWindow(val) { this._root = val; },
|
|
|
|
|
|
|
|
get currentSearchWindow() {
|
|
|
|
if (this._current)
|
|
|
|
return this._current;
|
|
|
|
|
|
|
|
var focusedWindow = this.window.document.commandDispatcher.focusedWindow;
|
|
|
|
if (!focusedWindow || focusedWindow == this.window)
|
|
|
|
focusedWindow = this.window.content;
|
|
|
|
|
|
|
|
return focusedWindow;
|
|
|
|
},
|
|
|
|
set currentSearchWindow(val) { this._current = val; },
|
|
|
|
|
|
|
|
get webBrowserFind() { return this.browser.webBrowserFind; },
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2003-11-20 12:48:16 +03:00
|
|
|
var findInst = this.webBrowserFind;
|
|
|
|
// set up the find to search the focussedWindow, bounded by the content window.
|
|
|
|
var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
|
|
|
|
findInFrames.rootSearchFrame = this.rootSearchWindow;
|
|
|
|
findInFrames.currentSearchFrame = this.currentSearchWindow;
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2003-11-20 12:48:16 +03:00
|
|
|
// always search in frames for now. We could add a checkbox to the dialog for this.
|
|
|
|
findInst.searchFrames = true;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
window,
|
2017-03-21 21:29:43 +03:00
|
|
|
_root: null,
|
|
|
|
_current: null
|
2003-11-20 12:48:16 +03:00
|
|
|
}
|
|
|
|
|
2002-11-03 00:14:22 +03:00
|
|
|
// browser is the <browser> element
|
2005-01-28 19:06:56 +03:00
|
|
|
// rootSearchWindow is the window to constrain the search to (normally window.content)
|
2003-11-20 12:48:16 +03:00
|
|
|
// currentSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
|
2016-12-31 05:47:25 +03:00
|
|
|
function findInPage(findInstData) {
|
2002-11-03 00:14:22 +03:00
|
|
|
// is the dialog up already?
|
|
|
|
if ("findDialog" in window && window.findDialog)
|
|
|
|
window.findDialog.focus();
|
2016-12-31 05:47:25 +03:00
|
|
|
else {
|
2003-11-20 12:48:16 +03:00
|
|
|
findInstData.init();
|
|
|
|
window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInstData);
|
|
|
|
}
|
2002-11-03 00:14:22 +03:00
|
|
|
}
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
function findAgainInPage(findInstData, reverse) {
|
2002-11-03 00:14:22 +03:00
|
|
|
if ("findDialog" in window && window.findDialog)
|
|
|
|
window.findDialog.focus();
|
2016-12-31 05:47:25 +03:00
|
|
|
else {
|
2002-11-03 00:14:22 +03:00
|
|
|
// get the find service, which stores global find state, and init the
|
|
|
|
// nsIWebBrowser find with it. We don't assume that there was a previous
|
|
|
|
// Find that set this up.
|
|
|
|
var findService = Components.classes["@mozilla.org/find/find_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIFindService);
|
|
|
|
|
2003-11-20 12:48:16 +03:00
|
|
|
var searchString = findService.searchString;
|
|
|
|
if (searchString.length == 0) {
|
2002-11-03 00:14:22 +03:00
|
|
|
// no previous find text
|
2003-11-20 12:48:16 +03:00
|
|
|
findInPage(findInstData);
|
2002-11-03 00:14:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-20 12:48:16 +03:00
|
|
|
findInstData.init();
|
|
|
|
var findInst = findInstData.webBrowserFind;
|
|
|
|
findInst.searchString = searchString;
|
|
|
|
findInst.matchCase = findService.matchCase;
|
|
|
|
findInst.wrapFind = findService.wrapFind;
|
|
|
|
findInst.entireWord = findService.entireWord;
|
|
|
|
findInst.findBackwards = findService.findBackwards ^ reverse;
|
|
|
|
|
|
|
|
var found = findInst.findNext();
|
2002-11-03 00:14:22 +03:00
|
|
|
if (!found) {
|
|
|
|
if (!gFindBundle)
|
|
|
|
gFindBundle = document.getElementById("findBundle");
|
2012-03-22 03:52:24 +04:00
|
|
|
|
|
|
|
Services.prompt.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
|
|
|
|
}
|
2002-11-03 00:14:22 +03:00
|
|
|
|
|
|
|
// Reset to normal value, otherwise setting can get changed in find dialog
|
2016-02-04 01:22:33 +03:00
|
|
|
findInst.findBackwards = findService.findBackwards;
|
2002-11-03 00:14:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
function canFindAgainInPage() {
|
2002-11-03 00:14:22 +03:00
|
|
|
var findService = Components.classes["@mozilla.org/find/find_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIFindService);
|
|
|
|
return (findService.searchString.length > 0);
|
|
|
|
}
|
|
|
|
|