1/* 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 4 * Copyright (C) 2008 Christian Dywan <christian@imendio.com> 5 * Copyright (C) 2008 Collabora Ltd. 6 * Copyright (C) 2009 Holger Hans Peter Freyther 7 * 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 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include "config.h" 32#include "PlatformScreen.h" 33 34#include "FloatRect.h" 35#include "GtkVersioning.h" 36#include "HostWindow.h" 37#include "NotImplemented.h" 38#include "ScrollView.h" 39#include "Widget.h" 40 41#include <gtk/gtk.h> 42 43namespace WebCore { 44 45static GtkWidget* getToplevel(GtkWidget* widget) 46{ 47 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); 48 return gtk_widget_is_toplevel(toplevel) ? toplevel : 0; 49} 50 51static GdkVisual* getVisual(Widget* widget) 52{ 53 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0; 54 if (!container) { 55 GdkScreen* screen = gdk_screen_get_default(); 56 return screen ? gdk_screen_get_system_visual(screen) : 0; 57 } 58 59 if (!gtk_widget_get_realized(container)) 60 container = getToplevel(container); 61 return container ? gdk_window_get_visual(gtk_widget_get_window(container)) : 0; 62} 63 64int screenDepth(Widget* widget) 65{ 66 GdkVisual* visual = getVisual(widget); 67 if (!visual) 68 return 24; 69 return gdk_visual_get_depth(visual); 70} 71 72int screenDepthPerComponent(Widget* widget) 73{ 74 GdkVisual* visual = getVisual(widget); 75 if (!visual) 76 return 8; 77 78 return gdk_visual_get_bits_per_rgb(visual); 79} 80 81bool screenIsMonochrome(Widget* widget) 82{ 83 return screenDepth(widget) < 2; 84} 85 86 87static GdkScreen* getScreen(GtkWidget* widget) 88{ 89 return gtk_widget_has_screen(widget) ? gtk_widget_get_screen(widget) : gdk_screen_get_default(); 90} 91 92FloatRect screenRect(Widget* widget) 93{ 94 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0; 95 if (container) 96 container = getToplevel(container); 97 98 GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default(); 99 if (!screen) 100 return FloatRect(); 101 102 gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0; 103 104 GdkRectangle geometry; 105 gdk_screen_get_monitor_geometry(screen, monitor, &geometry); 106 107 return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height); 108} 109 110FloatRect screenAvailableRect(Widget* widget) 111{ 112 GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0; 113 if (container && !gtk_widget_get_realized(container)) 114 return screenRect(widget); 115 116 GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default(); 117 if (!screen) 118 return FloatRect(); 119 120 gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0; 121 122 GdkRectangle workArea; 123 gdk_screen_get_monitor_workarea(screen, monitor, &workArea); 124 125 return FloatRect(workArea.x, workArea.y, workArea.width, workArea.height); 126 127} 128 129void screenColorProfile(ColorProfile&) 130{ 131 notImplemented(); 132} 133 134} // namespace WebCore 135