зеркало из https://github.com/mozilla/pjs.git
Bug 127589: when switching tabs with find dialog open, update dialog's internal state so it's "attached" to the focused tab. r=Jan, sr=peterv
This commit is contained in:
Родитель
e017897f19
Коммит
014a22be72
|
@ -375,15 +375,23 @@ function UpdateBackForwardButtons()
|
|||
forwardBroadcaster.setAttribute("disabled", !forwardDisabled);
|
||||
}
|
||||
|
||||
var gFindInstData;
|
||||
function getFindInstData()
|
||||
{
|
||||
if (!gFindInstData) {
|
||||
gFindInstData = new nsFindInstData();
|
||||
gFindInstData.browser = helpBrowser;
|
||||
// defaults for rootSearchWindow and currentSearchWindow are fine here
|
||||
}
|
||||
return gFindInstData;
|
||||
}
|
||||
|
||||
function find(again, reverse)
|
||||
{
|
||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||
if (!focusedWindow || focusedWindow == window)
|
||||
focusedWindow = window._content;
|
||||
if (again)
|
||||
findAgainInPage(helpBrowser, window._content, focusedWindow, reverse);
|
||||
findAgainInPage(getFindInstData(), reverse);
|
||||
else
|
||||
findInPage(helpBrowser, window._content, focusedWindow)
|
||||
findInPage(getFindInstData())
|
||||
}
|
||||
|
||||
function getMarkupDocumentViewer()
|
||||
|
|
|
@ -2222,6 +2222,8 @@ function cmdCloseTab (e)
|
|||
source2View.removeSourceTabAtIndex (e.index);
|
||||
}
|
||||
|
||||
var gFindInstData;
|
||||
|
||||
function cmdFindString (e)
|
||||
{
|
||||
var source2View = console.views.source2;
|
||||
|
@ -2233,7 +2235,12 @@ function cmdFindString (e)
|
|||
return;
|
||||
|
||||
var browser = source2View.sourceTabList[index].iframe;
|
||||
findInPage (browser, browser.contentWindow, browser.contentWindow);
|
||||
if (!gFindInstData)
|
||||
gFindInstData = new nsFindInstData();
|
||||
gFindInstData.browser = browser;
|
||||
gFindInstData.rootSearchWindow = browser.contentWindow;
|
||||
gFindInstData.currentSearchWindow = browser.contentWindow;
|
||||
findInPage(gFindInstData);
|
||||
}
|
||||
|
||||
function cmdReloadTab (e)
|
||||
|
|
|
@ -1260,18 +1260,26 @@ function MsgViewPageSource()
|
|||
ViewPageSource(messages);
|
||||
}
|
||||
|
||||
var gFindInstData;
|
||||
function getFindInstData()
|
||||
{
|
||||
if (!gFindInstData) {
|
||||
gFindInstData = new nsFindInstData();
|
||||
gFindInstData.browser = getMessageBrowser();
|
||||
gFindInstData.rootSearchWindow = window.top.content;
|
||||
gFindInstData.currentSearchWindow = window.top.content;
|
||||
}
|
||||
return gFindInstData;
|
||||
}
|
||||
|
||||
function MsgFind()
|
||||
{
|
||||
var contentWindow = window.top._content;
|
||||
|
||||
// from utilityOverlay.js
|
||||
findInPage(getMessageBrowser(), contentWindow, contentWindow)
|
||||
findInPage(getFindInstData());
|
||||
}
|
||||
|
||||
function MsgFindAgain(reverse)
|
||||
{
|
||||
var contentWindow = window.top._content;
|
||||
findAgainInPage(getMessageBrowser(), contentWindow, contentWindow, reverse)
|
||||
findAgainInPage(getFindInstData(), reverse);
|
||||
}
|
||||
|
||||
function MsgCanFindAgain()
|
||||
|
|
|
@ -299,22 +299,25 @@ function BrowserSetForcedDetector(doReload)
|
|||
BrowserReloadWithFlags(nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
||||
}
|
||||
|
||||
var gFindInstData;
|
||||
function getFindInstData()
|
||||
{
|
||||
if (!gFindInstData) {
|
||||
gFindInstData = new nsFindInstData();
|
||||
gFindInstData.browser = getBrowser();
|
||||
// defaults for rootSearchWindow and currentSearchWindow are fine here
|
||||
}
|
||||
return gFindInstData;
|
||||
}
|
||||
|
||||
function BrowserFind()
|
||||
{
|
||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||
if (!focusedWindow || focusedWindow == window)
|
||||
focusedWindow = window._content;
|
||||
|
||||
findInPage(getBrowser(), window._content, focusedWindow)
|
||||
findInPage(getFindInstData());
|
||||
}
|
||||
|
||||
function BrowserFindAgain(reverse)
|
||||
{
|
||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||
if (!focusedWindow || focusedWindow == window)
|
||||
focusedWindow = window._content;
|
||||
|
||||
findAgainInPage(getBrowser(), window._content, focusedWindow, reverse)
|
||||
findAgainInPage(getFindInstData(), reverse);
|
||||
}
|
||||
|
||||
function BrowserCanFindAgain()
|
||||
|
|
|
@ -40,61 +40,88 @@
|
|||
var gPromptService;
|
||||
var gFindBundle;
|
||||
|
||||
function nsFindInstData() {}
|
||||
nsFindInstData.prototype =
|
||||
{
|
||||
// set the next three attributes on your object to override the defaults
|
||||
browser : null,
|
||||
|
||||
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; },
|
||||
|
||||
init : function() {
|
||||
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;
|
||||
|
||||
// always search in frames for now. We could add a checkbox to the dialog for this.
|
||||
findInst.searchFrames = true;
|
||||
},
|
||||
|
||||
window : window,
|
||||
_root : null,
|
||||
_current : null
|
||||
}
|
||||
|
||||
// browser is the <browser> element
|
||||
// rootSearchWindow is the window to constrain the search to (normally window._content)
|
||||
// startSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
|
||||
function findInPage(browser, rootSearchWindow, startSearchWindow)
|
||||
// currentSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
|
||||
function findInPage(findInstData)
|
||||
{
|
||||
var findInst = browser.webBrowserFind;
|
||||
// set up the find to search the focussedWindow, bounded by the content window.
|
||||
var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
|
||||
findInFrames.rootSearchFrame = rootSearchWindow;
|
||||
findInFrames.currentSearchFrame = startSearchWindow;
|
||||
|
||||
// always search in frames for now. We could add a checkbox to the dialog for this.
|
||||
findInst.searchFrames = true;
|
||||
|
||||
// is the dialog up already?
|
||||
if ("findDialog" in window && window.findDialog)
|
||||
window.findDialog.focus();
|
||||
else
|
||||
window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInst);
|
||||
{
|
||||
findInstData.init();
|
||||
window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInstData);
|
||||
}
|
||||
}
|
||||
|
||||
function findAgainInPage(browser, rootSearchWindow, startSearchWindow, reverse)
|
||||
function findAgainInPage(findInstData, reverse)
|
||||
{
|
||||
if ("findDialog" in window && window.findDialog)
|
||||
window.findDialog.focus();
|
||||
else
|
||||
{
|
||||
var findInst = browser.webBrowserFind;
|
||||
// set up the find to search the focussedWindow, bounded by the content window.
|
||||
var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
|
||||
findInFrames.rootSearchFrame = rootSearchWindow;
|
||||
findInFrames.currentSearchFrame = startSearchWindow;
|
||||
|
||||
// always search in frames for now. We could add a checkbox to the dialog for this.
|
||||
findInst.searchFrames = true;
|
||||
|
||||
// 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);
|
||||
findInst.searchString = findService.searchString;
|
||||
|
||||
var searchString = findService.searchString;
|
||||
if (searchString.length == 0) {
|
||||
// no previous find text
|
||||
findInPage(findInstData);
|
||||
return;
|
||||
}
|
||||
|
||||
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 = false;
|
||||
if (findInst.searchString.length == 0) {
|
||||
// no previous find text
|
||||
findInPage(browser, rootSearchWindow, startSearchWindow);
|
||||
return;
|
||||
}
|
||||
|
||||
found = findInst.findNext();
|
||||
var found = findInst.findNext();
|
||||
if (!found) {
|
||||
if (!gPromptService)
|
||||
gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
var dialog; // Quick access to document/form elements.
|
||||
var gFindInst; // nsIWebBrowserFind that we're going to use
|
||||
var gFindInstData; // use this to update the find inst data
|
||||
|
||||
function initDialogObject()
|
||||
{
|
||||
|
@ -86,10 +87,15 @@ function onLoad()
|
|||
dialog.find.accessKey = document.getElementById("fBLT").getAttribute("accesskey");
|
||||
|
||||
// get the find instance
|
||||
var finder = window.arguments[0];
|
||||
// If the dialog was opened from window.find(), findInst will be an
|
||||
// nsISupports interface, so QueryInterface anyway to nsIWebBrowserFind.
|
||||
gFindInst = finder.QueryInterface(Components.interfaces.nsIWebBrowserFind);
|
||||
var arg0 = window.arguments[0];
|
||||
if (arg0 instanceof window.opener.nsFindInstData) {
|
||||
gFindInstData = arg0;
|
||||
gFindInst = gFindInstData.webBrowserFind;
|
||||
} else {
|
||||
// If the dialog was opened from window.find(), findInst will be an
|
||||
// nsISupports interface, so QueryInterface anyway to nsIWebBrowserFind.
|
||||
gFindInst = arg0.QueryInterface(Components.interfaces.nsIWebBrowserFind);
|
||||
}
|
||||
|
||||
fillDialog();
|
||||
doEnabling();
|
||||
|
@ -106,6 +112,11 @@ function onUnload()
|
|||
|
||||
function onAccept()
|
||||
{
|
||||
if (gFindInstData && gFindInst != gFindInstData.webBrowserFind) {
|
||||
gFindInstData.init();
|
||||
gFindInst = gFindInstData.webBrowserFind;
|
||||
}
|
||||
|
||||
// Transfer dialog contents to the find service.
|
||||
saveFindData();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче