Use enum classes and OptionSets for PaintPhase and PaintBehavior
[WebKit-https.git] / Source / WebCore / rendering / RenderHTMLCanvas.cpp
index f7ec311..5a3086e 100644 (file)
  *    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
 
 #include "CanvasRenderingContext.h"
 #include "Document.h"
+#include "Frame.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"
-#include "HitTestResult.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLNames.h"
+#include "ImageQualityController.h"
+#include "Page.h"
 #include "PaintInfo.h"
 #include "RenderView.h"
+#include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
 
 using namespace HTMLNames;
 
-RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element)
-    : RenderReplaced(element, element->size())
+WTF_MAKE_ISO_ALLOCATED_IMPL(RenderHTMLCanvas);
+
+RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, RenderStyle&& style)
+    : RenderReplaced(element, WTFMove(style), element.size())
+{
+    // Actual size is not known yet, report the default intrinsic size.
+    view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
+}
+
+HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
 {
-    view()->frameView()->setIsVisuallyNonEmpty();
+    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, int tx, int ty)
+void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
-    IntRect rect = contentBoxRect();
-    rect.move(tx, ty);
-    static_cast<HTMLCanvasElement*>(node())->paint(paintInfo.context, rect);
+    GraphicsContext& context = paintInfo.context();
+
+    LayoutRect contentBoxRect = this->contentBoxRect();
+    contentBoxRect.moveBy(paintOffset);
+    LayoutRect replacedContentRect = this->replacedContentRect();
+    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 (paintInfo.phase == PaintPhase::Foreground)
+        page().addRelevantRepaintedObject(this, intersection(replacedContentRect, contentBoxRect));
+
+    InterpolationQualityMaintainer interpolationMaintainer(context, ImageQualityController::interpolationQualityFromStyle(style()));
+    canvasElement().paint(context, replacedContentRect);
 }
 
 void RenderHTMLCanvas::canvasSizeChanged()
 {
-    IntSize canvasSize = static_cast<HTMLCanvasElement*>(node())->size();
-    IntSize 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;
@@ -74,50 +102,7 @@ void RenderHTMLCanvas::canvasSizeChanged()
 
     if (!parent())
         return;
-
-    if (!preferredLogicalWidthsDirty())
-        setPreferredLogicalWidthsDirty(true);
-
-    IntSize oldSize = size();
-    computeLogicalWidth();
-    computeLogicalHeight();
-    if (oldSize == size())
-        return;
-
-    if (!selfNeedsLayout())
-        setNeedsLayout(true);
-}
-
-void RenderHTMLCanvas::recursiveSetNoNeedsLayout(RenderObject* obj)
-{
-    obj->setNeedsLayout(false);
-    for (RenderObject* child = obj->firstChild(); child; child = child->nextSibling())
-        recursiveSetNoNeedsLayout(child);
-}
-
-void RenderHTMLCanvas::layout()
-{
-    recursiveSetNoNeedsLayout(this);
-    setNeedsLayout(true);
-    RenderReplaced::layout();
-}
-
-bool RenderHTMLCanvas::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int xPos, int yPos, int tx, int ty, HitTestAction action)
-{
-    UNUSED_PARAM(request);
-    tx += x();
-    ty += y();
-
-    // Ignore children (accessible fallback content that might be focusable but not clickable)
-    // but do test our own bounds for a hit.
-    IntRect boundsRect = IntRect(tx, ty, width(), height());
-    if (visibleToHitTesting() && action == HitTestForeground && boundsRect.intersects(result.rectForPoint(xPos, yPos))) {
-        updateHitTestResult(result, IntPoint(xPos - tx, yPos - ty));
-        if (!result.addNodeToRectBasedTestResult(node(), xPos, yPos, boundsRect))
-            return true;
-    }
-
-    return false;
+    setNeedsLayoutIfNeededAfterIntrinsicSizeChange();
 }
 
 } // namespace WebCore