From aad73e43d54fd67fc09f01570946c94667a3a81a Mon Sep 17 00:00:00 2001 From: wkorman Date: Fri, 25 Mar 2016 17:25:07 -0700 Subject: Correct visual rect for PageOverlay to reflect size of graphics layer. BUG=529938,569211 Review URL: https://codereview.chromium.org/1833233002 Cr-Commit-Position: refs/heads/master@{#383418} --- third_party/WebKit/Source/web/PageOverlay.cpp | 6 +++ third_party/WebKit/Source/web/PageOverlay.h | 3 +- third_party/WebKit/Source/web/PageOverlayTest.cpp | 52 ++++++++++++++--------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/third_party/WebKit/Source/web/PageOverlay.cpp b/third_party/WebKit/Source/web/PageOverlay.cpp index a1cfd0a..156ad70 100644 --- a/third_party/WebKit/Source/web/PageOverlay.cpp +++ b/third_party/WebKit/Source/web/PageOverlay.cpp @@ -97,6 +97,12 @@ void PageOverlay::update() m_layer->setNeedsDisplay(); } +LayoutRect PageOverlay::visualRect() const +{ + ASSERT(m_layer.get()); + return LayoutRect(FloatPoint(), m_layer->size()); +} + IntRect PageOverlay::computeInterestRect(const GraphicsLayer* graphicsLayer, const IntRect&) const { return IntRect(IntPoint(), expandedIntSize(m_layer->size())); diff --git a/third_party/WebKit/Source/web/PageOverlay.h b/third_party/WebKit/Source/web/PageOverlay.h index 815552e..6eb1917 100644 --- a/third_party/WebKit/Source/web/PageOverlay.h +++ b/third_party/WebKit/Source/web/PageOverlay.h @@ -69,8 +69,7 @@ public: // DisplayItemClient methods. String debugName() const final { return "PageOverlay"; } - // TODO(chrishtr): fix this. - LayoutRect visualRect() const override { return LayoutRect(); } + LayoutRect visualRect() const override; // GraphicsLayerClient implementation IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const override; diff --git a/third_party/WebKit/Source/web/PageOverlayTest.cpp b/third_party/WebKit/Source/web/PageOverlayTest.cpp index 935ae39..bf2036c 100644 --- a/third_party/WebKit/Source/web/PageOverlayTest.cpp +++ b/third_party/WebKit/Source/web/PageOverlayTest.cpp @@ -46,6 +46,24 @@ void disableAcceleratedCompositing(WebSettings* settings) settings->setAcceleratedCompositingEnabled(false); } +// PageOverlay that paints a solid color. +class SolidColorOverlay : public PageOverlay::Delegate { +public: + SolidColorOverlay(Color color) : m_color(color) { } + + void paintPageOverlay(const PageOverlay& pageOverlay, GraphicsContext& graphicsContext, const WebSize& size) const override + { + if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, pageOverlay, DisplayItem::PageOverlay)) + return; + FloatRect rect(0, 0, size.width, size.height); + DrawingRecorder drawingRecorder(graphicsContext, pageOverlay, DisplayItem::PageOverlay, rect); + graphicsContext.fillRect(rect, m_color); + } + +private: + Color m_color; +}; + class PageOverlayTest : public ::testing::Test { protected: enum CompositingMode { AcceleratedCompositing, UnacceleratedCompositing }; @@ -62,6 +80,11 @@ protected: WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } + PassOwnPtr createSolidYellowOverlay() + { + return PageOverlay::create(webViewImpl(), new SolidColorOverlay(SK_ColorYELLOW)); + } + template void runPageOverlayTestWithAcceleratedCompositing(); @@ -69,24 +92,6 @@ private: FrameTestHelpers::WebViewHelper m_helper; }; -// PageOverlay that paints a solid color. -class SolidColorOverlay : public PageOverlay::Delegate { -public: - SolidColorOverlay(Color color) : m_color(color) { } - - void paintPageOverlay(const PageOverlay& pageOverlay, GraphicsContext& graphicsContext, const WebSize& size) const override - { - if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, pageOverlay, DisplayItem::PageOverlay)) - return; - FloatRect rect(0, 0, size.width, size.height); - DrawingRecorder drawingRecorder(graphicsContext, pageOverlay, DisplayItem::PageOverlay, rect); - graphicsContext.fillRect(rect, m_color); - } - -private: - Color m_color; -}; - template class RuntimeFeatureChange { public: @@ -107,7 +112,7 @@ TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) initialize(AcceleratedCompositing); webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewportHeight)); - OwnPtr pageOverlay = PageOverlay::create(webViewImpl(), new SolidColorOverlay(SK_ColorYELLOW)); + OwnPtr pageOverlay = createSolidYellowOverlay(); pageOverlay->update(); webViewImpl()->updateAllLifecyclePhases(); @@ -134,5 +139,14 @@ TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing) graphicsContext.endRecording()->playback(&canvas); } +TEST_F(PageOverlayTest, PageOverlay_VisualRect) +{ + initialize(AcceleratedCompositing); + OwnPtr pageOverlay = createSolidYellowOverlay(); + pageOverlay->update(); + webViewImpl()->updateAllLifecyclePhases(); + EXPECT_EQ(LayoutRect(0, 0, viewportWidth, viewportHeight), pageOverlay->visualRect()); +} + } // namespace } // namespace blink -- cgit v1.1