diff options
Diffstat (limited to 'Source/WebCore/rendering/RenderHTMLCanvas.cpp')
-rw-r--r-- | Source/WebCore/rendering/RenderHTMLCanvas.cpp | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/Source/WebCore/rendering/RenderHTMLCanvas.cpp b/Source/WebCore/rendering/RenderHTMLCanvas.cpp index e68927033..f2de75d52 100644 --- a/Source/WebCore/rendering/RenderHTMLCanvas.cpp +++ b/Source/WebCore/rendering/RenderHTMLCanvas.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -33,6 +33,7 @@ #include "GraphicsContext.h" #include "HTMLCanvasElement.h" #include "HTMLNames.h" +#include "ImageQualityController.h" #include "Page.h" #include "PaintInfo.h" #include "RenderView.h" @@ -41,42 +42,57 @@ namespace WebCore { using namespace HTMLNames; -RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element) - : RenderReplaced(element, element->size()) +RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, Ref<RenderStyle>&& style) + : RenderReplaced(element, WTFMove(style), element.size()) { // Actual size is not known yet, report the default intrinsic size. - view()->frameView()->incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize())); + view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize())); +} + +HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const +{ + return downcast<HTMLCanvasElement>(nodeForNonAnonymous()); } bool RenderHTMLCanvas::requiresLayer() const { if (RenderReplaced::requiresLayer()) return true; - - HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(node()); - return canvas && canvas->renderingContext() && canvas->renderingContext()->isAccelerated(); + + if (CanvasRenderingContext* context = canvasElement().renderingContext()) + return context->isAccelerated(); + + return false; } 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); - } + GraphicsContext& context = paintInfo.context(); + + LayoutRect contentBoxRect = this->contentBoxRect(); + contentBoxRect.moveBy(paintOffset); + LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize()); + replacedContentRect.moveBy(paintOffset); + + // Not allowed to overflow the content box. + bool clip = !contentBoxRect.contains(replacedContentRect); + GraphicsContextStateSaver stateSaver(paintInfo.context(), clip); + if (clip) + paintInfo.context().clip(snappedIntRect(contentBoxRect)); + + if (Page* page = frame().page()) { + if (paintInfo.phase == PaintPhaseForeground) + page->addRelevantRepaintedObject(this, intersection(replacedContentRect, contentBoxRect)); } - bool useLowQualityScale = style()->imageRendering() == ImageRenderingCrispEdges || style()->imageRendering() == ImageRenderingOptimizeSpeed; - static_cast<HTMLCanvasElement*>(node())->paint(paintInfo.context, rect, useLowQualityScale); + InterpolationQualityMaintainer interpolationMaintainer(context, ImageQualityController::interpolationQualityFromStyle(style())); + canvasElement().paint(context, replacedContentRect); } void RenderHTMLCanvas::canvasSizeChanged() { - IntSize canvasSize = static_cast<HTMLCanvasElement*>(node())->size(); - LayoutSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasSize.height() * style()->effectiveZoom()); + IntSize canvasSize = canvasElement().size(); + LayoutSize zoomedSize(canvasSize.width() * style().effectiveZoom(), canvasSize.height() * style().effectiveZoom()); if (zoomedSize == intrinsicSize()) return; @@ -96,7 +112,7 @@ void RenderHTMLCanvas::canvasSizeChanged() return; if (!selfNeedsLayout()) - setNeedsLayout(true); + setNeedsLayout(); } } // namespace WebCore |