зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1174036 - Handle dynamically-removed textareas gracefully. r=mikedeboer r=ehsan
Also, flush layout when starting a find in order to avoid racing with textarea-hiding notifications and maintain JS type correctness when objects are passed over IPC.
This commit is contained in:
Родитель
97cb9159fa
Коммит
99310215c0
|
@ -315,6 +315,10 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// There could be unflushed notifications which hide textareas or other
|
||||
// elements that we don't want to find text in.
|
||||
presShell->FlushPendingNotifications(Flush_Layout);
|
||||
|
||||
RefPtr<nsPresContext> presContext = presShell->GetPresContext();
|
||||
|
||||
if (!presContext)
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["Finder","GetClipboardSearchString"];
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cu = Components.utils;
|
||||
const { interfaces: Ci, classes: Cc, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Geometry.jsm");
|
||||
|
@ -519,11 +517,16 @@ Finder.prototype = {
|
|||
let nodes = win.document.querySelectorAll("input, textarea");
|
||||
for (let node of nodes) {
|
||||
if (node instanceof Ci.nsIDOMNSEditableElement && node.editor) {
|
||||
try {
|
||||
let sc = node.editor.selectionController;
|
||||
selection = sc.getSelection(Ci.nsISelectionController.SELECTION_NORMAL);
|
||||
if (selection.rangeCount && !selection.isCollapsed) {
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
// If this textarea is hidden, then its selection controller might
|
||||
// not be intialized. Ignore the failure.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,15 +6,17 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["RemoteFinder", "RemoteFinderListener"];
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cu = Components.utils;
|
||||
const { interfaces: Ci, classes: Cc, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Geometry.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "GetClipboardSearchString",
|
||||
() => Cu.import("resource://gre/modules/Finder.jsm", {}).GetClipboardSearchString
|
||||
);
|
||||
XPCOMUtils.defineLazyGetter(this, "Rect",
|
||||
() => Cu.import("resource://gre/modules/Geometry.jsm", {}).Rect
|
||||
);
|
||||
|
||||
function RemoteFinder(browser) {
|
||||
this._listeners = new Set();
|
||||
|
@ -62,6 +64,10 @@ RemoteFinder.prototype = {
|
|||
switch (aMessage.name) {
|
||||
case "Finder:Result":
|
||||
this._searchString = aMessage.data.searchString;
|
||||
// The rect stops being a Geometry.jsm:Rect over IPC.
|
||||
if (aMessage.data.rect) {
|
||||
aMessage.data.rect = Rect.fromRect(aMessage.data.rect);
|
||||
}
|
||||
callback = "onFindResult";
|
||||
params = [ aMessage.data ];
|
||||
break;
|
||||
|
|
|
@ -25,6 +25,7 @@ support-files =
|
|||
[browser_Battery.js]
|
||||
[browser_Deprecated.js]
|
||||
[browser_Finder.js]
|
||||
[browser_Finder_hidden_textarea.js]
|
||||
[browser_Geometry.js]
|
||||
[browser_InlineSpellChecker.js]
|
||||
[browser_WebNavigation.js]
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* 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/. */
|
||||
add_task(function* test_bug1174036() {
|
||||
const URI =
|
||||
"<body><textarea>e1</textarea><textarea>e2</textarea><textarea>e3</textarea></body>";
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html;charset=utf-8," + encodeURIComponent(URI) },
|
||||
function* (browser) {
|
||||
// Hide the first textarea.
|
||||
yield ContentTask.spawn(browser, null, function() {
|
||||
content.document.getElementsByTagName("textarea")[0].style.display = "none";
|
||||
});
|
||||
|
||||
let finder = browser.finder;
|
||||
let listener = {
|
||||
onFindResult: function () {
|
||||
ok(false, "callback wasn't replaced");
|
||||
}
|
||||
};
|
||||
finder.addResultListener(listener);
|
||||
|
||||
function waitForFind() {
|
||||
return new Promise(resolve => {
|
||||
listener.onFindResult = resolve;
|
||||
})
|
||||
}
|
||||
|
||||
// Find the first 'e' (which should be in the second textarea).
|
||||
let promiseFind = waitForFind();
|
||||
finder.fastFind("e", false, false);
|
||||
let findResult = yield promiseFind;
|
||||
is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, "find first string");
|
||||
|
||||
let firstRect = findResult.rect;
|
||||
|
||||
// Find the second 'e' (in the third textarea).
|
||||
promiseFind = waitForFind();
|
||||
finder.findAgain(false, false, false);
|
||||
findResult = yield promiseFind;
|
||||
is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, "find second string");
|
||||
ok(!findResult.rect.equals(firstRect), "found new string");
|
||||
|
||||
// Ensure that we properly wrap to the second textarea.
|
||||
promiseFind = waitForFind();
|
||||
finder.findAgain(false, false, false);
|
||||
findResult = yield promiseFind;
|
||||
is(findResult.result, Ci.nsITypeAheadFind.FIND_WRAPPED, "wrapped to first string");
|
||||
ok(findResult.rect.equals(firstRect), "wrapped to original string");
|
||||
|
||||
finder.removeResultListener(listener);
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче