TileCoverageMap.cpp [plain text]
#include "config.h"
#include "TileCoverageMap.h"
#include "GraphicsContext.h"
#include "TileController.h"
#include "TileGrid.h"
namespace WebCore {
TileCoverageMap::TileCoverageMap(const TileController& controller)
: m_controller(controller)
, m_layer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeSimpleLayer, this))
, m_visibleRectIndicatorLayer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeLayer, nullptr))
, m_position(FloatPoint(0, controller.topContentInset()))
{
m_layer.get().setOpacity(0.75);
m_layer.get().setAnchorPoint(FloatPoint3D());
m_layer.get().setBorderColor(Color::black);
m_layer.get().setBorderWidth(1);
m_layer.get().setPosition(FloatPoint(2, 2));
m_layer.get().setContentsScale(m_controller.deviceScaleFactor());
m_visibleRectIndicatorLayer.get().setBorderWidth(2);
m_visibleRectIndicatorLayer.get().setAnchorPoint(FloatPoint3D());
m_visibleRectIndicatorLayer.get().setBorderColor(Color(255, 0, 0));
m_layer.get().appendSublayer(&m_visibleRectIndicatorLayer.get());
update();
}
TileCoverageMap::~TileCoverageMap()
{
m_layer.get().setOwner(nullptr);
}
void TileCoverageMap::update()
{
FloatRect containerBounds = m_controller.bounds();
FloatRect visibleRect = m_controller.visibleRect();
visibleRect.contract(4, 4);
float widthScale = 1;
float scale = 1;
if (!containerBounds.isEmpty()) {
widthScale = std::min<float>(visibleRect.width() / containerBounds.width(), 0.1);
scale = std::min(widthScale, visibleRect.height() / containerBounds.height());
}
float indicatorScale = scale * m_controller.tileGrid().scale();
FloatRect mapBounds = containerBounds;
mapBounds.scale(indicatorScale, indicatorScale);
m_layer.get().setPosition(m_position + FloatPoint(2, 2));
m_layer.get().setBounds(mapBounds);
m_layer.get().setNeedsDisplay();
visibleRect.scale(indicatorScale, indicatorScale);
visibleRect.expand(2, 2);
m_visibleRectIndicatorLayer->setPosition(visibleRect.location());
m_visibleRectIndicatorLayer->setBounds(FloatRect(FloatPoint(), visibleRect.size()));
Color visibleRectIndicatorColor;
switch (m_controller.indicatorMode()) {
case SynchronousScrollingBecauseOfStyleIndication:
visibleRectIndicatorColor = Color(255, 0, 0);
break;
case SynchronousScrollingBecauseOfEventHandlersIndication:
visibleRectIndicatorColor = Color(255, 255, 0);
break;
case AsyncScrollingIndication:
visibleRectIndicatorColor = Color(0, 200, 0);
break;
}
m_visibleRectIndicatorLayer.get().setBorderColor(visibleRectIndicatorColor);
}
void TileCoverageMap::platformCALayerPaintContents(PlatformCALayer* platformCALayer, GraphicsContext& context, const FloatRect&)
{
ASSERT_UNUSED(platformCALayer, platformCALayer == &m_layer.get());
m_controller.tileGrid().drawTileMapContents(context.platformContext(), m_layer.get().bounds());
}
float TileCoverageMap::platformCALayerDeviceScaleFactor() const
{
return m_controller.rootLayer().owner()->platformCALayerDeviceScaleFactor();
}
void TileCoverageMap::setDeviceScaleFactor(float deviceScaleFactor)
{
m_layer.get().setContentsScale(deviceScaleFactor);
}
}