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

Side by Side Diff: third_party/WebKit/Source/core/css/SelectorChecker.cpp

Issue 2496123002: Matching part for >>> (shadow-piercing descendant combinator). (Closed)
Patch Set: rebase Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelector.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
10 * (http://www.torchmobile.com/) 10 * (http://www.torchmobile.com/)
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 279
280 static inline Element* parentOrV0ShadowHostElement(const Element& element) { 280 static inline Element* parentOrV0ShadowHostElement(const Element& element) {
281 if (element.parentNode() && element.parentNode()->isShadowRoot()) { 281 if (element.parentNode() && element.parentNode()->isShadowRoot()) {
282 if (toShadowRoot(element.parentNode())->type() != ShadowRootType::V0) 282 if (toShadowRoot(element.parentNode())->type() != ShadowRootType::V0)
283 return nullptr; 283 return nullptr;
284 } 284 }
285 return element.parentOrShadowHostElement(); 285 return element.parentOrShadowHostElement();
286 } 286 }
287 287
288 static inline Element* parentOrOpenShadowHostElement(const Element& element) {
289 if (element.parentNode() && element.parentNode()->isShadowRoot()) {
290 if (toShadowRoot(element.parentNode())->type() != ShadowRootType::Open)
291 return nullptr;
rune 2016/11/17 10:05:25 So this can happen if you start querying inside a
kochi 2016/11/18 07:31:21 We filter out closed and user-agent shadow roots i
rune 2016/11/18 09:16:01 Acknowledged.
292 }
293 return element.parentOrShadowHostElement();
294 }
295
288 SelectorChecker::Match SelectorChecker::matchForRelation( 296 SelectorChecker::Match SelectorChecker::matchForRelation(
289 const SelectorCheckingContext& context, 297 const SelectorCheckingContext& context,
290 MatchResult& result) const { 298 MatchResult& result) const {
291 SelectorCheckingContext nextContext = prepareNextContextForRelation(context); 299 SelectorCheckingContext nextContext = prepareNextContextForRelation(context);
292 300
293 CSSSelector::RelationType relation = context.selector->relation(); 301 CSSSelector::RelationType relation = context.selector->relation();
294 302
295 // Disable :visited matching when we see the first link or try to match 303 // Disable :visited matching when we see the first link or try to match
296 // anything else than an ancestors. 304 // anything else than an ancestors.
297 if (!context.isSubSelector && 305 if (!context.isSubSelector &&
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 context.element->treeScope()) 398 context.element->treeScope())
391 return SelectorFailsCompletely; 399 return SelectorFailsCompletely;
392 400
393 Element* shadowHost = context.element->ownerShadowHost(); 401 Element* shadowHost = context.element->ownerShadowHost();
394 if (!shadowHost) 402 if (!shadowHost)
395 return SelectorFailsCompletely; 403 return SelectorFailsCompletely;
396 nextContext.element = shadowHost; 404 nextContext.element = shadowHost;
397 return matchSelector(nextContext, result); 405 return matchSelector(nextContext, result);
398 } 406 }
399 407
400 case CSSSelector::ShadowPiercingDescendant:
401 case CSSSelector::ShadowDeep: { 408 case CSSSelector::ShadowDeep: {
402 if (!m_isUARule && !m_isQuerySelector) 409 if (!m_isUARule && !m_isQuerySelector)
403 Deprecation::countDeprecation(context.element->document(), 410 Deprecation::countDeprecation(context.element->document(),
404 UseCounter::CSSDeepCombinator); 411 UseCounter::CSSDeepCombinator);
405 if (ShadowRoot* root = context.element->containingShadowRoot()) { 412 if (ShadowRoot* root = context.element->containingShadowRoot()) {
406 if (root->type() == ShadowRootType::UserAgent) 413 if (root->type() == ShadowRootType::UserAgent)
407 return SelectorFailsCompletely; 414 return SelectorFailsCompletely;
408 } 415 }
409 416
410 if (context.selector->relationIsAffectedByPseudoContent()) { 417 if (context.selector->relationIsAffectedByPseudoContent()) {
(...skipping 21 matching lines...) Expand all
432 UseCounter::count(context.element->document(), 439 UseCounter::count(context.element->document(),
433 UseCounter::CSSDeepCombinatorAndShadow); 440 UseCounter::CSSDeepCombinatorAndShadow);
434 if (match == SelectorMatches || match == SelectorFailsCompletely) 441 if (match == SelectorMatches || match == SelectorFailsCompletely)
435 return match; 442 return match;
436 if (nextSelectorExceedsScope(nextContext)) 443 if (nextSelectorExceedsScope(nextContext))
437 return SelectorFailsCompletely; 444 return SelectorFailsCompletely;
438 } 445 }
439 return SelectorFailsCompletely; 446 return SelectorFailsCompletely;
440 } 447 }
441 448
449 case CSSSelector::ShadowPiercingDescendant: {
450 DCHECK(m_isQuerySelector);
451 if (ShadowRoot* root = context.element->containingShadowRoot()) {
452 if (root->type() == ShadowRootType::UserAgent)
rune 2016/11/17 10:05:25 Will you be able to end up here at all? Doesn't th
kochi 2016/11/18 07:31:21 Good catch, removed. (the wip version naively copi
rune 2016/11/18 09:16:02 Perhaps you should DCHECK that the shadow root typ
453 return SelectorFailsCompletely;
454 }
455
456 for (nextContext.element =
457 parentOrOpenShadowHostElement(*context.element);
458 nextContext.element;
459 nextContext.element =
460 parentOrOpenShadowHostElement(*nextContext.element)) {
461 Match match = matchSelector(nextContext, result);
462 if (match == SelectorMatches || match == SelectorFailsCompletely)
463 return match;
464 if (nextSelectorExceedsScope(nextContext))
465 break;
466 }
467 return SelectorFailsCompletely;
468 }
469
442 case CSSSelector::ShadowSlot: { 470 case CSSSelector::ShadowSlot: {
443 const HTMLSlotElement* slot = findSlotElementInScope(context); 471 const HTMLSlotElement* slot = findSlotElementInScope(context);
444 if (!slot) 472 if (!slot)
445 return SelectorFailsCompletely; 473 return SelectorFailsCompletely;
446 474
447 nextContext.element = const_cast<HTMLSlotElement*>(slot); 475 nextContext.element = const_cast<HTMLSlotElement*>(slot);
448 return matchSelector(nextContext, result); 476 return matchSelector(nextContext, result);
449 } 477 }
450 478
451 case CSSSelector::SubSelector: 479 case CSSSelector::SubSelector:
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1306 }
1279 1307
1280 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) { 1308 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) {
1281 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element), 1309 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element),
1282 CSSSelector::PseudoFocus)) 1310 CSSSelector::PseudoFocus))
1283 return true; 1311 return true;
1284 return element.isFocused() && isFrameFocused(element); 1312 return element.isFocused() && isFrameFocused(element);
1285 } 1313 }
1286 1314
1287 } // namespace blink 1315 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelector.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698