From 02c0b30d9e972d773fd91b02a4d09347ce5de18d Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Fri, 20 Feb 2015 21:21:33 +1300 Subject: [PATCH] Bug 1123517 - Refactor sidebar code. r=florian --- browser/base/content/browser-sets.inc | 6 +- browser/base/content/browser-sidebar.js | 309 ++++++++++++++++++ browser/base/content/browser.js | 262 +++------------ browser/base/content/browser.xul | 4 +- .../content/test/general/browser_bug409481.js | 4 +- .../customizableui/content/panelUI.inc.xul | 4 +- .../test/browser_988072_sidebar_events.js | 2 +- .../places/tests/browser/browser_555547.js | 6 +- .../browser/browser_bookmarksProperties.js | 14 +- .../browser/browser_history_sidebar_search.js | 4 +- .../browser/browser_sidebarpanels_click.js | 6 +- .../tests/browser/browser_views_liveupdate.js | 4 +- .../browser_privatebrowsing_sidebar.js | 2 +- .../components/sessionstore/SessionStore.jsm | 2 +- 14 files changed, 380 insertions(+), 249 deletions(-) create mode 100644 browser/base/content/browser-sidebar.js diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc index ec3f227c2fd..3e293dc4c0d 100644 --- a/browser/base/content/browser-sets.inc +++ b/browser/base/content/browser-sets.inc @@ -138,7 +138,7 @@ + oncommand="SidebarUI.toggle('viewBookmarksSidebar');"/> @@ -1138,7 +1138,7 @@ diff --git a/browser/base/content/test/general/browser_bug409481.js b/browser/base/content/test/general/browser_bug409481.js index ade9d209928..395ad93d433 100644 --- a/browser/base/content/test/general/browser_bug409481.js +++ b/browser/base/content/test/general/browser_bug409481.js @@ -4,7 +4,7 @@ function test() { // XXX This looks a bit odd, but is needed to avoid throwing when removing the // event listeners below. See bug 310955. document.getElementById("sidebar").addEventListener("load", delayedOpenUrl, true); - toggleSidebar("viewWebPanelsSidebar", true); + SidebarUI.show("viewWebPanelsSidebar"); } function delayedOpenUrl() { @@ -75,7 +75,7 @@ function contextMenuClosed() var sidebar = document.getElementById("sidebar"); sidebar.contentDocument.removeEventListener("popuphidden", contextMenuClosed, false); - toggleSidebar("viewWebPanelsSidebar"); + SidebarUI.hide(); ok(document.getElementById("sidebar-box").hidden, "Sidebar successfully hidden"); diff --git a/browser/components/customizableui/content/panelUI.inc.xul b/browser/components/customizableui/content/panelUI.inc.xul index 3e7d4fca480..b96057246ae 100644 --- a/browser/components/customizableui/content/panelUI.inc.xul +++ b/browser/components/customizableui/content/panelUI.inc.xul @@ -64,7 +64,7 @@ type="checkbox" class="subviewbutton" key="key_gotoHistory" - oncommand="toggleSidebar('viewHistorySidebar'); PanelUI.hide();"> + oncommand="SidebarUI.toggle('viewHistorySidebar'); PanelUI.hide();"> + oncommand="SidebarUI.toggle('viewBookmarksSidebar'); PanelUI.hide();"> { // Ensure sidebar is hidden after each test: if (!document.getElementById("sidebar-box").hidden) { - toggleSidebar("", false); + SidebarUI.hide(); } }); diff --git a/browser/components/places/tests/browser/browser_555547.js b/browser/components/places/tests/browser/browser_555547.js index 04476c26e74..0654139cbac 100644 --- a/browser/components/places/tests/browser/browser_555547.js +++ b/browser/components/places/tests/browser/browser_555547.js @@ -16,7 +16,9 @@ add_task(function* test() { } let sidebar = yield promiseLoadedSidebar("viewBookmarksSidebar"); - registerCleanupFunction(toggleSidebar); + registerCleanupFunction(() => { + SidebarUI.hide(); + }); // Focus the tree and check if its controller is returned. let tree = sidebar.contentDocument.getElementById("bookmarks-view"); @@ -59,6 +61,6 @@ function promiseLoadedSidebar(cmd) { resolve(sidebar); }, true); - toggleSidebar(cmd, true); + SidebarUI.show(cmd); }); } diff --git a/browser/components/places/tests/browser/browser_bookmarksProperties.js b/browser/components/places/tests/browser/browser_bookmarksProperties.js index 3b3f3b424cd..ea1ca3a538d 100644 --- a/browser/components/places/tests/browser/browser_bookmarksProperties.js +++ b/browser/components/places/tests/browser/browser_bookmarksProperties.js @@ -79,7 +79,7 @@ gTests.push({ finish: function() { // Close window, toggle sidebar and goto next test. this.window.document.documentElement.cancelDialog(); - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -138,7 +138,7 @@ gTests.push({ finish: function() { this.window.document.documentElement.cancelDialog(); - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -232,7 +232,7 @@ gTests.push({ }, finish: function() { - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -291,7 +291,7 @@ gTests.push({ finish: function() { // Window is already closed. - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -390,7 +390,7 @@ gTests.push({ }, finish: function() { - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -468,7 +468,7 @@ gTests.push({ }, finish: function() { - toggleSidebar(this.sidebar, false); + SidebarUI.hide(); runNextTest(); }, @@ -529,7 +529,7 @@ function execute_test_in_sidebar() { // Need to executeSoon since the tree is initialized on sidebar load. executeSoon(open_properties_dialog); }, true); - toggleSidebar(gCurrentTest.sidebar, true); + SidebarUI.show(gCurrentTest.sidebar); } function open_properties_dialog() { diff --git a/browser/components/places/tests/browser/browser_history_sidebar_search.js b/browser/components/places/tests/browser/browser_history_sidebar_search.js index 906b9561e5f..0ae57a4d9ed 100644 --- a/browser/components/places/tests/browser/browser_history_sidebar_search.js +++ b/browser/components/places/tests/browser/browser_history_sidebar_search.js @@ -44,7 +44,7 @@ function continue_test() { transition: hs.TRANSITION_TYPED}); } PlacesTestUtils.addVisits(places).then(() => { - toggleSidebar("viewHistorySidebar", true); + SidebarUI.show("viewHistorySidebar"); }); sidebar.addEventListener("load", function() { @@ -63,7 +63,7 @@ function continue_test() { check_sidebar_tree_order(pages.length); // Cleanup. - toggleSidebar("viewHistorySidebar", false); + SidebarUI.hide(); PlacesTestUtils.clearHistory().then(finish); }); }, true); diff --git a/browser/components/places/tests/browser/browser_sidebarpanels_click.js b/browser/components/places/tests/browser/browser_sidebarpanels_click.js index 662e0d30fc0..80ed2eb2bb0 100644 --- a/browser/components/places/tests/browser/browser_sidebarpanels_click.js +++ b/browser/components/places/tests/browser/browser_sidebarpanels_click.js @@ -18,7 +18,7 @@ function test() { // If a sidebar is already open, close it. if (!document.getElementById("sidebar-box").hidden) { info("Unexpected sidebar found - a previous test failed to cleanup correctly"); - toggleSidebar(); + SidebarUI.hide(); } let sidebar = document.getElementById("sidebar"); @@ -76,7 +76,7 @@ function test() { function testPlacesPanel(preFunc, postFunc) { currentTest.init(function() { - toggleSidebar(currentTest.sidebarName); + SidebarUI.show(currentTest.sidebarName); }); sidebar.addEventListener("load", function() { @@ -95,7 +95,7 @@ function test() { aSubject.Dialog.ui.button0.click(); executeSoon(function () { - toggleSidebar(currentTest.sidebarName); + SidebarUI.hide(); currentTest.cleanup(postFunc); }); } diff --git a/browser/components/places/tests/browser/browser_views_liveupdate.js b/browser/components/places/tests/browser/browser_views_liveupdate.js index 41c61a1f6a2..994f2088899 100644 --- a/browser/components/places/tests/browser/browser_views_liveupdate.js +++ b/browser/components/places/tests/browser/browser_views_liveupdate.js @@ -37,7 +37,7 @@ function openBookmarksSidebar() { // Need to executeSoon since the tree is initialized on sidebar load. executeSoon(startTest); }, true); - toggleSidebar("viewBookmarksSidebar", true); + SidebarUI.show("viewBookmarksSidebar"); } /** @@ -171,7 +171,7 @@ function startTest() { */ function finishTest() { // Close bookmarks sidebar. - toggleSidebar("viewBookmarksSidebar", false); + SidebarUI.hide(); // Collapse the personal toolbar if needed. if (wasCollapsed) { diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_sidebar.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_sidebar.js index 7883f5d55df..2d89cdf3fc8 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_sidebar.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_sidebar.js @@ -33,7 +33,7 @@ function test() { resolve(win); }, true); - win.toggleSidebar(sidebarID, true); + win.SidebarUI.show(sidebarID); return promise; } diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index cc771af85e1..64017f7344b 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -2865,7 +2865,7 @@ let SessionStoreInternal = { } var sidebar = aWindow.document.getElementById("sidebar-box"); if (sidebar.getAttribute("sidebarcommand") != aSidebar) { - aWindow.toggleSidebar(aSidebar); + aWindow.SidebarUI.show(aSidebar); } // since resizing/moving a window brings it to the foreground, // we might want to re-focus the last focused window