Bug 592436 - Allow badging items in the awesomebar [r=mfinkle]

This commit is contained in:
Vivien Nicolas 2010-09-09 16:10:27 +02:00
parent c031823471
commit c562dfaf6a
3 changed files with 141 additions and 33 deletions

View File

@ -75,11 +75,15 @@
</handler>
</handlers>
<content orient="vertical">
<xul:hbox class="autocomplete-item-label" align="top" xbl:inherits="tags, favorite" mousethrough="always">
<xul:hbox class="autocomplete-item-container" align="top" xbl:inherits="favorite" mousethrough="always">
<xul:image xbl:inherits="src"/>
<xul:vbox flex="1">
<xul:label crop="center" xbl:inherits="value"/>
<xul:label class="autocomplete-item-url" xbl:inherits="value=url" crop="center" mousethrough="always"/>
<xul:label class="autocomplete-item-label" crop="center" xbl:inherits="value"/>
<xul:label class="autocomplete-item-url" xbl:inherits="value=url" crop="center"/>
</xul:vbox>
<xul:vbox align="end">
<xul:label class="autocomplete-item-tags" value="" xbl:inherits="value=tags"/>
<xul:label class="autocomplete-item-badge" value="" xbl:inherits="value=badge"/>
</xul:vbox>
</xul:hbox>
</content>
@ -130,6 +134,11 @@
this.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
</field>
<!-- Used by the badges implementation -->
<field name="_badges">[]</field>
<field name="_badgesTimeout">-1</field>
<field name="_eTLDService">Cc["@mozilla.org/network/effective-tld-service;1"].getService(Ci.nsIEffectiveTLDService);</field>
<!-- nsIAutocompleteInput -->
<property name="overrideValue"
readonly="true"
@ -258,7 +267,6 @@
continue;
}
item._empty = false;
// Assign the values
let type = controller.getStyleAt(i);
@ -274,11 +282,18 @@
let url = controller.getValueAt(i);
item.setAttribute("value", title || url);
item.setAttribute("url", url);
// remove the badge only if the url has changed
if (item._empty || item.getAttribute("url") != url) {
item.setAttribute("url", url);
item.removeAttribute("badge");
}
let isBookmark = ((type == "bookmark") || (type == "tag"));
item.setAttribute("favorite", isBookmark);
item.setAttribute("src", controller.getImageAt(i));
item._empty = false;
}
// Show the "no results" or "all bookmarks" entries as needed
@ -286,6 +301,7 @@
// Make sure the list is scrolled to the top
this.scrollToTop();
this._invalidateBadges();
]]></body>
</method>
@ -302,6 +318,7 @@
noResultsItem.removeAttribute("url");
noResultsItem.removeAttribute("src");
noResultsItem.removeAttribute("tags");
noResultsItem.removeAttribute("badge");
}
]]></body>
</method>
@ -328,6 +345,64 @@
]]></body>
</method>
<method name="_getEffectiveHost">
<parameter name="aURI"/>
<body><![CDATA[
let host = null;
try {
host = aURI.host;
return this._eTLDService.getBaseDomainFromHost(host);
} catch (e) {}
return host ? host : aURI.spec;
]]></body>
</method>
<method name="registerBadgeHandler">
<parameter name="aURL"/>
<parameter name="aHandler"/>
<body><![CDATA[
if (!aHandler)
return false;
let effectiveHost = this._getEffectiveHost(Services.io.newURI(aURL, null, null));
this._badges[effectiveHost] = aHandler;
return true;
]]></body>
</method>
<method name="unregisterBagdeHandler">
<parameter name="aURL"/>
<body><![CDATA[
let effectiveHost = this._getEffectiveHost(Services.io.newURI(aURL, null, null));
if (this._badges[effectiveHost])
delete this._badges[effectiveHost];
]]></body>
</method>
<method name="_invalidateBadges">
<body><![CDATA[
window.clearTimeout(this._badgesTimeout);
this._badgesTimeout = window.setTimeout(function(self) {
for (let i = 0; i < self._items.childNodes.length; i++) {
let item = self._items.childNodes[i];
if (!item.hasAttribute("url"))
continue;
let itemHost = self._getEffectiveHost(Services.io.newURI(item.getAttribute("url"), null, null));
for (let badgeHost in self._badges) {
if (itemHost == badgeHost) {
let handler = self._badges[badgeHost];
handler.updateBadge ? handler.updateBadge(item) : handler(item);
break;
}
}
}
}, 300, this);
]]></body>
</method>
<!-- Helpers -->
<field name="_items">
document.getAnonymousElementByAttribute(this,
@ -620,12 +695,15 @@
<binding id="place-item" extends="chrome://browser/content/bindings.xml#place-base">
<content orient="vertical">
<xul:hbox anonid="bookmark-item" class="bookmark-item-label" align="top" flex="1" xbl:inherits="tags" mousethrough="always">
<xul:hbox anonid="bookmark-item" class="bookmark-item-container" align="top" flex="1" mousethrough="always">
<xul:image xbl:inherits="src"/>
<xul:vbox flex="1">
<xul:label crop="center" xbl:inherits="value=title"/>
<xul:label class="bookmark-item-label" crop="center" xbl:inherits="value=title"/>
<xul:label anonid="bookmark-url" class="bookmark-item-url" xbl:inherits="value=uri" crop="center" mousethrough="always"/>
</xul:vbox>
<xul:vbox>
<xul:label class="bookmark-item-tags" xbl:inherits="value=tags"/>
</xul:vbox>
</xul:hbox>
<xul:hbox anonid="bookmark-manage" class="bookmark-manage" hidden="true" flex="1">

View File

@ -2433,7 +2433,6 @@ var ContextCommands = {
}
}
var SharingUI = {
_dialog: null,

View File

@ -674,7 +674,7 @@ placelist[ui="manage"] placeitem[type="folder"] {
background-image: none;
}
placeitem[type="folder"] > .bookmark-item-label > image,
placeitem[type="folder"] > .bookmark-item-container > image,
placeitem[type="folder"] > .bookmark-manage > image {
list-style-image: url(images/folder-32.png);
margin-top: 0;
@ -762,17 +762,21 @@ historylist placeitem:active:not([selected="true"]):not([class="remotetabs-item-
background-color: #8db8d8;
}
.autocomplete-item-label,
.bookmark-item-label {
.autocomplete-item-container,
.bookmark-item-container {
margin: 0;
padding: 0;
}
.autocomplete-item-label,
.bookmark-item-label {
font-size: 24px !important;
font-weight: normal;
-moz-margin-end: 8px;
}
.autocomplete-item-label > image,
.bookmark-item-label > image,
.autocomplete-item-container > image,
.bookmark-item-container > image,
placeitem > .bookmark-manage > image {
width: 32px;
height: 32px;
@ -784,35 +788,24 @@ placeitem > .bookmark-manage > image {
-moz-margin-start: 8px;
}
.autocomplete-item-label > image[src=""],
placeitem[src=""] .bookmark-item-label > image {
.autocomplete-item-container > image[src=""],
placeitem[src=""] .bookmark-item-container > image {
list-style-image: url(chrome://mozapps/skin/places/defaultFavicon.png);
}
.autocomplete-item-label > vbox > label,
.bookmark-item-label > vbox > label {
.autocomplete-item-container > vbox > label,
.bookmark-item-container > vbox > label {
-moz-margin-start: 1px;
}
.autocomplete-item-label[favorite="true"] {
-moz-padding-end: 30px;
.autocomplete-item-container[favorite="true"] {
background: url(images/star-24.png) no-repeat 100% 2px;
}
.autocomplete-item-label[favorite="true"]:-moz-locale-dir(rtl) {
.autocomplete-item-container[favorite="true"]:-moz-locale-dir(rtl) {
background: url(images/star-24.png) no-repeat left 2px;
}
.autocomplete-item-label:not([tags=""]):after,
.bookmark-item-label:not([tags=""]):after {
float: right;
content: attr(tags);
font-size: 18px !important;
font-weight: lighter;
padding-top: 4px;
-moz-margin-start: 8px;
}
.autocomplete-item-url,
.bookmark-item-url {
color: blue;
@ -820,6 +813,44 @@ placeitem[src=""] .bookmark-item-label > image {
-moz-margin-end: 24px;
}
.autocomplete-item-container[favorite="true"] .autocomplete-item-label {
-moz-padding-end: 30px;
}
.autocomplete-item-tags,
.bookmark-item-tags {
content: attr(tags);
font-size: 18px !important;
font-weight: lighter;
margin: 2px 0 4px 0px;
-moz-margin-start: 8px;
-moz-padding-end: 32px;
}
.autocomplete-item-tags[value=""] {
visibility: hidden;
}
.autocomplete-item-badge {
opacity: 1;
-moz-transition: opacity 1s ease;
background-color: #c90707;
border: 1px solid #951919;
-moz-border-radius: 2px;
content: attr(badge);
font-size: 12px !important;
font-weight: bolder;
margin: 4px 0 0 0;
padding: 4px 6px;
color: white;
}
autocompleteresult:not([badge]) .autocomplete-item-badge,
.autocomplete-item-badge[value=""] {
opacity: 0;
-moz-transition: none;
}
/* special "no results", "awesome header row" and "title rows" items */
autocompleteresult[class="history-item-title"],
autocompleteresult[class="remotetabs-item-title"] {
@ -833,8 +864,8 @@ autocompleteresult[class="remotetabs-item-title"] .bookmark-item-url {
display: none;
}
autocompleteresult[class="history-item-title"] .bookmark-item-label,
autocompleteresult[class="remotetabs-item-title"] .bookmark-item-label {
autocompleteresult[class="history-item-title"] .bookmark-item-container,
autocompleteresult[class="remotetabs-item-title"] .bookmark-item-container {
font-size: 24px !important;
}
@ -852,7 +883,7 @@ autocompleteresult.noresults:active {
background-color: white;
}
autocompleteresult.noresults > .autocomplete-item-label {
autocompleteresult.noresults > .autocomplete-item-container {
text-align: center;
color: grey;
}