1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*
* Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ViewClientEfl.h"
#include "EwkView.h"
#include "PageViewportController.h"
#include "WebViewportAttributes.h"
#include <WebKit2/WKString.h>
#include <WebKit2/WKView.h>
#include <WebKit2/WKViewEfl.h>
using namespace EwkViewCallbacks;
using namespace WebCore;
namespace WebKit {
EwkView* ViewClientEfl::toEwkView(const void* clientInfo)
{
return static_cast<ViewClientEfl*>(const_cast<void*>(clientInfo))->m_view;
}
void ViewClientEfl::viewNeedsDisplay(WKViewRef, WKRect, const void* clientInfo)
{
toEwkView(clientInfo)->scheduleUpdateDisplay();
}
void ViewClientEfl::didChangeContentsSize(WKViewRef, WKSize size, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
if (WKPageUseFixedLayout(ewkView->wkPage()))
#if USE(ACCELERATED_COMPOSITING)
ewkView->pageViewportController()->didChangeContentsSize(toIntSize(size));
#else
{ }
#endif
else
ewkView->scheduleUpdateDisplay();
ewkView->smartCallback<ContentsSizeChanged>().call(size);
}
void ViewClientEfl::webProcessCrashed(WKViewRef, WKURLRef url, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
// Check if loading was ongoing, when web process crashed.
double loadProgress = WKPageGetEstimatedProgress(ewkView->wkPage());
if (loadProgress >= 0 && loadProgress < 1) {
loadProgress = 1;
ewkView->smartCallback<LoadProgress>().call(&loadProgress);
}
ewkView->smartCallback<TooltipTextUnset>().call();
bool handled = false;
ewkView->smartCallback<WebProcessCrashed>().call(&handled);
if (!handled) {
WKEinaSharedString urlString(url);
WARN("WARNING: The web process experienced a crash on '%s'.\n", static_cast<const char*>(urlString));
// Display an error page
ewk_view_html_string_load(ewkView->evasObject(), "The web process has crashed.", 0, urlString);
}
}
void ViewClientEfl::webProcessDidRelaunch(WKViewRef viewRef, const void* clientInfo)
{
if (const char* themePath = toEwkView(clientInfo)->themePath())
WKViewSetThemePath(viewRef, adoptWK(WKStringCreateWithUTF8CString(themePath)).get());
}
void ViewClientEfl::didChangeContentsPosition(WKViewRef, WKPoint position, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
if (WKPageUseFixedLayout(ewkView->wkPage())) {
#if USE(ACCELERATED_COMPOSITING)
ewkView->pageViewportController()->pageDidRequestScroll(toIntPoint(position));
#endif
return;
}
ewkView->scheduleUpdateDisplay();
}
void ViewClientEfl::didRenderFrame(WKViewRef, WKSize contentsSize, WKRect coveredRect, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
if (WKPageUseFixedLayout(ewkView->wkPage())) {
#if USE(ACCELERATED_COMPOSITING)
ewkView->pageViewportController()->didRenderFrame(toIntSize(contentsSize), toIntRect(coveredRect));
#endif
return;
}
ewkView->scheduleUpdateDisplay();
}
void ViewClientEfl::didCompletePageTransition(WKViewRef, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
if (WKPageUseFixedLayout(ewkView->wkPage())) {
#if USE(ACCELERATED_COMPOSITING)
ewkView->pageViewportController()->pageTransitionViewportReady();
#endif
return;
}
ewkView->scheduleUpdateDisplay();
}
void ViewClientEfl::didChangeViewportAttributes(WKViewRef, WKViewportAttributesRef attributes, const void* clientInfo)
{
EwkView* ewkView = toEwkView(clientInfo);
if (WKPageUseFixedLayout(ewkView->wkPage())) {
#if USE(ACCELERATED_COMPOSITING)
// FIXME: pageViewportController should accept WKViewportAttributesRef.
ewkView->pageViewportController()->didChangeViewportAttributes(toImpl(attributes)->originalAttributes());
#endif
return;
}
ewkView->scheduleUpdateDisplay();
}
void ViewClientEfl::didChangeTooltip(WKViewRef, WKStringRef tooltip, const void* clientInfo)
{
if (WKStringIsEmpty(tooltip))
toEwkView(clientInfo)->smartCallback<TooltipTextUnset>().call();
else
toEwkView(clientInfo)->smartCallback<TooltipTextSet>().call(WKEinaSharedString(tooltip));
}
void ViewClientEfl::didFindZoomableArea(WKViewRef, WKPoint point, WKRect area, const void* clientInfo)
{
toEwkView(clientInfo)->didFindZoomableArea(point, area);
}
#if ENABLE(TOUCH_EVENTS)
void ViewClientEfl::doneWithTouchEvent(WKViewRef, WKTouchEventRef event, bool wasEventHandled, const void* clientInfo)
{
toEwkView(clientInfo)->doneWithTouchEvent(event, wasEventHandled);
}
#endif
ViewClientEfl::ViewClientEfl(EwkView* view)
: m_view(view)
{
ASSERT(m_view);
WKViewClient viewClient;
memset(&viewClient, 0, sizeof(WKViewClient));
viewClient.version = kWKViewClientCurrentVersion;
viewClient.clientInfo = this;
viewClient.didChangeContentsSize = didChangeContentsSize;
viewClient.didFindZoomableArea = didFindZoomableArea;
viewClient.viewNeedsDisplay = viewNeedsDisplay;
viewClient.webProcessCrashed = webProcessCrashed;
viewClient.webProcessDidRelaunch = webProcessDidRelaunch;
viewClient.didChangeContentsPosition = didChangeContentsPosition;
viewClient.didRenderFrame = didRenderFrame;
viewClient.didCompletePageTransition = didCompletePageTransition;
viewClient.didChangeViewportAttributes = didChangeViewportAttributes;
viewClient.didChangeTooltip = didChangeTooltip;
#if ENABLE(TOUCH_EVENTS)
viewClient.doneWithTouchEvent = doneWithTouchEvent;
#endif
WKViewSetViewClient(m_view->wkView(), &viewClient);
}
ViewClientEfl::~ViewClientEfl()
{
WKViewSetViewClient(m_view->wkView(), 0);
}
} // namespace WebKit
|