blob: 7125403569e42bdd7d3738c000128791ebd524bd [file] [log] [blame]
darin6fb113f2006-07-01 04:39:50 +00001/*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
alp@webkit.org040ad8b2008-02-04 11:00:43 +00003 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +00004 * Copyright (C) 2008 Christian Dywan <christian@imendio.com>
5 * Copyright (C) 2008 Collabora Ltd.
zecke@webkit.orgefa20552009-07-17 14:48:22 +00006 * Copyright (C) 2009 Holger Hans Peter Freyther
darin6fb113f2006-07-01 04:39:50 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
alp@webkit.org040ad8b2008-02-04 11:00:43 +000028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
darin6fb113f2006-07-01 04:39:50 +000029 */
30
31#include "config.h"
weinigb8d23232007-06-19 00:08:29 +000032#include "PlatformScreen.h"
darin6fb113f2006-07-01 04:39:50 +000033
kov@webkit.org8bab4ab2010-03-23 13:23:26 +000034#include "GtkVersioning.h"
jmalonzo@webkit.org047c3402008-10-04 04:02:30 +000035#include "HostWindow.h"
fsamuel@chromium.orga33350a2011-12-08 03:03:47 +000036#include "NotImplemented.h"
jmalonzo@webkit.org047c3402008-10-04 04:02:30 +000037#include "ScrollView.h"
weinigb8d23232007-06-19 00:08:29 +000038#include "Widget.h"
zeckedefdb0c2007-08-09 23:44:39 +000039
40#include <gtk/gtk.h>
darin6fb113f2006-07-01 04:39:50 +000041
42namespace WebCore {
43
carlosgc@webkit.org70592372011-06-24 15:42:28 +000044static GtkWidget* getToplevel(GtkWidget* widget)
45{
46 GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
47 return gtk_widget_is_toplevel(toplevel) ? toplevel : 0;
48}
49
zecke@webkit.orgefa20552009-07-17 14:48:22 +000050static GdkVisual* getVisual(Widget* widget)
bdash2f045e52007-05-18 08:41:43 +000051{
carlosgc@webkit.org777f9982012-01-05 14:38:23 +000052 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0;
carlosgc@webkit.org70592372011-06-24 15:42:28 +000053 if (!container) {
54 GdkScreen* screen = gdk_screen_get_default();
55 return screen ? gdk_screen_get_system_visual(screen) : 0;
zecke@webkit.orge27e3242008-12-11 10:22:40 +000056 }
57
carlosgc@webkit.org70592372011-06-24 15:42:28 +000058 if (!gtk_widget_get_realized(container))
59 container = getToplevel(container);
60 return container ? gdk_window_get_visual(gtk_widget_get_window(container)) : 0;
zecke@webkit.orgefa20552009-07-17 14:48:22 +000061}
62
fsamuel@chromium.orga33350a2011-12-08 03:03:47 +000063int screenHorizontalDPI(Widget* widget)
64{
65 notImplemented();
66 return 0;
67}
68
69int screenVerticalDPI(Widget* widget)
70{
71 notImplemented();
72 return 0;
73}
74
zecke@webkit.orgefa20552009-07-17 14:48:22 +000075int screenDepth(Widget* widget)
76{
77 GdkVisual* visual = getVisual(widget);
78 if (!visual)
79 return 24;
xan@webkit.orgcc8bbbf2010-06-15 19:14:38 +000080 return gdk_visual_get_depth(visual);
kjk55148982007-02-08 22:37:14 +000081}
bdashe2ec6f22006-09-16 00:39:12 +000082
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +000083int screenDepthPerComponent(Widget* widget)
kjk55148982007-02-08 22:37:14 +000084{
zecke@webkit.orgefa20552009-07-17 14:48:22 +000085 GdkVisual* visual = getVisual(widget);
86 if (!visual)
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +000087 return 8;
88
xan@webkit.orgcc8bbbf2010-06-15 19:14:38 +000089 return gdk_visual_get_bits_per_rgb(visual);
kjk55148982007-02-08 22:37:14 +000090}
darin6fb113f2006-07-01 04:39:50 +000091
alp@webkit.orgbdb392f2008-03-08 06:07:54 +000092bool screenIsMonochrome(Widget* widget)
alp@webkit.org040ad8b2008-02-04 11:00:43 +000093{
alp@webkit.orgbdb392f2008-03-08 06:07:54 +000094 return screenDepth(widget) < 2;
kjk55148982007-02-08 22:37:14 +000095}
96
carlosgc@webkit.org70592372011-06-24 15:42:28 +000097
98static GdkScreen* getScreen(GtkWidget* widget)
99{
100 return gtk_widget_has_screen(widget) ? gtk_widget_get_screen(widget) : gdk_screen_get_default();
101}
102
bdakin@apple.comc88f6da2012-02-03 19:29:13 +0000103FloatRect screenRect(Widget* widget)
alp@webkit.org040ad8b2008-02-04 11:00:43 +0000104{
bdakin@apple.comc88f6da2012-02-03 19:29:13 +0000105 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0;
carlosgc@webkit.org70592372011-06-24 15:42:28 +0000106 if (container)
107 container = getToplevel(container);
alp@webkit.orgbdb392f2008-03-08 06:07:54 +0000108
carlosgc@webkit.org70592372011-06-24 15:42:28 +0000109 GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default();
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +0000110 if (!screen)
111 return FloatRect();
112
carlosgc@webkit.org70592372011-06-24 15:42:28 +0000113 gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0;
114
alp@webkit.orgbdb392f2008-03-08 06:07:54 +0000115 GdkRectangle geometry;
alp@webkit.orgbdb392f2008-03-08 06:07:54 +0000116 gdk_screen_get_monitor_geometry(screen, monitor, &geometry);
carlosgc@webkit.org70592372011-06-24 15:42:28 +0000117
alp@webkit.orgbdb392f2008-03-08 06:07:54 +0000118 return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height);
alp@webkit.org040ad8b2008-02-04 11:00:43 +0000119}
120
bdakin@apple.comc88f6da2012-02-03 19:29:13 +0000121FloatRect screenAvailableRect(Widget* widget)
alp@webkit.org040ad8b2008-02-04 11:00:43 +0000122{
bdakin@apple.comc88f6da2012-02-03 19:29:13 +0000123 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0;
carlosgc@webkit.orgaaacedc2011-12-14 19:18:24 +0000124 if (container && !gtk_widget_get_realized(container))
bdakin@apple.comc88f6da2012-02-03 19:29:13 +0000125 return screenRect(widget);
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +0000126
carlosgc@webkit.orgaaacedc2011-12-14 19:18:24 +0000127 GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default();
128 if (!screen)
129 return FloatRect();
130
carlosgc@webkit.orgd22b46e2012-01-03 09:17:04 +0000131 gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0;
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +0000132
carlosgc@webkit.orgd22b46e2012-01-03 09:17:04 +0000133 GdkRectangle workArea;
134 gdk_screen_get_monitor_workarea(screen, monitor, &workArea);
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +0000135
carlosgc@webkit.orgd22b46e2012-01-03 09:17:04 +0000136 return FloatRect(workArea.x, workArea.y, workArea.width, workArea.height);
jmalonzo@webkit.org210145b2008-08-13 19:56:20 +0000137
kjk55148982007-02-08 22:37:14 +0000138}
darin6fb113f2006-07-01 04:39:50 +0000139
commit-queue@webkit.org23602772012-07-14 02:03:21 +0000140void screenColorProfile(ColorProfile&)
commit-queue@webkit.org26de5ec2012-06-20 02:15:00 +0000141{
142 notImplemented();
143}
144
weinigb8d23232007-06-19 00:08:29 +0000145} // namespace WebCore