Bug 1294502 - Move AutoCompletePopup implementation for content to browser-content.js so that non-e10s can use it in a later patch. r=MattN

MozReview-Commit-ID: 2fB4M3lqpLK
This commit is contained in:
Mike Conley
2016-07-28 14:18:50 -04:00
parent 515277b6c7
commit 98c0a7fdf7
4 changed files with 94 additions and 89 deletions

View File

@@ -588,82 +588,6 @@ addMessageListener("NetworkPrioritizer:SetPriority", (msg) => {
loadGroup.priority = msg.data.priority;
});
var AutoCompletePopup = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]),
init: function() {
// Hook up the form fill autocomplete controller.
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
.getService(Ci.nsIFormFillController);
controller.attachToBrowser(docShell, this.QueryInterface(Ci.nsIAutoCompletePopup));
this._input = null;
this._popupOpen = false;
addMessageListener("FormAutoComplete:HandleEnter", message => {
this.selectedIndex = message.data.selectedIndex;
let controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
getService(Components.interfaces.nsIAutoCompleteController);
controller.handleEnter(message.data.isPopupSelection);
});
addEventListener("unload", function() {
AutoCompletePopup.destroy();
});
},
destroy: function() {
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
.getService(Ci.nsIFormFillController);
controller.detachFromBrowser(docShell);
},
get input () { return this._input; },
get overrideValue () { return null; },
set selectedIndex (index) { },
get selectedIndex () {
// selectedIndex getter must be synchronous because we need the
// correct value when the controller is in controller::HandleEnter.
// We can't easily just let the parent inform us the new value every
// time it changes because not every action that can change the
// selectedIndex is trivial to catch (e.g. moving the mouse over the
// list).
return sendSyncMessage("FormAutoComplete:GetSelectedIndex", {});
},
get popupOpen () {
return this._popupOpen;
},
openAutocompletePopup: function (input, element) {
if (!this._popupOpen) {
// The search itself normally opens the popup itself, but in some cases,
// nsAutoCompleteController tries to use cached results so notify our
// popup to reuse the last results.
sendAsyncMessage("FormAutoComplete:MaybeOpenPopup", {});
}
this._input = input;
this._popupOpen = true;
},
closePopup: function () {
this._popupOpen = false;
sendAsyncMessage("FormAutoComplete:ClosePopup", {});
},
invalidate: function () {
},
selectBy: function(reverse, page) {
this._index = sendSyncMessage("FormAutoComplete:SelectBy", {
reverse: reverse,
page: page
});
}
}
addMessageListener("InPermitUnload", msg => {
let inPermitUnload = docShell.contentViewer && docShell.contentViewer.inPermitUnload;
sendAsyncMessage("InPermitUnload", {id: msg.data.id, inPermitUnload});
@@ -686,9 +610,3 @@ var outerWindowID = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
sendAsyncMessage("Browser:Init", {outerWindowID: outerWindowID});
addMessageListener("Browser:InitReceived", function onInitReceived(msg) {
removeMessageListener("Browser:InitReceived", onInitReceived);
if (msg.data.initPopup) {
AutoCompletePopup.init();
}
});

View File

@@ -1382,3 +1382,93 @@ addEventListener("MozApplicationManifest", function(e) {
sendAsyncMessage("MozApplicationManifest", info);
}, false);
let AutoCompletePopup = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]),
_connected: false,
init: function() {
// We need to wait for a content viewer to be available
// before we can attach our AutoCompletePopup handler,
// since nsFormFillController assumes one will exist
// when we call attachToBrowser.
let onDCL = () => {
removeEventListener("DOMContentLoaded", onDCL);
// Hook up the form fill autocomplete controller.
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
.getService(Ci.nsIFormFillController);
controller.attachToBrowser(docShell,
this.QueryInterface(Ci.nsIAutoCompletePopup));
this._connected = true;
};
addEventListener("DOMContentLoaded", onDCL);
this._input = null;
this._popupOpen = false;
addMessageListener("FormAutoComplete:HandleEnter", message => {
this.selectedIndex = message.data.selectedIndex;
let controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
getService(Components.interfaces.nsIAutoCompleteController);
controller.handleEnter(message.data.isPopupSelection);
});
addEventListener("unload", function() {
AutoCompletePopup.destroy();
});
},
destroy: function() {
if (this._connected) {
let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
.getService(Ci.nsIFormFillController);
controller.detachFromBrowser(docShell);
this._connected = false;
}
},
get input () { return this._input; },
get overrideValue () { return null; },
set selectedIndex (index) { },
get selectedIndex () {
// selectedIndex getter must be synchronous because we need the
// correct value when the controller is in controller::HandleEnter.
// We can't easily just let the parent inform us the new value every
// time it changes because not every action that can change the
// selectedIndex is trivial to catch (e.g. moving the mouse over the
// list).
return sendSyncMessage("FormAutoComplete:GetSelectedIndex", {});
},
get popupOpen () {
return this._popupOpen;
},
openAutocompletePopup: function (input, element) {
if (!this._popupOpen) {
// The search itself normally opens the popup itself, but in some cases,
// nsAutoCompleteController tries to use cached results so notify our
// popup to reuse the last results.
sendAsyncMessage("FormAutoComplete:MaybeOpenPopup", {});
}
this._input = input;
this._popupOpen = true;
},
closePopup: function () {
this._popupOpen = false;
sendAsyncMessage("FormAutoComplete:ClosePopup", {});
},
invalidate: function () {
},
selectBy: function(reverse, page) {
this._index = sendSyncMessage("FormAutoComplete:SelectBy", {
reverse: reverse,
page: page
});
}
}
AutoCompletePopup.init();

View File

@@ -263,6 +263,10 @@
]]></getter>
</property>
<property name="autoCompletePopup"
onget="return document.getElementById(this.getAttribute('autocompletepopup'))"
readonly="true"/>
<property name="docShellIsActive">
<getter>
<![CDATA[

View File

@@ -243,10 +243,6 @@
]]></getter>
</property>
<property name="autoCompletePopup"
onget="return document.getElementById(this.getAttribute('autocompletepopup'))"
readonly="true"/>
<property name="docShellIsActive">
<getter>
<![CDATA[
@@ -452,9 +448,6 @@
switch (aMessage.name) {
case "Browser:Init":
this._outerWindowID = data.outerWindowID;
this.messageManager.sendAsyncMessage("Browser:InitReceived", {
initPopup: this.autoCompletePopup != null,
});
break;
case "DOMTitleChanged":
this._contentTitle = data.title;