LayoutTests:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Apr 2006 23:38:06 +0000 (23:38 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Apr 2006 23:38:06 +0000 (23:38 +0000)
        Reviewed by Anders.

        - test changes for http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
          Canvas element breaks when RenderObject creation is deferred by external CSS

        * fast/canvas/canvas-before-css-expected.checksum: Added.
        * fast/canvas/canvas-before-css-expected.png: Added.
        * fast/canvas/canvas-before-css-expected.txt: Added.
        * fast/canvas/canvas-before-css.html: Added.

        * fast/canvas/image-object-in-canvas.html: Test had a bug where it used <canvas>
        without a </canvas> tag. Changed test to include a </canvas> tag.

        * fast/canvas/patternfill-repeat-expected.txt: Updated for name change from
        RenderCanvasImage to RenderHTMLCanvas.
        * fast/canvas/image-object-in-canvas-expected.txt: Ditto.
        * fast/canvas/fillrect_gradient-expected.txt: Ditto.
        * fast/canvas/quadraticCurveTo-expected.txt: Ditto.

WebCore:

        Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
          Canvas element breaks when RenderObject creation is deferred by external CSS

        Test: fast/canvas/canvas-before-css.html

        This patch makes us match the canvas documentation in Hixie's Web Applications
        draft as far as when the canvas is created and recreated and how it's sized.
        It also gets rid of the compositeOperation attribute of the canvas element.
        We can add that back if we need it. Anders points out that this specifically
        changes behavior for canvas elements where the size is set in CSS and not with
        width and height attributes. The CSS size now determines how big a box the canvas
        is rendered into, but has no effect on the size of the canvas's buffer.

        * html/CanvasRenderingContext2D.h: Added overloads of drawImage that take
        HTMLCanvasElement, which is no longer derived from HTMLImageElement.
        * html/CanvasRenderingContext2D.cpp:
        (WebCore::imageSize): Renamed from imageOrCanvasSize. Now used for images only,
        because canvas is no longer derived from image.
        (WebCore::CanvasRenderingContext2D::drawImage): Split the implementation of this
        for image sources from the implementation for canvas sources.
        (WebCore::CanvasRenderingContext2D::willDraw): Changed to call a new willDraw
        function on the canvas element.
        (WebCore::CanvasRenderingContext2D::drawingContext): Changed to call drawingContext
        on the canvas element rather than the renderer.

        * html/HTMLCanvasElement.h: Changed HTMLCanvasElement to derive from HTMLElement
        instead of HTMLImageElement. Added width, height, setWidth, setHeight, willDraw,
        paint, drawingContext, createDrawingContext, and reset functions. Added m_size,
        m_createdDrawingContext, m_data, and m_drawingContext data members. Removed
        mapToEntry, attach, detach, and isURLAttribute functins.

        * html/HTMLCanvasElement.cpp:
        (WebCore::HTMLCanvasElement::HTMLCanvasElement): Added initializers for new m_size,
        m_createdDrawingContext, m_data, and m_drawingContext data members.
        (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Free m_data and m_drawingContext.
        (WebCore::HTMLCanvasElement::parseMappedAttribute): Got rid of special case for
        srcAttr, which is no longer needed since we aren't deriving from HTMLImageElement.
        Added code that triggers a reset when either width or height is set.
        (WebCore::HTMLCanvasElement::createRenderer): Added code to set the intrinsic
        width and height of the renderer to the size of the element.
        (WebCore::HTMLCanvasElement::setHeight): Added. Sets the height attribute.
        (WebCore::HTMLCanvasElement::setWidth): Added. Sets the width attribute.
        (WebCore::HTMLCanvasElement::willDraw): Added. Tells the renderer to repaint.
        Also has FIXME mentioning we could dirty only the part that has changed in the future.
        (WebCore::HTMLCanvasElement::reset): Added. Sets the size of the canvas and discards
        the old buffer, which is an indirect way of resetting the buffer to transparent black.
        (WebCore::HTMLCanvasElement::paint): Added. Draws the canvas image into the graphics
        context that's passed in.
        (WebCore::HTMLCanvasElement::createDrawingContext): Added. Allocates a buffer for
        the bits, then creates a bitmap context for drawing into the buffer.
        (WebCore::HTMLCanvasElement::drawingContext): Added. Calls createDrawingContext if
        needed, then returns the current drawing context.
        (WebCore::HTMLCanvasElement::createPlatformImage): Changed to always call CGContextFlush
        and to create the image from the context in this class.

        * rendering/RenderHTMLCanvas.h: Remove almost all of the contents of this file.
        Removed ~RenderHTMLCanvas, setNeedsImageUpdate, element, updateDrawnImage, drawingContext,
        createDrawingContext, and drawnImage functions and _drawingContext, _drawingContextData,
        _drawnImage, and _needsImageUpdate booleans. Changed RenderHTMLCanvas to derive from
        RenderReplaced instead of RenderImage.

        * rendering/RenderHTMLCanvas.cpp:
        (WebCore::RenderHTMLCanvas::RenderHTMLCanvas): Changed to only initialize RenderReplaced.
        (WebCore::RenderHTMLCanvas::renderName): Moved this in here, since there's no good reason
        to have this virtual function inlined.
        (WebCore::RenderHTMLCanvas::paint): Changed implementation to use HTMLCanvasElement::paint
        instead ofcalling CGContextDrawImage directly.
        (WebCore::RenderHTMLCanvas::layout): Removed the code that detects changes in width and
        causes the drawing context to be recreated; instead, if the width and height changes we
        scale when we paint the canvas.

        * bindings/js/JSCanvasRenderingContext2DBase.cpp:
        (WebCore::JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction):
        Separated out handling for <canvas> vs. <img> elements in drawRect, since
        HTMLCanvasElement is no longer derived from HTMLImageElement.

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-before-css-expected.checksum [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-before-css-expected.png [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-before-css-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-before-css.html [new file with mode: 0644]
LayoutTests/fast/canvas/fillrect_gradient-expected.txt
LayoutTests/fast/canvas/image-object-in-canvas-expected.txt
LayoutTests/fast/canvas/image-object-in-canvas.html
LayoutTests/fast/canvas/patternfill-repeat-expected.txt
LayoutTests/fast/canvas/quadraticCurveTo-expected.txt
WebCore/ChangeLog
WebCore/bindings/js/JSCanvasRenderingContext2DBase.cpp
WebCore/html/CanvasRenderingContext2D.cpp
WebCore/html/CanvasRenderingContext2D.h
WebCore/html/HTMLCanvasElement.cpp
WebCore/html/HTMLCanvasElement.h
WebCore/rendering/RenderHTMLCanvas.cpp
WebCore/rendering/RenderHTMLCanvas.h

index f3f4279527c1c454fcdc11680dcfdebc87bd502b..b33b1531434a0ba9a03b8de2910d68c87b763a1f 100644 (file)
@@ -1,3 +1,24 @@
+2006-04-09  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - test changes for http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
+          Canvas element breaks when RenderObject creation is deferred by external CSS
+
+        * fast/canvas/canvas-before-css-expected.checksum: Added.
+        * fast/canvas/canvas-before-css-expected.png: Added.
+        * fast/canvas/canvas-before-css-expected.txt: Added.
+        * fast/canvas/canvas-before-css.html: Added.
+
+        * fast/canvas/image-object-in-canvas.html: Test had a bug where it used <canvas>
+        without a </canvas> tag. Changed test to include a </canvas> tag.
+
+        * fast/canvas/patternfill-repeat-expected.txt: Updated for name change from
+        RenderCanvasImage to RenderHTMLCanvas.
+        * fast/canvas/image-object-in-canvas-expected.txt: Ditto.
+        * fast/canvas/fillrect_gradient-expected.txt: Ditto.
+        * fast/canvas/quadraticCurveTo-expected.txt: Ditto.
+
 2006-04-09  Rob Buis  <buis@kde.org>
 
         Reviewed by eseidel.  Landed by eseidel.
         * fast/forms/input-text-drag-down-expected.txt: Added.
         * fast/forms/input-text-drag-down.html: Added.
 
+2006-04-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Hyatt.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8134
+          REGRESSION: dragging down from the middle of a text field does not select to end of field
+
+        * fast/forms/input-text-drag-down-expected.checksum: Added.
+        * fast/forms/input-text-drag-down-expected.png: Added.
+        * fast/forms/input-text-drag-down-expected.txt: Added.
+        * fast/forms/input-text-drag-down.html: Added.
+
 2006-04-07  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/canvas/canvas-before-css-expected.checksum b/LayoutTests/fast/canvas/canvas-before-css-expected.checksum
new file mode 100644 (file)
index 0000000..9a1fe4d
--- /dev/null
@@ -0,0 +1,2 @@
+9295ae92cf44e9b941226f41fc047ba1
+\ No newline at end of file
diff --git a/LayoutTests/fast/canvas/canvas-before-css-expected.png b/LayoutTests/fast/canvas/canvas-before-css-expected.png
new file mode 100644 (file)
index 0000000..bf8de3e
Binary files /dev/null and b/LayoutTests/fast/canvas/canvas-before-css-expected.png differ
diff --git a/LayoutTests/fast/canvas/canvas-before-css-expected.txt b/LayoutTests/fast/canvas/canvas-before-css-expected.txt
new file mode 100644 (file)
index 0000000..a50b55d
--- /dev/null
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {TEXT} at (0,0) size 573x18
+          text run at (0,0) width 573: "If the canvas below is black, then we managed to draw before loading stylesheets. Hooray!"
+      RenderBlock (anonymous) at (0,34) size 784x200
+        RenderHTMLCanvas {CANVAS} at (0,0) size 400x200
+        RenderText {TEXT} at (0,0) size 0x0
+        RenderText {TEXT} at (0,0) size 0x0
+        RenderText {TEXT} at (0,0) size 0x0
+        RenderText {TEXT} at (0,0) size 0x0
diff --git a/LayoutTests/fast/canvas/canvas-before-css.html b/LayoutTests/fast/canvas/canvas-before-css.html
new file mode 100644 (file)
index 0000000..51b562b
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+<head>
+    <link rel="stylesheet" href="about:blank" type="text/css">
+</head>
+<body>
+    <p>If the canvas below is black, then we managed to draw before loading stylesheets. Hooray!</p>
+    <canvas id="mycanvas" width="400" height="200"></canvas>
+    <script type="application/x-javascript">
+        var canvas = document.getElementById("mycanvas");
+        canvas.getContext("2d").fillRect(0, 0, canvas.width, canvas.height);
+    </script>
+</body>
+</html>
index 58e51fd63d4e12c404a2e1bcc4b80118d4b8fabf..7006de6e9233799ba004ece2b0b37c4a0b9a000f 100644 (file)
@@ -5,7 +5,7 @@ layer at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x584
       RenderText {TEXT} at (0,0) size 722x18
         text run at (0,0) width 722: "The canvas below should show a gradient, starting at green at the top and fading to white at the bottom of the rect. "
-      RenderCanvasImage {CANVAS} at (0,18) size 150x150
+      RenderHTMLCanvas {CANVAS} at (0,18) size 150x150
       RenderText {TEXT} at (0,0) size 0x0
       RenderText {TEXT} at (0,0) size 0x0
       RenderText {TEXT} at (0,0) size 0x0
index f2611b384e560c1d4bd2e956a0e89caf508531b0..3832a3d904ded1d4b2c17d2732b02ef5a4edfd26 100644 (file)
@@ -8,15 +8,15 @@ layer at (0,0) size 800x543
           text run at (0,0) width 779: "This tests that the Image JavaScript object works as expected when used in a canvas. If the test is successful, the Apple logo"
           text run at (0,18) width 354: "should appear scaled, normal and finally tiled in a circle."
       RenderBlock {DIV} at (0,52) size 784x154
-        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderHTMLCanvas {CANVAS} at (0,0) size 150x150
         RenderText {TEXT} at (150,136) size 117x18
           text run at (150,136) width 117: "Using drawImage."
       RenderBlock {DIV} at (0,206) size 784x154
-        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderHTMLCanvas {CANVAS} at (0,0) size 150x150
         RenderText {TEXT} at (150,136) size 180x18
           text run at (150,136) width 180: "Using drawImageFromRect."
       RenderBlock {DIV} at (0,360) size 784x154
-        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderHTMLCanvas {CANVAS} at (0,0) size 150x150
         RenderText {TEXT} at (150,136) size 129x18
           text run at (150,136) width 129: "Using ImagePattern."
       RenderBlock {PRE} at (0,527) size 784x0
index 9038ec0b14c0269960623ead96cf1592a6fb76b1..59ddcf41c36cc8b405ed7227e0a72401af0a7aa3 100644 (file)
@@ -46,9 +46,9 @@ function runTests() {
 </head>
 <body onload="runTests();">
 <p>This tests that the Image JavaScript object works as expected when used in a canvas. If the test is successful, the Apple logo should appear scaled, normal and finally tiled in a circle.</p>
-<div><canvas id="canvas1" width="150" height="150"/>Using drawImage.</div>
-<div><canvas id="canvas2" width="150" height="150"/>Using drawImageFromRect.</div>
-<div><canvas id="canvas3" width="150" height="150"/>Using ImagePattern.</div>
+<div><canvas id="canvas1" width="150" height="150"></canvas>Using drawImage.</div>
+<div><canvas id="canvas2" width="150" height="150"></canvas>Using drawImageFromRect.</div>
+<div><canvas id="canvas3" width="150" height="150"></canvas>Using ImagePattern.</div>
 
 <pre id="console">
 </pre>
index 54259bedcb86f068aa0d723c75861dc17f05c185..d9005613b41cdf0db920a869a1b200586261c6ed 100644 (file)
@@ -10,4 +10,4 @@ layer at (0,0) size 800x460
           text run at (0,36) width 764: "Bottom left square should be one row with three Apple images along the top of the square. Bottom right square should be"
           text run at (0,54) width 220: "one Apple image in top left corner."
       RenderBlock {P} at (0,88) size 784x340
-        RenderCanvasImage {CANVAS} at (0,0) size 336x336 [border: (3px solid #000000)]
+        RenderHTMLCanvas {CANVAS} at (0,0) size 336x336 [border: (3px solid #000000)]
index a9a3cf0fa6773e55d121a7054a2b6b0d841da76e..df3a473cd6387c396331d2bb9d1b8da0ada25c4a 100644 (file)
@@ -7,4 +7,4 @@ layer at (0,0) size 800x414
         RenderText {TEXT} at (0,0) size 416x18
           text run at (0,0) width 416: "This test case should produce a sine-wave stroked with 1px black."
     RenderBlock (anonymous) at (0,50) size 800x364
-      RenderCanvasImage {CANVAS} at (0,0) size 480x360
+      RenderHTMLCanvas {CANVAS} at (0,0) size 480x360
index ca1dd0c40dd9a2f8d0dbd7fc0314fef30075ecd5..aabc4a8ed1b3c84094288068d5094c022df7731c 100644 (file)
@@ -1,3 +1,83 @@
+2006-04-09  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
+          Canvas element breaks when RenderObject creation is deferred by external CSS
+
+        Test: fast/canvas/canvas-before-css.html
+
+        This patch makes us match the canvas documentation in Hixie's Web Applications
+        draft as far as when the canvas is created and recreated and how it's sized.
+        It also gets rid of the compositeOperation attribute of the canvas element.
+        We can add that back if we need it. Anders points out that this specifically
+        changes behavior for canvas elements where the size is set in CSS and not with
+        width and height attributes. The CSS size now determines how big a box the canvas
+        is rendered into, but has no effect on the size of the canvas's buffer.
+
+        * html/CanvasRenderingContext2D.h: Added overloads of drawImage that take
+        HTMLCanvasElement, which is no longer derived from HTMLImageElement.
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::imageSize): Renamed from imageOrCanvasSize. Now used for images only,
+        because canvas is no longer derived from image.
+        (WebCore::CanvasRenderingContext2D::drawImage): Split the implementation of this
+        for image sources from the implementation for canvas sources.
+        (WebCore::CanvasRenderingContext2D::willDraw): Changed to call a new willDraw
+        function on the canvas element.
+        (WebCore::CanvasRenderingContext2D::drawingContext): Changed to call drawingContext
+        on the canvas element rather than the renderer.
+
+        * html/HTMLCanvasElement.h: Changed HTMLCanvasElement to derive from HTMLElement
+        instead of HTMLImageElement. Added width, height, setWidth, setHeight, willDraw,
+        paint, drawingContext, createDrawingContext, and reset functions. Added m_size,
+        m_createdDrawingContext, m_data, and m_drawingContext data members. Removed
+        mapToEntry, attach, detach, and isURLAttribute functins.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::HTMLCanvasElement): Added initializers for new m_size,
+        m_createdDrawingContext, m_data, and m_drawingContext data members.
+        (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Free m_data and m_drawingContext.
+        (WebCore::HTMLCanvasElement::parseMappedAttribute): Got rid of special case for
+        srcAttr, which is no longer needed since we aren't deriving from HTMLImageElement.
+        Added code that triggers a reset when either width or height is set.
+        (WebCore::HTMLCanvasElement::createRenderer): Added code to set the intrinsic
+        width and height of the renderer to the size of the element.
+        (WebCore::HTMLCanvasElement::setHeight): Added. Sets the height attribute.
+        (WebCore::HTMLCanvasElement::setWidth): Added. Sets the width attribute.
+        (WebCore::HTMLCanvasElement::willDraw): Added. Tells the renderer to repaint.
+        Also has FIXME mentioning we could dirty only the part that has changed in the future.
+        (WebCore::HTMLCanvasElement::reset): Added. Sets the size of the canvas and discards
+        the old buffer, which is an indirect way of resetting the buffer to transparent black.
+        (WebCore::HTMLCanvasElement::paint): Added. Draws the canvas image into the graphics
+        context that's passed in.
+        (WebCore::HTMLCanvasElement::createDrawingContext): Added. Allocates a buffer for
+        the bits, then creates a bitmap context for drawing into the buffer.
+        (WebCore::HTMLCanvasElement::drawingContext): Added. Calls createDrawingContext if
+        needed, then returns the current drawing context.
+        (WebCore::HTMLCanvasElement::createPlatformImage): Changed to always call CGContextFlush
+        and to create the image from the context in this class.
+
+        * rendering/RenderHTMLCanvas.h: Remove almost all of the contents of this file.
+        Removed ~RenderHTMLCanvas, setNeedsImageUpdate, element, updateDrawnImage, drawingContext,
+        createDrawingContext, and drawnImage functions and _drawingContext, _drawingContextData,
+        _drawnImage, and _needsImageUpdate booleans. Changed RenderHTMLCanvas to derive from
+        RenderReplaced instead of RenderImage.
+
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::RenderHTMLCanvas): Changed to only initialize RenderReplaced.
+        (WebCore::RenderHTMLCanvas::renderName): Moved this in here, since there's no good reason
+        to have this virtual function inlined.
+        (WebCore::RenderHTMLCanvas::paint): Changed implementation to use HTMLCanvasElement::paint
+        instead ofcalling CGContextDrawImage directly.
+        (WebCore::RenderHTMLCanvas::layout): Removed the code that detects changes in width and
+        causes the drawing context to be recreated; instead, if the width and height changes we
+        scale when we paint the canvas.
+
+        * bindings/js/JSCanvasRenderingContext2DBase.cpp:
+        (WebCore::JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction):
+        Separated out handling for <canvas> vs. <img> elements in drawRect, since
+        HTMLCanvasElement is no longer derived from HTMLImageElement.
+
 2006-04-09  Rob Buis  <buis@kde.org>
 
         Reviewed by eseidel.  Landed by eseidel.
index 60b6445dd47a5312f8f0fa3aadecdf33cb6c2364..7274d7dbf4c0bbcce16161cadfa5b593c909c7f7 100644 (file)
@@ -17,8 +17,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-// This file needs to be touched every once in a while.
-
 #include "config.h"
 #include "JSCanvasRenderingContext2DBase.h"
 
@@ -26,6 +24,7 @@
 #include "CanvasPattern.h"
 #include "CanvasRenderingContext2D.h"
 #include "CanvasStyle.h"
+#include "HTMLCanvasElement.h"
 #include "JSCanvasGradient.h"
 #include "JSCanvasPattern.h"
 #include "html_imageimpl.h"
@@ -178,35 +177,57 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
             break;
         case JSCanvasRenderingContext2DBase::DrawImage: {
             // DrawImage has three variants:
-            // drawImage(img, dx, dy)
-            // drawImage(img, dx, dy, dw, dh)
-            // drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh)
-            // composite operation is specified with globalCompositeOperation
-            // img parameter can be a JavaScript Image, <img>, or a <canvas>
+            //     drawImage(img, dx, dy)
+            //     drawImage(img, dx, dy, dw, dh)
+            //     drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh)
+            // Composite operation is specified with globalCompositeOperation.
+            // The img parameter can be a <img> or <canvas> element.
             JSObject* o = static_cast<JSObject*>(args[0]);
             if (!o->isObject())
                 return throwError(exec, TypeError);
-            if (!(o->inherits(&JSHTMLElement::img_info) || o->inherits(&JSHTMLElement::canvas_info)))
-                return throwError(exec, TypeError);
-            HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
-            switch (args.size()) {
-                case 3:
-                    context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec));
-                    break;
-                case 5:
-                    context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
-                        args[3]->toNumber(exec), args[4]->toNumber(exec));
-                    break;
-                case 9:
-                    context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
-                        args[3]->toNumber(exec), args[4]->toNumber(exec),
-                        args[5]->toNumber(exec), args[6]->toNumber(exec),
-                        args[7]->toNumber(exec), args[8]->toNumber(exec));
-                    break;
-                default:
-                    return throwError(exec, SyntaxError);
+            if (o->inherits(&JSHTMLElement::img_info)) {
+                HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
+                switch (args.size()) {
+                    case 3:
+                        context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec));
+                        break;
+                    case 5:
+                        context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
+                            args[3]->toNumber(exec), args[4]->toNumber(exec));
+                        break;
+                    case 9:
+                        context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
+                            args[3]->toNumber(exec), args[4]->toNumber(exec),
+                            args[5]->toNumber(exec), args[6]->toNumber(exec),
+                            args[7]->toNumber(exec), args[8]->toNumber(exec));
+                        break;
+                    default:
+                        return throwError(exec, SyntaxError);
+                }
+                break;
             }
-            break;
+            if (o->inherits(&JSHTMLElement::canvas_info)) {
+                HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
+                switch (args.size()) {
+                    case 3:
+                        context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec));
+                        break;
+                    case 5:
+                        context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec),
+                            args[3]->toNumber(exec), args[4]->toNumber(exec));
+                        break;
+                    case 9:
+                        context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec),
+                            args[3]->toNumber(exec), args[4]->toNumber(exec),
+                            args[5]->toNumber(exec), args[6]->toNumber(exec),
+                            args[7]->toNumber(exec), args[8]->toNumber(exec));
+                        break;
+                    default:
+                        return throwError(exec, SyntaxError);
+                }
+                break;
+            }
+            return throwError(exec, TypeError);
         }
         case JSCanvasRenderingContext2DBase::DrawImageFromRect: {
             JSObject* o = static_cast<JSObject*>(args[0]);
index 706cc57a7d2a59f022b9f1e815958863d44f7433..88749c6f862e073c026963aa91cc41484a34e19f 100644 (file)
@@ -770,10 +770,8 @@ void CanvasRenderingContext2D::applyShadow()
 }
 
 // FIXME: This only exists because canvas is a subclass of image.
