[EFL] Rename TEST_THEME_DIR macro
[WebKit-https.git] / Source / WebKit2 / UIProcess / efl / WebInspectorProxyEfl.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "WebInspectorProxy.h"
28
29 #if ENABLE(INSPECTOR)
30
31 #include "EwkView.h"
32 #include "WebProcessProxy.h"
33 #include "ewk_context_private.h"
34 #include "ewk_page_group_private.h"
35 #include "ewk_settings.h"
36 #include "ewk_view.h"
37 #include "ewk_view_private.h"
38 #include <WebCore/EflInspectorUtilities.h>
39 #include <WebCore/NotImplemented.h>
40 #include <WebKit/WKPage.h>
41 #include <WebKit/WKPageGroup.h>
42 #include <WebKit/WKString.h>
43 #include <WebKit/WKViewEfl.h>
44 #include <wtf/text/CString.h>
45 #include <wtf/text/StringBuilder.h>
46 #include <wtf/text/WTFString.h>
47
48 namespace WebKit {
49
50 static void resizeInspectorWindow(Ecore_Evas* inspectorWindow)
51 {
52     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
53     if (!inspectorView)
54         return;
55
56     int width, height;
57     ecore_evas_geometry_get(inspectorWindow, 0, 0, &width, &height);
58
59     evas_object_move(inspectorView, 0, 0);
60     evas_object_resize(inspectorView, width, height);
61 }
62
63 static void destroyInspectorWindow(Ecore_Evas* inspectorWindow)
64 {
65     Evas_Object* inspectorView = evas_object_name_find(ecore_evas_get(inspectorWindow), "inspector");
66     if (inspectorView)
67         evas_object_smart_callback_call(inspectorView, "inspector,view,close", 0);
68 }
69
70 static void closeInspectorWindow(void* userData, Evas_Object*, void*)
71 {
72     WebInspectorProxy* inspectorProxy = static_cast<WebInspectorProxy*>(userData);
73
74     inspectorProxy->close();
75 }
76
77 void WebInspectorProxy::createInspectorWindow()
78 {
79     ecore_evas_title_set(m_inspectorWindow, "Web Inspector");
80     ecore_evas_callback_resize_set(m_inspectorWindow, resizeInspectorWindow);
81     ecore_evas_callback_delete_request_set(m_inspectorWindow, destroyInspectorWindow);
82     ecore_evas_show(m_inspectorWindow);
83
84     evas_object_name_set(m_inspectorView, "inspector");
85     evas_object_move(m_inspectorView, 0, 0);
86     evas_object_resize(m_inspectorView, initialWindowWidth, initialWindowHeight);
87     evas_object_show(m_inspectorView);
88
89     evas_object_focus_set(m_inspectorView, true);
90 }
91
92 WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
93 {
94     ASSERT(m_page);
95
96 #ifdef HAVE_ECORE_X
97     const char* engine = "opengl_x11";
98     m_inspectorWindow = ecore_evas_new(engine, 0, 0, initialWindowWidth, initialWindowHeight, 0);
99
100     // Gracefully fall back to software if evas_gl engine is not available.
101     if (!m_inspectorWindow)
102 #endif
103     m_inspectorWindow = ecore_evas_new(0, 0, 0, initialWindowWidth, initialWindowHeight, 0);
104     if (!m_inspectorWindow)
105         return 0;
106
107     WKContextRef wkContext = toAPI(&inspectorContext());
108     WKPageGroupRef wkPageGroup = toAPI(inspectorPageGroup());
109
110     m_inspectorView = EWKViewCreate(wkContext, wkPageGroup, ecore_evas_get(m_inspectorWindow), /* smart */ 0);
111     WKViewRef wkView = EWKViewGetWKView(m_inspectorView);
112
113     WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(DEFAULT_THEME_DIR "/default.edj"));
114     WKViewSetThemePath(wkView, wkTheme.get());
115
116     WKPreferencesRef wkPreferences = WKPageGroupGetPreferences(wkPageGroup);
117     WKPreferencesSetFileAccessFromFileURLsAllowed(wkPreferences, true);
118
119     return toImpl(WKViewGetPage(wkView));
120 }
121
122 void WebInspectorProxy::platformOpen()
123 {
124     if (m_isAttached)
125         platformAttach();
126     else
127         createInspectorWindow();
128
129     evas_object_smart_callback_add(m_inspectorView, "inspector,view,close", closeInspectorWindow, this);
130 }
131
132 void WebInspectorProxy::platformDidClose()
133 {
134     if (m_inspectorView) {
135         evas_object_del(m_inspectorView);
136         m_inspectorView = 0;
137     }
138
139     if (m_inspectorWindow) {
140         ecore_evas_free(m_inspectorWindow);
141         m_inspectorWindow = 0;
142     }
143 }
144
145 void WebInspectorProxy::platformHide()
146 {
147     notImplemented();
148 }
149
150 void WebInspectorProxy::platformBringToFront()
151 {
152     notImplemented();
153 }
154
155 bool WebInspectorProxy::platformIsFront()
156 {
157     notImplemented();
158     return false;
159 }
160
161 void WebInspectorProxy::platformInspectedURLChanged(const String& url)
162 {
163     if (!m_inspectorWindow)
164         return;
165
166     String title = "WebInspector - " + url;
167     ecore_evas_title_set(m_inspectorWindow, title.utf8().data());
168 }
169
170 String WebInspectorProxy::inspectorPageURL() const
171 {
172     StringBuilder builder;
173     builder.append(inspectorBaseURL());
174     builder.appendLiteral("/Main.html");
175
176     return builder.toString();
177 }
178
179 String WebInspectorProxy::inspectorTestPageURL() const
180 {
181     StringBuilder builder;
182     builder.append(inspectorBaseURL());
183     builder.appendLiteral("/Test.html");
184
185     return builder.toString();
186 }
187
188 String WebInspectorProxy::inspectorBaseURL() const
189 {
190     return "file://" + WebCore::inspectorResourcePath();
191 }
192
193 unsigned WebInspectorProxy::platformInspectedWindowHeight()
194 {
195     notImplemented();
196     return 0;
197 }
198
199 unsigned WebInspectorProxy::platformInspectedWindowWidth()
200 {
201     notImplemented();
202     return 0;
203 }
204
205 void WebInspectorProxy::platformAttach()
206 {
207     notImplemented();
208 }
209
210 void WebInspectorProxy::platformDetach()
211 {
212     notImplemented();
213 }
214
215 void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned)
216 {
217     notImplemented();
218 }
219
220 void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned)
221 {
222     notImplemented();
223 }
224
225 void WebInspectorProxy::platformSetToolbarHeight(unsigned)
226 {
227     notImplemented();
228 }
229
230 void WebInspectorProxy::platformSave(const String&, const String&, bool, bool)
231 {
232     notImplemented();
233 }
234
235 void WebInspectorProxy::platformAppend(const String&, const String&)
236 {
237     notImplemented();
238 }
239
240 void WebInspectorProxy::platformAttachAvailabilityChanged(bool)
241 {
242     notImplemented();
243 }
244
245 } // namespace WebKit
246
247 #endif // ENABLE(INSPECTOR)