eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 1 | /* |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
staikos@webkit.org | d6b8e53 | 2009-07-30 18:25:42 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 Torch Mobile, Inc. |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 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 | |
hyatt | 76f34f6 | 2006-05-31 20:05:01 +0000 | [diff] [blame] | 27 | #include "config.h" |
weinig | b8d2323 | 2007-06-19 00:08:29 +0000 | [diff] [blame] | 28 | #include "PlatformScreen.h" |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 29 | |
aroben@apple.com | a7c639a | 2009-12-18 17:38:45 +0000 | [diff] [blame] | 30 | #include "HostWindow.h" |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 31 | #include "IntRect.h" |
hyatt | 76f34f6 | 2006-05-31 20:05:01 +0000 | [diff] [blame] | 32 | #include "FloatRect.h" |
ggaren | 0de1f3e | 2006-09-22 00:50:41 +0000 | [diff] [blame] | 33 | #include "Frame.h" |
sfalken | 49fc47c | 2006-11-05 23:52:09 +0000 | [diff] [blame] | 34 | #include "FrameView.h" |
ggaren | 59b56c7 | 2006-08-24 23:32:11 +0000 | [diff] [blame] | 35 | #include "Page.h" |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 36 | #include <windows.h> |
| 37 | |
| 38 | namespace WebCore { |
| 39 | |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 40 | // Returns info for the default monitor if widget is NULL |
| 41 | static MONITORINFOEX monitorInfoForWidget(Widget* widget) |
ggaren | 0aa50c4 | 2006-05-31 07:48:22 +0000 | [diff] [blame] | 42 | { |
kenneth@webkit.org | e8249bf | 2009-09-18 17:34:17 +0000 | [diff] [blame] | 43 | HWND window = widget ? widget->root()->hostWindow()->platformPageClient() : 0; |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 44 | HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY); |
| 45 | |
| 46 | MONITORINFOEX monitorInfo; |
| 47 | monitorInfo.cbSize = sizeof(MONITORINFOEX); |
| 48 | GetMonitorInfo(monitor, &monitorInfo); |
| 49 | return monitorInfo; |
ggaren | 0aa50c4 | 2006-05-31 07:48:22 +0000 | [diff] [blame] | 50 | } |
| 51 | |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 52 | static DEVMODE deviceInfoForWidget(Widget* widget) |
ggaren | 0aa50c4 | 2006-05-31 07:48:22 +0000 | [diff] [blame] | 53 | { |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 54 | DEVMODE deviceInfo; |
| 55 | deviceInfo.dmSize = sizeof(DEVMODE); |
| 56 | deviceInfo.dmDriverExtra = 0; |
mjs@apple.com | acbcc28 | 2010-01-05 08:58:28 +0000 | [diff] [blame] | 57 | #if OS(WINCE) |
staikos@webkit.org | d6b8e53 | 2009-07-30 18:25:42 +0000 | [diff] [blame] | 58 | if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &deviceInfo)) |
| 59 | deviceInfo.dmBitsPerPel = 16; |
| 60 | #else |
| 61 | MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 62 | EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &deviceInfo); |
staikos@webkit.org | d6b8e53 | 2009-07-30 18:25:42 +0000 | [diff] [blame] | 63 | #endif |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 64 | |
| 65 | return deviceInfo; |
ggaren | 0aa50c4 | 2006-05-31 07:48:22 +0000 | [diff] [blame] | 66 | } |
ap | b2aa0fc | 2006-11-16 20:32:21 +0000 | [diff] [blame] | 67 | |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 68 | int screenDepth(Widget* widget) |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 69 | { |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 70 | DEVMODE deviceInfo = deviceInfoForWidget(widget); |
aroben@apple.com | 5d07262 | 2010-09-30 18:27:53 +0000 | [diff] [blame] | 71 | 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 | } |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 76 | return deviceInfo.dmBitsPerPel; |
| 77 | } |
| 78 | |
| 79 | int screenDepthPerComponent(Widget* widget) |
| 80 | { |
| 81 | // FIXME: Assumes RGB -- not sure if this is right. |
aroben@apple.com | 4c06ee3 | 2010-09-30 18:28:18 +0000 | [diff] [blame] | 82 | return screenDepth(widget) / 3; |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool screenIsMonochrome(Widget* widget) |
| 86 | { |
mjs@apple.com | acbcc28 | 2010-01-05 08:58:28 +0000 | [diff] [blame] | 87 | #if OS(WINCE) |
staikos@webkit.org | d6b8e53 | 2009-07-30 18:25:42 +0000 | [diff] [blame] | 88 | // EnumDisplaySettings doesn't set dmColor in DEVMODE. |
| 89 | return false; |
| 90 | #else |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 91 | DEVMODE deviceInfo = deviceInfoForWidget(widget); |
| 92 | return deviceInfo.dmColor == DMCOLOR_MONOCHROME; |
staikos@webkit.org | d6b8e53 | 2009-07-30 18:25:42 +0000 | [diff] [blame] | 93 | #endif |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 94 | } |
| 95 | |
ap | b2aa0fc | 2006-11-16 20:32:21 +0000 | [diff] [blame] | 96 | FloatRect screenRect(Widget* widget) |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 97 | { |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 98 | MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); |
| 99 | return monitorInfo.rcMonitor; |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 100 | } |
| 101 | |
ap | b2aa0fc | 2006-11-16 20:32:21 +0000 | [diff] [blame] | 102 | FloatRect screenAvailableRect(Widget* widget) |
| 103 | { |
aroben | fee2e82 | 2007-06-12 21:50:34 +0000 | [diff] [blame] | 104 | MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); |
| 105 | return monitorInfo.rcWork; |
eseidel | ce4602f | 2006-03-08 11:40:39 +0000 | [diff] [blame] | 106 | } |
| 107 | |
ggaren | 59b56c7 | 2006-08-24 23:32:11 +0000 | [diff] [blame] | 108 | } // namespace WebCore |