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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 255 } |
256 | 256 |
257 void StyleSheetHandler::ObserveProperty(unsigned start_offset, | 257 void StyleSheetHandler::ObserveProperty(unsigned start_offset, |
258 unsigned end_offset, | 258 unsigned end_offset, |
259 bool is_important, | 259 bool is_important, |
260 bool is_parsed) { | 260 bool is_parsed) { |
261 if (current_rule_data_stack_.IsEmpty() || | 261 if (current_rule_data_stack_.IsEmpty() || |
262 !current_rule_data_stack_.back()->HasProperties()) | 262 !current_rule_data_stack_.back()->HasProperties()) |
263 return; | 263 return; |
264 | 264 |
265 ASSERT(end_offset <= parsed_text_.length()); | 265 DCHECK_LE(end_offset, parsed_text_.length()); |
266 if (end_offset < parsed_text_.length() && | 266 if (end_offset < parsed_text_.length() && |
267 parsed_text_[end_offset] == | 267 parsed_text_[end_offset] == |
268 ';') // Include semicolon into the property text. | 268 ';') // Include semicolon into the property text. |
269 ++end_offset; | 269 ++end_offset; |
270 | 270 |
271 ASSERT(start_offset < end_offset); | 271 DCHECK_LT(start_offset, end_offset); |
272 String property_string = | 272 String property_string = |
273 parsed_text_.Substring(start_offset, end_offset - start_offset) | 273 parsed_text_.Substring(start_offset, end_offset - start_offset) |
274 .StripWhiteSpace(); | 274 .StripWhiteSpace(); |
275 if (property_string.EndsWith(';')) | 275 if (property_string.EndsWith(';')) |
276 property_string = property_string.Left(property_string.length() - 1); | 276 property_string = property_string.Left(property_string.length() - 1); |
277 size_t colon_index = property_string.find(':'); | 277 size_t colon_index = property_string.find(':'); |
278 ASSERT(colon_index != kNotFound); | 278 DCHECK_NE(colon_index, kNotFound); |
279 | 279 |
280 String name = property_string.Left(colon_index).StripWhiteSpace(); | 280 String name = property_string.Left(colon_index).StripWhiteSpace(); |
281 String value = | 281 String value = |
282 property_string.Substring(colon_index + 1, property_string.length()) | 282 property_string.Substring(colon_index + 1, property_string.length()) |
283 .StripWhiteSpace(); | 283 .StripWhiteSpace(); |
284 current_rule_data_stack_.back()->property_data.push_back( | 284 current_rule_data_stack_.back()->property_data.push_back( |
285 CSSPropertySourceData(name, value, is_important, false, is_parsed, | 285 CSSPropertySourceData(name, value, is_important, false, is_parsed, |
286 SourceRange(start_offset, end_offset))); | 286 SourceRange(start_offset, end_offset))); |
287 } | 287 } |
288 | 288 |
289 void StyleSheetHandler::ObserveComment(unsigned start_offset, | 289 void StyleSheetHandler::ObserveComment(unsigned start_offset, |
290 unsigned end_offset) { | 290 unsigned end_offset) { |
291 ASSERT(end_offset <= parsed_text_.length()); | 291 DCHECK_LE(end_offset, parsed_text_.length()); |
292 | 292 |
293 if (current_rule_data_stack_.IsEmpty() || | 293 if (current_rule_data_stack_.IsEmpty() || |
294 !current_rule_data_stack_.back()->rule_header_range.end || | 294 !current_rule_data_stack_.back()->rule_header_range.end || |
295 !current_rule_data_stack_.back()->HasProperties()) | 295 !current_rule_data_stack_.back()->HasProperties()) |
296 return; | 296 return; |
297 | 297 |
298 // The lexer is not inside a property AND it is scanning a declaration-aware | 298 // The lexer is not inside a property AND it is scanning a declaration-aware |
299 // rule body. | 299 // rule body. |
300 String comment_text = | 300 String comment_text = |
301 parsed_text_.Substring(start_offset, end_offset - start_offset); | 301 parsed_text_.Substring(start_offset, end_offset - start_offset); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 753 |
754 return TextForRange(source_data_->rule_body_range, result); | 754 return TextForRange(source_data_->rule_body_range, result); |
755 } | 755 } |
756 | 756 |
757 bool InspectorStyle::TextForRange(const SourceRange& range, String* result) { | 757 bool InspectorStyle::TextForRange(const SourceRange& range, String* result) { |
758 String style_sheet_text; | 758 String style_sheet_text; |
759 bool success = parent_style_sheet_->GetText(&style_sheet_text); | 759 bool success = parent_style_sheet_->GetText(&style_sheet_text); |
760 if (!success) | 760 if (!success) |
761 return false; | 761 return false; |
762 | 762 |
763 ASSERT(0 <= range.start); | 763 DCHECK(0 <= range.start); |
764 ASSERT(range.start <= range.end); | 764 DCHECK_LE(range.start, range.end); |
765 ASSERT(range.end <= style_sheet_text.length()); | 765 DCHECK_LE(range.end, style_sheet_text.length()); |
766 *result = style_sheet_text.Substring(range.start, range.end - range.start); | 766 *result = style_sheet_text.Substring(range.start, range.end - range.start); |
767 return true; | 767 return true; |
768 } | 768 } |
769 | 769 |
770 void InspectorStyle::PopulateAllProperties( | 770 void InspectorStyle::PopulateAllProperties( |
771 Vector<CSSPropertySourceData>& result) { | 771 Vector<CSSPropertySourceData>& result) { |
772 HashSet<String> source_property_names; | 772 HashSet<String> source_property_names; |
773 | 773 |
774 if (source_data_ && source_data_->HasProperties()) { | 774 if (source_data_ && source_data_->HasProperties()) { |
775 Vector<CSSPropertySourceData>& source_property_data = | 775 Vector<CSSPropertySourceData>& source_property_data = |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 if (parent_rule->type() != CSSRule::kMediaRule) { | 1333 if (parent_rule->type() != CSSRule::kMediaRule) { |
1334 exception_state.ThrowDOMException( | 1334 exception_state.ThrowDOMException( |
1335 kNotFoundError, "Cannot remove rule from non-media rule."); | 1335 kNotFoundError, "Cannot remove rule from non-media rule."); |
1336 return false; | 1336 return false; |
1337 } | 1337 } |
1338 CSSMediaRule* parent_media_rule = ToCSSMediaRule(parent_rule); | 1338 CSSMediaRule* parent_media_rule = ToCSSMediaRule(parent_rule); |
1339 size_t index = 0; | 1339 size_t index = 0; |
1340 while (index < parent_media_rule->length() && | 1340 while (index < parent_media_rule->length() && |
1341 parent_media_rule->Item(index) != rule) | 1341 parent_media_rule->Item(index) != rule) |
1342 ++index; | 1342 ++index; |
1343 ASSERT(index < parent_media_rule->length()); | 1343 DCHECK_LT(index, parent_media_rule->length()); |
1344 parent_media_rule->deleteRule(index, exception_state); | 1344 parent_media_rule->deleteRule(index, exception_state); |
1345 } else { | 1345 } else { |
1346 size_t index = 0; | 1346 size_t index = 0; |
1347 while (index < style_sheet->length() && style_sheet->item(index) != rule) | 1347 while (index < style_sheet->length() && style_sheet->item(index) != rule) |
1348 ++index; | 1348 ++index; |
1349 ASSERT(index < style_sheet->length()); | 1349 DCHECK_LT(index, style_sheet->length()); |
1350 style_sheet->deleteRule(index, exception_state); | 1350 style_sheet->deleteRule(index, exception_state); |
1351 } | 1351 } |
1352 // |rule| MAY NOT be addressed after this line! | 1352 // |rule| MAY NOT be addressed after this line! |
1353 | 1353 |
1354 if (exception_state.HadException()) | 1354 if (exception_state.HadException()) |
1355 return false; | 1355 return false; |
1356 | 1356 |
1357 ReplaceText(range, "", nullptr, nullptr); | 1357 ReplaceText(range, "", nullptr, nullptr); |
1358 OnStyleSheetTextChanged(); | 1358 OnStyleSheetTextChanged(); |
1359 return true; | 1359 return true; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 | 1729 |
1730 RemapSourceDataToCSSOMIfNecessary(); | 1730 RemapSourceDataToCSSOMIfNecessary(); |
1731 | 1731 |
1732 size_t index = source_data_->Find(source_data); | 1732 size_t index = source_data_->Find(source_data); |
1733 if (index == kNotFound) | 1733 if (index == kNotFound) |
1734 return nullptr; | 1734 return nullptr; |
1735 IndexMap::iterator it = source_data_to_rule_.find(index); | 1735 IndexMap::iterator it = source_data_to_rule_.find(index); |
1736 if (it == source_data_to_rule_.end()) | 1736 if (it == source_data_to_rule_.end()) |
1737 return nullptr; | 1737 return nullptr; |
1738 | 1738 |
1739 ASSERT(it->value < cssom_flat_rules_.size()); | 1739 DCHECK_LT(it->value, cssom_flat_rules_.size()); |
1740 | 1740 |
1741 // Check that CSSOM did not mutate this rule. | 1741 // Check that CSSOM did not mutate this rule. |
1742 CSSRule* result = cssom_flat_rules_.at(it->value); | 1742 CSSRule* result = cssom_flat_rules_.at(it->value); |
1743 if (CanonicalCSSText(parsed_flat_rules_.at(index)) != | 1743 if (CanonicalCSSText(parsed_flat_rules_.at(index)) != |
1744 CanonicalCSSText(result)) | 1744 CanonicalCSSText(result)) |
1745 return nullptr; | 1745 return nullptr; |
1746 return result; | 1746 return result; |
1747 } | 1747 } |
1748 | 1748 |
1749 CSSRuleSourceData* InspectorStyleSheet::SourceDataForRule(CSSRule* rule) { | 1749 CSSRuleSourceData* InspectorStyleSheet::SourceDataForRule(CSSRule* rule) { |
1750 if (!source_data_ || !rule) | 1750 if (!source_data_ || !rule) |
1751 return nullptr; | 1751 return nullptr; |
1752 | 1752 |
1753 RemapSourceDataToCSSOMIfNecessary(); | 1753 RemapSourceDataToCSSOMIfNecessary(); |
1754 | 1754 |
1755 size_t index = cssom_flat_rules_.Find(rule); | 1755 size_t index = cssom_flat_rules_.Find(rule); |
1756 if (index == kNotFound) | 1756 if (index == kNotFound) |
1757 return nullptr; | 1757 return nullptr; |
1758 IndexMap::iterator it = rule_to_source_data_.find(index); | 1758 IndexMap::iterator it = rule_to_source_data_.find(index); |
1759 if (it == rule_to_source_data_.end()) | 1759 if (it == rule_to_source_data_.end()) |
1760 return nullptr; | 1760 return nullptr; |
1761 | 1761 |
1762 ASSERT(it->value < source_data_->size()); | 1762 DCHECK_LT(it->value, source_data_->size()); |
1763 | 1763 |
1764 // Check that CSSOM did not mutate this rule. | 1764 // Check that CSSOM did not mutate this rule. |
1765 CSSRule* parsed_rule = parsed_flat_rules_.at(it->value); | 1765 CSSRule* parsed_rule = parsed_flat_rules_.at(it->value); |
1766 if (CanonicalCSSText(rule) != CanonicalCSSText(parsed_rule)) | 1766 if (CanonicalCSSText(rule) != CanonicalCSSText(parsed_rule)) |
1767 return nullptr; | 1767 return nullptr; |
1768 return source_data_->at(it->value).Get(); | 1768 return source_data_->at(it->value).Get(); |
1769 } | 1769 } |
1770 | 1770 |
1771 void InspectorStyleSheet::RemapSourceDataToCSSOMIfNecessary() { | 1771 void InspectorStyleSheet::RemapSourceDataToCSSOMIfNecessary() { |
1772 CSSRuleVector cssom_rules; | 1772 CSSRuleVector cssom_rules; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 return element_->getAttribute("style").GetString(); | 1942 return element_->getAttribute("style").GetString(); |
1943 } | 1943 } |
1944 | 1944 |
1945 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) { | 1945 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) { |
1946 visitor->Trace(element_); | 1946 visitor->Trace(element_); |
1947 visitor->Trace(inspector_style_); | 1947 visitor->Trace(inspector_style_); |
1948 InspectorStyleSheetBase::Trace(visitor); | 1948 InspectorStyleSheetBase::Trace(visitor); |
1949 } | 1949 } |
1950 | 1950 |
1951 } // namespace blink | 1951 } // namespace blink |
OLD | NEW |