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

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 202103002: DevTools: refactor InspectorStyleSheet (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: introduce InspectorStyleSheetBase class 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 else if (pseudoClass == visited) 114 else if (pseudoClass == visited)
115 result |= PseudoVisited; 115 result |= PseudoVisited;
116 } 116 }
117 117
118 return result; 118 return result;
119 } 119 }
120 120
121 class InspectorCSSAgent::StyleSheetAction : public InspectorHistory::Action { 121 class InspectorCSSAgent::StyleSheetAction : public InspectorHistory::Action {
122 WTF_MAKE_NONCOPYABLE(StyleSheetAction); 122 WTF_MAKE_NONCOPYABLE(StyleSheetAction);
123 public: 123 public:
124 StyleSheetAction(const String& name, InspectorStyleSheet* styleSheet) 124 StyleSheetAction(const String& name)
125 : InspectorHistory::Action(name) 125 : InspectorHistory::Action(name)
126 , m_styleSheet(styleSheet)
127 { 126 {
128 } 127 }
129
130 protected:
131 RefPtr<InspectorStyleSheet> m_styleSheet;
132 }; 128 };
133 129
134 class InspectorCSSAgent::EnableResourceClient FINAL : public StyleSheetResourceC lient { 130 class InspectorCSSAgent::EnableResourceClient FINAL : public StyleSheetResourceC lient {
135 public: 131 public:
136 EnableResourceClient(InspectorCSSAgent*, const Vector<InspectorStyleSheet*>& , PassRefPtr<EnableCallback>); 132 EnableResourceClient(InspectorCSSAgent*, const Vector<InspectorStyleSheet*>& , PassRefPtr<EnableCallback>);
137 133
138 virtual void setCSSStyleSheet(const String&, const KURL&, const String&, con st CSSStyleSheetResource*) OVERRIDE; 134 virtual void setCSSStyleSheet(const String&, const KURL&, const String&, con st CSSStyleSheetResource*) OVERRIDE;
139 135
140 private: 136 private:
141 RefPtr<EnableCallback> m_callback; 137 RefPtr<EnableCallback> m_callback;
(...skipping 26 matching lines...) Expand all
168 164
169 // enable always succeeds. 165 // enable always succeeds.
170 if (m_callback->isActive()) 166 if (m_callback->isActive())
171 m_cssAgent->wasEnabled(m_callback.release()); 167 m_cssAgent->wasEnabled(m_callback.release());
172 delete this; 168 delete this;
173 } 169 }
174 170
175 class InspectorCSSAgent::SetStyleSheetTextAction FINAL : public InspectorCSSAgen t::StyleSheetAction { 171 class InspectorCSSAgent::SetStyleSheetTextAction FINAL : public InspectorCSSAgen t::StyleSheetAction {
176 WTF_MAKE_NONCOPYABLE(SetStyleSheetTextAction); 172 WTF_MAKE_NONCOPYABLE(SetStyleSheetTextAction);
177 public: 173 public:
178 SetStyleSheetTextAction(InspectorStyleSheet* styleSheet, const String& text) 174 SetStyleSheetTextAction(InspectorStyleSheetBase* styleSheet, const String& t ext)
179 : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", styleSheet) 175 : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText")
176 , m_styleSheet(styleSheet)
180 , m_text(text) 177 , m_text(text)
181 { 178 {
182 } 179 }
183 180
184 virtual bool perform(ExceptionState& exceptionState) OVERRIDE 181 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
185 { 182 {
186 if (!m_styleSheet->getText(&m_oldText)) 183 if (!m_styleSheet->getText(&m_oldText))
187 return false; 184 return false;
188 return redo(exceptionState); 185 return redo(exceptionState);
189 } 186 }
(...skipping 23 matching lines...) Expand all
213 210
214 virtual void merge(PassOwnPtr<Action> action) OVERRIDE 211 virtual void merge(PassOwnPtr<Action> action) OVERRIDE
215 { 212 {
216 ASSERT(action->mergeId() == mergeId()); 213 ASSERT(action->mergeId() == mergeId());
217 214
218 SetStyleSheetTextAction* other = static_cast<SetStyleSheetTextAction*>(a ction.get()); 215 SetStyleSheetTextAction* other = static_cast<SetStyleSheetTextAction*>(a ction.get());
219 m_text = other->m_text; 216 m_text = other->m_text;
220 } 217 }
221 218
222 private: 219 private:
220 RefPtr<InspectorStyleSheetBase> m_styleSheet;
223 String m_text; 221 String m_text;
224 String m_oldText; 222 String m_oldText;
225 }; 223 };
226 224
227 class InspectorCSSAgent::SetPropertyTextAction FINAL : public InspectorCSSAgent: :StyleSheetAction { 225 class InspectorCSSAgent::SetPropertyTextAction FINAL : public InspectorCSSAgent: :StyleSheetAction {
228 WTF_MAKE_NONCOPYABLE(SetPropertyTextAction); 226 WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
229 public: 227 public:
230 SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite) 228 SetPropertyTextAction(InspectorStyleSheetBase* styleSheet, const InspectorCS SId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
231 : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet) 229 : InspectorCSSAgent::StyleSheetAction("SetPropertyText")
230 , m_styleSheet(styleSheet)
232 , m_cssId(cssId) 231 , m_cssId(cssId)
233 , m_propertyIndex(propertyIndex) 232 , m_propertyIndex(propertyIndex)
234 , m_text(text) 233 , m_text(text)
235 , m_overwrite(overwrite) 234 , m_overwrite(overwrite)
236 { 235 {
237 } 236 }
238 237
239 virtual String toString() OVERRIDE 238 virtual String toString() OVERRIDE
240 { 239 {
241 return mergeId() + ": " + m_oldText + " -> " + m_text; 240 return mergeId() + ": " + m_oldText + " -> " + m_text;
(...skipping 25 matching lines...) Expand all
267 266
268 virtual void merge(PassOwnPtr<Action> action) OVERRIDE 267 virtual void merge(PassOwnPtr<Action> action) OVERRIDE
269 { 268 {
270 ASSERT(action->mergeId() == mergeId()); 269 ASSERT(action->mergeId() == mergeId());
271 270
272 SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(actio n.get()); 271 SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(actio n.get());
273 m_text = other->m_text; 272 m_text = other->m_text;
274 } 273 }
275 274
276 private: 275 private:
276 RefPtr<InspectorStyleSheetBase> m_styleSheet;
277 InspectorCSSId m_cssId; 277 InspectorCSSId m_cssId;
278 unsigned m_propertyIndex; 278 unsigned m_propertyIndex;
279 String m_text; 279 String m_text;
280 String m_oldText; 280 String m_oldText;
281 bool m_overwrite; 281 bool m_overwrite;
282 }; 282 };
283 283
284 class InspectorCSSAgent::SetRuleSelectorAction FINAL : public InspectorCSSAgent: :StyleSheetAction { 284 class InspectorCSSAgent::SetRuleSelectorAction FINAL : public InspectorCSSAgent: :StyleSheetAction {
285 WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction); 285 WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction);
286 public: 286 public:
287 SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector) 287 SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector)
288 : InspectorCSSAgent::StyleSheetAction("SetRuleSelector", styleSheet) 288 : InspectorCSSAgent::StyleSheetAction("SetRuleSelector")
289 , m_styleSheet(styleSheet)
289 , m_cssId(cssId) 290 , m_cssId(cssId)
290 , m_selector(selector) 291 , m_selector(selector)
291 { 292 {
292 } 293 }
293 294
294 virtual bool perform(ExceptionState& exceptionState) OVERRIDE 295 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
295 { 296 {
296 m_oldSelector = m_styleSheet->ruleSelector(m_cssId, exceptionState); 297 m_oldSelector = m_styleSheet->ruleSelector(m_cssId, exceptionState);
297 if (exceptionState.hadException()) 298 if (exceptionState.hadException())
298 return false; 299 return false;
299 return redo(exceptionState); 300 return redo(exceptionState);
300 } 301 }
301 302
302 virtual bool undo(ExceptionState& exceptionState) OVERRIDE 303 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
303 { 304 {
304 return m_styleSheet->setRuleSelector(m_cssId, m_oldSelector, exceptionSt ate); 305 return m_styleSheet->setRuleSelector(m_cssId, m_oldSelector, exceptionSt ate);
305 } 306 }
306 307
307 virtual bool redo(ExceptionState& exceptionState) OVERRIDE 308 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
308 { 309 {
309 return m_styleSheet->setRuleSelector(m_cssId, m_selector, exceptionState ); 310 return m_styleSheet->setRuleSelector(m_cssId, m_selector, exceptionState );
310 } 311 }
311 312
312 private: 313 private:
314 RefPtr<InspectorStyleSheet> m_styleSheet;
313 InspectorCSSId m_cssId; 315 InspectorCSSId m_cssId;
314 String m_selector; 316 String m_selector;
315 String m_oldSelector; 317 String m_oldSelector;
316 }; 318 };
317 319
318 class InspectorCSSAgent::AddRuleAction FINAL : public InspectorCSSAgent::StyleSh eetAction { 320 class InspectorCSSAgent::AddRuleAction FINAL : public InspectorCSSAgent::StyleSh eetAction {
319 WTF_MAKE_NONCOPYABLE(AddRuleAction); 321 WTF_MAKE_NONCOPYABLE(AddRuleAction);
320 public: 322 public:
321 AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector) 323 AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector)
322 : InspectorCSSAgent::StyleSheetAction("AddRule", styleSheet) 324 : InspectorCSSAgent::StyleSheetAction("AddRule")
325 , m_styleSheet(styleSheet)
323 , m_selector(selector) 326 , m_selector(selector)
324 { 327 {
325 } 328 }
326 329
327 virtual bool perform(ExceptionState& exceptionState) OVERRIDE 330 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
328 { 331 {
329 return redo(exceptionState); 332 return redo(exceptionState);
330 } 333 }
331 334
332 virtual bool undo(ExceptionState& exceptionState) OVERRIDE 335 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
333 { 336 {
334 return m_styleSheet->deleteRule(m_newId, exceptionState); 337 return m_styleSheet->deleteRule(m_newId, exceptionState);
335 } 338 }
336 339
337 virtual bool redo(ExceptionState& exceptionState) OVERRIDE 340 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
338 { 341 {
339 CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, exception State); 342 CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, exception State);
340 if (exceptionState.hadException()) 343 if (exceptionState.hadException())
341 return false; 344 return false;
342 m_newId = m_styleSheet->ruleId(cssStyleRule); 345 m_newId = m_styleSheet->ruleId(cssStyleRule);
343 return true; 346 return true;
344 } 347 }
345 348
346 InspectorCSSId newRuleId() { return m_newId; } 349 InspectorCSSId newRuleId() { return m_newId; }
347 350
348 private: 351 private:
352 RefPtr<InspectorStyleSheet> m_styleSheet;
349 InspectorCSSId m_newId; 353 InspectorCSSId m_newId;
350 String m_selector; 354 String m_selector;
351 String m_oldSelector; 355 String m_oldSelector;
352 }; 356 };
353 357
354 // static 358 // static
355 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) 359 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule)
356 { 360 {
357 if (!rule || rule->type() != CSSRule::STYLE_RULE) 361 if (!rule || rule->type() != CSSRule::STYLE_RULE)
358 return 0; 362 return 0;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 431
428 void InspectorCSSAgent::restore() 432 void InspectorCSSAgent::restore()
429 { 433 {
430 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled)) 434 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled))
431 wasEnabled(nullptr); 435 wasEnabled(nullptr);
432 } 436 }
433 437
434 void InspectorCSSAgent::reset() 438 void InspectorCSSAgent::reset()
435 { 439 {
436 m_idToInspectorStyleSheet.clear(); 440 m_idToInspectorStyleSheet.clear();
441 m_idToInspectorStyleSheetForInlineStyle.clear();
437 m_cssStyleSheetToInspectorStyleSheet.clear(); 442 m_cssStyleSheetToInspectorStyleSheet.clear();
438 m_frameToCSSStyleSheets.clear(); 443 m_frameToCSSStyleSheets.clear();
439 m_nodeToInspectorStyleSheet.clear(); 444 m_nodeToInspectorStyleSheet.clear();
440 m_documentToViaInspectorStyleSheet.clear(); 445 m_documentToViaInspectorStyleSheet.clear();
441 resetNonPersistentData(); 446 resetNonPersistentData();
442 } 447 }
443 448
444 void InspectorCSSAgent::resetNonPersistentData() 449 void InspectorCSSAgent::resetNonPersistentData()
445 { 450 {
446 resetPseudoStates(); 451 resetPseudoStates();
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 for (HashCountedSet<String>::iterator it = fontStats.begin(), end = fontStat s.end(); it != end; ++it) { 815 for (HashCountedSet<String>::iterator it = fontStats.begin(), end = fontStat s.end(); it != end; ++it) {
811 RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder:: CSS::PlatformFontUsage::create() 816 RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder:: CSS::PlatformFontUsage::create()
812 .setFamilyName(it->key) 817 .setFamilyName(it->key)
813 .setGlyphCount(it->value); 818 .setGlyphCount(it->value);
814 platformFonts->addItem(platformFont); 819 platformFonts->addItem(platformFont);
815 } 820 }
816 } 821 }
817 822
818 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result) 823 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result)
819 { 824 {
820 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 825 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt ring, styleSheetId);
821 if (!inspectorStyleSheet) 826 if (!inspectorStyleSheet)
822 return; 827 return;
823 828
824 inspectorStyleSheet->getText(result); 829 inspectorStyleSheet->getText(result);
825 } 830 }
826 831
827 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text) 832 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text)
828 { 833 {
829 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 834 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt ring, styleSheetId);
830 if (!inspectorStyleSheet) { 835 if (!inspectorStyleSheet) {
831 *errorString = "Style sheet with id " + styleSheetId + " not found."; 836 *errorString = "Style sheet with id " + styleSheetId + " not found.";
832 return; 837 return;
833 } 838 }
834 839
835 TrackExceptionState exceptionState; 840 TrackExceptionState exceptionState;
836 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState); 841 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState);
837 *errorString = InspectorDOMAgent::toErrorString(exceptionState); 842 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
838 } 843 }
839 844
840 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result) 845 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
841 { 846 {
842 InspectorCSSId compoundId(fullStyleId); 847 InspectorCSSId compoundId(fullStyleId);
843 ASSERT(!compoundId.isEmpty()); 848 ASSERT(!compoundId.isEmpty());
844 849
845 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId()); 850 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt ring, compoundId.styleSheetId());
846 if (!inspectorStyleSheet) 851 if (!inspectorStyleSheet)
847 return; 852 return;
848 853
849 TrackExceptionState exceptionState; 854 TrackExceptionState exceptionState;
850 bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAc tion(inspectorStyleSheet, compoundId, propertyIndex, text, overwrite)), exceptio nState); 855 bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAc tion(inspectorStyleSheet, compoundId, propertyIndex, text, overwrite)), exceptio nState);
851 if (success) 856 if (success)
852 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->s tyleForId(compoundId)); 857 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->s tyleForId(compoundId));
853 *errorString = InspectorDOMAgent::toErrorString(exceptionState); 858 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
854 } 859 }
855 860
856 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const RefPtr<J SONObject>& fullRuleId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule >& result) 861 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const RefPtr<J SONObject>& fullRuleId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule >& result)
857 { 862 {
858 InspectorCSSId compoundId(fullRuleId); 863 InspectorCSSId compoundId(fullRuleId);
859 ASSERT(!compoundId.isEmpty()); 864 ASSERT(!compoundId.isEmpty());
860 865
861 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId()); 866 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, compoundId.styleSheetId());
862 if (!inspectorStyleSheet) 867 if (!inspectorStyleSheet)
863 return; 868 return;
864 869
865 TrackExceptionState exceptionState; 870 TrackExceptionState exceptionState;
866 bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAc tion(inspectorStyleSheet, compoundId, selector)), exceptionState); 871 bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAc tion(inspectorStyleSheet, compoundId, selector)), exceptionState);
867 872
868 if (success) { 873 if (success) {
869 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(compoundId); 874 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(compoundId);
870 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListCha in(rule)); 875 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListCha in(rule));
871 } 876 }
(...skipping 18 matching lines...) Expand all
890 if (!inspectorStyleSheet) { 895 if (!inspectorStyleSheet) {
891 *errorString = "No target stylesheet found"; 896 *errorString = "No target stylesheet found";
892 return; 897 return;
893 } 898 }
894 899
895 *outStyleSheetId = inspectorStyleSheet->id(); 900 *outStyleSheetId = inspectorStyleSheet->id();
896 } 901 }
897 902
898 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) 903 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result)
899 { 904 {
900 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 905 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId);
901 if (!inspectorStyleSheet) 906 if (!inspectorStyleSheet)
902 return; 907 return;
903 908
904 TrackExceptionState exceptionState; 909 TrackExceptionState exceptionState;
905 OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleShee t, selector)); 910 OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleShee t, selector));
906 AddRuleAction* rawAction = action.get(); 911 AddRuleAction* rawAction = action.get();
907 bool success = m_domAgent->history()->perform(action.release(), exceptionSta te); 912 bool success = m_domAgent->history()->perform(action.release(), exceptionSta te);
908 if (!success) { 913 if (!success) {
909 *errorString = InspectorDOMAgent::toErrorString(exceptionState); 914 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
910 return; 915 return;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 { 1050 {
1046 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); 1051 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement);
1047 if (it != m_nodeToInspectorStyleSheet.end()) 1052 if (it != m_nodeToInspectorStyleSheet.end())
1048 return it->value.get(); 1053 return it->value.get();
1049 1054
1050 CSSStyleDeclaration* style = element->isStyledElement() ? element->style() : 0; 1055 CSSStyleDeclaration* style = element->isStyledElement() ? element->style() : 0;
1051 if (!style) 1056 if (!style)
1052 return 0; 1057 return 0;
1053 1058
1054 String newStyleSheetId = String::number(m_lastStyleSheetId++); 1059 String newStyleSheetId = String::number(m_lastStyleSheetId++);
1055 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorSty leSheetForInlineStyle::create(m_pageAgent, m_resourceAgent, newStyleSheetId, ele ment, this); 1060 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorSty leSheetForInlineStyle::create(newStyleSheetId, element, this);
1056 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); 1061 m_idToInspectorStyleSheetForInlineStyle.set(newStyleSheetId, inspectorStyleS heet);
1057 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); 1062 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
1058 return inspectorStyleSheet.get(); 1063 return inspectorStyleSheet.get();
1059 } 1064 }
1060 1065
1061 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) 1066 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId)
1062 { 1067 {
1063 Node* node = m_domAgent->nodeForId(nodeId); 1068 Node* node = m_domAgent->nodeForId(nodeId);
1064 if (!node) { 1069 if (!node) {
1065 *errorString = "No node with given id found"; 1070 *errorString = "No node with given id found";
1066 return 0; 1071 return 0;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 // At this point the added stylesheet will get bound through the updateA ctiveStyleSheets() invocation. 1168 // At this point the added stylesheet will get bound through the updateA ctiveStyleSheets() invocation.
1164 // We just need to pick the respective InspectorStyleSheet from m_docume ntToViaInspectorStyleSheet. 1169 // We just need to pick the respective InspectorStyleSheet from m_docume ntToViaInspectorStyleSheet.
1165 m_creatingViaInspectorStyleSheet = false; 1170 m_creatingViaInspectorStyleSheet = false;
1166 } 1171 }
1167 if (exceptionState.hadException()) 1172 if (exceptionState.hadException())
1168 return 0; 1173 return 0;
1169 1174
1170 return m_documentToViaInspectorStyleSheet.get(document); 1175 return m_documentToViaInspectorStyleSheet.get(document);
1171 } 1176 }
1172 1177
1173 InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* error String, const String& styleSheetId) 1178 InspectorStyleSheet* InspectorCSSAgent::assertInspectorStyleSheetForId(ErrorStri ng* errorString, const String& styleSheetId)
1174 { 1179 {
1175 IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleS heetId); 1180 IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleS heetId);
1176 if (it == m_idToInspectorStyleSheet.end()) { 1181 if (it == m_idToInspectorStyleSheet.end()) {
1177 *errorString = "No style sheet with given id found"; 1182 *errorString = "No style sheet with given id found";
1178 return 0; 1183 return 0;
1179 } 1184 }
1180 return it->value.get(); 1185 return it->value.get();
1181 } 1186 }
1182 1187
1188 InspectorStyleSheetBase* InspectorCSSAgent::assertStyleSheetForId(ErrorString* e rrorString, const String& styleSheetId)
1189 {
1190 String placeholder;
1191 InspectorStyleSheetBase* result = assertInspectorStyleSheetForId(&placeholde r, styleSheetId);
1192 if (result)
1193 return result;
1194 IdToInspectorStyleSheetForInlineStyle::iterator it = m_idToInspectorStyleShe etForInlineStyle.find(styleSheetId);
1195 if (it == m_idToInspectorStyleSheetForInlineStyle.end()) {
1196 *errorString = "No style sheet with given id found";
1197 return 0;
1198 }
1199 return it->value.get();
1200 }
1201
1183 TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyl eSheet* pageStyleSheet, Document* ownerDocument) 1202 TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyl eSheet* pageStyleSheet, Document* ownerDocument)
1184 { 1203 {
1185 if (m_creatingViaInspectorStyleSheet) 1204 if (m_creatingViaInspectorStyleSheet)
1186 return TypeBuilder::CSS::StyleSheetOrigin::Inspector; 1205 return TypeBuilder::CSS::StyleSheetOrigin::Inspector;
1187 1206
1188 TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleShe etOrigin::Regular; 1207 TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleShe etOrigin::Regular;
1189 if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href() .isEmpty()) 1208 if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href() .isEmpty())
1190 origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent; 1209 origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent;
1191 else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ow nerNode()->isDocumentNode()) 1210 else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ow nerNode()->isDocumentNode())
1192 origin = TypeBuilder::CSS::StyleSheetOrigin::User; 1211 origin = TypeBuilder::CSS::StyleSheetOrigin::User;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 return; 1306 return;
1288 1307
1289 int nodeId = m_domAgent->boundNodeId(node); 1308 int nodeId = m_domAgent->boundNodeId(node);
1290 if (nodeId) 1309 if (nodeId)
1291 m_nodeIdToForcedPseudoState.remove(nodeId); 1310 m_nodeIdToForcedPseudoState.remove(nodeId);
1292 1311
1293 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(no de); 1312 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(no de);
1294 if (it == m_nodeToInspectorStyleSheet.end()) 1313 if (it == m_nodeToInspectorStyleSheet.end())
1295 return; 1314 return;
1296 1315
1297 m_idToInspectorStyleSheet.remove(it->value->id()); 1316 m_idToInspectorStyleSheetForInlineStyle.remove(it->value->id());
1298 m_nodeToInspectorStyleSheet.remove(node); 1317 m_nodeToInspectorStyleSheet.remove(node);
1299 } 1318 }
1300 1319
1301 void InspectorCSSAgent::didModifyDOMAttr(Element* element) 1320 void InspectorCSSAgent::didModifyDOMAttr(Element* element)
1302 { 1321 {
1303 if (!element) 1322 if (!element)
1304 return; 1323 return;
1305 1324
1306 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); 1325 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement);
1307 if (it == m_nodeToInspectorStyleSheet.end()) 1326 if (it == m_nodeToInspectorStyleSheet.end())
1308 return; 1327 return;
1309 1328
1310 it->value->didModifyElementAttribute(); 1329 it->value->didModifyElementAttribute();
1311 } 1330 }
1312 1331
1313 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet) 1332 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheetBase* styleSheet)
1314 { 1333 {
1315 if (m_frontend) 1334 if (m_frontend)
1316 m_frontend->styleSheetChanged(styleSheet->id()); 1335 m_frontend->styleSheetChanged(styleSheet->id());
1317 } 1336 }
1318 1337
1319 void InspectorCSSAgent::willReparseStyleSheet() 1338 void InspectorCSSAgent::willReparseStyleSheet()
1320 { 1339 {
1321 ASSERT(!m_isSettingStyleSheetText); 1340 ASSERT(!m_isSettingStyleSheetText);
1322 m_isSettingStyleSheetText = true; 1341 m_isSettingStyleSheetText = true;
1323 } 1342 }
(...skipping 13 matching lines...) Expand all
1337 documentsToChange.add(element->ownerDocument()); 1356 documentsToChange.add(element->ownerDocument());
1338 } 1357 }
1339 1358
1340 m_nodeIdToForcedPseudoState.clear(); 1359 m_nodeIdToForcedPseudoState.clear();
1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1360 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1361 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1343 } 1362 }
1344 1363
1345 } // namespace WebCore 1364 } // namespace WebCore
1346 1365
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698