2 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Copyright (C) 2008 Kenneth Rohde Christiansen
5 * Copyright (C) 2008 Diego Gonzalez
6 * Copyright (C) 2009-2010 ProFUSION embedded systems
7 * Copyright (C) 2009-2010 Samsung Electronics
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
29 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "ChromeClientEfl.h"
38 #include "DatabaseDetails.h"
39 #include "DatabaseTracker.h"
42 #include "FileChooser.h"
43 #include "FileIconLoader.h"
44 #include "FloatRect.h"
45 #include "FrameLoader.h"
46 #include "FrameLoaderClientEfl.h"
47 #include "HitTestResult.h"
50 #include "NavigationAction.h"
51 #if ENABLE(NOTIFICATIONS)
52 #include "NotificationPresenterClientEfl.h"
54 #include "NotImplemented.h"
55 #include "PlatformString.h"
56 #include "PopupMenuEfl.h"
57 #include "SearchPopupMenuEfl.h"
58 #include "SecurityOrigin.h"
59 #include "ViewportArguments.h"
60 #include "WindowFeatures.h"
61 #include "ewk_private.h"
62 #include <Ecore_Evas.h>
64 #include <wtf/text/CString.h>
66 using namespace WebCore;
68 static inline Evas_Object* kit(Frame* frame)
73 FrameLoaderClientEfl* client = static_cast<FrameLoaderClientEfl*>(frame->loader()->client());
74 return client ? client->webFrame() : 0;
79 ChromeClientEfl::ChromeClientEfl(Evas_Object* view)
85 ChromeClientEfl::~ChromeClientEfl()
89 void ChromeClientEfl::chromeDestroyed()
94 void ChromeClientEfl::focusedNodeChanged(Node*)
99 void ChromeClientEfl::focusedFrameChanged(Frame*)
103 FloatRect ChromeClientEfl::windowRect()
108 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_view));
109 ecore_evas_geometry_get(ee, &x, &y, &w, &h);
110 return FloatRect(x, y, w, h);
113 void ChromeClientEfl::setWindowRect(const FloatRect& rect)
115 if (!ewk_view_setting_enable_auto_resize_window_get(m_view))
119 IntRect intrect = IntRect(rect);
121 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_view));
122 ecore_evas_move(ee, intrect.x(), intrect.y());
123 ecore_evas_resize(ee, intrect.width(), intrect.height());
126 FloatRect ChromeClientEfl::pageRect()
128 return ewk_view_page_rect_get(m_view);
131 void ChromeClientEfl::focus()
133 evas_object_focus_set(m_view, EINA_TRUE);
136 void ChromeClientEfl::unfocus()
138 evas_object_focus_set(m_view, EINA_FALSE);
141 Page* ChromeClientEfl::createWindow(Frame*, const FrameLoadRequest& frameLoadRequest, const WindowFeatures& features, const NavigationAction&)
143 Evas_Object* newView = ewk_view_window_create(m_view, EINA_TRUE, &features);
147 return ewk_view_core_page_get(newView);
150 void ChromeClientEfl::show()
152 ewk_view_ready(m_view);
155 bool ChromeClientEfl::canRunModal()
161 void ChromeClientEfl::runModal()
166 void ChromeClientEfl::setToolbarsVisible(bool visible)
168 ewk_view_toolbars_visible_set(m_view, visible);
171 bool ChromeClientEfl::toolbarsVisible()
175 ewk_view_toolbars_visible_get(m_view, &visible);
179 void ChromeClientEfl::setStatusbarVisible(bool visible)
181 ewk_view_statusbar_visible_set(m_view, visible);
184 bool ChromeClientEfl::statusbarVisible()
188 ewk_view_statusbar_visible_get(m_view, &visible);
192 void ChromeClientEfl::setScrollbarsVisible(bool visible)
194 ewk_view_scrollbars_visible_set(m_view, visible);
197 bool ChromeClientEfl::scrollbarsVisible()
201 ewk_view_scrollbars_visible_get(m_view, &visible);
205 void ChromeClientEfl::setMenubarVisible(bool visible)
207 ewk_view_menubar_visible_set(m_view, visible);
210 bool ChromeClientEfl::menubarVisible()
214 ewk_view_menubar_visible_get(m_view, &visible);
218 void ChromeClientEfl::createSelectPopup(PopupMenuClient* client, int selected, const IntRect& rect)
220 ewk_view_popup_new(m_view, client, selected, rect);
223 bool ChromeClientEfl::destroySelectPopup()
225 return ewk_view_popup_destroy(m_view);
228 void ChromeClientEfl::setResizable(bool)
233 void ChromeClientEfl::closeWindowSoon()
235 ewk_view_window_close(m_view);
238 bool ChromeClientEfl::canTakeFocus(FocusDirection)
240 // This is called when cycling through links/focusable objects and we
241 // reach the last focusable object.
245 void ChromeClientEfl::takeFocus(FocusDirection)
250 bool ChromeClientEfl::canRunBeforeUnloadConfirmPanel()
255 bool ChromeClientEfl::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
257 return runJavaScriptConfirm(frame, message);
260 void ChromeClientEfl::addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message,
261 unsigned int lineNumber, const String& sourceID)
263 ewk_view_add_console_message(m_view, message.utf8().data(), lineNumber, sourceID.utf8().data());
266 void ChromeClientEfl::runJavaScriptAlert(Frame* frame, const String& message)
268 ewk_view_run_javascript_alert(m_view, kit(frame), message.utf8().data());
271 bool ChromeClientEfl::runJavaScriptConfirm(Frame* frame, const String& message)
273 return ewk_view_run_javascript_confirm(m_view, kit(frame), message.utf8().data());
276 bool ChromeClientEfl::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
279 ewk_view_run_javascript_prompt(m_view, kit(frame), message.utf8().data(), defaultValue.utf8().data(), &value);
281 result = String::fromUTF8(value);
288 void ChromeClientEfl::setStatusbarText(const String& string)
290 ewk_view_statusbar_text_set(m_view, string.utf8().data());
293 bool ChromeClientEfl::shouldInterruptJavaScript()
295 return ewk_view_should_interrupt_javascript(m_view);
298 KeyboardUIMode ChromeClientEfl::keyboardUIMode()
300 return KeyboardAccessTabsToLinks;
303 IntRect ChromeClientEfl::windowResizerRect() const
306 // Implementing this function will make repaint being
307 // called during resize, but as this will be done with
308 // a minor delay it adds a weird "filling" effect due
309 // to us using an evas image for showing the cairo
310 // context. So instead of implementing this function
311 // we call paint directly during resize with
312 // the new object size as its argument.
316 void ChromeClientEfl::contentsSizeChanged(Frame* frame, const IntSize& size) const
318 ewk_frame_contents_size_changed(kit(frame), size.width(), size.height());
319 if (ewk_view_frame_main_get(m_view) == kit(frame))
320 ewk_view_contents_size_changed(m_view, size.width(), size.height());
323 IntRect ChromeClientEfl::windowToScreen(const IntRect& rect) const
329 IntPoint ChromeClientEfl::screenToWindow(const IntPoint& point) const
335 PlatformPageClient ChromeClientEfl::platformPageClient() const
340 void ChromeClientEfl::scrollbarsModeDidChange() const
344 void ChromeClientEfl::mouseDidMoveOverElement(const HitTestResult& hit, unsigned modifierFlags)
346 // FIXME, compare with old link, look at Qt impl.
347 bool isLink = hit.isLiveLink();
349 KURL url = hit.absoluteLinkURL();
350 if (!url.isEmpty() && url != m_hoveredLinkURL) {
353 CString urlStr = url.string().utf8();
354 CString titleStr = hit.title(dir).utf8();
355 link[0] = urlStr.data();
356 link[1] = titleStr.data();
357 ewk_view_mouse_link_hover_in(m_view, link);
358 m_hoveredLinkURL = url;
360 } else if (!isLink && !m_hoveredLinkURL.isEmpty()) {
361 ewk_view_mouse_link_hover_out(m_view);
362 m_hoveredLinkURL = KURL();
366 void ChromeClientEfl::setToolTip(const String& toolTip, TextDirection)
368 ewk_view_tooltip_text_set(m_view, toolTip.utf8().data());
371 void ChromeClientEfl::print(Frame* frame)
376 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
377 void ChromeClientEfl::reachedMaxAppCacheSize(int64_t spaceNeeded)
379 // FIXME: Free some space.
383 void ChromeClientEfl::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
389 #if ENABLE(TOUCH_EVENTS)
390 void ChromeClientEfl::needTouchEvents(bool needed)
392 ewk_view_need_touch_events_set(m_view, needed);
397 void ChromeClientEfl::exceededDatabaseQuota(Frame* frame, const String& databaseName)
400 SecurityOrigin* origin = frame->document()->securityOrigin();
402 DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(databaseName, origin);
403 quota = ewk_view_exceeded_database_quota(m_view,
404 kit(frame), databaseName.utf8().data(),
405 details.currentUsage(), details.expectedUsage());
407 /* if client did not set quota, and database is being created now, the
408 * default quota is applied
410 if (!quota && !DatabaseTracker::tracker().hasEntryForOrigin(origin))
411 quota = ewk_settings_web_database_default_quota_get();
413 DatabaseTracker::tracker().setQuota(origin, quota);
417 #if ENABLE(NOTIFICATIONS)
418 NotificationPresenter* ChromeClientEfl::notificationPresenter() const
425 void ChromeClientEfl::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser)
427 RefPtr<FileChooser> chooser = prpFileChooser;
429 Eina_List* selectedFilenames = 0;
431 Vector<String> filenames;
433 CString accept = chooser->settings().acceptTypes.utf8();
434 confirm = ewk_view_run_open_panel(m_view, kit(frame), chooser->settings().allowsMultipleFiles, accept.data(), &selectedFilenames);
439 EINA_LIST_FREE(selectedFilenames, filename) {
440 filenames.append((char *)filename);
444 if (chooser->settings().allowsMultipleFiles)
445 chooser->chooseFiles(filenames);
447 chooser->chooseFile(filenames[0]);
450 void ChromeClientEfl::formStateDidChange(const Node*)
455 void ChromeClientEfl::setCursor(const Cursor&)
460 void ChromeClientEfl::setCursorHiddenUntilMouseMoves(bool)
465 void ChromeClientEfl::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
467 // See the comment in WebCore/page/ChromeClient.h
471 void ChromeClientEfl::cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*)
476 void ChromeClientEfl::cancelGeolocationPermissionForFrame(Frame*, Geolocation*)
481 void ChromeClientEfl::invalidateContents(const IntRect& updateRect, bool immediate)
486 void ChromeClientEfl::invalidateWindow(const IntRect& updateRect, bool immediate)
491 void ChromeClientEfl::invalidateContentsAndWindow(const IntRect& updateRect, bool immediate)
493 if (updateRect.isEmpty())
496 Evas_Coord x, y, w, h;
500 w = updateRect.width();
501 h = updateRect.height();
502 ewk_view_repaint(m_view, x, y, w, h);
505 void ChromeClientEfl::invalidateContentsForSlowScroll(const IntRect& updateRect, bool immediate)
507 invalidateContentsAndWindow(updateRect, immediate);
510 void ChromeClientEfl::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
512 ewk_view_scroll(m_view, scrollDelta.width(), scrollDelta.height(), rectToScroll.x(), rectToScroll.y(), rectToScroll.width(), rectToScroll.height(), clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height(), EINA_TRUE);
515 void ChromeClientEfl::cancelGeolocationPermissionRequestForFrame(Frame*)
520 void ChromeClientEfl::iconForFiles(const Vector<String, 0u>&, PassRefPtr<FileChooser>)
525 void ChromeClientEfl::loadIconForFiles(const Vector<String>&, FileIconLoader*)
530 void ChromeClientEfl::dispatchViewportDataDidChange(const ViewportArguments& arguments) const
532 ewk_view_viewport_attributes_set(m_view, arguments);
535 bool ChromeClientEfl::selectItemWritingDirectionIsNatural()
540 bool ChromeClientEfl::selectItemAlignmentFollowsMenuWritingDirection()
545 PassRefPtr<PopupMenu> ChromeClientEfl::createPopupMenu(PopupMenuClient* client) const
547 return adoptRef(new PopupMenuEfl(client));
550 PassRefPtr<SearchPopupMenu> ChromeClientEfl::createSearchPopupMenu(PopupMenuClient* client) const
552 return adoptRef(new SearchPopupMenuEfl(client));
555 #if USE(ACCELERATED_COMPOSITING)
556 void ChromeClientEfl::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* rootLayer)
561 void ChromeClientEfl::setNeedsOneShotDrawingSynchronization()
566 void ChromeClientEfl::scheduleCompositingLayerSync()
571 ChromeClient::CompositingTriggerFlags ChromeClientEfl::allowedCompositingTriggers() const
577 #if ENABLE(FULLSCREEN_API)
578 bool ChromeClientEfl::supportsFullScreenForElement(const WebCore::Element* element, bool withKeyboard)
586 void ChromeClientEfl::enterFullScreenForElement(WebCore::Element* element)
588 element->document()->webkitWillEnterFullScreenForElement(element);
589 element->document()->webkitDidEnterFullScreenForElement(element);
592 void ChromeClientEfl::exitFullScreenForElement(WebCore::Element* element)
594 element->document()->webkitWillExitFullScreenForElement(element);
595 element->document()->webkitDidExitFullScreenForElement(element);