blob: b2a76a167505fc971b610ce05912ccff67ac0dea [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
darin@apple.com55132112009-08-12 23:40:28 +00002 * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved.
alp94739442007-10-03 17:16:23 +00003 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
darinb9481ed2006-03-20 02:57:59 +00004 *
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
eseidel8eddecf2007-01-16 00:49:43 +000027#ifndef HTMLCanvasElement_h
28#define HTMLCanvasElement_h
darinb9481ed2006-03-20 02:57:59 +000029
levin@chromium.org0fcdb6b2010-02-24 22:09:08 +000030#include "CanvasSurface.h"
oliver@apple.com0607b322008-12-30 12:19:23 +000031#include "FloatRect.h"
eseidel84943622006-05-15 23:23:42 +000032#include "HTMLElement.h"
cmarrin@apple.comf493aa22009-08-25 18:45:56 +000033#if ENABLE(3D_CANVAS)
34#include "GraphicsContext3D.h"
35#endif
eseidel84943622006-05-15 23:23:42 +000036#include "IntSize.h"
darinb9481ed2006-03-20 02:57:59 +000037
darinb9481ed2006-03-20 02:57:59 +000038namespace WebCore {
39
eric@webkit.org70260e12010-01-14 05:50:45 +000040class CanvasContextAttributes;
cmarrin@apple.comf493aa22009-08-25 18:45:56 +000041class CanvasRenderingContext;
hyatt8285c6b2006-08-01 01:50:45 +000042class GraphicsContext;
hyatt@apple.come95c6172008-04-16 20:53:02 +000043class HTMLCanvasElement;
oliver@apple.comae996a92008-02-23 01:16:16 +000044class IntSize;
darinb9481ed2006-03-20 02:57:59 +000045
hyatt@apple.come95c6172008-04-16 20:53:02 +000046class CanvasObserver {
47public:
darin@apple.com55132112009-08-12 23:40:28 +000048 virtual ~CanvasObserver() { }
hyatt@apple.come95c6172008-04-16 20:53:02 +000049
eric@webkit.org22b2c2c2009-05-14 01:44:27 +000050 virtual void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect) = 0;
51 virtual void canvasResized(HTMLCanvasElement*) = 0;
52 virtual void canvasDestroyed(HTMLCanvasElement*) = 0;
hyatt@apple.come95c6172008-04-16 20:53:02 +000053};
54
levin@chromium.org0fcdb6b2010-02-24 22:09:08 +000055class HTMLCanvasElement : public HTMLElement, public CanvasSurface {
darinb9481ed2006-03-20 02:57:59 +000056public:
jchaffraix@webkit.org94d95b02008-12-04 22:39:05 +000057 HTMLCanvasElement(const QualifiedName&, Document*);
darinee3ce572006-04-09 23:38:06 +000058 virtual ~HTMLCanvasElement();
59
darinee3ce572006-04-09 23:38:06 +000060 void setWidth(int);
61 void setHeight(int);
darinb9481ed2006-03-20 02:57:59 +000062
eric@webkit.org70260e12010-01-14 05:50:45 +000063 CanvasRenderingContext* getContext(const String&, CanvasContextAttributes* attributes = 0);
darinb9481ed2006-03-20 02:57:59 +000064
levin@chromium.org14da04b2010-03-24 17:50:33 +000065 void setSize(const IntSize& newSize)
hyatt@apple.com68382152008-04-17 04:13:36 +000066 {
levin@chromium.org14da04b2010-03-24 17:50:33 +000067 if (newSize == size())
hyatt@apple.com68382152008-04-17 04:13:36 +000068 return;
69 m_ignoreReset = true;
levin@chromium.org14da04b2010-03-24 17:50:33 +000070 setWidth(newSize.width());
71 setHeight(newSize.height());
hyatt@apple.com68382152008-04-17 04:13:36 +000072 m_ignoreReset = false;
73 reset();
74 }
hyatt@apple.come95c6172008-04-16 20:53:02 +000075
levin@chromium.org14da04b2010-03-24 17:50:33 +000076 virtual void willDraw(const FloatRect&);
darinee3ce572006-04-09 23:38:06 +000077
78 void paint(GraphicsContext*, const IntRect&);
darinb9481ed2006-03-20 02:57:59 +000079
darin@apple.com55132112009-08-12 23:40:28 +000080 void setObserver(CanvasObserver* observer) { m_observer = observer; }
hyatt@apple.come95c6172008-04-16 20:53:02 +000081
cmarrin@apple.comf493aa22009-08-25 18:45:56 +000082 CanvasRenderingContext* renderingContext() const { return m_context.get(); }
83
levin@chromium.org61fc3bb2010-04-02 20:31:53 +000084 RenderBox* renderBox() const { return HTMLElement::renderBox(); }
85 RenderStyle* computedStyle() { return HTMLElement::computedStyle(); }
86
cmarrin@apple.comf493aa22009-08-25 18:45:56 +000087#if ENABLE(3D_CANVAS)
88 bool is3D() const;
cmarrin@apple.comf493aa22009-08-25 18:45:56 +000089#endif
darin@apple.com55132112009-08-12 23:40:28 +000090
darinb9481ed2006-03-20 02:57:59 +000091private:
darin@apple.com55132112009-08-12 23:40:28 +000092#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
darinee3ce572006-04-09 23:38:06 +0000100 void reset();
101
darin3fd60e12007-03-13 23:18:23 +0000102 bool m_rendererIsCanvas;
103
cmarrin@apple.comf493aa22009-08-25 18:45:56 +0000104 OwnPtr<CanvasRenderingContext> m_context;
hyatt@apple.come95c6172008-04-16 20:53:02 +0000105 CanvasObserver* m_observer;
darinee3ce572006-04-09 23:38:06 +0000106
hyatt@apple.com68382152008-04-17 04:13:36 +0000107 bool m_ignoreReset;
oliver@apple.com0607b322008-12-30 12:19:23 +0000108 FloatRect m_dirtyRect;
darinb9481ed2006-03-20 02:57:59 +0000109};
110
111} //namespace
112
113#endif