Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / style / ContentData.h
blob774e1fe1ff60cc812e70c13404b135b06426f5f0
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)
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.
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.
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.
25 #ifndef ContentData_h
26 #define ContentData_h
28 #include "core/style/CounterContent.h"
29 #include "core/style/StyleImage.h"
30 #include "wtf/OwnPtr.h"
31 #include "wtf/PassOwnPtr.h"
33 namespace blink {
35 class Document;
36 class LayoutObject;
37 class ComputedStyle;
39 class ContentData : public NoBaseWillBeGarbageCollectedFinalized<ContentData> {
40 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(ContentData);
41 public:
42 static PassOwnPtrWillBeRawPtr<ContentData> create(PassRefPtrWillBeRawPtr<StyleImage>);
43 static PassOwnPtrWillBeRawPtr<ContentData> create(const String&);
44 static PassOwnPtrWillBeRawPtr<ContentData> create(PassOwnPtr<CounterContent>);
45 static PassOwnPtrWillBeRawPtr<ContentData> create(QuoteType);
47 virtual ~ContentData() { }
49 virtual bool isCounter() const { return false; }
50 virtual bool isImage() const { return false; }
51 virtual bool isQuote() const { return false; }
52 virtual bool isText() const { return false; }
54 virtual LayoutObject* createLayoutObject(Document&, ComputedStyle&) const = 0;
56 virtual PassOwnPtrWillBeRawPtr<ContentData> clone() const;
58 ContentData* next() const { return m_next.get(); }
59 void setNext(PassOwnPtrWillBeRawPtr<ContentData> next) { m_next = next; }
61 virtual bool equals(const ContentData&) const = 0;
63 DECLARE_VIRTUAL_TRACE();
65 private:
66 virtual PassOwnPtrWillBeRawPtr<ContentData> cloneInternal() const = 0;
68 OwnPtrWillBeMember<ContentData> m_next;
71 #define DEFINE_CONTENT_DATA_TYPE_CASTS(typeName) \
72 DEFINE_TYPE_CASTS(typeName##ContentData, ContentData, content, content->is##typeName(), content.is##typeName())
74 class ImageContentData final : public ContentData {
75 friend class ContentData;
76 public:
77 const StyleImage* image() const { return m_image.get(); }
78 StyleImage* image() { return m_image.get(); }
79 void setImage(PassRefPtrWillBeRawPtr<StyleImage> image) { m_image = image; }
81 bool isImage() const override { return true; }
82 LayoutObject* createLayoutObject(Document&, ComputedStyle&) const override;
84 bool equals(const ContentData& data) const override
86 if (!data.isImage())
87 return false;
88 return *static_cast<const ImageContentData&>(data).image() == *image();
91 DECLARE_VIRTUAL_TRACE();
93 private:
94 ImageContentData(PassRefPtrWillBeRawPtr<StyleImage> image)
95 : m_image(image)
99 PassOwnPtrWillBeRawPtr<ContentData> cloneInternal() const override
101 RefPtrWillBeRawPtr<StyleImage> image = const_cast<StyleImage*>(this->image());
102 return create(image.release());
105 RefPtrWillBeMember<StyleImage> m_image;
108 DEFINE_CONTENT_DATA_TYPE_CASTS(Image);
110 class TextContentData final : public ContentData {
111 friend class ContentData;
112 public:
113 const String& text() const { return m_text; }
114 void setText(const String& text) { m_text = text; }
116 bool isText() const override { return true; }
117 LayoutObject* createLayoutObject(Document&, ComputedStyle&) const override;
119 bool equals(const ContentData& data) const override
121 if (!data.isText())
122 return false;
123 return static_cast<const TextContentData&>(data).text() == text();
126 private:
127 TextContentData(const String& text)
128 : m_text(text)
132 PassOwnPtrWillBeRawPtr<ContentData> cloneInternal() const override { return create(text()); }
134 String m_text;
137 DEFINE_CONTENT_DATA_TYPE_CASTS(Text);
139 class CounterContentData final : public ContentData {
140 friend class ContentData;
141 public:
142 const CounterContent* counter() const { return m_counter.get(); }
143 void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
145 bool isCounter() const override { return true; }
146 LayoutObject* createLayoutObject(Document&, ComputedStyle&) const override;
148 private:
149 CounterContentData(PassOwnPtr<CounterContent> counter)
150 : m_counter(counter)
154 PassOwnPtrWillBeRawPtr<ContentData> cloneInternal() const override
156 OwnPtr<CounterContent> counterData = adoptPtr(new CounterContent(*counter()));
157 return create(counterData.release());
160 bool equals(const ContentData& data) const override
162 if (!data.isCounter())
163 return false;
164 return *static_cast<const CounterContentData&>(data).counter() == *counter();
167 OwnPtr<CounterContent> m_counter;
170 DEFINE_CONTENT_DATA_TYPE_CASTS(Counter);
172 class QuoteContentData final : public ContentData {
173 friend class ContentData;
174 public:
175 QuoteType quote() const { return m_quote; }
176 void setQuote(QuoteType quote) { m_quote = quote; }
178 bool isQuote() const override { return true; }
179 LayoutObject* createLayoutObject(Document&, ComputedStyle&) const override;
181 bool equals(const ContentData& data) const override
183 if (!data.isQuote())
184 return false;
185 return static_cast<const QuoteContentData&>(data).quote() == quote();
188 private:
189 QuoteContentData(QuoteType quote)
190 : m_quote(quote)
194 PassOwnPtrWillBeRawPtr<ContentData> cloneInternal() const override { return create(quote()); }
196 QuoteType m_quote;
199 DEFINE_CONTENT_DATA_TYPE_CASTS(Quote);
201 inline bool operator==(const ContentData& a, const ContentData& b)
203 return a.equals(b);
206 inline bool operator!=(const ContentData& a, const ContentData& b)
208 return !(a == b);
211 } // namespace blink
213 #endif // ContentData_h