15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/* 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * (C) 1999-2003 Lars Knoll (knoll@kde.org) 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2013 Intel Corporation. All rights reserved. 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * This library is free software; you can redistribute it and/or 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * modify it under the terms of the GNU Library General Public 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * License as published by the Free Software Foundation; either 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * version 2 of the License, or (at your option) any later version. 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * This library is distributed in the hope that it will be useful, 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Library General Public License for more details. 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * You should have received a copy of the GNU Library General Public License 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * along with this library; see the file COPYING.LIB. If not, write to 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Boston, MA 02110-1301, USA. 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "config.h" 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "core/StylePropertyShorthand.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace blink { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const StylePropertyShorthand& borderShorthandForParsing() 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const CSSPropertyID borderShorthandProperties[] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor }; 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const StylePropertyShorthand* propertiesForInitialization[] = { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &borderWidthShorthand(), 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &borderStyleShorthand(), 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &borderColorShorthand(), 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DEFINE_STATIC_LOCAL(StylePropertyShorthand, borderForParsingLonghands, (CSSPropertyBorder, borderShorthandProperties, propertiesForInitialization, WTF_ARRAY_LENGTH(borderShorthandProperties))); 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return borderForParsingLonghands; 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const StylePropertyShorthand& animationShorthandForParsing() 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // When we parse the animation shorthand we need to look for animation-name 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // last because otherwise it might match against the keywords for fill mode, 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // timing functions and infinite iteration. This means that animation names 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // that are the same as keywords (e.g. 'forwards') won't always match in the 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // shorthand. In that case the authors should be using longhands (or 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // reconsidering their approach). This is covered by the animations spec 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // And in the spec (editor's draft) at: 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const CSSPropertyID animationPropertiesForParsing[] = { 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationDuration, 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationTimingFunction, 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationDelay, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationIterationCount, 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationDirection, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationFillMode, 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationPlayState, 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CSSPropertyAnimationName 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitAnimationLonghandsForParsing, (CSSPropertyAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing))); 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return webkitAnimationLonghandsForParsing; 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 64const StylePropertyShorthand& webkitAnimationShorthandForParsing() 65{ 66 // When we parse the animation shorthand we need to look for animation-name 67 // last because otherwise it might match against the keywords for fill mode, 68 // timing functions and infinite iteration. This means that animation names 69 // that are the same as keywords (e.g. 'forwards') won't always match in the 70 // shorthand. In that case the authors should be using longhands (or 71 // reconsidering their approach). This is covered by the animations spec 72 // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790 73 // And in the spec (editor's draft) at: 74 // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property 75 static const CSSPropertyID animationPropertiesForParsing[] = { 76 CSSPropertyWebkitAnimationDuration, 77 CSSPropertyWebkitAnimationTimingFunction, 78 CSSPropertyWebkitAnimationDelay, 79 CSSPropertyWebkitAnimationIterationCount, 80 CSSPropertyWebkitAnimationDirection, 81 CSSPropertyWebkitAnimationFillMode, 82 CSSPropertyWebkitAnimationPlayState, 83 CSSPropertyWebkitAnimationName 84 }; 85 DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitAnimationLonghandsForParsing, (CSSPropertyWebkitAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing))); 86 return webkitAnimationLonghandsForParsing; 87} 88 89// Similar to animations, we have property after timing-function and delay after duration 90const StylePropertyShorthand& transitionShorthandForParsing() 91{ 92 static const CSSPropertyID transitionProperties[] = { 93 CSSPropertyTransitionDuration, 94 CSSPropertyTransitionTimingFunction, 95 CSSPropertyTransitionDelay, 96 CSSPropertyTransitionProperty 97 }; 98 DEFINE_STATIC_LOCAL(StylePropertyShorthand, transitionLonghands, (CSSPropertyTransition, transitionProperties, WTF_ARRAY_LENGTH(transitionProperties))); 99 return transitionLonghands; 100} 101 102const StylePropertyShorthand& webkitTransitionShorthandForParsing() 103{ 104 static const CSSPropertyID webkitTransitionProperties[] = { 105 CSSPropertyWebkitTransitionDuration, 106 CSSPropertyWebkitTransitionTimingFunction, 107 CSSPropertyWebkitTransitionDelay, 108 CSSPropertyWebkitTransitionProperty 109 }; 110 DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitTransitionLonghands, (CSSPropertyWebkitTransition, webkitTransitionProperties, WTF_ARRAY_LENGTH(webkitTransitionProperties))); 111 return webkitTransitionLonghands; 112} 113 114// Returns an empty list if the property is not a shorthand, otherwise the list of longhands for parsing. 115const StylePropertyShorthand& parsingShorthandForProperty(CSSPropertyID propertyID) 116{ 117 switch (propertyID) { 118 case CSSPropertyAnimation: 119 return animationShorthandForParsing(); 120 case CSSPropertyBorder: 121 return borderShorthandForParsing(); 122 case CSSPropertyWebkitAnimation: 123 return webkitAnimationShorthandForParsing(); 124 case CSSPropertyTransition: 125 return transitionShorthandForParsing(); 126 case CSSPropertyWebkitTransition: 127 return webkitTransitionShorthandForParsing(); 128 default: 129 return shorthandForProperty(propertyID); 130 } 131} 132 133bool isExpandedShorthand(CSSPropertyID id) 134{ 135 // The system fonts bypass the normal style resolution by using RenderTheme, 136 // thus we need to special case it here. FIXME: This is a violation of CSS 3 Fonts 137 // as we should still be able to change the longhands. 138 // DON'T ADD ANY SHORTHAND HERE UNLESS IT ISN'T ALWAYS EXPANDED AT PARSE TIME (which is wrong). 139 if (id == CSSPropertyFont) 140 return false; 141 142 return shorthandForProperty(id).length(); 143} 144 145bool isExpandedShorthandForAll(CSSPropertyID propertyId) 146{ 147 // FIXME: isExpandedShorthand says "font" is not an expanded shorthand, 148 // but font is expanded to font-family, font-size, and so on. 149 // StylePropertySerializer::asText should not generate css text like 150 // "font: initial; font-family: initial;...". To avoid this, we need to 151 // treat "font" as an expanded shorthand. 152 // And while applying "all" property, we cannot apply "font" property 153 // directly. This causes ASSERT crash, because StyleBuilder assume that 154 // all given properties are not expanded shorthands. 155 // "marker" has the same issue. 156 if (propertyId == CSSPropertyMarker || propertyId == CSSPropertyFont) 157 return true; 158 return shorthandForProperty(propertyId).length(); 159} 160 161unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand, 4>& shorthands) 162{ 163 for (unsigned i = 0; i < shorthands.size(); ++i) { 164 if (shorthands.at(i).id() == shorthandID) 165 return i; 166 } 167 ASSERT_NOT_REACHED(); 168 return 0; 169} 170 171} // namespace blink 172