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

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

Issue 172593003: DevTools: [CSS] Add CSS.editRangeInStyleSheetText() to the protocol (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix glitch Created 6 years, 9 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 class InspectorStyleSheet : public RefCounted<InspectorStyleSheet> { 162 class InspectorStyleSheet : public RefCounted<InspectorStyleSheet> {
163 public: 163 public:
164 class Listener { 164 class Listener {
165 public: 165 public:
166 Listener() { } 166 Listener() { }
167 virtual ~Listener() { } 167 virtual ~Listener() { }
168 virtual void styleSheetChanged(InspectorStyleSheet*) = 0; 168 virtual void styleSheetChanged(InspectorStyleSheet*) = 0;
169 virtual void willReparseStyleSheet() = 0; 169 virtual void willReparseStyleSheet() = 0;
170 virtual void didReparseStyleSheet() = 0; 170 virtual void didReparseStyleSheet() = 0;
171 }; 171 };
172 struct EditRangeResult {
173 RefPtr<CSSStyleRule> rule;
174 RefPtr<CSSStyleDeclaration> style;
175 };
172 176
173 static PassRefPtr<InspectorStyleSheet> create(InspectorPageAgent*, Inspector ResourceAgent*, const String& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, Type Builder::CSS::StyleSheetOrigin::Enum, const String& documentURL, Listener*); 177 static PassRefPtr<InspectorStyleSheet> create(InspectorPageAgent*, Inspector ResourceAgent*, const String& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, Type Builder::CSS::StyleSheetOrigin::Enum, const String& documentURL, Listener*);
174 static String styleSheetURL(CSSStyleSheet* pageStyleSheet); 178 static String styleSheetURL(CSSStyleSheet* pageStyleSheet);
175 static void collectFlatRules(PassRefPtr<CSSRuleList>, CSSRuleVector* result) ; 179 static void collectFlatRules(PassRefPtr<CSSRuleList>, CSSRuleVector* result) ;
176 180
177 virtual ~InspectorStyleSheet(); 181 virtual ~InspectorStyleSheet();
178 182
179 String id() const { return m_id; } 183 String id() const { return m_id; }
180 String finalURL() const; 184 String finalURL() const;
181 virtual Document* ownerDocument() const; 185 virtual Document* ownerDocument() const;
182 bool canBind() const { return m_origin != TypeBuilder::CSS::StyleSheetOrigin ::User_agent && m_origin != TypeBuilder::CSS::StyleSheetOrigin::User; } 186 bool canBind() const { return m_origin != TypeBuilder::CSS::StyleSheetOrigin ::User_agent && m_origin != TypeBuilder::CSS::StyleSheetOrigin::User; }
183 CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet.get(); } 187 CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet.get(); }
184 virtual void reparseStyleSheet(const String&); 188 virtual void reparseStyleSheet(const String&);
185 virtual bool setText(const String&, ExceptionState&); 189 virtual bool setText(const String&, ExceptionState&);
190 virtual bool editRange(const String&, unsigned startOffset, unsigned endOffs et, EditRangeResult*, ExceptionState&);
186 String ruleSelector(const InspectorCSSId&, ExceptionState&); 191 String ruleSelector(const InspectorCSSId&, ExceptionState&);
187 bool setRuleSelector(const InspectorCSSId&, const String& selector, Exceptio nState&); 192 bool setRuleSelector(const InspectorCSSId&, const String& selector, Exceptio nState&);
188 CSSStyleRule* addRule(const String& selector, ExceptionState&); 193 CSSStyleRule* addRule(const String& selector, ExceptionState&);
189 bool deleteRule(const InspectorCSSId&, ExceptionState&); 194 bool deleteRule(const InspectorCSSId&, ExceptionState&);
190 CSSStyleRule* ruleForId(const InspectorCSSId&) const; 195 CSSStyleRule* ruleForId(const InspectorCSSId&) const;
191 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> buildObjectForStyleSheetIn fo() const; 196 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> buildObjectForStyleSheetIn fo() const;
192 PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*, Pass RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> >); 197 PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*, Pass RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> >);
193 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle(CSSStyleDeclarati on*); 198 PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle(CSSStyleDeclarati on*);
194 bool setStyleText(const InspectorCSSId&, const String& text, String* oldText , ExceptionState&); 199 bool setStyleText(const InspectorCSSId&, const String& text, String* oldText , ExceptionState&);
195 bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const St ring& text, bool overwrite, String* oldPropertyText, ExceptionState&); 200 bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const St ring& text, bool overwrite, String* oldPropertyText, ExceptionState&);
196 201
197 virtual TypeBuilder::CSS::StyleSheetOrigin::Enum origin() const { return m_o rigin; } 202 virtual TypeBuilder::CSS::StyleSheetOrigin::Enum origin() const { return m_o rigin; }
198 virtual bool getText(String* result) const; 203 virtual bool getText(String* result) const;
199 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const; 204 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const;
200 void fireStyleSheetChanged(); 205 void fireStyleSheetChanged();
201 PassRefPtr<TypeBuilder::CSS::SourceRange> ruleHeaderSourceRange(const CSSRul e*); 206 PassRefPtr<TypeBuilder::CSS::SourceRange> ruleHeaderSourceRange(const CSSRul e*);
202 207
203 InspectorCSSId ruleId(CSSStyleRule*) const; 208 InspectorCSSId ruleId(CSSStyleRule*) const;
204 InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyl eId(style); } 209 InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyl eId(style); }
210 bool lineNumberAndColumnToOffset(unsigned lineNumber, unsigned columnNumber, unsigned* offset) const;
205 211
206 protected: 212 protected:
213 enum PropertyScopeEditType {
214 EditExistingProperty = 0,
215 AppendNewProperty
216 };
217
207 InspectorStyleSheet(InspectorPageAgent*, InspectorResourceAgent*, const Stri ng& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOr igin::Enum, const String& documentURL, Listener*); 218 InspectorStyleSheet(InspectorPageAgent*, InspectorResourceAgent*, const Stri ng& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOr igin::Enum, const String& documentURL, Listener*);
208 219
209 InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const; 220 InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const;
210 virtual PassRefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* ) const; 221 virtual PassRefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* ) const;
211 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const; 222 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const;
212 virtual unsigned ruleIndexByRule(const CSSRule*) const; 223 virtual unsigned ruleIndexByRule(const CSSRule*) const;
213 virtual bool ensureParsedDataReady(); 224 virtual bool ensureParsedDataReady();
214 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId& ); 225 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId& );
215 virtual String sourceMapURL() const; 226 virtual String sourceMapURL() const;
216 virtual String sourceURL() const; 227 virtual String sourceURL() const;
217 228
218 // Also accessed by friend class InspectorStyle. 229 // Also accessed by friend class InspectorStyle.
219 virtual bool setStyleText(CSSStyleDeclaration*, const String&); 230 virtual bool setStyleText(CSSStyleDeclaration*, const String&);
220 virtual PassOwnPtr<Vector<unsigned> > lineEndings() const; 231 virtual PassOwnPtr<Vector<unsigned> > lineEndings() const;
232 bool handlePropertyScope(const CSSStyleSourceData* originalData, const CSSSt yleSourceData* modifiedData, const unsigned ruleIndex, const PropertyScopeEditTy pe, EditRangeResult*, ExceptionState&);
221 233
222 private: 234 private:
223 friend class InspectorStyle; 235 friend class InspectorStyle;
224 236
225 bool checkPageStyleSheet(ExceptionState&) const; 237 bool checkPageStyleSheet(ExceptionState&) const;
226 bool ensureText() const; 238 bool ensureText() const;
227 void ensureFlatRules() const; 239 void ensureFlatRules() const;
228 bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newS tyleText, String* result); 240 bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newS tyleText, String* result);
229 bool originalStyleSheetText(String* result) const; 241 bool originalStyleSheetText(String* result) const;
230 bool resourceStyleSheetText(String* result) const; 242 bool resourceStyleSheetText(String* result) const;
231 bool inlineStyleSheetText(String* result) const; 243 bool inlineStyleSheetText(String* result) const;
232 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectorsFromSou rce(const CSSRuleSourceData*, const String&) const; 244 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectorsFromSou rce(const CSSRuleSourceData*, const String&) const;
233 PassRefPtr<TypeBuilder::CSS::SelectorList> buildObjectForSelectorList(CSSSty leRule*); 245 PassRefPtr<TypeBuilder::CSS::SelectorList> buildObjectForSelectorList(CSSSty leRule*);
234 String url() const; 246 String url() const;
235 bool hasSourceURL() const; 247 bool hasSourceURL() const;
236 bool startsAtZero() const; 248 bool startsAtZero() const;
249 bool handleSelectorEditScope(const CSSRuleSourceData* originalData, const CS SRuleSourceData* modifiedData, const String& modifiedText, const unsigned ruleIn dex, EditRangeResult*, ExceptionState&);
250 bool handleStyleSheetEditScope(const ParsedStyleSheet* originalData, const P arsedStyleSheet* modifiedData, EditRangeResult*, ExceptionState&);
237 251
238 InspectorPageAgent* m_pageAgent; 252 InspectorPageAgent* m_pageAgent;
239 InspectorResourceAgent* m_resourceAgent; 253 InspectorResourceAgent* m_resourceAgent;
240 String m_id; 254 String m_id;
241 RefPtr<CSSStyleSheet> m_pageStyleSheet; 255 RefPtr<CSSStyleSheet> m_pageStyleSheet;
242 TypeBuilder::CSS::StyleSheetOrigin::Enum m_origin; 256 TypeBuilder::CSS::StyleSheetOrigin::Enum m_origin;
243 String m_documentURL; 257 String m_documentURL;
244 ParsedStyleSheet* m_parsedStyleSheet; 258 ParsedStyleSheet* m_parsedStyleSheet;
245 mutable CSSRuleVector m_flatRules; 259 mutable CSSRuleVector m_flatRules;
246 Listener* m_listener; 260 Listener* m_listener;
247 mutable String m_sourceURL; 261 mutable String m_sourceURL;
248 }; 262 };
249 263
250 class InspectorStyleSheetForInlineStyle FINAL : public InspectorStyleSheet { 264 class InspectorStyleSheetForInlineStyle FINAL : public InspectorStyleSheet {
251 public: 265 public:
252 static PassRefPtr<InspectorStyleSheetForInlineStyle> create(InspectorPageAge nt*, InspectorResourceAgent*, const String& id, PassRefPtr<Element>, TypeBuilder ::CSS::StyleSheetOrigin::Enum, Listener*); 266 static PassRefPtr<InspectorStyleSheetForInlineStyle> create(InspectorPageAge nt*, InspectorResourceAgent*, const String& id, PassRefPtr<Element>, TypeBuilder ::CSS::StyleSheetOrigin::Enum, Listener*);
253 267
254 void didModifyElementAttribute(); 268 void didModifyElementAttribute();
255 virtual void reparseStyleSheet(const String&) OVERRIDE; 269 virtual void reparseStyleSheet(const String&) OVERRIDE;
256 virtual bool setText(const String&, ExceptionState&) OVERRIDE; 270 virtual bool setText(const String&, ExceptionState&) OVERRIDE;
271 virtual bool editRange(const String&, unsigned startOffset, unsigned endOffs et, EditRangeResult*, ExceptionState&);
257 virtual bool getText(String* result) const OVERRIDE; 272 virtual bool getText(String* result) const OVERRIDE;
258 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const OVER RIDE { ASSERT_UNUSED(id, !id.ordinal()); return inlineStyle(); } 273 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const OVER RIDE { ASSERT_UNUSED(id, !id.ordinal()); return inlineStyle(); }
259 virtual TypeBuilder::CSS::StyleSheetOrigin::Enum origin() const OVERRIDE { r eturn TypeBuilder::CSS::StyleSheetOrigin::Regular; } 274 virtual TypeBuilder::CSS::StyleSheetOrigin::Enum origin() const OVERRIDE { r eturn TypeBuilder::CSS::StyleSheetOrigin::Regular; }
260 275
261 protected: 276 protected:
262 InspectorStyleSheetForInlineStyle(InspectorPageAgent*, InspectorResourceAgen t*, const String& id, PassRefPtr<Element>, TypeBuilder::CSS::StyleSheetOrigin::E num, Listener*); 277 InspectorStyleSheetForInlineStyle(InspectorPageAgent*, InspectorResourceAgen t*, const String& id, PassRefPtr<Element>, TypeBuilder::CSS::StyleSheetOrigin::E num, Listener*);
263 278
264 virtual Document* ownerDocument() const OVERRIDE; 279 virtual Document* ownerDocument() const OVERRIDE;
265 virtual PassRefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const OVERRIDE { ASSERT_UNUSED(style, style == inlineStyle()); return m_ ruleSourceData; } 280 virtual PassRefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const OVERRIDE { ASSERT_UNUSED(style, style == inlineStyle()); return m_ ruleSourceData; }
266 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const OVERRIDE { ret urn 0; } 281 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const OVERRIDE { ret urn 0; }
(...skipping 17 matching lines...) Expand all
284 299
285 // Contains "style" attribute value. 300 // Contains "style" attribute value.
286 mutable String m_styleText; 301 mutable String m_styleText;
287 mutable bool m_isStyleTextValid; 302 mutable bool m_isStyleTextValid;
288 }; 303 };
289 304
290 305
291 } // namespace WebCore 306 } // namespace WebCore
292 307
293 #endif // !defined(InspectorStyleSheet_h) 308 #endif // !defined(InspectorStyleSheet_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698