Bug 605601 - when there are no (or few) awesomeresults, add search providers to list [r=mfinkle]

This commit is contained in:
Wesley Johnston 2010-11-03 11:41:00 -04:00
Родитель 8c5b385758
Коммит 4c354be29c
5 изменённых файлов: 73 добавлений и 21 удалений

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

@ -261,6 +261,7 @@ pref("browser.urlbar.restrict.bookmark", "*");
pref("browser.urlbar.restrict.tag", "+");
pref("browser.urlbar.match.title", "#");
pref("browser.urlbar.match.url", "@");
pref("browser.urlbar.autocomplete.search_threshold", 5);
pref("browser.history.grouping", "day");
pref("browser.history.showSessions", false);
pref("browser.sessionhistory.max_entries", 50);

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

@ -146,11 +146,11 @@
</handler>
</handlers>
<content orient="vertical">
<xul:hbox class="autocomplete-item-container" align="top" xbl:inherits="favorite,remote" mousethrough="always">
<xul:hbox class="autocomplete-item-container" align="top" xbl:inherits="favorite,remote,search" mousethrough="always">
<xul:image xbl:inherits="src"/>
<xul:vbox flex="1">
<xul:label class="autocomplete-item-label" crop="center" xbl:inherits="value"/>
<xul:label class="autocomplete-item-url" xbl:inherits="value=url" crop="center"/>
<xul:label class="autocomplete-item-subtitle" xbl:inherits="value=subtitle" crop="center"/>
</xul:vbox>
<xul:vbox align="end">
<xul:label class="autocomplete-item-tags" value="" xbl:inherits="value=tags"/>
@ -314,6 +314,9 @@
let matchCount = this._matchCount;
let children = items.childNodes;
let iterCount = Math.max(children.length, matchCount);
let searchSubtitle = Elements.browserBundle.stringBundle.formatStringFromName("opensearch.searchFor", [searchString], 1);
for (let i = 0; i < iterCount; ++i) {
let item = children.item(i);
@ -353,13 +356,20 @@
// remove the badge only if the url has changed
if (item._empty || item.getAttribute("url") != url) {
item.setAttribute("url", url);
item.setAttribute("subtitle", url);
item.removeAttribute("badge");
item.removeAttribute("remote");
item.removeAttribute("search");
}
let isBookmark = ((type == "bookmark") || (type == "tag"));
item.setAttribute("favorite", isBookmark);
item.setAttribute("src", controller.getImageAt(i));
if (type=="search") {
item.setAttribute("search", true);
item.setAttribute("subtitle", searchSubtitle);
}
item._empty = false;
}
@ -388,6 +398,8 @@
noResultsItem.removeAttribute("tags");
noResultsItem.removeAttribute("badge");
noResultsItem.removeAttribute("remote");
noResultsItem.removeAttribute("search");
noResultsItem.removeAttribute("subtitle");
}
]]></body>
</method>

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

