| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (!commentText.endsWith("*/")) | 282 if (!commentText.endsWith("*/")) |
| 283 return; | 283 return; |
| 284 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS
pace(); | 284 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS
pace(); |
| 285 if (commentText.isEmpty()) | 285 if (commentText.isEmpty()) |
| 286 return; | 286 return; |
| 287 | 287 |
| 288 // FIXME: Use the actual rule type rather than STYLE_RULE? | 288 // FIXME: Use the actual rule type rather than STYLE_RULE? |
| 289 RuleSourceDataList sourceData; | 289 RuleSourceDataList sourceData; |
| 290 | 290 |
| 291 StyleSheetHandler handler(commentText, m_document, &sourceData); | 291 StyleSheetHandler handler(commentText, m_document, &sourceData); |
| 292 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | 292 CSSParser::parseDeclarationListForInspector(parserContextForDocument(m_docum
ent), commentText, handler); |
| 293 CSSParser::parseDeclarationList(parserContextForDocument(m_document), tempMu
tableStyle.get(), commentText, &handler); | |
| 294 WillBeHeapVector<CSSPropertySourceData>& commentPropertyData = sourceData.fi
rst()->styleSourceData->propertyData; | 293 WillBeHeapVector<CSSPropertySourceData>& commentPropertyData = sourceData.fi
rst()->styleSourceData->propertyData; |
| 295 if (commentPropertyData.size() != 1) | 294 if (commentPropertyData.size() != 1) |
| 296 return; | 295 return; |
| 297 CSSPropertySourceData& propertyData = commentPropertyData.at(0); | 296 CSSPropertySourceData& propertyData = commentPropertyData.at(0); |
| 298 if (propertyData.range.length() != commentText.length()) | 297 if (propertyData.range.length() != commentText.length()) |
| 299 return; | 298 return; |
| 300 | 299 |
| 301 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( | 300 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( |
| 302 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset, endOffset))); | 301 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset, endOffset))); |
| 303 } | 302 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 bool ParsedStyleSheet::ensureSourceData() | 399 bool ParsedStyleSheet::ensureSourceData() |
| 401 { | 400 { |
| 402 if (hasSourceData()) | 401 if (hasSourceData()) |
| 403 return true; | 402 return true; |
| 404 | 403 |
| 405 if (!hasText()) | 404 if (!hasText()) |
| 406 return false; | 405 return false; |
| 407 | 406 |
| 408 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS
ourceDataList()); | 407 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS
ourceDataList()); |
| 409 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), result.
get()); | 408 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), result.
get()); |
| 410 CSSParser::parseSheet(parserContextForDocument(m_pageStyleSheet->ownerDocume
nt()), nullptr, text(), &handler); | 409 CSSParser::parseSheetForInspector(parserContextForDocument(m_pageStyleSheet-
>ownerDocument()), text(), handler); |
| 411 setSourceData(result.release()); | 410 setSourceData(result.release()); |
| 412 return hasSourceData(); | 411 return hasSourceData(); |
| 413 } | 412 } |
| 414 | 413 |
| 415 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>
sourceData) | 414 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>
sourceData) |
| 416 { | 415 { |
| 417 if (!sourceData) { | 416 if (!sourceData) { |
| 418 m_sourceData.clear(); | 417 m_sourceData.clear(); |
| 419 return; | 418 return; |
| 420 } | 419 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 .setValue(propertyEntry.value); | 511 .setValue(propertyEntry.value); |
| 513 result->addItem(entry); | 512 result->addItem(entry); |
| 514 } | 513 } |
| 515 | 514 |
| 516 return result.release(); | 515 return result.release(); |
| 517 } | 516 } |
| 518 | 517 |
| 519 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) | 518 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) |
| 520 { | 519 { |
| 521 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 520 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 522 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | |
| 523 RuleSourceDataList sourceData; | 521 RuleSourceDataList sourceData; |
| 524 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; | 522 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; |
| 525 StyleSheetHandler handler(declarationText, ownerDocument(), &sourceData); | 523 StyleSheetHandler handler(declarationText, ownerDocument(), &sourceData); |
| 526 CSSParser::parseDeclarationList(parserContextForDocument(ownerDocument()), t
empMutableStyle.get(), declarationText, &handler); | 524 CSSParser::parseDeclarationListForInspector(parserContextForDocument(ownerDo
cument()), declarationText, handler); |
| 527 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.first()->
styleSourceData->propertyData; | 525 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.first()->
styleSourceData->propertyData; |
| 528 unsigned propertyCount = propertyData.size(); | 526 unsigned propertyCount = propertyData.size(); |
| 529 | 527 |
| 530 // At least one property + the bogus property added just above should be pre
sent. | 528 // At least one property + the bogus property added just above should be pre
sent. |
| 531 if (propertyCount < 2) | 529 if (propertyCount < 2) |
| 532 return false; | 530 return false; |
| 533 | 531 |
| 534 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). | 532 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). |
| 535 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) | 533 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) |
| 536 return false; | 534 return false; |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 } | 1134 } |
| 1137 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r
uleText, exceptionState); | 1135 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r
uleText, exceptionState); |
| 1138 } | 1136 } |
| 1139 | 1137 |
| 1140 bool InspectorStyleSheet::verifyRuleText(const String& ruleText) | 1138 bool InspectorStyleSheet::verifyRuleText(const String& ruleText) |
| 1141 { | 1139 { |
| 1142 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 1140 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 1143 RuleSourceDataList sourceData; | 1141 RuleSourceDataList sourceData; |
| 1144 String text = ruleText + " div { " + bogusPropertyName + ": none; }"; | 1142 String text = ruleText + " div { " + bogusPropertyName + ": none; }"; |
| 1145 StyleSheetHandler handler(text, ownerDocument(), &sourceData); | 1143 StyleSheetHandler handler(text, ownerDocument(), &sourceData); |
| 1146 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), nullptr, te
xt, &handler); | 1144 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()),
text, handler); |
| 1147 unsigned ruleCount = sourceData.size(); | 1145 unsigned ruleCount = sourceData.size(); |
| 1148 | 1146 |
| 1149 // Exactly two rules should be parsed. | 1147 // Exactly two rules should be parsed. |
| 1150 if (ruleCount != 2) | 1148 if (ruleCount != 2) |
| 1151 return false; | 1149 return false; |
| 1152 | 1150 |
| 1153 // Added rule must be style rule. | 1151 // Added rule must be style rule. |
| 1154 if (!sourceData.at(0)->styleSourceData) | 1152 if (!sourceData.at(0)->styleSourceData) |
| 1155 return false; | 1153 return false; |
| 1156 | 1154 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1167 | 1165 |
| 1168 return true; | 1166 return true; |
| 1169 } | 1167 } |
| 1170 | 1168 |
| 1171 bool InspectorStyleSheet::verifySelectorText(const String& selectorText) | 1169 bool InspectorStyleSheet::verifySelectorText(const String& selectorText) |
| 1172 { | 1170 { |
| 1173 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 1171 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 1174 RuleSourceDataList sourceData; | 1172 RuleSourceDataList sourceData; |
| 1175 String text = selectorText + " { " + bogusPropertyName + ": none; }"; | 1173 String text = selectorText + " { " + bogusPropertyName + ": none; }"; |
| 1176 StyleSheetHandler handler(text, ownerDocument(), &sourceData); | 1174 StyleSheetHandler handler(text, ownerDocument(), &sourceData); |
| 1177 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), nullptr, te
xt, &handler); | 1175 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()),
text, handler); |
| 1178 | 1176 |
| 1179 // Exactly one rule should be parsed. | 1177 // Exactly one rule should be parsed. |
| 1180 unsigned ruleCount = sourceData.size(); | 1178 unsigned ruleCount = sourceData.size(); |
| 1181 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style) | 1179 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style) |
| 1182 return false; | 1180 return false; |
| 1183 | 1181 |
| 1184 // Exactly one property should be in style rule. | 1182 // Exactly one property should be in style rule. |
| 1185 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; | 1183 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; |
| 1186 unsigned propertyCount = propertyData.size(); | 1184 unsigned propertyCount = propertyData.size(); |
| 1187 if (propertyCount != 1) | 1185 if (propertyCount != 1) |
| 1188 return false; | 1186 return false; |
| 1189 | 1187 |
| 1190 // Check for the property name. | 1188 // Check for the property name. |
| 1191 if (propertyData.at(0).name != bogusPropertyName) | 1189 if (propertyData.at(0).name != bogusPropertyName) |
| 1192 return false; | 1190 return false; |
| 1193 | 1191 |
| 1194 return true; | 1192 return true; |
| 1195 } | 1193 } |
| 1196 | 1194 |
| 1197 bool InspectorStyleSheet::verifyMediaText(const String& mediaText) | 1195 bool InspectorStyleSheet::verifyMediaText(const String& mediaText) |
| 1198 { | 1196 { |
| 1199 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 1197 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 1200 RuleSourceDataList sourceData; | 1198 RuleSourceDataList sourceData; |
| 1201 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; | 1199 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; |
| 1202 StyleSheetHandler handler(text, ownerDocument(), &sourceData); | 1200 StyleSheetHandler handler(text, ownerDocument(), &sourceData); |
| 1203 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), nullptr, te
xt, &handler); | 1201 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()),
text, handler); |
| 1204 | 1202 |
| 1205 // Exactly one media rule should be parsed. | 1203 // Exactly one media rule should be parsed. |
| 1206 unsigned ruleCount = sourceData.size(); | 1204 unsigned ruleCount = sourceData.size(); |
| 1207 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media) | 1205 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media) |
| 1208 return false; | 1206 return false; |
| 1209 | 1207 |
| 1210 // Media rule should have exactly one style rule child. | 1208 // Media rule should have exactly one style rule child. |
| 1211 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; | 1209 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; |
| 1212 ruleCount = childSourceData.size(); | 1210 ruleCount = childSourceData.size(); |
| 1213 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) | 1211 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 | 1918 |
| 1921 if (m_styleText.isEmpty()) { | 1919 if (m_styleText.isEmpty()) { |
| 1922 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create
(StyleRule::Style); | 1920 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create
(StyleRule::Style); |
| 1923 result->ruleBodyRange.start = 0; | 1921 result->ruleBodyRange.start = 0; |
| 1924 result->ruleBodyRange.end = 0; | 1922 result->ruleBodyRange.end = 0; |
| 1925 return result.release(); | 1923 return result.release(); |
| 1926 } | 1924 } |
| 1927 | 1925 |
| 1928 RuleSourceDataList ruleSourceDataResult; | 1926 RuleSourceDataList ruleSourceDataResult; |
| 1929 StyleSheetHandler handler(m_styleText, &m_element->document(), &ruleSourceDa
taResult); | 1927 StyleSheetHandler handler(m_styleText, &m_element->document(), &ruleSourceDa
taResult); |
| 1930 CSSParser::parseDeclarationList(parserContextForDocument(&m_element->documen
t()), nullptr, m_styleText, &handler); | 1928 CSSParser::parseDeclarationListForInspector(parserContextForDocument(&m_elem
ent->document()), m_styleText, handler); |
| 1931 return ruleSourceDataResult.first().release(); | 1929 return ruleSourceDataResult.first().release(); |
| 1932 } | 1930 } |
| 1933 | 1931 |
| 1934 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1932 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1935 { | 1933 { |
| 1936 visitor->trace(m_element); | 1934 visitor->trace(m_element); |
| 1937 visitor->trace(m_ruleSourceData); | 1935 visitor->trace(m_ruleSourceData); |
| 1938 visitor->trace(m_inspectorStyle); | 1936 visitor->trace(m_inspectorStyle); |
| 1939 InspectorStyleSheetBase::trace(visitor); | 1937 InspectorStyleSheetBase::trace(visitor); |
| 1940 } | 1938 } |
| 1941 | 1939 |
| 1942 } // namespace blink | 1940 } // namespace blink |
| OLD | NEW |