2 * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef HTMLCanvasElement_h
28 #define HTMLCanvasElement_h
30 #include "TransformationMatrix.h"
31 #include "FloatRect.h"
32 #include "HTMLElement.h"
34 #include "GraphicsContext3D.h"
40 class CanvasRenderingContext
;
44 class GraphicsContext
;
45 class HTMLCanvasElement
;
50 class CanvasObserver
{
52 virtual ~CanvasObserver() { }
54 virtual void canvasChanged(HTMLCanvasElement
*, const FloatRect
& changedRect
) = 0;
55 virtual void canvasResized(HTMLCanvasElement
*) = 0;
56 virtual void canvasDestroyed(HTMLCanvasElement
*) = 0;
59 class HTMLCanvasElement
: public HTMLElement
{
61 HTMLCanvasElement(const QualifiedName
&, Document
*);
62 virtual ~HTMLCanvasElement();
64 int width() const { return m_size
.width(); }
65 int height() const { return m_size
.height(); }
69 String
toDataURL(const String
& mimeType
, ExceptionCode
&);
71 CanvasRenderingContext
* getContext(const String
&);
73 const IntSize
& size() const { return m_size
; }
74 void setSize(const IntSize
& size
)
79 setWidth(size
.width());
80 setHeight(size
.height());
81 m_ignoreReset
= false;
85 void willDraw(const FloatRect
&);
87 void paint(GraphicsContext
*, const IntRect
&);
89 GraphicsContext
* drawingContext() const;
91 ImageBuffer
* buffer() const;
93 IntRect
convertLogicalToDevice(const FloatRect
&) const;
94 IntSize
convertLogicalToDevice(const FloatSize
&) const;
95 IntPoint
convertLogicalToDevice(const FloatPoint
&) const;
97 void setOriginTainted() { m_originClean
= false; }
98 bool originClean() const { return m_originClean
; }
100 void setObserver(CanvasObserver
* observer
) { m_observer
= observer
; }
102 TransformationMatrix
baseTransform() const;
104 CanvasRenderingContext
* renderingContext() const { return m_context
.get(); }
106 #if ENABLE(3D_CANVAS)
111 #if ENABLE(DASHBOARD_SUPPORT)
112 virtual HTMLTagStatus
endTagRequirement() const;
113 virtual int tagPriority() const;
116 virtual void parseMappedAttribute(MappedAttribute
*);
117 virtual RenderObject
* createRenderer(RenderArena
*, RenderStyle
*);
119 void createImageBuffer() const;
122 static const float MaxCanvasArea
;
124 bool m_rendererIsCanvas
;
126 OwnPtr
<CanvasRenderingContext
> m_context
;
128 CanvasObserver
* m_observer
;
132 FloatRect m_dirtyRect
;
134 // m_createdImageBuffer means we tried to malloc the buffer. We didn't necessarily get it.
135 mutable bool m_createdImageBuffer
;
136 mutable OwnPtr
<ImageBuffer
> m_imageBuffer
;