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/. */
6
7 /* CSS parsing utility functions */
8
9 #include "ServoCSSParser.h"
10
11 #include "mozilla/ServoBindings.h"
12 #include "mozilla/ServoStyleSet.h"
13 #include "mozilla/dom/Document.h"
14
15 using namespace mozilla;
16 using namespace mozilla::dom;
17
18 /* static */
IsValidCSSColor(const nsACString & aValue)19 bool ServoCSSParser::IsValidCSSColor(const nsACString& aValue) {
20 return Servo_IsValidCSSColor(&aValue);
21 }
22
23 /* static */
ComputeColor(ServoStyleSet * aStyleSet,nscolor aCurrentColor,const nsACString & aValue,nscolor * aResultColor,bool * aWasCurrentColor,css::Loader * aLoader)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);
32 }
33
34 /* static */
ParseProperty(nsCSSPropertyID aProperty,const nsACString & aValue,const ParsingEnvironment & aParsingEnvironment,ParsingMode aParsingMode)35 already_AddRefed<RawServoDeclarationBlock> ServoCSSParser::ParseProperty(
36 nsCSSPropertyID aProperty, const nsACString& aValue,
37 const ParsingEnvironment& aParsingEnvironment, ParsingMode aParsingMode) {
38 return Servo_ParseProperty(
39 aProperty, &aValue, aParsingEnvironment.mUrlExtraData,
40 aParsingMode, aParsingEnvironment.mCompatMode,
41 aParsingEnvironment.mLoader, aParsingEnvironment.mRuleType)
42 .Consume();
43 }
44
45 /* static */
ParseEasing(const nsACString & aValue,nsTimingFunction & aResult)46 bool ServoCSSParser::ParseEasing(const nsACString& aValue,
47 nsTimingFunction& aResult) {
48 return Servo_ParseEasing(&aValue, &aResult);
49 }
50
51 /* static */
ParseTransformIntoMatrix(const nsACString & aValue,bool & aContains3DTransform,gfx::Matrix4x4 & aResult)52 bool ServoCSSParser::ParseTransformIntoMatrix(const nsACString& aValue,
53 bool& aContains3DTransform,
54 gfx::Matrix4x4& aResult) {
55 return Servo_ParseTransformIntoMatrix(&aValue, &aContains3DTransform,
56 &aResult.components);
57 }
58
59 /* static */
ParseFontShorthandForMatching(const nsACString & aValue,URLExtraData * aUrl,StyleFontFamilyList & aList,StyleComputedFontStyleDescriptor & aStyle,float & aStretch,float & aWeight)60 bool ServoCSSParser::ParseFontShorthandForMatching(
61 const nsACString& aValue, URLExtraData* aUrl, StyleFontFamilyList& aList,
62 StyleComputedFontStyleDescriptor& aStyle, float& aStretch, float& aWeight) {
63 return Servo_ParseFontShorthandForMatching(&aValue, aUrl, &aList, &aStyle,
64 &aStretch, &aWeight);
65 }
66
67 /* static */
GetURLExtraData(Document * aDocument)68 already_AddRefed<URLExtraData> ServoCSSParser::GetURLExtraData(
69 Document* aDocument) {
70 MOZ_ASSERT(aDocument);
71
72 nsCOMPtr<nsIReferrerInfo> referrerInfo =
73 ReferrerInfo::CreateForInternalCSSResources(aDocument);
74
75 // FIXME this is using the wrong base uri (bug 1343919)
76 RefPtr<URLExtraData> url = new URLExtraData(
77 aDocument->GetDocumentURI(), referrerInfo, aDocument->NodePrincipal());
78 return url.forget();
79 }
80
81 /* static */ ServoCSSParser::ParsingEnvironment
GetParsingEnvironment(Document * aDocument)82 ServoCSSParser::GetParsingEnvironment(Document* aDocument) {
83 return {GetURLExtraData(aDocument), aDocument->GetCompatibilityMode(),
84 aDocument->CSSLoader()};
85 }
86