Bug 939091 - fix forward-moving detection to check if we actually can, r=mikedeboer

This commit is contained in:
Gijs Kruitbosch 2013-11-15 15:25:41 +01:00
Родитель cc2610edfd
Коммит 6ba7967627
2 изменённых файлов: 84 добавлений и 19 удалений

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

@ -74,7 +74,25 @@ let PanelWideWidgetTracker = {
}, },
shouldMoveForward: function(aWidgetId, aPosition) { shouldMoveForward: function(aWidgetId, aPosition) {
let currentWidgetAtPosition = gPanelPlacements[aPosition + 1]; let currentWidgetAtPosition = gPanelPlacements[aPosition + 1];
return gWideWidgets.has(currentWidgetAtPosition) && !gWideWidgets.has(aWidgetId); let rv = gWideWidgets.has(currentWidgetAtPosition) && !gWideWidgets.has(aWidgetId);
// We might now think we can move forward, but for that we need at least 2 more small
// widgets to be present:
if (rv) {
let furtherWidgets = gPanelPlacements.slice(aPosition + 2);
let realWidgets = 0;
if (furtherWidgets.length >= 2) {
while (furtherWidgets.length && realWidgets < 2) {
let w = furtherWidgets.shift();
if (!gWideWidgets.has(w) && this.checkWidgetStatus(w)) {
realWidgets++;
}
}
}
if (realWidgets < 2) {
rv = false;
}
}
return rv;
}, },
adjustWidgets: function(aWidgetId, aMoveForwards) { adjustWidgets: function(aWidgetId, aMoveForwards) {
if (this.adjusting) { if (this.adjusting) {
@ -107,26 +125,12 @@ let PanelWideWidgetTracker = {
if (gWideWidgets.has(thisWidgetId)) { if (gWideWidgets.has(thisWidgetId)) {
continue; continue;
} }
let widgetWrapper = CustomizableUI.getWidget(gPanelPlacements[placementIndex]); let widgetStatus = this.checkWidgetStatus(thisWidgetId);
// This widget might not actually exist: if (!widgetStatus) {
if (!widgetWrapper) {
continue; continue;
} }
// This widget might still not actually exist: if (widgetStatus == "public-only") {
if (widgetWrapper.provider == CustomizableUI.PROVIDER_XUL && fixedPos = !fixedPos ? placementIndex : Math.min(fixedPos, placementIndex);
widgetWrapper.instances.length == 0) {
continue;
}
// Or it might only be there some of the time:
if (widgetWrapper.provider == CustomizableUI.PROVIDER_API &&
widgetWrapper.showInPrivateBrowsing === false) {
if (!fixedPos) {
fixedPos = placementIndex;
} else {
fixedPos = Math.min(fixedPos, placementIndex);
}
// We want to position ourselves before this item:
prevSiblingCount = 0; prevSiblingCount = 0;
} else { } else {
prevSiblingCount++; prevSiblingCount++;
@ -144,6 +148,33 @@ let PanelWideWidgetTracker = {
CustomizableUI.moveWidgetWithinArea(aWidgetId, desiredPos); CustomizableUI.moveWidgetWithinArea(aWidgetId, desiredPos);
} }
}, },
/*
* Check whether a widget id is actually known anywhere.
* @returns false if the widget doesn't exist,
* "public-only" if it's not shown in private windows
* "real" if it does exist and is shown even in private windows
*/
checkWidgetStatus: function(aWidgetId) {
let widgetWrapper = CustomizableUI.getWidget(aWidgetId);
// This widget might not actually exist:
if (!widgetWrapper) {
return false;
}
// This widget might still not actually exist:
if (widgetWrapper.provider == CustomizableUI.PROVIDER_XUL &&
widgetWrapper.instances.length == 0) {
return false;
}
// Or it might only be there some of the time:
if (widgetWrapper.provider == CustomizableUI.PROVIDER_API &&
widgetWrapper.showInPrivateBrowsing === false) {
return "public-only";
}
return "real";
},
init: function() { init: function() {
// Initialize our local placements copy and register the listener // Initialize our local placements copy and register the listener
gPanelPlacements = CustomizableUI.getWidgetIdsInArea(gPanel); gPanelPlacements = CustomizableUI.getWidgetIdsInArea(gPanel);

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

@ -407,6 +407,40 @@ let gTests = [
ok(CustomizableUI.inDefaultState, "Should still be in default state."); ok(CustomizableUI.inDefaultState, "Should still be in default state.");
}, },
}, },
{
desc: "Dragging a small button onto the last big button should work.",
setup: startCustomizing,
run: function() {
let editControls = document.getElementById("edit-controls");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let target = panel.getElementsByClassName("panel-customization-placeholder")[0];
let placementsAfterMove = ["zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"edit-controls"];
simulateItemDrag(editControls, target);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let itemToDrag = "sync-button";
let button = document.getElementById(itemToDrag);
placementsAfterMove.push(itemToDrag);
simulateItemDrag(button, editControls);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
// Put stuff back:
let palette = document.getElementById("customization-palette");
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(button, palette);
simulateItemDrag(editControls, zoomControls);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
},
},
]; ];
function asyncCleanup() { function asyncCleanup() {