blob: 21fa10d549ec902e900623515e93890da41a9a3d [file] [log] [blame]
eseidelce4602f2006-03-08 11:40:39 +00001/*
arobenfee2e822007-06-12 21:50:34 +00002 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
staikos@webkit.orgd6b8e532009-07-30 18:25:42 +00003 * Copyright (C) 2009 Torch Mobile, Inc.
eseidelce4602f2006-03-08 11:40:39 +00004 *
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
hyatt76f34f62006-05-31 20:05:01 +000027#include "config.h"
weinigb8d23232007-06-19 00:08:29 +000028#include "PlatformScreen.h"
eseidelce4602f2006-03-08 11:40:39 +000029
aroben@apple.coma7c639a2009-12-18 17:38:45 +000030#include "HostWindow.h"
eseidelce4602f2006-03-08 11:40:39 +000031#include "IntRect.h"
hyatt76f34f62006-05-31 20:05:01 +000032#include "FloatRect.h"
ggaren0de1f3e2006-09-22 00:50:41 +000033#include "Frame.h"
sfalken49fc47c2006-11-05 23:52:09 +000034#include "FrameView.h"
ggaren59b56c72006-08-24 23:32:11 +000035#include "Page.h"
eseidelce4602f2006-03-08 11:40:39 +000036#include <windows.h>
37
38namespace WebCore {
39
arobenfee2e822007-06-12 21:50:34 +000040// Returns info for the default monitor if widget is NULL
41static MONITORINFOEX monitorInfoForWidget(Widget* widget)
ggaren0aa50c42006-05-31 07:48:22 +000042{
kenneth@webkit.orge8249bf2009-09-18 17:34:17 +000043 HWND window = widget ? widget->root()->hostWindow()->platformPageClient() : 0;
arobenfee2e822007-06-12 21:50:34 +000044 HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
45
46 MONITORINFOEX monitorInfo;
47 monitorInfo.cbSize = sizeof(MONITORINFOEX);
48 GetMonitorInfo(monitor, &monitorInfo);
49 return monitorInfo;
ggaren0aa50c42006-05-31 07:48:22 +000050}
51
arobenfee2e822007-06-12 21:50:34 +000052static DEVMODE deviceInfoForWidget(Widget* widget)
ggaren0aa50c42006-05-31 07:48:22 +000053{
arobenfee2e822007-06-12 21:50:34 +000054 DEVMODE deviceInfo;
55 deviceInfo.dmSize = sizeof(DEVMODE);
56 deviceInfo.dmDriverExtra = 0;
mjs@apple.comacbcc282010-01-05 08:58:28 +000057#if OS(WINCE)
staikos@webkit.orgd6b8e532009-07-30 18:25:42 +000058 if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &deviceInfo))
59 deviceInfo.dmBitsPerPel = 16;
60#else
61 MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
arobenfee2e822007-06-12 21:50:34 +000062 EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &deviceInfo);
staikos@webkit.orgd6b8e532009-07-30 18:25:42 +000063#endif
arobenfee2e822007-06-12 21:50:34 +000064
65 return deviceInfo;
ggaren0aa50c42006-05-31 07:48:22 +000066}
apb2aa0fc2006-11-16 20:32:21 +000067
arobenfee2e822007-06-12 21:50:34 +000068int screenDepth(Widget* widget)
eseidelce4602f2006-03-08 11:40:39 +000069{
arobenfee2e822007-06-12 21:50:34 +000070 DEVMODE deviceInfo = deviceInfoForWidget(widget);
aroben@apple.com5d072622010-09-30 18:27:53 +000071 if (deviceInfo.dmBitsPerPel == 32) {
72 // Some video drivers return 32, but this function is supposed to ignore the alpha
73 // component. See <http://webkit.org/b/42972>.
74 return 24;
75 }
arobenfee2e822007-06-12 21:50:34 +000076 return deviceInfo.dmBitsPerPel;
77}
78
79int screenDepthPerComponent(Widget* widget)
80{
81 // FIXME: Assumes RGB -- not sure if this is right.
aroben@apple.com4c06ee32010-09-30 18:28:18 +000082 return screenDepth(widget) / 3;
arobenfee2e822007-06-12 21:50:34 +000083}
84
85bool screenIsMonochrome(Widget* widget)
86{
mjs@apple.comacbcc282010-01-05 08:58:28 +000087#if OS(WINCE)
staikos@webkit.orgd6b8e532009-07-30 18:25:42 +000088 // EnumDisplaySettings doesn't set dmColor in DEVMODE.
89 return false;
90#else
arobenfee2e822007-06-12 21:50:34 +000091 DEVMODE deviceInfo = deviceInfoForWidget(widget);
92 return deviceInfo.dmColor == DMCOLOR_MONOCHROME;
staikos@webkit.orgd6b8e532009-07-30 18:25:42 +000093#endif
eseidelce4602f2006-03-08 11:40:39 +000094}
95
apb2aa0fc2006-11-16 20:32:21 +000096FloatRect screenRect(Widget* widget)
eseidelce4602f2006-03-08 11:40:39 +000097{
arobenfee2e822007-06-12 21:50:34 +000098 MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
99 return monitorInfo.rcMonitor;
eseidelce4602f2006-03-08 11:40:39 +0000100}
101
apb2aa0fc2006-11-16 20:32:21 +0000102FloatRect screenAvailableRect(Widget* widget)
103{
arobenfee2e822007-06-12 21:50:34 +0000104 MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
105 return monitorInfo.rcWork;
eseidelce4602f2006-03-08 11:40:39 +0000106}
107
ggaren59b56c72006-08-24 23:32:11 +0000108} // namespace WebCore