• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 
31 #include "config.h"
32 #include "web/PageWidgetDelegate.h"
33 
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/rendering/RenderView.h"
39 #include "core/rendering/compositing/RenderLayerCompositor.h"
40 #include "platform/graphics/GraphicsContext.h"
41 #include "public/web/WebInputEvent.h"
42 #include "web/PageOverlayList.h"
43 #include "web/WebInputEventConversion.h"
44 #include "wtf/CurrentTime.h"
45 
46 using namespace WebCore;
47 
48 namespace blink {
49 
mainFrameView(Page * page)50 static inline FrameView* mainFrameView(Page* page)
51 {
52     if (!page)
53         return 0;
54     // FIXME: Can we remove this check?
55     if (!page->mainFrame())
56         return 0;
57     if (!page->mainFrame()->isLocalFrame())
58         return 0;
59     return page->deprecatedLocalMainFrame()->view();
60 }
61 
animate(Page * page,double monotonicFrameBeginTime)62 void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime)
63 {
64     RefPtr<FrameView> view = mainFrameView(page);
65     if (!view)
66         return;
67     page->autoscrollController().animate(monotonicFrameBeginTime);
68     page->animator().serviceScriptedAnimations(monotonicFrameBeginTime);
69 }
70 
layout(Page * page)71 void PageWidgetDelegate::layout(Page* page)
72 {
73     if (!page || !page->mainFrame())
74         return;
75     page->animator().updateLayoutAndStyleForPainting();
76 }
77 
paint(Page * page,PageOverlayList * overlays,WebCanvas * canvas,const WebRect & rect,CanvasBackground background)78 void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background)
79 {
80     if (rect.isEmpty())
81         return;
82     GraphicsContext gc(canvas);
83     gc.setCertainlyOpaque(background == Opaque);
84     gc.applyDeviceScaleFactor(page->deviceScaleFactor());
85     gc.setUseHighResMarkers(page->deviceScaleFactor() > 1.5f);
86     IntRect dirtyRect(rect);
87     gc.save(); // Needed to save the canvas, not the GraphicsContext.
88     FrameView* view = mainFrameView(page);
89     // FIXME: Can we remove the mainFrame()->document() check?
90     if (view && page->deprecatedLocalMainFrame()->document()) {
91         gc.clip(dirtyRect);
92         view->paint(&gc, dirtyRect);
93         if (overlays)
94             overlays->paintWebFrame(gc);
95     } else {
96         gc.fillRect(dirtyRect, Color::white);
97     }
98     gc.restore();
99 }
100 
handleInputEvent(Page * page,PageWidgetEventHandler & handler,const WebInputEvent & event)101 bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event)
102 {
103     LocalFrame* frame = page && page->mainFrame()->isLocalFrame() ? page->deprecatedLocalMainFrame() : 0;
104     switch (event.type) {
105 
106     // FIXME: WebKit seems to always return false on mouse events processing
107     // methods. For now we'll assume it has processed them (as we are only
108     // interested in whether keyboard events are processed).
109     case WebInputEvent::MouseMove:
110         if (!frame || !frame->view())
111             return true;
112         handler.handleMouseMove(*frame, *static_cast<const WebMouseEvent*>(&event));
113         return true;
114     case WebInputEvent::MouseLeave:
115         if (!frame || !frame->view())
116             return true;
117         handler.handleMouseLeave(*frame, *static_cast<const WebMouseEvent*>(&event));
118         return true;
119     case WebInputEvent::MouseDown:
120         if (!frame || !frame->view())
121             return true;
122         handler.handleMouseDown(*frame, *static_cast<const WebMouseEvent*>(&event));
123         return true;
124     case WebInputEvent::MouseUp:
125         if (!frame || !frame->view())
126             return true;
127         handler.handleMouseUp(*frame, *static_cast<const WebMouseEvent*>(&event));
128         return true;
129 
130     case WebInputEvent::MouseWheel:
131         if (!frame || !frame->view())
132             return false;
133         return handler.handleMouseWheel(*frame, *static_cast<const WebMouseWheelEvent*>(&event));
134 
135     case WebInputEvent::RawKeyDown:
136     case WebInputEvent::KeyDown:
137     case WebInputEvent::KeyUp:
138         return handler.handleKeyEvent(*static_cast<const WebKeyboardEvent*>(&event));
139 
140     case WebInputEvent::Char:
141         return handler.handleCharEvent(*static_cast<const WebKeyboardEvent*>(&event));
142     case WebInputEvent::GestureScrollBegin:
143     case WebInputEvent::GestureScrollEnd:
144     case WebInputEvent::GestureScrollUpdate:
145     case WebInputEvent::GestureScrollUpdateWithoutPropagation:
146     case WebInputEvent::GestureFlingStart:
147     case WebInputEvent::GestureFlingCancel:
148     case WebInputEvent::GestureTap:
149     case WebInputEvent::GestureTapUnconfirmed:
150     case WebInputEvent::GestureTapDown:
151     case WebInputEvent::GestureShowPress:
152     case WebInputEvent::GestureTapCancel:
153     case WebInputEvent::GestureDoubleTap:
154     case WebInputEvent::GestureTwoFingerTap:
155     case WebInputEvent::GestureLongPress:
156     case WebInputEvent::GestureLongTap:
157         return handler.handleGestureEvent(*static_cast<const WebGestureEvent*>(&event));
158 
159     case WebInputEvent::TouchStart:
160     case WebInputEvent::TouchMove:
161     case WebInputEvent::TouchEnd:
162     case WebInputEvent::TouchCancel:
163         if (!frame || !frame->view())
164             return false;
165         return handler.handleTouchEvent(*frame, *static_cast<const WebTouchEvent*>(&event));
166 
167     case WebInputEvent::GesturePinchBegin:
168     case WebInputEvent::GesturePinchEnd:
169     case WebInputEvent::GesturePinchUpdate:
170         // FIXME: Once PlatformGestureEvent is updated to support pinch, this
171         // should call handleGestureEvent, just like it currently does for
172         // gesture scroll.
173         return false;
174 
175     default:
176         return false;
177     }
178 }
179 
180 // ----------------------------------------------------------------
181 // Default handlers for PageWidgetEventHandler
182 
handleMouseMove(LocalFrame & mainFrame,const WebMouseEvent & event)183 void PageWidgetEventHandler::handleMouseMove(LocalFrame& mainFrame, const WebMouseEvent& event)
184 {
185     mainFrame.eventHandler().handleMouseMoveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
186 }
187 
handleMouseLeave(LocalFrame & mainFrame,const WebMouseEvent & event)188 void PageWidgetEventHandler::handleMouseLeave(LocalFrame& mainFrame, const WebMouseEvent& event)
189 {
190     mainFrame.eventHandler().handleMouseLeaveEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
191 }
192 
handleMouseDown(LocalFrame & mainFrame,const WebMouseEvent & event)193 void PageWidgetEventHandler::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& event)
194 {
195     mainFrame.eventHandler().handleMousePressEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
196 }
197 
handleMouseUp(LocalFrame & mainFrame,const WebMouseEvent & event)198 void PageWidgetEventHandler::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& event)
199 {
200     mainFrame.eventHandler().handleMouseReleaseEvent(PlatformMouseEventBuilder(mainFrame.view(), event));
201 }
202 
handleMouseWheel(LocalFrame & mainFrame,const WebMouseWheelEvent & event)203 bool PageWidgetEventHandler::handleMouseWheel(LocalFrame& mainFrame, const WebMouseWheelEvent& event)
204 {
205     return mainFrame.eventHandler().handleWheelEvent(PlatformWheelEventBuilder(mainFrame.view(), event));
206 }
207 
handleTouchEvent(LocalFrame & mainFrame,const WebTouchEvent & event)208 bool PageWidgetEventHandler::handleTouchEvent(LocalFrame& mainFrame, const WebTouchEvent& event)
209 {
210     return mainFrame.eventHandler().handleTouchEvent(PlatformTouchEventBuilder(mainFrame.view(), event));
211 }
212 
213 }
214