This source file includes following definitions.
- m_isPaintingInsideReflection
- reflectionLayer
- updateAfterStyleChange
- paint
- debugName
#include "config.h"
#include "core/rendering/RenderLayerReflectionInfo.h"
#include "core/frame/UseCounter.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderReplica.h"
#include "core/rendering/style/RenderStyle.h"
#include "platform/transforms/ScaleTransformOperation.h"
#include "platform/transforms/TranslateTransformOperation.h"
#include "wtf/RefPtr.h"
namespace WebCore {
RenderLayerReflectionInfo::RenderLayerReflectionInfo(RenderBox* renderer)
: m_renderer(renderer)
, m_isPaintingInsideReflection(false)
{
UseCounter::count(m_renderer->document(), UseCounter::Reflection);
m_reflection = RenderReplica::createAnonymous(&(m_renderer->document()));
m_reflection->setParent(m_renderer);
}
RenderLayerReflectionInfo::~RenderLayerReflectionInfo()
{
if (!m_reflection->documentBeingDestroyed())
m_reflection->removeLayers(renderer()->layer());
m_reflection->setParent(0);
m_reflection->destroy();
m_reflection = 0;
}
RenderLayer* RenderLayerReflectionInfo::reflectionLayer() const
{
return m_reflection->layer();
}
void RenderLayerReflectionInfo::updateAfterStyleChange(const RenderStyle* oldStyle)
{
RefPtr<RenderStyle> newStyle = RenderStyle::create();
newStyle->inheritFrom(renderer()->style());
TransformOperations transform;
switch (renderer()->style()->boxReflect()->direction()) {
case ReflectionBelow:
transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
Length(100., Percent), TransformOperation::Translate));
transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
renderer()->style()->boxReflect()->offset(), TransformOperation::Translate));
transform.operations().append(ScaleTransformOperation::create(1.0, -1.0, ScaleTransformOperation::Scale));
break;
case ReflectionAbove:
transform.operations().append(ScaleTransformOperation::create(1.0, -1.0, ScaleTransformOperation::Scale));
transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
Length(100., Percent), TransformOperation::Translate));
transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
renderer()->style()->boxReflect()->offset(), TransformOperation::Translate));
break;
case ReflectionRight:
transform.operations().append(TranslateTransformOperation::create(Length(100., Percent),
Length(0, Fixed), TransformOperation::Translate));
transform.operations().append(TranslateTransformOperation::create(
renderer()->style()->boxReflect()->offset(), Length(0, Fixed), TransformOperation::Translate));
transform.operations().append(ScaleTransformOperation::create(-1.0, 1.0, ScaleTransformOperation::Scale));
break;
case ReflectionLeft:
transform.operations().append(ScaleTransformOperation::create(-1.0, 1.0, ScaleTransformOperation::Scale));
transform.operations().append(TranslateTransformOperation::create(Length(100., Percent),
Length(0, Fixed), TransformOperation::Translate));
transform.operations().append(TranslateTransformOperation::create(
renderer()->style()->boxReflect()->offset(), Length(0, Fixed), TransformOperation::Translate));
break;
}
newStyle->setTransform(transform);
newStyle->setMaskBoxImage(renderer()->style()->boxReflect()->mask());
m_reflection->setStyle(newStyle.release());
}
void RenderLayerReflectionInfo::paint(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags flags)
{
if (m_isPaintingInsideReflection)
return;
m_isPaintingInsideReflection = true;
reflectionLayer()->paintLayer(context, paintingInfo, flags);
m_isPaintingInsideReflection = false;
}
String RenderLayerReflectionInfo::debugName() const
{
return renderer()->debugName() + " (reflection)";
}
}