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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 private: | 309 private: |
310 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 310 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
311 InspectorCSSId m_cssId; | 311 InspectorCSSId m_cssId; |
312 String m_selector; | 312 String m_selector; |
313 String m_oldSelector; | 313 String m_oldSelector; |
314 }; | 314 }; |
315 | 315 |
316 class InspectorCSSAgent::AddRuleAction FINAL : public InspectorCSSAgent::StyleSh
eetAction { | 316 class InspectorCSSAgent::AddRuleAction FINAL : public InspectorCSSAgent::StyleSh
eetAction { |
317 WTF_MAKE_NONCOPYABLE(AddRuleAction); | 317 WTF_MAKE_NONCOPYABLE(AddRuleAction); |
318 public: | 318 public: |
319 AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector) | 319 AddRuleAction(InspectorStyleSheet* styleSheet, const String& ruleText, const
SourceRange& location) |
320 : InspectorCSSAgent::StyleSheetAction("AddRule") | 320 : InspectorCSSAgent::StyleSheetAction("AddRule") |
321 , m_styleSheet(styleSheet) | 321 , m_styleSheet(styleSheet) |
322 , m_selector(selector) | 322 , m_ruleText(ruleText) |
| 323 , m_location(location) |
323 { | 324 { |
324 } | 325 } |
325 | 326 |
326 virtual bool perform(ExceptionState& exceptionState) OVERRIDE | 327 virtual bool perform(ExceptionState& exceptionState) OVERRIDE |
327 { | 328 { |
328 return redo(exceptionState); | 329 return redo(exceptionState); |
329 } | 330 } |
330 | 331 |
331 virtual bool undo(ExceptionState& exceptionState) OVERRIDE | 332 virtual bool undo(ExceptionState& exceptionState) OVERRIDE |
332 { | 333 { |
333 return m_styleSheet->deleteRule(m_newId, exceptionState); | 334 return m_styleSheet->deleteRule(m_newId, m_oldText, exceptionState); |
334 } | 335 } |
335 | 336 |
336 virtual bool redo(ExceptionState& exceptionState) OVERRIDE | 337 virtual bool redo(ExceptionState& exceptionState) OVERRIDE |
337 { | 338 { |
338 CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, exception
State); | 339 if (!m_styleSheet->getText(&m_oldText)) |
| 340 return false; |
| 341 CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_ruleText, m_locatio
n, exceptionState); |
339 if (exceptionState.hadException()) | 342 if (exceptionState.hadException()) |
340 return false; | 343 return false; |
341 m_newId = m_styleSheet->ruleId(cssStyleRule); | 344 m_newId = m_styleSheet->ruleId(cssStyleRule); |
342 return true; | 345 return true; |
343 } | 346 } |
344 | 347 |
345 InspectorCSSId newRuleId() { return m_newId; } | 348 InspectorCSSId newRuleId() { return m_newId; } |
346 | 349 |
347 virtual void trace(Visitor* visitor) OVERRIDE | 350 virtual void trace(Visitor* visitor) OVERRIDE |
348 { | 351 { |
349 visitor->trace(m_styleSheet); | 352 visitor->trace(m_styleSheet); |
350 InspectorCSSAgent::StyleSheetAction::trace(visitor); | 353 InspectorCSSAgent::StyleSheetAction::trace(visitor); |
351 } | 354 } |
352 | 355 |
353 private: | 356 private: |
354 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 357 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
355 InspectorCSSId m_newId; | 358 InspectorCSSId m_newId; |
356 String m_selector; | 359 String m_ruleText; |
357 String m_oldSelector; | 360 String m_oldText; |
| 361 SourceRange m_location; |
358 }; | 362 }; |
359 | 363 |
360 // static | 364 // static |
361 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) | 365 CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) |
362 { | 366 { |
363 if (!rule || rule->type() != CSSRule::STYLE_RULE) | 367 if (!rule || rule->type() != CSSRule::STYLE_RULE) |
364 return 0; | 368 return 0; |
365 return toCSSStyleRule(rule); | 369 return toCSSStyleRule(rule); |
366 } | 370 } |
367 | 371 |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 if (!inspectorStyleSheet) { | 929 if (!inspectorStyleSheet) { |
926 *errorString = "No target stylesheet found"; | 930 *errorString = "No target stylesheet found"; |
927 return; | 931 return; |
928 } | 932 } |
929 | 933 |
930 updateActiveStyleSheets(document, ExistingFrontendRefresh); | 934 updateActiveStyleSheets(document, ExistingFrontendRefresh); |
931 | 935 |
932 *outStyleSheetId = inspectorStyleSheet->id(); | 936 *outStyleSheetId = inspectorStyleSheet->id(); |
933 } | 937 } |
934 | 938 |
935 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe
etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) | 939 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe
etId, const String& ruleText, const RefPtr<JSONObject>& location, RefPtr<TypeBui
lder::CSS::CSSRule>& result) |
936 { | 940 { |
937 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); | 941 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); |
938 if (!inspectorStyleSheet) | 942 if (!inspectorStyleSheet) |
939 return; | 943 return; |
| 944 SourceRange ruleLocation; |
| 945 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, location, &rul
eLocation)) |
| 946 return; |
940 | 947 |
941 TrackExceptionState exceptionState; | 948 TrackExceptionState exceptionState; |
942 RefPtrWillBeRawPtr<AddRuleAction> action = adoptRefWillBeNoop(new AddRuleAct
ion(inspectorStyleSheet, selector)); | 949 RefPtrWillBeRawPtr<AddRuleAction> action = adoptRefWillBeNoop(new AddRuleAct
ion(inspectorStyleSheet, ruleText, ruleLocation)); |
943 bool success = m_domAgent->history()->perform(action, exceptionState); | 950 bool success = m_domAgent->history()->perform(action, exceptionState); |
944 if (!success) { | 951 if (!success) { |
945 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 952 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
946 return; | 953 return; |
947 } | 954 } |
948 | 955 |
949 InspectorCSSId ruleId = action->newRuleId(); | 956 InspectorCSSId ruleId = action->newRuleId(); |
950 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId); | 957 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId); |
951 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListChain(r
ule)); | 958 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListChain(r
ule)); |
952 } | 959 } |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 visitor->trace(m_invalidatedDocuments); | 1453 visitor->trace(m_invalidatedDocuments); |
1447 visitor->trace(m_nodeToInspectorStyleSheet); | 1454 visitor->trace(m_nodeToInspectorStyleSheet); |
1448 visitor->trace(m_documentToViaInspectorStyleSheet); | 1455 visitor->trace(m_documentToViaInspectorStyleSheet); |
1449 #endif | 1456 #endif |
1450 visitor->trace(m_inspectorUserAgentStyleSheet); | 1457 visitor->trace(m_inspectorUserAgentStyleSheet); |
1451 InspectorBaseAgent::trace(visitor); | 1458 InspectorBaseAgent::trace(visitor); |
1452 } | 1459 } |
1453 | 1460 |
1454 } // namespace blink | 1461 } // namespace blink |
1455 | 1462 |
OLD | NEW |