| OLD | NEW |
| 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.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 if (context.elementStyle) | 540 if (context.elementStyle) |
| 541 context.elementStyle->setEmptyState(result); | 541 context.elementStyle->setEmptyState(result); |
| 542 else if (element.renderStyle() && (element.document().styleE
ngine()->usesSiblingRules() || element.renderStyle()->unique())) | 542 else if (element.renderStyle() && (element.document().styleE
ngine()->usesSiblingRules() || element.renderStyle()->unique())) |
| 543 element.renderStyle()->setEmptyState(result); | 543 element.renderStyle()->setEmptyState(result); |
| 544 } | 544 } |
| 545 return result; | 545 return result; |
| 546 } | 546 } |
| 547 case CSSSelector::PseudoFirstChild: | 547 case CSSSelector::PseudoFirstChild: |
| 548 // first-child matches the first child that is an element | 548 // first-child matches the first child that is an element |
| 549 if (Element* parent = element.parentElement()) { | 549 if (Element* parent = element.parentElement()) { |
| 550 bool result = siblingTraversalStrategy.isFirstChild(&element); | 550 bool result = siblingTraversalStrategy.isFirstChild(element); |
| 551 if (m_mode == ResolvingStyle) { | 551 if (m_mode == ResolvingStyle) { |
| 552 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); | 552 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); |
| 553 parent->setChildrenAffectedByFirstChildRules(); | 553 parent->setChildrenAffectedByFirstChildRules(); |
| 554 if (result && childStyle) | 554 if (result && childStyle) |
| 555 childStyle->setFirstChildState(); | 555 childStyle->setFirstChildState(); |
| 556 } | 556 } |
| 557 return result; | 557 return result; |
| 558 } | 558 } |
| 559 break; | 559 break; |
| 560 case CSSSelector::PseudoFirstOfType: | 560 case CSSSelector::PseudoFirstOfType: |
| 561 // first-of-type matches the first element of its type | 561 // first-of-type matches the first element of its type |
| 562 if (Element* parent = element.parentElement()) { | 562 if (Element* parent = element.parentElement()) { |
| 563 bool result = siblingTraversalStrategy.isFirstOfType(&element, e
lement.tagQName()); | 563 bool result = siblingTraversalStrategy.isFirstOfType(element, el
ement.tagQName()); |
| 564 if (m_mode == ResolvingStyle) | 564 if (m_mode == ResolvingStyle) |
| 565 parent->setChildrenAffectedByForwardPositionalRules(); | 565 parent->setChildrenAffectedByForwardPositionalRules(); |
| 566 return result; | 566 return result; |
| 567 } | 567 } |
| 568 break; | 568 break; |
| 569 case CSSSelector::PseudoLastChild: | 569 case CSSSelector::PseudoLastChild: |
| 570 // last-child matches the last child that is an element | 570 // last-child matches the last child that is an element |
| 571 if (Element* parent = element.parentElement()) { | 571 if (Element* parent = element.parentElement()) { |
| 572 bool result = parent->isFinishedParsingChildren() && siblingTrav
ersalStrategy.isLastChild(&element); | 572 bool result = parent->isFinishedParsingChildren() && siblingTrav
ersalStrategy.isLastChild(element); |
| 573 if (m_mode == ResolvingStyle) { | 573 if (m_mode == ResolvingStyle) { |
| 574 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); | 574 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); |
| 575 parent->setChildrenAffectedByLastChildRules(); | 575 parent->setChildrenAffectedByLastChildRules(); |
| 576 if (result && childStyle) | 576 if (result && childStyle) |
| 577 childStyle->setLastChildState(); | 577 childStyle->setLastChildState(); |
| 578 } | 578 } |
| 579 return result; | 579 return result; |
| 580 } | 580 } |
| 581 break; | 581 break; |
| 582 case CSSSelector::PseudoLastOfType: | 582 case CSSSelector::PseudoLastOfType: |
| 583 // last-of-type matches the last element of its type | 583 // last-of-type matches the last element of its type |
| 584 if (Element* parent = element.parentElement()) { | 584 if (Element* parent = element.parentElement()) { |
| 585 if (m_mode == ResolvingStyle) | 585 if (m_mode == ResolvingStyle) |
| 586 parent->setChildrenAffectedByBackwardPositionalRules(); | 586 parent->setChildrenAffectedByBackwardPositionalRules(); |
| 587 if (!parent->isFinishedParsingChildren()) | 587 if (!parent->isFinishedParsingChildren()) |
| 588 return false; | 588 return false; |
| 589 return siblingTraversalStrategy.isLastOfType(&element, element.t
agQName()); | 589 return siblingTraversalStrategy.isLastOfType(element, element.ta
gQName()); |
| 590 } | 590 } |
| 591 break; | 591 break; |
| 592 case CSSSelector::PseudoOnlyChild: | 592 case CSSSelector::PseudoOnlyChild: |
| 593 if (Element* parent = element.parentElement()) { | 593 if (Element* parent = element.parentElement()) { |
| 594 bool firstChild = siblingTraversalStrategy.isFirstChild(&element
); | 594 bool firstChild = siblingTraversalStrategy.isFirstChild(element)
; |
| 595 bool onlyChild = firstChild && parent->isFinishedParsingChildren
() && siblingTraversalStrategy.isLastChild(&element); | 595 bool onlyChild = firstChild && parent->isFinishedParsingChildren
() && siblingTraversalStrategy.isLastChild(element); |
| 596 if (m_mode == ResolvingStyle) { | 596 if (m_mode == ResolvingStyle) { |
| 597 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); | 597 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); |
| 598 parent->setChildrenAffectedByFirstChildRules(); | 598 parent->setChildrenAffectedByFirstChildRules(); |
| 599 parent->setChildrenAffectedByLastChildRules(); | 599 parent->setChildrenAffectedByLastChildRules(); |
| 600 if (firstChild && childStyle) | 600 if (firstChild && childStyle) |
| 601 childStyle->setFirstChildState(); | 601 childStyle->setFirstChildState(); |
| 602 if (onlyChild && childStyle) | 602 if (onlyChild && childStyle) |
| 603 childStyle->setLastChildState(); | 603 childStyle->setLastChildState(); |
| 604 } | 604 } |
| 605 return onlyChild; | 605 return onlyChild; |
| 606 } | 606 } |
| 607 break; | 607 break; |
| 608 case CSSSelector::PseudoOnlyOfType: | 608 case CSSSelector::PseudoOnlyOfType: |
| 609 // FIXME: This selector is very slow. | 609 // FIXME: This selector is very slow. |
| 610 if (Element* parent = element.parentElement()) { | 610 if (Element* parent = element.parentElement()) { |
| 611 if (m_mode == ResolvingStyle) { | 611 if (m_mode == ResolvingStyle) { |
| 612 parent->setChildrenAffectedByForwardPositionalRules(); | 612 parent->setChildrenAffectedByForwardPositionalRules(); |
| 613 parent->setChildrenAffectedByBackwardPositionalRules(); | 613 parent->setChildrenAffectedByBackwardPositionalRules(); |
| 614 } | 614 } |
| 615 if (!parent->isFinishedParsingChildren()) | 615 if (!parent->isFinishedParsingChildren()) |
| 616 return false; | 616 return false; |
| 617 return siblingTraversalStrategy.isFirstOfType(&element, element.
tagQName()) && siblingTraversalStrategy.isLastOfType(&element, element.tagQName(
)); | 617 return siblingTraversalStrategy.isFirstOfType(element, element.t
agQName()) && siblingTraversalStrategy.isLastOfType(element, element.tagQName())
; |
| 618 } | 618 } |
| 619 break; | 619 break; |
| 620 case CSSSelector::PseudoNthChild: | 620 case CSSSelector::PseudoNthChild: |
| 621 if (!selector.parseNth()) | 621 if (!selector.parseNth()) |
| 622 break; | 622 break; |
| 623 if (Element* parent = element.parentElement()) { | 623 if (Element* parent = element.parentElement()) { |
| 624 int count = 1 + siblingTraversalStrategy.countElementsBefore(&el
ement); | 624 int count = 1 + siblingTraversalStrategy.countElementsBefore(ele
ment); |
| 625 if (m_mode == ResolvingStyle) { | 625 if (m_mode == ResolvingStyle) { |
| 626 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); | 626 RenderStyle* childStyle = context.elementStyle ? context.ele
mentStyle : element.renderStyle(); |
| 627 element.setChildIndex(count); | 627 element.setChildIndex(count); |
| 628 if (childStyle) | 628 if (childStyle) |
| 629 childStyle->setUnique(); | 629 childStyle->setUnique(); |
| 630 parent->setChildrenAffectedByForwardPositionalRules(); | 630 parent->setChildrenAffectedByForwardPositionalRules(); |
| 631 } | 631 } |
| 632 | 632 |
| 633 if (selector.matchNth(count)) | 633 if (selector.matchNth(count)) |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 break; | 636 break; |
| 637 case CSSSelector::PseudoNthOfType: | 637 case CSSSelector::PseudoNthOfType: |
| 638 if (!selector.parseNth()) | 638 if (!selector.parseNth()) |
| 639 break; | 639 break; |
| 640 if (Element* parent = element.parentElement()) { | 640 if (Element* parent = element.parentElement()) { |
| 641 int count = 1 + siblingTraversalStrategy.countElementsOfTypeBefo
re(&element, element.tagQName()); | 641 int count = 1 + siblingTraversalStrategy.countElementsOfTypeBefo
re(element, element.tagQName()); |
| 642 if (m_mode == ResolvingStyle) | 642 if (m_mode == ResolvingStyle) |
| 643 parent->setChildrenAffectedByForwardPositionalRules(); | 643 parent->setChildrenAffectedByForwardPositionalRules(); |
| 644 | 644 |
| 645 if (selector.matchNth(count)) | 645 if (selector.matchNth(count)) |
| 646 return true; | 646 return true; |
| 647 } | 647 } |
| 648 break; | 648 break; |
| 649 case CSSSelector::PseudoNthLastChild: | 649 case CSSSelector::PseudoNthLastChild: |
| 650 if (!selector.parseNth()) | 650 if (!selector.parseNth()) |
| 651 break; | 651 break; |
| 652 if (Element* parent = element.parentElement()) { | 652 if (Element* parent = element.parentElement()) { |
| 653 if (m_mode == ResolvingStyle) | 653 if (m_mode == ResolvingStyle) |
| 654 parent->setChildrenAffectedByBackwardPositionalRules(); | 654 parent->setChildrenAffectedByBackwardPositionalRules(); |
| 655 if (!parent->isFinishedParsingChildren()) | 655 if (!parent->isFinishedParsingChildren()) |
| 656 return false; | 656 return false; |
| 657 int count = 1 + siblingTraversalStrategy.countElementsAfter(&ele
ment); | 657 int count = 1 + siblingTraversalStrategy.countElementsAfter(elem
ent); |
| 658 if (selector.matchNth(count)) | 658 if (selector.matchNth(count)) |
| 659 return true; | 659 return true; |
| 660 } | 660 } |
| 661 break; | 661 break; |
| 662 case CSSSelector::PseudoNthLastOfType: | 662 case CSSSelector::PseudoNthLastOfType: |
| 663 if (!selector.parseNth()) | 663 if (!selector.parseNth()) |
| 664 break; | 664 break; |
| 665 if (Element* parent = element.parentElement()) { | 665 if (Element* parent = element.parentElement()) { |
| 666 if (m_mode == ResolvingStyle) | 666 if (m_mode == ResolvingStyle) |
| 667 parent->setChildrenAffectedByBackwardPositionalRules(); | 667 parent->setChildrenAffectedByBackwardPositionalRules(); |
| 668 if (!parent->isFinishedParsingChildren()) | 668 if (!parent->isFinishedParsingChildren()) |
| 669 return false; | 669 return false; |
| 670 | 670 |
| 671 int count = 1 + siblingTraversalStrategy.countElementsOfTypeAfte
r(&element, element.tagQName()); | 671 int count = 1 + siblingTraversalStrategy.countElementsOfTypeAfte
r(element, element.tagQName()); |
| 672 if (selector.matchNth(count)) | 672 if (selector.matchNth(count)) |
| 673 return true; | 673 return true; |
| 674 } | 674 } |
| 675 break; | 675 break; |
| 676 case CSSSelector::PseudoTarget: | 676 case CSSSelector::PseudoTarget: |
| 677 if (element == element.document().cssTarget()) | 677 if (element == element.document().cssTarget()) |
| 678 return true; | 678 return true; |
| 679 break; | 679 break; |
| 680 case CSSSelector::PseudoAny: | 680 case CSSSelector::PseudoAny: |
| 681 { | 681 { |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 return element.focused() && isFrameFocused(element); | 1073 return element.focused() && isFrameFocused(element); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 template | 1076 template |
| 1077 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co
nst DOMSiblingTraversalStrategy&, MatchResult*) const; | 1077 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co
nst DOMSiblingTraversalStrategy&, MatchResult*) const; |
| 1078 | 1078 |
| 1079 template | 1079 template |
| 1080 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co
nst ShadowDOMSiblingTraversalStrategy&, MatchResult*) const; | 1080 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co
nst ShadowDOMSiblingTraversalStrategy&, MatchResult*) const; |
| 1081 | 1081 |
| 1082 } | 1082 } |
| OLD | NEW |