Bug 966599 - [Australis] Restore Defaults should collapse non-default-visible toolbars. r=Gijs

This commit is contained in:
Jared Wein 2014-02-07 11:20:23 -05:00
parent e4d778b08c
commit 84a3ecef4f
6 changed files with 162 additions and 20 deletions

View File

@ -170,7 +170,7 @@ let CustomizableUIInternal = {
anchor: "PanelUI-menu-button",
type: CustomizableUI.TYPE_MENU_PANEL,
defaultPlacements: panelPlacements
});
}, true);
PanelWideWidgetTracker.init();
this.registerArea(CustomizableUI.AREA_NAVBAR, {
@ -185,16 +185,30 @@ let CustomizableUIInternal = {
"downloads-button",
"home-button",
"social-share-button",
]
});
],
defaultCollapsed: false,
}, true);
#ifndef XP_MACOSX
this.registerArea(CustomizableUI.AREA_MENUBAR, {
legacy: true,
type: CustomizableUI.TYPE_TOOLBAR,
defaultPlacements: [
"menubar-items",
]
});
],
get defaultCollapsed() {
#ifdef MENUBAR_CAN_AUTOHIDE
#if defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_QT)
return true;
#else
// This is duplicated logic from /browser/base/jar.mn
// for win6BrowserOverlay.xul.
return Services.appinfo.OS == "WINNT" &&
Services.sysinfo.getProperty("version") != "5.1";
#endif
#endif
return false;
}
}, true);
#endif
this.registerArea(CustomizableUI.AREA_TABSTRIP, {
legacy: true,
@ -204,21 +218,24 @@ let CustomizableUIInternal = {
"new-tab-button",
"alltabs-button",
"tabs-closebutton",
]
});
],
defaultCollapsed: false,
}, true);
this.registerArea(CustomizableUI.AREA_BOOKMARKS, {
legacy: true,
type: CustomizableUI.TYPE_TOOLBAR,
defaultPlacements: [
"personal-bookmarks",
]
});
],
defaultCollapsed: true,
}, true);
this.registerArea(CustomizableUI.AREA_ADDONBAR, {
type: CustomizableUI.TYPE_TOOLBAR,
legacy: true,
defaultPlacements: ["addonbar-closebutton", "status-bar"]
});
defaultPlacements: ["addonbar-closebutton", "status-bar"],
defaultCollapsed: false,
}, true);
},
_defineBuiltInWidgets: function() {
@ -254,7 +271,7 @@ let CustomizableUIInternal = {
return wrapper;
},
registerArea: function(aName, aProperties) {
registerArea: function(aName, aProperties, aInternalCaller) {
if (typeof aName != "string" || !/^[a-z0-9-_]{1,}$/i.test(aName)) {
throw new Error("Invalid area name");
}
@ -274,6 +291,16 @@ let CustomizableUIInternal = {
if (!props.has("type")) {
props.set("type", CustomizableUI.TYPE_TOOLBAR);
}
if (props.get("type") == CustomizableUI.TYPE_TOOLBAR) {
if (!aInternalCaller && props.has("defaultCollapsed")) {
throw new Error("defaultCollapsed is only allowed for default toolbars.")
}
if (!props.has("defaultCollapsed")) {
props.set("defaultCollapsed", true);
}
} else if (props.has("defaultCollapsed")) {
throw new Error("defaultCollapsed only applies for TYPE_TOOLBAR areas.");
}
// Sanity check type:
let allTypes = [CustomizableUI.TYPE_TOOLBAR, CustomizableUI.TYPE_MENU_PANEL];
if (allTypes.indexOf(props.get("type")) == -1) {
@ -2041,6 +2068,13 @@ let CustomizableUIInternal = {
let placements = gPlacements.get(areaId);
for (let areaNode of areaNodes) {
this.buildArea(areaId, placements, areaNode);
let area = gAreas.get(areaId);
if (area.get("type") == CustomizableUI.TYPE_TOOLBAR) {
let defaultCollapsed = area.get("defaultCollapsed");
let win = areaNode.ownerDocument.defaultView;
win.setToolbarVisibility(areaNode, !defaultCollapsed);
}
}
}
gResetting = false;
@ -2163,6 +2197,16 @@ let CustomizableUIInternal = {
return itemNode && removableOrDefault(itemNode || item);
});
}
if (props.get("type") == CustomizableUI.TYPE_TOOLBAR) {
let attribute = container.getAttribute("type") == "menubar" ? "autohide" : "collapsed";
let collapsed = container.getAttribute(attribute) == "true";
let defaultCollapsed = props.get("defaultCollapsed");
if (collapsed != defaultCollapsed) {
LOG("Found " + areaId + " had non-default toolbar visibility (expected " + defaultCollapsed + ", was " + collapsed + ")");
return false;
}
}
}
LOG("Checking default state for " + areaId + ":\n" + currentPlacements.join(",") +
"\nvs.\n" + defaultPlacements.join(","));
@ -2360,6 +2404,8 @@ this.CustomizableUI = {
* effect for toolbars.
* - defaultPlacements: an array of widget IDs making up the
* default contents of the area
* - defaultCollapsed: (INTERNAL ONLY) applies if the type is TYPE_TOOLBAR, specifies
* if toolbar is collapsed by default (default to true)
*/
registerArea: function(aName, aProperties) {
CustomizableUIInternal.registerArea(aName, aProperties);
@ -2738,6 +2784,16 @@ this.CustomizableUI = {
let area = gAreas.get(aArea);
return area ? area.get("type") : null;
},
/**
* Check if a toolbar is collapsed by default.
*
* @param aArea the ID of the area whose default-collapsed state you want to know.
* @return `true` or `false` depending on the area, null if the area is unknown.
*/
isToolbarDefaultCollapsed: function(aArea) {
let area = gAreas.get(aArea);
return area ? area.get("defaultCollapsed") : null;
},
/**
* Obtain the DOM node that is the customize target for an area in a
* specific window.

View File

@ -12,6 +12,9 @@ EXTRA_JS_MODULES += [
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'cocoa'):
DEFINES['CAN_DRAW_IN_TITLEBAR'] = 1
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3'):
DEFINES['MENUBAR_CAN_AUTOHIDE'] = 1
EXTRA_PP_JS_MODULES += [
'CustomizableUI.jsm',
'CustomizableWidgets.jsm',

View File

@ -39,11 +39,10 @@ add_task(function checkRegisteringAndUnregistering() {
[/customizableui-special-spring\d+/,
kButtonId,
/customizableui-special-spring\d+/]);
ok(CustomizableUI.inDefaultState, "With a new toolbar and default placements, " +
"everything should still be in a default state.");
ok(!CustomizableUI.inDefaultState, "With a new toolbar it is no longer in a default state.");
removeCustomToolbars(); // Will call unregisterArea for us
ok(CustomizableUI.inDefaultState, "When the toolbar is unregistered, " +
"everything should still be in a default state.");
"everything will return to the default state.");
});
add_task(function asyncCleanup() {

View File

@ -6,9 +6,10 @@
// Adding, moving and removing items should update the relevant currentset attributes
add_task(function() {
ok(CustomizableUI.inDefaultState, "Should be in the default state when we start");
let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
setToolbarVisibility(personalbar, true);
ok(CustomizableUI.inDefaultState, "Should be in the default state when we start");
ok(!CustomizableUI.inDefaultState, "Making the bookmarks toolbar visible takes it out of the default state");
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);

View File

@ -4,14 +4,95 @@
"use strict";
let bookmarksToolbar = document.getElementById("PersonalToolbar");
let navbar = document.getElementById("nav-bar");
let tabsToolbar = document.getElementById("TabsToolbar");
// Customization reset should restore visibility to default-visible toolbars.
add_task(function() {
let navbar = document.getElementById("nav-bar");
is(navbar.collapsed, false, "Test should start with navbar visible");
navbar.collapsed = true;
setToolbarVisibility(navbar, false);
is(navbar.collapsed, true, "navbar should be hidden now");
yield resetCustomization();
is(navbar.collapsed, false, "Customization reset should restore visibility to the navbar");
});
// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(function() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
is(bookmarksToolbar.collapsed, true, "Test should start with bookmarks toolbar collapsed");
is(bookmarksToolbar.getBoundingClientRect().height, 0, "bookmarksToolbar should have height=0");
isnot(tabsToolbar.getBoundingClientRect().height, 0, "TabsToolbar should have non-zero height");
is(navbar.collapsed, false, "The nav-bar should be shown by default");
setToolbarVisibility(bookmarksToolbar, true);
setToolbarVisibility(navbar, false);
isnot(bookmarksToolbar.getBoundingClientRect().height, 0, "bookmarksToolbar should be visible now");
is(navbar.getBoundingClientRect().height, 1, "navbar should have a height=1 (due to border)");
is(CustomizableUI.inDefaultState, false, "Should no longer be in default state");
yield startCustomizing();
gCustomizeMode.reset();
yield waitForCondition(function() !gCustomizeMode.resetting);
yield endCustomizing();
is(bookmarksToolbar.collapsed, true, "Customization reset should restore collapsed-state to the bookmarks toolbar");
isnot(tabsToolbar.getBoundingClientRect().height, 0, "TabsToolbar should have non-zero height");
is(bookmarksToolbar.getBoundingClientRect().height, 0, "The bookmarksToolbar should have height=0 after reset");
ok(CustomizableUI.inDefaultState, "Everything should be back to default state");
});
// Check that the menubar will be collapsed by resetting, if the platform supports it.
add_task(function() {
let menubar = document.getElementById("toolbar-menubar");
const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(menubar.id);
if (!canMenubarCollapse) {
return;
}
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
is(menubar.getBoundingClientRect().height, 0, "menubar should be hidden by default");
setToolbarVisibility(menubar, true);
isnot(menubar.getBoundingClientRect().height, 0, "menubar should be visible now");
yield startCustomizing();
gCustomizeMode.reset();
yield waitForCondition(function() !gCustomizeMode.resetting);
is(menubar.getAttribute("autohide"), "true", "The menubar should have autohide=true after reset in customization mode");
is(menubar.getBoundingClientRect().height, 0, "The menubar should have height=0 after reset in customization mode");
yield endCustomizing();
is(menubar.getAttribute("autohide"), "true", "The menubar should have autohide=true after reset");
is(menubar.getBoundingClientRect().height, 0, "The menubar should have height=0 after reset");
});
// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(function() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
is(bookmarksToolbar.getBoundingClientRect().height, 0, "bookmarksToolbar should have height=0");
isnot(tabsToolbar.getBoundingClientRect().height, 0, "TabsToolbar should have non-zero height");
setToolbarVisibility(bookmarksToolbar, true);
isnot(bookmarksToolbar.getBoundingClientRect().height, 0, "bookmarksToolbar should be visible now");
is(CustomizableUI.inDefaultState, false, "Should no longer be in default state");
yield startCustomizing();
isnot(bookmarksToolbar.getBoundingClientRect().height, 0, "The bookmarksToolbar should be visible before reset");
isnot(navbar.getBoundingClientRect().height, 0, "The navbar should be visible before reset");
isnot(tabsToolbar.getBoundingClientRect().height, 0, "TabsToolbar should have non-zero height");
gCustomizeMode.reset();
yield waitForCondition(function() !gCustomizeMode.resetting);
is(bookmarksToolbar.getBoundingClientRect().height, 0, "The bookmarksToolbar should have height=0 after reset");
isnot(tabsToolbar.getBoundingClientRect().height, 0, "TabsToolbar should have non-zero height");
isnot(navbar.getBoundingClientRect().height, 0, "The navbar should still be visible after reset");
ok(CustomizableUI.inDefaultState, "Everything should be back to default state");
yield endCustomizing();
});

View File

@ -10,6 +10,7 @@ registerCleanupFunction(cleanup);
// Registering a toolbar with defaultset attribute should work
add_task(function() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
let btn = createDummyXULButton(kButtonId);
let toolbar = document.createElement("toolbar");
toolbar.id = kToolbarId;
@ -21,7 +22,7 @@ add_task(function() {
is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
"Area should be registered as toolbar");
assertAreaPlacements(kToolbarId, [kButtonId]);
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
CustomizableUI.unregisterArea(kToolbarId, true);
toolbar.remove();
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
@ -31,6 +32,7 @@ add_task(function() {
// Registering a toolbar without a defaultset attribute should
// wait for the registerArea call
add_task(function() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
let btn = createDummyXULButton(kButtonId);
let toolbar = document.createElement("toolbar");
toolbar.id = kToolbarId;
@ -44,7 +46,7 @@ add_task(function() {
is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
"Area should be registered as toolbar");
assertAreaPlacements(kToolbarId, [kButtonId]);
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
CustomizableUI.unregisterArea(kToolbarId, true);
toolbar.remove();
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");