-static IntSize imageOrCanvasSize(HTMLImageElement* image)
+static IntSize imageSize(HTMLImageElement* image)
 {
-    if (image->hasLocalName(canvasTag))
-        return static_cast<HTMLCanvasElement*>(image)->size();
     if (CachedImage* cachedImage = image->cachedImage())
         return cachedImage->imageSize();
     return IntSize();
@@ -783,7 +781,7 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float
 {
     if (!image)
         return;
-    IntSize size = imageOrCanvasSize(image);
+    IntSize size = imageSize(image);
     drawImage(image, 0, 0, size.width(), size.height(), x, y, size.width(), size.height());
 }
 
@@ -791,7 +789,7 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float
 {
     if (!image)
         return;
-    IntSize size = imageOrCanvasSize(image);
+    IntSize size = imageSize(image);
     drawImage(image, 0, 0, size.width(), size.height(), x, y, width, height);
 }
 
@@ -808,23 +806,49 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
     if (!c)
         return;
 
+    CachedImage* cachedImage = image->cachedImage();
+    if (!cachedImage)
+        return;
+
     FloatRect destRect = FloatRect(dx, dy, dw, dh);
+    willDraw(destRect);
+    cachedImage->image()->drawInRect(destRect, FloatRect(sx, sy, sw, sh),
+        Image::compositeOperatorFromString(state().m_globalComposite), c);
+#endif
+}
 
