Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
      3  * Copyright (C) 2009 Torch Mobile, Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "config.h"
     28 #include "PlatformScreen.h"
     29 
     30 #include "HostWindow.h"
     31 #include "IntRect.h"
     32 #include "FloatRect.h"
     33 #include "Frame.h"
     34 #include "FrameView.h"
     35 #include "Page.h"
     36 #include <windows.h>
     37 
     38 namespace WebCore {
     39 
     40 // Returns info for the default monitor if widget is NULL
     41 static MONITORINFOEX monitorInfoForWidget(Widget* widget)
     42 {
     43     HWND window = widget ? widget->root()->hostWindow()->platformPageClient() : 0;
     44     HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
     45 
     46     MONITORINFOEX monitorInfo;
     47     monitorInfo.cbSize = sizeof(MONITORINFOEX);
     48     GetMonitorInfo(monitor, &monitorInfo);
     49     return monitorInfo;
     50 }
     51 
     52 static DEVMODE deviceInfoForWidget(Widget* widget)
     53 {
     54     DEVMODE deviceInfo;
     55     deviceInfo.dmSize = sizeof(DEVMODE);
     56     deviceInfo.dmDriverExtra = 0;
     57 #if OS(WINCE)
     58     if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &deviceInfo))
     59         deviceInfo.dmBitsPerPel = 16;
     60 #else
     61     MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
     62     EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &deviceInfo);
     63 #endif
     64 
     65     return deviceInfo;
     66 }
     67 
     68 int screenDepth(Widget* widget)
     69 {
     70     DEVMODE deviceInfo = deviceInfoForWidget(widget);
     71     return deviceInfo.dmBitsPerPel;
     72 }
     73 
     74 int screenDepthPerComponent(Widget* widget)
     75 {
     76     // FIXME: Assumes RGB -- not sure if this is right.
     77     DEVMODE deviceInfo = deviceInfoForWidget(widget);
     78     return deviceInfo.dmBitsPerPel / 3;
     79 }
     80 
     81 bool screenIsMonochrome(Widget* widget)
     82 {
     83 #if OS(WINCE)
     84     // EnumDisplaySettings doesn't set dmColor in DEVMODE.
     85     return false;
     86 #else
     87     DEVMODE deviceInfo = deviceInfoForWidget(widget);
     88     return deviceInfo.dmColor == DMCOLOR_MONOCHROME;
     89 #endif
     90 }
     91 
     92 FloatRect screenRect(Widget* widget)
     93 {
     94     MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
     95     return monitorInfo.rcMonitor;
     96 }
     97 
     98 FloatRect screenAvailableRect(Widget* widget)
     99 {
    100     MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
    101     return monitorInfo.rcWork;
    102 }
    103 
    104 } // namespace WebCore
    105