Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 private: | 280 private: |
| 281 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet; | 281 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet; |
| 282 unsigned m_ruleIndex; | 282 unsigned m_ruleIndex; |
| 283 unsigned m_propertyIndex; | 283 unsigned m_propertyIndex; |
| 284 String m_text; | 284 String m_text; |
| 285 String m_oldStyleText; | 285 String m_oldStyleText; |
| 286 String m_newStyleText; | 286 String m_newStyleText; |
| 287 bool m_overwrite; | 287 bool m_overwrite; |
| 288 }; | 288 }; |
| 289 | 289 |
| 290 class InspectorCSSAgent::SetRuleSelectorAction final : public InspectorCSSAgent: :StyleSheetAction { | 290 class InspectorCSSAgent::SetRuleSelectorOrMediaAction final : public InspectorCS SAgent::StyleSheetAction { |
| 291 WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction); | 291 WTF_MAKE_NONCOPYABLE(SetRuleSelectorOrMediaAction); |
| 292 public: | 292 public: |
| 293 SetRuleSelectorAction(InspectorStyleSheet* styleSheet, unsigned ruleIndex, c onst String& selector) | 293 SetRuleSelectorOrMediaAction(bool isMedia, InspectorStyleSheet* styleSheet, const SourceRange& range, const String& text) |
| 294 : InspectorCSSAgent::StyleSheetAction("SetRuleSelector") | 294 : InspectorCSSAgent::StyleSheetAction("SetRuleSelectorOrMediaAction") |
| 295 , m_styleSheet(styleSheet) | 295 , m_styleSheet(styleSheet) |
| 296 , m_ruleIndex(ruleIndex) | 296 , m_isMedia(isMedia) |
| 297 , m_selector(selector) | 297 , m_range(range) |
| 298 , m_text(text) | |
| 299 , m_cssRule(nullptr) | |
| 298 { | 300 { |
| 299 } | 301 } |
| 300 | 302 |
| 301 virtual bool perform(ExceptionState& exceptionState) override | 303 virtual bool perform(ExceptionState& exceptionState) override |
| 302 { | 304 { |
| 303 m_oldSelector = m_styleSheet->ruleSelector(m_ruleIndex, exceptionState); | |
| 304 if (exceptionState.hadException()) | |
| 305 return false; | |
| 306 return redo(exceptionState); | 305 return redo(exceptionState); |
| 307 } | 306 } |
| 308 | 307 |
| 309 virtual bool undo(ExceptionState& exceptionState) override | 308 virtual bool undo(ExceptionState& exceptionState) override |
| 310 { | 309 { |
| 311 return m_styleSheet->setRuleSelector(m_ruleIndex, m_oldSelector, excepti onState); | 310 if (m_isMedia) |
| 311 return m_styleSheet->setMediaRuleText(m_newRange, m_oldText, nullptr , nullptr, exceptionState); | |
| 312 return m_styleSheet->setRuleSelector(m_newRange, m_oldText, nullptr, nul lptr, exceptionState); | |
| 312 } | 313 } |
| 313 | 314 |
| 314 virtual bool redo(ExceptionState& exceptionState) override | 315 virtual bool redo(ExceptionState& exceptionState) override |
| 315 { | 316 { |
| 316 return m_styleSheet->setRuleSelector(m_ruleIndex, m_selector, exceptionS tate); | 317 if (m_isMedia) |
| 318 m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRa nge, &m_oldText, exceptionState); | |
| 319 else | |
| 320 m_cssRule = m_styleSheet->setRuleSelector(m_range, m_text, &m_newRan ge, &m_oldText, exceptionState); | |
| 321 return m_cssRule; | |
| 322 } | |
| 323 | |
| 324 CSSRule* takeRule() | |
| 325 { | |
| 326 CSSRule* result = m_cssRule.get(); | |
| 327 m_cssRule = nullptr; | |
| 328 return result; | |
| 317 } | 329 } |
| 318 | 330 |
| 319 DEFINE_INLINE_VIRTUAL_TRACE() | 331 DEFINE_INLINE_VIRTUAL_TRACE() |
| 320 { | 332 { |
| 321 visitor->trace(m_styleSheet); | 333 visitor->trace(m_styleSheet); |
| 334 visitor->trace(m_cssRule); | |
| 322 InspectorCSSAgent::StyleSheetAction::trace(visitor); | 335 InspectorCSSAgent::StyleSheetAction::trace(visitor); |
| 323 } | 336 } |
| 324 | 337 |
| 325 private: | 338 private: |
| 326 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 339 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
| 327 unsigned m_ruleIndex; | 340 bool m_isMedia; |
| 328 String m_selector; | 341 SourceRange m_range; |
| 329 String m_oldSelector; | |
| 330 }; | |
| 331 | |
| 332 class InspectorCSSAgent::SetMediaTextAction final : public InspectorCSSAgent::St yleSheetAction { | |
| 333 WTF_MAKE_NONCOPYABLE(SetMediaTextAction); | |
| 334 public: | |
| 335 SetMediaTextAction(InspectorStyleSheet* styleSheet, unsigned ruleIndex, cons t String& text) | |
| 336 : InspectorCSSAgent::StyleSheetAction("SetMediaText") | |
| 337 , m_styleSheet(styleSheet) | |
| 338 , m_ruleIndex(ruleIndex) | |
| 339 , m_text(text) | |
| 340 { | |
| 341 } | |
| 342 | |
| 343 virtual bool perform(ExceptionState& exceptionState) override | |
| 344 { | |
| 345 m_oldText = m_styleSheet->mediaRuleText(m_ruleIndex, exceptionState); | |
| 346 if (exceptionState.hadException()) | |
| 347 return false; | |
| 348 return redo(exceptionState); | |
| 349 } | |
| 350 | |
| 351 virtual bool undo(ExceptionState& exceptionState) override | |
| 352 { | |
| 353 return m_styleSheet->setMediaRuleText(m_ruleIndex, m_oldText, exceptionS tate); | |
| 354 } | |
| 355 | |
| 356 virtual bool redo(ExceptionState& exceptionState) override | |
| 357 { | |
| 358 return m_styleSheet->setMediaRuleText(m_ruleIndex, m_text, exceptionStat e); | |
| 359 } | |
| 360 | |
| 361 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 362 { | |
| 363 visitor->trace(m_styleSheet); | |
| 364 InspectorCSSAgent::StyleSheetAction::trace(visitor); | |
| 365 } | |
| 366 | |
| 367 private: | |
| 368 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | |
| 369 unsigned m_ruleIndex; | |
| 370 String m_text; | 342 String m_text; |
| 371 String m_oldText; | 343 String m_oldText; |
| 344 SourceRange m_newRange; | |
| 345 RefPtrWillBeMember<CSSRule> m_cssRule; | |
| 372 }; | 346 }; |
| 373 | 347 |
| 374 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh eetAction { | 348 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh eetAction { |
| 375 WTF_MAKE_NONCOPYABLE(AddRuleAction); | 349 WTF_MAKE_NONCOPYABLE(AddRuleAction); |
| 376 public: | 350 public: |
| 377 AddRuleAction(InspectorStyleSheet* styleSheet, const String& ruleText, const SourceRange& location) | 351 AddRuleAction(InspectorStyleSheet* styleSheet, const String& ruleText, const SourceRange& location) |
| 378 : InspectorCSSAgent::StyleSheetAction("AddRule") | 352 : InspectorCSSAgent::StyleSheetAction("AddRule") |
| 379 , m_styleSheet(styleSheet) | 353 , m_styleSheet(styleSheet) |
| 380 , m_ruleText(ruleText) | 354 , m_ruleText(ruleText) |
| 381 , m_location(location) | 355 , m_location(location) |
| 382 { | 356 { |
| 383 } | 357 } |
| 384 | 358 |
| 385 virtual bool perform(ExceptionState& exceptionState) override | 359 virtual bool perform(ExceptionState& exceptionState) override |
| 386 { | 360 { |
| 387 return redo(exceptionState); | 361 return redo(exceptionState); |
| 388 } | 362 } |
| 389 | 363 |
| 390 virtual bool undo(ExceptionState& exceptionState) override | 364 virtual bool undo(ExceptionState& exceptionState) override |
| 391 { | 365 { |
| 392 return m_styleSheet->deleteRule(m_newOrdinal, m_oldText, exceptionState) ; | 366 return m_styleSheet->deleteRule(m_addedRange, exceptionState); |
| 393 } | 367 } |
| 394 | 368 |
| 395 virtual bool redo(ExceptionState& exceptionState) override | 369 virtual bool redo(ExceptionState& exceptionState) override |
| 396 { | 370 { |
| 397 if (!m_styleSheet->getText(&m_oldText)) | 371 m_cssRule = m_styleSheet->addRule(m_ruleText, m_location, &m_addedRange, exceptionState); |
| 398 return false; | |
| 399 CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_ruleText, m_locatio n, exceptionState); | |
| 400 if (exceptionState.hadException()) | 372 if (exceptionState.hadException()) |
| 401 return false; | 373 return false; |
| 402 m_newOrdinal = m_styleSheet->indexOf(cssStyleRule); | |
| 403 return true; | 374 return true; |
| 404 } | 375 } |
| 405 | 376 |
| 406 unsigned newRuleOrdinal() { return m_newOrdinal; } | 377 CSSStyleRule* takeRule() |
| 378 { | |
| 379 CSSStyleRule* result = m_cssRule.get(); | |
| 380 m_cssRule = nullptr; | |
|
lushnikov
2015/06/17 09:56:22
FYI: this looks shaggy as this might kill the "res
pfeldman
2015/06/17 11:05:08
Done.
| |
| 381 return result; | |
| 382 } | |
| 407 | 383 |
| 408 DEFINE_INLINE_VIRTUAL_TRACE() | 384 DEFINE_INLINE_VIRTUAL_TRACE() |
| 409 { | 385 { |
| 410 visitor->trace(m_styleSheet); | 386 visitor->trace(m_styleSheet); |
| 387 visitor->trace(m_cssRule); | |
| 411 InspectorCSSAgent::StyleSheetAction::trace(visitor); | 388 InspectorCSSAgent::StyleSheetAction::trace(visitor); |
| 412 } | 389 } |
| 413 | 390 |
| 414 private: | 391 private: |
| 415 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 392 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
| 416 unsigned m_newOrdinal; | 393 RefPtrWillBeMember<CSSStyleRule> m_cssRule; |
| 417 String m_ruleText; | 394 String m_ruleText; |
| 418 String m_oldText; | 395 String m_oldText; |
| 419 SourceRange m_location; | 396 SourceRange m_location; |
| 397 SourceRange m_addedRange; | |
| 420 }; | 398 }; |
| 421 | 399 |
| 422 // static | 400 // static |
| 423 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) | 401 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) |
| 424 { | 402 { |
| 425 if (!rule || rule->type() != CSSRule::STYLE_RULE) | 403 if (!rule || rule->type() != CSSRule::STYLE_RULE) |
| 426 return nullptr; | 404 return nullptr; |
| 427 return toCSSStyleRule(rule); | 405 return toCSSStyleRule(rule); |
| 428 } | 406 } |
| 429 | 407 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty peBuilder::CSS::CSSRule>& result) | 957 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty peBuilder::CSS::CSSRule>& result) |
| 980 { | 958 { |
| 981 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); | 959 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); |
| 982 if (!inspectorStyleSheet) { | 960 if (!inspectorStyleSheet) { |
| 983 *errorString = "Stylesheet not found"; | 961 *errorString = "Stylesheet not found"; |
| 984 return; | 962 return; |
| 985 } | 963 } |
| 986 SourceRange selectorRange; | 964 SourceRange selectorRange; |
| 987 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) | 965 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) |
| 988 return; | 966 return; |
| 989 unsigned ruleIndex = 0; | |
| 990 if (!inspectorStyleSheet->findRuleBySelectorRange(selectorRange, &ruleIndex) ) { | |
| 991 *errorString = "Source range didn't match any rule selector source range "; | |
| 992 return; | |
| 993 } | |
| 994 | 967 |
| 995 TrackExceptionState exceptionState; | 968 TrackExceptionState exceptionState; |
| 996 bool success = m_domAgent->history()->perform(adoptRefWillBeNoop(new SetRule SelectorAction(inspectorStyleSheet, ruleIndex, selector)), exceptionState); | 969 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(false, inspectorStyleSheet, selectorRange, sel ector)); |
| 970 bool success = m_domAgent->history()->perform(action, exceptionState); | |
| 997 if (success) { | 971 if (success) { |
| 998 CSSStyleRule* rule = inspectorStyleSheet->ruleAt(ruleIndex); | 972 CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(action->takeRule( )); |
| 999 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListCha in(rule)); | 973 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListCha in(rule)); |
| 1000 } | 974 } |
| 1001 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 975 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1002 } | 976 } |
| 1003 | 977 |
| 1004 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild er::CSS::CSSMedia>& result) | 978 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild er::CSS::CSSMedia>& result) |
| 1005 { | 979 { |
| 1006 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); | 980 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); |
| 1007 if (!inspectorStyleSheet) { | 981 if (!inspectorStyleSheet) { |
| 1008 *errorString = "Stylesheet not found"; | 982 *errorString = "Stylesheet not found"; |
| 1009 return; | 983 return; |
| 1010 } | 984 } |
| 1011 SourceRange textRange; | 985 SourceRange textRange; |
| 1012 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa nge)) | 986 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa nge)) |
| 1013 return; | 987 return; |
| 1014 unsigned ruleIndex = 0; | |
| 1015 if (!inspectorStyleSheet->findMediaRuleByRange(textRange, &ruleIndex)) { | |
| 1016 *errorString = "Source range didn't match any media rule source range"; | |
| 1017 return; | |
| 1018 } | |
| 1019 | 988 |
| 1020 TrackExceptionState exceptionState; | 989 TrackExceptionState exceptionState; |
| 1021 bool success = m_domAgent->history()->perform(adoptRefWillBeNoop(new SetMedi aTextAction(inspectorStyleSheet, ruleIndex, text)), exceptionState); | 990 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(true, inspectorStyleSheet, textRange, text)); |
| 991 bool success = m_domAgent->history()->perform(action, exceptionState); | |
| 1022 if (success) { | 992 if (success) { |
| 1023 CSSMediaRule* rule = inspectorStyleSheet->mediaRuleAt(ruleIndex); | 993 CSSMediaRule* rule = InspectorCSSAgent::asCSSMediaRule(action->takeRule( )); |
| 1024 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); | 994 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); |
| 1025 if (sourceURL.isEmpty()) | 995 if (sourceURL.isEmpty()) |
| 1026 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh eet()->ownerDocument()); | 996 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh eet()->ownerDocument()); |
| 1027 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc eURL, rule->parentStyleSheet()); | 997 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc eURL, rule->parentStyleSheet()); |
| 1028 } | 998 } |
| 1029 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 999 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1030 } | 1000 } |
| 1031 | 1001 |
| 1032 void InspectorCSSAgent::createStyleSheet(ErrorString* errorString, const String& frameId, TypeBuilder::CSS::StyleSheetId* outStyleSheetId) | 1002 void InspectorCSSAgent::createStyleSheet(ErrorString* errorString, const String& frameId, TypeBuilder::CSS::StyleSheetId* outStyleSheetId) |
| 1033 { | 1003 { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1064 return; | 1034 return; |
| 1065 | 1035 |
| 1066 TrackExceptionState exceptionState; | 1036 TrackExceptionState exceptionState; |
| 1067 RefPtrWillBeRawPtr<AddRuleAction> action = adoptRefWillBeNoop(new AddRuleAct ion(inspectorStyleSheet, ruleText, ruleLocation)); | 1037 RefPtrWillBeRawPtr<AddRuleAction> action = adoptRefWillBeNoop(new AddRuleAct ion(inspectorStyleSheet, ruleText, ruleLocation)); |
| 1068 bool success = m_domAgent->history()->perform(action, exceptionState); | 1038 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 1069 if (!success) { | 1039 if (!success) { |
| 1070 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 1040 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1071 return; | 1041 return; |
| 1072 } | 1042 } |
| 1073 | 1043 |
| 1074 unsigned ruleOrdinal = action->newRuleOrdinal(); | 1044 CSSStyleRule* rule = action->takeRule(); |
| 1075 CSSStyleRule* rule = inspectorStyleSheet->ruleAt(ruleOrdinal); | |
| 1076 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListChain(r ule)); | 1045 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListChain(r ule)); |
| 1077 } | 1046 } |
| 1078 | 1047 |
| 1079 void InspectorCSSAgent::forcePseudoState(ErrorString* errorString, int nodeId, c onst RefPtr<JSONArray>& forcedPseudoClasses) | 1048 void InspectorCSSAgent::forcePseudoState(ErrorString* errorString, int nodeId, c onst RefPtr<JSONArray>& forcedPseudoClasses) |
| 1080 { | 1049 { |
| 1081 Element* element = m_domAgent->assertElement(errorString, nodeId); | 1050 Element* element = m_domAgent->assertElement(errorString, nodeId); |
| 1082 if (!element) | 1051 if (!element) |
| 1083 return; | 1052 return; |
| 1084 | 1053 |
| 1085 unsigned forcedPseudoState = computePseudoClassMask(forcedPseudoClasses.get( )); | 1054 unsigned forcedPseudoState = computePseudoClassMask(forcedPseudoClasses.get( )); |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1589 visitor->trace(m_invalidatedDocuments); | 1558 visitor->trace(m_invalidatedDocuments); |
| 1590 visitor->trace(m_nodeToInspectorStyleSheet); | 1559 visitor->trace(m_nodeToInspectorStyleSheet); |
| 1591 visitor->trace(m_documentToViaInspectorStyleSheet); | 1560 visitor->trace(m_documentToViaInspectorStyleSheet); |
| 1592 #endif | 1561 #endif |
| 1593 visitor->trace(m_inspectorUserAgentStyleSheet); | 1562 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 1594 InspectorBaseAgent::trace(visitor); | 1563 InspectorBaseAgent::trace(visitor); |
| 1595 } | 1564 } |
| 1596 | 1565 |
| 1597 } // namespace blink | 1566 } // namespace blink |
| 1598 | 1567 |
| OLD | NEW |