Chromium Code Reviews| 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 return; | 676 return; |
| 677 | 677 |
| 678 // FIXME: It's really gross for the inspector to reach in and access StyleRe solver | 678 // FIXME: It's really gross for the inspector to reach in and access StyleRe solver |
| 679 // directly here. We need to provide the Inspector better APIs to get this i nformation | 679 // directly here. We need to provide the Inspector better APIs to get this i nformation |
| 680 // without grabbing at internal style classes! | 680 // without grabbing at internal style classes! |
| 681 | 681 |
| 682 // Matched rules. | 682 // Matched rules. |
| 683 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); | 683 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); |
| 684 | 684 |
| 685 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(element, elementPseudoId, StyleResolver::AllCSSRules); | 685 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(element, elementPseudoId, StyleResolver::AllCSSRules); |
| 686 matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), originalE lement); | 686 matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), originalE lement, NOPSEUDO); |
| 687 | 687 |
| 688 // Pseudo elements. | 688 // Pseudo elements. |
| 689 if (!elementPseudoId && !asBool(excludePseudo)) { | 689 if (!elementPseudoId && !asBool(excludePseudo)) { |
| 690 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoEle ments = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create(); | 690 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoEle ments = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create(); |
| 691 for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_IN TERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { | 691 for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_IN TERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { |
| 692 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoC SSRulesForElement(element, pseudoId, StyleResolver::AllCSSRules); | 692 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoC SSRulesForElement(element, pseudoId, StyleResolver::AllCSSRules); |
| 693 if (matchedRules && matchedRules->length()) { | 693 if (matchedRules && matchedRules->length()) { |
| 694 RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder: :CSS::PseudoIdMatches::create() | 694 RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder: :CSS::PseudoIdMatches::create() |
| 695 .setPseudoId(static_cast<int>(pseudoId)) | 695 .setPseudoId(static_cast<int>(pseudoId)) |
| 696 .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), element)); | 696 .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), element, pseudoId)); |
| 697 pseudoElements->addItem(matches.release()); | 697 pseudoElements->addItem(matches.release()); |
| 698 } | 698 } |
| 699 } | 699 } |
| 700 | 700 |
| 701 pseudoIdMatches = pseudoElements.release(); | 701 pseudoIdMatches = pseudoElements.release(); |
| 702 } | 702 } |
| 703 | 703 |
| 704 // Inherited styles. | 704 // Inherited styles. |
| 705 if (!elementPseudoId && !asBool(excludeInherited)) { | 705 if (!elementPseudoId && !asBool(excludeInherited)) { |
| 706 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entri es = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create(); | 706 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entri es = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create(); |
| 707 Element* parentElement = element->parentElement(); | 707 Element* parentElement = element->parentElement(); |
| 708 while (parentElement) { | 708 while (parentElement) { |
| 709 StyleResolver& parentStyleResolver = parentElement->ownerDocument()- >ensureStyleResolver(); | 709 StyleResolver& parentStyleResolver = parentElement->ownerDocument()- >ensureStyleResolver(); |
| 710 RefPtrWillBeRawPtr<CSSRuleList> parentMatchedRules = parentStyleReso lver.cssRulesForElement(parentElement, StyleResolver::AllCSSRules); | 710 RefPtrWillBeRawPtr<CSSRuleList> parentMatchedRules = parentStyleReso lver.cssRulesForElement(parentElement, StyleResolver::AllCSSRules); |
| 711 RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::C SS::InheritedStyleEntry::create() | 711 RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::C SS::InheritedStyleEntry::create() |
| 712 .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRu les.get(), parentElement)); | 712 .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRu les.get(), parentElement, NOPSEUDO)); |
| 713 if (parentElement->style() && parentElement->style()->length()) { | 713 if (parentElement->style() && parentElement->style()->length()) { |
| 714 InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyle Sheet(parentElement); | 714 InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyle Sheet(parentElement); |
| 715 if (styleSheet) | 715 if (styleSheet) |
| 716 entry->setInlineStyle(styleSheet->buildObjectForStyle(styleS heet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); | 716 entry->setInlineStyle(styleSheet->buildObjectForStyle(styleS heet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); |
| 717 } | 717 } |
| 718 | 718 |
| 719 entries->addItem(entry.release()); | 719 entries->addItem(entry.release()); |
| 720 parentElement = parentElement->parentElement(); | 720 parentElement = parentElement->parentElement(); |
| 721 } | 721 } |
| 722 | 722 |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 // According to http://www.w3.org/TR/css3-selectors/#pseudo-elements, "Only one pseudo-element may appear per selector." | 1339 // According to http://www.w3.org/TR/css3-selectors/#pseudo-elements, "Only one pseudo-element may appear per selector." |
| 1340 // As such, check the last selector in the tag history. | 1340 // As such, check the last selector in the tag history. |
| 1341 for (; !selector->isLastInTagHistory(); ++selector) { } | 1341 for (; !selector->isLastInTagHistory(); ++selector) { } |
| 1342 PseudoId selectorPseudoId = selector->matchesPseudoElement() ? CSSSelector:: pseudoId(selector->pseudoType()) : NOPSEUDO; | 1342 PseudoId selectorPseudoId = selector->matchesPseudoElement() ? CSSSelector:: pseudoId(selector->pseudoType()) : NOPSEUDO; |
| 1343 | 1343 |
| 1344 // FIXME: This only covers the case of matching pseudo-element selectors aga inst PseudoElements. | 1344 // FIXME: This only covers the case of matching pseudo-element selectors aga inst PseudoElements. |
| 1345 // We should come up with a solution for matching pseudo-element selectors a gainst ordinary Elements, too. | 1345 // We should come up with a solution for matching pseudo-element selectors a gainst ordinary Elements, too. |
| 1346 return selectorPseudoId == elementPseudoId; | 1346 return selectorPseudoId == elementPseudoId; |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element) | 1349 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element, PseudoId m atchesForPseudoId) |
| 1350 { | 1350 { |
| 1351 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); | 1351 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); |
| 1352 if (!ruleList) | 1352 if (!ruleList) |
| 1353 return result.release(); | 1353 return result.release(); |
| 1354 | 1354 |
| 1355 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { | 1355 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
| 1356 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); | 1356 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); |
| 1357 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule); | 1357 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule); |
| 1358 if (!ruleObject) | 1358 if (!ruleObject) |
| 1359 continue; | 1359 continue; |
| 1360 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create(); | 1360 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create(); |
| 1361 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); | 1361 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| 1362 long index = 0; | 1362 long index = 0; |
| 1363 PseudoId elementPseudoId = element->pseudoId(); | 1363 PseudoId elementPseudoId = matchesForPseudoId != NOPSEUDO ? matchesForPs eudoId : element->pseudoId(); |
| 1364 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) { | 1364 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) { |
| 1365 const CSSSelector* firstTagHistorySelector = selector; | 1365 const CSSSelector* firstTagHistorySelector = selector; |
| 1366 bool matched = false; | 1366 bool matched = false; |
| 1367 if (elementPseudoId) | 1367 if (elementPseudoId) |
|
vsevik
2014/11/05 07:09:26
Why do we do elementPseudoId != NOPSEUDO above?
L
lushnikov
2014/11/05 07:41:13
Done.
| |
| 1368 matched = matchesPseudoElement(selector, elementPseudoId); // Mo difies |selector|. | 1368 matched = matchesPseudoElement(selector, elementPseudoId); // Mo difies |selector|. |
| 1369 matched |= element->matches(firstTagHistorySelector->selectorText(), IGNORE_EXCEPTION); | 1369 else |
| 1370 matched |= element->matches(firstTagHistorySelector->selectorTex t(), IGNORE_EXCEPTION); | |
|
vsevik
2014/11/05 07:09:26
|= -> =
lushnikov
2014/11/05 07:41:13
Done.
| |
| 1370 if (matched) | 1371 if (matched) |
| 1371 matchingSelectors->addItem(index); | 1372 matchingSelectors->addItem(index); |
| 1372 ++index; | 1373 ++index; |
| 1373 } | 1374 } |
| 1374 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create() | 1375 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create() |
| 1375 .setRule(ruleObject.release()) | 1376 .setRule(ruleObject.release()) |
| 1376 .setMatchingSelectors(matchingSelectors.release()); | 1377 .setMatchingSelectors(matchingSelectors.release()); |
| 1377 result->addItem(match); | 1378 result->addItem(match); |
| 1378 } | 1379 } |
| 1379 | 1380 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 visitor->trace(m_invalidatedDocuments); | 1477 visitor->trace(m_invalidatedDocuments); |
| 1477 visitor->trace(m_nodeToInspectorStyleSheet); | 1478 visitor->trace(m_nodeToInspectorStyleSheet); |
| 1478 visitor->trace(m_documentToViaInspectorStyleSheet); | 1479 visitor->trace(m_documentToViaInspectorStyleSheet); |
| 1479 #endif | 1480 #endif |
| 1480 visitor->trace(m_inspectorUserAgentStyleSheet); | 1481 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 1481 InspectorBaseAgent::trace(visitor); | 1482 InspectorBaseAgent::trace(visitor); |
| 1482 } | 1483 } |
| 1483 | 1484 |
| 1484 } // namespace blink | 1485 } // namespace blink |
| 1485 | 1486 |
| OLD | NEW |