• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  *     * Redistributions of source code must retain the above copyright
5  * notice, this list of conditions and the following disclaimer.
6  *     * Redistributions in binary form must reproduce the above
7  * copyright notice, this list of conditions and the following disclaimer
8  * in the documentation and/or other materials provided with the
9  * distribution.
10  *     * Neither the name of Google Inc. nor the names of its
11  * contributors may be used to endorse or promote products derived from
12  * this software without specific prior written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef StyleBuilderConverter_h
28 #define StyleBuilderConverter_h
29 
30 #include "core/css/CSSValue.h"
31 #include "core/css/resolver/StyleResolverState.h"
32 #include "core/rendering/RenderView.h"
33 #include "core/rendering/style/QuotesData.h"
34 #include "core/rendering/style/ShadowList.h"
35 #include "core/rendering/style/StyleReflection.h"
36 #include "core/svg/SVGLength.h"
37 #include "platform/LengthSize.h"
38 
39 namespace WebCore {
40 
41 // Note that we assume the parser only allows valid CSSValue types.
42 
43 class StyleBuilderConverter {
44 public:
45     static PassRefPtr<StyleReflection> convertBoxReflect(StyleResolverState&, CSSValue*);
46     static AtomicString convertFragmentIdentifier(StyleResolverState&, CSSValue*);
47     template <typename T> static T convertComputedLength(StyleResolverState&, CSSValue*);
48     static EGlyphOrientation convertGlyphOrientation(StyleResolverState&, CSSValue*);
49     static GridPosition convertGridPosition(StyleResolverState&, CSSValue*);
50     static GridTrackSize convertGridTrackSize(StyleResolverState&, CSSValue*);
51     template <typename T> static T convertLineWidth(StyleResolverState&, CSSValue*);
52     static Length convertLength(StyleResolverState&, CSSValue*);
53     static Length convertLengthOrAuto(StyleResolverState&, CSSValue*);
54     static Length convertLengthSizing(StyleResolverState&, CSSValue*);
55     static Length convertLengthMaxSizing(StyleResolverState&, CSSValue*);
56     static LengthPoint convertLengthPoint(StyleResolverState&, CSSValue*);
57     static LineBoxContain convertLineBoxContain(StyleResolverState&, CSSValue*);
58     static float convertNumberOrPercentage(StyleResolverState&, CSSValue*);
59     static PassRefPtr<QuotesData> convertQuotes(StyleResolverState&, CSSValue*);
60     static LengthSize convertRadius(StyleResolverState&, CSSValue*);
61     static EPaintOrder convertPaintOrder(StyleResolverState&, CSSValue*);
62     static PassRefPtr<ShadowList> convertShadow(StyleResolverState&, CSSValue*);
63     static float convertSpacing(StyleResolverState&, CSSValue*);
64     template <CSSValueID IdForNone> static AtomicString convertString(StyleResolverState&, CSSValue*);
65     static PassRefPtr<SVGLengthList> convertStrokeDasharray(StyleResolverState&, CSSValue*);
66     static Color convertSVGColor(StyleResolverState&, CSSValue*);
67     static PassRefPtr<SVGLength> convertSVGLength(StyleResolverState&, CSSValue*);
68     static float convertTextStrokeWidth(StyleResolverState&, CSSValue*);
69 
70     static bool convertGridTrackList(CSSValue*, Vector<GridTrackSize>&, NamedGridLinesMap&, OrderedNamedGridLines&, StyleResolverState&);
71     static void createImplicitNamedGridLinesFromGridArea(const NamedGridAreaMap&, NamedGridLinesMap&, GridTrackSizingDirection);
72 };
73 
74 template <typename T>
convertComputedLength(StyleResolverState & state,CSSValue * value)75 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, CSSValue* value)
76 {
77     return toCSSPrimitiveValue(value)->computeLength<T>(state.cssToLengthConversionData());
78 }
79 
80 template <typename T>
convertLineWidth(StyleResolverState & state,CSSValue * value)81 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, CSSValue* value)
82 {
83     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
84     CSSValueID valueID = primitiveValue->getValueID();
85     if (valueID == CSSValueThin)
86         return 1;
87     if (valueID == CSSValueMedium)
88         return 3;
89     if (valueID == CSSValueThick)
90         return 5;
91     if (valueID == CSSValueInvalid) {
92         // Any original result that was >= 1 should not be allowed to fall below 1.
93         // This keeps border lines from vanishing.
94         T result = primitiveValue->computeLength<T>(state.cssToLengthConversionData());
95         if (state.style()->effectiveZoom() < 1.0f && result < 1.0) {
96             T originalLength = primitiveValue->computeLength<T>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
97             if (originalLength >= 1.0)
98                 return 1.0;
99         }
100         return result;
101     }
102     ASSERT_NOT_REACHED();
103     return 0;
104 }
105 
106 template <CSSValueID IdForNone>
convertString(StyleResolverState &,CSSValue * value)107 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, CSSValue* value)
108 {
109     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
110     if (primitiveValue->getValueID() == IdForNone)
111         return nullAtom;
112     return AtomicString(primitiveValue->getStringValue());
113 }
114 
115 } // namespace WebCore
116 
117 #endif
118