1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef StyleBuilderConverter_h
#define StyleBuilderConverter_h
#include "core/css/CSSIdentifierValue.h"
#include "core/css/CSSStringValue.h"
#include "core/css/CSSValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/CSSValuePair.h"
#include "core/css/resolver/StyleResolverState.h"
#include "core/style/QuotesData.h"
#include "core/style/ShadowList.h"
#include "core/style/StyleOffsetRotation.h"
#include "core/style/StyleReflection.h"
#include "core/style/StyleScrollSnapData.h"
#include "core/style/TransformOrigin.h"
#include "platform/LengthSize.h"
#include "platform/fonts/FontDescription.h"
#include "platform/text/TabSize.h"
#include "platform/transforms/Rotation.h"
#include "wtf/Allocator.h"
namespace blink {
class ClipPathOperation;
class RotateTransformOperation;
class ScaleTransformOperation;
class StylePath;
class TextSizeAdjust;
class TranslateTransformOperation;
// Note that we assume the parser only allows valid CSSValue types.
class StyleBuilderConverter {
STATIC_ONLY(StyleBuilderConverter);
public:
static PassRefPtr<StyleReflection> convertBoxReflect(StyleResolverState&,
const CSSValue&);
static AtomicString convertFragmentIdentifier(StyleResolverState&,
const CSSValue&);
static Color convertColor(StyleResolverState&,
const CSSValue&,
bool forVisitedLink = false);
template <typename T>
static T convertComputedLength(StyleResolverState&, const CSSValue&);
static LengthBox convertClip(StyleResolverState&, const CSSValue&);
static PassRefPtr<ClipPathOperation> convertClipPath(StyleResolverState&,
const CSSValue&);
static FilterOperations convertFilterOperations(StyleResolverState&,
const CSSValue&);
template <typename T>
static T convertFlags(StyleResolverState&, const CSSValue&);
static FontDescription::FamilyDescription convertFontFamily(
StyleResolverState&,
const CSSValue&);
static PassRefPtr<FontFeatureSettings> convertFontFeatureSettings(
StyleResolverState&,
const CSSValue&);
static PassRefPtr<FontVariationSettings> convertFontVariationSettings(
StyleResolverState&,
const CSSValue&);
static FontDescription::Size convertFontSize(StyleResolverState&,
const CSSValue&);
static float convertFontSizeAdjust(StyleResolverState&, const CSSValue&);
static FontWeight convertFontWeight(StyleResolverState&, const CSSValue&);
static FontDescription::FontVariantCaps convertFontVariantCaps(
StyleResolverState&,
const CSSValue&);
static FontDescription::VariantLigatures convertFontVariantLigatures(
StyleResolverState&,
const CSSValue&);
static FontVariantNumeric convertFontVariantNumeric(StyleResolverState&,
const CSSValue&);
static StyleSelfAlignmentData convertSelfOrDefaultAlignmentData(
StyleResolverState&,
const CSSValue&);
static StyleContentAlignmentData convertContentAlignmentData(
StyleResolverState&,
const CSSValue&);
static GridAutoFlow convertGridAutoFlow(StyleResolverState&, const CSSValue&);
static GridPosition convertGridPosition(StyleResolverState&, const CSSValue&);
static GridTrackSize convertGridTrackSize(StyleResolverState&,
const CSSValue&);
static Vector<GridTrackSize> convertGridTrackSizeList(StyleResolverState&,
const CSSValue&);
template <typename T>
static T convertLineWidth(StyleResolverState&, const CSSValue&);
static Length convertLength(const StyleResolverState&, const CSSValue&);
static UnzoomedLength convertUnzoomedLength(const StyleResolverState&,
const CSSValue&);
static Length convertLengthOrAuto(const StyleResolverState&, const CSSValue&);
static Length convertLengthSizing(StyleResolverState&, const CSSValue&);
static Length convertLengthMaxSizing(StyleResolverState&, const CSSValue&);
static TabSize convertLengthOrTabSpaces(StyleResolverState&, const CSSValue&);
static Length convertLineHeight(StyleResolverState&, const CSSValue&);
static float convertNumberOrPercentage(StyleResolverState&, const CSSValue&);
static StyleOffsetRotation convertOffsetRotate(StyleResolverState&,
const CSSValue&);
static LengthPoint convertPosition(StyleResolverState&, const CSSValue&);
static LengthPoint convertPositionOrAuto(StyleResolverState&,
const CSSValue&);
static float convertPerspective(StyleResolverState&, const CSSValue&);
static Length convertQuirkyLength(StyleResolverState&, const CSSValue&);
static PassRefPtr<QuotesData> convertQuotes(StyleResolverState&,
const CSSValue&);
static LengthSize convertRadius(StyleResolverState&, const CSSValue&);
static EPaintOrder convertPaintOrder(StyleResolverState&, const CSSValue&);
static ShadowData convertShadow(StyleResolverState&, const CSSValue&);
static PassRefPtr<ShadowList> convertShadowList(StyleResolverState&,
const CSSValue&);
static ShapeValue* convertShapeValue(StyleResolverState&, const CSSValue&);
static float convertSpacing(StyleResolverState&, const CSSValue&);
template <CSSValueID IdForNone>
static AtomicString convertString(StyleResolverState&, const CSSValue&);
static PassRefPtr<SVGDashArray> convertStrokeDasharray(StyleResolverState&,
const CSSValue&);
static StyleColor convertStyleColor(StyleResolverState&,
const CSSValue&,
bool forVisitedLink = false);
static StyleAutoColor convertStyleAutoColor(StyleResolverState&,
const CSSValue&,
bool forVisitedLink = false);
static float convertTextStrokeWidth(StyleResolverState&, const CSSValue&);
static TextSizeAdjust convertTextSizeAdjust(StyleResolverState&,
const CSSValue&);
static TransformOperations convertTransformOperations(StyleResolverState&,
const CSSValue&);
static TransformOrigin convertTransformOrigin(StyleResolverState&,
const CSSValue&);
static void convertGridTrackList(const CSSValue&,
Vector<GridTrackSize>&,
NamedGridLinesMap&,
OrderedNamedGridLines&,
Vector<GridTrackSize>& autoRepeatTrackSizes,
NamedGridLinesMap&,
OrderedNamedGridLines&,
size_t& autoRepeatInsertionPoint,
AutoRepeatType&,
StyleResolverState&);
static void createImplicitNamedGridLinesFromGridArea(
const NamedGridAreaMap&,
NamedGridLinesMap&,
GridTrackSizingDirection);
static void convertOrderedNamedGridLinesMapToNamedGridLinesMap(
const OrderedNamedGridLines&,
NamedGridLinesMap&);
static ScrollSnapPoints convertSnapPoints(StyleResolverState&,
const CSSValue&);
static Vector<LengthPoint> convertSnapCoordinates(StyleResolverState&,
const CSSValue&);
static LengthPoint convertSnapDestination(StyleResolverState&,
const CSSValue&);
static PassRefPtr<TranslateTransformOperation> convertTranslate(
StyleResolverState&,
const CSSValue&);
static PassRefPtr<RotateTransformOperation> convertRotate(StyleResolverState&,
const CSSValue&);
static PassRefPtr<ScaleTransformOperation> convertScale(StyleResolverState&,
const CSSValue&);
static RespectImageOrientationEnum convertImageOrientation(
StyleResolverState&,
const CSSValue&);
static PassRefPtr<StylePath> convertPathOrNone(StyleResolverState&,
const CSSValue&);
static StyleOffsetRotation convertOffsetRotate(const CSSValue&);
template <CSSValueID cssValueFor0, CSSValueID cssValueFor100>
static Length convertPositionLength(StyleResolverState&, const CSSValue&);
static Rotation convertRotation(const CSSValue&);
static const CSSValue& convertRegisteredPropertyInitialValue(const CSSValue&);
static const CSSValue& convertRegisteredPropertyValue(
const StyleResolverState&,
const CSSValue&);
};
template <typename T>
T StyleBuilderConverter::convertComputedLength(StyleResolverState& state,
const CSSValue& value) {
return toCSSPrimitiveValue(value).computeLength<T>(
state.cssToLengthConversionData());
}
template <typename T>
T StyleBuilderConverter::convertFlags(StyleResolverState& state,
const CSSValue& value) {
T flags = static_cast<T>(0);
if (value.isIdentifierValue() &&
toCSSIdentifierValue(value).getValueID() == CSSValueNone)
return flags;
for (auto& flagValue : toCSSValueList(value))
flags |= toCSSIdentifierValue(*flagValue).convertTo<T>();
return flags;
}
template <typename T>
T StyleBuilderConverter::convertLineWidth(StyleResolverState& state,
const CSSValue& value) {
if (value.isIdentifierValue()) {
CSSValueID valueID = toCSSIdentifierValue(value).getValueID();
if (valueID == CSSValueThin)
return 1;
if (valueID == CSSValueMedium)
return 3;
if (valueID == CSSValueThick)
return 5;
NOTREACHED();
return 0;
}
const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
// FIXME: We are moving to use the full page zoom implementation to handle
// high-dpi. In that case specyfing a border-width of less than 1px would
// result in a border that is one device pixel thick. With this change that
// would instead be rounded up to 2 device pixels. Consider clamping it to
// device pixels or zoom adjusted CSS pixels instead of raw CSS pixels.
// Reference crbug.com/485650 and crbug.com/382483
double result =
primitiveValue.computeLength<double>(state.cssToLengthConversionData());
if (result > 0.0 && result < 1.0)
return 1.0;
return clampTo<T>(roundForImpreciseConversion<T>(result),
defaultMinimumForClamp<T>(), defaultMaximumForClamp<T>());
}
template <CSSValueID cssValueFor0, CSSValueID cssValueFor100>
Length StyleBuilderConverter::convertPositionLength(StyleResolverState& state,
const CSSValue& value) {
if (value.isValuePair()) {
const CSSValuePair& pair = toCSSValuePair(value);
Length length = StyleBuilderConverter::convertLength(state, pair.second());
if (toCSSIdentifierValue(pair.first()).getValueID() == cssValueFor0)
return length;
DCHECK_EQ(toCSSIdentifierValue(pair.first()).getValueID(), cssValueFor100);
return length.subtractFromOneHundredPercent();
}
if (value.isIdentifierValue()) {
switch (toCSSIdentifierValue(value).getValueID()) {
case cssValueFor0:
return Length(0, Percent);
case cssValueFor100:
return Length(100, Percent);
case CSSValueCenter:
return Length(50, Percent);
default:
NOTREACHED();
}
}
return StyleBuilderConverter::convertLength(state,
toCSSPrimitiveValue(value));
}
template <CSSValueID IdForNone>
AtomicString StyleBuilderConverter::convertString(StyleResolverState&,
const CSSValue& value) {
if (value.isStringValue())
return AtomicString(toCSSStringValue(value).value());
DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), IdForNone);
return nullAtom;
}
} // namespace blink
#endif
|