Bug 1218351 - (e10s) Don't lose initial typed characters when opening the findbar; r=mikedeboer

Moved some of the routine from content to chrome process. The drawback is that now the content process must wait for a response on every keypress.

--HG--
extra : transplant_source : f%99%83H%91%C6B%3FJ%DC%29s%AF%E1%BA%E6GO%0B%17
This commit is contained in:
Luis Miguel [:quicksaver] 2015-11-04 15:26:40 +00:00
Родитель 21debe5b31
Коммит 8fd6fc6676
5 изменённых файлов: 78 добавлений и 22 удалений

Просмотреть файл

@ -32,6 +32,8 @@ Cc["@mozilla.org/globalmessagemanager;1"]
XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
"resource:///modules/E10SUtils.jsm");
var gSendCharCount = 0;
this.BrowserTestUtils = {
/**
* Loads a page in a new tab, executes a Task and closes the tab.
@ -663,12 +665,21 @@ this.BrowserTestUtils = {
*/
sendChar(char, browser) {
return new Promise(resolve => {
let seq = ++gSendCharCount;
let mm = browser.messageManager;
mm.addMessageListener("Test:SendCharDone", function charMsg(message) {
if (message.data.seq != seq)
return;
mm.removeMessageListener("Test:SendCharDone", charMsg);
resolve(message.data.sendCharResult);
});
mm.sendAsyncMessage("Test:SendChar", { char: char });
mm.sendAsyncMessage("Test:SendChar", {
char: char,
seq: seq
});
});
}
};

Просмотреть файл

