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 "PageWidgetDelegate.h"
34 #include "PageOverlayList.h"
35 #include "WebInputEvent.h"
36 #include "WebInputEventConversion.h"
37 #include "core/frame/FrameView.h"
38 #include "core/frame/LocalFrame.h"
39 #include "core/page/AutoscrollController.h"
40 #include "core/page/EventHandler.h"
41 #include "core/rendering/RenderView.h"
42 #include "core/rendering/compositing/RenderLayerCompositor.h"
43 #include "platform/graphics/GraphicsContext.h"
44 #include "wtf/CurrentTime.h"
46 using namespace WebCore;
50 static inline FrameView* mainFrameView(Page* page)
54 // FIXME: Can we remove this check?
55 if (!page->mainFrame())
57 return page->mainFrame()->view();
60 void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime)
62 RefPtr<FrameView> view = mainFrameView(page);
65 page->autoscrollController().animate(monotonicFrameBeginTime);
66 page->animator().serviceScriptedAnimations(monotonicFrameBeginTime);
69 void PageWidgetDelegate::layout(Page* page)
71 if (!page || !page->mainFrame())
73 page->animator().updateLayoutAndStyleForPainting();
76 void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background)
80 GraphicsContext gc(canvas);
81 gc.setCertainlyOpaque(background == Opaque);
82 gc.applyDeviceScaleFactor(page->deviceScaleFactor());
83 gc.setUseHighResMarkers(page->deviceScaleFactor() > 1.5f);
84 IntRect dirtyRect(rect);
85 gc.save(); // Needed to save the canvas, not the GraphicsContext.
86 FrameView* view = mainFrameView(page);
87 // FIXME: Can we remove the mainFrame()->document() check?
88 if (view && page->mainFrame()->document()) {
90 view->paint(&gc, dirtyRect);
92 overlays->paintWebFrame(gc);
94 gc.fillRect(dirtyRect, Color::white);
99 bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event)
101 LocalFrame* frame = page ? page->mainFrame() : 0;
102 switch (event.type) {
104 // FIXME: WebKit seems to always return false on mouse events processing
105 // methods. For now we'll assume it has processed them (as we are only
106 // interested in whether keyboard events are processed).
107 case WebInputEvent::MouseMove:
108 if (!frame || !frame->view())
110 handler.handleMouseMove(*frame, *static_cast<const WebMouseEvent*>(&event));
112 case WebInputEvent::MouseLeave:
113 if (!frame || !frame->view())
115 handler.handleMouseLeave(*frame, *static_cast<const WebMouseEvent*>(&event));
117 case WebInputEvent::MouseDown:
118 if (!frame || !frame->view())
120 handler.handleMouseDown(*frame, *static_cast<const WebMouseEvent*>(&event));
122 case WebInputEvent::MouseUp:
123 if (!frame || !frame->view())
125 handler.handleMouseUp(*frame, *static_cast<const WebMouseEvent*>(&event));
128 case WebInputEvent::MouseWheel:
129 if (!frame || !frame->view())
131 return handler.handleMouseWheel(*frame, *static_cast<const WebMouseWheelEvent*>(&event));
133 case WebInputEvent::RawKeyDown:
134 case WebInputEvent::KeyDown:
135 case WebInputEvent::KeyUp:
136 return handler.handleKeyEvent(*static_cast<const WebKeyboardEvent*>(&event));
138 case WebInputEvent::Char:
139 return handler.handleCharEvent(*static_cast<const WebKeyboardEvent*>(&event));
140 case WebInputEvent::GestureScrollBegin:
141 case WebInputEvent::GestureScrollEnd:
142 case WebInputEvent::GestureScrollUpdate:
143 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
144 case WebInputEvent::GestureFlingStart:
145 case WebInputEvent::GestureFlingCancel:
146 case WebInputEvent::GestureTap:
147 case WebInputEvent::GestureTapUnconfirmed:
148 case WebInputEvent::GestureTapDown:
149 case WebInputEvent::GestureShowPress:
150 case WebInputEvent::GestureTapCancel:
151 case WebInputEvent::GestureDoubleTap:
152 case WebInputEvent::GestureTwoFingerTap:
153 case WebInputEvent::GestureLongPress:
154 case WebInputEvent::GestureLongTap:
155 return handler.handleGestureEvent(*static_cast<const WebGestureEvent*>(&event));
157 case WebInputEvent::TouchStart:
158 case WebInputEvent::TouchMove:
159 case WebInputEvent::TouchEnd:
160 case WebInputEvent::TouchCancel:
161 if (!frame || !frame->view())
163 return handler.handleTouchEvent(*frame, *static_cast<const WebTouchEvent*>(&event));
165 case WebInputEvent::GesturePinchBegin:
166 case WebInputEvent::GesturePinchEnd:
167 case WebInputEvent::GesturePinchUpdate:
168 // FIXME: Once PlatformGestureEvent is updated to support pinch, this
169 // should call handleGestureEvent, just like it currently does for
178 // ----------------------------------------------------------------
179 // Default handlers for PageWidgetEventHandler
181 void PageWidgetEventHandler::handleMouseMove(LocalFrame& mainFrame, const WebMouseEvent& event)
183 mainFrame.eventHandler().handleMouseMoveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
186 void PageWidgetEventHandler::handleMouseLeave(LocalFrame& mainFrame, const WebMouseEvent& event)
188 mainFrame.eventHandler().handleMouseLeaveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
191 void PageWidgetEventHandler::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& event)
193 mainFrame.eventHandler().handleMousePressEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
196 void PageWidgetEventHandler::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& event)
198 mainFrame.eventHandler().handleMouseReleaseEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
201 bool PageWidgetEventHandler::handleMouseWheel(LocalFrame& mainFrame, const WebMouseWheelEvent& event)
203 return mainFrame.eventHandler().handleWheelEvent(PlatformWheelEventBuilder(mainFrame.view(), event));
206 bool PageWidgetEventHandler::handleTouchEvent(LocalFrame& mainFrame, const WebTouchEvent& event)
208 return mainFrame.eventHandler().handleTouchEvent(PlatformTouchEventBuilder(mainFrame.view(), event));