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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 } | 559 } |
560 | 560 |
561 // Now check SMIL animation override style. | 561 // Now check SMIL animation override style. |
562 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledEleme
nt() && m_state.styledElement()->isSVGElement()) | 562 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledEleme
nt() && m_state.styledElement()->isSVGElement()) |
563 collector.addElementStyleProperties(toSVGElement(m_state.styledElement()
)->animatedSMILStyleProperties(), false /* isCacheable */); | 563 collector.addElementStyleProperties(toSVGElement(m_state.styledElement()
)->animatedSMILStyleProperties(), false /* isCacheable */); |
564 | 564 |
565 if (m_state.styledElement() && m_state.styledElement()->hasActiveAnimations(
)) | 565 if (m_state.styledElement() && m_state.styledElement()->hasActiveAnimations(
)) |
566 collector.matchedResult().isCacheable = false; | 566 collector.matchedResult().isCacheable = false; |
567 } | 567 } |
568 | 568 |
569 inline void StyleResolver::initElement(Element* e) | 569 inline void StyleResolver::initElement(Element* e, int childIndex) |
570 { | 570 { |
571 if (m_state.element() != e) { | 571 if (m_state.element() != e) { |
572 m_state.initElement(e); | 572 m_state.initElement(e, childIndex); |
573 if (e && e == e->document()->documentElement()) { | 573 if (e && e == e->document()->documentElement()) { |
574 e->document()->setDirectionSetOnDocumentElement(false); | 574 e->document()->setDirectionSetOnDocumentElement(false); |
575 e->document()->setWritingModeSetOnDocumentElement(false); | 575 e->document()->setWritingModeSetOnDocumentElement(false); |
576 } | 576 } |
577 } | 577 } |
578 } | 578 } |
579 | 579 |
580 static const unsigned cStyleSearchThreshold = 10; | 580 static const unsigned cStyleSearchThreshold = 10; |
581 static const unsigned cStyleSearchLevelThreshold = 10; | 581 static const unsigned cStyleSearchLevelThreshold = 10; |
582 | 582 |
(...skipping 16 matching lines...) Expand all Loading... |
599 if (p->inlineStyle()) | 599 if (p->inlineStyle()) |
600 return 0; | 600 return 0; |
601 if (p->isSVGElement() && toSVGElement(p)->animatedSMILStyleProperties()) | 601 if (p->isSVGElement() && toSVGElement(p)->animatedSMILStyleProperties()) |
602 return 0; | 602 return 0; |
603 if (p->hasID() && m_features.idsInRules.contains(p->idForStyleResolution().i
mpl())) | 603 if (p->hasID() && m_features.idsInRules.contains(p->idForStyleResolution().i
mpl())) |
604 return 0; | 604 return 0; |
605 | 605 |
606 RenderStyle* parentStyle = p->renderStyle(); | 606 RenderStyle* parentStyle = p->renderStyle(); |
607 unsigned subcount = 0; | 607 unsigned subcount = 0; |
608 Node* thisCousin = p; | 608 Node* thisCousin = p; |
609 Node* currentNode = p->previousSibling(); | 609 Node* currentNode = p->nextSibling(); |
610 | 610 |
611 // Reserve the tries for this level. This effectively makes sure that the al
gorithm | 611 // Reserve the tries for this level. This effectively makes sure that the al
gorithm |
612 // will never go deeper than cStyleSearchLevelThreshold levels into recursio
n. | 612 // will never go deeper than cStyleSearchLevelThreshold levels into recursio
n. |
613 visitedNodeCount += cStyleSearchThreshold; | 613 visitedNodeCount += cStyleSearchThreshold; |
614 while (thisCousin) { | 614 while (thisCousin) { |
615 while (currentNode) { | 615 while (currentNode) { |
616 ++subcount; | 616 ++subcount; |
617 if (!currentNode->hasScopedHTMLStyleChild() && currentNode->renderSt
yle() == parentStyle && currentNode->lastChild() | 617 if (!currentNode->hasScopedHTMLStyleChild() && currentNode->renderSt
yle() == parentStyle && currentNode->lastChild() |
618 && currentNode->isElementNode() && !parentElementPreventsSharing
(toElement(currentNode)) | 618 && currentNode->isElementNode() && !parentElementPreventsSharing
(toElement(currentNode)) |
619 && !toElement(currentNode)->shadow() | 619 && !toElement(currentNode)->shadow() |
620 ) { | 620 ) { |
621 // Adjust for unused reserved tries. | 621 // Adjust for unused reserved tries. |
622 visitedNodeCount -= cStyleSearchThreshold - subcount; | 622 visitedNodeCount -= cStyleSearchThreshold - subcount; |
623 return currentNode->lastChild(); | 623 return currentNode->lastChild(); |
624 } | 624 } |
625 if (subcount >= cStyleSearchThreshold) | 625 if (subcount >= cStyleSearchThreshold) |
626 return 0; | 626 return 0; |
627 currentNode = currentNode->previousSibling(); | 627 currentNode = currentNode->nextSibling(); |
628 } | 628 } |
629 currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeC
ount); | 629 currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeC
ount); |
630 thisCousin = currentNode; | 630 thisCousin = currentNode; |
631 } | 631 } |
632 | 632 |
633 return 0; | 633 return 0; |
634 } | 634 } |
635 | 635 |
636 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet) | 636 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet) |
637 { | 637 { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWe
bVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNo
de()) | 813 if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWe
bVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNo
de()) |
814 return false; | 814 return false; |
815 | 815 |
816 if (element == element->document()->webkitCurrentFullScreenElement() || stat
e.element() == state.document()->webkitCurrentFullScreenElement()) | 816 if (element == element->document()->webkitCurrentFullScreenElement() || stat
e.element() == state.document()->webkitCurrentFullScreenElement()) |
817 return false; | 817 return false; |
818 return true; | 818 return true; |
819 } | 819 } |
820 | 820 |
821 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsi
gned& count) const | 821 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsi
gned& count) const |
822 { | 822 { |
823 for (; node; node = node->previousSibling()) { | 823 for (; node; node = node->nextSibling()) { |
824 if (!node->isStyledElement()) | 824 if (!node->isStyledElement()) |
825 continue; | 825 continue; |
826 if (canShareStyleWithElement(static_cast<StyledElement*>(node))) | 826 if (canShareStyleWithElement(static_cast<StyledElement*>(node))) |
827 break; | 827 break; |
828 if (count++ == cStyleSearchThreshold) | 828 if (count++ == cStyleSearchThreshold) |
829 return 0; | 829 return 0; |
830 } | 830 } |
831 return static_cast<StyledElement*>(node); | 831 return static_cast<StyledElement*>(node); |
832 } | 832 } |
833 | 833 |
(...skipping 19 matching lines...) Expand all Loading... |
853 return 0; | 853 return 0; |
854 if (elementHasDirectionAuto(state.element())) | 854 if (elementHasDirectionAuto(state.element())) |
855 return 0; | 855 return 0; |
856 if (state.element()->hasActiveAnimations()) | 856 if (state.element()->hasActiveAnimations()) |
857 return 0; | 857 return 0; |
858 | 858 |
859 // Cache whether state.element is affected by any known class selectors. | 859 // Cache whether state.element is affected by any known class selectors. |
860 // FIXME: This shouldn't be a member variable. The style sharing code could
be factored out of StyleResolver. | 860 // FIXME: This shouldn't be a member variable. The style sharing code could
be factored out of StyleResolver. |
861 state.setElementAffectedByClassRules(state.element() && state.element()->has
Class() && classNamesAffectedByRules(state.element()->classNames())); | 861 state.setElementAffectedByClassRules(state.element() && state.element()->has
Class() && classNamesAffectedByRules(state.element()->classNames())); |
862 | 862 |
863 // Check previous siblings and their cousins. | 863 // Check next siblings and their cousins. |
864 unsigned count = 0; | 864 unsigned count = 0; |
865 unsigned visitedNodeCount = 0; | 865 unsigned visitedNodeCount = 0; |
866 StyledElement* shareElement = 0; | 866 StyledElement* shareElement = 0; |
867 Node* cousinList = state.styledElement()->previousSibling(); | 867 Node* cousinList = state.styledElement()->nextSibling(); |
868 while (cousinList) { | 868 while (cousinList) { |
869 shareElement = findSiblingForStyleSharing(cousinList, count); | 869 shareElement = findSiblingForStyleSharing(cousinList, count); |
870 if (shareElement) | 870 if (shareElement) |
871 break; | 871 break; |
872 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo
unt); | 872 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo
unt); |
873 } | 873 } |
874 | 874 |
875 // If we have exhausted all our budget or our cousins. | 875 // If we have exhausted all our budget or our cousins. |
876 if (!shareElement) | 876 if (!shareElement) |
877 return 0; | 877 return 0; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 } | 1072 } |
1073 | 1073 |
1074 static inline bool isAtShadowBoundary(const Element* element) | 1074 static inline bool isAtShadowBoundary(const Element* element) |
1075 { | 1075 { |
1076 if (!element) | 1076 if (!element) |
1077 return false; | 1077 return false; |
1078 ContainerNode* parentNode = element->parentNode(); | 1078 ContainerNode* parentNode = element->parentNode(); |
1079 return parentNode && parentNode->isShadowRoot(); | 1079 return parentNode && parentNode->isShadowRoot(); |
1080 } | 1080 } |
1081 | 1081 |
1082 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent, | 1082 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent, StyleSharingBehavior sharingBehavior, |
1083 StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior,
RenderRegion* regionForStyling) | 1083 RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling, int c
hildIndex) |
1084 { | 1084 { |
1085 // Once an element has a renderer, we don't try to destroy it, since otherwi
se the renderer | 1085 // Once an element has a renderer, we don't try to destroy it, since otherwi
se the renderer |
1086 // will vanish if a style recalc happens during loading. | 1086 // will vanish if a style recalc happens during loading. |
1087 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles
heetsLoaded() && !element->renderer()) { | 1087 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles
heetsLoaded() && !element->renderer()) { |
1088 if (!s_styleNotYetAvailable) { | 1088 if (!s_styleNotYetAvailable) { |
1089 s_styleNotYetAvailable = RenderStyle::create().leakRef(); | 1089 s_styleNotYetAvailable = RenderStyle::create().leakRef(); |
1090 s_styleNotYetAvailable->setDisplay(NONE); | 1090 s_styleNotYetAvailable->setDisplay(NONE); |
1091 s_styleNotYetAvailable->font().update(m_fontSelector); | 1091 s_styleNotYetAvailable->font().update(m_fontSelector); |
1092 } | 1092 } |
1093 element->document()->setHasNodesWithPlaceholderStyle(); | 1093 element->document()->setHasNodesWithPlaceholderStyle(); |
1094 return s_styleNotYetAvailable; | 1094 return s_styleNotYetAvailable; |
1095 } | 1095 } |
1096 | 1096 |
1097 StyleResolverState& state = m_state; | 1097 StyleResolverState& state = m_state; |
1098 initElement(element); | 1098 initElement(element, childIndex); |
1099 state.initForStyleResolve(document(), element, defaultParent, regionForStyli
ng); | 1099 state.initForStyleResolve(document(), element, defaultParent, regionForStyli
ng); |
1100 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi
nt()) { | 1100 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi
nt()) { |
1101 RenderStyle* sharedStyle = locateSharedStyle(); | 1101 RenderStyle* sharedStyle = locateSharedStyle(); |
1102 if (sharedStyle) { | 1102 if (sharedStyle) { |
1103 state.clear(); | 1103 state.clear(); |
1104 return sharedStyle; | 1104 return sharedStyle; |
1105 } | 1105 } |
1106 } | 1106 } |
1107 | 1107 |
1108 if (state.parentStyle()) { | 1108 if (state.parentStyle()) { |
(...skipping 2620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3729 info.addMember(m_state, "state"); | 3729 info.addMember(m_state, "state"); |
3730 | 3730 |
3731 // FIXME: move this to a place where it would be called only once? | 3731 // FIXME: move this to a place where it would be called only once? |
3732 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); | 3732 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); |
3733 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl
e"); | 3733 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl
e"); |
3734 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle"
); | 3734 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle"
); |
3735 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo
urceStyle"); | 3735 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo
urceStyle"); |
3736 } | 3736 } |
3737 | 3737 |
3738 } // namespace WebCore | 3738 } // namespace WebCore |
OLD | NEW |