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.
28 #include "CounterContent.h"
29 #include <wtf/OwnPtr.h>
30 #include <wtf/PassOwnPtr.h>
37 WTF_MAKE_FAST_ALLOCATED;
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);
44 virtual ~ContentData() { }
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; }
51 virtual StyleContentType type() const = 0;
53 friend bool operator==(const ContentData&, const ContentData&);
54 friend bool operator!=(const ContentData&, const ContentData&);
56 virtual PassOwnPtr<ContentData> clone() const;
58 ContentData* next() const { return m_next.get(); }
59 void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
62 virtual PassOwnPtr<ContentData> cloneInternal() const = 0;
64 OwnPtr<ContentData> m_next;
67 class ImageContentData : public ContentData {
68 friend class ContentData;
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; }
75 ImageContentData(PassRefPtr<StyleImage> image)
80 virtual StyleContentType type() const { return CONTENT_OBJECT; }
81 virtual bool isImage() const { return true; }
82 virtual PassOwnPtr<ContentData> cloneInternal() const
84 RefPtr<StyleImage> image = const_cast<StyleImage*>(this->image());
85 return create(image.release());
88 RefPtr<StyleImage> m_image;
91 class TextContentData : public ContentData {
92 friend class ContentData;
94 const String& text() const { return m_text; }
95 void setText(const String& text) { m_text = text; }
98 TextContentData(const String& text)
103 virtual StyleContentType type() const { return CONTENT_TEXT; }
104 virtual bool isText() const { return true; }
105 virtual PassOwnPtr<ContentData> cloneInternal() const { return create(text()); }
110 class CounterContentData : public ContentData {
111 friend class ContentData;
113 const CounterContent* counter() const { return m_counter.get(); }
114 void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
117 CounterContentData(PassOwnPtr<CounterContent> counter)
122 virtual StyleContentType type() const { return CONTENT_COUNTER; }
123 virtual bool isCounter() const { return true; }
124 virtual PassOwnPtr<ContentData> cloneInternal() const
126 OwnPtr<CounterContent> counterData = adoptPtr(new CounterContent(*counter()));
127 return create(counterData.release());
130 OwnPtr<CounterContent> m_counter;
133 class QuoteContentData : public ContentData {
134 friend class ContentData;
136 QuoteType quote() const { return m_quote; }
137 void setQuote(QuoteType quote) { m_quote = quote; }
140 QuoteContentData(QuoteType quote)
145 virtual StyleContentType type() const { return CONTENT_QUOTE; }
146 virtual bool isQuote() const { return true; }
147 virtual PassOwnPtr<ContentData> cloneInternal() const { return create(quote()); }
152 } // namespace WebCore
154 #endif // ContentData_h