darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 5513211 | 2009-08-12 23:40:28 +0000 | [diff] [blame] | 2 | * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. |
alp | 9473944 | 2007-10-03 17:16:23 +0000 | [diff] [blame] | 3 | * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4 | * |
| 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. |
| 13 | * |
| 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. |
| 25 | */ |
| 26 | |
eseidel | 8eddecf | 2007-01-16 00:49:43 +0000 | [diff] [blame] | 27 | #ifndef HTMLCanvasElement_h |
| 28 | #define HTMLCanvasElement_h |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 29 | |
levin@chromium.org | 0fcdb6b | 2010-02-24 22:09:08 +0000 | [diff] [blame] | 30 | #include "CanvasSurface.h" |
oliver@apple.com | 0607b32 | 2008-12-30 12:19:23 +0000 | [diff] [blame] | 31 | #include "FloatRect.h" |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 32 | #include "HTMLElement.h" |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 33 | #if ENABLE(3D_CANVAS) |
| 34 | #include "GraphicsContext3D.h" |
| 35 | #endif |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 36 | #include "IntSize.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 37 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 38 | namespace WebCore { |
| 39 | |
eric@webkit.org | 70260e1 | 2010-01-14 05:50:45 +0000 | [diff] [blame] | 40 | class CanvasContextAttributes; |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 41 | class CanvasRenderingContext; |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 42 | class GraphicsContext; |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 43 | class HTMLCanvasElement; |
oliver@apple.com | ae996a9 | 2008-02-23 01:16:16 +0000 | [diff] [blame] | 44 | class IntSize; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 45 | |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 46 | class CanvasObserver { |
| 47 | public: |
darin@apple.com | 5513211 | 2009-08-12 23:40:28 +0000 | [diff] [blame] | 48 | virtual ~CanvasObserver() { } |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 49 | |
eric@webkit.org | 22b2c2c | 2009-05-14 01:44:27 +0000 | [diff] [blame] | 50 | virtual void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect) = 0; |
| 51 | virtual void canvasResized(HTMLCanvasElement*) = 0; |
| 52 | virtual void canvasDestroyed(HTMLCanvasElement*) = 0; |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
levin@chromium.org | 0fcdb6b | 2010-02-24 22:09:08 +0000 | [diff] [blame] | 55 | class HTMLCanvasElement : public HTMLElement, public CanvasSurface { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 56 | public: |
jchaffraix@webkit.org | 94d95b0 | 2008-12-04 22:39:05 +0000 | [diff] [blame] | 57 | HTMLCanvasElement(const QualifiedName&, Document*); |
darin | ee3ce57 | 2006-04-09 23:38:06 +0000 | [diff] [blame] | 58 | virtual ~HTMLCanvasElement(); |
| 59 | |
darin | ee3ce57 | 2006-04-09 23:38:06 +0000 | [diff] [blame] | 60 | void setWidth(int); |
| 61 | void setHeight(int); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 62 | |
eric@webkit.org | 70260e1 | 2010-01-14 05:50:45 +0000 | [diff] [blame] | 63 | CanvasRenderingContext* getContext(const String&, CanvasContextAttributes* attributes = 0); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 64 | |
levin@chromium.org | 14da04b | 2010-03-24 17:50:33 +0000 | [diff] [blame] | 65 | void setSize(const IntSize& newSize) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 66 | { |
levin@chromium.org | 14da04b | 2010-03-24 17:50:33 +0000 | [diff] [blame] | 67 | if (newSize == size()) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 68 | return; |
| 69 | m_ignoreReset = true; |
levin@chromium.org | 14da04b | 2010-03-24 17:50:33 +0000 | [diff] [blame] | 70 | setWidth(newSize.width()); |
| 71 | setHeight(newSize.height()); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 72 | m_ignoreReset = false; |
| 73 | reset(); |
| 74 | } |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 75 | |
levin@chromium.org | 14da04b | 2010-03-24 17:50:33 +0000 | [diff] [blame] | 76 | virtual void willDraw(const FloatRect&); |
darin | ee3ce57 | 2006-04-09 23:38:06 +0000 | [diff] [blame] | 77 | |
| 78 | void paint(GraphicsContext*, const IntRect&); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 79 | |
darin@apple.com | 5513211 | 2009-08-12 23:40:28 +0000 | [diff] [blame] | 80 | void setObserver(CanvasObserver* observer) { m_observer = observer; } |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 81 | |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 82 | CanvasRenderingContext* renderingContext() const { return m_context.get(); } |
| 83 | |
levin@chromium.org | 61fc3bb | 2010-04-02 20:31:53 +0000 | [diff] [blame] | 84 | RenderBox* renderBox() const { return HTMLElement::renderBox(); } |
| 85 | RenderStyle* computedStyle() { return HTMLElement::computedStyle(); } |
| 86 | |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 87 | #if ENABLE(3D_CANVAS) |
| 88 | bool is3D() const; |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 89 | #endif |
darin@apple.com | 5513211 | 2009-08-12 23:40:28 +0000 | [diff] [blame] | 90 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 91 | private: |
darin@apple.com | 5513211 | 2009-08-12 23:40:28 +0000 | [diff] [blame] | 92 | #if ENABLE(DASHBOARD_SUPPORT) |
| 93 | virtual HTMLTagStatus endTagRequirement() const; |
| 94 | virtual int tagPriority() const; |
| 95 | #endif |
| 96 | |
| 97 | virtual void parseMappedAttribute(MappedAttribute*); |
| 98 | virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); |
| 99 | |
darin | ee3ce57 | 2006-04-09 23:38:06 +0000 | [diff] [blame] | 100 | void reset(); |
| 101 | |
darin | 3fd60e1 | 2007-03-13 23:18:23 +0000 | [diff] [blame] | 102 | bool m_rendererIsCanvas; |
| 103 | |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 104 | OwnPtr<CanvasRenderingContext> m_context; |
hyatt@apple.com | e95c617 | 2008-04-16 20:53:02 +0000 | [diff] [blame] | 105 | CanvasObserver* m_observer; |
darin | ee3ce57 | 2006-04-09 23:38:06 +0000 | [diff] [blame] | 106 | |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 107 | bool m_ignoreReset; |
oliver@apple.com | 0607b32 | 2008-12-30 12:19:23 +0000 | [diff] [blame] | 108 | FloatRect m_dirtyRect; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } //namespace |
| 112 | |
| 113 | #endif |