Bug 1256731 - patch 2 - Notify front-end code when screen resolution changes on Windows, so that TabsInTitlebar code can refresh its computations. r=gijs,emk

This commit is contained in:
Jonathan Kew 2016-03-17 12:53:31 +00:00
parent d5c912cdc6
commit 08fa921c03
6 changed files with 33 additions and 0 deletions

View File

@ -35,6 +35,8 @@ var TabsInTitlebar = {
};
CustomizableUI.addListener(this);
addEventListener("resolutionchange", this, false);
this._initialized = true;
},
@ -65,6 +67,12 @@ var TabsInTitlebar = {
this._readPref();
},
handleEvent: function (aEvent) {
if (aEvent.type == "resolutionchange" && aEvent.target == window) {
this._update(true);
}
},
_onMenuMutate: function (aMutations) {
for (let mutation of aMutations) {
if (mutation.attributeName == "inactive" ||
@ -241,6 +249,7 @@ var TabsInTitlebar = {
uninit: function () {
this._initialized = false;
removeEventListener("resolutionchange", this);
Services.prefs.removeObserver(this._prefName, this);
this._menuObserver.disconnect();
CustomizableUI.removeListener(this);

View File

@ -54,6 +54,11 @@ nsIWidgetListener::SizeModeChanged(nsSizeMode aSizeMode)
{
}
void
nsIWidgetListener::UIResolutionChanged()
{
}
void
nsIWidgetListener::FullscreenChanged(bool aInFullscreen)
{

View File

@ -79,6 +79,12 @@ public:
*/
virtual void SizeModeChanged(nsSizeMode aSizeMode);
/**
* Called when the DPI (device resolution scaling factor) is changed,
* such that UI elements may need to be rescaled.
*/
virtual void UIResolutionChanged();
/**
* Called when the z-order of the window is changed. Returns true if the
* notification was handled. aPlacement indicates the new z order. If

View File

@ -112,6 +112,7 @@ void nsWindowBase::ChangedDPI()
if (presShell) {
presShell->BackingScaleFactorChanged();
}
mWidgetListener->UIResolutionChanged();
}
}

View File

@ -377,6 +377,17 @@ nsWebShellWindow::SizeModeChanged(nsSizeMode sizeMode)
// then need to be different.
}
void
nsWebShellWindow::UIResolutionChanged()
{
nsCOMPtr<nsPIDOMWindowOuter> ourWindow =
mDocShell ? mDocShell->GetWindow() : nullptr;
if (ourWindow) {
MOZ_ASSERT(ourWindow->IsOuterWindow());
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("resolutionchange"));
}
}
void
nsWebShellWindow::FullscreenChanged(bool aInFullscreen)
{

View File

@ -56,6 +56,7 @@ public:
virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) override;
virtual bool RequestWindowClose(nsIWidget* aWidget) override;
virtual void SizeModeChanged(nsSizeMode sizeMode) override;
virtual void UIResolutionChanged() override;
virtual void FullscreenChanged(bool aInFullscreen) override;
virtual void OSToolbarButtonPressed() override;
virtual bool ZLevelChanged(bool aImmediate, nsWindowZ *aPlacement,