mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
Bug 694291 - Add a preference mirroring the presence of the search widget in the navigation toolbar. r=past
MozReview-Commit-ID: 9UmowyRTTMK --HG-- extra : rebase_source : 15a2a48e3dae3447e18d65b5f329501717d6a1fe
This commit is contained in:
parent
bd21ee4811
commit
9e788278c4
@ -404,6 +404,12 @@ pref("browser.search.context.loadInBackground", false);
|
||||
// comma seperated list of of engines to hide in the search panel.
|
||||
pref("browser.search.hiddenOneOffs", "");
|
||||
|
||||
// Mirrors whether the search-container widget is in the navigation toolbar. The
|
||||
// default value of this preference must match the DEFAULT_AREA_PLACEMENTS of
|
||||
// UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
|
||||
// position and attributes of the search-container element in browser.xul.
|
||||
pref("browser.search.widget.inNavBar", true);
|
||||
|
||||
#ifndef RELEASE_OR_BETA
|
||||
pref("browser.search.reset.enabled", true);
|
||||
#endif
|
||||
|
@ -13,6 +13,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PanelWideWidgetTracker",
|
||||
"resource:///modules/PanelWideWidgetTracker.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SearchWidgetTracker",
|
||||
"resource:///modules/SearchWidgetTracker.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableWidgets",
|
||||
"resource:///modules/CustomizableWidgets.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
|
||||
@ -299,6 +301,8 @@ var CustomizableUIInternal = {
|
||||
defaultPlacements: ["addonbar-closebutton", "status-bar"],
|
||||
defaultCollapsed: false,
|
||||
}, true);
|
||||
|
||||
SearchWidgetTracker.init();
|
||||
},
|
||||
|
||||
_updateAreasForPhoton() {
|
||||
|
71
browser/components/customizableui/SearchWidgetTracker.jsm
Normal file
71
browser/components/customizableui/SearchWidgetTracker.jsm
Normal file
@ -0,0 +1,71 @@
|
||||
/* 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/. */
|
||||
|
||||
/*
|
||||
* Keeps the "browser.search.widget.inNavBar" preference synchronized.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["SearchWidgetTracker"];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
|
||||
"resource:///modules/CustomizableUI.jsm");
|
||||
|
||||
const WIDGET_ID = "search-container";
|
||||
const PREF_NAME = "browser.search.widget.inNavBar";
|
||||
|
||||
const SearchWidgetTracker = {
|
||||
init() {
|
||||
this.onWidgetAdded = this.onWidgetRemoved = (widgetId, area) => {
|
||||
if (widgetId == WIDGET_ID && area == CustomizableUI.AREA_NAVBAR) {
|
||||
this.syncPreferenceWithWidget();
|
||||
}
|
||||
};
|
||||
this.onWidgetReset = this.onWidgetUndoMove = node => {
|
||||
if (node.id == WIDGET_ID) {
|
||||
this.syncPreferenceWithWidget();
|
||||
}
|
||||
};
|
||||
CustomizableUI.addListener(this);
|
||||
Services.prefs.addObserver(PREF_NAME,
|
||||
() => this.syncWidgetWithPreference());
|
||||
},
|
||||
|
||||
onCustomizeEnd() {
|
||||
// onWidgetUndoMove does not fire when the search container is moved back to
|
||||
// the customization palette as a result of an undo, so we sync again here.
|
||||
this.syncPreferenceWithWidget();
|
||||
},
|
||||
|
||||
syncPreferenceWithWidget() {
|
||||
Services.prefs.setBoolPref(PREF_NAME, this.widgetIsInNavBar);
|
||||
},
|
||||
|
||||
syncWidgetWithPreference() {
|
||||
let newValue = Services.prefs.getBoolPref(PREF_NAME);
|
||||
if (newValue == this.widgetIsInNavBar) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newValue) {
|
||||
// The URL bar widget is always present in the navigation toolbar, so we
|
||||
// can simply read its position to place the search bar right after it.
|
||||
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR,
|
||||
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
|
||||
} else {
|
||||
CustomizableUI.removeWidgetFromArea(WIDGET_ID);
|
||||
}
|
||||
},
|
||||
|
||||
get widgetIsInNavBar() {
|
||||
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
|
||||
return placement ? placement.area == CustomizableUI.AREA_NAVBAR : false;
|
||||
},
|
||||
};
|
@ -18,6 +18,7 @@ EXTRA_JS_MODULES += [
|
||||
'PanelMultiView.jsm',
|
||||
'PanelWideWidgetTracker.jsm',
|
||||
'ScrollbarSampler.jsm',
|
||||
'SearchWidgetTracker.jsm',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'cocoa'):
|
||||
|
@ -5,6 +5,7 @@ support-files =
|
||||
support/feeds_test_page.html
|
||||
support/test-feed.xml
|
||||
|
||||
[browser_694291_searchbar_preference.js]
|
||||
[browser_873501_handle_specials.js]
|
||||
[browser_876926_customize_mode_wrapping.js]
|
||||
[browser_876944_customize_mode_create_destroy.js]
|
||||
|
@ -0,0 +1,48 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const WIDGET_ID = "search-container";
|
||||
const PREF_NAME = "browser.search.widget.inNavBar";
|
||||
|
||||
function checkDefaults() {
|
||||
// If the following defaults change, then the DEFAULT_AREA_PLACEMENTS of
|
||||
// UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
|
||||
// position and attributes of the search-container element in browser.xul
|
||||
// should also change at the same time.
|
||||
ok(Services.prefs.getBoolPref(PREF_NAME));
|
||||
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
|
||||
is(placement.area, CustomizableUI.AREA_NAVBAR);
|
||||
is(placement.position,
|
||||
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
|
||||
}
|
||||
|
||||
add_task(async function test_defaults() {
|
||||
await SpecialPowers.pushPrefEnv({set: [["browser.photon.structure.enabled", false]]});
|
||||
|
||||
// Verify the default state before the first test.
|
||||
checkDefaults();
|
||||
});
|
||||
|
||||
add_task(async function test_syncPreferenceWithWidget() {
|
||||
// Moving the widget to any position outside of the navigation toolbar should
|
||||
// turn the preference to false.
|
||||
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_PANEL);
|
||||
ok(!Services.prefs.getBoolPref(PREF_NAME));
|
||||
|
||||
// Moving the widget back to any position in the navigation toolbar should
|
||||
// turn the preference to true again.
|
||||
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR);
|
||||
ok(Services.prefs.getBoolPref(PREF_NAME));
|
||||
});
|
||||
|
||||
add_task(async function test_syncWidgetWithPreference() {
|
||||
// This should move the widget the customization palette.
|
||||
Services.prefs.setBoolPref(PREF_NAME, false);
|
||||
is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
|
||||
|
||||
// This should return the widget to its default placement.
|
||||
Services.prefs.setBoolPref(PREF_NAME, true);
|
||||
checkDefaults();
|
||||
});
|
Loading…
Reference in New Issue
Block a user