Changeset 102301 in webkit


Ignore:
Timestamp:
Dec 7, 2011 7:03:47 PM (12 years ago)
Author:
fsamuel@chromium.org
Message:

[Chromium] Plumb DPI info into PlatformScreen
https://bugs.webkit.org/show_bug.cgi?id=70556

Source/WebCore:

Reviewed by Darin Fisher.

Make DPI information accessible from WebKit through
PlatformScreen. This is useful when making scaling
computations on various devices (e.g. Viewport meta tag).

This patch adds DPI plumbing on Chromium Win/Mac/Linux
platforms.

  • page/Screen.cpp:

(WebCore::Screen::horizontalDPI):
(WebCore::Screen::verticalDPI):

  • page/Screen.h:
  • platform/PlatformScreen.h:
  • platform/chromium/PlatformScreenChromium.cpp:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

  • platform/chromium/PlatformSupport.h:
  • platform/efl/PlatformScreenEfl.cpp:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

  • platform/gtk/PlatformScreenGtk.cpp:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

  • platform/mac/PlatformScreenMac.mm:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

  • platform/qt/PlatformScreenQt.cpp:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

  • platform/win/PlatformScreenWin.cpp:

(WebCore::screenHorizontalDPI):
(WebCore::screenVerticalDPI):

Source/WebKit/chromium:

Reviewed by Darin Fisher.

Make DPI information accessible from WebKit through
PlatformScreen. This is useful when making scaling
computations on various devices (e.g. Viewport meta tag).

This patch adds DPI plumbing on Chromium Win/Mac/Linux
platforms.

  • public/WebScreenInfo.h:

(WebKit::WebScreenInfo::WebScreenInfo):

  • src/PlatformSupport.cpp:

(WebCore::PlatformSupport::screenHorizontalDPI):
(WebCore::PlatformSupport::screenVerticalDPI):

  • src/mac/WebScreenInfoFactory.mm:

(WebKit::WebScreenInfoFactory::screenInfo):

  • src/win/WebScreenInfoFactory.cpp:

(WebKit::WebScreenInfoFactory::screenInfo):

  • src/x11/WebScreenInfoFactory.cpp:

