diff --git a/Source/web/PageWidgetDelegate.cpp b/Source/web/PageWidgetDelegate.cpp index 621091ce839..0f7e4d4bcda 100644 --- a/Source/web/PageWidgetDelegate.cpp +++ b/Source/web/PageWidgetDelegate.cpp @@ -47,24 +47,41 @@ namespace blink { -void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime, LocalFrame* root) +static inline FrameView* rootFrameView(Page* page, LocalFrame* rootFrame) { - RefPtr view = root->view(); + if (rootFrame) + return rootFrame->view(); + if (!page) + return 0; + if (!page->mainFrame()->isLocalFrame()) + return 0; + return toLocalFrame(page->mainFrame())->view(); +} + +void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime, LocalFrame* rootFrame) +{ + RefPtr view = rootFrameView(page, rootFrame); if (!view) return; page->autoscrollController().animate(monotonicFrameBeginTime); page->animator().serviceScriptedAnimations(monotonicFrameBeginTime); } -void PageWidgetDelegate::layout(Page* page, LocalFrame* root) +void PageWidgetDelegate::layout(Page* page, LocalFrame* rootFrame) { if (!page) return; - page->animator().updateLayoutAndStyleForPainting(root); + if (!rootFrame) { + if (!page->mainFrame() || !page->mainFrame()->isLocalFrame()) + return; + rootFrame = toLocalFrame(page->mainFrame()); + } + + page->animator().updateLayoutAndStyleForPainting(rootFrame); } -void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background, LocalFrame* root) +void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background, LocalFrame* rootFrame) { if (rect.isEmpty()) return; @@ -74,7 +91,7 @@ void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* gc.setDeviceScaleFactor(page->deviceScaleFactor()); IntRect dirtyRect(rect); gc.save(); // Needed to save the canvas, not the GraphicsContext. - FrameView* view = root->view(); + FrameView* view = rootFrameView(page, rootFrame); if (view) { gc.clip(dirtyRect); view->paint(&gc, dirtyRect); @@ -86,40 +103,41 @@ void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* gc.restore(); } -bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event, LocalFrame* root) +bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& handler, const WebInputEvent& event, LocalFrame* rootFrame) { + LocalFrame* frame = rootFrame; + if (!frame) + frame = page && page->mainFrame()->isLocalFrame() ? toLocalFrame(page->mainFrame()) : 0; switch (event.type) { // FIXME: WebKit seems to always return false on mouse events processing // methods. For now we'll assume it has processed them (as we are only // interested in whether keyboard events are processed). - // FIXME: Why do we return true when there is no root or the root is - // detached? case WebInputEvent::MouseMove: - if (!root || !root->view()) + if (!frame || !frame->view()) return true; - handler.handleMouseMove(*root, static_cast(event)); + handler.handleMouseMove(*frame, static_cast(event)); return true; case WebInputEvent::MouseLeave: - if (!root || !root->view()) + if (!frame || !frame->view()) return true; - handler.handleMouseLeave(*root, static_cast(event)); + handler.handleMouseLeave(*frame, static_cast(event)); return true; case WebInputEvent::MouseDown: - if (!root || !root->view()) + if (!frame || !frame->view()) return true; - handler.handleMouseDown(*root, static_cast(event)); + handler.handleMouseDown(*frame, static_cast(event)); return true; case WebInputEvent::MouseUp: - if (!root || !root->view()) + if (!frame || !frame->view()) return true; - handler.handleMouseUp(*root, static_cast(event)); + handler.handleMouseUp(*frame, static_cast(event)); return true; case WebInputEvent::MouseWheel: - if (!root || !root->view()) + if (!frame || !frame->view()) return false; - return handler.handleMouseWheel(*root, static_cast(event)); + return handler.handleMouseWheel(*frame, static_cast(event)); case WebInputEvent::RawKeyDown: case WebInputEvent::KeyDown: @@ -149,9 +167,9 @@ bool PageWidgetDelegate::handleInputEvent(Page* page, PageWidgetEventHandler& ha case WebInputEvent::TouchMove: case WebInputEvent::TouchEnd: case WebInputEvent::TouchCancel: - if (!root || !root->view()) + if (!frame || !frame->view()) return false; - return handler.handleTouchEvent(*root, static_cast(event)); + return handler.handleTouchEvent(*frame, static_cast(event)); case WebInputEvent::GesturePinchBegin: case WebInputEvent::GesturePinchEnd: diff --git a/Source/web/PageWidgetDelegate.h b/Source/web/PageWidgetDelegate.h index f2defaf7345..32200b8cb55 100644 --- a/Source/web/PageWidgetDelegate.h +++ b/Source/web/PageWidgetDelegate.h @@ -72,10 +72,10 @@ class PageWidgetDelegate { // rootFrame arguments indicate a root localFrame from which to start performing the // specified operation. If rootFrame is 0, these methods will attempt to use the // Page's mainFrame(), if it is a LocalFrame. - static void animate(Page*, double monotonicFrameBeginTime, LocalFrame* root); - static void layout(Page*, LocalFrame* root); - static void paint(Page*, PageOverlayList*, WebCanvas*, const WebRect&, CanvasBackground, LocalFrame* root); - static bool handleInputEvent(Page*, PageWidgetEventHandler&, const WebInputEvent&, LocalFrame* root); + static void animate(Page*, double monotonicFrameBeginTime, LocalFrame* rootFrame = 0); + static void layout(Page*, LocalFrame* rootFrame = 0); + static void paint(Page*, PageOverlayList*, WebCanvas*, const WebRect&, CanvasBackground, LocalFrame* rootFrame = 0); + static bool handleInputEvent(Page*, PageWidgetEventHandler&, const WebInputEvent&, LocalFrame* rootFrame = 0); private: PageWidgetDelegate() { } diff --git a/Source/web/WebPagePopupImpl.cpp b/Source/web/WebPagePopupImpl.cpp index bf001cf9b4c..0d3cb7acc77 100644 --- a/Source/web/WebPagePopupImpl.cpp +++ b/Source/web/WebPagePopupImpl.cpp @@ -323,7 +323,7 @@ void WebPagePopupImpl::beginFrame(const WebBeginFrameArgs& frameTime) { // FIXME: This should use frameTime.lastFrameTimeMonotonic but doing so // breaks tests. - PageWidgetDelegate::animate(m_page.get(), monotonicallyIncreasingTime(), m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::animate(m_page.get(), monotonicallyIncreasingTime()); } void WebPagePopupImpl::willCloseLayerTreeView() @@ -334,13 +334,13 @@ void WebPagePopupImpl::willCloseLayerTreeView() void WebPagePopupImpl::layout() { - PageWidgetDelegate::layout(m_page.get(), m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::layout(m_page.get()); } void WebPagePopupImpl::paint(WebCanvas* canvas, const WebRect& rect) { if (!m_closing) - PageWidgetDelegate::paint(m_page.get(), 0, canvas, rect, PageWidgetDelegate::Opaque, m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::paint(m_page.get(), 0, canvas, rect, PageWidgetDelegate::Opaque); } void WebPagePopupImpl::resize(const WebSize& newSize) @@ -379,7 +379,7 @@ bool WebPagePopupImpl::handleInputEvent(const WebInputEvent& event) { if (m_closing) return false; - return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, event, m_page->deprecatedLocalMainFrame()); + return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, event); } bool WebPagePopupImpl::handleKeyEvent(const PlatformKeyboardEvent& event) diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp index 4c84e95cebf..ee8370585b4 100644 --- a/Source/web/WebViewImpl.cpp +++ b/Source/web/WebViewImpl.cpp @@ -1839,9 +1839,7 @@ void WebViewImpl::beginFrame(const WebBeginFrameArgs& frameTime) if (!m_page) return; - // FIXME: This should probably be using the local root? - if (m_page->mainFrame()->isLocalFrame()) - PageWidgetDelegate::animate(m_page.get(), validFrameTime.lastFrameTimeMonotonic, m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::animate(m_page.get(), validFrameTime.lastFrameTimeMonotonic); if (m_continuousPaintingEnabled) { ContinuousPainter::setNeedsDisplayRecursive(m_rootGraphicsLayer, m_pageOverlays.get()); @@ -1877,7 +1875,7 @@ void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect) ASSERT(!isAcceleratedCompositingActive()); double paintStart = currentTime(); - PageWidgetDelegate::paint(m_page.get(), pageOverlays(), canvas, rect, isTransparent() ? PageWidgetDelegate::Translucent : PageWidgetDelegate::Opaque, m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::paint(m_page.get(), pageOverlays(), canvas, rect, isTransparent() ? PageWidgetDelegate::Translucent : PageWidgetDelegate::Opaque); double paintEnd = currentTime(); double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStart); Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30); @@ -1896,7 +1894,7 @@ void WebViewImpl::paintCompositedDeprecated(WebCanvas* canvas, const WebRect& re PaintBehavior oldPaintBehavior = view->paintBehavior(); view->setPaintBehavior(oldPaintBehavior | PaintBehaviorFlattenCompositingLayers); - PageWidgetDelegate::paint(m_page.get(), pageOverlays(), canvas, rect, isTransparent() ? PageWidgetDelegate::Translucent : PageWidgetDelegate::Opaque, m_page->deprecatedLocalMainFrame()); + PageWidgetDelegate::paint(m_page.get(), pageOverlays(), canvas, rect, isTransparent() ? PageWidgetDelegate::Translucent : PageWidgetDelegate::Opaque); view->setPaintBehavior(oldPaintBehavior); } @@ -2086,7 +2084,7 @@ bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent) return true; } - return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, inputEvent, m_page->deprecatedLocalMainFrame()); + return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, inputEvent); } void WebViewImpl::setCursorVisibilityState(bool isVisible)