@ -53,5 +53,8 @@ addMessageListener("Test:SynthesizeMouse", (message) => {
addMessageListener("Test:SendChar", message => {
let result = EventUtils.sendChar(message.data.char, content);
sendAsyncMessage("Test:SendCharDone", { sendCharResult: result });
sendAsyncMessage("Test:SendCharDone", {
sendCharResult: result,
seq: message.data.seq
});
});

Просмотреть файл

@ -580,15 +580,10 @@ var FindBar = {
FIND_NORMAL: 0,
FIND_TYPEAHEAD: 1,
FIND_LINKS: 2,
FAYT_LINKS_KEY: "'".charCodeAt(0),
FAYT_TEXT_KEY: "/".charCodeAt(0),
_findMode: 0,
_findAsYouType: false,
init() {
this._findAsYouType =
Services.prefs.getBoolPref("accessibility.typeaheadfind");
addMessageListener("Findbar:UpdateState", this);
Services.els.addSystemEventListener(global, "keypress", this, false);
Services.els.addSystemEventListener(global, "mouseup", this, false);
@ -598,7 +593,6 @@ var FindBar = {
switch (msg.name) {
case "Findbar:UpdateState":
this._findMode = msg.data.findMode;
this._findAsYouType = msg.data.findAsYouType;
break;
}
},
@ -632,16 +626,9 @@ var FindBar = {
if (event.ctrlKey || event.altKey || event.metaKey || event.defaultPrevented) {
return;
}
// Not interested in random keypresses most of the time:
if (this._findMode == this.FIND_NORMAL && !this._findAsYouType &&
event.charCode != this.FAYT_LINKS_KEY && event.charCode != this.FAYT_TEXT_KEY) {
return;
}
// Check the focused element etc.
if (!this._shouldFastFind()) {
return;
}
let shouldFastFind = this._shouldFastFind();
let fakeEvent = {};
for (let k in event) {
@ -650,7 +637,10 @@ var FindBar = {
}
}
// sendSyncMessage returns an array of the responses from all listeners
let rv = sendSyncMessage("Findbar:Keypress", fakeEvent);
let rv = sendSyncMessage("Findbar:Keypress", {
fakeEvent: fakeEvent,
shouldFastFind: shouldFastFind
});
if (rv.indexOf(false) !== -1) {
event.preventDefault();
return false;

Просмотреть файл

@ -158,6 +158,45 @@ add_task(function * test_reinitialization_at_remoteness_change() {
yield BrowserTestUtils.removeTab(tab);
});
/**
* Ensure that the initial typed characters aren't lost immediately after
* opening the find bar.
*/
add_task(function* () {
// This test only makes sence in e10s evironment.
if (!gMultiProcessBrowser) {
info("Skipping this test because of non-e10s environment.");
return true;
}
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE_URI);
let browser = tab.linkedBrowser;
ok(!gFindBarInitialized, "findbar isn't initialized yet");
let findBar = gFindBar;
let initialValue = findBar._findField.value;
EventUtils.synthesizeKey("f", { accelKey: true }, window);
let promises = [
BrowserTestUtils.sendChar("a", browser),
BrowserTestUtils.sendChar("b", browser),
BrowserTestUtils.sendChar("c", browser)
];
isnot(document.activeElement, findBar._findField.inputField,
"findbar is not yet focused");
is(findBar._findField.value, initialValue, "still has initial find query");
yield Promise.all(promises);
is(document.activeElement, findBar._findField.inputField,
"findbar is now focused");
is(findBar._findField.value, "abc", "abc fully entered as find query");
yield BrowserTestUtils.removeTab(tab);
});
function promiseFindFinished(searchText, highlightOn) {
let deferred = Promise.defer();

Просмотреть файл

@ -285,7 +285,7 @@
this._browser = val;
if (this._browser) {
// Need to do this in case FAYT
// Need to do this to ensure the correct initial state.
this._updateBrowserWithState();
this._browser.messageManager.addMessageListener("Findbar:Keypress", this);
this._browser.messageManager.addMessageListener("Findbar:Mouseup", this);
@ -320,7 +320,6 @@
switch (aPrefName) {
case "accessibility.typeaheadfind":
this._self._findAsYouType = prefsvc.getBoolPref(aPrefName);
this._self._updateBrowserWithState();
break;
case "accessibility.typeaheadfind.linksonly":
this._self._typeAheadLinksOnly = prefsvc.getBoolPref(aPrefName);
@ -741,10 +740,21 @@
on the real event. -->
<method name="_onBrowserKeypress">
<parameter name="aFakeEvent"/>
<parameter name="aShouldFastFind"/>
<body><![CDATA[
const FAYT_LINKS_KEY = "'";
const FAYT_TEXT_KEY = "/";
// Fast keypresses can stack up when the content process is slow or
// hangs when in e10s mode. We make sure the findbar isn't 'opened'
// several times in a row, because then the find query is selected
// each time, losing characters typed initially.
let inputField = this._findField.inputField;
if (!this.hidden && document.activeElement == inputField) {
this._dispatchKeypressEvent(inputField, aFakeEvent);
return false;
}
if (this._findMode != this.FIND_NORMAL && this._quickFindTimeout) {
if (!aFakeEvent.charCode)
return true;
@ -755,6 +765,9 @@
return false;
}
if (!aShouldFastFind)
return true;
let key = aFakeEvent.charCode ? String.fromCharCode(aFakeEvent.charCode) : null;
let manualstartFAYT = (key == FAYT_LINKS_KEY || key == FAYT_TEXT_KEY);
let autostartFAYT = !manualstartFAYT && this._findAsYouType &&
@ -797,7 +810,8 @@
break;
case "Findbar:Keypress":
return this._onBrowserKeypress(aMessage.data);
return this._onBrowserKeypress(aMessage.data.fakeEvent,
aMessage.data.shouldFastFind);
}
]]></body>
</method>
@ -806,8 +820,7 @@
<body><![CDATA[
if (this._browser && this._browser.messageManager) {
this._browser.messageManager.sendAsyncMessage("Findbar:UpdateState", {
findMode: this._findMode,
findAsYouType: this._findAsYouType,
findMode: this._findMode
});
}
]]></body>