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