1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* CSS parsing utility functions */
9 #include "ServoCSSParser.h"
11 #include "mozilla/AnimatedPropertyID.h"
12 #include "mozilla/ServoBindings.h"
13 #include "mozilla/ServoStyleSet.h"
14 #include "mozilla/dom/Document.h"
16 using namespace mozilla
;
17 using namespace mozilla::dom
;
20 bool ServoCSSParser::IsValidCSSColor(const nsACString
& aValue
) {
21 return Servo_IsValidCSSColor(&aValue
);
25 bool ServoCSSParser::ComputeColor(ServoStyleSet
* aStyleSet
,
26 nscolor aCurrentColor
,
27 const nsACString
& aValue
,
28 nscolor
* aResultColor
, bool* aWasCurrentColor
,
29 css::Loader
* aLoader
) {
30 return Servo_ComputeColor(aStyleSet
? aStyleSet
->RawData() : nullptr,
31 aCurrentColor
, &aValue
, aResultColor
,
32 aWasCurrentColor
, aLoader
);
36 bool ServoCSSParser::ColorTo(const nsACString
& aFromColor
,
37 const nsACString
& aToColorSpace
,
38 nsACString
* aResultColor
,
39 nsTArray
<float>* aResultComponents
,
40 bool* aResultAdjusted
, css::Loader
* aLoader
) {
41 return Servo_ColorTo(&aFromColor
, &aToColorSpace
, aResultColor
,
42 aResultComponents
, aResultAdjusted
, aLoader
);
46 already_AddRefed
<StyleLockedDeclarationBlock
> ServoCSSParser::ParseProperty(
47 nsCSSPropertyID aProperty
, const nsACString
& aValue
,
48 const ParsingEnvironment
& aParsingEnvironment
,
49 const StyleParsingMode
& aParsingMode
) {
50 AnimatedPropertyID
property(aProperty
);
51 return ParseProperty(property
, aValue
, aParsingEnvironment
, aParsingMode
);
55 already_AddRefed
<StyleLockedDeclarationBlock
> ServoCSSParser::ParseProperty(
56 const AnimatedPropertyID
& aProperty
, const nsACString
& aValue
,
57 const ParsingEnvironment
& aParsingEnvironment
,
58 const StyleParsingMode
& aParsingMode
) {
59 return Servo_ParseProperty(
60 &aProperty
, &aValue
, aParsingEnvironment
.mUrlExtraData
,
61 aParsingMode
, aParsingEnvironment
.mCompatMode
,
62 aParsingEnvironment
.mLoader
, aParsingEnvironment
.mRuleType
)
67 bool ServoCSSParser::ParseEasing(const nsACString
& aValue
,
68 StyleComputedTimingFunction
& aResult
) {
69 return Servo_ParseEasing(&aValue
, &aResult
);
73 bool ServoCSSParser::ParseTransformIntoMatrix(const nsACString
& aValue
,
74 bool& aContains3DTransform
,
75 gfx::Matrix4x4
& aResult
) {
76 return Servo_ParseTransformIntoMatrix(&aValue
, &aContains3DTransform
,
81 bool ServoCSSParser::ParseFontShorthandForMatching(
82 const nsACString
& aValue
, URLExtraData
* aUrl
, StyleFontFamilyList
& aList
,
83 StyleFontStyle
& aStyle
, StyleFontStretch
& aStretch
,
84 StyleFontWeight
& aWeight
, float* aSize
, bool* aSmallCaps
) {
85 return Servo_ParseFontShorthandForMatching(
86 &aValue
, aUrl
, &aList
, &aStyle
, &aStretch
, &aWeight
, aSize
, aSmallCaps
);
90 already_AddRefed
<URLExtraData
> ServoCSSParser::GetURLExtraData(
91 Document
* aDocument
) {
92 MOZ_ASSERT(aDocument
);
93 return do_AddRef(aDocument
->DefaultStyleAttrURLData());
96 /* static */ ServoCSSParser::ParsingEnvironment
97 ServoCSSParser::GetParsingEnvironment(Document
* aDocument
) {
98 return {GetURLExtraData(aDocument
), aDocument
->GetCompatibilityMode(),
99 aDocument
->CSSLoader()};