2 * Copyright (C) 2012 Samsung Electronics
3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this program; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "ewk_view_private.h"
23 #include "PlatformWebView.h"
26 #include <Ecore_Evas.h>
27 #include <WebCore/RefPtrCairo.h>
28 #include <WebKit/WKImageCairo.h>
29 #include <WebKit/WKViewEfl.h>
32 using namespace WebKit;
36 static Ecore_Evas* initEcoreEvas()
38 Ecore_Evas* ecoreEvas = 0;
39 #if defined(HAVE_ECORE_X)
40 const char* engine = "opengl_x11";
41 ecoreEvas = ecore_evas_new(engine, 0, 0, 800, 600, 0);
42 // Graceful fallback to software rendering if evas_gl engine is not available.
45 ecoreEvas = ecore_evas_new(0, 0, 0, 800, 600, 0);
50 ecore_evas_title_set(ecoreEvas, "EFL WebKitTestRunner");
51 ecore_evas_show(ecoreEvas);
56 PlatformWebView::PlatformWebView(WKPageConfigurationRef configuration, const TestOptions& options)
59 WKRetainPtr<WKStringRef> useFixedLayoutKey(AdoptWK, WKStringCreateWithUTF8CString("UseFixedLayout"));
60 m_usingFixedLayout = options.useFixedLayout;
62 m_window = initEcoreEvas();
64 WKContextRef context = WKPageConfigurationGetContext(configuration);
65 WKPageGroupRef pageGroup = WKPageConfigurationGetPageGroup(configuration);
66 m_view = EWKViewCreate(context, pageGroup, ecore_evas_get(m_window), /* smart */ 0);
68 WKPageSetUseFixedLayout(WKViewGetPage(EWKViewGetWKView(m_view)), m_usingFixedLayout);
70 if (m_usingFixedLayout)
73 ewk_view_theme_set(m_view, DEFAULT_THEME_DIR "/default.edj");
74 m_windowIsKey = false;
75 evas_object_show(m_view);
78 PlatformWebView::~PlatformWebView()
80 evas_object_del(m_view);
82 ecore_evas_free(m_window);
85 void PlatformWebView::resizeTo(unsigned width, unsigned height)
87 // FIXME: Don't we need to resize the window too?
88 evas_object_resize(m_view, width, height);
91 WKPageRef PlatformWebView::page()
93 return WKViewGetPage(EWKViewGetWKView(m_view));
96 void PlatformWebView::focus()
98 // In a few cases, an iframe might receive focus from JavaScript and Evas is not aware of it at all
99 // (WebCoreSupport::focusedFrameChanged() does not emit any notification). We then manually remove the
100 // focus from the view to make the call give focus to evas_object_focus_set(..., true) to be effectful.
101 if (WKPageGetFocusedFrame(page()) != WKPageGetMainFrame(page()))
102 evas_object_focus_set(m_view, false);
103 evas_object_focus_set(m_view, true);
106 WKRect PlatformWebView::windowFrame()
108 int x, y, width, height;
110 ecore_evas_request_geometry_get(m_window, &x, &y, &width, &height);
112 return WKRectMake(x, y, width, height);
115 void PlatformWebView::setWindowFrame(WKRect frame)
117 ecore_evas_move_resize(m_window, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
118 evas_object_resize(m_view, frame.size.width, frame.size.height);
121 void PlatformWebView::addChromeInputField()
125 void PlatformWebView::removeChromeInputField()
129 void PlatformWebView::makeWebViewFirstResponder()
133 void PlatformWebView::changeWindowScaleIfNeeded(float)
137 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
141 ecore_evas_geometry_get(m_window, 0, 0, &width, &height);
142 ASSERT(width > 0 && height > 0);
144 return adoptWK(WKViewCreateSnapshot(EWKViewGetWKView(m_view)));
147 bool PlatformWebView::viewSupportsOptions(const TestOptions& options) const
149 if (m_options.useFixedLayout != options.useFixedLayout)
155 void PlatformWebView::didInitializeClients()
159 void PlatformWebView::setNavigationGesturesEnabled(bool)