[CTTE] RenderHTMLCanvas's element is always a HTMLCanvasElement.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Sep 2013 05:11:18 +0000 (05:11 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Sep 2013 05:11:18 +0000 (05:11 +0000)
<https://webkit.org/b/121272>

Reviewed by Anders Carlsson.

Add RenderHTMLCanvas::canvasElement(), hiding element().
This function also returns a reference since this renderer cannot be anonymous.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155668 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/rendering/RenderHTMLCanvas.cpp
Source/WebCore/rendering/RenderHTMLCanvas.h

index 552c16f..ca1f277 100644 (file)
@@ -1,5 +1,15 @@
 2013-09-12  Andreas Kling  <akling@apple.com>
 
+        [CTTE] RenderHTMLCanvas's element is always a HTMLCanvasElement.
+        <https://webkit.org/b/121272>
+
+        Reviewed by Anders Carlsson.
+
+        Add RenderHTMLCanvas::canvasElement(), hiding element().
+        This function also returns a reference since this renderer cannot be anonymous.
+
+2013-09-12  Andreas Kling  <akling@apple.com>
+
         [CTTE] RenderTextControlMultiLine's element is always a HTMLTextAreaElement.
         <https://webkit.org/b/121271>
 
index 5d01149..b67f799 100644 (file)
@@ -114,7 +114,7 @@ RenderObject* HTMLCanvasElement::createRenderer(RenderArena* arena, RenderStyle*
     Frame* frame = document().frame();
     if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) {
         m_rendererIsCanvas = true;
-        return new (arena) RenderHTMLCanvas(this);
+        return new (arena) RenderHTMLCanvas(*this);
     }
 
     m_rendererIsCanvas = false;
index fa335b3..e4cdbf5 100644 (file)
@@ -41,20 +41,28 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element)
-    : RenderReplaced(element, element->size())
+RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element)
+    : RenderReplaced(&element, element.size())
 {
     // Actual size is not known yet, report the default intrinsic size.
     view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
 }
 
+HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
+{
+    ASSERT(RenderObject::node());
+    return toHTMLCanvasElement(*RenderObject::node());
+}
+
 bool RenderHTMLCanvas::requiresLayer() const
 {
     if (RenderReplaced::requiresLayer())
         return true;
-    
-    HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(element());
-    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)
@@ -78,12 +86,12 @@ void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
     }
 
     bool useLowQualityScale = style()->imageRendering() == ImageRenderingCrispEdges || style()->imageRendering() == ImageRenderingOptimizeSpeed;
-    static_cast<HTMLCanvasElement*>(element())->paint(context, paintRect, useLowQualityScale);
+    canvasElement().paint(context, paintRect, useLowQualityScale);
 }
 
 void RenderHTMLCanvas::canvasSizeChanged()
 {
-    IntSize canvasSize = static_cast<HTMLCanvasElement*>(element())->size();
+    IntSize canvasSize = canvasElement().size();
     LayoutSize zoomedSize(canvasSize.width() * style()->effectiveZoom(), canvasSize.height() * style()->effectiveZoom());
 
     if (zoomedSize == intrinsicSize())
index 9b8e4d7..eb7b7fc 100644 (file)
@@ -34,17 +34,19 @@ class HTMLCanvasElement;
 
 class RenderHTMLCanvas FINAL : public RenderReplaced {
 public:
-    explicit RenderHTMLCanvas(HTMLCanvasElement*);
+    explicit RenderHTMLCanvas(HTMLCanvasElement&);
 
-    virtual bool isCanvas() const { return true; }
-    virtual bool requiresLayer() const;
+    HTMLCanvasElement& canvasElement() const;
 
     void canvasSizeChanged();
-    
+
 private:
-    virtual const char* renderName() const { return "RenderHTMLCanvas"; }
-    virtual void paintReplaced(PaintInfo&, const LayoutPoint&);
-    virtual void intrinsicSizeChanged() { canvasSizeChanged(); }
+    void element() const WTF_DELETED_FUNCTION;
+    virtual bool requiresLayer() const OVERRIDE;
+    virtual bool isCanvas() const OVERRIDE { return true; }
+    virtual const char* renderName() const OVERRIDE { return "RenderHTMLCanvas"; }
+    virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE;
+    virtual void intrinsicSizeChanged() OVERRIDE { canvasSizeChanged(); }
 };
 
 inline RenderHTMLCanvas* toRenderHTMLCanvas(RenderObject* object)