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

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 350333003: Cascade declared property values instead of applying values on top of each other (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 4 months 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
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. 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 13 matching lines...) Expand all
24 * along with this library; see the file COPYING.LIB. If not, write to 24 * along with this library; see the file COPYING.LIB. If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA. 26 * Boston, MA 02110-1301, USA.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/StyleResolver.h" 30 #include "core/css/resolver/StyleResolver.h"
31 31
32 #include "core/CSSPropertyNames.h" 32 #include "core/CSSPropertyNames.h"
33 #include "core/HTMLNames.h" 33 #include "core/HTMLNames.h"
34 #include "core/StylePropertyShorthand.h"
35 #include "core/animation/ActiveAnimations.h" 34 #include "core/animation/ActiveAnimations.h"
36 #include "core/animation/Animation.h" 35 #include "core/animation/Animation.h"
37 #include "core/animation/AnimationTimeline.h" 36 #include "core/animation/AnimationTimeline.h"
38 #include "core/animation/StyleInterpolation.h" 37 #include "core/animation/StyleInterpolation.h"
39 #include "core/animation/animatable/AnimatableValue.h" 38 #include "core/animation/animatable/AnimatableValue.h"
40 #include "core/animation/css/CSSAnimatableValueFactory.h" 39 #include "core/animation/css/CSSAnimatableValueFactory.h"
41 #include "core/animation/css/CSSAnimations.h" 40 #include "core/animation/css/CSSAnimations.h"
42 #include "core/css/CSSCalculationValue.h" 41 #include "core/css/CSSCalculationValue.h"
43 #include "core/css/CSSDefaultStyleSheets.h" 42 #include "core/css/CSSDefaultStyleSheets.h"
44 #include "core/css/CSSFontSelector.h" 43 #include "core/css/CSSFontSelector.h"
45 #include "core/css/CSSKeyframeRule.h" 44 #include "core/css/CSSKeyframeRule.h"
46 #include "core/css/CSSKeyframesRule.h" 45 #include "core/css/CSSKeyframesRule.h"
47 #include "core/css/CSSReflectValue.h" 46 #include "core/css/CSSReflectValue.h"
48 #include "core/css/CSSRuleList.h" 47 #include "core/css/CSSRuleList.h"
49 #include "core/css/CSSSelector.h" 48 #include "core/css/CSSSelector.h"
50 #include "core/css/CSSStyleRule.h" 49 #include "core/css/CSSStyleRule.h"
51 #include "core/css/CSSValueList.h" 50 #include "core/css/CSSValueList.h"
52 #include "core/css/CSSValuePool.h" 51 #include "core/css/CSSValuePool.h"
53 #include "core/css/ElementRuleCollector.h" 52 #include "core/css/ElementRuleCollector.h"
54 #include "core/css/FontFace.h" 53 #include "core/css/FontFace.h"
55 #include "core/css/MediaQueryEvaluator.h" 54 #include "core/css/MediaQueryEvaluator.h"
56 #include "core/css/PageRuleCollector.h" 55 #include "core/css/PageRuleCollector.h"
57 #include "core/css/StylePropertySet.h" 56 #include "core/css/StylePropertySet.h"
58 #include "core/css/StyleRuleImport.h" 57 #include "core/css/StyleRuleImport.h"
59 #include "core/css/StyleSheetContents.h" 58 #include "core/css/StyleSheetContents.h"
60 #include "core/css/parser/BisonCSSParser.h" 59 #include "core/css/parser/BisonCSSParser.h"
61 #include "core/css/resolver/AnimatedStyleBuilder.h" 60 #include "core/css/resolver/AnimatedStyleBuilder.h"
61 #include "core/css/resolver/CascadedValues.h"
62 #include "core/css/resolver/MatchResult.h" 62 #include "core/css/resolver/MatchResult.h"
63 #include "core/css/resolver/MediaQueryResult.h" 63 #include "core/css/resolver/MediaQueryResult.h"
64 #include "core/css/resolver/SharedStyleFinder.h" 64 #include "core/css/resolver/SharedStyleFinder.h"
65 #include "core/css/resolver/StyleAdjuster.h" 65 #include "core/css/resolver/StyleAdjuster.h"
66 #include "core/css/resolver/StyleResolverParentScope.h" 66 #include "core/css/resolver/StyleResolverParentScope.h"
67 #include "core/css/resolver/StyleResolverState.h" 67 #include "core/css/resolver/StyleResolverState.h"
68 #include "core/css/resolver/StyleResolverStats.h" 68 #include "core/css/resolver/StyleResolverStats.h"
69 #include "core/css/resolver/ViewportStyleResolver.h" 69 #include "core/css/resolver/ViewportStyleResolver.h"
70 #include "core/dom/CSSSelectorWatch.h" 70 #include "core/dom/CSSSelectorWatch.h"
71 #include "core/dom/NodeRenderStyle.h" 71 #include "core/dom/NodeRenderStyle.h"
(...skipping 18 matching lines...) Expand all
90 using namespace blink; 90 using namespace blink;
91 91
92 void setAnimationUpdateIfNeeded(StyleResolverState& state, Element& element) 92 void setAnimationUpdateIfNeeded(StyleResolverState& state, Element& element)
93 { 93 {
94 // If any changes to CSS Animations were detected, stash the update away for application after the 94 // If any changes to CSS Animations were detected, stash the update away for application after the
95 // render object is updated if we're in the appropriate scope. 95 // render object is updated if we're in the appropriate scope.
96 if (state.animationUpdate()) 96 if (state.animationUpdate())
97 element.ensureActiveAnimations().cssAnimations().setPendingUpdate(state. takeAnimationUpdate()); 97 element.ensureActiveAnimations().cssAnimations().setPendingUpdate(state. takeAnimationUpdate());
98 } 98 }
99 99
100 static bool elementTypeHasAppearanceFromUAStyle(const Element& element)
101 {
102 // These elements have -webkit-appearance specified in html.css
103 const AtomicString& localName = element.localName();
104 return localName == HTMLNames::inputTag
105 || localName == HTMLNames::textareaTag
106 || localName == HTMLNames::buttonTag
107 || localName == HTMLNames::progressTag
108 || localName == HTMLNames::selectTag
109 || localName == HTMLNames::meterTag;
110 }
111
100 } // namespace 112 } // namespace
101 113
102 namespace blink { 114 namespace blink {
103 115
104 using namespace HTMLNames; 116 using namespace HTMLNames;
105 117
106 RenderStyle* StyleResolver::s_styleNotYetAvailable; 118 RenderStyle* StyleResolver::s_styleNotYetAvailable;
107 119
108 static StylePropertySet* leftToRightDeclaration() 120 static StylePropertySet* leftToRightDeclaration()
109 { 121 {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 698
687 setAnimationUpdateIfNeeded(state, *element); 699 setAnimationUpdateIfNeeded(state, *element);
688 700
689 if (state.style()->hasViewportUnits()) 701 if (state.style()->hasViewportUnits())
690 document().setHasViewportUnits(); 702 document().setHasViewportUnits();
691 703
692 // Now return the style. 704 // Now return the style.
693 return state.takeStyle(); 705 return state.takeStyle();
694 } 706 }
695 707
708 // FIXME: Consider refactoring to create a new class which owns the following
709 // first/last/range properties.
710 // c.f. //src/third_party/WebKit/Source/core/css/CSSPropertyNames.in.
711
712 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::HighPr iorityProperties>()
713 {
714 COMPILE_ASSERT(CSSPropertyColor == CSSPropertyWebkitWritingMode + 1, CSS_col or_is_first_high_priority_property);
715 return CSSPropertyColor;
716 }
717
718 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::HighPri orityProperties>()
719 {
720 return CSSPropertyZoom;
721 }
722
723 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::LowPri orityProperties>()
724 {
725 COMPILE_ASSERT(CSSPropertyBackground == CSSPropertyZoom + 1, CSS_background_ is_first_low_priority_property);
726 return CSSPropertyBackground;
727 }
728
729 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::LowPrio rityProperties>()
730 {
731 return convertToCSSPropertyID(lastCSSProperty);
732 }
733
734 template <StyleResolver::StyleApplicationPass pass>
735 bool StyleResolver::isPropertyForPass(CSSPropertyID property)
736 {
737 return firstCSSPropertyId<pass>() <= property && property <= lastCSSProperty Id<pass>();
738 }
739
696 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra me, const AtomicString& animationName) 740 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra me, const AtomicString& animationName)
697 { 741 {
698 ASSERT(document().frame()); 742 ASSERT(document().frame());
699 ASSERT(document().settings()); 743 ASSERT(document().settings());
700 ASSERT(!hasPendingAuthorStyleSheets()); 744 ASSERT(!hasPendingAuthorStyleSheets());
701 745
702 if (element == document().documentElement()) 746 if (element == document().documentElement())
703 resetDirectionAndWritingModeOnDocument(document()); 747 resetDirectionAndWritingModeOnDocument(document());
704 StyleResolverState state(document(), element, parentStyle); 748 StyleResolverState state(document(), element, parentStyle);
705 749
706 MatchResult result; 750 MatchResult matchResult;
707 result.addMatchedProperties(&keyframe->properties()); 751 matchResult.addMatchedProperties(&keyframe->properties());
708 752
709 ASSERT(!state.style()); 753 ASSERT(!state.style());
710 754
711 // Create the style 755 // Create the style
712 state.setStyle(RenderStyle::clone(&elementStyle)); 756 state.setStyle(RenderStyle::clone(&elementStyle));
713 state.setLineHeightValue(0);
714 757
715 state.fontBuilder().initForStyleResolve(state.document(), state.style()); 758 state.fontBuilder().initForStyleResolve(state.document(), state.style());
716 759
717 // We don't need to bother with !important. Since there is only ever one 760 CascadedValues cascadedValues(state, matchResult);
718 // decl, there's nothing to override. So just add the first properties. 761
719 // We also don't need to bother with animation properties since the only 762 cascadedValues.applyValues(firstCSSPropertyId<HighPriorityProperties>(), las tCSSPropertyId<HighPriorityProperties>());
720 // relevant one is animation-timing-function and we special-case that in
721 // CSSAnimations.cpp
722 bool inheritedOnly = false;
723 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly);
724 763
725 // If our font got dirtied, go ahead and update it now. 764 // If our font got dirtied, go ahead and update it now.
726 updateFont(state); 765 updateFont(state);
727 766
728 // Line-height is set when we are sure we decided on the font-size 767 cascadedValues.applyValues(firstCSSPropertyId<LowPriorityProperties>(), last CSSPropertyId<LowPriorityProperties>());
729 if (state.lineHeightValue())
730 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
731
732 // Now do rest of the properties.
733 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
734 768
735 // If our font got dirtied by one of the non-essential font props, 769 // If our font got dirtied by one of the non-essential font props,
736 // go ahead and update it a second time. 770 // go ahead and update it a second time.
737 updateFont(state); 771 updateFont(state);
738 772
739 loadPendingResources(state); 773 loadPendingResources(state);
740 774
741 didAccess(); 775 didAccess();
742 776
743 return state.takeStyle(); 777 return state.takeStyle();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 928
895 state.fontBuilder().initForStyleResolve(state.document(), state.style()); 929 state.fontBuilder().initForStyleResolve(state.document(), state.style());
896 930
897 PageRuleCollector collector(rootElementStyle, pageIndex); 931 PageRuleCollector collector(rootElementStyle, pageIndex);
898 932
899 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ()); 933 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ());
900 934
901 if (ScopedStyleResolver* scopedResolver = m_document.scopedStyleResolver()) 935 if (ScopedStyleResolver* scopedResolver = m_document.scopedStyleResolver())
902 scopedResolver->matchPageRules(collector); 936 scopedResolver->matchPageRules(collector);
903 937
904 state.setLineHeightValue(0); 938 MatchResult& matchResult = collector.matchedResult();
905 bool inheritedOnly = false; 939 CascadedValues cascadedValues(state, matchResult);
906 940
907 MatchResult& result = collector.matchedResult(); 941 cascadedValues.applyValues(firstCSSPropertyId<HighPriorityProperties>(), las tCSSPropertyId<HighPriorityProperties>());
908 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly);
909 942
910 // If our font got dirtied, go ahead and update it now. 943 // If our font got dirtied, go ahead and update it now.
911 updateFont(state); 944 updateFont(state);
912 945
913 // Line-height is set when we are sure we decided on the font-size. 946 cascadedValues.applyValues(firstCSSPropertyId<LowPriorityProperties>(), last CSSPropertyId<LowPriorityProperties>());
914 if (state.lineHeightValue())
915 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
916
917 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
918 947
919 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); 948 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features);
920 949
921 loadPendingResources(state); 950 loadPendingResources(state);
922 951
923 didAccess(); 952 didAccess();
924 953
925 // Now return the style. 954 // Now return the style.
926 return state.takeStyle(); 955 return state.takeStyle();
927 } 956 }
(...skipping 14 matching lines...) Expand all
942 971
943 viewportStyleResolver()->resolve(); 972 viewportStyleResolver()->resolve();
944 } 973 }
945 974
946 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() 975 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
947 { 976 {
948 StyleResolverState state(document(), 0); 977 StyleResolverState state(document(), 0);
949 state.setStyle(RenderStyle::create()); 978 state.setStyle(RenderStyle::create());
950 state.fontBuilder().initForStyleResolve(document(), state.style()); 979 state.fontBuilder().initForStyleResolve(document(), state.style());
951 state.style()->setLineHeight(RenderStyle::initialLineHeight()); 980 state.style()->setLineHeight(RenderStyle::initialLineHeight());
952 state.setLineHeightValue(0);
953 state.fontBuilder().setInitial(state.style()->effectiveZoom()); 981 state.fontBuilder().setInitial(state.style()->effectiveZoom());
954 state.style()->font().update(document().styleEngine()->fontSelector()); 982 state.style()->font().update(document().styleEngine()->fontSelector());
955 return state.takeStyle(); 983 return state.takeStyle();
956 } 984 }
957 985
958 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) 986 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode)
959 { 987 {
960 ASSERT(textNode); 988 ASSERT(textNode);
961 989
962 Node* parentNode = NodeRenderingTraversal::parent(textNode); 990 Node* parentNode = NodeRenderingTraversal::parent(textNode);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 if (!(animatingElement && animatingElement->hasActiveAnimations()) 1054 if (!(animatingElement && animatingElement->hasActiveAnimations())
1027 && !state.style()->transitions() && !state.style()->animations()) 1055 && !state.style()->transitions() && !state.style()->animations())
1028 return false; 1056 return false;
1029 1057
1030 state.setAnimationUpdate(CSSAnimations::calculateUpdate(animatingElement, *e lement, *state.style(), state.parentStyle(), this)); 1058 state.setAnimationUpdate(CSSAnimations::calculateUpdate(animatingElement, *e lement, *state.style(), state.parentStyle(), this));
1031 if (!state.animationUpdate()) 1059 if (!state.animationUpdate())
1032 return false; 1060 return false;
1033 1061
1034 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForAnimations = state.animationUpdate()->activeInterpolation sForAnimations(); 1062 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForAnimations = state.animationUpdate()->activeInterpolation sForAnimations();
1035 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForTransitions = state.animationUpdate()->activeInterpolatio nsForTransitions(); 1063 const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpolationsForTransitions = state.animationUpdate()->activeInterpolatio nsForTransitions();
1064
1065 // FIXME: Is it possible to use CascadedValues here or is it too expensive t o
1066 // convert from Interpolations to CSSValues?
1036 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orAnimations); 1067 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orAnimations);
1037 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orTransitions); 1068 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orTransitions);
1038 1069
1039 updateFont(state); 1070 updateFont(state);
1040 1071
1041 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rAnimations); 1072 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rAnimations);
1042 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions); 1073 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions);
1043 1074
1044 // Start loading resources used by animations. 1075 // Start loading resources used by animations.
1045 loadPendingResources(state); 1076 loadPendingResources(state);
1046 1077
1047 ASSERT(!state.fontBuilder().fontDirty()); 1078 ASSERT(!state.fontBuilder().fontDirty());
1048 1079
1049 return true; 1080 return true;
1050 } 1081 }
1051 1082
1052 template <StyleResolver::StyleApplicationPass pass> 1083 template <StyleResolver::StyleApplicationPass pass>
1053 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Wil lBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpo lations) 1084 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Wil lBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >& activeInterpo lations)
1054 { 1085 {
1055 for (WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >::c onst_iterator iter = activeInterpolations.begin(); iter != activeInterpolations. end(); ++iter) { 1086 for (WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >::c onst_iterator iter = activeInterpolations.begin(); iter != activeInterpolations. end(); ++iter) {
1056 CSSPropertyID property = iter->key; 1087 CSSPropertyID property = iter->key;
1057 if (!isPropertyForPass<pass>(property)) 1088 if (!isPropertyForPass<pass>(property))
1058 continue; 1089 continue;
1059 const StyleInterpolation* interpolation = toStyleInterpolation(iter->val ue.get()); 1090 const StyleInterpolation* interpolation = toStyleInterpolation(iter->val ue.get());
1060 interpolation->apply(state); 1091 interpolation->apply(state);
1061 } 1092 }
1062 } 1093 }
1063 1094
1064 static inline bool isValidCueStyleProperty(CSSPropertyID id)
1065 {
1066 switch (id) {
1067 case CSSPropertyBackground:
1068 case CSSPropertyBackgroundAttachment:
1069 case CSSPropertyBackgroundClip:
1070 case CSSPropertyBackgroundColor:
1071 case CSSPropertyBackgroundImage:
1072 case CSSPropertyBackgroundOrigin:
1073 case CSSPropertyBackgroundPosition:
1074 case CSSPropertyBackgroundPositionX:
1075 case CSSPropertyBackgroundPositionY:
1076 case CSSPropertyBackgroundRepeat:
1077 case CSSPropertyBackgroundRepeatX:
1078 case CSSPropertyBackgroundRepeatY:
1079 case CSSPropertyBackgroundSize:
1080 case CSSPropertyColor:
1081 case CSSPropertyFont:
1082 case CSSPropertyFontFamily:
1083 case CSSPropertyFontSize:
1084 case CSSPropertyFontStretch:
1085 case CSSPropertyFontStyle:
1086 case CSSPropertyFontVariant:
1087 case CSSPropertyFontWeight:
1088 case CSSPropertyLineHeight:
1089 case CSSPropertyOpacity:
1090 case CSSPropertyOutline:
1091 case CSSPropertyOutlineColor:
1092 case CSSPropertyOutlineOffset:
1093 case CSSPropertyOutlineStyle:
1094 case CSSPropertyOutlineWidth:
1095 case CSSPropertyVisibility:
1096 case CSSPropertyWhiteSpace:
1097 // FIXME: 'text-decoration' shorthand to be handled when available.
1098 // See https://chromiumcodereview.appspot.com/19516002 for details.
1099 case CSSPropertyTextDecoration:
1100 case CSSPropertyTextShadow:
1101 case CSSPropertyBorderStyle:
1102 return true;
1103 case CSSPropertyTextDecorationLine:
1104 case CSSPropertyTextDecorationStyle:
1105 case CSSPropertyTextDecorationColor:
1106 return RuntimeEnabledFeatures::css3TextDecorationsEnabled();
1107 default:
1108 break;
1109 }
1110 return false;
1111 }
1112
1113 static inline bool isValidFirstLetterStyleProperty(CSSPropertyID id)
1114 {
1115 switch (id) {
1116 // Valid ::first-letter properties listed in spec:
1117 // http://www.w3.org/TR/css3-selectors/#application-in-css
1118 case CSSPropertyBackgroundAttachment:
1119 case CSSPropertyBackgroundBlendMode:
1120 case CSSPropertyBackgroundClip:
1121 case CSSPropertyBackgroundColor:
1122 case CSSPropertyBackgroundImage:
1123 case CSSPropertyBackgroundOrigin:
1124 case CSSPropertyBackgroundPosition:
1125 case CSSPropertyBackgroundPositionX:
1126 case CSSPropertyBackgroundPositionY:
1127 case CSSPropertyBackgroundRepeat:
1128 case CSSPropertyBackgroundRepeatX:
1129 case CSSPropertyBackgroundRepeatY:
1130 case CSSPropertyBackgroundSize:
1131 case CSSPropertyBorderBottomColor:
1132 case CSSPropertyBorderBottomLeftRadius:
1133 case CSSPropertyBorderBottomRightRadius:
1134 case CSSPropertyBorderBottomStyle:
1135 case CSSPropertyBorderBottomWidth:
1136 case CSSPropertyBorderImageOutset:
1137 case CSSPropertyBorderImageRepeat:
1138 case CSSPropertyBorderImageSlice:
1139 case CSSPropertyBorderImageSource:
1140 case CSSPropertyBorderImageWidth:
1141 case CSSPropertyBorderLeftColor:
1142 case CSSPropertyBorderLeftStyle:
1143 case CSSPropertyBorderLeftWidth:
1144 case CSSPropertyBorderRightColor:
1145 case CSSPropertyBorderRightStyle:
1146 case CSSPropertyBorderRightWidth:
1147 case CSSPropertyBorderTopColor:
1148 case CSSPropertyBorderTopLeftRadius:
1149 case CSSPropertyBorderTopRightRadius:
1150 case CSSPropertyBorderTopStyle:
1151 case CSSPropertyBorderTopWidth:
1152 case CSSPropertyColor:
1153 case CSSPropertyFloat:
1154 case CSSPropertyFont:
1155 case CSSPropertyFontFamily:
1156 case CSSPropertyFontKerning:
1157 case CSSPropertyFontSize:
1158 case CSSPropertyFontStretch:
1159 case CSSPropertyFontStyle:
1160 case CSSPropertyFontVariant:
1161 case CSSPropertyFontVariantLigatures:
1162 case CSSPropertyFontWeight:
1163 case CSSPropertyLetterSpacing:
1164 case CSSPropertyLineHeight:
1165 case CSSPropertyMarginBottom:
1166 case CSSPropertyMarginLeft:
1167 case CSSPropertyMarginRight:
1168 case CSSPropertyMarginTop:
1169 case CSSPropertyPaddingBottom:
1170 case CSSPropertyPaddingLeft:
1171 case CSSPropertyPaddingRight:
1172 case CSSPropertyPaddingTop:
1173 case CSSPropertyTextTransform:
1174 case CSSPropertyVerticalAlign:
1175 case CSSPropertyWebkitBackgroundClip:
1176 case CSSPropertyWebkitBackgroundComposite:
1177 case CSSPropertyWebkitBackgroundOrigin:
1178 case CSSPropertyWebkitBackgroundSize:
1179 case CSSPropertyWebkitBorderAfter:
1180 case CSSPropertyWebkitBorderAfterColor:
1181 case CSSPropertyWebkitBorderAfterStyle:
1182 case CSSPropertyWebkitBorderAfterWidth:
1183 case CSSPropertyWebkitBorderBefore:
1184 case CSSPropertyWebkitBorderBeforeColor:
1185 case CSSPropertyWebkitBorderBeforeStyle:
1186 case CSSPropertyWebkitBorderBeforeWidth:
1187 case CSSPropertyWebkitBorderEnd:
1188 case CSSPropertyWebkitBorderEndColor:
1189 case CSSPropertyWebkitBorderEndStyle:
1190 case CSSPropertyWebkitBorderEndWidth:
1191 case CSSPropertyWebkitBorderFit:
1192 case CSSPropertyWebkitBorderHorizontalSpacing:
1193 case CSSPropertyWebkitBorderImage:
1194 case CSSPropertyWebkitBorderRadius:
1195 case CSSPropertyWebkitBorderStart:
1196 case CSSPropertyWebkitBorderStartColor:
1197 case CSSPropertyWebkitBorderStartStyle:
1198 case CSSPropertyWebkitBorderStartWidth:
1199 case CSSPropertyWebkitBorderVerticalSpacing:
1200 case CSSPropertyWebkitFontSmoothing:
1201 case CSSPropertyWebkitMarginAfter:
1202 case CSSPropertyWebkitMarginAfterCollapse:
1203 case CSSPropertyWebkitMarginBefore:
1204 case CSSPropertyWebkitMarginBeforeCollapse:
1205 case CSSPropertyWebkitMarginBottomCollapse:
1206 case CSSPropertyWebkitMarginCollapse:
1207 case CSSPropertyWebkitMarginEnd:
1208 case CSSPropertyWebkitMarginStart:
1209 case CSSPropertyWebkitMarginTopCollapse:
1210 case CSSPropertyWordSpacing:
1211 return true;
1212 case CSSPropertyTextDecorationColor:
1213 case CSSPropertyTextDecorationLine:
1214 case CSSPropertyTextDecorationStyle:
1215 return RuntimeEnabledFeatures::css3TextDecorationsEnabled();
1216
1217 // text-shadow added in text decoration spec:
1218 // http://www.w3.org/TR/css-text-decor-3/#text-shadow-property
1219 case CSSPropertyTextShadow:
1220 // box-shadox added in CSS3 backgrounds spec:
1221 // http://www.w3.org/TR/css3-background/#placement
1222 case CSSPropertyBoxShadow:
1223 case CSSPropertyWebkitBoxShadow:
1224 // Properties that we currently support outside of spec.
1225 case CSSPropertyWebkitLineBoxContain:
1226 case CSSPropertyVisibility:
1227 return true;
1228
1229 default:
1230 return false;
1231 }
1232 }
1233
1234 // FIXME: Consider refactoring to create a new class which owns the following
1235 // first/last/range properties.
1236 // This method returns the first CSSPropertyId of high priority properties.
1237 // Other properties can depend on high priority properties. For example,
1238 // border-color property with currentColor value depends on color property.
1239 // All high priority properties are obtained by using
1240 // firstCSSPropertyId<HighPriorityProperties> and
1241 // lastCSSPropertyId<HighPriorityProperties>.
1242 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::HighPr iorityProperties>()
1243 {
1244 COMPILE_ASSERT(CSSPropertyColor == firstCSSProperty, CSS_color_is_first_high _priority_property);
1245 return CSSPropertyColor;
1246 }
1247
1248 // This method returns the last CSSPropertyId of high priority properties.
1249 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::HighPri orityProperties>()
1250 {
1251 COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyColor + 18, CSS_line_heig ht_is_end_of_high_prioity_property_range);
1252 COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyLineHeight - 1, CSS_zoom_is_bef ore_line_height);
1253 return CSSPropertyLineHeight;
1254 }
1255
1256 // This method returns the first CSSPropertyId of remaining properties,
1257 // i.e. low priority properties. No properties depend on low priority
1258 // properties. So we don't need to resolve such properties quickly.
1259 // All low priority properties are obtained by using
1260 // firstCSSPropertyId<LowPriorityProperties> and
1261 // lastCSSPropertyId<LowPriorityProperties>.
1262 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::LowPri orityProperties>()
1263 {
1264 COMPILE_ASSERT(CSSPropertyBackground == CSSPropertyLineHeight + 1, CSS_backg round_is_first_low_priority_property);
1265 return CSSPropertyBackground;
1266 }
1267
1268 // This method returns the last CSSPropertyId of low priority properties.
1269 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::LowPrio rityProperties>()
1270 {
1271 return static_cast<CSSPropertyID>(lastCSSProperty);
1272 }
1273
1274 template <StyleResolver::StyleApplicationPass pass>
1275 bool StyleResolver::isPropertyForPass(CSSPropertyID property)
1276 {
1277 return firstCSSPropertyId<pass>() <= property && property <= lastCSSProperty Id<pass>();
1278 }
1279
1280 // This method expands the 'all' shorthand property to longhand properties
1281 // and applies the expanded longhand properties.
1282 template <StyleResolver::StyleApplicationPass pass>
1283 void StyleResolver::applyAllProperty(StyleResolverState& state, CSSValue* allVal ue)
1284 {
1285 bool isUnsetValue = !allValue->isInitialValue() && !allValue->isInheritedVal ue();
1286 unsigned startCSSProperty = firstCSSPropertyId<pass>();
1287 unsigned endCSSProperty = lastCSSPropertyId<pass>();
1288
1289 for (unsigned i = startCSSProperty; i <= endCSSProperty; ++i) {
1290 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
1291
1292 // StyleBuilder does not allow any expanded shorthands.
1293 if (isExpandedShorthandForAll(propertyId))
1294 continue;
1295
1296 // all shorthand spec says:
1297 // The all property is a shorthand that resets all CSS properties
1298 // except direction and unicode-bidi.
1299 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand
1300 // We skip applyProperty when a given property is unicode-bidi or
1301 // direction.
1302 if (!CSSProperty::isAffectedByAllProperty(propertyId))
1303 continue;
1304
1305 CSSValue* value;
1306 if (!isUnsetValue) {
1307 value = allValue;
1308 } else {
1309 if (CSSProperty::isInheritedProperty(propertyId))
1310 value = cssValuePool().createInheritedValue().get();
1311 else
1312 value = cssValuePool().createExplicitInitialValue().get();
1313 }
1314 StyleBuilder::applyProperty(propertyId, state, value);
1315 }
1316 }
1317
1318 template <StyleResolver::StyleApplicationPass pass>
1319 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, Proper tyWhitelistType propertyWhitelistType)
1320 {
1321 state.setCurrentRule(rule);
1322
1323 unsigned propertyCount = properties->propertyCount();
1324 for (unsigned i = 0; i < propertyCount; ++i) {
1325 StylePropertySet::PropertyReference current = properties->propertyAt(i);
1326 if (isImportant != current.isImportant())
1327 continue;
1328
1329 CSSPropertyID property = current.id();
1330 if (property == CSSPropertyAll) {
1331 applyAllProperty<pass>(state, current.value());
1332 continue;
1333 }
1334
1335 if (inheritedOnly && !current.isInherited()) {
1336 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties
1337 // as they might override the value inherited here. For this reason we don't allow declarations with
1338 // explicitly inherited properties to be cached.
1339 ASSERT(!current.value()->isInheritedValue());
1340 continue;
1341 }
1342
1343 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property))
1344 continue;
1345 if (propertyWhitelistType == PropertyWhitelistFirstLetter && !isValidFir stLetterStyleProperty(property))
1346 continue;
1347 if (!isPropertyForPass<pass>(property))
1348 continue;
1349 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
1350 state.setLineHeightValue(current.value());
1351 else
1352 StyleBuilder::applyProperty(current.id(), state, current.value());
1353 }
1354 }
1355
1356 template <StyleResolver::StyleApplicationPass pass>
1357 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher itedOnly)
1358 {
1359 if (startIndex == -1)
1360 return;
1361
1362 if (state.style()->insideLink() != NotInsideLink) {
1363 for (int i = startIndex; i <= endIndex; ++i) {
1364 const MatchedProperties& matchedProperties = matchResult.matchedProp erties[i];
1365 unsigned linkMatchType = matchedProperties.m_types.linkMatchType;
1366 // FIXME: It would be nicer to pass these as arguments but that requ ires changes in many places.
1367 state.setApplyPropertyToRegularStyle(linkMatchType & SelectorChecker ::MatchLink);
1368 state.setApplyPropertyToVisitedLinkStyle(linkMatchType & SelectorChe cker::MatchVisited);
1369
1370 applyProperties<pass>(state, matchedProperties.properties.get(), mat chResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitel istType>(matchedProperties.m_types.whitelistType));
1371 }
1372 state.setApplyPropertyToRegularStyle(true);
1373 state.setApplyPropertyToVisitedLinkStyle(false);
1374 return;
1375 }
1376 for (int i = startIndex; i <= endIndex; ++i) {
1377 const MatchedProperties& matchedProperties = matchResult.matchedProperti es[i];
1378 applyProperties<pass>(state, matchedProperties.properties.get(), matchRe sult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistT ype>(matchedProperties.m_types.whitelistType));
1379 }
1380 }
1381
1382 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size) 1095 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size)
1383 { 1096 {
1384 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size ); 1097 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size );
1385 } 1098 }
1386 1099
1387 void StyleResolver::invalidateMatchedPropertiesCache() 1100 void StyleResolver::invalidateMatchedPropertiesCache()
1388 { 1101 {
1389 m_matchedPropertiesCache.clear(); 1102 m_matchedPropertiesCache.clear();
1390 } 1103 }
1391 1104
(...skipping 29 matching lines...) Expand all
1421 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done. 1134 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done.
1422 state.style()->inheritFrom(cachedMatchedProperties->renderStyle.get( )); 1135 state.style()->inheritFrom(cachedMatchedProperties->renderStyle.get( ));
1423 1136
1424 // Unfortunately the link status is treated like an inherited proper ty. We need to explicitly restore it. 1137 // Unfortunately the link status is treated like an inherited proper ty. We need to explicitly restore it.
1425 state.style()->setInsideLink(linkStatus); 1138 state.style()->setInsideLink(linkStatus);
1426 return; 1139 return;
1427 } 1140 }
1428 applyInheritedOnly = true; 1141 applyInheritedOnly = true;
1429 } 1142 }
1430 1143
1431 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply 1144 CascadedValues cascadedValues(state, matchResult);
1432 // high-priority properties first, i.e., those properties that other propert ies depend on. 1145 cascadedValues.applyValues(firstCSSPropertyId<HighPriorityProperties>(), las tCSSPropertyId<HighPriorityProperties>(), applyInheritedOnly);
1433 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important
1434 // and (4) normal important.
1435 state.setLineHeightValue(0);
1436 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
1437 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, mat chResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherit edOnly);
1438 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, mat chResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOn ly);
1439 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1440 1146
1441 if (UNLIKELY(isSVGForeignObjectElement(element))) { 1147 if (UNLIKELY(isSVGForeignObjectElement(element))) {
1442 // RenderSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should not be scaled again. 1148 // RenderSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should not be scaled again.
1443 // 1149 //
1444 // FIXME: The following hijacks the zoom property for foreignObject so t hat children of foreignObject get the 1150 // FIXME: The following hijacks the zoom property for foreignObject so t hat children of foreignObject get the
1445 // correct font-size in case of zooming. 'zoom' is part of HighPriorityP roperties, along with other font-related 1151 // correct font-size in case of zooming. 'zoom' is part of HighPriorityP roperties, along with other font-related
1446 // properties used as input to the FontBuilder, so resetting it here may cause the FontBuilder to recompute the 1152 // properties used as input to the FontBuilder, so resetting it here may cause the FontBuilder to recompute the
1447 // font used as inheritable font for foreignObject content. If we want t o support zoom on foreignObject we'll 1153 // font used as inheritable font for foreignObject content. If we want t o support zoom on foreignObject we'll
1448 // need to find another way of handling the SVG zoom model. 1154 // need to find another way of handling the SVG zoom model.
1449 state.setEffectiveZoom(RenderStyle::initialZoom()); 1155 state.setEffectiveZoom(RenderStyle::initialZoom());
1450 } 1156 }
1451 1157
1452 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) { 1158 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) {
1453 state.fontBuilder().setFontDirty(true); 1159 state.fontBuilder().setFontDirty(true);
1454 applyInheritedOnly = false; 1160 applyInheritedOnly = false;
1455 } 1161 }
1456 1162
1457 // If our font got dirtied, go ahead and update it now. 1163 // If our font got dirtied, go ahead and update it now.
1458 updateFont(state); 1164 updateFont(state);
1459 1165
1460 // Line-height is set when we are sure we decided on the font-size.
1461 if (state.lineHeightValue())
1462 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
1463
1464 // Many properties depend on the font. If it changes we just apply all prope rties. 1166 // Many properties depend on the font. If it changes we just apply all prope rties.
1465 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription()) 1167 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription())
1466 applyInheritedOnly = false; 1168 applyInheritedOnly = false;
1467 1169
1468 // Now do the normal priority UA properties. 1170 // This code supports -webkit-appearance, for which we are interested
1469 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1171 // in whether the user has specified border or background properties.
1172 // FIXME: This is a bit of a mess, we should just compare CSSValues and
1173 // store a single bit for this.
1174 if (elementTypeHasAppearanceFromUAStyle(*element)) {
1175 CascadedValues userAgentValues(state, matchResult, true);
1176 // We only actually care about border and background properties here
1177 userAgentValues.applyValues(firstCSSPropertyId<LowPriorityProperties>(), lastCSSPropertyId<LowPriorityProperties>(), applyInheritedOnly);
1178 state.cacheUserAgentBorderAndBackground();
1179 }
1470 1180
1471 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle. 1181 cascadedValues.applyValues(firstCSSPropertyId<LowPriorityProperties>(), last CSSPropertyId<LowPriorityProperties>(), applyInheritedOnly);
1472 state.cacheUserAgentBorderAndBackground();
1473
1474 // Now do the author and user normal priority properties and all the !import ant properties.
1475 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyI nheritedOnly);
1476 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherite dOnly);
1477 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnl y);
1478 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1479 1182
1480 loadPendingResources(state); 1183 loadPendingResources(state);
1481 1184
1482 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) { 1185 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) {
1483 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded); 1186 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded);
1484 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult); 1187 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult);
1485 } 1188 }
1486 1189
1487 ASSERT(!state.fontBuilder().fontDirty()); 1190 ASSERT(!state.fontBuilder().fontDirty());
1488 } 1191 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 visitor->trace(m_siblingRuleSet); 1274 visitor->trace(m_siblingRuleSet);
1572 visitor->trace(m_uncommonAttributeRuleSet); 1275 visitor->trace(m_uncommonAttributeRuleSet);
1573 visitor->trace(m_watchedSelectorsRules); 1276 visitor->trace(m_watchedSelectorsRules);
1574 visitor->trace(m_treeBoundaryCrossingRules); 1277 visitor->trace(m_treeBoundaryCrossingRules);
1575 visitor->trace(m_pendingStyleSheets); 1278 visitor->trace(m_pendingStyleSheets);
1576 visitor->trace(m_styleTree); 1279 visitor->trace(m_styleTree);
1577 #endif 1280 #endif
1578 } 1281 }
1579 1282
1580 } // namespace blink 1283 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698