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)
: 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, const LayoutPoint& paintOffset)
{
LayoutRect rect = contentBoxRect();
rect.moveBy(paintOffset);
if (Frame* frame = this->frame()) {
if (Page* page = frame->page()) {
if (paintInfo.phase == PaintPhaseForeground)
page->addRelevantRepaintedObject(this, rect);
}
}
bool useLowQualityScale = style()->imageRendering() == ImageRenderingOptimizeContrast;
static_cast<HTMLCanvasElement*>(node())->paint(paintInfo.context, rect, useLowQualityScale);
}
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);
LayoutSize oldSize = size();
computeLogicalWidth();
computeLogicalHeight();
if (oldSize == size())
return;
if (!selfNeedsLayout())
setNeedsLayout(true);
}
}