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 30 matching lines...) Expand all Loading... | |
41 #include "core/css/CSSStyleSheet.h" | 41 #include "core/css/CSSStyleSheet.h" |
42 #include "core/css/MediaList.h" | 42 #include "core/css/MediaList.h" |
43 #include "core/css/StylePropertySet.h" | 43 #include "core/css/StylePropertySet.h" |
44 #include "core/css/StyleRule.h" | 44 #include "core/css/StyleRule.h" |
45 #include "core/css/StyleSheet.h" | 45 #include "core/css/StyleSheet.h" |
46 #include "core/css/StyleSheetContents.h" | 46 #include "core/css/StyleSheetContents.h" |
47 #include "core/css/StyleSheetList.h" | 47 #include "core/css/StyleSheetList.h" |
48 #include "core/css/resolver/StyleResolver.h" | 48 #include "core/css/resolver/StyleResolver.h" |
49 #include "core/dom/Node.h" | 49 #include "core/dom/Node.h" |
50 #include "core/dom/NodeList.h" | 50 #include "core/dom/NodeList.h" |
51 #include "core/dom/VisitedLinkState.h" | |
51 #include "core/fetch/CSSStyleSheetResource.h" | 52 #include "core/fetch/CSSStyleSheetResource.h" |
52 #include "core/fetch/ResourceClient.h" | 53 #include "core/fetch/ResourceClient.h" |
53 #include "core/fetch/ResourceFetcher.h" | 54 #include "core/fetch/ResourceFetcher.h" |
54 #include "core/fetch/StyleSheetResourceClient.h" | 55 #include "core/fetch/StyleSheetResourceClient.h" |
55 #include "core/frame/LocalFrame.h" | 56 #include "core/frame/LocalFrame.h" |
56 #include "core/html/HTMLHeadElement.h" | 57 #include "core/html/HTMLHeadElement.h" |
57 #include "core/inspector/InspectorHistory.h" | 58 #include "core/inspector/InspectorHistory.h" |
58 #include "core/inspector/InspectorPageAgent.h" | 59 #include "core/inspector/InspectorPageAgent.h" |
59 #include "core/inspector/InspectorResourceAgent.h" | 60 #include "core/inspector/InspectorResourceAgent.h" |
60 #include "core/inspector/InspectorState.h" | 61 #include "core/inspector/InspectorState.h" |
61 #include "core/inspector/InstrumentingAgents.h" | 62 #include "core/inspector/InstrumentingAgents.h" |
62 #include "core/loader/DocumentLoader.h" | 63 #include "core/loader/DocumentLoader.h" |
63 #include "core/page/Page.h" | 64 #include "core/page/Page.h" |
64 #include "core/rendering/InlineTextBox.h" | 65 #include "core/rendering/InlineTextBox.h" |
65 #include "core/rendering/RenderObject.h" | 66 #include "core/rendering/RenderObject.h" |
66 #include "core/rendering/RenderText.h" | 67 #include "core/rendering/RenderText.h" |
67 #include "core/rendering/RenderTextFragment.h" | 68 #include "core/rendering/RenderTextFragment.h" |
69 #include "core/rendering/style/RenderStyleConstants.h" | |
68 #include "platform/fonts/Font.h" | 70 #include "platform/fonts/Font.h" |
69 #include "platform/fonts/GlyphBuffer.h" | 71 #include "platform/fonts/GlyphBuffer.h" |
70 #include "platform/fonts/WidthIterator.h" | 72 #include "platform/fonts/WidthIterator.h" |
71 #include "platform/text/TextRun.h" | 73 #include "platform/text/TextRun.h" |
72 #include "wtf/CurrentTime.h" | 74 #include "wtf/CurrentTime.h" |
73 #include "wtf/text/CString.h" | 75 #include "wtf/text/CString.h" |
74 #include "wtf/text/StringConcatenate.h" | 76 #include "wtf/text/StringConcatenate.h" |
75 | 77 |
76 namespace CSSAgentState { | 78 namespace CSSAgentState { |
77 static const char cssAgentEnabled[] = "cssAgentEnabled"; | 79 static const char cssAgentEnabled[] = "cssAgentEnabled"; |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 return; | 681 return; |
680 | 682 |
681 // FIXME: It's really gross for the inspector to reach in and access StyleRe solver | 683 // FIXME: It's really gross for the inspector to reach in and access StyleRe solver |
682 // directly here. We need to provide the Inspector better APIs to get this i nformation | 684 // directly here. We need to provide the Inspector better APIs to get this i nformation |
683 // without grabbing at internal style classes! | 685 // without grabbing at internal style classes! |
684 | 686 |
685 // Matched rules. | 687 // Matched rules. |
686 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); | 688 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); |
687 | 689 |
688 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(element, elementPseudoId, StyleResolver::AllCSSRules); | 690 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(element, elementPseudoId, StyleResolver::AllCSSRules); |
689 matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), originalE lement); | 691 matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), originalE lement, true); |
690 | 692 |
691 // Pseudo elements. | 693 // Pseudo elements. |
692 if (!elementPseudoId && (!includePseudo || *includePseudo)) { | 694 if (!elementPseudoId && (!includePseudo || *includePseudo)) { |
693 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoEle ments = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create(); | 695 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoEle ments = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create(); |
694 for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_IN TERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { | 696 for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_IN TERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { |
695 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoC SSRulesForElement(element, pseudoId, StyleResolver::AllCSSRules); | 697 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoC SSRulesForElement(element, pseudoId, StyleResolver::AllCSSRules); |
696 if (matchedRules && matchedRules->length()) { | 698 if (matchedRules && matchedRules->length()) { |
697 RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder: :CSS::PseudoIdMatches::create() | 699 RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder: :CSS::PseudoIdMatches::create() |
698 .setPseudoId(static_cast<int>(pseudoId)) | 700 .setPseudoId(static_cast<int>(pseudoId)) |
699 .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), element)); | 701 .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), element, false)); |
700 pseudoElements->addItem(matches.release()); | 702 pseudoElements->addItem(matches.release()); |
701 } | 703 } |
702 } | 704 } |
703 | 705 |
704 pseudoIdMatches = pseudoElements.release(); | 706 pseudoIdMatches = pseudoElements.release(); |
705 } | 707 } |
706 | 708 |
707 // Inherited styles. | 709 // Inherited styles. |
708 if (!elementPseudoId && (!includeInherited || *includeInherited)) { | 710 if (!elementPseudoId && (!includeInherited || *includeInherited)) { |
709 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entri es = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create(); | 711 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entri es = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create(); |
710 Element* parentElement = element->parentElement(); | 712 Element* parentElement = element->parentElement(); |
711 while (parentElement) { | 713 while (parentElement) { |
712 StyleResolver& parentStyleResolver = parentElement->ownerDocument()- >ensureStyleResolver(); | 714 StyleResolver& parentStyleResolver = parentElement->ownerDocument()- >ensureStyleResolver(); |
713 RefPtrWillBeRawPtr<CSSRuleList> parentMatchedRules = parentStyleReso lver.cssRulesForElement(parentElement, StyleResolver::AllCSSRules); | 715 RefPtrWillBeRawPtr<CSSRuleList> parentMatchedRules = parentStyleReso lver.cssRulesForElement(parentElement, StyleResolver::AllCSSRules); |
714 RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::C SS::InheritedStyleEntry::create() | 716 RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::C SS::InheritedStyleEntry::create() |
715 .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRu les.get(), parentElement)); | 717 .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRu les.get(), parentElement, true)); |
716 if (parentElement->style() && parentElement->style()->length()) { | 718 if (parentElement->style() && parentElement->style()->length()) { |
717 InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyle Sheet(parentElement); | 719 InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyle Sheet(parentElement); |
718 if (styleSheet) | 720 if (styleSheet) |
719 entry->setInlineStyle(styleSheet->buildObjectForStyle(styleS heet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); | 721 entry->setInlineStyle(styleSheet->buildObjectForStyle(styleS heet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); |
720 } | 722 } |
721 | 723 |
722 entries->addItem(entry.release()); | 724 entries->addItem(entry.release()); |
723 parentElement = parentElement->parentElement(); | 725 parentElement = parentElement->parentElement(); |
724 } | 726 } |
725 | 727 |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1287 // According to http://www.w3.org/TR/css3-selectors/#pseudo-elements, "Only one pseudo-element may appear per selector." | 1289 // According to http://www.w3.org/TR/css3-selectors/#pseudo-elements, "Only one pseudo-element may appear per selector." |
1288 // As such, check the last selector in the tag history. | 1290 // As such, check the last selector in the tag history. |
1289 for (; !selector->isLastInTagHistory(); ++selector) { } | 1291 for (; !selector->isLastInTagHistory(); ++selector) { } |
1290 PseudoId selectorPseudoId = selector->matchesPseudoElement() ? CSSSelector:: pseudoId(selector->pseudoType()) : NOPSEUDO; | 1292 PseudoId selectorPseudoId = selector->matchesPseudoElement() ? CSSSelector:: pseudoId(selector->pseudoType()) : NOPSEUDO; |
1291 | 1293 |
1292 // FIXME: This only covers the case of matching pseudo-element selectors aga inst PseudoElements. | 1294 // FIXME: This only covers the case of matching pseudo-element selectors aga inst PseudoElements. |
1293 // We should come up with a solution for matching pseudo-element selectors a gainst ordinary Elements, too. | 1295 // We should come up with a solution for matching pseudo-element selectors a gainst ordinary Elements, too. |
1294 return selectorPseudoId == elementPseudoId; | 1296 return selectorPseudoId == elementPseudoId; |
1295 } | 1297 } |
1296 | 1298 |
1297 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element) | 1299 static inline bool matchesElement(const CSSSelector& selector, Element& element) |
1300 { | |
1301 SelectorChecker selectorChecker(element.document(), SelectorChecker::Queryin gRules); | |
1302 SelectorChecker::SelectorCheckingContext selectorCheckingContext(selector, & element, SelectorChecker::VisitedMatchEnabled); | |
1303 selectorCheckingContext.behaviorAtBoundary = SelectorChecker::StaysWithinTre eScope; | |
1304 selectorCheckingContext.scope = !element.isDocumentNode() ? &element : 0; | |
1305 return selectorChecker.match(selectorCheckingContext, DOMSiblingTraversalStr ategy()) == SelectorChecker::SelectorMatches; | |
1306 } | |
1307 | |
1308 EInsideLink InspectorCSSAgent::linkStateForElement(Element* element) | |
1309 { | |
1310 EInsideLink linkState = NotInsideLink; | |
1311 if (element->isLink()) { | |
1312 VisitedLinkState& visitedLinkState = element->ownerDocument()->visitedLi nkState(); | |
1313 linkState = visitedLinkState.determineLinkState(*element); | |
1314 bool forceVisited = forcePseudoState(element, CSSSelector::PseudoVisited ); | |
1315 if (forceVisited) | |
1316 linkState = InsideVisitedLink; | |
1317 } | |
1318 return linkState; | |
1319 } | |
1320 | |
1321 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element, bool skipR ulesWithoutMatchedSelectors) | |
apavlov
2014/04/08 16:59:51
Blink typically uses enums to clarify boolean argu
| |
1298 { | 1322 { |
1299 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); | 1323 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); |
1300 if (!ruleList) | 1324 if (!ruleList) |
1301 return result.release(); | 1325 return result.release(); |
1302 | 1326 |
1327 EInsideLink linkState = linkStateForElement(element); | |
1303 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { | 1328 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
1304 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); | 1329 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); |
1305 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule); | 1330 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule); |
1306 if (!ruleObject) | 1331 if (!ruleObject) |
1307 continue; | 1332 continue; |
1308 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create(); | 1333 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create(); |
1309 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); | 1334 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
1310 long index = 0; | 1335 long index = 0; |
1311 PseudoId elementPseudoId = element->pseudoId(); | 1336 PseudoId elementPseudoId = element->pseudoId(); |
1337 bool hasMatchingSelectors = false; | |
1312 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) { | 1338 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) { |
1313 const CSSSelector* firstTagHistorySelector = selector; | 1339 const CSSSelector* firstTagHistorySelector = selector; |
1314 bool matched = false; | 1340 bool matchedPseudo = false; |
1315 if (elementPseudoId) | 1341 if (elementPseudoId) |
1316 matched = matchesPseudoElement(selector, elementPseudoId); // Mo difies |selector|. | 1342 matchedPseudo = matchesPseudoElement(selector, elementPseudoId); // Modifies |selector|. |
1317 matched |= element->matches(firstTagHistorySelector->selectorText(), IGNORE_EXCEPTION); | 1343 |
1318 if (matched) | 1344 bool matchedElement = matchesElement(*firstTagHistorySelector, *elem ent); |
1345 if (matchedElement) { | |
1346 unsigned linkMatchType = SelectorChecker::determineLinkMatchType (*firstTagHistorySelector); | |
1347 if (linkState == InsideUnvisitedLink) | |
1348 matchedElement = linkMatchType & SelectorChecker::MatchLink; | |
1349 else if (linkState == InsideVisitedLink) | |
1350 matchedElement = linkMatchType & SelectorChecker::MatchVisit ed; | |
1351 } | |
1352 | |
1353 if (matchedPseudo || matchedElement) { | |
1319 matchingSelectors->addItem(index); | 1354 matchingSelectors->addItem(index); |
1355 hasMatchingSelectors = true; | |
1356 } | |
1320 ++index; | 1357 ++index; |
1321 } | 1358 } |
1359 if (skipRulesWithoutMatchedSelectors && !hasMatchingSelectors) | |
1360 continue; | |
1322 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create() | 1361 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create() |
1323 .setRule(ruleObject.release()) | 1362 .setRule(ruleObject.release()) |
1324 .setMatchingSelectors(matchingSelectors.release()); | 1363 .setMatchingSelectors(matchingSelectors.release()); |
1325 result->addItem(match); | 1364 result->addItem(match); |
1326 } | 1365 } |
1327 | 1366 |
1328 return result; | 1367 return result; |
1329 } | 1368 } |
1330 | 1369 |
1331 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttribut esStyle(Element* element) | 1370 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttribut esStyle(Element* element) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 documentsToChange.add(element->ownerDocument()); | 1445 documentsToChange.add(element->ownerDocument()); |
1407 } | 1446 } |
1408 | 1447 |
1409 m_nodeIdToForcedPseudoState.clear(); | 1448 m_nodeIdToForcedPseudoState.clear(); |
1410 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) | 1449 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) |
1411 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); | 1450 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); |
1412 } | 1451 } |
1413 | 1452 |
1414 } // namespace WebCore | 1453 } // namespace WebCore |
1415 | 1454 |
OLD | NEW |