| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 668 } |
| 669 | 669 |
| 670 static inline bool isAtShadowBoundary(const Element* element) | 670 static inline bool isAtShadowBoundary(const Element* element) |
| 671 { | 671 { |
| 672 if (!element) | 672 if (!element) |
| 673 return false; | 673 return false; |
| 674 ContainerNode* parentNode = element->parentNode(); | 674 ContainerNode* parentNode = element->parentNode(); |
| 675 return parentNode && parentNode->isShadowRoot(); | 675 return parentNode && parentNode->isShadowRoot(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 static inline void resetDirectionAndWritingModeOnDocument(Document* document) |
| 679 { |
| 680 document->setDirectionSetOnDocumentElement(false); |
| 681 document->setWritingModeSetOnDocumentElement(false); |
| 682 } |
| 683 |
| 684 |
| 678 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent, StyleSharingBehavior sharingBehavior, | 685 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
tyle* defaultParent, StyleSharingBehavior sharingBehavior, |
| 679 RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling) | 686 RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling) |
| 680 { | 687 { |
| 681 // Once an element has a renderer, we don't try to destroy it, since otherwi
se the renderer | 688 // Once an element has a renderer, we don't try to destroy it, since otherwi
se the renderer |
| 682 // will vanish if a style recalc happens during loading. | 689 // will vanish if a style recalc happens during loading. |
| 683 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles
heetsLoaded() && !element->renderer()) { | 690 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles
heetsLoaded() && !element->renderer()) { |
| 684 if (!s_styleNotYetAvailable) { | 691 if (!s_styleNotYetAvailable) { |
| 685 s_styleNotYetAvailable = RenderStyle::create().leakRef(); | 692 s_styleNotYetAvailable = RenderStyle::create().leakRef(); |
| 686 s_styleNotYetAvailable->setDisplay(NONE); | 693 s_styleNotYetAvailable->setDisplay(NONE); |
| 687 s_styleNotYetAvailable->font().update(m_fontSelector); | 694 s_styleNotYetAvailable->font().update(m_fontSelector); |
| 688 } | 695 } |
| 689 element->document()->setHasNodesWithPlaceholderStyle(); | 696 element->document()->setHasNodesWithPlaceholderStyle(); |
| 690 return s_styleNotYetAvailable; | 697 return s_styleNotYetAvailable; |
| 691 } | 698 } |
| 692 | 699 |
| 700 if (element == document()->documentElement()) |
| 701 resetDirectionAndWritingModeOnDocument(document()); |
| 693 StyleResolverState& state = m_state; | 702 StyleResolverState& state = m_state; |
| 694 StyleResolveScope resolveScope(&state, document(), element, defaultParent, r
egionForStyling); | 703 StyleResolveScope resolveScope(&state, document(), element, defaultParent, r
egionForStyling); |
| 704 |
| 695 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi
nt() && state.parentStyle()) { | 705 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi
nt() && state.parentStyle()) { |
| 696 SharedStyleFinder styleFinder(m_features, m_siblingRuleSet.get(), m_unco
mmonAttributeRuleSet.get(), this); | 706 SharedStyleFinder styleFinder(m_features, m_siblingRuleSet.get(), m_unco
mmonAttributeRuleSet.get(), this); |
| 697 RefPtr<RenderStyle> sharedStyle = styleFinder.locateSharedStyle(state.el
ementContext()); | 707 RefPtr<RenderStyle> sharedStyle = styleFinder.locateSharedStyle(state.el
ementContext()); |
| 698 if (sharedStyle) | 708 if (sharedStyle) |
| 699 return sharedStyle.release(); | 709 return sharedStyle.release(); |
| 700 } | 710 } |
| 701 | 711 |
| 702 if (state.parentStyle()) { | 712 if (state.parentStyle()) { |
| 703 state.setStyle(RenderStyle::create()); | 713 state.setStyle(RenderStyle::create()); |
| 704 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme
nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); | 714 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme
nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // FIXME: Shouldn't this be on RenderBody::styleDidChange? | 762 // FIXME: Shouldn't this be on RenderBody::styleDidChange? |
| 753 if (element->hasTagName(bodyTag)) | 763 if (element->hasTagName(bodyTag)) |
| 754 document()->textLinkColors().setTextColor(state.style()->visitedDependen
tColor(CSSPropertyColor)); | 764 document()->textLinkColors().setTextColor(state.style()->visitedDependen
tColor(CSSPropertyColor)); |
| 755 | 765 |
| 756 // Now return the style. | 766 // Now return the style. |
| 757 return state.takeStyle(); | 767 return state.takeStyle(); |
| 758 } | 768 } |
| 759 | 769 |
| 760 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render
Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue
) | 770 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render
Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue
) |
| 761 { | 771 { |
| 772 if (e == document()->documentElement()) |
| 773 resetDirectionAndWritingModeOnDocument(document()); |
| 762 StyleResolveScope resolveScope(&m_state, document(), e); | 774 StyleResolveScope resolveScope(&m_state, document(), e); |
| 763 | 775 |
| 764 MatchResult result; | 776 MatchResult result; |
| 765 if (keyframe->properties()) | 777 if (keyframe->properties()) |
| 766 result.addMatchedProperties(keyframe->properties()); | 778 result.addMatchedProperties(keyframe->properties()); |
| 767 | 779 |
| 768 StyleResolverState& state = m_state; | 780 StyleResolverState& state = m_state; |
| 769 ASSERT(!state.style()); | 781 ASSERT(!state.style()); |
| 770 | 782 |
| 771 // Create the style | 783 // Create the style |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 list.insert(keyframeValue); | 887 list.insert(keyframeValue); |
| 876 } | 888 } |
| 877 } | 889 } |
| 878 | 890 |
| 879 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P
seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) | 891 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P
seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) |
| 880 { | 892 { |
| 881 ASSERT(parentStyle); | 893 ASSERT(parentStyle); |
| 882 if (!e) | 894 if (!e) |
| 883 return 0; | 895 return 0; |
| 884 | 896 |
| 897 if (e == document()->documentElement()) |
| 898 resetDirectionAndWritingModeOnDocument(document()); |
| 885 StyleResolverState& state = m_state; | 899 StyleResolverState& state = m_state; |
| 886 | |
| 887 StyleResolveScope resolveScope(&state, document(), e, parentStyle); | 900 StyleResolveScope resolveScope(&state, document(), e, parentStyle); |
| 888 | 901 |
| 889 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { | 902 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { |
| 890 state.setStyle(RenderStyle::create()); | 903 state.setStyle(RenderStyle::create()); |
| 891 state.style()->inheritFrom(state.parentStyle()); | 904 state.style()->inheritFrom(state.parentStyle()); |
| 892 } else { | 905 } else { |
| 893 state.setStyle(defaultStyleForElement()); | 906 state.setStyle(defaultStyleForElement()); |
| 894 state.setParentStyle(RenderStyle::clone(state.style())); | 907 state.setParentStyle(RenderStyle::clone(state.style())); |
| 895 } | 908 } |
| 896 | 909 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 922 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle
Resources()); | 935 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle
Resources()); |
| 923 | 936 |
| 924 document()->didAccessStyleResolver(); | 937 document()->didAccessStyleResolver(); |
| 925 | 938 |
| 926 // Now return the style. | 939 // Now return the style. |
| 927 return state.takeStyle(); | 940 return state.takeStyle(); |
| 928 } | 941 } |
| 929 | 942 |
| 930 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) | 943 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) |
| 931 { | 944 { |
| 945 resetDirectionAndWritingModeOnDocument(document()); |
| 932 StyleResolverState& state = m_state; | 946 StyleResolverState& state = m_state; |
| 933 StyleResolveScope resolveScope(&state, document(), document()->documentEleme
nt()); // m_rootElementStyle will be set to the document style. | 947 StyleResolveScope resolveScope(&state, document(), document()->documentEleme
nt()); // m_rootElementStyle will be set to the document style. |
| 934 | 948 |
| 935 state.setStyle(RenderStyle::create()); | 949 state.setStyle(RenderStyle::create()); |
| 936 state.style()->inheritFrom(state.rootElementStyle()); | 950 state.style()->inheritFrom(state.rootElementStyle()); |
| 937 | 951 |
| 938 PageRuleCollector collector(state.elementContext(), pageIndex); | 952 PageRuleCollector collector(state.elementContext(), pageIndex); |
| 939 | 953 |
| 940 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); | 954 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); |
| 941 collector.matchPageRules(m_ruleSets.userStyle()); | 955 collector.matchPageRules(m_ruleSets.userStyle()); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned
rulesToInclude) | 1393 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned
rulesToInclude) |
| 1380 { | 1394 { |
| 1381 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude); | 1395 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude); |
| 1382 } | 1396 } |
| 1383 | 1397 |
| 1384 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps
eudoId pseudoId, unsigned rulesToInclude) | 1398 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps
eudoId pseudoId, unsigned rulesToInclude) |
| 1385 { | 1399 { |
| 1386 if (!e || !e->document()->haveStylesheetsLoaded()) | 1400 if (!e || !e->document()->haveStylesheetsLoaded()) |
| 1387 return 0; | 1401 return 0; |
| 1388 | 1402 |
| 1403 if (e == document()->documentElement()) |
| 1404 resetDirectionAndWritingModeOnDocument(document()); |
| 1389 StyleResolveScope resolveScope(&m_state, document(), e); | 1405 StyleResolveScope resolveScope(&m_state, document(), e); |
| 1390 | 1406 |
| 1391 ElementRuleCollector collector(m_state.elementContext(), m_selectorFilter, m
_state.style(), m_inspectorCSSOMWrappers); | 1407 ElementRuleCollector collector(m_state.elementContext(), m_selectorFilter, m
_state.style(), m_inspectorCSSOMWrappers); |
| 1392 collector.setMode(SelectorChecker::CollectingRules); | 1408 collector.setMode(SelectorChecker::CollectingRules); |
| 1393 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); | 1409 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); |
| 1394 | 1410 |
| 1395 if (rulesToInclude & UAAndUserCSSRules) { | 1411 if (rulesToInclude & UAAndUserCSSRules) { |
| 1396 // First we match rules from the user agent sheet. | 1412 // First we match rules from the user agent sheet. |
| 1397 matchUARules(collector); | 1413 matchUARules(collector); |
| 1398 | 1414 |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 info.addMember(m_state, "state"); | 1954 info.addMember(m_state, "state"); |
| 1939 | 1955 |
| 1940 // FIXME: move this to a place where it would be called only once? | 1956 // FIXME: move this to a place where it would be called only once? |
| 1941 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); | 1957 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); |
| 1942 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl
e"); | 1958 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl
e"); |
| 1943 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle"
); | 1959 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle"
); |
| 1944 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo
urceStyle"); | 1960 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo
urceStyle"); |
| 1945 } | 1961 } |
| 1946 | 1962 |
| 1947 } // namespace WebCore | 1963 } // namespace WebCore |
| OLD | NEW |