2 * Copyright (C) 2011 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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "web/PageOverlay.h"
32 #include "core/frame/FrameHost.h"
33 #include "core/frame/Settings.h"
34 #include "core/page/Page.h"
35 #include "platform/graphics/GraphicsContext.h"
36 #include "platform/graphics/GraphicsLayer.h"
37 #include "platform/graphics/GraphicsLayerClient.h"
38 #include "public/platform/WebLayer.h"
39 #include "public/web/WebViewClient.h"
40 #include "web/WebDevToolsAgentImpl.h"
41 #include "web/WebGraphicsContextImpl.h"
42 #include "web/WebViewImpl.h"
46 PassOwnPtr
<PageOverlay
> PageOverlay::create(WebViewImpl
* viewImpl
, PageOverlay::Delegate
* delegate
)
48 return adoptPtr(new PageOverlay(viewImpl
, delegate
));
51 PageOverlay::PageOverlay(WebViewImpl
* viewImpl
, PageOverlay::Delegate
* delegate
)
52 : m_viewImpl(viewImpl
)
53 , m_delegate(delegate
)
57 PageOverlay::~PageOverlay()
62 m_layer
->removeFromParent();
63 if (WebDevToolsAgentImpl
* devTools
= m_viewImpl
->mainFrameDevToolsAgentImpl())
64 devTools
->didRemovePageOverlay(m_layer
.get());
68 void PageOverlay::update()
70 if (!m_viewImpl
->isAcceleratedCompositingActive())
73 Page
* page
= m_viewImpl
->page();
77 if (!page
->mainFrame()->isLocalFrame())
81 m_layer
= GraphicsLayer::create(m_viewImpl
->graphicsLayerFactory(), this);
82 m_layer
->setDrawsContent(true);
84 if (WebDevToolsAgentImpl
* devTools
= m_viewImpl
->mainFrameDevToolsAgentImpl())
85 devTools
->willAddPageOverlay(m_layer
.get());
87 // This is required for contents of overlay to stay in sync with the page while scrolling.
88 WebLayer
* platformLayer
= m_layer
->platformLayer();
89 platformLayer
->setShouldScrollOnMainThread(true);
90 page
->frameHost().visualViewport().containerLayer()->addChild(m_layer
.get());
93 FloatSize size
= page
->frameHost().visualViewport().size();
94 if (size
!= m_layer
->size())
95 m_layer
->setSize(size
);
97 m_layer
->setNeedsDisplay();
100 void PageOverlay::paintContents(const GraphicsLayer
*, GraphicsContext
& gc
, GraphicsLayerPaintingPhase
, const IntRect
& inClip
)
103 WebGraphicsContextImpl
contextWrapper(gc
, *this, DisplayItem::PageOverlay
);
104 m_delegate
->paintPageOverlay(&contextWrapper
, expandedIntSize(m_layer
->size()));
107 String
PageOverlay::debugName(const GraphicsLayer
*)
109 return "WebViewImpl Page Overlay Content Layer";