Bug 1350643 - Part 4.2: Use screen.dpi in nsChildView::GetDPI. r?mstange
MozReview-Commit-ID: AiGBxTNzxSp
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -31,16 +31,17 @@
#include "nsIInterfaceRequestor.h"
#include "nsIFile.h"
#include "nsILocalFileMac.h"
#include "nsGfxCIID.h"
#include "nsIDOMSimpleGestureEvent.h"
#include "nsThemeConstants.h"
#include "nsIWidgetListener.h"
#include "nsIPresShell.h"
+#include "nsIScreen.h"
#include "nsDragService.h"
#include "nsClipboard.h"
#include "nsCursorManager.h"
#include "nsWindowMap.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsMenuUtilsX.h"
@@ -818,22 +819,22 @@ nsIWidget*
nsChildView::GetParent()
{
return mParentWidget;
}
float
nsChildView::GetDPI()
{
- NSWindow* window = [mView window];
- if (window && [window isKindOfClass:[BaseWindow class]]) {
- return [(BaseWindow*)window getDPI];
- }
-
- return 96.0;
+ float dpi = 96.0;
+ nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
+ if (screen) {
+ screen->GetDpi(&dpi);
+ }
+ return dpi;
}
void
nsChildView::Enable(bool aState)
{
}
bool nsChildView::IsEnabled() const
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -39,23 +39,16 @@ typedef struct _nsCocoaWindowList {
NSMutableDictionary* mState;
BOOL mDrawsIntoWindowFrame;
NSColor* mActiveTitlebarColor;
NSColor* mInactiveTitlebarColor;
// Invalidation disabling
BOOL mDisabledNeedsDisplay;
- // DPI cache. Getting the physical screen size (CGDisplayScreenSize)
- // is ridiculously slow, so we cache it in the toplevel window for all
- // descendants to use.
- //
- // XXX the dpi cache won't change when moving across different monitors.
- float mDPI;
-
NSTrackingArea* mTrackingArea;
NSRect mDirtyRect;
BOOL mBeingShown;
BOOL mDrawTitle;
BOOL mBrightTitlebarForeground;
BOOL mUseMenuStyle;
@@ -63,17 +56,16 @@ typedef struct _nsCocoaWindowList {
- (void)importState:(NSDictionary*)aState;
- (NSMutableDictionary*)exportState;
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
- (BOOL)drawsContentsIntoWindowFrame;
- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
- (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive;
-- (float)getDPI;
- (void)mouseEntered:(NSEvent*)aEvent;
- (void)mouseExited:(NSEvent*)aEvent;
- (void)mouseMoved:(NSEvent*)aEvent;
- (void)updateTrackingArea;
- (NSView*)trackingAreaView;
- (void)setBeingShown:(BOOL)aValue;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2882,41 +2882,16 @@ nsCocoaWindow::GetEditCommands(NativeKey
listener->WindowDeactivated();
}
mToplevelActiveState = false;
}
}
@end
-static float
-GetDPI(NSWindow* aWindow)
-{
- NSScreen* screen = [aWindow screen];
- if (!screen)
- return 96.0f;
-
- CGDirectDisplayID displayID =
- [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
- CGFloat heightMM = ::CGDisplayScreenSize(displayID).height;
- size_t heightPx = ::CGDisplayPixelsHigh(displayID);
- if (heightMM < 1 || heightPx < 1) {
- // Something extremely bogus is going on
- return 96.0f;
- }
-
- float dpi = heightPx / (heightMM / MM_PER_INCH_FLOAT);
-
- // Account for HiDPI mode where Cocoa's "points" do not correspond to real
- // device pixels
- CGFloat backingScale = GetBackingScaleFactor(aWindow);
-
- return dpi * backingScale;
-}
-
@interface NSView(FrameViewMethodSwizzling)
- (NSPoint)FrameView__closeButtonOrigin;
- (NSPoint)FrameView__fullScreenButtonOrigin;
@end
@implementation NSView(FrameViewMethodSwizzling)
- (NSPoint)FrameView__closeButtonOrigin
@@ -3060,17 +3035,16 @@ static NSMutableSet *gSwizzledFrameViewC
- (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
{
mDrawsIntoWindowFrame = NO;
[super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag];
mState = nil;
mActiveTitlebarColor = nil;
mInactiveTitlebarColor = nil;
mDisabledNeedsDisplay = NO;
- mDPI = GetDPI(self);
mTrackingArea = nil;
mDirtyRect = NSZeroRect;
mBeingShown = NO;
mDrawTitle = NO;
mBrightTitlebarForeground = NO;
mUseMenuStyle = NO;
[self updateTrackingArea];
@@ -3208,21 +3182,16 @@ static const NSString* kStateCollectionB
}
}
- (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive
{
return aActive ? mActiveTitlebarColor : mInactiveTitlebarColor;
}
-- (float)getDPI
-{
- return mDPI;
-}
-
- (NSView*)trackingAreaView
{
NSView* contentView = [self contentView];
return [contentView superview] ? [contentView superview] : contentView;
}
- (ChildView*)mainChildView
{