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

Side by Side Diff: Source/core/inspector/InspectorStyleSheet.h

Issue 1201713011: DevTools: remove ruleId from the style. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: for landing Created 5 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 class Element; 48 class Element;
49 class ExceptionState; 49 class ExceptionState;
50 class InspectorCSSAgent; 50 class InspectorCSSAgent;
51 class InspectorResourceAgent; 51 class InspectorResourceAgent;
52 class InspectorStyleSheetBase; 52 class InspectorStyleSheetBase;
53 53
54 typedef WillBeHeapVector<RefPtrWillBeMember<CSSRule> > CSSRuleVector; 54 typedef WillBeHeapVector<RefPtrWillBeMember<CSSRule> > CSSRuleVector;
55 typedef String ErrorString; 55 typedef String ErrorString;
56 typedef Vector<unsigned> LineEndings; 56 typedef Vector<unsigned> LineEndings;
57 57
58 struct InspectorStyleProperty {
59 ALLOW_ONLY_INLINE_ALLOCATION();
60 public:
61 explicit InspectorStyleProperty(CSSPropertySourceData sourceData)
62 : sourceData(sourceData)
63 , hasSource(true)
64 {
65 }
66
67 InspectorStyleProperty(CSSPropertySourceData sourceData, bool hasSource)
68 : sourceData(sourceData)
69 , hasSource(hasSource)
70 {
71 }
72
73 bool hasRawText() const { return !rawText.isEmpty(); }
74
75 DEFINE_INLINE_TRACE() { visitor->trace(sourceData); }
76
77 CSSPropertySourceData sourceData;
78 bool hasSource;
79 String rawText;
80 };
81
82 class InspectorStyle final : public RefCountedWillBeGarbageCollectedFinalized<In spectorStyle> { 58 class InspectorStyle final : public RefCountedWillBeGarbageCollectedFinalized<In spectorStyle> {
83 public: 59 public:
84 static PassRefPtrWillBeRawPtr<InspectorStyle> create(unsigned ruleIndex, Pas sRefPtrWillBeRawPtr<CSSStyleDeclaration>, InspectorStyleSheetBase* parentStyleSh eet); 60 static PassRefPtrWillBeRawPtr<InspectorStyle> create(PassRefPtrWillBeRawPtr< CSSStyleDeclaration>, PassRefPtrWillBeRawPtr<CSSRuleSourceData>, InspectorStyleS heetBase* parentStyleSheet);
85 61
86 CSSStyleDeclaration* cssStyle() const { return m_style.get(); } 62 CSSStyleDeclaration* cssStyle() { return m_style.get(); }
87 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle() const; 63 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle();
88 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > buildArrayForComputedStyle() const; 64 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>> b uildArrayForComputedStyle();
89 bool styleText(String* result) const; 65 bool styleText(String* result);
90 bool textForRange(const SourceRange&, String* result) const; 66 bool textForRange(const SourceRange&, String* result);
91 67
92 DECLARE_TRACE(); 68 DECLARE_TRACE();
93 69
94 private: 70 private:
95 InspectorStyle(unsigned ruleIndex, PassRefPtrWillBeRawPtr<CSSStyleDeclaratio n>, InspectorStyleSheetBase* parentStyleSheet); 71 InspectorStyle(PassRefPtrWillBeRawPtr<CSSStyleDeclaration>, PassRefPtrWillBe RawPtr<CSSRuleSourceData>, InspectorStyleSheetBase* parentStyleSheet);
96 72
97 void populateAllProperties(WillBeHeapVector<InspectorStyleProperty>& result) const; 73 void populateAllProperties(WillBeHeapVector<CSSPropertySourceData>& result);
98 PassRefPtr<TypeBuilder::CSS::CSSStyle> styleWithProperties() const; 74 PassRefPtr<TypeBuilder::CSS::CSSStyle> styleWithProperties();
99 PassRefPtrWillBeRawPtr<CSSRuleSourceData> extractSourceData() const; 75 String shorthandValue(const String& shorthandProperty);
100 String shorthandValue(const String& shorthandProperty) const;
101 inline Document* ownerDocument() const;
102 76
103 unsigned m_ruleIndex;
104 RefPtrWillBeMember<CSSStyleDeclaration> m_style; 77 RefPtrWillBeMember<CSSStyleDeclaration> m_style;
78 RefPtrWillBeMember<CSSRuleSourceData> m_sourceData;
105 RawPtrWillBeMember<InspectorStyleSheetBase> m_parentStyleSheet; 79 RawPtrWillBeMember<InspectorStyleSheetBase> m_parentStyleSheet;
106 }; 80 };
107 81
108 class InspectorStyleSheetBase : public RefCountedWillBeGarbageCollectedFinalized <InspectorStyleSheetBase> { 82 class InspectorStyleSheetBase : public RefCountedWillBeGarbageCollectedFinalized <InspectorStyleSheetBase> {
109 public: 83 public:
110 class CORE_EXPORT Listener { 84 class CORE_EXPORT Listener {
111 public: 85 public:
112 Listener() { } 86 Listener() { }
113 virtual ~Listener() { } 87 virtual ~Listener() { }
114 virtual void styleSheetChanged(InspectorStyleSheetBase*) = 0; 88 virtual void styleSheetChanged(InspectorStyleSheetBase*) = 0;
115 virtual void willReparseStyleSheet() = 0; 89 virtual void willReparseStyleSheet() = 0;
116 virtual void didReparseStyleSheet() = 0; 90 virtual void didReparseStyleSheet() = 0;
117 }; 91 };
118 virtual ~InspectorStyleSheetBase() { } 92 virtual ~InspectorStyleSheetBase() { }
119 DEFINE_INLINE_VIRTUAL_TRACE() { } 93 DEFINE_INLINE_VIRTUAL_TRACE() { }
120 94
121 String id() const { return m_id; } 95 String id() { return m_id; }
122 96
123 virtual Document* ownerDocument() const = 0;
124 virtual bool setText(const String&, ExceptionState&) = 0; 97 virtual bool setText(const String&, ExceptionState&) = 0;
125 virtual bool getText(String* result) const = 0; 98 virtual bool getText(String* result) = 0;
126
127 virtual CSSStyleDeclaration* styleAt(unsigned ruleIndex) const = 0;
128 virtual unsigned indexOf(CSSStyleDeclaration*) const = 0;
129 99
130 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle(CSSStyleDeclarati on*); 100 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle(CSSStyleDeclarati on*);
131 bool lineNumberAndColumnToOffset(unsigned lineNumber, unsigned columnNumber, unsigned* offset); 101 bool lineNumberAndColumnToOffset(unsigned lineNumber, unsigned columnNumber, unsigned* offset);
132 virtual bool isInlineStyle() = 0; 102 virtual bool isInlineStyle() = 0;
133 103
134 protected: 104 protected:
135 InspectorStyleSheetBase(const String& id, Listener*); 105 InspectorStyleSheetBase(const String& id, Listener*);
136 106
137 Listener* listener() const { return m_listener; } 107 Listener* listener() { return m_listener; }
138 void onStyleSheetTextChanged(); 108 void onStyleSheetTextChanged();
139 const LineEndings* lineEndings(); 109 const LineEndings* lineEndings();
140 110
141 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyleAt(unsigned rul eIndex) = 0; 111 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyle(RefPtrWillBeRa wPtr<CSSStyleDeclaration>) = 0;
142 virtual unsigned ruleCount() = 0;
143
144 // Also accessed by friend class InspectorStyle.
145 virtual PassRefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceDataAt(unsigned) const = 0;
146 virtual bool ensureParsedDataReady() = 0;
147 112
148 private: 113 private:
149 friend class InspectorStyle; 114 friend class InspectorStyle;
150 115
151 String m_id; 116 String m_id;
152 Listener* m_listener; 117 Listener* m_listener;
153 OwnPtr<LineEndings> m_lineEndings; 118 OwnPtr<LineEndings> m_lineEndings;
154 }; 119 };
155 120
156 class InspectorStyleSheet : public InspectorStyleSheetBase { 121 class InspectorStyleSheet : public InspectorStyleSheetBase {
157 public: 122 public:
158 static PassRefPtrWillBeRawPtr<InspectorStyleSheet> create(InspectorResourceA gent*, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, T ypeBuilder::CSS::StyleSheetOrigin::Enum, const String& documentURL, InspectorCSS Agent*); 123 static PassRefPtrWillBeRawPtr<InspectorStyleSheet> create(InspectorResourceA gent*, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, T ypeBuilder::CSS::StyleSheetOrigin::Enum, const String& documentURL, InspectorCSS Agent*);
159 124
160 virtual ~InspectorStyleSheet(); 125 virtual ~InspectorStyleSheet();
161 DECLARE_VIRTUAL_TRACE(); 126 DECLARE_VIRTUAL_TRACE();
162 127
163 String finalURL() const; 128 String finalURL();
164 virtual Document* ownerDocument() const override;
165 virtual bool setText(const String&, ExceptionState&) override; 129 virtual bool setText(const String&, ExceptionState&) override;
166 virtual bool getText(String* result) const override; 130 virtual bool getText(String* result) override;
167 RefPtrWillBeRawPtr<CSSStyleRule> setRuleSelector(const SourceRange&, const String& selector, SourceRange* newRange, String* oldSelector, ExceptionState&); 131 RefPtrWillBeRawPtr<CSSStyleRule> setRuleSelector(const SourceRange&, const String& selector, SourceRange* newRange, String* oldSelector, ExceptionState&);
168 RefPtrWillBeRawPtr<CSSStyleRule> setStyleText(const SourceRange&, const Str ing& text, SourceRange* newRange, String* oldSelector, ExceptionState&); 132 RefPtrWillBeRawPtr<CSSStyleRule> setStyleText(const SourceRange&, const Str ing& text, SourceRange* newRange, String* oldSelector, ExceptionState&);
169 RefPtrWillBeRawPtr<CSSMediaRule> setMediaRuleText(const SourceRange&, const String& selector, SourceRange* newRange, String* oldSelector, ExceptionState&); 133 RefPtrWillBeRawPtr<CSSMediaRule> setMediaRuleText(const SourceRange&, const String& selector, SourceRange* newRange, String* oldSelector, ExceptionState&);
170 RefPtrWillBeRawPtr<CSSStyleRule> addRule(const String& ruleText, const Sour ceRange& location, SourceRange* addedRange, ExceptionState&); 134 RefPtrWillBeRawPtr<CSSStyleRule> addRule(const String& ruleText, const Sour ceRange& location, SourceRange* addedRange, ExceptionState&);
171 bool deleteRule(const SourceRange&, ExceptionState&); 135 bool deleteRule(const SourceRange&, ExceptionState&);
172 136
173 CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet.get(); } 137 CSSStyleSheet* pageStyleSheet() { return m_pageStyleSheet.get(); }
174 138
175 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> buildObjectForStyleSheetIn fo() const; 139 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> buildObjectForStyleSheetIn fo();
176 PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*, Pass RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> >); 140 PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*, Pass RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> >);
177 141
178 PassRefPtr<TypeBuilder::CSS::SourceRange> ruleHeaderSourceRange(const CSSRul e*); 142 PassRefPtr<TypeBuilder::CSS::SourceRange> ruleHeaderSourceRange(const CSSRul e*);
179 PassRefPtr<TypeBuilder::CSS::SourceRange> mediaQueryExpValueSourceRange(cons t CSSRule*, size_t mediaQueryIndex, size_t mediaQueryExpIndex); 143 PassRefPtr<TypeBuilder::CSS::SourceRange> mediaQueryExpValueSourceRange(cons t CSSRule*, size_t mediaQueryIndex, size_t mediaQueryExpIndex);
180 144
181 unsigned indexOf(CSSStyleRule*) const;
182 CSSStyleRule* ruleAt(unsigned ruleIndex) const;
183 CSSMediaRule* mediaRuleAt(unsigned ruleIndex) const;
184
185 virtual unsigned indexOf(CSSStyleDeclaration*) const override;
186 virtual CSSStyleDeclaration* styleAt(unsigned ruleIndex) const override;
187 bool isInlineStyle() override { return false; } 145 bool isInlineStyle() override { return false; }
188 const CSSRuleVector& flatRules(); 146 const CSSRuleVector& flatRules();
189 147
190 protected: 148 protected:
191 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyleAt(unsigned rul eIndex) override; 149 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyle(RefPtrWillBeRa wPtr<CSSStyleDeclaration>) override;
192 virtual unsigned ruleCount() override;
193
194 // Also accessed by friend class InspectorStyle.
195 virtual PassRefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceDataAt(unsigned) const override;
196 virtual bool ensureParsedDataReady() override;
197 150
198 private: 151 private:
199 InspectorStyleSheet(InspectorResourceAgent*, const String& id, PassRefPtrWil lBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enu m, const String& documentURL, InspectorCSSAgent*); 152 InspectorStyleSheet(InspectorResourceAgent*, const String& id, PassRefPtrWil lBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enu m, const String& documentURL, InspectorCSSAgent*);
200 unsigned ruleIndexBySourceRange(const CSSMediaRule* parentMediaRule, const S ourceRange&); 153 unsigned ruleIndexBySourceRange(const CSSMediaRule* parentMediaRule, const S ourceRange&);
201 bool findRuleByHeaderRange(const SourceRange&, CSSRule**, CSSRuleSourceData* *); 154 bool findRuleByHeaderRange(const SourceRange&, CSSRule**, CSSRuleSourceData* *);
202 bool findRuleByBodyRange(const SourceRange&, CSSRule**, CSSRuleSourceData**) ; 155 bool findRuleByBodyRange(const SourceRange&, CSSRule**, CSSRuleSourceData**) ;
203 CSSStyleRule* insertCSSOMRuleInStyleSheet(const SourceRange&, const String& ruleText, ExceptionState&); 156 CSSStyleRule* insertCSSOMRuleInStyleSheet(const SourceRange&, const String& ruleText, ExceptionState&);
204 CSSStyleRule* insertCSSOMRuleInMediaRule(CSSMediaRule*, const SourceRange&, const String& ruleText, ExceptionState&); 157 CSSStyleRule* insertCSSOMRuleInMediaRule(CSSMediaRule*, const SourceRange&, const String& ruleText, ExceptionState&);
205 CSSStyleRule* insertCSSOMRuleBySourceRange(const SourceRange&, const String& ruleText, ExceptionState&); 158 CSSStyleRule* insertCSSOMRuleBySourceRange(const SourceRange&, const String& ruleText, ExceptionState&);
206 String sourceMapURL() const; 159 String sourceMapURL();
207 String sourceURL() const; 160 String sourceURL();
208 bool ensureText() const; 161 bool ensureText();
209 void ensureFlatRules() const; 162 void ensureFlatRules();
210 bool originalStyleSheetText(String* result) const; 163 bool originalStyleSheetText(String* result);
211 bool resourceStyleSheetText(String* result) const; 164 bool resourceStyleSheetText(String* result);
212 bool inlineStyleSheetText(String* result) const; 165 bool inlineStyleSheetText(String* result);
213 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectorsFromSou rce(const CSSRuleSourceData*, const String&); 166 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectorsFromSou rce(const CSSRuleSourceData*, const String&);
214 PassRefPtr<TypeBuilder::CSS::SelectorList> buildObjectForSelectorList(CSSSty leRule*); 167 PassRefPtr<TypeBuilder::CSS::SelectorList> buildObjectForSelectorList(CSSSty leRule*);
215 String url() const; 168 String url();
216 bool hasSourceURL() const; 169 bool hasSourceURL();
217 bool startsAtZero() const; 170 bool startsAtZero();
218 171
172 unsigned indexOf(CSSStyleDeclaration*);
173 bool ensureParsedDataReady();
219 void replaceText(const SourceRange&, const String& text, SourceRange* newRan ge, String* oldText); 174 void replaceText(const SourceRange&, const String& text, SourceRange* newRan ge, String* oldText);
220 void innerSetText(const String& newText); 175 void innerSetText(const String& newText);
221 Element* ownerStyleElement() const; 176 Element* ownerStyleElement();
222 177
223 RawPtrWillBeMember<InspectorCSSAgent> m_cssAgent; 178 RawPtrWillBeMember<InspectorCSSAgent> m_cssAgent;
224 RawPtrWillBeMember<InspectorResourceAgent> m_resourceAgent; 179 RawPtrWillBeMember<InspectorResourceAgent> m_resourceAgent;
225 RefPtrWillBeMember<CSSStyleSheet> m_pageStyleSheet; 180 RefPtrWillBeMember<CSSStyleSheet> m_pageStyleSheet;
226 TypeBuilder::CSS::StyleSheetOrigin::Enum m_origin; 181 TypeBuilder::CSS::StyleSheetOrigin::Enum m_origin;
227 String m_documentURL; 182 String m_documentURL;
228 OwnPtrWillBeMember<ParsedStyleSheet> m_parsedStyleSheet; 183 OwnPtrWillBeMember<ParsedStyleSheet> m_parsedStyleSheet;
229 mutable CSSRuleVector m_flatRules; 184 CSSRuleVector m_flatRules;
230 mutable String m_sourceURL; 185 String m_sourceURL;
231 }; 186 };
232 187
233 class InspectorStyleSheetForInlineStyle final : public InspectorStyleSheetBase { 188 class InspectorStyleSheetForInlineStyle final : public InspectorStyleSheetBase {
234 public: 189 public:
235 static PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> create(cons t String& id, PassRefPtrWillBeRawPtr<Element>, Listener*); 190 static PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> create(cons t String& id, PassRefPtrWillBeRawPtr<Element>, Listener*);
236 191
237 void didModifyElementAttribute(); 192 void didModifyElementAttribute();
238 virtual Document* ownerDocument() const override;
239 virtual bool setText(const String&, ExceptionState&) override; 193 virtual bool setText(const String&, ExceptionState&) override;
240 virtual bool getText(String* result) const override; 194 virtual bool getText(String* result) override;
241 195 CSSStyleDeclaration* inlineStyle();
242 virtual CSSStyleDeclaration* styleAt(unsigned ruleIndex) const override { AS SERT_UNUSED(ruleIndex, !ruleIndex); return inlineStyle(); }
243 virtual unsigned indexOf(CSSStyleDeclaration* style) const override { return 0; }
244 CSSStyleDeclaration* inlineStyle() const;
245 196
246 DECLARE_VIRTUAL_TRACE(); 197 DECLARE_VIRTUAL_TRACE();
247 198
248 protected: 199 protected:
249 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyleAt(unsigned rul eIndex) override; 200 virtual PassRefPtrWillBeRawPtr<InspectorStyle> inspectorStyle(RefPtrWillBeRa wPtr<CSSStyleDeclaration>) override;
250 virtual unsigned ruleCount() override { return 1; }
251 201
252 // Also accessed by friend class InspectorStyle. 202 // Also accessed by friend class InspectorStyle.
253 virtual bool ensureParsedDataReady() override;
254 virtual PassRefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceDataAt(unsigned ruleIndex) const override { ASSERT_UNUSED(ruleIndex, !ruleIndex); return m_ruleS ourceData; }
255 bool isInlineStyle() override { return true; } 203 bool isInlineStyle() override { return true; }
256 204
257 private: 205 private:
258 InspectorStyleSheetForInlineStyle(const String& id, PassRefPtrWillBeRawPtr<E lement>, Listener*); 206 InspectorStyleSheetForInlineStyle(const String& id, PassRefPtrWillBeRawPtr<E lement>, Listener*);
259 const String& elementStyleText() const; 207 const String& elementStyleText();
260 PassRefPtrWillBeRawPtr<CSSRuleSourceData> getStyleAttributeData() const;
261 208
262 RefPtrWillBeMember<Element> m_element; 209 RefPtrWillBeMember<Element> m_element;
263 RefPtrWillBeMember<CSSRuleSourceData> m_ruleSourceData;
264 RefPtrWillBeMember<InspectorStyle> m_inspectorStyle; 210 RefPtrWillBeMember<InspectorStyle> m_inspectorStyle;
265
266 // Contains "style" attribute value.
267 mutable String m_styleText;
268 mutable bool m_isStyleTextValid;
269 }; 211 };
270 212
271
272
273 } // namespace blink 213 } // namespace blink
274 214
275 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::InspectorStyleProperty);
276
277 #endif // !defined(InspectorStyleSheet_h) 215 #endif // !defined(InspectorStyleSheet_h)
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.cpp ('k') | Source/core/inspector/InspectorStyleSheet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698