зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1326138 - Add a new profile item binding. r=MattN
MozReview-Commit-ID: KzbnQteM1pY --HG-- extra : rebase_source : 51db4a0200b9aa2ad82082e8947e1f398cfa0795
This commit is contained in:
Родитель
fdac0321d0
Коммит
26a5f8796a
|
@ -7,6 +7,8 @@
|
|||
/* exported startup, shutdown, install, uninstall */
|
||||
|
||||
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
|
||||
const STYLESHEET_URI = "chrome://formautofill/content/formautofill.css";
|
||||
const CACHED_STYLESHEETS = [];
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
@ -14,6 +16,25 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent",
|
||||
"resource://formautofill/FormAutofillParent.jsm");
|
||||
|
||||
let windowListener = {
|
||||
onOpenWindow: function(aWindow) {
|
||||
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
|
||||
|
||||
domWindow.addEventListener("load", function onWindowLoaded() {
|
||||
insertStyleSheet(domWindow, STYLESHEET_URI);
|
||||
}, { once: true });
|
||||
}
|
||||
};
|
||||
|
||||
function insertStyleSheet(domWindow, url) {
|
||||
let doc = domWindow.document;
|
||||
let styleSheetAttr = `href="${url}" type="text/css"`;
|
||||
let styleSheet = doc.createProcessingInstruction("xml-stylesheet", styleSheetAttr);
|
||||
|
||||
doc.insertBefore(styleSheet, doc.documentElement);
|
||||
CACHED_STYLESHEETS.push(styleSheet);
|
||||
}
|
||||
|
||||
function startup() {
|
||||
// Besides this pref, we'll need dom.forms.autocomplete.experimental enabled
|
||||
// as well to make sure form autocomplete works correctly.
|
||||
|
@ -22,10 +43,29 @@ function startup() {
|
|||
}
|
||||
|
||||
let parent = new FormAutofillParent();
|
||||
let enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||
// Load stylesheet to already opened windows
|
||||
while(enumerator.hasMoreElements()) {
|
||||
let win = enumerator.getNext();
|
||||
let domWindow = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
|
||||
|
||||
insertStyleSheet(domWindow, STYLESHEET_URI);
|
||||
}
|
||||
|
||||
Services.wm.addListener(windowListener);
|
||||
|
||||
parent.init();
|
||||
Services.mm.loadFrameScript("chrome://formautofill/content/FormAutofillContent.js", true);
|
||||
}
|
||||
|
||||
function shutdown() {}
|
||||
function shutdown() {
|
||||
Services.wm.removeListener(windowListener);
|
||||
|
||||
let styleNode;
|
||||
while(styleNode = CACHED_STYLESHEETS.pop()) {
|
||||
styleNode.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function install() {}
|
||||
function uninstall() {}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/* 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/. */
|
||||
|
||||
.autocomplete-richlistitem[originaltype="autofill-profile"] {
|
||||
-moz-binding: url("chrome://formautofill/content/formautofill.xml#autocomplete-profile-listitem");
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<bindings id="formautofillBindings"
|
||||
xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:xbl="http://www.mozilla.org/xbl">
|
||||
|
||||
<binding id="autocomplete-profile-listitem" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
|
||||
<xbl:content xmlns="http://www.w3.org/1999/xhtml">
|
||||
<div anonid="profile-item-box" class="profile-item-box">
|
||||
<div class="profile-label-col profile-item-col">
|
||||
<span anonid="profile-label" class="profile-label"></span>
|
||||
</div>
|
||||
<div class="profile-comment-col profile-item-col">
|
||||
<span anonid="profile-comment" class="profile-comment"></span>
|
||||
</div>
|
||||
</div>
|
||||
</xbl:content>
|
||||
|
||||
<implementation implements="nsIDOMXULSelectControlItemElement">
|
||||
<constructor>
|
||||
<![CDATA[
|
||||
this._itemBox = document.getAnonymousElementByAttribute(
|
||||
this, "anonid", "profile-item-box"
|
||||
);
|
||||
this._label = document.getAnonymousElementByAttribute(
|
||||
this, "anonid", "profile-label"
|
||||
);
|
||||
this._comment = document.getAnonymousElementByAttribute(
|
||||
this, "anonid", "profile-comment"
|
||||
);
|
||||
|
||||
this._adjustAcItem();
|
||||
]]>
|
||||
</constructor>
|
||||
|
||||
<method name="_cleanup">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._itemBox.removeAttribute("size");
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="_onOverflow">
|
||||
<body></body>
|
||||
</method>
|
||||
|
||||
<method name="_onUnderflow">
|
||||
<body></body>
|
||||
</method>
|
||||
|
||||
<method name="_adjustAcItem">
|
||||
<body>
|
||||
<![CDATA[
|
||||
let outerBoxRect = this.parentNode.getBoundingClientRect();
|
||||
let value = this.getAttribute("ac-value");
|
||||
let comment = this.getAttribute("ac-comment");
|
||||
|
||||
this._comment.textContent = comment;
|
||||
this._label.textContent = value;
|
||||
|
||||
// Use two-lines layout when width is smaller than 150px
|
||||
if (outerBoxRect.width <= 150) {
|
||||
this._itemBox.setAttribute("size", "small");
|
||||
} else {
|
||||
this._itemBox.removeAttribute("size");
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
</bindings>
|
Загрузка…
Ссылка в новой задаче