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

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

Issue 1186613005: DevTools: migrate inspector's ParsedStyleSheet to Oilpan. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 m_currentRuleDataStack.last()->mediaSourceData->queryData.append(data); 328 m_currentRuleDataStack.last()->mediaSourceData->queryData.append(data);
329 } 329 }
330 330
331 void StyleSheetHandler::endMediaQuery() 331 void StyleSheetHandler::endMediaQuery()
332 { 332 {
333 m_currentMediaQueryData.clear(); 333 m_currentMediaQueryData.clear();
334 } 334 }
335 335
336 } // namespace 336 } // namespace
337 337
338 class ParsedStyleSheet { 338 class ParsedStyleSheet : public RefCountedWillBeGarbageCollectedFinalized<Parsed StyleSheet> {
339 WTF_MAKE_FAST_ALLOCATED(ParsedStyleSheet);
340 public: 339 public:
341 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet); 340 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet);
342 341
343 const String& text() const { ASSERT(m_hasText); return m_text; } 342 const String& text() const { ASSERT(m_hasText); return m_text; }
344 void setText(const String&); 343 void setText(const String&);
345 bool hasText() const { return m_hasText; } 344 bool hasText() const { return m_hasText; }
346 bool ensureSourceData(); 345 bool ensureSourceData();
347 bool hasSourceData() const { return m_sourceData; } 346 bool hasSourceData() const { return m_sourceData; }
348 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; 347 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ruleSourceDataAt(unsigned) const;
349 unsigned ruleCount() { return m_sourceData->size(); } 348 unsigned ruleCount() { return m_sourceData->size(); }
350 349
350 DECLARE_TRACE();
351
351 private: 352 private:
352 void flattenSourceData(RuleSourceDataList*); 353 void flattenSourceData(RuleSourceDataList*);
353 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>); 354 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>);
354 355
355 String m_text; 356 String m_text;
356 bool m_hasText; 357 bool m_hasText;
357 OwnPtrWillBePersistent<RuleSourceDataList> m_sourceData; 358 OwnPtrWillBeMember<RuleSourceDataList> m_sourceData;
358 RefPtrWillBePersistent<CSSStyleSheet> m_pageStyleSheet; 359 RefPtrWillBeMember<CSSStyleSheet> m_pageStyleSheet;
359 }; 360 };
360 361
361 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet) 362 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet)
362 : m_hasText(false) 363 : m_hasText(false)
363 , m_pageStyleSheet(pageStyleSheet) 364 , m_pageStyleSheet(pageStyleSheet)
364 { 365 {
365 } 366 }
366 367
367 void ParsedStyleSheet::setText(const String& text) 368 void ParsedStyleSheet::setText(const String& text)
368 { 369 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 428 }
428 429
429 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDat aAt(unsigned index) const 430 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDat aAt(unsigned index) const
430 { 431 {
431 if (!hasSourceData() || index >= m_sourceData->size()) 432 if (!hasSourceData() || index >= m_sourceData->size())
432 return nullptr; 433 return nullptr;
433 434
434 return m_sourceData->at(index); 435 return m_sourceData->at(index);
435 } 436 }
436 437
438 DEFINE_TRACE(ParsedStyleSheet)
439 {
440 visitor->trace(m_sourceData);
441 visitor->trace(m_pageStyleSheet);
442 }
443
437 namespace blink { 444 namespace blink {
438 445
439 enum MediaListSource { 446 enum MediaListSource {
440 MediaListSourceLinkedSheet, 447 MediaListSourceLinkedSheet,
441 MediaListSourceInlineSheet, 448 MediaListSourceInlineSheet,
442 MediaListSourceMediaRule, 449 MediaListSourceMediaRule,
443 MediaListSourceImportRule 450 MediaListSourceImportRule
444 }; 451 };
445 452
446 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So urceRange& range, const LineEndings* lineEndings) 453 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So urceRange& range, const LineEndings* lineEndings)
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 } 936 }
930 937
931 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent) 938 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent)
932 : InspectorStyleSheetBase(id, cssAgent) 939 : InspectorStyleSheetBase(id, cssAgent)
933 , m_cssAgent(cssAgent) 940 , m_cssAgent(cssAgent)
934 , m_resourceAgent(resourceAgent) 941 , m_resourceAgent(resourceAgent)
935 , m_pageStyleSheet(pageStyleSheet) 942 , m_pageStyleSheet(pageStyleSheet)
936 , m_origin(origin) 943 , m_origin(origin)
937 , m_documentURL(documentURL) 944 , m_documentURL(documentURL)
938 { 945 {
939 m_parsedStyleSheet = adoptPtr(new ParsedStyleSheet(m_pageStyleSheet.get())); 946 m_parsedStyleSheet = new ParsedStyleSheet(m_pageStyleSheet.get());
yurys 2015/06/15 08:21:56 Why was it removed? It should have become adoptPtr
940 } 947 }
941 948
942 InspectorStyleSheet::~InspectorStyleSheet() 949 InspectorStyleSheet::~InspectorStyleSheet()
943 { 950 {
944 } 951 }
945 952
946 DEFINE_TRACE(InspectorStyleSheet) 953 DEFINE_TRACE(InspectorStyleSheet)
947 { 954 {
948 visitor->trace(m_cssAgent); 955 visitor->trace(m_cssAgent);
949 visitor->trace(m_resourceAgent); 956 visitor->trace(m_resourceAgent);
950 visitor->trace(m_pageStyleSheet); 957 visitor->trace(m_pageStyleSheet);
958 visitor->trace(m_parsedStyleSheet);
951 visitor->trace(m_flatRules); 959 visitor->trace(m_flatRules);
952 InspectorStyleSheetBase::trace(visitor); 960 InspectorStyleSheetBase::trace(visitor);
953 } 961 }
954 962
955 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) 963 static String styleSheetURL(CSSStyleSheet* pageStyleSheet)
956 { 964 {
957 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) 965 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty())
958 return pageStyleSheet->contents()->baseURL().string(); 966 return pageStyleSheet->contents()->baseURL().string();
959 return emptyString(); 967 return emptyString();
960 } 968 }
961 969
962 String InspectorStyleSheet::finalURL() const 970 String InspectorStyleSheet::finalURL() const
963 { 971 {
964 String url = styleSheetURL(m_pageStyleSheet.get()); 972 String url = styleSheetURL(m_pageStyleSheet.get());
965 return url.isEmpty() ? m_documentURL : url; 973 return url.isEmpty() ? m_documentURL : url;
966 } 974 }
967 975
968 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) 976 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate)
969 { 977 {
970 updateText(text); 978 updateText(text);
971 m_flatRules.clear();
972 979
973 if (listener()) 980 if (listener())
974 listener()->willReparseStyleSheet(); 981 listener()->willReparseStyleSheet();
975 982
976 { 983 {
977 // Have a separate scope for clearRules() (bug 95324). 984 // Have a separate scope for clearRules() (bug 95324).
978 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); 985 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get());
979 m_pageStyleSheet->contents()->clearRules(); 986 m_pageStyleSheet->contents()->clearRules();
980 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); 987 m_pageStyleSheet->clearChildRuleCSSOMWrappers();
981 } 988 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 } 1258 }
1252 1259
1253 ensureFlatRules(); 1260 ensureFlatRules();
1254 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState); 1261 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState);
1255 if (exceptionState.hadException()) 1262 if (exceptionState.hadException())
1256 return nullptr; 1263 return nullptr;
1257 1264
1258 text.insert(ruleText, location.start); 1265 text.insert(ruleText, location.start);
1259 1266
1260 updateText(text); 1267 updateText(text);
1261 m_flatRules.clear();
1262 1268
1263 onStyleSheetTextChanged(); 1269 onStyleSheetTextChanged();
1264 return styleRule; 1270 return styleRule;
1265 } 1271 }
1266 1272
1267 bool InspectorStyleSheet::deleteRule(unsigned ruleIndex, const String& oldText, ExceptionState& exceptionState) 1273 bool InspectorStyleSheet::deleteRule(unsigned ruleIndex, const String& oldText, ExceptionState& exceptionState)
1268 { 1274 {
1269 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleAt(ruleIndex); 1275 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleAt(ruleIndex);
1270 if (!rule) { 1276 if (!rule) {
1271 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1277 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
(...skipping 29 matching lines...) Expand all
1301 ++index; 1307 ++index;
1302 ASSERT(index < styleSheet->length()); 1308 ASSERT(index < styleSheet->length());
1303 styleSheet->deleteRule(index, exceptionState); 1309 styleSheet->deleteRule(index, exceptionState);
1304 } 1310 }
1305 // |rule| MAY NOT be addressed after this line! 1311 // |rule| MAY NOT be addressed after this line!
1306 1312
1307 if (exceptionState.hadException()) 1313 if (exceptionState.hadException())
1308 return false; 1314 return false;
1309 1315
1310 updateText(oldText); 1316 updateText(oldText);
1311 m_flatRules.clear();
1312 onStyleSheetTextChanged(); 1317 onStyleSheetTextChanged();
1313 return true; 1318 return true;
1314 } 1319 }
1315 1320
1316 void InspectorStyleSheet::updateText(const String& newText) 1321 void InspectorStyleSheet::updateText(const String& newText)
1317 { 1322 {
1318 Element* element = ownerStyleElement(); 1323 Element* element = ownerStyleElement();
1319 if (element) 1324 if (element)
1320 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); 1325 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t);
1321 else 1326 else
1322 m_cssAgent->addEditedStyleSheet(finalURL(), newText); 1327 m_cssAgent->addEditedStyleSheet(finalURL(), newText);
1323 m_parsedStyleSheet->setText(newText); 1328 m_parsedStyleSheet->setText(newText);
1329 m_flatRules.clear();
lushnikov 2015/06/15 12:21:36 this is wrong - updateText is called from way more
1324 } 1330 }
1325 1331
1326 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const 1332 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const
1327 { 1333 {
1328 ensureFlatRules(); 1334 ensureFlatRules();
1329 return InspectorCSSAgent::asCSSStyleRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get()); 1335 return InspectorCSSAgent::asCSSStyleRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get());
1330 } 1336 }
1331 1337
1332 CSSMediaRule* InspectorStyleSheet::mediaRuleAt(unsigned ruleIndex) const 1338 CSSMediaRule* InspectorStyleSheet::mediaRuleAt(unsigned ruleIndex) const
1333 { 1339 {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1929
1924 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1930 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1925 { 1931 {
1926 visitor->trace(m_element); 1932 visitor->trace(m_element);
1927 visitor->trace(m_ruleSourceData); 1933 visitor->trace(m_ruleSourceData);
1928 visitor->trace(m_inspectorStyle); 1934 visitor->trace(m_inspectorStyle);
1929 InspectorStyleSheetBase::trace(visitor); 1935 InspectorStyleSheetBase::trace(visitor);
1930 } 1936 }
1931 1937
1932 } // namespace blink 1938 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698