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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index d79f534115c5a40cb6856c9071ec9fba204f4891..b64cd4b5c744d74aae5dc6b60938d74f26b1f7fe 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -48,6 +48,7 @@
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/Node.h"
#include "core/dom/NodeList.h"
+#include "core/dom/VisitedLinkState.h"
#include "core/fetch/CSSStyleSheetResource.h"
#include "core/fetch/ResourceClient.h"
#include "core/fetch/ResourceFetcher.h"
@@ -65,6 +66,7 @@
#include "core/rendering/RenderObject.h"
#include "core/rendering/RenderText.h"
#include "core/rendering/RenderTextFragment.h"
+#include "core/rendering/style/RenderStyleConstants.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/GlyphBuffer.h"
#include "platform/fonts/WidthIterator.h"
@@ -1294,12 +1296,30 @@ static inline bool matchesPseudoElement(const CSSSelector* selector, PseudoId el
return selectorPseudoId == elementPseudoId;
}
+static inline bool matchesElement(const CSSSelector& selector, Element& element)
+{
+ SelectorChecker selectorChecker(element.document(), SelectorChecker::QueryingRules);
+ SelectorChecker::SelectorCheckingContext selectorCheckingContext(selector, &element, SelectorChecker::VisitedMatchEnabled);
+ selectorCheckingContext.behaviorAtBoundary = SelectorChecker::StaysWithinTreeScope;
+ selectorCheckingContext.scope = !element.isDocumentNode() ? &element : 0;
+ return selectorChecker.match(selectorCheckingContext, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches;
+}
+
PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::buildArrayForMatchedRuleList(CSSRuleList* ruleList, Element* element)
{
RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilder::Array<TypeBuilder::CSS::RuleMatch>::create();
if (!ruleList)
return result.release();
+ EInsideLink linkState = NotInsideLink;
apavlov 2014/04/08 14:19:46 please extract
lushnikov 2014/04/08 15:28:32 Done.
+ if (element->isLink()) {
+ VisitedLinkState& visitedLinkState = element->ownerDocument()->visitedLinkState();
+ linkState = visitedLinkState.determineLinkState(*element);
+ bool forceVisited = forcePseudoState(element, CSSSelector::PseudoVisited);
+ if (forceVisited)
+ linkState = InsideVisitedLink;
+ }
+
for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule);
@@ -1309,16 +1329,27 @@ PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::
const CSSSelectorList& selectorList = rule->styleRule()->selectorList();
long index = 0;
PseudoId elementPseudoId = element->pseudoId();
+ bool hasMatchingSelectors = false;
for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector)) {
const CSSSelector* firstTagHistorySelector = selector;
- bool matched = false;
+ bool matchedPseudo = false;
if (elementPseudoId)
- matched = matchesPseudoElement(selector, elementPseudoId); // Modifies |selector|.
- matched |= element->matches(firstTagHistorySelector->selectorText(), IGNORE_EXCEPTION);
- if (matched)
+ matchedPseudo = matchesPseudoElement(selector, elementPseudoId); // Modifies |selector|.
+ bool matchedElement = matchesElement(*firstTagHistorySelector, *element);
+ unsigned linkMatchType = SelectorChecker::determineLinkMatchType(*firstTagHistorySelector);
apavlov 2014/04/08 14:19:46 This is not necessary if !matchedElement
lushnikov 2014/04/08 15:28:32 Done.
+ if (matchedElement && linkState == InsideUnvisitedLink)
+ matchedElement = linkMatchType & SelectorChecker::MatchLink;
+ else if (matchedElement && linkState == InsideVisitedLink)
+ matchedElement = linkMatchType & SelectorChecker::MatchVisited;
+
+ if (matchedPseudo || matchedElement) {
matchingSelectors->addItem(index);
+ hasMatchingSelectors = true;
+ }
++index;
}
+ if (!hasMatchingSelectors)
+ continue;
RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch::create()
.setRule(ruleObject.release())
.setMatchingSelectors(matchingSelectors.release());

Powered by Google App Engine
This is Rietveld 408576698