initial import
[vuplus_webkit] / Source / WebCore / rendering / style / ContentData.h
1 /*
2  * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3  *           (C) 2000 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2003, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
6  * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #ifndef ContentData_h
26 #define ContentData_h
27
28 #include "CounterContent.h"
29 #include <wtf/OwnPtr.h>
30 #include <wtf/PassOwnPtr.h>
31
32 namespace WebCore {
33
34 class StyleImage;
35
36 class ContentData {
37     WTF_MAKE_FAST_ALLOCATED;
38 public:
39     static PassOwnPtr<ContentData> create(PassRefPtr<StyleImage>);
40     static PassOwnPtr<ContentData> create(const String&);
41     static PassOwnPtr<ContentData> create(PassOwnPtr<CounterContent>);
42     static PassOwnPtr<ContentData> create(QuoteType);
43     
44     virtual ~ContentData() { }
45
46     virtual bool isCounter() const { return false; }
47     virtual bool isImage() const { return false; }
48     virtual bool isQuote() const { return false; }
49     virtual bool isText() const { return false; }
50
51     virtual StyleContentType type() const = 0;
52
53     friend bool operator==(const ContentData&, const ContentData&);
54     friend bool operator!=(const ContentData&, const ContentData&);
55
56     virtual PassOwnPtr<ContentData> clone() const;
57
58     ContentData* next() const { return m_next.get(); }
59     void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
60
61 private:
62     virtual PassOwnPtr<ContentData> cloneInternal() const = 0;
63
64     OwnPtr<ContentData> m_next;
65 };
66
67 class ImageContentData : public ContentData {
68     friend class ContentData;
69 public:
70     const StyleImage* image() const { return m_image.get(); }
71     StyleImage* image() { return m_image.get(); }
72     void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
73
74 private:
75     ImageContentData(PassRefPtr<StyleImage> image)
76         : m_image(image)
77     {
78     }
79
80     virtual StyleContentType type() const { return CONTENT_OBJECT; }
81     virtual bool isImage() const { return true; }
82     virtual PassOwnPtr<ContentData> cloneInternal() const
83     {
84         RefPtr<StyleImage> image = const_cast<StyleImage*>(this->image());
85         return create(image.release());
86     }
87
88     RefPtr<StyleImage> m_image;
89 };
90
91 class TextContentData : public ContentData {
92     friend class ContentData;
93 public:
94     const String& text() const { return m_text; }
95     void setText(const String& text) { m_text = text; }
96
97 private:
98     TextContentData(const String& text)
99         : m_text(text)
100     {
101     }
102
103     virtual StyleContentType type() const { return CONTENT_TEXT; }
104     virtual bool isText() const { return true; }
105     virtual PassOwnPtr<ContentData> cloneInternal() const { return create(text()); }
106
107     String m_text;
108 };
109
110 class CounterContentData : public ContentData {
111     friend class ContentData;
112 public:
113     const CounterContent* counter() const { return m_counter.get(); }
114     void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
115
116 private:
117     CounterContentData(PassOwnPtr<CounterContent> counter)
118         : m_counter(counter)
119     {
120     }
121
122     virtual StyleContentType type() const { return CONTENT_COUNTER; }
123     virtual bool isCounter() const { return true; }
124     virtual PassOwnPtr<ContentData> cloneInternal() const
125     {
126         OwnPtr<CounterContent> counterData = adoptPtr(new CounterContent(*counter()));
127         return create(counterData.release());
128     }
129
130     OwnPtr<CounterContent> m_counter;
131 };
132
133 class QuoteContentData : public ContentData {
134     friend class ContentData;
135 public:
136     QuoteType quote() const { return m_quote; }
137     void setQuote(QuoteType quote) { m_quote = quote; }
138
139 private:
140     QuoteContentData(QuoteType quote)
141         : m_quote(quote)
142     {
143     }
144
145     virtual StyleContentType type() const { return CONTENT_QUOTE; }
146     virtual bool isQuote() const { return true; }
147     virtual PassOwnPtr<ContentData> cloneInternal() const { return create(quote()); }
148
149     QuoteType m_quote;
150 };
151
152 } // namespace WebCore
153
154 #endif // ContentData_h