зеркало из https://github.com/mozilla/pjs.git
Bug 537890. Part 6: Switch DPI dynamically when the window moves across screens or the screen mode changes. r=dbaron
This commit is contained in:
Родитель
785d99cad2
Коммит
703c969440
|
@ -765,31 +765,40 @@ nsPresContext::GetUserPreferences()
|
|||
SetBidi(bidiOptions, PR_FALSE);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsPresContext::CheckDPIChange()
|
||||
{
|
||||
PRInt32 oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
||||
if (!mDeviceContext->CheckDPIChange())
|
||||
return PR_FALSE;
|
||||
if (mShell) {
|
||||
mDeviceContext->FlushFontCache();
|
||||
|
||||
// Re-fetch the view manager's window dimensions in case there's a deferred
|
||||
// resize which hasn't affected our mVisibleArea yet
|
||||
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
||||
nsIViewManager* vm = mShell->GetViewManager();
|
||||
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
||||
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
||||
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
||||
|
||||
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
||||
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
||||
vm->SetWindowDimensions(width, height);
|
||||
|
||||
MediaFeatureValuesChanged(PR_TRUE);
|
||||
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsPresContext::PreferenceChanged(const char* aPrefName)
|
||||
{
|
||||
nsDependentCString prefName(aPrefName);
|
||||
if (prefName.EqualsLiteral("layout.css.dpi") ||
|
||||
prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
|
||||
PRInt32 oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
|
||||
if (mDeviceContext->CheckDPIChange() && mShell) {
|
||||
mDeviceContext->FlushFontCache();
|
||||
|
||||
// Re-fetch the view manager's window dimensions in case there's a deferred
|
||||
// resize which hasn't affected our mVisibleArea yet
|
||||
nscoord oldWidthAppUnits, oldHeightAppUnits;
|
||||
nsIViewManager* vm = mShell->GetViewManager();
|
||||
vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
|
||||
float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
|
||||
float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
|
||||
|
||||
nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
|
||||
nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
|
||||
vm->SetWindowDimensions(width, height);
|
||||
|
||||
MediaFeatureValuesChanged(PR_TRUE);
|
||||
RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
||||
}
|
||||
CheckDPIChange();
|
||||
return;
|
||||
}
|
||||
if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("font."))) {
|
||||
|
@ -1510,6 +1519,11 @@ nsPresContext::ThemeChanged()
|
|||
void
|
||||
nsPresContext::ThemeChangedInternal()
|
||||
{
|
||||
// We might have been torn down. If so, bail out now; we don't want to
|
||||
// start poking possibly-dead widgets etc
|
||||
if (!mShell)
|
||||
return;
|
||||
|
||||
mPendingThemeChanged = PR_FALSE;
|
||||
|
||||
// Tell the theme that it changed, so it can flush any handles to stale theme
|
||||
|
@ -1528,6 +1542,12 @@ nsPresContext::ThemeChangedInternal()
|
|||
// This will force the system metrics to be generated the next time they're used
|
||||
nsCSSRuleProcessor::FreeSystemMetrics();
|
||||
|
||||
if (CheckDPIChange()) {
|
||||
// DPI changes take care of MediaFeatureValuesChanged/
|
||||
// RebuildAllStyleData.
|
||||
return;
|
||||
}
|
||||
|
||||
// Changes to system metrics can change media queries on them.
|
||||
MediaFeatureValuesChanged(PR_TRUE);
|
||||
|
||||
|
|
|
@ -995,6 +995,7 @@ protected:
|
|||
#endif // MOZ_SMIL
|
||||
NS_HIDDEN_(void) GetDocumentColorPreferences();
|
||||
|
||||
NS_HIDDEN_(PRBool) CheckDPIChange();
|
||||
NS_HIDDEN_(void) PreferenceChanged(const char* aPrefName);
|
||||
static NS_HIDDEN_(int) PrefChangedCallback(const char*, void*);
|
||||
|
||||
|
|
|
@ -2167,6 +2167,10 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||
selector:@selector(systemMetricsChanged)
|
||||
name:NSSystemColorsDidChangeNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(systemMetricsChanged)
|
||||
name:NSWindowDidChangeScreenNotification
|
||||
object:[self window]];
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(systemMetricsChanged)
|
||||
name:@"AppleAquaScrollBarVariantChanged"
|
||||
|
|
Загрузка…
Ссылка в новой задаче