Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: sky/engine/core/rendering/style/ContentData.h

Issue 709213002: Remove ContentData. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 reserv ed.
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 "core/rendering/style/RenderStyleConstants.h"
29 #include "core/rendering/style/StyleImage.h"
30 #include "wtf/OwnPtr.h"
31 #include "wtf/PassOwnPtr.h"
32
33 namespace blink {
34
35 class Document;
36 class RenderObject;
37 class RenderStyle;
38
39 class ContentData {
40 WTF_MAKE_FAST_ALLOCATED;
41 public:
42 static PassOwnPtr<ContentData> create(PassRefPtr<StyleImage>);
43 static PassOwnPtr<ContentData> create(const String&);
44
45 virtual ~ContentData() { }
46
47 virtual bool isImage() const { return false; }
48 virtual bool isText() const { return false; }
49
50 virtual RenderObject* createRenderer(Document&, RenderStyle*) const = 0;
51
52 virtual PassOwnPtr<ContentData> clone() const;
53
54 ContentData* next() const { return m_next.get(); }
55 void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
56
57 virtual bool equals(const ContentData&) const = 0;
58
59 private:
60 virtual PassOwnPtr<ContentData> cloneInternal() const = 0;
61
62 OwnPtr<ContentData> m_next;
63 };
64
65 #define DEFINE_CONTENT_DATA_TYPE_CASTS(typeName) \
66 DEFINE_TYPE_CASTS(typeName##ContentData, ContentData, content, content->is## typeName(), content.is##typeName())
67
68 class ImageContentData final : public ContentData {
69 friend class ContentData;
70 public:
71 const StyleImage* image() const { return m_image.get(); }
72 StyleImage* image() { return m_image.get(); }
73 void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
74
75 virtual bool isImage() const override { return true; }
76 virtual RenderObject* createRenderer(Document&, RenderStyle*) const override ;
77
78 virtual bool equals(const ContentData& data) const override
79 {
80 if (!data.isImage())
81 return false;
82 return *static_cast<const ImageContentData&>(data).image() == *image();
83 }
84
85 private:
86 ImageContentData(PassRefPtr<StyleImage> image)
87 : m_image(image)
88 {
89 }
90
91 virtual PassOwnPtr<ContentData> cloneInternal() const override
92 {
93 RefPtr<StyleImage> image = const_cast<StyleImage*>(this->image());
94 return create(image.release());
95 }
96
97 RefPtr<StyleImage> m_image;
98 };
99
100 DEFINE_CONTENT_DATA_TYPE_CASTS(Image);
101
102 class TextContentData final : public ContentData {
103 friend class ContentData;
104 public:
105 const String& text() const { return m_text; }
106 void setText(const String& text) { m_text = text; }
107
108 virtual bool isText() const override { return true; }
109 virtual RenderObject* createRenderer(Document&, RenderStyle*) const override ;
110
111 virtual bool equals(const ContentData& data) const override
112 {
113 if (!data.isText())
114 return false;
115 return static_cast<const TextContentData&>(data).text() == text();
116 }
117
118 private:
119 TextContentData(const String& text)
120 : m_text(text)
121 {
122 }
123
124 virtual PassOwnPtr<ContentData> cloneInternal() const override { return crea te(text()); }
125
126 String m_text;
127 };
128
129 DEFINE_CONTENT_DATA_TYPE_CASTS(Text);
130
131 inline bool operator==(const ContentData& a, const ContentData& b)
132 {
133 return a.equals(b);
134 }
135
136 inline bool operator!=(const ContentData& a, const ContentData& b)
137 {
138 return !(a == b);
139 }
140
141 } // namespace blink
142
143 #endif // ContentData_h
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderObject.cpp ('k') | sky/engine/core/rendering/style/ContentData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698