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

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

Issue 202103002: DevTools: refactor InspectorStyleSheet (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline 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
« 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 497
498 if (rule->type() == CSSRule::KEYFRAMES_RULE) 498 if (rule->type() == CSSRule::KEYFRAMES_RULE)
499 return toCSSKeyframesRule(rule)->cssRules(); 499 return toCSSKeyframesRule(rule)->cssRules();
500 500
501 if (rule->type() == CSSRule::SUPPORTS_RULE) 501 if (rule->type() == CSSRule::SUPPORTS_RULE)
502 return toCSSSupportsRule(rule)->cssRules(); 502 return toCSSSupportsRule(rule)->cssRules();
503 503
504 return nullptr; 504 return nullptr;
505 } 505 }
506 506
507 PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet) 507 PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheetBase* parentStyleShee t)
508 { 508 {
509 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); 509 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet));
510 } 510 }
511 511
512 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyl eDeclaration> style, InspectorStyleSheet* parentStyleSheet) 512 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyl eDeclaration> style, InspectorStyleSheetBase* parentStyleSheet)
513 : m_styleId(styleId) 513 : m_styleId(styleId)
514 , m_style(style) 514 , m_style(style)
515 , m_parentStyleSheet(parentStyleSheet) 515 , m_parentStyleSheet(parentStyleSheet)
516 , m_formatAcquired(false) 516 , m_formatAcquired(false)
517 { 517 {
518 ASSERT(m_style); 518 ASSERT(m_style);
519 } 519 }
520 520
521 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st 521 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st
522 { 522 {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 823 }
824 } 824 }
825 825
826 m_format.first = formatLineFeed.toString(); 826 m_format.first = formatLineFeed.toString();
827 m_format.second = isFullPrefixScanned ? prefix.toString() : candidatePrefix; 827 m_format.second = isFullPrefixScanned ? prefix.toString() : candidatePrefix;
828 return m_format; 828 return m_format;
829 } 829 }
830 830
831 Document* InspectorStyle::ownerDocument() const 831 Document* InspectorStyle::ownerDocument() const
832 { 832 {
833 return m_parentStyleSheet->pageStyleSheet() ? m_parentStyleSheet->pageStyleS heet()->ownerDocument() : 0; 833 return m_parentStyleSheet->ownerDocument();
834 }
835
836 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener)
837 : m_id(id)
838 , m_listener(listener)
839 {
840 }
841
842 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText, ExceptionSt ate& exceptionState)
843 {
844 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
845 if (!inspectorStyle) {
846 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID.");
847 return false;
848 }
849
850 bool success = inspectorStyle->setPropertyText(propertyIndex, text, overwrit e, oldText, exceptionState);
851 if (success)
852 fireStyleSheetChanged();
853 return success;
854 }
855
856 void InspectorStyleSheetBase::fireStyleSheetChanged()
857 {
858 if (listener())
859 listener()->styleSheetChanged(this);
860 }
861
862 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style)
863 {
864 RefPtr<CSSRuleSourceData> sourceData;
865 if (ensureParsedDataReady())
866 sourceData = ruleSourceDataFor(style);
867
868 InspectorCSSId id = styleId(style);
869 if (id.isEmpty()) {
870 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id.
871 // See InspectorCSSAgent::buildObjectForRule for details.
872 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(id, style , this);
873 return inspectorStyle->buildObjectForStyle();
874 }
875 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
876 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle();
877
878 // Style text cannot be retrieved without stylesheet, so set cssText here.
879 if (sourceData) {
880 String sheetText;
881 bool success = getText(&sheetText);
882 if (success) {
883 const SourceRange& bodyRange = sourceData->ruleBodyRange;
884 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start));
885 }
886 }
887
888 return result.release();
834 } 889 }
835 890
836 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWi llBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::En um origin, const String& documentURL, Listener* listener) 891 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWi llBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::En um origin, const String& documentURL, Listener* listener)
837 { 892 {
838 return adoptRef(new InspectorStyleSheet(pageAgent, resourceAgent, id, pageSt yleSheet, origin, documentURL, listener)); 893 return adoptRef(new InspectorStyleSheet(pageAgent, resourceAgent, id, pageSt yleSheet, origin, documentURL, listener));
839 } 894 }
840 895
841 InspectorStyleSheet::InspectorStyleSheet(InspectorPageAgent* pageAgent, Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyle Sheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const St ring& documentURL, Listener* listener) 896 InspectorStyleSheet::InspectorStyleSheet(InspectorPageAgent* pageAgent, Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyle Sheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const St ring& documentURL, Listener* listener)
842 : m_pageAgent(pageAgent) 897 : InspectorStyleSheetBase(id, listener)
898 , m_pageAgent(pageAgent)
843 , m_resourceAgent(resourceAgent) 899 , m_resourceAgent(resourceAgent)
844 , m_id(id)
845 , m_pageStyleSheet(pageStyleSheet) 900 , m_pageStyleSheet(pageStyleSheet)
846 , m_origin(origin) 901 , m_origin(origin)
847 , m_documentURL(documentURL) 902 , m_documentURL(documentURL)
848 , m_listener(listener)
849 { 903 {
850 m_parsedStyleSheet = adoptPtr(new ParsedStyleSheet(m_pageStyleSheet.get())); 904 m_parsedStyleSheet = adoptPtr(new ParsedStyleSheet(m_pageStyleSheet.get()));
851 } 905 }
852 906
853 InspectorStyleSheet::~InspectorStyleSheet() 907 InspectorStyleSheet::~InspectorStyleSheet()
854 { 908 {
855 } 909 }
856 910
857 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) 911 static String styleSheetURL(CSSStyleSheet* pageStyleSheet)
858 { 912 {
859 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) 913 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty())
860 return pageStyleSheet->contents()->baseURL().string(); 914 return pageStyleSheet->contents()->baseURL().string();
861 return emptyString(); 915 return emptyString();
862 } 916 }
863 917
864 String InspectorStyleSheet::finalURL() const 918 String InspectorStyleSheet::finalURL() const
865 { 919 {
866 String url = styleSheetURL(m_pageStyleSheet.get()); 920 String url = styleSheetURL(m_pageStyleSheet.get());
867 return url.isEmpty() ? m_documentURL : url; 921 return url.isEmpty() ? m_documentURL : url;
868 } 922 }
869 923
870 void InspectorStyleSheet::reparseStyleSheet(const String& text) 924 void InspectorStyleSheet::reparseStyleSheet(const String& text)
871 { 925 {
872 if (m_listener) 926 if (listener())
873 m_listener->willReparseStyleSheet(); 927 listener()->willReparseStyleSheet();
874 928
875 { 929 {
876 // Have a separate scope for clearRules() (bug 95324). 930 // Have a separate scope for clearRules() (bug 95324).
877 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); 931 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get());
878 m_pageStyleSheet->contents()->clearRules(); 932 m_pageStyleSheet->contents()->clearRules();
879 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); 933 m_pageStyleSheet->clearChildRuleCSSOMWrappers();
880 } 934 }
881 { 935 {
882 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); 936 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get());
883 m_pageStyleSheet->contents()->parseString(text); 937 m_pageStyleSheet->contents()->parseString(text);
884 } 938 }
885 939
886 if (m_listener) 940 if (listener())
887 m_listener->didReparseStyleSheet(); 941 listener()->didReparseStyleSheet();
888 fireStyleSheetChanged(); 942 fireStyleSheetChanged();
889 m_pageStyleSheet->ownerDocument()->styleResolverChanged(RecalcStyleImmediate ly, FullStyleUpdate); 943 m_pageStyleSheet->ownerDocument()->styleResolverChanged(RecalcStyleImmediate ly, FullStyleUpdate);
890 } 944 }
891 945
892 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) 946 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate)
893 { 947 {
894 if (!checkPageStyleSheet(exceptionState))
895 return false;
896 if (!m_parsedStyleSheet)
897 return false;
898
899 m_parsedStyleSheet->setText(text); 948 m_parsedStyleSheet->setText(text);
900 m_flatRules.clear(); 949 m_flatRules.clear();
901 950
902 return true; 951 return true;
903 } 952 }
904 953
905 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) 954 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState)
906 { 955 {
907 CSSStyleRule* rule = ruleForId(id); 956 CSSStyleRule* rule = ruleForId(id);
908 if (!rule) { 957 if (!rule) {
909 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 958 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
910 return ""; 959 return "";
911 } 960 }
912 return rule->selectorText(); 961 return rule->selectorText();
913 } 962 }
914 963
915 bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String & selector, ExceptionState& exceptionState) 964 bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String & selector, ExceptionState& exceptionState)
916 { 965 {
917 if (!checkPageStyleSheet(exceptionState))
918 return false;
919 CSSStyleRule* rule = ruleForId(id); 966 CSSStyleRule* rule = ruleForId(id);
920 if (!rule) { 967 if (!rule) {
921 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 968 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
922 return false; 969 return false;
923 } 970 }
924 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 971 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
925 if (!styleSheet || !ensureParsedDataReady()) { 972 if (!styleSheet || !ensureParsedDataReady()) {
926 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector."); 973 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector.");
927 return false; 974 return false;
928 } 975 }
(...skipping 14 matching lines...) Expand all
943 990
944 static bool checkStyleRuleSelector(Document* document, const String& selector) 991 static bool checkStyleRuleSelector(Document* document, const String& selector)
945 { 992 {
946 CSSSelectorList selectorList; 993 CSSSelectorList selectorList;
947 createCSSParser(document)->parseSelector(selector, selectorList); 994 createCSSParser(document)->parseSelector(selector, selectorList);
948 return selectorList.isValid(); 995 return selectorList.isValid();
949 } 996 }
950 997
951 CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionStat e& exceptionState) 998 CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionStat e& exceptionState)
952 { 999 {
953 if (!checkPageStyleSheet(exceptionState))
954 return 0;
955 if (!checkStyleRuleSelector(m_pageStyleSheet->ownerDocument(), selector)) { 1000 if (!checkStyleRuleSelector(m_pageStyleSheet->ownerDocument(), selector)) {
956 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto r + "' could not be added."); 1001 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto r + "' could not be added.");
957 return 0; 1002 return 0;
958 } 1003 }
959 1004
960 String text; 1005 String text;
961 bool success = getText(&text); 1006 bool success = getText(&text);
962 if (!success) { 1007 if (!success) {
963 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec tor + "' could not be added."); 1008 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec tor + "' could not be added.");
964 return 0; 1009 return 0;
(...skipping 26 matching lines...) Expand all
991 // Using setText() as this operation changes the style sheet rule set. 1036 // Using setText() as this operation changes the style sheet rule set.
992 setText(styleSheetText.toString(), ASSERT_NO_EXCEPTION); 1037 setText(styleSheetText.toString(), ASSERT_NO_EXCEPTION);
993 1038
994 fireStyleSheetChanged(); 1039 fireStyleSheetChanged();
995 1040
996 return styleRule; 1041 return styleRule;
997 } 1042 }
998 1043
999 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionState& e xceptionState) 1044 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionState& e xceptionState)
1000 { 1045 {
1001 if (!checkPageStyleSheet(exceptionState))
1002 return false;
1003 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); 1046 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id);
1004 if (!rule) { 1047 if (!rule) {
1005 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1048 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1006 return false; 1049 return false;
1007 } 1050 }
1008 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1051 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1009 if (!styleSheet || !ensureParsedDataReady()) { 1052 if (!styleSheet || !ensureParsedDataReady()) {
1010 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); 1053 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found.");
1011 return false; 1054 return false;
1012 } 1055 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 if (!id.isEmpty()) 1182 if (!id.isEmpty())
1140 result->setRuleId(id.asProtocolValue<TypeBuilder::CSS::CSSRuleId>()) ; 1183 result->setRuleId(id.asProtocolValue<TypeBuilder::CSS::CSSRuleId>()) ;
1141 } 1184 }
1142 1185
1143 if (mediaStack) 1186 if (mediaStack)
1144 result->setMedia(mediaStack); 1187 result->setMedia(mediaStack);
1145 1188
1146 return result.release(); 1189 return result.release();
1147 } 1190 }
1148 1191
1149 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheet::buildObjectForStyle( CSSStyleDeclaration* style)
1150 {
1151 RefPtr<CSSRuleSourceData> sourceData;
1152 if (ensureParsedDataReady())
1153 sourceData = ruleSourceDataFor(style);
1154
1155 InspectorCSSId id = ruleIdByStyle(style);
1156 if (id.isEmpty()) {
1157 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id.
1158 // See InspectorCSSAgent::buildObjectForRule for details.
1159 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(id, style , this);
1160 return inspectorStyle->buildObjectForStyle();
1161 }
1162 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
1163 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle();
1164
1165 // Style text cannot be retrieved without stylesheet, so set cssText here.
1166 if (sourceData) {
1167 String sheetText;
1168 bool success = getText(&sheetText);
1169 if (success) {
1170 const SourceRange& bodyRange = sourceData->ruleBodyRange;
1171 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start));
1172 }
1173 }
1174
1175 return result.release();
1176 }
1177
1178 bool InspectorStyleSheet::setPropertyText(const InspectorCSSId& id, unsigned pro pertyIndex, const String& text, bool overwrite, String* oldText, ExceptionState& exceptionState)
1179 {
1180 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
1181 if (!inspectorStyle) {
1182 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID.");
1183 return false;
1184 }
1185
1186 bool success = inspectorStyle->setPropertyText(propertyIndex, text, overwrit e, oldText, exceptionState);
1187 if (success)
1188 fireStyleSheetChanged();
1189 return success;
1190 }
1191
1192 bool InspectorStyleSheet::getText(String* result) const 1192 bool InspectorStyleSheet::getText(String* result) const
1193 { 1193 {
1194 if (!ensureText()) 1194 if (!ensureText())
1195 return false; 1195 return false;
1196 *result = m_parsedStyleSheet->text(); 1196 *result = m_parsedStyleSheet->text();
1197 return true; 1197 return true;
1198 } 1198 }
1199 1199
1200 CSSStyleDeclaration* InspectorStyleSheet::styleForId(const InspectorCSSId& id) c onst 1200 CSSStyleDeclaration* InspectorStyleSheet::styleForId(const InspectorCSSId& id) c onst
1201 { 1201 {
1202 CSSStyleRule* rule = ruleForId(id); 1202 CSSStyleRule* rule = ruleForId(id);
1203 if (!rule) 1203 if (!rule)
1204 return 0; 1204 return 0;
1205 1205
1206 return rule->style(); 1206 return rule->style();
1207 } 1207 }
1208 1208
1209 void InspectorStyleSheet::fireStyleSheetChanged()
1210 {
1211 if (m_listener)
1212 m_listener->styleSheetChanged(this);
1213 }
1214
1215 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) 1209 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule)
1216 { 1210 {
1217 if (!ensureParsedDataReady()) 1211 if (!ensureParsedDataReady())
1218 return nullptr; 1212 return nullptr;
1219 1213
1220 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt( ruleIndexByRule(rule)); 1214 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt( ruleIndexByRule(rule));
1221 if (!sourceData) 1215 if (!sourceData)
1222 return nullptr; 1216 return nullptr;
1223 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get ()); 1217 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get ());
1224 } 1218 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 return true; 1353 return true;
1360 } 1354 }
1361 1355
1362 bool InspectorStyleSheet::ensureParsedDataReady() 1356 bool InspectorStyleSheet::ensureParsedDataReady()
1363 { 1357 {
1364 return ensureText() && m_parsedStyleSheet->ensureSourceData(); 1358 return ensureText() && m_parsedStyleSheet->ensureSourceData();
1365 } 1359 }
1366 1360
1367 bool InspectorStyleSheet::ensureText() const 1361 bool InspectorStyleSheet::ensureText() const
1368 { 1362 {
1369 if (!m_parsedStyleSheet)
1370 return false;
1371 if (m_parsedStyleSheet->hasText()) 1363 if (m_parsedStyleSheet->hasText())
1372 return true; 1364 return true;
1373 1365
1374 String text; 1366 String text;
1375 bool success = originalStyleSheetText(&text); 1367 bool success = originalStyleSheetText(&text);
1376 if (success) 1368 if (success)
1377 m_parsedStyleSheet->setText(text); 1369 m_parsedStyleSheet->setText(text);
1378 // No need to clear m_flatRules here - it's empty. 1370 // No need to clear m_flatRules here - it's empty.
1379 1371
1380 return success; 1372 return success;
(...skipping 27 matching lines...) Expand all
1408 1400
1409 void InspectorStyleSheet::ensureFlatRules() const 1401 void InspectorStyleSheet::ensureFlatRules() const
1410 { 1402 {
1411 // We are fine with redoing this for empty stylesheets as this will run fast . 1403 // We are fine with redoing this for empty stylesheets as this will run fast .
1412 if (m_flatRules.isEmpty()) 1404 if (m_flatRules.isEmpty())
1413 collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules); 1405 collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules);
1414 } 1406 }
1415 1407
1416 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text) 1408 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text)
1417 { 1409 {
1418 if (!m_pageStyleSheet)
1419 return false;
1420 if (!ensureParsedDataReady()) 1410 if (!ensureParsedDataReady())
1421 return false; 1411 return false;
1422 1412
1423 String patchedStyleSheetText; 1413 String patchedStyleSheetText;
1424 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); 1414 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText);
1425 if (!success) 1415 if (!success)
1426 return false; 1416 return false;
1427 1417
1428 InspectorCSSId id = ruleIdByStyle(style); 1418 InspectorCSSId id = ruleIdByStyle(style);
1429 if (id.isEmpty()) 1419 if (id.isEmpty())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 if (!success) 1459 if (!success)
1470 success = resourceStyleSheetText(result); 1460 success = resourceStyleSheetText(result);
1471 return success; 1461 return success;
1472 } 1462 }
1473 1463
1474 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const 1464 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const
1475 { 1465 {
1476 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::User || m_origin == Type Builder::CSS::StyleSheetOrigin::User_agent) 1466 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::User || m_origin == Type Builder::CSS::StyleSheetOrigin::User_agent)
1477 return false; 1467 return false;
1478 1468
1479 if (!m_pageStyleSheet || !ownerDocument() || !ownerDocument()->frame()) 1469 if (!ownerDocument() || !ownerDocument()->frame())
1480 return false; 1470 return false;
1481 1471
1482 bool base64Encoded; 1472 bool base64Encoded;
1483 bool success = m_resourceAgent->fetchResourceContent(ownerDocument()->frame( ), KURL(ParsedURLString, m_pageStyleSheet->href()), result, &base64Encoded) && ! base64Encoded; 1473 bool success = m_resourceAgent->fetchResourceContent(ownerDocument()->frame( ), KURL(ParsedURLString, m_pageStyleSheet->href()), result, &base64Encoded) && ! base64Encoded;
1484 return success; 1474 return success;
1485 } 1475 }
1486 1476
1487 bool InspectorStyleSheet::inlineStyleSheetText(String* result) const 1477 bool InspectorStyleSheet::inlineStyleSheetText(String* result) const
1488 { 1478 {
1489 if (!m_pageStyleSheet)
1490 return false;
1491
1492 Node* ownerNode = m_pageStyleSheet->ownerNode(); 1479 Node* ownerNode = m_pageStyleSheet->ownerNode();
1493 if (!ownerNode || ownerNode->nodeType() != Node::ELEMENT_NODE) 1480 if (!ownerNode || ownerNode->nodeType() != Node::ELEMENT_NODE)
1494 return false; 1481 return false;
1495 Element& ownerElement = toElement(*ownerNode); 1482 Element& ownerElement = toElement(*ownerNode);
1496 1483
1497 if (!isHTMLStyleElement(ownerElement) && !isSVGStyleElement(ownerElement)) 1484 if (!isHTMLStyleElement(ownerElement) && !isSVGStyleElement(ownerElement))
1498 return false; 1485 return false;
1499 *result = ownerElement.textContent(); 1486 *result = ownerElement.textContent();
1500 return true; 1487 return true;
1501 } 1488 }
1502 1489
1503 PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle: :create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, co nst String& id, PassRefPtr<Element> element, Listener* listener) 1490 PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle: :create(const String& id, PassRefPtr<Element> element, Listener* listener)
1504 { 1491 {
1505 return adoptRef(new InspectorStyleSheetForInlineStyle(pageAgent, resourceAge nt, id, element, listener)); 1492 return adoptRef(new InspectorStyleSheetForInlineStyle(id, element, listener) );
1506 } 1493 }
1507 1494
1508 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(InspectorPa geAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, Pas sRefPtr<Element> element, Listener* listener) 1495 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtr<Element> element, Listener* listener)
1509 : InspectorStyleSheet(pageAgent, resourceAgent, id, nullptr, TypeBuilder::CS S::StyleSheetOrigin::Regular, "", listener) 1496 : InspectorStyleSheetBase(id, listener)
1510 , m_element(element) 1497 , m_element(element)
1511 , m_ruleSourceData(nullptr) 1498 , m_ruleSourceData(nullptr)
1512 , m_isStyleTextValid(false) 1499 , m_isStyleTextValid(false)
1513 { 1500 {
1514 ASSERT(m_element); 1501 ASSERT(m_element);
1515 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle (), this); 1502 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle (), this);
1516 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String(); 1503 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String();
1517 } 1504 }
1518 1505
1519 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() 1506 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute()
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 1614
1628 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate(); 1615 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate();
1629 RuleSourceDataList ruleSourceDataResult; 1616 RuleSourceDataList ruleSourceDataResult;
1630 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult); 1617 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult);
1631 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge t(), m_styleText, &handler, m_element->document().elementSheet().contents()); 1618 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge t(), m_styleText, &handler, m_element->document().elementSheet().contents());
1632 return ruleSourceDataResult.first().release(); 1619 return ruleSourceDataResult.first().release();
1633 } 1620 }
1634 1621
1635 } // namespace WebCore 1622 } // namespace WebCore
1636 1623
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