RenderHTMLCanvas.cpp [plain text]
#include "config.h"
#include "RenderHTMLCanvas.h"
#include "CanvasRenderingContext.h"
#include "Document.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLCanvasElement.h"
#include "HTMLNames.h"
#include "PaintInfo.h"
#include "RenderView.h"
namespace WebCore {
using namespace HTMLNames;
RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element)
: RenderReplaced(element, element->size())
{
view()->frameView()->setIsVisuallyNonEmpty();
}
bool RenderHTMLCanvas::requiresLayer() const
{
if (RenderReplaced::requiresLayer())
return true;
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(node());
return canvas && canvas->renderingContext() && canvas->renderingContext()->isAccelerated();
}
void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, int tx, int ty)
{
IntRect rect = contentBoxRect();
rect.move(tx, ty);
static_cast<HTMLCanvasElement*>(node())->paint(paintInfo.context, rect);
}
void RenderHTMLCanvas::canvasSizeChanged()
{
IntSize canvasSize = static_cast<HTMLCanvasElement*>(node())->size();
IntSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasSize.height() * style()->effectiveZoom());
if (zoomedSize == intrinsicSize())
return;
setIntrinsicSize(zoomedSize);
if (!parent())
return;
if (!preferredLogicalWidthsDirty())
setPreferredLogicalWidthsDirty(true);
IntSize oldSize = size();
computeLogicalWidth();
computeLogicalHeight();
if (oldSize == size())
return;
if (!selfNeedsLayout())
setNeedsLayout(true);
}
}