-    if (!image->hasLocalName(canvasTag)) {
-        CachedImage* cachedImage = image->cachedImage();
-        if (!cachedImage)
-            return;
+void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y)
+{
+    if (!canvas)
+        return;
+    drawImage(canvas, 0, 0, canvas->width(), canvas->height(), x, y, canvas->width(), canvas->height());
+}
 
-        willDraw(destRect);
-        cachedImage->image()->drawInRect(destRect, FloatRect(sx, sy, sw, sh),
-            Image::compositeOperatorFromString(state().m_globalComposite), c);
+void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y, float width, float height)
+{
+    if (!canvas)
+        return;
+    drawImage(canvas, 0, 0, canvas->width(), canvas->height(), x, y, width, height);
+}
+
+void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
+    float sx, float sy, float sw, float sh,
+    float dx, float dy, float dw, float dh)
+{
+    if (!canvas)
+        return;
+
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+    CGContextRef c = drawingContext();
+    if (!c)
         return;
-    }
 
-    CGImageRef platformImage = static_cast<HTMLCanvasElement*>(image)->createPlatformImage();
+    CGImageRef platformImage = canvas->createPlatformImage();
     if (!platformImage)
         return;
 
+    FloatRect destRect = FloatRect(dx, dy, dw, dh);
     willDraw(destRect);
 
     float iw = CGImageGetWidth(platformImage);