@ -55,6 +55,9 @@ const MODE_TRUNCATE = 0x20;
// file is modified.
const CACHE_VERSION = 1;
const RESULT_CACHE = 1;
const RESULT_NEW = 2;
// Lazily get the base Places AutoComplete Search
XPCOMUtils.defineLazyGetter(this, "PACS", function() {
return Components.classesByID["{d0272978-beab-4adc-a3d4-04b76acfa4e7}"]
@ -90,7 +93,7 @@ var AutoCompleteUtils = {
onSearchResult: function(search, result) {
// Let the listener know about the result right away
if (typeof onResult == "function")
onResult(result);
onResult(result, RESULT_NEW);
// Don't do any more processing if we're not completely done
if (result.searchResult == result.RESULT_NOMATCH_ONGOING ||
@ -235,9 +238,31 @@ AutoCompleteCache.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteSearch, Ci.nsIObserver, Ci.nsISupportsWeakReference]),
get _searchThreshold() {
delete this._searchCount;
return this._searchCount = Services.prefs.getIntPref("browser.urlbar.autocomplete.search_threshold");
},
startSearch: function(query, param, prev, listener) {
let self = this;
let done = function(result) {
let done = function(result, aType) {
let showSearch = (result.matchCount < self._searchThreshold) && (aType == RESULT_NEW);
if (showSearch && (result.searchResult == Ci.nsIAutoCompleteResult.RESULT_SUCCESS ||
result.searchResult == Ci.nsIAutoCompleteResult.RESULT_NOMATCH)) {
let engines = Services.search.getVisibleEngines();
try {
result.QueryInterface(Ci.nsIAutoCompleteSimpleResult);
if (engines.length > 0) {
for (let i = 0; i < engines.length; i++) {
let url = engines[i].getSubmission(query).uri.spec;
result.appendMatch(url, engines[i].name, engines[i].iconURI.spec, "search");
}
result.setSearchResult(Ci.nsIAutoCompleteResult.RESULT_SUCCESS);
}
} catch(ex) {
}
}
listener.onSearchResult(self, result);
};
@ -246,7 +271,7 @@ AutoCompleteCache.prototype = {
if (AutoCompleteUtils.query == query && AutoCompleteUtils.cache) {
// On a cache-hit, give the results right away and fetch in the background
done(AutoCompleteUtils.cache);
done(AutoCompleteUtils.cache, RESULT_CACHE);
} else {
// Otherwise, fetch the result, cache it, and pass it on
AutoCompleteUtils.fetch(query, done);

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

@ -189,6 +189,7 @@ pageactions.password=Password
# Open Search
opensearch.searchWith=Search With:
opensearch.searchFor=Search for "%S"
# Mobile Sync
# LOCALIZATION NOTE (sync.clientUpdate, sync.remoteUpdate):

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

@ -682,34 +682,45 @@ placeitem[src=""] .bookmark-item-container > image {
-moz-margin-start: 1px;
}
.autocomplete-item-container[favorite="true"] {
background: url(images/autocomplete-bookmarked-hdpi.png) no-repeat 100% 2px;
.autocomplete-item-container[favorite="true"],
.autocomplete-item-container[remote="true"],
.autocomplete-item-container[search="true"] {
background-repeat: no-repeat;
background-position: 100% 2px;
background-size: 24px 24px;
}
.autocomplete-item-container[favorite="true"] {
background-image: url("chrome://browser/skin/images/autocomplete-bookmarked-hdpi.png");
}
.autocomplete-item-container[remote="true"] {
background: url(images/autocomplete-desktop-hdpi.png) no-repeat 100% 2px;
background-size: 24px 24px;
background-image: url("chrome://browser/skin/images/autocomplete-desktop-hdpi.png");
}
.autocomplete-item-container[search="true"] {
background-image: url("chrome://browser/skin/images/search-glass-30.png");
}
.autocomplete-item-container[favorite="true"][remote="true"] {
background: url(images/autocomplete-bookmarked-hdpi.png) no-repeat 100% 2px, url(images/autocomplete-desktop-hdpi.png) no-repeat 94% 2px;
background-size: 24px 24px;
}
.autocomplete-item-container[favorite="true"]:-moz-locale-dir(rtl) {
background: url(images/autocomplete-bookmarked-hdpi.png) no-repeat left 2px;
background-image: url("chrome://browser/skin/images/autocomplete-bookmarked-hdpi.png"),
url("chrome://browser/skin/images/autocomplete-desktop-hdpi.png");
background-position: 100% 2px,
94% 2px;
-moz-padding-end: 48px;
}
.autocomplete-item-container[favorite="true"]:-moz-locale-dir(rtl),
.autocomplete-item-container[remote="true"]:-moz-locale-dir(rtl) {
background: url(images/autocomplete-desktop-hdpi.png) no-repeat left 2px;
background-position: left 2px;
}
.autocomplete-item-container[favorite="true"][remote="true"]:-moz-locale-dir(rtl) {
background: url(images/autocomplete-bookmarked-hdpi.png) no-repeat left 2px, url(images/autocomplete-desktop-hdpi.png) no-repeat 6% 2px;
background-position: left 2px,
6% 2px;
}
.autocomplete-item-url,
.autocomplete-item-subtitle,
.bookmark-item-url {
color: blue;
font-size: 18px !important;
@ -717,12 +728,14 @@ placeitem[src=""] .bookmark-item-container > image {
}
.autocomplete-item-container[favorite="true"] .autocomplete-item-label,
.autocomplete-item-container[remote="true"] .autocomplete-item-label {
.autocomplete-item-container[remote="true"] .autocomplete-item-label,
.autocomplete-item-container[search="true"] .autocomplete-item-label {
-moz-padding-end: 30px;
}
.autocomplete-item-container[favorite="true"][remote="true"] {
-moz-padding-end: 48px;
.autocomplete-item-container[search="true"] .autocomplete-item-subtitle {
color: black;
font-size: smaller;
}
.autocomplete-item-tags,