Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 228673002: DevTools: matched styles respect :visited/:link pseudo classes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
1297 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element) 1308 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element)
1298 { 1309 {
1299 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); 1310 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create();
1300 if (!ruleList) 1311 if (!ruleList)
1301 return result.release(); 1312 return result.release();
1302 1313
1314 EInsideLink linkState = NotInsideLink;
apavlov 2014/04/08 14:19:46 please extract
lushnikov 2014/04/08 15:28:32 Done.
1315 if (element->isLink()) {
1316 VisitedLinkState& visitedLinkState = element->ownerDocument()->visitedLi nkState();
1317 linkState = visitedLinkState.determineLinkState(*element);
1318 bool forceVisited = forcePseudoState(element, CSSSelector::PseudoVisited );
1319 if (forceVisited)
1320 linkState = InsideVisitedLink;
1321 }
1322
1303 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { 1323 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
1304 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); 1324 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
1305 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule); 1325 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule);
1306 if (!ruleObject) 1326 if (!ruleObject)
1307 continue; 1327 continue;
1308 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create(); 1328 RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array< int>::create();
1309 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); 1329 const CSSSelectorList& selectorList = rule->styleRule()->selectorList();
1310 long index = 0; 1330 long index = 0;
1311 PseudoId elementPseudoId = element->pseudoId(); 1331 PseudoId elementPseudoId = element->pseudoId();
1332 bool hasMatchingSelectors = false;
1312 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) { 1333 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) {
1313 const CSSSelector* firstTagHistorySelector = selector; 1334 const CSSSelector* firstTagHistorySelector = selector;
1314 bool matched = false; 1335 bool matchedPseudo = false;
1315 if (elementPseudoId) 1336 if (elementPseudoId)
1316 matched = matchesPseudoElement(selector, elementPseudoId); // Mo difies |selector|. 1337 matchedPseudo = matchesPseudoElement(selector, elementPseudoId); // Modifies |selector|.
1317 matched |= element->matches(firstTagHistorySelector->selectorText(), IGNORE_EXCEPTION); 1338 bool matchedElement = matchesElement(*firstTagHistorySelector, *elem ent);
1318 if (matched) 1339 unsigned linkMatchType = SelectorChecker::determineLinkMatchType(*fi rstTagHistorySelector);
apavlov 2014/04/08 14:19:46 This is not necessary if !matchedElement
lushnikov 2014/04/08 15:28:32 Done.
1340 if (matchedElement && linkState == InsideUnvisitedLink)
1341 matchedElement = linkMatchType & SelectorChecker::MatchLink;
1342 else if (matchedElement && linkState == InsideVisitedLink)
1343 matchedElement = linkMatchType & SelectorChecker::MatchVisited;
1344
1345 if (matchedPseudo || matchedElement) {
1319 matchingSelectors->addItem(index); 1346 matchingSelectors->addItem(index);
1347 hasMatchingSelectors = true;
1348 }
1320 ++index; 1349 ++index;
1321 } 1350 }
1351 if (!hasMatchingSelectors)
1352 continue;
1322 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create() 1353 RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch: :create()
1323 .setRule(ruleObject.release()) 1354 .setRule(ruleObject.release())
1324 .setMatchingSelectors(matchingSelectors.release()); 1355 .setMatchingSelectors(matchingSelectors.release());
1325 result->addItem(match); 1356 result->addItem(match);
1326 } 1357 }
1327 1358
1328 return result; 1359 return result;
1329 } 1360 }
1330 1361
1331 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttribut esStyle(Element* element) 1362 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttribut esStyle(Element* element)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 documentsToChange.add(element->ownerDocument()); 1437 documentsToChange.add(element->ownerDocument());
1407 } 1438 }
1408 1439
1409 m_nodeIdToForcedPseudoState.clear(); 1440 m_nodeIdToForcedPseudoState.clear();
1410 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1441 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1411 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1442 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1412 } 1443 }
1413 1444
1414 } // namespace WebCore 1445 } // namespace WebCore
1415 1446
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698