| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 449 |
| 450 void StyleResolver::matchAllRules(ElementRuleCollector& collector, bool matchAut
horAndUserStyles, bool includeSMILProperties) | 450 void StyleResolver::matchAllRules(ElementRuleCollector& collector, bool matchAut
horAndUserStyles, bool includeSMILProperties) |
| 451 { | 451 { |
| 452 matchUARules(collector); | 452 matchUARules(collector); |
| 453 | 453 |
| 454 // Now we check user sheet rules. | 454 // Now we check user sheet rules. |
| 455 if (matchAuthorAndUserStyles) | 455 if (matchAuthorAndUserStyles) |
| 456 matchUserRules(collector, false); | 456 matchUserRules(collector, false); |
| 457 | 457 |
| 458 // Now check author rules, beginning first with presentational attributes ma
pped from HTML. | 458 // Now check author rules, beginning first with presentational attributes ma
pped from HTML. |
| 459 if (m_state.styledElement()) { | 459 if (m_state.element()->isStyledElement()) { |
| 460 collector.addElementStyleProperties(m_state.styledElement()->presentatio
nAttributeStyle()); | 460 collector.addElementStyleProperties(m_state.element()->presentationAttri
buteStyle()); |
| 461 | 461 |
| 462 // Now we check additional mapped declarations. | 462 // Now we check additional mapped declarations. |
| 463 // Tables and table cells share an additional mapped rule that must be a
pplied | 463 // Tables and table cells share an additional mapped rule that must be a
pplied |
| 464 // after all attributes, since their mapped style depends on the values
of multiple attributes. | 464 // after all attributes, since their mapped style depends on the values
of multiple attributes. |
| 465 collector.addElementStyleProperties(m_state.styledElement()->additionalP
resentationAttributeStyle()); | 465 collector.addElementStyleProperties(m_state.element()->additionalPresent
ationAttributeStyle()); |
| 466 | 466 |
| 467 if (m_state.styledElement()->isHTMLElement()) { | 467 if (m_state.element()->isHTMLElement()) { |
| 468 bool isAuto; | 468 bool isAuto; |
| 469 TextDirection textDirection = toHTMLElement(m_state.styledElement())
->directionalityIfhasDirAutoAttribute(isAuto); | 469 TextDirection textDirection = toHTMLElement(m_state.element())->dire
ctionalityIfhasDirAutoAttribute(isAuto); |
| 470 if (isAuto) | 470 if (isAuto) |
| 471 collector.matchedResult().addMatchedProperties(textDirection ==
LTR ? leftToRightDeclaration() : rightToLeftDeclaration()); | 471 collector.matchedResult().addMatchedProperties(textDirection ==
LTR ? leftToRightDeclaration() : rightToLeftDeclaration()); |
| 472 } | 472 } |
| 473 } | 473 } |
| 474 | 474 |
| 475 // Check the rules in author sheets next. | 475 // Check the rules in author sheets next. |
| 476 if (matchAuthorAndUserStyles) | 476 if (matchAuthorAndUserStyles) |
| 477 matchAuthorRules(collector, false); | 477 matchAuthorRules(collector, false); |
| 478 | 478 |
| 479 // Now check our inline style attribute. | 479 if (m_state.element()->isStyledElement()) { |
| 480 if (matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledEle
ment()->inlineStyle()) { | 480 // Now check our inline style attribute. |
| 481 // Inline style is immutable as long as there is no CSSOM wrapper. | 481 if (matchAuthorAndUserStyles && m_state.element()->inlineStyle()) { |
| 482 // FIXME: Media control shadow trees seem to have problems with caching. | 482 // Inline style is immutable as long as there is no CSSOM wrapper. |
| 483 bool isInlineStyleCacheable = !m_state.styledElement()->inlineStyle()->i
sMutable() && !m_state.styledElement()->isInShadowTree(); | 483 // FIXME: Media control shadow trees seem to have problems with cach
ing. |
| 484 // FIXME: Constify. | 484 bool isInlineStyleCacheable = !m_state.element()->inlineStyle()->isM
utable() && !m_state.element()->isInShadowTree(); |
| 485 collector.addElementStyleProperties(m_state.styledElement()->inlineStyle
(), isInlineStyleCacheable); | 485 // FIXME: Constify. |
| 486 collector.addElementStyleProperties(m_state.element()->inlineStyle()
, isInlineStyleCacheable); |
| 487 } |
| 488 |
| 489 // Now check SMIL animation override style. |
| 490 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.element
()->isSVGElement()) |
| 491 collector.addElementStyleProperties(toSVGElement(m_state.element())-
>animatedSMILStyleProperties(), false /* isCacheable */); |
| 492 |
| 493 if (m_state.element()->hasActiveAnimations()) |
| 494 collector.matchedResult().isCacheable = false; |
| 486 } | 495 } |
| 487 | |
| 488 // Now check SMIL animation override style. | |
| 489 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledEleme
nt() && m_state.styledElement()->isSVGElement()) | |
| 490 collector.addElementStyleProperties(toSVGElement(m_state.styledElement()
)->animatedSMILStyleProperties(), false /* isCacheable */); | |
| 491 | |
| 492 if (m_state.styledElement() && m_state.styledElement()->hasActiveAnimations(
)) | |
| 493 collector.matchedResult().isCacheable = false; | |
| 494 } | 496 } |
| 495 | 497 |
| 496 static const unsigned cStyleSearchThreshold = 10; | 498 static const unsigned cStyleSearchThreshold = 10; |
| 497 static const unsigned cStyleSearchLevelThreshold = 10; | 499 static const unsigned cStyleSearchLevelThreshold = 10; |
| 498 | 500 |
| 499 static inline bool parentElementPreventsSharing(const Element* parentElement) | 501 static inline bool parentElementPreventsSharing(const Element* parentElement) |
| 500 { | 502 { |
| 501 if (!parentElement) | 503 if (!parentElement) |
| 502 return false; | 504 return false; |
| 503 return parentElement->hasFlagsSetDuringStylingOfChildren(); | 505 return parentElement->hasFlagsSetDuringStylingOfChildren(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 if (context.element()->isSVGElement()) { | 630 if (context.element()->isSVGElement()) { |
| 629 if (context.element()->getAttribute(classAttr) != sharingCandidate->
getAttribute(classAttr)) | 631 if (context.element()->getAttribute(classAttr) != sharingCandidate->
getAttribute(classAttr)) |
| 630 return false; | 632 return false; |
| 631 } else if (context.element()->classNames() != sharingCandidate->classNam
es()) { | 633 } else if (context.element()->classNames() != sharingCandidate->classNam
es()) { |
| 632 return false; | 634 return false; |
| 633 } | 635 } |
| 634 } else { | 636 } else { |
| 635 return false; | 637 return false; |
| 636 } | 638 } |
| 637 | 639 |
| 638 if (context.styledElement()->presentationAttributeStyle() != sharingCandidat
e->presentationAttributeStyle()) | 640 if (context.element()->presentationAttributeStyle() != sharingCandidate->pre
sentationAttributeStyle()) |
| 639 return false; | 641 return false; |
| 640 | 642 |
| 641 if (context.element()->hasTagName(progressTag)) { | 643 if (context.element()->hasTagName(progressTag)) { |
| 642 if (context.element()->shouldAppearIndeterminate() != sharingCandidate->
shouldAppearIndeterminate()) | 644 if (context.element()->shouldAppearIndeterminate() != sharingCandidate->
shouldAppearIndeterminate()) |
| 643 return false; | 645 return false; |
| 644 } | 646 } |
| 645 | 647 |
| 646 return true; | 648 return true; |
| 647 } | 649 } |
| 648 | 650 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 670 if (element->active() != context.element()->active()) | 672 if (element->active() != context.element()->active()) |
| 671 return false; | 673 return false; |
| 672 if (element->focused() != context.element()->focused()) | 674 if (element->focused() != context.element()->focused()) |
| 673 return false; | 675 return false; |
| 674 if (element->shadowPseudoId() != context.element()->shadowPseudoId()) | 676 if (element->shadowPseudoId() != context.element()->shadowPseudoId()) |
| 675 return false; | 677 return false; |
| 676 if (element == element->document()->cssTarget()) | 678 if (element == element->document()->cssTarget()) |
| 677 return false; | 679 return false; |
| 678 if (!sharingCandidateHasIdenticalStyleAffectingAttributes(context, element)) | 680 if (!sharingCandidateHasIdenticalStyleAffectingAttributes(context, element)) |
| 679 return false; | 681 return false; |
| 680 if (element->additionalPresentationAttributeStyle() != context.styledElement
()->additionalPresentationAttributeStyle()) | 682 if (element->additionalPresentationAttributeStyle() != context.element()->ad
ditionalPresentationAttributeStyle()) |
| 681 return false; | 683 return false; |
| 682 | 684 |
| 683 if (element->hasID() && m_features.idsInRules.contains(element->idForStyleRe
solution().impl())) | 685 if (element->hasID() && m_features.idsInRules.contains(element->idForStyleRe
solution().impl())) |
| 684 return false; | 686 return false; |
| 685 if (element->hasScopedHTMLStyleChild()) | 687 if (element->hasScopedHTMLStyleChild()) |
| 686 return false; | 688 return false; |
| 687 | 689 |
| 688 // FIXME: We should share style for option and optgroup whenever possible. | 690 // FIXME: We should share style for option and optgroup whenever possible. |
| 689 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems | 691 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems |
| 690 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 | 692 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 if (canShareStyleWithElement(context, toElement(node))) | 741 if (canShareStyleWithElement(context, toElement(node))) |
| 740 break; | 742 break; |
| 741 if (count++ == cStyleSearchThreshold) | 743 if (count++ == cStyleSearchThreshold) |
| 742 return 0; | 744 return 0; |
| 743 } | 745 } |
| 744 return toElement(node); | 746 return toElement(node); |
| 745 } | 747 } |
| 746 | 748 |
| 747 RenderStyle* StyleResolver::locateSharedStyle(const ElementResolveContext& conte
xt) | 749 RenderStyle* StyleResolver::locateSharedStyle(const ElementResolveContext& conte
xt) |
| 748 { | 750 { |
| 749 if (!context.styledElement()) | 751 if (!context.element() || !context.element()->isStyledElement()) |
| 750 return 0; | 752 return 0; |
| 751 | 753 |
| 752 // If the element has inline style it is probably unique. | 754 // If the element has inline style it is probably unique. |
| 753 if (context.styledElement()->inlineStyle()) | 755 if (context.element()->inlineStyle()) |
| 754 return 0; | 756 return 0; |
| 755 if (context.styledElement()->isSVGElement() && toSVGElement(context.styledEl
ement())->animatedSMILStyleProperties()) | 757 if (context.element()->isSVGElement() && toSVGElement(context.element())->an
imatedSMILStyleProperties()) |
| 756 return 0; | 758 return 0; |
| 757 // Ids stop style sharing if they show up in the stylesheets. | 759 // Ids stop style sharing if they show up in the stylesheets. |
| 758 if (context.styledElement()->hasID() && m_features.idsInRules.contains(conte
xt.styledElement()->idForStyleResolution().impl())) | 760 if (context.element()->hasID() && m_features.idsInRules.contains(context.ele
ment()->idForStyleResolution().impl())) |
| 759 return 0; | 761 return 0; |
| 760 // Active and hovered elements always make a chain towards the document node | 762 // Active and hovered elements always make a chain towards the document node |
| 761 // and no siblings or cousins will have the same state. | 763 // and no siblings or cousins will have the same state. |
| 762 if (context.styledElement()->hovered()) | 764 if (context.element()->hovered()) |
| 763 return 0; | 765 return 0; |
| 764 if (context.styledElement()->active()) | 766 if (context.element()->active()) |
| 765 return 0; | 767 return 0; |
| 766 // There is always only one focused element. | 768 // There is always only one focused element. |
| 767 if (context.styledElement()->focused()) | 769 if (context.element()->focused()) |
| 768 return 0; | 770 return 0; |
| 769 if (parentElementPreventsSharing(context.element()->parentElement())) | 771 if (parentElementPreventsSharing(context.element()->parentElement())) |
| 770 return 0; | 772 return 0; |
| 771 if (context.styledElement()->hasScopedHTMLStyleChild()) | 773 if (context.element()->hasScopedHTMLStyleChild()) |
| 772 return 0; | 774 return 0; |
| 773 if (context.element() == context.document()->cssTarget()) | 775 if (context.element() == context.document()->cssTarget()) |
| 774 return 0; | 776 return 0; |
| 775 if (elementHasDirectionAuto(context.element())) | 777 if (elementHasDirectionAuto(context.element())) |
| 776 return 0; | 778 return 0; |
| 777 if (context.element()->hasActiveAnimations()) | 779 if (context.element()->hasActiveAnimations()) |
| 778 return 0; | 780 return 0; |
| 779 // When a dialog is first shown, its style is mutated to center it in the | 781 // When a dialog is first shown, its style is mutated to center it in the |
| 780 // viewport. So the styles can't be shared since the viewport position and | 782 // viewport. So the styles can't be shared since the viewport position and |
| 781 // size may be different each time a dialog is opened. | 783 // size may be different each time a dialog is opened. |
| 782 if (context.element()->hasTagName(dialogTag)) | 784 if (context.element()->hasTagName(dialogTag)) |
| 783 return 0; | 785 return 0; |
| 784 | 786 |
| 785 // Cache whether context.element() is affected by any known class selectors. | 787 // Cache whether context.element() is affected by any known class selectors. |
| 786 // FIXME: This should be an explicit out parameter, instead of a member vari
able. | 788 // FIXME: This should be an explicit out parameter, instead of a member vari
able. |
| 787 m_elementAffectedByClassRules = context.element() && context.element()->hasC
lass() && classNamesAffectedByRules(context.element()->classNames()); | 789 m_elementAffectedByClassRules = context.element() && context.element()->hasC
lass() && classNamesAffectedByRules(context.element()->classNames()); |
| 788 | 790 |
| 789 // Check next siblings and their cousins. | 791 // Check next siblings and their cousins. |
| 790 unsigned count = 0; | 792 unsigned count = 0; |
| 791 unsigned visitedNodeCount = 0; | 793 unsigned visitedNodeCount = 0; |
| 792 Element* shareElement = 0; | 794 Element* shareElement = 0; |
| 793 Node* cousinList = context.styledElement()->nextSibling(); | 795 Node* cousinList = context.element()->nextSibling(); |
| 794 while (cousinList) { | 796 while (cousinList) { |
| 795 shareElement = findSiblingForStyleSharing(context, cousinList, count); | 797 shareElement = findSiblingForStyleSharing(context, cousinList, count); |
| 796 if (shareElement) | 798 if (shareElement) |
| 797 break; | 799 break; |
| 798 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo
unt); | 800 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo
unt); |
| 799 } | 801 } |
| 800 | 802 |
| 801 // If we have exhausted all our budget or our cousins. | 803 // If we have exhausted all our budget or our cousins. |
| 802 if (!shareElement) | 804 if (!shareElement) |
| 803 return 0; | 805 return 0; |
| (...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn
fo) const | 2401 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn
fo) const |
| 2400 { | 2402 { |
| 2401 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 2403 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
| 2402 info.addMember(matchedProperties, "matchedProperties"); | 2404 info.addMember(matchedProperties, "matchedProperties"); |
| 2403 info.addMember(ranges, "ranges"); | 2405 info.addMember(ranges, "ranges"); |
| 2404 info.addMember(renderStyle, "renderStyle"); | 2406 info.addMember(renderStyle, "renderStyle"); |
| 2405 info.addMember(parentRenderStyle, "parentRenderStyle"); | 2407 info.addMember(parentRenderStyle, "parentRenderStyle"); |
| 2406 } | 2408 } |
| 2407 | 2409 |
| 2408 } // namespace WebCore | 2410 } // namespace WebCore |
| OLD | NEW |