Title: [119786] trunk/Source/WebKit/chromium
Revision
119786
Author
[email protected]
Date
2012-06-07 19:51:54 -0700 (Thu, 07 Jun 2012)

Log Message

[chromium/mac] Improve deviceDPI, rect, and availableRect computation
https://bugs.webkit.org/show_bug.cgi?id=88596

Reviewed by Adam Barth.

Set deviceDPI to 160 for normal displays and 320 for HiDPI displays.
(Why 160? That's what chromium's render_view.cc assumes as default
single-resolution resolution at the moment. The only other place
where this number gets used is fixed layout mode, which is currently
not enabled.)

Also fix rect and availableRect computations: They get returned in
user space already.

Needed for http://crbug.com/31960.

* src/mac/WebScreenInfoFactory.mm:
(WebKit::toUserSpace):
(WebKit::deviceScaleFactor):
(WebKit):
(WebKit::WebScreenInfoFactory::screenInfo):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (119785 => 119786)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-06-08 02:40:55 UTC (rev 119785)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-06-08 02:51:54 UTC (rev 119786)
@@ -1,3 +1,27 @@
+2012-06-07  Nico Weber  <[email protected]>
+
+        [chromium/mac] Improve deviceDPI, rect, and availableRect computation
+        https://bugs.webkit.org/show_bug.cgi?id=88596
+
+        Reviewed by Adam Barth.
+
+        Set deviceDPI to 160 for normal displays and 320 for HiDPI displays.
+        (Why 160? That's what chromium's render_view.cc assumes as default
+        single-resolution resolution at the moment. The only other place
+        where this number gets used is fixed layout mode, which is currently
+        not enabled.)
+
+        Also fix rect and availableRect computations: They get returned in
+        user space already.
+
+        Needed for http://crbug.com/31960.
+
+        * src/mac/WebScreenInfoFactory.mm:
+        (WebKit::toUserSpace):
+        (WebKit::deviceScaleFactor):
+        (WebKit):
+        (WebKit::WebScreenInfoFactory::screenInfo):
+
 2012-06-07  Mark Pilgrim  <[email protected]>
 
         [Chromium] Move didStartWorkerRunLoop to Platform.h

Modified: trunk/Source/WebKit/chromium/src/mac/WebScreenInfoFactory.mm (119785 => 119786)


--- trunk/Source/WebKit/chromium/src/mac/WebScreenInfoFactory.mm	2012-06-08 02:40:55 UTC (rev 119785)
+++ trunk/Source/WebKit/chromium/src/mac/WebScreenInfoFactory.mm	2012-06-08 02:51:54 UTC (rev 119786)
@@ -35,6 +35,14 @@
 
 #include "WebScreenInfo.h"
 
+@interface NSWindow (LionAPI)
+- (CGFloat)backingScaleFactor;
+@end
+
+@interface NSScreen (LionAPI)
+- (CGFloat)backingScaleFactor;
+@end
+
 namespace WebKit {
 
 static NSScreen* screenForWindow(NSWindow* window)
@@ -50,40 +58,46 @@
     return nil;
 }
 
-static WebRect toUserSpace(const NSRect& rect, NSWindow* destination)
+static WebRect convertRect(const NSRect& rect, NSWindow* destination)
 {
     CGRect userRect = NSRectToCGRect(rect);
-
     userRect.origin.y =
-        NSMaxY([screenForWindow(destination) frame]) - (userRect.origin.y + userRect.size.height); // flip
-
-    if (destination) {
-        CGFloat scale = 1 / [destination userSpaceScaleFactor];  // scale down
-        userRect.origin.x *= scale;
-        userRect.origin.y *= scale;
-        userRect.size.width *= scale;
-        userRect.size.height *= scale;
-    }
-
+        NSMaxY([screenForWindow(destination) frame]) - NSMaxY(rect); // flip
     return WebRect(userRect.origin.x,
                    userRect.origin.y,
                    userRect.size.width,
                    userRect.size.height);
 }
 
+static float deviceScaleFactor(NSView* view)
+{
+    NSWindow* window = [view window];
+    if (window)
+    {
+        if ([window respondsToSelector:@selector(backingScaleFactor)])
+            return [window backingScaleFactor];
+        return [window userSpaceScaleFactor];
+    }
+
+    NSArray* screens = [NSScreen screens];
+    if (![screens count])
+        return 1;
+
+    NSScreen* screen = [screens objectAtIndex:0];
+    if ([screen respondsToSelector:@selector(backingScaleFactor)])
+        return [screen backingScaleFactor];
+    return [screen userSpaceScaleFactor];
+}
+
 WebScreenInfo WebScreenInfoFactory::screenInfo(NSView* view)
 {
     NSString *colorSpace = NSColorSpaceFromDepth([[NSScreen deepestScreen] depth]);
 
     WebScreenInfo results;
 
-    // FIXME: Currently Mac seems to always report 72dpi. Need to find a way to
-    // report the true screen dpi.
-    NSWindow* window = [view window];
-    NSDictionary* deviceDescription = [window deviceDescription];
-    NSSize deviceDPI = [[deviceDescription valueForKey:NSDeviceResolution] sizeValue];
-    results.horizontalDPI = static_cast<int>(deviceDPI.width);
-    results.verticalDPI = static_cast<int>(deviceDPI.height);
+    float deviceDPI = 160 * deviceScaleFactor(view);
+    results.horizontalDPI = deviceDPI;
+    results.verticalDPI = deviceDPI;
 
     results.depth =
         NSBitsPerPixelFromDepth([[NSScreen deepestScreen] depth]);
@@ -93,10 +107,9 @@
                         || colorSpace == NSCalibratedBlackColorSpace
                         || colorSpace == NSDeviceWhiteColorSpace
                         || colorSpace == NSDeviceBlackColorSpace;
-    results.rect =
-        toUserSpace([screenForWindow([view window]) frame], [view window]);
+    results.rect = convertRect([screenForWindow([view window]) frame], [view window]);
     results.availableRect =
-        toUserSpace([screenForWindow([view window]) visibleFrame], [view window]);
+        convertRect([screenForWindow([view window]) visibleFrame], [view window]);
     return results;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to