RenderHTMLCanvas.cpp [plain text]
#include "config.h"
#include "RenderHTMLCanvas.h"
#include "CanvasRenderingContext.h"
#include "Document.h"
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLCanvasElement.h"
#include "HTMLNames.h"
#include "Page.h"
#include "PaintInfo.h"
#include "RenderView.h"
namespace WebCore {
using namespace HTMLNames;
RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, PassRef<RenderStyle> style)
: RenderReplaced(element, WTF::move(style), element.size())
{
view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
}
HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
{
return toHTMLCanvasElement(nodeForNonAnonymous());
}
bool RenderHTMLCanvas::requiresLayer() const
{
if (RenderReplaced::requiresLayer())
return true;
if (CanvasRenderingContext* context = canvasElement().renderingContext())
return context->isAccelerated();
return false;
}
void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
GraphicsContext* context = paintInfo.context;
LayoutRect contentRect = contentBoxRect();
contentRect.moveBy(paintOffset);
LayoutRect paintRect = replacedContentRect(intrinsicSize());
paintRect.moveBy(paintOffset);
bool clip = !contentRect.contains(paintRect);
GraphicsContextStateSaver stateSaver(*paintInfo.context, clip);
if (clip)
paintInfo.context->clip(pixelSnappedIntRect(contentRect));
if (Page* page = frame().page()) {
if (paintInfo.phase == PaintPhaseForeground)
page->addRelevantRepaintedObject(this, intersection(paintRect, contentRect));
}
bool useLowQualityScale = style().imageRendering() == ImageRenderingCrispEdges || style().imageRendering() == ImageRenderingOptimizeSpeed;
canvasElement().paint(context, paintRect, useLowQualityScale);
}
void RenderHTMLCanvas::canvasSizeChanged()
{
IntSize canvasSize = canvasElement().size();
LayoutSize zoomedSize(canvasSize.width() * style().effectiveZoom(), canvasSize.height() * style().effectiveZoom());
if (zoomedSize == intrinsicSize())
return;
setIntrinsicSize(zoomedSize);
if (!parent())
return;
if (!preferredLogicalWidthsDirty())
setPreferredLogicalWidthsDirty(true);
LayoutSize oldSize = size();
updateLogicalWidth();
updateLogicalHeight();
if (oldSize == size())
return;
if (!selfNeedsLayout())
setNeedsLayout();
}
}