@@ -871,21 +895,17 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
     if (!image)
         return;
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = drawingContext();
-    if (!c)
-        return;
-
-    FloatRect destRect = FloatRect(dx, dy, dw, dh);
-
-    // FIXME: Does not support using a canvas as a source image.
     CachedImage* cachedImage = image->cachedImage();
     if (!cachedImage)
         return;
 
+    // FIXME: Do this through platform-independent GraphicsContext API.
+    FloatRect destRect = FloatRect(dx, dy, dw, dh);
     willDraw(destRect);
-
+#if __APPLE__
+    CGContextRef c = drawingContext();
+    if (!c)
+        return;
     cachedImage->image()->drawInRect(destRect, FloatRect(sx, sy, sw, sh),
         Image::compositeOperatorFromString(compositeOperation), c);
 #endif
@@ -916,13 +936,11 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
     return new CanvasPattern(image ? image->cachedImage() : 0, repetitionType);
 }
 
-void CanvasRenderingContext2D::willDraw(const FloatRect&)
+void CanvasRenderingContext2D::willDraw(const FloatRect& r)
 {
     if (!m_canvas)
         return;
-    RenderHTMLCanvas* renderer = static_cast<RenderHTMLCanvas*>(m_canvas->renderer());
-    if (renderer)
-        renderer->setNeedsImageUpdate();
+    m_canvas->willDraw(r);
 }
 
 #if __APPLE__
