1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. 4 * Copyright (C) 2011 Igalia S.L. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25 * THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "config.h" 29#include "PageClientImpl.h" 30 31#include "DrawingAreaProxyImpl.h" 32#include "NativeWebKeyboardEvent.h" 33#include "NativeWebMouseEvent.h" 34#include "NotImplemented.h" 35#include "WebContext.h" 36#include "WebContextMenuProxyGtk.h" 37#include "WebEventFactory.h" 38#include "WebKitWebViewBasePrivate.h" 39#include "WebPageProxy.h" 40#include "WebPopupMenuProxyGtk.h" 41#include <WebCore/Cursor.h> 42#include <WebCore/EventNames.h> 43#include <WebCore/GtkUtilities.h> 44#include <wtf/text/CString.h> 45#include <wtf/text/WTFString.h> 46 47using namespace WebCore; 48 49namespace WebKit { 50 51PageClientImpl::PageClientImpl(GtkWidget* viewWidget) 52 : m_viewWidget(viewWidget) 53{ 54} 55 56PageClientImpl::~PageClientImpl() 57{ 58} 59 60void PageClientImpl::getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent& event, const AtomicString& eventType, Vector<WTF::String>& commandList) 61{ 62 ASSERT(eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent); 63 64 KeyBindingTranslator::EventType type = eventType == eventNames().keydownEvent ? 65 KeyBindingTranslator::KeyDown : KeyBindingTranslator::KeyPress; 66 m_keyBindingTranslator.getEditorCommandsForKeyEvent(const_cast<GdkEventKey*>(&event.nativeEvent()->key), type, commandList); 67} 68 69// PageClient's pure virtual functions 70PassOwnPtr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy() 71{ 72 return DrawingAreaProxyImpl::create(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_viewWidget))); 73} 74 75void PageClientImpl::setViewNeedsDisplay(const WebCore::IntRect& rect) 76{ 77 gtk_widget_queue_draw_area(m_viewWidget, rect.x(), rect.y(), rect.width(), rect.height()); 78} 79 80void PageClientImpl::displayView() 81{ 82 notImplemented(); 83} 84 85void PageClientImpl::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) 86{ 87 setViewNeedsDisplay(scrollRect); 88} 89 90WebCore::IntSize PageClientImpl::viewSize() 91{ 92 if (!gtk_widget_get_realized(m_viewWidget)) 93 return IntSize(); 94 GtkAllocation allocation; 95 gtk_widget_get_allocation(m_viewWidget, &allocation); 96 return IntSize(allocation.width, allocation.height); 97} 98 99bool PageClientImpl::isViewWindowActive() 100{ 101 return webkitWebViewBaseIsInWindowActive(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); 102} 103 104bool PageClientImpl::isViewFocused() 105{ 106 return webkitWebViewBaseIsFocused(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); 107} 108 109bool PageClientImpl::isViewVisible() 110{ 111 return webkitWebViewBaseIsVisible(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); 112} 113 114bool PageClientImpl::isViewInWindow() 115{ 116 return webkitWebViewBaseIsInWindow(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); 117} 118 119void PageClientImpl::PageClientImpl::processDidCrash() 120{ 121 notImplemented(); 122} 123 124void PageClientImpl::didRelaunchProcess() 125{ 126 notImplemented(); 127} 128 129void PageClientImpl::takeFocus(bool) 130{ 131 notImplemented(); 132} 133 134void PageClientImpl::toolTipChanged(const String&, const String& newToolTip) 135{ 136 webkitWebViewBaseSetTooltipText(WEBKIT_WEB_VIEW_BASE(m_viewWidget), newToolTip.utf8().data()); 137} 138 139void PageClientImpl::setCursor(const Cursor& cursor) 140{ 141 if (!gtk_widget_get_realized(m_viewWidget)) 142 return; 143 144 // [GTK] Widget::setCursor() gets called frequently 145 // http://bugs.webkit.org/show_bug.cgi?id=16388 146 // Setting the cursor may be an expensive operation in some backends, 147 // so don't re-set the cursor if it's already set to the target value. 148 GdkWindow* window = gtk_widget_get_window(m_viewWidget); 149 GdkCursor* currentCursor = gdk_window_get_cursor(window); 150 GdkCursor* newCursor = cursor.platformCursor().get(); 151 if (currentCursor != newCursor) 152 gdk_window_set_cursor(window, newCursor); 153} 154 155void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves) 156{ 157 notImplemented(); 158} 159 160void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes&) 161{ 162 notImplemented(); 163} 164 165void PageClientImpl::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo) 166{ 167 notImplemented(); 168} 169 170void PageClientImpl::clearAllEditCommands() 171{ 172 notImplemented(); 173} 174 175bool PageClientImpl::canUndoRedo(WebPageProxy::UndoOrRedo) 176{ 177 notImplemented(); 178 return false; 179} 180 181void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo) 182{ 183 notImplemented(); 184} 185 186FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& viewRect) 187{ 188 notImplemented(); 189 return viewRect; 190} 191 192FloatRect PageClientImpl::convertToUserSpace(const FloatRect& viewRect) 193{ 194 notImplemented(); 195 return viewRect; 196} 197 198IntPoint PageClientImpl::screenToWindow(const IntPoint& point) 199{ 200 IntPoint widgetPositionOnScreen = convertWidgetPointToScreenPoint(m_viewWidget, IntPoint()); 201 IntPoint result(point); 202 result.move(-widgetPositionOnScreen.x(), -widgetPositionOnScreen.y()); 203 return result; 204} 205 206IntRect PageClientImpl::windowToScreen(const IntRect& rect) 207{ 208 return IntRect(convertWidgetPointToScreenPoint(m_viewWidget, rect.location()), rect.size()); 209} 210 211void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool wasEventHandled) 212{ 213 if (wasEventHandled) 214 return; 215 if (event.isFakeEventForComposition()) 216 return; 217 218 WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(m_viewWidget); 219 webkitWebViewBaseForwardNextKeyEvent(webkitWebViewBase); 220 gtk_main_do_event(event.nativeEvent()); 221} 222 223PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy* page) 224{ 225 return WebPopupMenuProxyGtk::create(m_viewWidget, page); 226} 227 228PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page) 229{ 230 return WebContextMenuProxyGtk::create(m_viewWidget, page); 231} 232 233#if ENABLE(INPUT_TYPE_COLOR) 234PassRefPtr<WebColorChooserProxy> PageClientImpl::createColorChooserProxy(WebPageProxy*, const WebCore::Color&, const WebCore::IntRect&) 235{ 236 notImplemented(); 237 return 0; 238} 239#endif 240 241void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut, bool animate) 242{ 243 notImplemented(); 244} 245 246#if USE(ACCELERATED_COMPOSITING) 247void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext&) 248{ 249 notImplemented(); 250} 251 252void PageClientImpl::exitAcceleratedCompositingMode() 253{ 254 notImplemented(); 255} 256 257void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&) 258{ 259 notImplemented(); 260} 261#endif // USE(ACCELERATED_COMPOSITING) 262 263void PageClientImpl::didCommitLoadForMainFrame(bool useCustomRepresentation) 264{ 265} 266 267void PageClientImpl::didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&) 268{ 269} 270 271double PageClientImpl::customRepresentationZoomFactor() 272{ 273 notImplemented(); 274 return 0; 275} 276 277void PageClientImpl::setCustomRepresentationZoomFactor(double) 278{ 279 notImplemented(); 280} 281 282void PageClientImpl::pageClosed() 283{ 284 notImplemented(); 285} 286 287void PageClientImpl::preferencesDidChange() 288{ 289 notImplemented(); 290} 291 292void PageClientImpl::flashBackingStoreUpdates(const Vector<IntRect>&) 293{ 294 notImplemented(); 295} 296 297void PageClientImpl::findStringInCustomRepresentation(const String&, FindOptions, unsigned) 298{ 299 notImplemented(); 300} 301 302void PageClientImpl::countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned) 303{ 304 notImplemented(); 305} 306 307void PageClientImpl::updateTextInputState() 308{ 309 webkitWebViewBaseUpdateTextInputState(WEBKIT_WEB_VIEW_BASE(m_viewWidget)); 310} 311 312void PageClientImpl::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage) 313{ 314 webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), dragData, dragImage); 315} 316 317void PageClientImpl::handleDownloadRequest(DownloadProxy* download) 318{ 319 webkitWebViewBaseHandleDownloadRequest(WEBKIT_WEB_VIEW_BASE(m_viewWidget), download); 320} 321 322} // namespace WebKit 323