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