Bug 1082108 - Add a button to disable the devedition theme from Customize Mode;r=Gijs

This commit is contained in:
Brian Grinstead 2014-10-14 13:29:30 -05:00
Родитель ffcde0a833
Коммит 7e0d0bdea2
6 изменённых файлов: 102 добавлений и 10 удалений

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

@ -1292,6 +1292,7 @@ pref("services.sync.prefs.sync.xpinstall.whitelist.required", true);
// Developer edition preferences
pref("browser.devedition.theme.enabled", false);
pref("browser.devedition.theme.showCustomizeButton", false);
// Disable the error console
pref("devtools.errorconsole.enabled", false);

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

@ -37,6 +37,7 @@ const kPrefCustomizationState = "browser.uiCustomization.state";
const kPrefCustomizationAutoAdd = "browser.uiCustomization.autoAdd";
const kPrefCustomizationDebug = "browser.uiCustomization.debug";
const kPrefDrawInTitlebar = "browser.tabs.drawInTitlebar";
const kPrefDeveditionTheme = "browser.devedition.theme.enabled";
/**
* The keys are the handlers that are fired when the event type (the value)
@ -139,6 +140,7 @@ let gListeners = new Set();
let gUIStateBeforeReset = {
uiCustomizationState: null,
drawInTitlebar: null,
gUIStateBeforeReset: null,
};
let gModuleName = "[CustomizableUI]";
@ -2299,6 +2301,7 @@ let CustomizableUIInternal = {
_resetUIState: function() {
try {
gUIStateBeforeReset.drawInTitlebar = Services.prefs.getBoolPref(kPrefDrawInTitlebar);
gUIStateBeforeReset.deveditionTheme = Services.prefs.getBoolPref(kPrefDeveditionTheme);
gUIStateBeforeReset.uiCustomizationState = Services.prefs.getCharPref(kPrefCustomizationState);
} catch(e) { }
@ -2306,6 +2309,7 @@ let CustomizableUIInternal = {
Services.prefs.clearUserPref(kPrefCustomizationState);
Services.prefs.clearUserPref(kPrefDrawInTitlebar);
Services.prefs.clearUserPref(kPrefDeveditionTheme);
LOG("State reset");
// Reset placements to make restoring default placements possible.
@ -2367,13 +2371,15 @@ let CustomizableUIInternal = {
*/
undoReset: function() {
if (gUIStateBeforeReset.uiCustomizationState == null ||
gUIStateBeforeReset.drawInTitlebar == null) {
gUIStateBeforeReset.drawInTitlebar == null ||
gUIStateBeforeReset.deveditionTheme == null) {
return;
}
gUndoResetting = true;
let uiCustomizationState = gUIStateBeforeReset.uiCustomizationState;
let drawInTitlebar = gUIStateBeforeReset.drawInTitlebar;
let deveditionTheme = gUIStateBeforeReset.deveditionTheme;
// Need to clear the previous state before setting the prefs
// because pref observers may check if there is a previous UI state.
@ -2381,6 +2387,7 @@ let CustomizableUIInternal = {
Services.prefs.setCharPref(kPrefCustomizationState, uiCustomizationState);
Services.prefs.setBoolPref(kPrefDrawInTitlebar, drawInTitlebar);
Services.prefs.setBoolPref(kPrefDeveditionTheme, deveditionTheme);
this.loadSavedState();
// If the user just customizes toolbar/titlebar visibility, gSavedState will be null
// and we don't need to do anything else here:
@ -2558,6 +2565,10 @@ let CustomizableUIInternal = {
LOG(kPrefDrawInTitlebar + " pref is non-default");
return false;
}
if (Services.prefs.prefHasUserValue(kPrefDeveditionTheme)) {
LOG(kPrefDeveditionTheme + " pref is non-default");
return false;
}
return true;
},
@ -3258,7 +3269,8 @@ this.CustomizableUI = {
*/
get canUndoReset() {
return gUIStateBeforeReset.uiCustomizationState != null ||
gUIStateBeforeReset.drawInTitlebar != null;
gUIStateBeforeReset.drawInTitlebar != null ||
gUIStateBeforeReset.deveditionTheme != null;
},
/**

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

@ -17,6 +17,8 @@ const kPlaceholderClass = "panel-customization-placeholder";
const kSkipSourceNodePref = "browser.uiCustomization.skipSourceNodeCheck";
const kToolbarVisibilityBtn = "customization-toolbar-visibility-button";
const kDrawInTitlebarPref = "browser.tabs.drawInTitlebar";
const kDeveditionThemePref = "browser.devedition.theme.enabled";
const kDeveditionButtonPref = "browser.devedition.theme.showCustomizeButton";
const kMaxTransitionDurationMs = 2000;
const kPanelItemContextMenu = "customizationPanelItemContextMenu";
@ -69,8 +71,11 @@ function CustomizeMode(aWindow) {
#ifdef CAN_DRAW_IN_TITLEBAR
this._updateTitlebarButton();
Services.prefs.addObserver(kDrawInTitlebarPref, this, false);
this.window.addEventListener("unload", this);
#endif
this._updateDevEditionThemeButton();
Services.prefs.addObserver(kDeveditionButtonPref, this, false);
Services.prefs.addObserver(kDeveditionThemePref, this, false);
this.window.addEventListener("unload", this);
};
CustomizeMode.prototype = {
@ -105,6 +110,8 @@ CustomizeMode.prototype = {
#ifdef CAN_DRAW_IN_TITLEBAR
Services.prefs.removeObserver(kDrawInTitlebarPref, this);
#endif
Services.prefs.removeObserver(kDeveditionButtonPref, this);
Services.prefs.removeObserver(kDeveditionThemePref, this);
},
toggle: function() {
@ -1447,11 +1454,9 @@ CustomizeMode.prototype = {
this.exit();
}
break;
#ifdef CAN_DRAW_IN_TITLEBAR
case "unload":
this.uninit();
break;
#endif
}
},
@ -1463,6 +1468,7 @@ CustomizeMode.prototype = {
#ifdef CAN_DRAW_IN_TITLEBAR
this._updateTitlebarButton();
#endif
this._updateDevEditionThemeButton();
break;
case "lightweight-theme-window-updated":
if (aSubject == this.window) {
@ -1498,6 +1504,29 @@ CustomizeMode.prototype = {
},
#endif
_updateDevEditionThemeButton: function() {
let button = this.document.getElementById("customization-devedition-theme-button");
let themeEnabled = Services.prefs.getBoolPref(kDeveditionThemePref);
if (themeEnabled) {
button.setAttribute("checked", "true");
} else {
button.removeAttribute("checked");
}
let buttonVisible = Services.prefs.getBoolPref(kDeveditionButtonPref);
if (buttonVisible) {
button.removeAttribute("hidden");
} else {
button.setAttribute("hidden", "true");
}
},
toggleDevEditionTheme: function() {
let button = this.document.getElementById("customization-devedition-theme-button");
let preferenceValue = button.hasAttribute("checked");
Services.prefs.setBoolPref(kDeveditionThemePref, preferenceValue);
},
_onDragStart: function(aEvent) {
__dumpDragData(aEvent);
let item = aEvent.target;

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

@ -52,6 +52,14 @@
</hbox>
</panel>
</button>
<button id="customization-devedition-theme-button"
class="customizationmode-button"
hidden="true"
label="&customizeMode.deveditionTheme.label;"
oncommand="gCustomizeMode.toggleDevEditionTheme()"
type="checkbox" />
<spacer id="customization-footer-spacer"/>
<button id="customization-undo-reset-button"
class="customizationmode-button"

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

@ -101,6 +101,44 @@ add_task(function() {
is(undoResetButton.hidden, true, "Undo reset button should be hidden at end of test");
});
// Bug 1082108 - Restore Defaults should clear user pref for devedition theme
add_task(function() {
let prefName = "browser.devedition.theme.enabled";
Services.prefs.setBoolPref("browser.devedition.theme.showCustomizeButton", true);
let defaultValue = Services.prefs.getBoolPref(prefName);
let restoreDefaultsButton = document.getElementById("customization-reset-button");
let deveditionThemeButton = document.getElementById("customization-devedition-theme-button");
let undoResetButton = document.getElementById("customization-undo-reset-button");
ok(CustomizableUI.inDefaultState, "Should be in default state at start of test");
ok(restoreDefaultsButton.disabled, "Restore defaults button should be disabled when in default state");
is(deveditionThemeButton.hasAttribute("checked"), defaultValue, "Devedition theme button should reflect pref value");
is(undoResetButton.hidden, true, "Undo reset button should be hidden at start of test");
Services.prefs.setBoolPref(prefName, !defaultValue);
ok(!restoreDefaultsButton.disabled, "Restore defaults button should be enabled when pref changed");
is(deveditionThemeButton.hasAttribute("checked"), !defaultValue, "Devedition theme button should reflect changed pref value");
ok(!CustomizableUI.inDefaultState, "With devedition theme flipped, no longer default");
is(undoResetButton.hidden, true, "Undo reset button should be hidden after pref change");
yield gCustomizeMode.reset();
ok(restoreDefaultsButton.disabled, "Restore defaults button should be disabled after reset");
is(deveditionThemeButton.hasAttribute("checked"), defaultValue, "devedition theme button should reflect default value after reset");
is(Services.prefs.getBoolPref(prefName), defaultValue, "Reset should reset devedition.theme.enabled");
ok(CustomizableUI.inDefaultState, "In default state after devedition theme reset");
is(undoResetButton.hidden, false, "Undo reset button should be visible after reset");
ok(!undoResetButton.disabled, "Undo reset button should be enabled after reset");
yield gCustomizeMode.undoReset();
ok(!restoreDefaultsButton.disabled, "Restore defaults button should be enabled after undo-reset");
is(deveditionThemeButton.hasAttribute("checked"), !defaultValue, "devedition theme button should reflect undo-reset value");
ok(!CustomizableUI.inDefaultState, "No longer in default state after undo");
is(Services.prefs.getBoolPref(prefName), !defaultValue, "Undo-reset goes back to previous pref value");
is(undoResetButton.hidden, true, "Undo reset button should be hidden after undo-reset clicked");
Services.prefs.clearUserPref(prefName);
ok(CustomizableUI.inDefaultState, "In default state after pref cleared");
is(undoResetButton.hidden, true, "Undo reset button should be hidden at end of test");
});
add_task(function asyncCleanup() {
yield gCustomizeMode.reset();
yield endCustomizing();

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

@ -130,6 +130,15 @@
-moz-appearance: none;
}
#customization-titlebar-visibility-button[checked],
#customization-devedition-theme-button[checked] {
background-color: rgb(218, 218, 218);
border-color: rgb(168, 168, 168);
text-shadow: 0 1px rgb(236, 236, 236);
box-shadow: 0 1px rgba(255, 255, 255, 0.5),
inset 0 1px rgb(196, 196, 196);
}
.customizationmode-button[disabled="true"] {
opacity: .5;
}
@ -156,11 +165,6 @@
#customization-titlebar-visibility-button[checked] {
-moz-image-region: rect(0, 48px, 24px, 24px);
background-color: rgb(218, 218, 218);
border-color: rgb(168, 168, 168);
text-shadow: 0 1px rgb(236, 236, 236);
box-shadow: 0 1px rgba(255, 255, 255, 0.5),
inset 0 1px rgb(196, 196, 196);
}
#main-window[customize-entered] #customization-panel-container {