Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / CSSPropertySourceData.h
1 /*
2  * Copyright (c) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef CSSPropertySourceData_h
32 #define CSSPropertySourceData_h
33
34 #include "platform/heap/Handle.h"
35 #include "wtf/Forward.h"
36 #include "wtf/RefCounted.h"
37 #include "wtf/Vector.h"
38 #include "wtf/text/WTFString.h"
39
40 namespace blink {
41
42 struct SourceRange {
43     ALLOW_ONLY_INLINE_ALLOCATION();
44 public:
45     SourceRange();
46     SourceRange(unsigned start, unsigned end);
47     unsigned length() const;
48
49     void trace(Visitor*) { }
50
51     unsigned start;
52     unsigned end;
53 };
54
55 struct CSSPropertySourceData {
56     ALLOW_ONLY_INLINE_ALLOCATION();
57 public:
58     CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange& range);
59     CSSPropertySourceData(const CSSPropertySourceData& other);
60     CSSPropertySourceData();
61
62     String toString() const;
63     unsigned hash() const;
64
65     void trace(Visitor* visitor) { visitor->trace(range); }
66
67     String name;
68     String value;
69     bool important;
70     bool disabled;
71     bool parsedOk;
72     SourceRange range;
73 };
74
75 struct CSSStyleSourceData : public RefCountedWillBeGarbageCollected<CSSStyleSourceData> {
76     static PassRefPtrWillBeRawPtr<CSSStyleSourceData> create()
77     {
78         return adoptRefWillBeNoop(new CSSStyleSourceData());
79     }
80
81     void trace(Visitor* visitor) { visitor->trace(propertyData); }
82
83     WillBeHeapVector<CSSPropertySourceData> propertyData;
84 };
85
86 struct CSSMediaQueryExpSourceData {
87     ALLOW_ONLY_INLINE_ALLOCATION();
88 public:
89     CSSMediaQueryExpSourceData(const SourceRange& valueRange)
90         : valueRange(valueRange) { }
91
92     void trace(Visitor* visitor) { visitor->trace(valueRange); }
93
94     SourceRange valueRange;
95 };
96
97 struct CSSMediaQuerySourceData : public RefCountedWillBeGarbageCollected<CSSMediaQuerySourceData> {
98     static PassRefPtrWillBeRawPtr<CSSMediaQuerySourceData> create()
99     {
100         return adoptRefWillBeNoop(new CSSMediaQuerySourceData());
101     }
102
103     void trace(Visitor* visitor) { visitor->trace(expData); }
104
105     WillBeHeapVector<CSSMediaQueryExpSourceData> expData;
106 };
107
108 struct CSSMediaSourceData : public RefCountedWillBeGarbageCollected<CSSMediaSourceData> {
109     static PassRefPtrWillBeRawPtr<CSSMediaSourceData> create()
110     {
111         return adoptRefWillBeNoop(new CSSMediaSourceData());
112     }
113
114     void trace(Visitor* visitor) { visitor->trace(queryData); }
115
116     WillBeHeapVector<RefPtrWillBeMember<CSSMediaQuerySourceData> > queryData;
117 };
118
119 struct CSSRuleSourceData;
120 typedef WillBeHeapVector<RefPtrWillBeMember<CSSRuleSourceData> > RuleSourceDataList;
121 typedef WillBeHeapVector<SourceRange> SelectorRangeList;
122
123 struct CSSRuleSourceData : public RefCountedWillBeGarbageCollected<CSSRuleSourceData> {
124     enum Type {
125         UNKNOWN_RULE,
126         STYLE_RULE,
127         CHARSET_RULE,
128         IMPORT_RULE,
129         MEDIA_RULE,
130         FONT_FACE_RULE,
131         PAGE_RULE,
132         KEYFRAMES_RULE,
133         VIEWPORT_RULE,
134         SUPPORTS_RULE,
135     };
136
137     static PassRefPtrWillBeRawPtr<CSSRuleSourceData> create(Type type)
138     {
139         return adoptRefWillBeNoop(new CSSRuleSourceData(type));
140     }
141
142     static PassRefPtrWillBeRawPtr<CSSRuleSourceData> createUnknown()
143     {
144         return adoptRefWillBeNoop(new CSSRuleSourceData(UNKNOWN_RULE));
145     }
146
147     CSSRuleSourceData(Type type)
148         : type(type)
149     {
150         if (type == STYLE_RULE || type == FONT_FACE_RULE || type == PAGE_RULE)
151             styleSourceData = CSSStyleSourceData::create();
152         if (type == MEDIA_RULE || type == IMPORT_RULE)
153             mediaSourceData = CSSMediaSourceData::create();
154     }
155
156     void trace(Visitor*);
157
158     Type type;
159
160     // Range of the selector list in the enclosing source.
161     SourceRange ruleHeaderRange;
162
163     // Range of the rule body (e.g. style text for style rules) in the enclosing source.
164     SourceRange ruleBodyRange;
165
166     // Only for CSSStyleRules.
167     SelectorRangeList selectorRanges;
168
169     // Only for CSSStyleRules, CSSFontFaceRules, and CSSPageRules.
170     RefPtrWillBeMember<CSSStyleSourceData> styleSourceData;
171
172     // Only for CSSMediaRules.
173     RuleSourceDataList childRules;
174
175     // Only for CSSMediaRules and CSSImportRules.
176     RefPtrWillBeMember<CSSMediaSourceData> mediaSourceData;
177 };
178
179 } // namespace blink
180
181 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::SourceRange);
182 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSPropertySourceData);
183 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSMediaQueryExpSourceData);
184
185 #endif // CSSPropertySourceData_h