Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / html / HTMLCanvasElement.h
blobedae9e55775412c02c411a793e43d2fc85e60437
1 /*
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
7 * are met:
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"
33 #if ENABLE(3D_CANVAS)
34 #include "GraphicsContext3D.h"
35 #endif
36 #include "IntSize.h"
38 namespace WebCore {
40 class CanvasRenderingContext;
41 class FloatPoint;
42 class FloatRect;
43 class FloatSize;
44 class GraphicsContext;
45 class HTMLCanvasElement;
46 class ImageBuffer;
47 class IntPoint;
48 class IntSize;
50 class CanvasObserver {
51 public:
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 {
60 public:
61 HTMLCanvasElement(const QualifiedName&, Document*);
62 virtual ~HTMLCanvasElement();
64 int width() const { return m_size.width(); }
65 int height() const { return m_size.height(); }
66 void setWidth(int);
67 void setHeight(int);
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)
76 if (size == m_size)
77 return;
78 m_ignoreReset = true;
79 setWidth(size.width());
80 setHeight(size.height());
81 m_ignoreReset = false;
82 reset();
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)
107 bool is3D() const;
108 #endif
110 private:
111 #if ENABLE(DASHBOARD_SUPPORT)
112 virtual HTMLTagStatus endTagRequirement() const;
113 virtual int tagPriority() const;
114 #endif
116 virtual void parseMappedAttribute(MappedAttribute*);
117 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
119 void createImageBuffer() const;
120 void reset();
122 static const float MaxCanvasArea;
124 bool m_rendererIsCanvas;
126 OwnPtr<CanvasRenderingContext> m_context;
127 IntSize m_size;
128 CanvasObserver* m_observer;
130 bool m_originClean;
131 bool m_ignoreReset;
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;
139 } //namespace
141 #endif