@@ -931,10 +949,7 @@ CGContextRef CanvasRenderingContext2D::drawingContext() const
 {
     if (!m_canvas)
         return 0;
-    RenderHTMLCanvas* renderer = static_cast<RenderHTMLCanvas*>(m_canvas->renderer());
-    if (!renderer)
-        return 0;
-    return renderer->drawingContext();
+    return m_canvas->drawingContext();
 }
 
 void CanvasRenderingContext2D::applyStrokePattern()
index 44d63ffc12b49f9c9a9880883b6a1181ef622294..fb7349ff01406316b2bc16f18d802db2e2cef3a0 100644 (file)
@@ -142,6 +142,10 @@ namespace WebCore {
         void drawImage(HTMLImageElement*, float x, float y, float width, float height);
         void drawImage(HTMLImageElement*, float sx, float sy, float sw, float sh,
             float dx, float dy, float dw, float dh);
+        void drawImage(HTMLCanvasElement*, float x, float y);
+        void drawImage(HTMLCanvasElement*, float x, float y, float width, float height);
+        void drawImage(HTMLCanvasElement*, float sx, float sy, float sw, float sh,
+            float dx, float dy, float dw, float dh);
 
         void drawImageFromRect(HTMLImageElement*, float sx, float sy, float sw, float sh,
             float dx, float dy, float dw, float dh, const String& compositeOperation);
index f3ec75ad2619075a683ad8ec9d753924d84b95f5..105a2d779fea89a68abea7df49d182e8fd8f7a2f 100644 (file)
@@ -30,6 +30,7 @@
 #include "CanvasPattern.h"
 #include "CanvasRenderingContext2D.h"
 #include "CanvasStyle.h"
+#include "GraphicsContext.h"
 #include "HTMLNames.h"
 #include "RenderHTMLCanvas.h"
 
@@ -37,8 +38,16 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLCanvasElement::HTMLCanvasElement(Document *doc)
-    : HTMLImageElement(canvasTag, doc), m_2DContext(0)
+// These value come from the specification.
+const int defaultWidth = 300;
+const int defaultHeight = 150;
+
+HTMLCanvasElement::HTMLCanvasElement(Document* doc)
+    : HTMLElement(canvasTag, doc), m_size(defaultWidth, defaultHeight)
+    , m_createdDrawingContext(false), m_data(0)
+#if __APPLE__
+    , m_drawingContext(0)
+#endif
 {
 }
 
@@ -46,48 +55,36 @@ HTMLCanvasElement::~HTMLCanvasElement()
 {
     if (m_2DContext)
         m_2DContext->detachCanvas();
-}
-
-bool HTMLCanvasElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
-{
-    if (attrName != srcAttr) // Ignore the src attribute
-        return HTMLImageElement::mapToEntry(attrName, result);
-    return false;
-}
-
-void HTMLCanvasElement::parseMappedAttribute(MappedAttribute *attr)
-{
-    if (attr->name() != srcAttr) // Canvas ignores the src attribute
-        HTMLImageElement::parseMappedAttribute(attr);
-}
-
-RenderObject *HTMLCanvasElement::createRenderer(RenderArena *arena, RenderStyle *style)
-{
+    fastFree(m_data);
 #if __APPLE__
-    return new (arena) RenderHTMLCanvas(this);
-#else
-    return 0;
+    CGContextRelease(m_drawingContext);
 #endif
 }
 
-void HTMLCanvasElement::attach()
+void HTMLCanvasElement::parseMappedAttribute(MappedAttribute* attr)
 {
-    // Don't want to call image's attach().
-    HTMLElement::attach();
+    const QualifiedName& attrName = attr->name();
+    if (attrName == widthAttr || attrName == heightAttr)
+        reset();
+    HTMLElement::parseMappedAttribute(attr);
 }
 
-void HTMLCanvasElement::detach()
+RenderObject* HTMLCanvasElement::createRenderer(RenderArena *arena, RenderStyle *style)
 {
-    // Don't want to call image's detach().
-    HTMLElement::detach();
+    RenderHTMLCanvas* r = new (arena) RenderHTMLCanvas(this);
+    r->setIntrinsicWidth(width());
+    r->setIntrinsicHeight(height());
+    return r;
+}
 
-    if (m_2DContext)
-        m_2DContext->reset();
+void HTMLCanvasElement::setHeight(int value)
+{
+    setAttribute(heightAttr, String::number(value));
 }
 
-bool HTMLCanvasElement::isURLAttribute(Attribute *attr) const
+void HTMLCanvasElement::setWidth(int value)
 {
-    return ((attr->name() == usemapAttr && attr->value().domString()[0] != '#'));
+    setAttribute(widthAttr, String::number(value));
 }
 
 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
@@ -101,28 +98,91 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
     return 0;
 }
 
