| OLD | NEW |
| (Empty) |
| 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 "sky/engine/config.h" | |
| 32 #include "sky/engine/web/PageWidgetDelegate.h" | |
| 33 | |
| 34 #include "sky/engine/core/frame/FrameView.h" | |
| 35 #include "sky/engine/core/frame/LocalFrame.h" | |
| 36 #include "sky/engine/core/page/AutoscrollController.h" | |
| 37 #include "sky/engine/core/page/EventHandler.h" | |
| 38 #include "sky/engine/core/page/Page.h" | |
| 39 #include "sky/engine/core/rendering/RenderView.h" | |
| 40 #include "sky/engine/platform/Logging.h" | |
| 41 #include "sky/engine/platform/graphics/GraphicsContext.h" | |
| 42 #include "sky/engine/public/platform/WebInputEvent.h" | |
| 43 #include "sky/engine/web/WebInputEventConversion.h" | |
| 44 #include "sky/engine/wtf/CurrentTime.h" | |
| 45 | |
| 46 namespace blink { | |
| 47 | |
| 48 static inline FrameView* rootFrameView(Page* page, LocalFrame* rootFrame) | |
| 49 { | |
| 50 if (rootFrame) | |
| 51 return rootFrame->view(); | |
| 52 if (!page) | |
| 53 return 0; | |
| 54 return page->mainFrame()->view(); | |
| 55 } | |
| 56 | |
| 57 void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime, Loc
alFrame* rootFrame) | |
| 58 { | |
| 59 RefPtr<FrameView> view = rootFrameView(page, rootFrame); | |
| 60 WTF_LOG(ScriptedAnimationController, "PageWidgetDelegate::animate: view = %d
", !view ? 0 : 1); | |
| 61 if (!view) | |
| 62 return; | |
| 63 page->autoscrollController().animate(monotonicFrameBeginTime); | |
| 64 page->animator().serviceScriptedAnimations(monotonicFrameBeginTime); | |
| 65 } | |
| 66 | |
| 67 void PageWidgetDelegate::layout(Page* page, LocalFrame* rootFrame) | |
| 68 { | |
| 69 if (!page) | |
| 70 return; | |
| 71 | |
| 72 if (!rootFrame) { | |
| 73 if (!page->mainFrame()) | |
| 74 return; | |
| 75 rootFrame = page->mainFrame(); | |
| 76 } | |
| 77 | |
| 78 page->animator().updateLayoutAndStyleForPainting(rootFrame); | |
| 79 } | |
| 80 | |
| 81 void PageWidgetDelegate::paint(Page* page, WebCanvas* canvas, const WebRect& rec
t, CanvasBackground background, LocalFrame* rootFrame) | |
| 82 { | |
| 83 if (rect.isEmpty()) | |
| 84 return; | |
| 85 GraphicsContext gc(canvas); | |
| 86 gc.setCertainlyOpaque(background == Opaque); | |
| 87 gc.applyDeviceScaleFactor(page->deviceScaleFactor()); | |
| 88 gc.setDeviceScaleFactor(page->deviceScaleFactor()); | |
| 89 IntRect dirtyRect(rect); | |
| 90 gc.save(); // Needed to save the canvas, not the GraphicsContext. | |
| 91 FrameView* view = rootFrameView(page, rootFrame); | |
| 92 if (view) { | |
| 93 gc.clip(dirtyRect); | |
| 94 view->paint(&gc, dirtyRect); | |
| 95 } else { | |
| 96 gc.fillRect(dirtyRect, Color::white); | |
| 97 } | |
| 98 gc.restore(); | |
| 99 } | |
| 100 | |
| 101 bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& ha
ndler, const WebInputEvent& event, LocalFrame* rootFrame) | |
| 102 { | |
| 103 LocalFrame* frame = rootFrame; | |
| 104 if (!frame) | |
| 105 frame = page ? page->mainFrame() : 0; | |
| 106 switch (event.type) { | |
| 107 | |
| 108 // FIXME: WebKit seems to always return false on mouse events processing | |
| 109 // methods. For now we'll assume it has processed them (as we are only | |
| 110 // interested in whether keyboard events are processed). | |
| 111 case WebInputEvent::MouseMove: | |
| 112 if (!frame || !frame->view()) | |
| 113 return true; | |
| 114 handler.handleMouseMove(*frame, static_cast<const WebMouseEvent&>(event)
); | |
| 115 return true; | |
| 116 case WebInputEvent::MouseLeave: | |
| 117 if (!frame || !frame->view()) | |
| 118 return true; | |
| 119 handler.handleMouseLeave(*frame, static_cast<const WebMouseEvent&>(event
)); | |
| 120 return true; | |
| 121 case WebInputEvent::MouseDown: | |
| 122 if (!frame || !frame->view()) | |
| 123 return true; | |
| 124 handler.handleMouseDown(*frame, static_cast<const WebMouseEvent&>(event)
); | |
| 125 return true; | |
| 126 case WebInputEvent::MouseUp: | |
| 127 if (!frame || !frame->view()) | |
| 128 return true; | |
| 129 handler.handleMouseUp(*frame, static_cast<const WebMouseEvent&>(event)); | |
| 130 return true; | |
| 131 | |
| 132 case WebInputEvent::MouseWheel: | |
| 133 if (!frame || !frame->view()) | |
| 134 return false; | |
| 135 return handler.handleMouseWheel(*frame, static_cast<const WebMouseWheelE
vent&>(event)); | |
| 136 | |
| 137 case WebInputEvent::RawKeyDown: | |
| 138 case WebInputEvent::KeyDown: | |
| 139 case WebInputEvent::KeyUp: | |
| 140 return handler.handleKeyEvent(static_cast<const WebKeyboardEvent&>(event
)); | |
| 141 | |
| 142 case WebInputEvent::Char: | |
| 143 return handler.handleCharEvent(static_cast<const WebKeyboardEvent&>(even
t)); | |
| 144 case WebInputEvent::GestureScrollBegin: | |
| 145 case WebInputEvent::GestureScrollEnd: | |
| 146 case WebInputEvent::GestureScrollUpdate: | |
| 147 case WebInputEvent::GestureScrollUpdateWithoutPropagation: | |
| 148 case WebInputEvent::GestureFlingStart: | |
| 149 case WebInputEvent::GestureFlingCancel: | |
| 150 case WebInputEvent::GestureTap: | |
| 151 case WebInputEvent::GestureTapUnconfirmed: | |
| 152 case WebInputEvent::GestureTapDown: | |
| 153 case WebInputEvent::GestureShowPress: | |
| 154 case WebInputEvent::GestureTapCancel: | |
| 155 case WebInputEvent::GestureDoubleTap: | |
| 156 case WebInputEvent::GestureTwoFingerTap: | |
| 157 case WebInputEvent::GestureLongPress: | |
| 158 case WebInputEvent::GestureLongTap: | |
| 159 return handler.handleGestureEvent(static_cast<const WebGestureEvent&>(ev
ent)); | |
| 160 | |
| 161 case WebInputEvent::TouchStart: | |
| 162 case WebInputEvent::TouchMove: | |
| 163 case WebInputEvent::TouchEnd: | |
| 164 case WebInputEvent::TouchCancel: | |
| 165 if (!frame || !frame->view()) | |
| 166 return false; | |
| 167 return handler.handleTouchEvent(*frame, static_cast<const WebTouchEvent&
>(event)); | |
| 168 | |
| 169 case WebInputEvent::GesturePinchBegin: | |
| 170 case WebInputEvent::GesturePinchEnd: | |
| 171 case WebInputEvent::GesturePinchUpdate: | |
| 172 // FIXME: Once PlatformGestureEvent is updated to support pinch, this | |
| 173 // should call handleGestureEvent, just like it currently does for | |
| 174 // gesture scroll. | |
| 175 return false; | |
| 176 | |
| 177 default: | |
| 178 return false; | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 // ---------------------------------------------------------------- | |
| 183 // Default handlers for PageWidgetEventHandler | |
| 184 | |
| 185 void PageWidgetEventHandler::handleMouseMove(LocalFrame& mainFrame, const WebMou
seEvent& event) | |
| 186 { | |
| 187 mainFrame.eventHandler().handleMouseMoveEvent(PlatformMouseEventBuilder(main
Frame.view(), event)); | |
| 188 } | |
| 189 | |
| 190 void PageWidgetEventHandler::handleMouseLeave(LocalFrame& mainFrame, const WebMo
useEvent& event) | |
| 191 { | |
| 192 mainFrame.eventHandler().handleMouseLeaveEvent(PlatformMouseEventBuilder(mai
nFrame.view(), event)); | |
| 193 } | |
| 194 | |
| 195 void PageWidgetEventHandler::handleMouseDown(LocalFrame& mainFrame, const WebMou
seEvent& event) | |
| 196 { | |
| 197 mainFrame.eventHandler().handleMousePressEvent(PlatformMouseEventBuilder(mai
nFrame.view(), event)); | |
| 198 } | |
| 199 | |
| 200 void PageWidgetEventHandler::handleMouseUp(LocalFrame& mainFrame, const WebMouse
Event& event) | |
| 201 { | |
| 202 mainFrame.eventHandler().handleMouseReleaseEvent(PlatformMouseEventBuilder(m
ainFrame.view(), event)); | |
| 203 } | |
| 204 | |
| 205 bool PageWidgetEventHandler::handleMouseWheel(LocalFrame& mainFrame, const WebMo
useWheelEvent& event) | |
| 206 { | |
| 207 return mainFrame.eventHandler().handleWheelEvent(PlatformWheelEventBuilder(m
ainFrame.view(), event)); | |
| 208 } | |
| 209 | |
| 210 bool PageWidgetEventHandler::handleTouchEvent(LocalFrame& mainFrame, const WebTo
uchEvent& event) | |
| 211 { | |
| 212 return mainFrame.eventHandler().handleTouchEvent(PlatformTouchEventBuilder(m
ainFrame.view(), event)); | |
| 213 } | |
| 214 | |
| 215 } // namespace blink | |
| OLD | NEW |