From 233f3a1a909c5589cc4a5ce9a8b0f9b0efe6de63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Wed, 1 Mar 2017 10:35:20 +0100 Subject: [PATCH] Bug 1300376 - Update zoom indicator when moving a browser to another window. r=jaws MozReview-Commit-ID: 3iWBQBM9jC3 --HG-- extra : rebase_source : 60675f06a4c68d429f8f7a9ffac6334b22f47804 --- browser/base/content/browser.js | 7 +++-- browser/components/nsBrowserGlue.js | 4 +-- browser/modules/URLBarZoom.jsm | 48 +++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a70d972b9cfa..6171302ab398 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -27,7 +27,8 @@ Cu.import("resource://gre/modules/NotificationDB.jsm"); ShortcutUtils:false, SimpleServiceDiscovery:false, SitePermissions:false, Social:false, TabCrashHandler:false, Task:false, TelemetryStopwatch:false, Translation:false, UITour:false, UpdateUtils:false, Weave:false, - fxAccounts:false, gDevTools:false, gDevToolsBrowser:false, webrtcUI:false + fxAccounts:false, gDevTools:false, gDevToolsBrowser:false, webrtcUI:false, + URLBarZoom:false */ /** @@ -74,11 +75,12 @@ Cu.import("resource://gre/modules/NotificationDB.jsm"); ["Translation", "resource:///modules/translation/Translation.jsm"], ["UITour", "resource:///modules/UITour.jsm"], ["UpdateUtils", "resource://gre/modules/UpdateUtils.jsm"], + ["URLBarZoom", "resource:///modules/URLBarZoom.jsm"], ["Weave", "resource://services-sync/main.js"], ["fxAccounts", "resource://gre/modules/FxAccounts.jsm"], ["gDevTools", "resource://devtools/client/framework/gDevTools.jsm"], ["gDevToolsBrowser", "resource://devtools/client/framework/gDevTools.jsm"], - ["webrtcUI", "resource:///modules/webrtcUI.jsm", ] + ["webrtcUI", "resource:///modules/webrtcUI.jsm"], ].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource)); XPCOMUtils.defineLazyModuleGetter(this, "SafeBrowsing", @@ -1132,6 +1134,7 @@ var gBrowserInit = { TrackingProtection.init(); RefreshBlocker.init(); CaptivePortalWatcher.init(); + URLBarZoom.init(window); let mm = window.getGroupMessageManager("browsers"); mm.loadFrameScript("chrome://browser/content/tab-content.js", true); diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 828bfbccc090..a780dcf02329 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -32,7 +32,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "AlertsService", "@mozilla.org/alerts-s ProcessHangMonitor:false, ReaderParent:false, RecentWindow:false, RemotePrompt:false, SelfSupportBackend:false, SessionStore:false, ShellService:false, SimpleServiceDiscovery:false, TabCrashHandler:false, - Task:false, UITour:false, URLBarZoom:false, WebChannel:false, + Task:false, UITour:false, WebChannel:false, WindowsRegistry:false, webrtcUI:false */ /** @@ -86,7 +86,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "AlertsService", "@mozilla.org/alerts-s ["TabCrashHandler", "resource:///modules/ContentCrashHandlers.jsm"], ["Task", "resource://gre/modules/Task.jsm"], ["UITour", "resource:///modules/UITour.jsm"], - ["URLBarZoom", "resource:///modules/URLBarZoom.jsm"], ["WebChannel", "resource://gre/modules/WebChannel.jsm"], ["WindowsRegistry", "resource://gre/modules/WindowsRegistry.jsm"], ["webrtcUI", "resource:///modules/webrtcUI.jsm"], @@ -631,7 +630,6 @@ BrowserGlue.prototype = { LoginManagerParent.init(); ReaderParent.init(); - URLBarZoom.init(); SelfSupportBackend.init(); diff --git a/browser/modules/URLBarZoom.jsm b/browser/modules/URLBarZoom.jsm index 9d488b0409c0..c5393cdeb686 100644 --- a/browser/modules/URLBarZoom.jsm +++ b/browser/modules/URLBarZoom.jsm @@ -10,20 +10,39 @@ this.EXPORTED_SYMBOLS = [ "URLBarZoom" ]; Components.utils.import("resource://gre/modules/Services.jsm"); var URLBarZoom = { - init(aWindow) { - // Register ourselves with the service so we know when the zoom prefs change. - Services.obs.addObserver(updateZoomButton, "browser-fullZoom:zoomChange", false); - Services.obs.addObserver(updateZoomButton, "browser-fullZoom:zoomReset", false); - Services.obs.addObserver(updateZoomButton, "browser-fullZoom:location-change", false); + aWindow.addEventListener("EndSwapDocShells", onEndSwapDocShells, true); + aWindow.addEventListener("unload", () => { + aWindow.removeEventListener("EndSwapDocShells", onEndSwapDocShells, true); + }, {once: true}); }, } -function updateZoomButton(aSubject, aTopic) { - let win = aSubject.ownerGlobal; +function fullZoomObserver(aSubject, aTopic) { + // If the tab was the last one in its window and has been dragged to another + // window, the original browser's window will be unavailable here. Since that + // window is closing, we can just ignore this notification. + if (!aSubject.ownerGlobal) { + return; + } + + // Only allow pulse animation for zoom changes, not tab switching. + let animate = (aTopic != "browser-fullZoom:location-change"); + updateZoomButton(aSubject, animate); +} + +function onEndSwapDocShells(event) { + updateZoomButton(event.originalTarget); +} + +function updateZoomButton(aBrowser, aAnimate = false) { + let win = aBrowser.ownerGlobal; + if (aBrowser != win.gBrowser.selectedBrowser) { + return; + } + let customizableZoomControls = win.document.getElementById("zoom-controls"); let zoomResetButton = win.document.getElementById("urlbar-zoom-button"); - let zoomFactor = Math.round(win.ZoomManager.zoom * 100); // Ensure that zoom controls haven't already been added to browser in Customize Mode if (customizableZoomControls && @@ -31,21 +50,26 @@ function updateZoomButton(aSubject, aTopic) { zoomResetButton.hidden = true; return; } + + let zoomFactor = Math.round(win.ZoomManager.zoom * 100); if (zoomFactor != 100) { // Check if zoom button is visible and update label if it is if (zoomResetButton.hidden) { zoomResetButton.hidden = false; } - // Only allow pulse animation for zoom changes, not tab switching - if (aTopic != "browser-fullZoom:location-change") { + if (aAnimate) { zoomResetButton.setAttribute("animate", "true"); } else { zoomResetButton.removeAttribute("animate"); } zoomResetButton.setAttribute("label", win.gNavigatorBundle.getFormattedString("urlbar-zoom-button.label", [zoomFactor])); - // Hide button if zoom is at 100% } else { - zoomResetButton.hidden = true; + // Hide button if zoom is at 100% + zoomResetButton.hidden = true; } } + +Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:zoomChange", false); +Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:zoomReset", false); +Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:location-change", false);