Home | History | Annotate | Download | only in css
      1 /*
      2  * (C) 1999-2003 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      4  * Copyright (C) 2013 Intel Corporation. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #include "config.h"
     23 #include "StylePropertyShorthand.h"
     24 
     25 namespace WebCore {
     26 
     27 const StylePropertyShorthand& borderShorthandForParsing()
     28 {
     29     static const CSSPropertyID borderShorthandProperties[] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor };
     30     static const StylePropertyShorthand* propertiesForInitialization[] = {
     31         &borderWidthShorthand(),
     32         &borderStyleShorthand(),
     33         &borderColorShorthand(),
     34     };
     35     DEFINE_STATIC_LOCAL(StylePropertyShorthand, borderForParsingLonghands, (CSSPropertyBorder, borderShorthandProperties, propertiesForInitialization, WTF_ARRAY_LENGTH(borderShorthandProperties)));
     36     return borderForParsingLonghands;
     37 }
     38 
     39 const StylePropertyShorthand& webkitAnimationShorthandForParsing()
     40 {
     41     // When we parse the animation shorthand we need to look for animation-name
     42     // last because otherwise it might match against the keywords for fill mode,
     43     // timing functions and infinite iteration. This means that animation names
     44     // that are the same as keywords (e.g. 'forwards') won't always match in the
     45     // shorthand. In that case the authors should be using longhands (or
     46     // reconsidering their approach). This is covered by the animations spec
     47     // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790
     48     // And in the spec (editor's draft) at:
     49     // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property
     50     static const CSSPropertyID animationPropertiesForParsing[] = {
     51         CSSPropertyWebkitAnimationDuration,
     52         CSSPropertyWebkitAnimationTimingFunction,
     53         CSSPropertyWebkitAnimationDelay,
     54         CSSPropertyWebkitAnimationIterationCount,
     55         CSSPropertyWebkitAnimationDirection,
     56         CSSPropertyWebkitAnimationFillMode,
     57         CSSPropertyWebkitAnimationName
     58     };
     59     DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitAnimationLonghandsForParsing, (CSSPropertyWebkitAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing)));
     60     return webkitAnimationLonghandsForParsing;
     61 }
     62 
     63 bool isExpandedShorthand(CSSPropertyID id)
     64 {
     65     // The system fonts bypass the normal style resolution by using RenderTheme,
     66     // thus we need to special case it here. FIXME: This is a violation of CSS 3 Fonts
     67     // as we should still be able to change the longhands.
     68     // DON'T ADD ANY SHORTHAND HERE UNLESS IT ISN'T ALWAYS EXPANDED AT PARSE TIME (which is wrong).
     69     if (id == CSSPropertyFont)
     70         return false;
     71 
     72     return shorthandForProperty(id).length();
     73 }
     74 
     75 unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand>& shorthands)
     76 {
     77     for (unsigned i = 0; i < shorthands.size(); ++i) {
     78         if (shorthands.at(i).id() == shorthandID)
     79             return i;
     80     }
     81     ASSERT_NOT_REACHED();
     82     return 0;
     83 }
     84 
     85 } // namespace WebCore
     86