-IntSize HTMLCanvasElement::size() const
+void HTMLCanvasElement::willDraw(const FloatRect&)
+{
+    // FIXME: Change to repaint just the dirty rect for speed.
+    // Until we start doing this, we won't know if the rects passed in are
+    // accurate. Also don't forget to take into account the transform
+    // on the context when determining what needs to be repainted.
+    if (renderer())
+        renderer()->repaint();
+}
+
+void HTMLCanvasElement::reset()
 {
-    RenderHTMLCanvas* canvasRenderer = static_cast<RenderHTMLCanvas*>(renderer());
-    if (!canvasRenderer)
-        return IntSize();
+    bool ok;
+    int w = getAttribute(widthAttr).toInt(&ok);
+    if (!ok)
+        w = defaultWidth;
+    int h = getAttribute(heightAttr).toInt(&ok);
+    if (!ok)
+        h = defaultHeight;
+    m_size = IntSize(w, h);
+
+    RenderHTMLCanvas* r = static_cast<RenderHTMLCanvas*>(renderer());
+    if (r) {
+        r->setIntrinsicWidth(w);
+        r->setIntrinsicHeight(h);
+        r->repaint();
+    }
+
+    m_createdDrawingContext = false;
+    CGContextRelease(m_drawingContext);
+    m_drawingContext = 0;
+    fastFree(m_data);
+    m_data = 0;
+}
+
+void HTMLCanvasElement::paint(GraphicsContext* p, const IntRect& r)
+{
+    if (p->paintingDisabled())
+        return;
 #if __APPLE__
-    if (CGContextRef context = canvasRenderer->drawingContext())
-        return IntSize(CGBitmapContextGetWidth(context), CGBitmapContextGetHeight(context));
+    if (CGImageRef image = createPlatformImage()) {
+        CGContextDrawImage(p->currentCGContext(), r, image);
+        CGImageRelease(image);
+    }
+#endif
+}
+
+void HTMLCanvasElement::createDrawingContext() const
+{
+    ASSERT(!m_createdDrawingContext);
+    ASSERT(!m_data);
+
+    m_createdDrawingContext = true;
+
+    if (width() <= 0 || height() <= 0)
+        return;
+    unsigned w = width();
+    size_t bytesPerRow = w * 4;
+    if (bytesPerRow / 4 != w) // check for overflow
+        return;
+    m_data = fastCalloc(height(), bytesPerRow);
+    if (!m_data)
+        return;
+#if __APPLE__
+    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+    m_drawingContext = CGBitmapContextCreate(m_data, w, height(), 8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
+    CGColorSpaceRelease(colorSpace);
 #endif
-    return IntSize();
 }
 
 #if __APPLE__
 
+CGContextRef HTMLCanvasElement::drawingContext() const
+{
+    if (!m_createdDrawingContext)
+        createDrawingContext();
+    return m_drawingContext;
+}
+
 CGImageRef HTMLCanvasElement::createPlatformImage() const
 {
-    RenderHTMLCanvas* canvasRenderer = static_cast<RenderHTMLCanvas*>(renderer());
-    if (!canvasRenderer)
-        return 0;
-    CGContextRef context = canvasRenderer->drawingContext();
+    CGContextRef context = drawingContext();
     if (!context)
         return 0;
+    CGContextFlush(context);
     return CGBitmapContextCreateImage(context);
 }
 
index 5b93a8927980e8d77a0c0a0d40cf7e1e8d3120e3..bce4ea7757df4e8bf478d2be123b3bdf4b363755 100644 (file)
@@ -29,6 +29,8 @@
 #include "html_imageimpl.h"
 
 #if __APPLE__
+// FIXME: Mac-specific parts need to move to the platform directory.
+typedef struct CGContext* CGContextRef;
 typedef struct CGImage* CGImageRef;
 #endif
 
@@ -37,35 +39,48 @@ namespace WebCore {
 class CanvasRenderingContext2D;
 typedef CanvasRenderingContext2D CanvasRenderingContext;
 
-// FIXME: Should inherit from HTMLElement instead of HTMLImageElement.
-class HTMLCanvasElement : public HTMLImageElement {
+class HTMLCanvasElement : public HTMLElement {
 public:
     HTMLCanvasElement(Document*);
-    ~HTMLCanvasElement();
+    virtual ~HTMLCanvasElement();
 
-    CanvasRenderingContext* getContext(const String&);
+    int width() const { return m_size.width(); }
+    int height() const { return m_size.height(); }
+    void setWidth(int);
+    void setHeight(int);
 
+    CanvasRenderingContext* getContext(const String&);
     // FIXME: Web Applications 1.0 describes a toDataURL function.
 
-    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
     virtual void parseMappedAttribute(MappedAttribute*);
-
-    virtual void attach();
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
-    virtual void detach();
-    
-    virtual bool isURLAttribute(Attribute*) const;
 
-    IntSize size() const;
+    IntSize size() const { return m_size; }
+    void willDraw(const FloatRect&);
+
+    void paint(GraphicsContext*, const IntRect&);
 
 #if __APPLE__
     CGImageRef createPlatformImage() const;
+    CGContextRef drawingContext() const;
 #endif
 
 private:
+    void createDrawingContext() const;
+    void reset();
+
     RefPtr<CanvasRenderingContext2D> m_2DContext;
-    // FIXME: Web Applications 1.0 describes a security feature where we track if we ever drew
-    // any images outside the domain.
+    IntSize m_size;
+
+    // FIXME: Web Applications 1.0 describes a security feature where we track
+    // if we ever drew any images outside the domain, so we can disable toDataURL.
+
+    mutable bool m_createdDrawingContext;
+    mutable void* m_data;
+
+#if __APPLE__
+    mutable CGContextRef m_drawingContext;
+#endif
 };
 
 } //namespace
index 71a8c8c5b86b9ddeb1861fff14302573f118f4dd..24f505947cda4ad1cecc1fd5e5e6da64bbbaf40e 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-//#define DEBUG_LAYOUT
-
 #include "config.h"
 #include "RenderHTMLCanvas.h"
 
-#if __APPLE__
-
-#include "Document.h"
 #include "GraphicsContext.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLNames.h"
@@ -39,104 +34,29 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-RenderHTMLCanvas::RenderHTMLCanvas(Node *_node)
-    : RenderImage(_node), _drawingContext(0), _drawingContextData(0), _drawnImage(0), _needsImageUpdate(0)
-{
-}
-
-RenderHTMLCanvas::~RenderHTMLCanvas()
-{
-    if (_drawingContext) {
-        CFRelease (_drawingContext);
-        _drawingContext = 0;
-    }
-    
-    fastFree(_drawingContextData);
-    _drawingContextData = 0;
-    
-    if (_drawnImage) {
-        CFRelease (_drawnImage);
-        _drawnImage = 0;
-    }
-}
-
-#define BITS_PER_COMPONENT 8
-#define BYTES_PER_ROW(width,bitsPerComponent,numComponents) ((width * bitsPerComponent * numComponents + 7)/8)
-
-void RenderHTMLCanvas::createDrawingContext()
-{
-    if (_drawingContext) {
-        CFRelease (_drawingContext);
-        _drawingContext = 0;
-    }
-    fastFree(_drawingContextData);
-    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-
-    int cWidth = contentWidth();
-    int cHeight = contentHeight();
-    size_t numComponents = CGColorSpaceGetNumberOfComponents(colorSpace);
-    size_t bytesPerRow = BYTES_PER_ROW(cWidth,BITS_PER_COMPONENT,(numComponents+1)); // + 1 for alpha
-    _drawingContextData = fastCalloc(height(), bytesPerRow);
-    _drawingContext = CGBitmapContextCreate(_drawingContextData, cWidth, cHeight, BITS_PER_COMPONENT, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
-    
-#ifdef DEBUG_CANVAS_BACKGROUND
-    CGContextSetRGBFillColor(_drawingContext, 1.0, 0., 0., 1.);
-    CGContextFillRect (_drawingContext, CGRectMake (0, 0, width(), height()));
-    CGContextFlush (_drawingContext);
-#endif
-    
-    updateDrawnImage();
-    
-    CFRelease (colorSpace);
-}
-
-CGContextRef RenderHTMLCanvas::drawingContext()
-{
-    if (!_drawingContext) {
-        document()->updateLayout();
-        createDrawingContext();
-    }
-    
-    return _drawingContext;
-}
-
-void RenderHTMLCanvas::setNeedsImageUpdate()
+RenderHTMLCanvas::RenderHTMLCanvas(Node* n)
+    : RenderReplaced(n)
 {
-    _needsImageUpdate = true;
-    repaint();
 }
 
-
-void RenderHTMLCanvas::updateDrawnImage()
+const char* RenderHTMLCanvas::renderName() const
 {
-    if (_drawnImage)
-        CFRelease (_drawnImage);
-    CGContextFlush (_drawingContext);
-    _drawnImage = CGBitmapContextCreateImage (_drawingContext);
+    return "RenderHTMLCanvas";
 }
 
-CGImageRef RenderHTMLCanvas::drawnImage()
+void RenderHTMLCanvas::paint(PaintInfo& i, int tx, int ty)
 {
-    return _drawnImage;
-}
-
-void RenderHTMLCanvas::paint(PaintInfo& i, int _tx, int _ty)
-{
-    if (!shouldPaint(i, _tx, _ty))
+    if (!shouldPaint(i, tx, ty))
         return;
 
-    int x = _tx + m_x;
-    int y = _ty + m_y;
+    int x = tx + m_x;
+    int y = ty + m_y;
 
     if (shouldPaintBackgroundOrBorder() && (i.phase == PaintPhaseForeground || i.phase == PaintPhaseSelection)) 
         paintBoxDecorations(i, x, y);
 
-    GraphicsContext* p = i.p;
-    if (p->paintingDisabled())
-        return;
-    
     if ((i.phase == PaintPhaseOutline || i.phase == PaintPhaseSelfOutline) && style()->outlineWidth() && style()->visibility() == VISIBLE)
-        paintOutline(p, x, y, width(), height(), style());
+        paintOutline(i.p, x, y, width(), height(), style());
     
     if (i.phase != PaintPhaseForeground && i.phase != PaintPhaseSelection)
         return;
@@ -144,71 +64,36 @@ void RenderHTMLCanvas::paint(PaintInfo& i, int _tx, int _ty)
     if (!shouldPaintWithinRoot(i))
         return;
 
-    bool isPrinting = i.p->printing();
-    bool drawSelectionTint = (selectionState() != SelectionNone) && !isPrinting;
+    bool drawSelectionTint = selectionState() != SelectionNone && !i.p->printing();
     if (i.phase == PaintPhaseSelection) {
         if (selectionState() == SelectionNone)
             return;
         drawSelectionTint = false;
     }
 
-    int cWidth = contentWidth();
-    int cHeight = contentHeight();
-    int leftBorder = borderLeft();
-    int topBorder = borderTop();
-    int leftPad = paddingLeft();
-    int topPad = paddingTop();
-
-    x += leftBorder + leftPad;
-    y += topBorder + topPad;
-    
-    if (_needsImageUpdate) {
-        updateDrawnImage();
-        _needsImageUpdate = false;
-    }
-    
-    if (drawnImage()) {
-        HTMLCanvasElement* i = (element() && element()->hasTagName(canvasTag)) ? static_cast<HTMLCanvasElement*>(element()) : 0;
-        int oldOperation = 0;
-        if (i) {
-            oldOperation = GraphicsContext::getCompositeOperation(GraphicsContext::currentCGContext());
-            GraphicsContext::setCompositeOperation(GraphicsContext::currentCGContext(), i->compositeOperator());
-        }
-        CGContextDrawImage(GraphicsContext::currentCGContext(), CGRectMake(x, y, cWidth, cHeight), drawnImage());
-        if (i)
-            GraphicsContext::setCompositeOperation(GraphicsContext::currentCGContext(), oldOperation);
-    }
+    if (element() && element()->hasTagName(canvasTag))
+        static_cast<HTMLCanvasElement*>(element())->paint(i.p,
+            IntRect(x + borderLeft() + paddingLeft(), y + borderTop() + paddingTop(), contentWidth(), contentHeight()));
 
     if (drawSelectionTint)
-        p->fillRect(selectionRect(), selectionColor(p));
+        i.p->fillRect(selectionRect(), selectionColor(i.p));
 }
 
 void RenderHTMLCanvas::layout()
 {
-    KHTMLAssert(needsLayout());
-    KHTMLAssert(minMaxKnown());
+    ASSERT(needsLayout());
+    ASSERT(minMaxKnown());
 
     IntRect oldBounds;
     bool checkForRepaint = checkForRepaintDuringLayout();
     if (checkForRepaint)
         oldBounds = getAbsoluteRepaintRect();
-
-    int oldwidth = m_width;
-    int oldheight = m_height;
-    
     calcWidth();
     calcHeight();
-
-    if ( m_width != oldwidth || m_height != oldheight ) {
-        createDrawingContext();
-    }
-
     if (checkForRepaint)
         repaintAfterLayoutIfNeeded(oldBounds, oldBounds);
-    
+
     setNeedsLayout(false);
 }
 
 }
-
-#endif
index f25cf78a941c7aac68dec8162051ae4843dfe341..f835da23897430bdf993a31e77befaac68519803 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef RENDER_CANVASIMAGE_H
-#define RENDER_CANVASIMAGE_H
+#ifndef RENDERHTMLCANVAS_H
+#define RENDERHTMLCANVAS_H
 
-
-#include "HTMLElement.h"
-#include "RenderImage.h"
-
-#if __APPLE__
-// FIXME: Mac-specific parts need to move to the platform directory.
-#include <ApplicationServices/ApplicationServices.h>
-#endif
+#include "render_replaced.h"
 
 namespace WebCore {
 
-class DocLoader;
-
-class RenderHTMLCanvas : public RenderImage
-{
-public:
-    RenderHTMLCanvas(Node*);
-    virtual ~RenderHTMLCanvas();
-
-    virtual const char *renderName() const { return "RenderCanvasImage"; }
-    
-    virtual void paint(PaintInfo& i, int tx, int ty);
-
-    virtual void layout();
-
-    void setNeedsImageUpdate();
-    
-    // don't even think about making this method virtual!
-    HTMLElement* element() const
-        { return static_cast<HTMLElement*>(RenderImage::element()); }
-    
-#if __APPLE__
-    void updateDrawnImage();
-    CGContextRef drawingContext();
-    
-private:
-    void createDrawingContext();
-    CGImageRef drawnImage();
-
-    CGContextRef _drawingContext;
-    void *_drawingContextData;
-    CGImageRef _drawnImage;
-    
-    bool _needsImageUpdate : 1;
-#endif
-};
+    class RenderHTMLCanvas : public RenderReplaced {
+    public:
+        RenderHTMLCanvas(Node*);
+        virtual const char* renderName() const;
+        virtual void paint(PaintInfo&, int tx, int ty);
+        virtual void layout();
+    };
 
 } //namespace