(WebKit::WebScreenInfoFactory::screenInfo):

Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102300 r102301  
     12011-12-07  Fady Samuel  <fsamuel@chromium.org>
     2
     3        [Chromium] Plumb DPI info into PlatformScreen
     4        https://bugs.webkit.org/show_bug.cgi?id=70556
     5
     6        Reviewed by Darin Fisher.
     7
     8        Make DPI information accessible from WebKit through
     9        PlatformScreen. This is useful when making scaling
     10        computations on various devices (e.g. Viewport meta tag).
     11
     12        This patch adds DPI plumbing on Chromium Win/Mac/Linux
     13        platforms.
     14
     15        * page/Screen.cpp:
     16        (WebCore::Screen::horizontalDPI):
     17        (WebCore::Screen::verticalDPI):
     18        * page/Screen.h:
     19        * platform/PlatformScreen.h:
     20        * platform/chromium/PlatformScreenChromium.cpp:
     21        (WebCore::screenHorizontalDPI):
     22        (WebCore::screenVerticalDPI):
     23        * platform/chromium/PlatformSupport.h:
     24        * platform/efl/PlatformScreenEfl.cpp:
     25        (WebCore::screenHorizontalDPI):
     26        (WebCore::screenVerticalDPI):
     27        * platform/gtk/PlatformScreenGtk.cpp:
     28        (WebCore::screenHorizontalDPI):
     29        (WebCore::screenVerticalDPI):
     30        * platform/mac/PlatformScreenMac.mm:
     31        (WebCore::screenHorizontalDPI):
     32        (WebCore::screenVerticalDPI):
     33        * platform/qt/PlatformScreenQt.cpp:
     34        (WebCore::screenHorizontalDPI):
     35        (WebCore::screenVerticalDPI):
     36        * platform/win/PlatformScreenWin.cpp:
     37        (WebCore::screenHorizontalDPI):
     38        (WebCore::screenVerticalDPI):
     39
    1402011-12-07  Aaron Colwell  <acolwell@chromium.org>
    241
  • trunk/Source/WebCore/page/Screen.cpp

    r69599 r102301  
    5252{
    5353    m_frame = 0;
     54}
     55
     56unsigned Screen::horizontalDPI() const
     57{
     58    if (!m_frame)
     59        return 0;
     60    return static_cast<unsigned>(screenHorizontalDPI(m_frame->view()));
     61}
     62
     63unsigned Screen::verticalDPI() const
     64{
     65    if (!m_frame)
     66        return 0;
     67    return static_cast<unsigned>(screenVerticalDPI(m_frame->view()));
    5468}
    5569
  • trunk/Source/WebCore/page/Screen.h

    r69599 r102301  
    4545        void disconnectFrame();
    4646
     47        unsigned horizontalDPI() const;
     48        unsigned verticalDPI() const;
    4749        unsigned height() const;
    4850        unsigned width() const;
  • trunk/Source/WebCore/platform/PlatformScreen.h

    r100751 r102301  
    4848    class Widget;
    4949
     50    int screenHorizontalDPI(Widget*);
     51    int screenVerticalDPI(Widget*);
    5052    int screenDepth(Widget*);
    5153    int screenDepthPerComponent(Widget*);
  • trunk/Source/WebCore/platform/chromium/PlatformScreenChromium.cpp

    r100751 r102301  
    3737namespace WebCore {
    3838
     39int screenHorizontalDPI(Widget* widget)
     40{
     41    return PlatformSupport::screenHorizontalDPI(widget);
     42}
     43
     44int screenVerticalDPI(Widget* widget)
     45{
     46    return PlatformSupport::screenVerticalDPI(widget);
     47}
     48
    3949int screenDepth(Widget* widget)
    4050{
  • trunk/Source/WebCore/platform/chromium/PlatformSupport.h

    r101828 r102301  
    241241
    242242    // Screen -------------------------------------------------------------
     243    static int screenHorizontalDPI(Widget*);
     244    static int screenVerticalDPI(Widget*);
    243245    static int screenDepth(Widget*);
    244246    static int screenDepthPerComponent(Widget*);
  • trunk/Source/WebCore/platform/efl/PlatformScreenEfl.cpp

    r95901 r102301  
    4343
    4444namespace WebCore {
     45 
     46int screenHorizontalDPI(Widget* widget)
     47{
     48    notImplemented();
     49    return 0;
     50}
     51
     52int screenVerticalDPI(Widget* widget)
     53{
     54    notImplemented();
     55    return 0;
     56}
    4557
    4658int screenDepth(Widget* widget)
  • trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp

    r89673 r102301  
    3434#include "GtkVersioning.h"
    3535#include "HostWindow.h"
     36#include "NotImplemented.h"
    3637#include "ScrollView.h"
    3738#include "Widget.h"
     
    6667        container = getToplevel(container);
    6768    return container ? gdk_window_get_visual(gtk_widget_get_window(container)) : 0;
     69}
     70
     71int screenHorizontalDPI(Widget* widget)
     72{
     73    notImplemented();
     74    return 0;
     75}
     76
     77int screenVerticalDPI(Widget* widget)
     78{
     79    notImplemented();
     80    return 0;
    6881}
    6982
  • trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm

    r82398 r102301  
    3131#import "FrameView.h"
    3232#import "Page.h"
     33#import "NotImplemented.h"
    3334
    3435namespace WebCore {
     36
     37int screenHorizontalDPI(Widget*)
     38{
     39    notImplemented();
     40    return 0;
     41}
     42
     43int screenVerticalDPI(Widget*)
     44{
     45    notImplemented();
     46    return 0;
     47}
    3548
    3649int screenDepth(Widget*)
  • trunk/Source/WebCore/platform/qt/PlatformScreenQt.cpp

    r91452 r102301  
    3636#include "FrameView.h"
    3737#include "HostWindow.h"
     38#include "NotImplemented.h"
    3839#include "Widget.h"
    3940#include "QWebPageClient.h"
     
    4243
    4344namespace WebCore {
     45
     46int screenHorizontalDPI(Widget* widget)
     47{
     48    notImplemented();
     49    return 0;
     50}
     51
     52int screenVerticalDPI(Widget* widget)
     53{
     54    notImplemented();
     55    return 0;
     56}
    4457
    4558static int screenNumber(Widget* w)
  • trunk/Source/WebCore/platform/win/PlatformScreenWin.cpp

    r68809 r102301  
    2828#include "PlatformScreen.h"
    2929
    30 #include "HostWindow.h"
    31 #include "IntRect.h"
    3230#include "FloatRect.h"
    3331#include "Frame.h"
    3432#include "FrameView.h"
     33#include "HostWindow.h"
     34#include "IntRect.h"
     35#include "NotImplemented.h"
    3536#include "Page.h"
    3637#include <windows.h>
     
    6465
    6566    return deviceInfo;
     67}
     68
     69int screenHorizontalDPI(Widget* widget)
     70{
     71    notImplemented();
     72    return 0;
     73}
     74
     75int screenVerticalDPI(Widget* widget)
     76{
     77    notImplemented();
     78    return 0;
    6679}
    6780
  • trunk/Source/WebKit/chromium/ChangeLog

    r102292 r102301  
     12011-12-07  Fady Samuel  <fsamuel@chromium.org>
     2
     3        [Chromium] Plumb DPI info into PlatformScreen
     4        https://bugs.webkit.org/show_bug.cgi?id=70556
     5
     6        Reviewed by Darin Fisher.
     7       
     8        Make DPI information accessible from WebKit through
     9        PlatformScreen. This is useful when making scaling
     10        computations on various devices (e.g. Viewport meta tag).
     11
     12        This patch adds DPI plumbing on Chromium Win/Mac/Linux
     13        platforms.
     14
     15        * public/WebScreenInfo.h:
     16        (WebKit::WebScreenInfo::WebScreenInfo):
     17        * src/PlatformSupport.cpp:
     18        (WebCore::PlatformSupport::screenHorizontalDPI):
     19        (WebCore::PlatformSupport::screenVerticalDPI):
     20        * src/mac/WebScreenInfoFactory.mm:
     21        (WebKit::WebScreenInfoFactory::screenInfo):
     22        * src/win/WebScreenInfoFactory.cpp:
     23        (WebKit::WebScreenInfoFactory::screenInfo):
     24        * src/x11/WebScreenInfoFactory.cpp:
     25        (WebKit::WebScreenInfoFactory::screenInfo):
     26
    1272011-12-07  Alexandre Elias  <aelias@google.com>
    228
  • trunk/Source/WebKit/chromium/public/WebScreenInfo.h

    r101224 r102301  
    3737
    3838struct WebScreenInfo {
     39    // The horizontal screen dpi.
     40    int horizontalDPI;
     41
     42    // The vertical screen dpi.
     43    int verticalDPI;
     44
    3945    // The screen depth in bits per pixel
    4046    int depth;
     
    6874
    6975    WebScreenInfo()
    70         : depth(0)
     76        : horizontalDPI(0)
     77        , verticalDPI(0)
     78        , depth(0)
    7179        , depthPerComponent(0)
    7280        , isMonochrome(false)
  • trunk/Source/WebKit/chromium/src/PlatformSupport.cpp

    r102044 r102301  
    10531053}
    10541054
     1055int PlatformSupport::screenHorizontalDPI(Widget* widget)
     1056{
     1057    WebWidgetClient* client = toWebWidgetClient(widget);
     1058    if (!client)
     1059        return 0;
     1060    return client->screenInfo().horizontalDPI;
     1061}
     1062
     1063int PlatformSupport::screenVerticalDPI(Widget* widget)
     1064{
     1065    WebWidgetClient* client = toWebWidgetClient(widget);
     1066    if (!client)
     1067        return 0;
     1068    return client->screenInfo().verticalDPI;
     1069}
     1070
    10551071int PlatformSupport::screenDepth(Widget* widget)
    10561072{
  • trunk/Source/WebKit/chromium/src/mac/WebScreenInfoFactory.mm

    r95901 r102301  
    7777
    7878    WebScreenInfo results;
     79
     80    // FIXME: Currently Mac seems to always report 72dpi. Need to find a way to
     81    // report the true screen dpi.
     82    NSWindow* window = [view window];
     83    NSDictionary* deviceDescription = [window deviceDescription];
     84    NSSize deviceDPI = [[deviceDescription valueForKey:NSDeviceResolution] sizeValue];
     85    results.horizontalDPI = static_cast<int>(deviceDPI.width);
     86    results.verticalDPI = static_cast<int>(deviceDPI.height);
     87
    7988    results.depth =
    8089        NSBitsPerPixelFromDepth([[NSScreen deepestScreen] depth]);
  • trunk/Source/WebKit/chromium/src/win/WebScreenInfoFactory.cpp

    r95901 r102301  
    6161    EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
    6262
     63    HDC hdc = GetDC(0);
     64
    6365    WebScreenInfo results;
     66    results.horizontalDPI = GetDeviceCaps(hdc, LOGPIXELSX);
     67    results.verticalDPI = GetDeviceCaps(hdc, LOGPIXELSY);
    6468    results.depth = devMode.dmBitsPerPel;
    6569    results.depthPerComponent = devMode.dmBitsPerPel / 3;  // Assumes RGB
  • trunk/Source/WebKit/chromium/src/x11/WebScreenInfoFactory.cpp

    r95901 r102301  
    3535
    3636#include <X11/Xlib.h>
     37#include <stdio.h>
    3738
    3839namespace WebKit {
     
    4445WebScreenInfo WebScreenInfoFactory::screenInfo(Display* display, int screenNumber)
    4546{
     47    const float inchesPerMillimeter = 25.4;
    4648    // XDisplayWidth() and XDisplayHeight() return cached values. To ensure that
    4749    // we return the correct dimensions after the screen is resized, query the
     
    5557
    5658    WebScreenInfo results;
     59    int displayWidth = DisplayWidth(display, screenNumber);
     60    int displayWidthInMillimeters = DisplayWidthMM(display, screenNumber);
     61    results.horizontalDPI = static_cast<int>(inchesPerMillimeter * displayWidth / displayWidthInMillimeters);
     62
     63    int displayHeight = DisplayHeight(display, screenNumber);
     64    int displayHeightInMillimeters = DisplayHeightMM(display, screenNumber);
     65    results.verticalDPI = static_cast<int>(inchesPerMillimeter * displayHeight / displayHeightInMillimeters);
     66
    5767    // FIXME: Not all screens use 8bpp.
    5868    results.depthPerComponent = 8;
Note: See TracChangeset for help on using the changeset viewer.