Tizen 2.1 base
[framework/web/webkit-efl.git] / Source / WebCore / platform / efl / PlatformScreenEfl.cpp
1 /*
2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4  * Copyright (C) 2008 Holger Hans Peter Freyther
5  * Copyright (C) 2008 INdT - Instituto Nokia de Tecnologia
6  * Copyright (C) 2009-2010 ProFUSION embedded systems
7  * Copyright (C) 2009-2010 Samsung Electronics
8  * Copyright (C) 2012 Intel Corporation. All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1.  Redistributions of source code must retain the above copyright
15  *     notice, this list of conditions and the following disclaimer.
16  * 2.  Redistributions in binary form must reproduce the above copyright
17  *     notice, this list of conditions and the following disclaimer in the
18  *     documentation and/or other materials provided with the distribution.
19  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20  *     its contributors may be used to endorse or promote products derived
21  *     from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include "config.h"
36 #include "PlatformScreen.h"
37
38 #include "NotImplemented.h"
39 #include "PlatformString.h"
40 #include "Widget.h"
41
42 #include <Ecore_Evas.h>
43 #include <wtf/text/CString.h>
44
45 #ifdef HAVE_ECORE_X
46 #include <Ecore_X.h>
47 #endif
48
49 #if ENABLE(TIZEN_WEBKIT2)
50 #include "Frame.h"
51 #include "FrameView.h"
52 #include "Settings.h"
53 #endif
54
55 #if ENABLE(TIZEN_VIEWPORT_POLICY)
56 #include "Chrome.h"
57 #include "ChromeClient.h"
58 #include "Frame.h"
59 #include "FrameView.h"
60 #include "Page.h"
61 #include "Settings.h"
62 #endif
63
64 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
65 #include <EflScreenUtilities.h>
66 #endif
67
68 namespace WebCore {
69
70 int screenHorizontalDPI(Widget*)
71 {
72     notImplemented();
73     return 0;
74 }
75
76 int screenVerticalDPI(Widget*)
77 {
78     notImplemented();
79     return 0;
80 }
81
82 int screenDepth(Widget*)
83 {
84
85 #ifdef HAVE_ECORE_X
86     return ecore_x_default_depth_get(ecore_x_display_get(), ecore_x_default_screen_get());
87 #else
88    return 24;
89 #endif
90 }
91
92 int screenDepthPerComponent(Widget* widget)
93 {
94     if (!widget)
95         return 8;
96
97     int depth = screenDepth(widget);
98
99     switch (depth) {
100     // Special treat 0 as an error, and return 8 bit per component.
101     case 0:
102     case 24:
103     case 32:
104         return 8;
105    case 8:
106         return 2;
107     default:
108         return depth / 3;
109     }
110 }
111
112 bool screenIsMonochrome(Widget* widget)
113 {
114     return screenDepth(widget) < 2;
115 }
116
117 FloatRect screenRect(Widget* widget)
118 {
119 #ifdef HAVE_ECORE_X
120     UNUSED_PARAM(widget);
121     // Fallback to realistic values if the EcoreX call fails
122     // and we cannot accurately detect the screen size.
123     int width = 800;
124     int height = 600;
125     ecore_x_screen_size_get(ecore_x_default_screen_get(), &width, &height);
126
127 #if OS(TIZEN)
128     int count = 0;
129     unsigned char *prop_data = NULL;
130     Ecore_X_Window xWindow = ecore_x_window_root_first_get();
131 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
132     if (Ecore_X_Window applicationXWindow = getXWindow())
133         xWindow = applicationXWindow;
134 #endif
135     int ret = ecore_x_window_prop_property_get(xWindow, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
136
137     int angle = 0;
138     if (ret && prop_data)
139         memcpy(&angle, prop_data, sizeof(int));
140
141     if (prop_data)
142         free(prop_data);
143
144     // ecore_x_screen_size_get() doesn't return orientation applied size
145     // we can consider orientation with window's angle
146     if (angle == 90 || angle == 270) {
147         int temp = width;
148         width = height;
149         height = temp;
150     }
151 #endif
152
153     return FloatRect(0, 0, width, height);
154 #else
155     if (!widget || !widget->evas())
156         return FloatRect();
157
158     int x, y, w, h;
159     ecore_evas_screen_geometry_get(ecore_evas_ecore_evas_get(widget->evas()), &x, &y, &w, &h);
160     return FloatRect(x, y, w, h);
161 #endif
162 }
163
164 FloatRect screenAvailableRect(Widget* widget)
165 {
166     return screenRect(widget);
167 }
168
169 void screenColorProfile(ColorProfile&)
170 {
171     notImplemented();
172 }
173
174 }