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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 , m_commentParser(parserContextForDocument(document)) | 78 , m_commentParser(parserContextForDocument(document)) |
79 , m_propertyRangeStart(UINT_MAX) | 79 , m_propertyRangeStart(UINT_MAX) |
80 , m_selectorRangeStart(UINT_MAX) | 80 , m_selectorRangeStart(UINT_MAX) |
81 , m_commentRangeStart(UINT_MAX) | 81 , m_commentRangeStart(UINT_MAX) |
82 , m_mediaQueryExpValueRangeStart(UINT_MAX) | 82 , m_mediaQueryExpValueRangeStart(UINT_MAX) |
83 { | 83 { |
84 ASSERT(m_result); | 84 ASSERT(m_result); |
85 } | 85 } |
86 | 86 |
87 private: | 87 private: |
88 virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned) override; | 88 virtual void startRuleHeader(StyleRule::Type, unsigned) override; |
89 virtual void endRuleHeader(unsigned) override; | 89 virtual void endRuleHeader(unsigned) override; |
90 virtual void startSelector(unsigned) override; | 90 virtual void startSelector(unsigned) override; |
91 virtual void endSelector(unsigned) override; | 91 virtual void endSelector(unsigned) override; |
92 virtual void startRuleBody(unsigned) override; | 92 virtual void startRuleBody(unsigned) override; |
93 virtual void endRuleBody(unsigned, bool) override; | 93 virtual void endRuleBody(unsigned, bool) override; |
94 virtual void startProperty(unsigned) override; | 94 virtual void startProperty(unsigned) override; |
95 virtual void endProperty(bool, bool, unsigned, CSSParserError) override; | 95 virtual void endProperty(bool, bool, unsigned, CSSParserError) override; |
96 virtual void startComment(unsigned) override; | 96 virtual void startComment(unsigned) override; |
97 virtual void endComment(unsigned) override; | 97 virtual void endComment(unsigned) override; |
98 virtual void startMediaQueryExp(unsigned offset) override; | 98 virtual void startMediaQueryExp(unsigned offset) override; |
(...skipping 13 matching lines...) Expand all Loading... |
112 RuleSourceDataList m_currentRuleDataStack; | 112 RuleSourceDataList m_currentRuleDataStack; |
113 RefPtrWillBeMember<CSSRuleSourceData> m_currentRuleData; | 113 RefPtrWillBeMember<CSSRuleSourceData> m_currentRuleData; |
114 CSSParser m_commentParser; | 114 CSSParser m_commentParser; |
115 unsigned m_propertyRangeStart; | 115 unsigned m_propertyRangeStart; |
116 unsigned m_selectorRangeStart; | 116 unsigned m_selectorRangeStart; |
117 unsigned m_commentRangeStart; | 117 unsigned m_commentRangeStart; |
118 RefPtrWillBeMember<CSSMediaQuerySourceData> m_currentMediaQueryData; | 118 RefPtrWillBeMember<CSSMediaQuerySourceData> m_currentMediaQueryData; |
119 unsigned m_mediaQueryExpValueRangeStart; | 119 unsigned m_mediaQueryExpValueRangeStart; |
120 }; | 120 }; |
121 | 121 |
122 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o
ffset) | 122 void StyleSheetHandler::startRuleHeader(StyleRule::Type type, unsigned offset) |
123 { | 123 { |
124 // Pop off data for a previous invalid rule. | 124 // Pop off data for a previous invalid rule. |
125 if (m_currentRuleData) | 125 if (m_currentRuleData) |
126 m_currentRuleDataStack.removeLast(); | 126 m_currentRuleDataStack.removeLast(); |
127 | 127 |
128 RefPtrWillBeRawPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(type)
; | 128 RefPtrWillBeRawPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(type)
; |
129 data->ruleHeaderRange.start = offset; | 129 data->ruleHeaderRange.start = offset; |
130 m_currentRuleData = data; | 130 m_currentRuleData = data; |
131 m_currentRuleDataStack.append(data.release()); | 131 m_currentRuleDataStack.append(data.release()); |
132 } | 132 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 setSourceData(nullptr); | 424 setSourceData(nullptr); |
425 } | 425 } |
426 | 426 |
427 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) | 427 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) |
428 { | 428 { |
429 for (size_t i = 0; i < dataList->size(); ++i) { | 429 for (size_t i = 0; i < dataList->size(); ++i) { |
430 RefPtrWillBeMember<CSSRuleSourceData>& data = dataList->at(i); | 430 RefPtrWillBeMember<CSSRuleSourceData>& data = dataList->at(i); |
431 | 431 |
432 // The m_sourceData->append()'ed types should be exactly the same as in
collectFlatRules(). | 432 // The m_sourceData->append()'ed types should be exactly the same as in
collectFlatRules(). |
433 switch (data->type) { | 433 switch (data->type) { |
434 case CSSRuleSourceData::STYLE_RULE: | 434 case StyleRule::Style: |
435 case CSSRuleSourceData::IMPORT_RULE: | 435 case StyleRule::Import: |
436 case CSSRuleSourceData::CHARSET_RULE: | 436 case StyleRule::Page: |
437 case CSSRuleSourceData::PAGE_RULE: | 437 case StyleRule::FontFace: |
438 case CSSRuleSourceData::FONT_FACE_RULE: | 438 case StyleRule::Viewport: |
439 case CSSRuleSourceData::VIEWPORT_RULE: | 439 case StyleRule::Keyframes: |
440 case CSSRuleSourceData::KEYFRAMES_RULE: | |
441 m_sourceData->append(data); | 440 m_sourceData->append(data); |
442 break; | 441 break; |
443 case CSSRuleSourceData::MEDIA_RULE: | 442 case StyleRule::Media: |
444 case CSSRuleSourceData::SUPPORTS_RULE: | 443 case StyleRule::Supports: |
445 m_sourceData->append(data); | 444 m_sourceData->append(data); |
446 flattenSourceData(&data->childRules); | 445 flattenSourceData(&data->childRules); |
447 break; | 446 break; |
| 447 case StyleRule::Unknown: |
448 default: | 448 default: |
449 break; | 449 break; |
450 } | 450 } |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 bool ParsedStyleSheet::ensureSourceData() | 454 bool ParsedStyleSheet::ensureSourceData() |
455 { | 455 { |
456 if (hasSourceData()) | 456 if (hasSourceData()) |
457 return true; | 457 return true; |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 { | 1229 { |
1230 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 1230 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
1231 RuleSourceDataList sourceData; | 1231 RuleSourceDataList sourceData; |
1232 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); | 1232 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); |
1233 String text = selectorText + " { " + bogusPropertyName + ": none; }"; | 1233 String text = selectorText + " { " + bogusPropertyName + ": none; }"; |
1234 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), &
sourceData); | 1234 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), &
sourceData); |
1235 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), styleSheetC
ontents.get(), text, TextPosition::minimumPosition(), &handler); | 1235 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), styleSheetC
ontents.get(), text, TextPosition::minimumPosition(), &handler); |
1236 | 1236 |
1237 // Exactly one rule should be parsed. | 1237 // Exactly one rule should be parsed. |
1238 unsigned ruleCount = sourceData.size(); | 1238 unsigned ruleCount = sourceData.size(); |
1239 if (ruleCount != 1 || sourceData.at(0)->type != CSSRuleSourceData::STYLE_RUL
E) | 1239 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style) |
1240 return false; | 1240 return false; |
1241 | 1241 |
1242 // Exactly one property should be in style rule. | 1242 // Exactly one property should be in style rule. |
1243 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; | 1243 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; |
1244 unsigned propertyCount = propertyData.size(); | 1244 unsigned propertyCount = propertyData.size(); |
1245 if (propertyCount != 1) | 1245 if (propertyCount != 1) |
1246 return false; | 1246 return false; |
1247 | 1247 |
1248 // Check for the property name. | 1248 // Check for the property name. |
1249 if (propertyData.at(0).name != bogusPropertyName) | 1249 if (propertyData.at(0).name != bogusPropertyName) |
1250 return false; | 1250 return false; |
1251 | 1251 |
1252 return true; | 1252 return true; |
1253 } | 1253 } |
1254 | 1254 |
1255 bool InspectorStyleSheet::verifyMediaText(const String& mediaText) | 1255 bool InspectorStyleSheet::verifyMediaText(const String& mediaText) |
1256 { | 1256 { |
1257 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 1257 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
1258 RuleSourceDataList sourceData; | 1258 RuleSourceDataList sourceData; |
1259 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); | 1259 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); |
1260 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; | 1260 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; |
1261 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), &
sourceData); | 1261 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), &
sourceData); |
1262 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), styleSheetC
ontents.get(), text, TextPosition::minimumPosition(), &handler); | 1262 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), styleSheetC
ontents.get(), text, TextPosition::minimumPosition(), &handler); |
1263 | 1263 |
1264 // Exactly one media rule should be parsed. | 1264 // Exactly one media rule should be parsed. |
1265 unsigned ruleCount = sourceData.size(); | 1265 unsigned ruleCount = sourceData.size(); |
1266 if (ruleCount != 1 || sourceData.at(0)->type != CSSRuleSourceData::MEDIA_RUL
E) | 1266 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media) |
1267 return false; | 1267 return false; |
1268 | 1268 |
1269 // Media rule should have exactly one style rule child. | 1269 // Media rule should have exactly one style rule child. |
1270 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; | 1270 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; |
1271 ruleCount = childSourceData.size(); | 1271 ruleCount = childSourceData.size(); |
1272 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) | 1272 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) |
1273 return false; | 1273 return false; |
1274 | 1274 |
1275 // Exactly one property should be in style rule. | 1275 // Exactly one property should be in style rule. |
1276 WillBeHeapVector<CSSPropertySourceData>& propertyData = childSourceData.at(0
)->styleSourceData->propertyData; | 1276 WillBeHeapVector<CSSPropertySourceData>& propertyData = childSourceData.at(0
)->styleSourceData->propertyData; |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 m_isStyleTextValid = true; | 1938 m_isStyleTextValid = true; |
1939 } | 1939 } |
1940 | 1940 |
1941 if (m_ruleSourceData) | 1941 if (m_ruleSourceData) |
1942 return true; | 1942 return true; |
1943 | 1943 |
1944 m_ruleSourceData = getStyleAttributeData(); | 1944 m_ruleSourceData = getStyleAttributeData(); |
1945 | 1945 |
1946 bool success = !!m_ruleSourceData; | 1946 bool success = !!m_ruleSourceData; |
1947 if (!success) { | 1947 if (!success) { |
1948 m_ruleSourceData = CSSRuleSourceData::create(CSSRuleSourceData::STYLE_RU
LE); | 1948 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); |
1949 return false; | 1949 return false; |
1950 } | 1950 } |
1951 | 1951 |
1952 return true; | 1952 return true; |
1953 } | 1953 } |
1954 | 1954 |
1955 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec
torStyleForId(const InspectorCSSId& id) | 1955 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec
torStyleForId(const InspectorCSSId& id) |
1956 { | 1956 { |
1957 ASSERT_UNUSED(id, !id.ordinal()); | 1957 ASSERT_UNUSED(id, !id.ordinal()); |
1958 return m_inspectorStyle; | 1958 return m_inspectorStyle; |
1959 } | 1959 } |
1960 | 1960 |
1961 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const | 1961 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const |
1962 { | 1962 { |
1963 return m_element->style(); | 1963 return m_element->style(); |
1964 } | 1964 } |
1965 | 1965 |
1966 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const | 1966 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const |
1967 { | 1967 { |
1968 return m_element->getAttribute("style").string(); | 1968 return m_element->getAttribute("style").string(); |
1969 } | 1969 } |
1970 | 1970 |
1971 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::get
StyleAttributeData() const | 1971 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::get
StyleAttributeData() const |
1972 { | 1972 { |
1973 if (!m_element->isStyledElement()) | 1973 if (!m_element->isStyledElement()) |
1974 return nullptr; | 1974 return nullptr; |
1975 | 1975 |
1976 if (m_styleText.isEmpty()) { | 1976 if (m_styleText.isEmpty()) { |
1977 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create
(CSSRuleSourceData::STYLE_RULE); | 1977 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create
(StyleRule::Style); |
1978 result->ruleBodyRange.start = 0; | 1978 result->ruleBodyRange.start = 0; |
1979 result->ruleBodyRange.end = 0; | 1979 result->ruleBodyRange.end = 0; |
1980 return result.release(); | 1980 return result.release(); |
1981 } | 1981 } |
1982 | 1982 |
1983 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); | 1983 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); |
1984 RuleSourceDataList ruleSourceDataResult; | 1984 RuleSourceDataList ruleSourceDataResult; |
1985 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); | 1985 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); |
1986 CSSParser(parserContextForDocument(&m_element->document())).parseDeclaration
(tempDeclaration.get(), m_styleText, &handler, m_element->document().elementShee
t().contents()); | 1986 CSSParser(parserContextForDocument(&m_element->document())).parseDeclaration
(tempDeclaration.get(), m_styleText, &handler, m_element->document().elementShee
t().contents()); |
1987 return ruleSourceDataResult.first().release(); | 1987 return ruleSourceDataResult.first().release(); |
1988 } | 1988 } |
1989 | 1989 |
1990 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1990 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
1991 { | 1991 { |
1992 visitor->trace(m_element); | 1992 visitor->trace(m_element); |
1993 visitor->trace(m_ruleSourceData); | 1993 visitor->trace(m_ruleSourceData); |
1994 visitor->trace(m_inspectorStyle); | 1994 visitor->trace(m_inspectorStyle); |
1995 InspectorStyleSheetBase::trace(visitor); | 1995 InspectorStyleSheetBase::trace(visitor); |
1996 } | 1996 } |
1997 | 1997 |
1998 } // namespace blink | 1998 } // namespace blink |
OLD | NEW |