2 * Copyright (C) 2013 Google Inc. All rights reserved.
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
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.
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.
27 #ifndef StyleBuilderConverter_h
28 #define StyleBuilderConverter_h
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 #include "platform/fonts/FontDescription.h"
42 // Note that we assume the parser only allows valid CSSValue types.
44 class StyleBuilderConverter {
46 static PassRefPtr<StyleReflection> convertBoxReflect(StyleResolverState&, CSSValue*);
47 static AtomicString convertFragmentIdentifier(StyleResolverState&, CSSValue*);
48 static Color convertColor(StyleResolverState&, CSSValue*, bool forVisitedLink = false);
49 template <typename T> static T convertComputedLength(StyleResolverState&, CSSValue*);
50 template <typename T> static T convertFlags(StyleResolverState&, CSSValue*);
51 static PassRefPtr<FontFeatureSettings> convertFontFeatureSettings(StyleResolverState&, CSSValue*);
52 static FontWeight convertFontWeight(StyleResolverState&, CSSValue*);
53 static FontDescription::VariantLigatures convertFontVariantLigatures(StyleResolverState&, CSSValue*);
54 static EGlyphOrientation convertGlyphOrientation(StyleResolverState&, CSSValue*);
55 static GridPosition convertGridPosition(StyleResolverState&, CSSValue*);
56 static GridTrackSize convertGridTrackSize(StyleResolverState&, CSSValue*);
57 template <typename T> static T convertLineWidth(StyleResolverState&, CSSValue*);
58 static Length convertLength(StyleResolverState&, CSSValue*);
59 static Length convertLengthOrAuto(StyleResolverState&, CSSValue*);
60 static Length convertLengthSizing(StyleResolverState&, CSSValue*);
61 static Length convertLengthMaxSizing(StyleResolverState&, CSSValue*);
62 static LengthPoint convertLengthPoint(StyleResolverState&, CSSValue*);
63 static LineBoxContain convertLineBoxContain(StyleResolverState&, CSSValue*);
64 static float convertNumberOrPercentage(StyleResolverState&, CSSValue*);
65 static PassRefPtr<QuotesData> convertQuotes(StyleResolverState&, CSSValue*);
66 static LengthSize convertRadius(StyleResolverState&, CSSValue*);
67 static EPaintOrder convertPaintOrder(StyleResolverState&, CSSValue*);
68 static PassRefPtr<ShadowList> convertShadow(StyleResolverState&, CSSValue*);
69 static float convertSpacing(StyleResolverState&, CSSValue*);
70 template <CSSValueID IdForNone> static AtomicString convertString(StyleResolverState&, CSSValue*);
71 static PassRefPtr<SVGLengthList> convertStrokeDasharray(StyleResolverState&, CSSValue*);
72 static Color convertSVGColor(StyleResolverState&, CSSValue*);
73 static PassRefPtr<SVGLength> convertSVGLength(StyleResolverState&, CSSValue*);
74 static float convertTextStrokeWidth(StyleResolverState&, CSSValue*);
76 static bool convertGridTrackList(CSSValue*, Vector<GridTrackSize>&, NamedGridLinesMap&, OrderedNamedGridLines&, StyleResolverState&);
77 static void createImplicitNamedGridLinesFromGridArea(const NamedGridAreaMap&, NamedGridLinesMap&, GridTrackSizingDirection);
81 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, CSSValue* value)
83 return toCSSPrimitiveValue(value)->computeLength<T>(state.cssToLengthConversionData());
87 T StyleBuilderConverter::convertFlags(StyleResolverState& state, CSSValue* value)
89 T flags = static_cast<T>(0);
90 for (CSSValueListIterator i(value); i.hasMore(); i.advance())
91 flags |= *toCSSPrimitiveValue(i.value());
96 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, CSSValue* value)
98 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
99 CSSValueID valueID = primitiveValue->getValueID();
100 if (valueID == CSSValueThin)
102 if (valueID == CSSValueMedium)
104 if (valueID == CSSValueThick)
106 if (valueID == CSSValueInvalid) {
107 // Any original result that was >= 1 should not be allowed to fall below 1.
108 // This keeps border lines from vanishing.
109 T result = primitiveValue->computeLength<T>(state.cssToLengthConversionData());
110 if (state.style()->effectiveZoom() < 1.0f && result < 1.0) {
111 T originalLength = primitiveValue->computeLength<T>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
112 if (originalLength >= 1.0)
117 ASSERT_NOT_REACHED();
121 template <CSSValueID IdForNone>
122 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, CSSValue* value)
124 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
125 if (primitiveValue->getValueID() == IdForNone)
127 return AtomicString(primitiveValue->getStringValue());