This source file includes following definitions.
- ToWebCanvas
- create
- m_zOrder
- create
- notifyAnimationStarted
- paintContents
- debugName
- clear
- update
- paintWebFrame
- invalidateWebFrame
#include "config.h"
#include "PageOverlay.h"
#include "WebPageOverlay.h"
#include "WebViewClient.h"
#include "WebViewImpl.h"
#include "core/page/Page.h"
#include "core/frame/Settings.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/graphics/GraphicsLayerClient.h"
#include "public/platform/WebLayer.h"
using namespace WebCore;
namespace blink {
namespace {
WebCanvas* ToWebCanvas(GraphicsContext* gc)
{
return gc->canvas();
}
}
PassOwnPtr<PageOverlay> PageOverlay::create(WebViewImpl* viewImpl, WebPageOverlay* overlay)
{
return adoptPtr(new PageOverlay(viewImpl, overlay));
}
PageOverlay::PageOverlay(WebViewImpl* viewImpl, WebPageOverlay* overlay)
: m_viewImpl(viewImpl)
, m_overlay(overlay)
, m_zOrder(0)
{
}
class OverlayGraphicsLayerClientImpl : public WebCore::GraphicsLayerClient {
public:
static PassOwnPtr<OverlayGraphicsLayerClientImpl> create(WebPageOverlay* overlay)
{
return adoptPtr(new OverlayGraphicsLayerClientImpl(overlay));
}
virtual ~OverlayGraphicsLayerClientImpl() { }
virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTime) OVERRIDE { }
virtual void paintContents(const GraphicsLayer*, GraphicsContext& gc, GraphicsLayerPaintingPhase, const IntRect& inClip)
{
gc.save();
m_overlay->paintPageOverlay(ToWebCanvas(&gc));
gc.restore();
}
virtual String debugName(const GraphicsLayer* graphicsLayer) OVERRIDE
{
return String("WebViewImpl Page Overlay Content Layer");
}
private:
explicit OverlayGraphicsLayerClientImpl(WebPageOverlay* overlay)
: m_overlay(overlay)
{
}
WebPageOverlay* m_overlay;
};
void PageOverlay::clear()
{
invalidateWebFrame();
if (m_layer) {
m_layer->removeFromParent();
if (WebCore::Page* page = m_viewImpl->page())
page->inspectorController().didRemovePageOverlay(m_layer.get());
m_layer = nullptr;
m_layerClient = nullptr;
}
}
void PageOverlay::update()
{
invalidateWebFrame();
if (!m_layer) {
m_layerClient = OverlayGraphicsLayerClientImpl::create(m_overlay);
m_layer = GraphicsLayer::create(m_viewImpl->graphicsLayerFactory(), m_layerClient.get());
m_layer->setDrawsContent(true);
if (WebCore::Page* page = m_viewImpl->page())
page->inspectorController().willAddPageOverlay(m_layer.get());
WebLayer* platformLayer = m_layer->platformLayer();
platformLayer->setShouldScrollOnMainThread(true);
WebVector<WebRect> webRects(static_cast<size_t>(1));
webRects[0] = WebRect(0, 0, INT_MAX, INT_MAX);
platformLayer->setTouchEventHandlerRegion(webRects);
}
FloatSize size(m_viewImpl->size());
if (size != m_layer->size()) {
m_layer->removeFromParent();
m_layer->setSize(size);
}
m_viewImpl->setOverlayLayer(m_layer.get());
m_layer->setNeedsDisplay();
}
void PageOverlay::paintWebFrame(GraphicsContext& gc)
{
if (!m_viewImpl->isAcceleratedCompositingActive()) {
gc.save();
m_overlay->paintPageOverlay(ToWebCanvas(&gc));
gc.restore();
}
}
void PageOverlay::invalidateWebFrame()
{
if (!m_viewImpl->isAcceleratedCompositingActive()) {
const WebSize& size = m_viewImpl->size();
WebRect damagedRect(0, 0, size.width, size.height);
if (m_viewImpl->client())
m_viewImpl->client()->didInvalidateRect(damagedRect);
}
}
}