Bug 738818 part 3: Make changing currentEngine also change defaultEngine, including for about:home. r=fryn ui-r=limi sr=gavin

This commit is contained in:
Mike de Boer 2013-04-09 17:12:27 -07:00
Родитель 2c2f0b79b2
Коммит fca481e9e3
4 изменённых файлов: 46 добавлений и 33 удалений

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

@ -256,19 +256,6 @@ function onSearchSubmit(aEvent)
function setupSearchEngine() function setupSearchEngine()
{ {
let searchEngineName = document.documentElement.getAttribute("searchEngineName");
let searchEngineInfo = SEARCH_ENGINES[searchEngineName];
if (!searchEngineInfo) {
return;
}
// Add search engine logo.
if (searchEngineInfo.image) {
let logoElt = document.getElementById("searchEngineLogo");
logoElt.src = searchEngineInfo.image;
logoElt.alt = searchEngineName;
}
// The "autofocus" attribute doesn't focus the form element // The "autofocus" attribute doesn't focus the form element
// immediately when the element is first drawn, so the // immediately when the element is first drawn, so the
// attribute is also used for styling when the page first loads. // attribute is also used for styling when the page first loads.
@ -277,6 +264,26 @@ function setupSearchEngine()
searchText.removeEventListener("blur", searchText_onBlur); searchText.removeEventListener("blur", searchText_onBlur);
searchText.removeAttribute("autofocus"); searchText.removeAttribute("autofocus");
}); });
let searchEngineName = document.documentElement.getAttribute("searchEngineName");
let searchEngineInfo = SEARCH_ENGINES[searchEngineName];
let logoElt = document.getElementById("searchEngineLogo");
// Add search engine logo.
if (searchEngineInfo && searchEngineInfo.image) {
logoElt.parentNode.hidden = false;
logoElt.src = searchEngineInfo.image;
#ifdef XP_MACOSX
if (searchEngineInfo.imageHD && !window.matchMedia("(max-resolution: 1dppx)").matches)
logoElt.src = searchEngineInfo.imageHD;
#endif
logoElt.alt = searchEngineName;
searchText.placeholder = "";
}
else {
logoElt.parentNode.hidden = true;
searchText.placeholder = searchEngineName;
}
} }

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

@ -45,6 +45,7 @@ var gEngineManagerDialog = {
break; break;
case "engine-removed": case "engine-removed":
case "engine-current": case "engine-current":
case "engine-default":
// Not relevant // Not relevant
break; break;
} }

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

@ -121,8 +121,12 @@
<field name="searchButton">document.getAnonymousElementByAttribute(this, <field name="searchButton">document.getAnonymousElementByAttribute(this,
"anonid", "searchbar-engine-button");</field> "anonid", "searchbar-engine-button");</field>
<property name="currentEngine" <property name="currentEngine">
onset="this.searchService.currentEngine = val; return val;"> <setter><![CDATA[
let ss = this.searchService;
ss.defaultEngine = ss.currentEngine = val;
return val;
]]></setter>
<getter><![CDATA[ <getter><![CDATA[
var currentEngine = this.searchService.currentEngine; var currentEngine = this.searchService.currentEngine;
// Return a dummy engine if there is no currentEngine // Return a dummy engine if there is no currentEngine
@ -422,8 +426,9 @@
var newIndex = this.engines.indexOf(this.currentEngine); var newIndex = this.engines.indexOf(this.currentEngine);
newIndex += isNextEngine ? 1 : -1; newIndex += isNextEngine ? 1 : -1;
if (newIndex >= 0 && newIndex < this.engines.length) if (newIndex >= 0 && newIndex < this.engines.length) {
this.currentEngine = this.engines[newIndex]; this.currentEngine = this.engines[newIndex];
}
aEvent.preventDefault(); aEvent.preventDefault();
aEvent.stopPropagation(); aEvent.stopPropagation();

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

@ -18,6 +18,23 @@ const STARTPAGE_VERSION = 4;
this.AboutHomeUtils = { this.AboutHomeUtils = {
get snippetsVersion() STARTPAGE_VERSION, get snippetsVersion() STARTPAGE_VERSION,
/**
* Returns an object containing the name and searchURL of the original default
* search engine.
*/
get defaultSearchEngine() {
let defaultEngine = Services.search.defaultEngine;
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
if (submission.postData) {
throw new Error("Home page does not support POST search engines.");
}
return Object.freeze({
name: defaultEngine.name,
searchURL: submission.uri.spec
});
},
/* /*
* showKnowYourRights - Determines if the user should be shown the * showKnowYourRights - Determines if the user should be shown the
* about:rights notification. The notification should *not* be shown if * about:rights notification. The notification should *not* be shown if
@ -59,23 +76,6 @@ this.AboutHomeUtils = {
} }
}; };
/**
* Returns an object containing the name and searchURL of the original default
* search engine.
*/
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "defaultSearchEngine", function() {
let defaultEngine = Services.search.defaultEngine;
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
if (submission.postData) {
throw new Error("Home page does not support POST search engines.");
}
return Object.freeze({
name: defaultEngine.name,
searchURL: submission.uri.spec
});
});
/** /**
* Returns the URL to fetch snippets from, in the urlFormatter service format. * Returns the URL to fetch snippets from, in the urlFormatter service format.
*/ */