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/ServoBindings.h"
12 #include "mozilla/ServoStyleSet.h"
13 #include "mozilla/dom/Document.h"
15 using namespace mozilla
;
16 using namespace mozilla::dom
;
19 bool ServoCSSParser::IsValidCSSColor(const nsACString
& aValue
) {
20 return Servo_IsValidCSSColor(&aValue
);
24 bool ServoCSSParser::ComputeColor(ServoStyleSet
* aStyleSet
,
25 nscolor aCurrentColor
,
26 const nsACString
& aValue
,
27 nscolor
* aResultColor
, bool* aWasCurrentColor
,
28 css::Loader
* aLoader
) {
29 return Servo_ComputeColor(aStyleSet
? aStyleSet
->RawSet() : nullptr,
30 aCurrentColor
, &aValue
, aResultColor
,
31 aWasCurrentColor
, aLoader
);
35 already_AddRefed
<RawServoDeclarationBlock
> ServoCSSParser::ParseProperty(
36 nsCSSPropertyID aProperty
, const nsAString
& aValue
,
37 const ParsingEnvironment
& aParsingEnvironment
, ParsingMode aParsingMode
) {
38 NS_ConvertUTF16toUTF8
value(aValue
);
39 return Servo_ParseProperty(
40 aProperty
, &value
, aParsingEnvironment
.mUrlExtraData
, aParsingMode
,
41 aParsingEnvironment
.mCompatMode
, aParsingEnvironment
.mLoader
)
46 bool ServoCSSParser::ParseEasing(const nsAString
& aValue
, URLExtraData
* aUrl
,
47 nsTimingFunction
& aResult
) {
48 return Servo_ParseEasing(&aValue
, aUrl
, &aResult
);
52 bool ServoCSSParser::ParseTransformIntoMatrix(const nsACString
& aValue
,
53 bool& aContains3DTransform
,
54 gfx::Matrix4x4
& aResult
) {
55 return Servo_ParseTransformIntoMatrix(&aValue
, &aContains3DTransform
,
60 bool ServoCSSParser::ParseFontShorthandForMatching(
61 const nsAString
& aValue
, URLExtraData
* aUrl
, RefPtr
<SharedFontList
>& aList
,
62 StyleComputedFontStyleDescriptor
& aStyle
, float& aStretch
, float& aWeight
) {
63 return Servo_ParseFontShorthandForMatching(&aValue
, aUrl
, &aList
, &aStyle
,
68 already_AddRefed
<URLExtraData
> ServoCSSParser::GetURLExtraData(
69 Document
* aDocument
) {
70 MOZ_ASSERT(aDocument
);
72 nsCOMPtr
<nsIReferrerInfo
> referrerInfo
=
73 ReferrerInfo::CreateForInternalCSSResources(aDocument
);
75 // FIXME this is using the wrong base uri (bug 1343919)
76 RefPtr
<URLExtraData
> url
= new URLExtraData(
77 aDocument
->GetDocumentURI(), referrerInfo
, aDocument
->NodePrincipal());
81 /* static */ ServoCSSParser::ParsingEnvironment
82 ServoCSSParser::GetParsingEnvironment(Document
* aDocument
) {
83 return ParsingEnvironment(GetURLExtraData(aDocument
),
84 aDocument
->GetCompatibilityMode(),
85 aDocument
->CSSLoader());