2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "web/PageWidgetDelegate.h"
34 #include "core/frame/FrameView.h"
35 #include "core/frame/LocalFrame.h"
36 #include "core/page/AutoscrollController.h"
37 #include "core/page/EventHandler.h"
38 #include "core/page/Page.h"
39 #include "core/rendering/RenderView.h"
40 #include "core/rendering/compositing/RenderLayerCompositor.h"
41 #include "platform/graphics/GraphicsContext.h"
42 #include "public/web/WebInputEvent.h"
43 #include "web/PageOverlayList.h"
44 #include "web/WebInputEventConversion.h"
45 #include "wtf/CurrentTime.h"
49 static inline FrameView* mainFrameView(Page* page)
53 // FIXME: Can we remove this check?
54 if (!page->mainFrame())
56 if (!page->mainFrame()->isLocalFrame())
58 return page->deprecatedLocalMainFrame()->view();
61 void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime)
63 RefPtr<FrameView> view = mainFrameView(page);
66 page->autoscrollController().animate(monotonicFrameBeginTime);
67 page->animator().serviceScriptedAnimations(monotonicFrameBeginTime);
70 void PageWidgetDelegate::layout(Page* page, LocalFrame* rootFrame)
76 if (!page->mainFrame() || !page->mainFrame()->isLocalFrame())
78 rootFrame = toLocalFrame(page->mainFrame());
81 page->animator().updateLayoutAndStyleForPainting(rootFrame);
84 void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background)
88 GraphicsContext gc(canvas);
89 gc.setCertainlyOpaque(background == Opaque);
90 gc.applyDeviceScaleFactor(page->deviceScaleFactor());
91 gc.setDeviceScaleFactor(page->deviceScaleFactor());
92 IntRect dirtyRect(rect);
93 gc.save(); // Needed to save the canvas, not the GraphicsContext.
94 FrameView* view = mainFrameView(page);
95 // FIXME: Can we remove the mainFrame()->document() check?
96 if (view && page->deprecatedLocalMainFrame()->document()) {
98 view->paint(&gc, dirtyRect);
100 overlays->paintWebFrame(gc);
102 gc.fillRect(dirtyRect, Color::white);
107 bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event)
109 LocalFrame* frame = page && page->mainFrame()->isLocalFrame() ? page->deprecatedLocalMainFrame() : 0;
110 switch (event.type) {
112 // FIXME: WebKit seems to always return false on mouse events processing
113 // methods. For now we'll assume it has processed them (as we are only
114 // interested in whether keyboard events are processed).
115 case WebInputEvent::MouseMove:
116 if (!frame || !frame->view())
118 handler.handleMouseMove(*frame, static_cast<const WebMouseEvent&>(event));
120 case WebInputEvent::MouseLeave:
121 if (!frame || !frame->view())
123 handler.handleMouseLeave(*frame, static_cast<const WebMouseEvent&>(event));
125 case WebInputEvent::MouseDown:
126 if (!frame || !frame->view())
128 handler.handleMouseDown(*frame, static_cast<const WebMouseEvent&>(event));
130 case WebInputEvent::MouseUp:
131 if (!frame || !frame->view())
133 handler.handleMouseUp(*frame, static_cast<const WebMouseEvent&>(event));
136 case WebInputEvent::MouseWheel:
137 if (!frame || !frame->view())
139 return handler.handleMouseWheel(*frame, static_cast<const WebMouseWheelEvent&>(event));
141 case WebInputEvent::RawKeyDown:
142 case WebInputEvent::KeyDown:
143 case WebInputEvent::KeyUp:
144 return handler.handleKeyEvent(static_cast<const WebKeyboardEvent&>(event));
146 case WebInputEvent::Char:
147 return handler.handleCharEvent(static_cast<const WebKeyboardEvent&>(event));
148 case WebInputEvent::GestureScrollBegin:
149 case WebInputEvent::GestureScrollEnd:
150 case WebInputEvent::GestureScrollUpdate:
151 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
152 case WebInputEvent::GestureFlingStart:
153 case WebInputEvent::GestureFlingCancel:
154 case WebInputEvent::GestureTap:
155 case WebInputEvent::GestureTapUnconfirmed:
156 case WebInputEvent::GestureTapDown:
157 case WebInputEvent::GestureShowPress:
158 case WebInputEvent::GestureTapCancel:
159 case WebInputEvent::GestureDoubleTap:
160 case WebInputEvent::GestureTwoFingerTap:
161 case WebInputEvent::GestureLongPress:
162 case WebInputEvent::GestureLongTap:
163 return handler.handleGestureEvent(static_cast<const WebGestureEvent&>(event));
165 case WebInputEvent::TouchStart:
166 case WebInputEvent::TouchMove:
167 case WebInputEvent::TouchEnd:
168 case WebInputEvent::TouchCancel:
169 if (!frame || !frame->view())
171 return handler.handleTouchEvent(*frame, static_cast<const WebTouchEvent&>(event));
173 case WebInputEvent::GesturePinchBegin:
174 case WebInputEvent::GesturePinchEnd:
175 case WebInputEvent::GesturePinchUpdate:
176 // FIXME: Once PlatformGestureEvent is updated to support pinch, this
177 // should call handleGestureEvent, just like it currently does for
186 // ----------------------------------------------------------------
187 // Default handlers for PageWidgetEventHandler
189 void PageWidgetEventHandler::handleMouseMove(LocalFrame& mainFrame, const WebMouseEvent& event)
191 mainFrame.eventHandler().handleMouseMoveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
194 void PageWidgetEventHandler::handleMouseLeave(LocalFrame& mainFrame, const WebMouseEvent& event)
196 mainFrame.eventHandler().handleMouseLeaveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
199 void PageWidgetEventHandler::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& event)
201 mainFrame.eventHandler().handleMousePressEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
204 void PageWidgetEventHandler::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& event)
206 mainFrame.eventHandler().handleMouseReleaseEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
209 bool PageWidgetEventHandler::handleMouseWheel(LocalFrame& mainFrame, const WebMouseWheelEvent& event)
211 return mainFrame.eventHandler().handleWheelEvent(PlatformWheelEventBuilder(mainFrame.view(), event));
214 bool PageWidgetEventHandler::handleTouchEvent(LocalFrame& mainFrame, const WebTouchEvent& event)
216 return mainFrame.eventHandler().handleTouchEvent(PlatformTouchEventBuilder(mainFrame.view(), event));