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 #ifndef mozilla_ServoCSSParser_h
10 #define mozilla_ServoCSSParser_h
12 #include "mozilla/gfx/Types.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/ServoStyleConsts.h"
15 #include "mozilla/ServoTypes.h"
17 #include "nsCSSPropertyID.h"
18 #include "nsDOMCSSDeclaration.h"
19 #include "nsStringFwd.h"
22 struct nsTimingFunction
;
23 struct RawServoDeclarationBlock
;
39 class ServoCSSParser
{
41 using ParsingEnvironment
= nsDOMCSSDeclaration::ParsingEnvironment
;
44 * Returns whether the specified string can be parsed as a valid CSS
47 * This includes Mozilla-specific keywords such as -moz-default-color.
49 static bool IsValidCSSColor(const nsACString
& aValue
);
52 * Computes an nscolor from the given CSS <color> value.
54 * @param aStyleSet The style set whose nsPresContext will be used to
55 * compute system colors and other special color values.
56 * @param aCurrentColor The color value that currentcolor should compute to.
57 * @param aValue The CSS <color> value.
58 * @param aResultColor The resulting computed color value.
59 * @param aWasCurrentColor Whether aValue was currentcolor. Can be nullptr
60 * if the caller doesn't care.
61 * @param aLoader The CSS loader for document we're parsing a color for,
62 * so that parse errors can be reported to the console. If nullptr, errors
63 * won't be reported to the console.
64 * @return Whether aValue was successfully parsed and aResultColor was set.
66 static bool ComputeColor(ServoStyleSet
* aStyleSet
, nscolor aCurrentColor
,
67 const nsACString
& aValue
, nscolor
* aResultColor
,
68 bool* aWasCurrentColor
= nullptr,
69 css::Loader
* aLoader
= nullptr);
72 * Parse a string representing a CSS property value into a
73 * RawServoDeclarationBlock.
75 * @param aProperty The property to be parsed.
76 * @param aValue The specified value.
77 * @param aParsingEnvironment All the parsing environment data we need.
78 * @param aParsingMode The paring mode we apply.
79 * @return The parsed value as a RawServoDeclarationBlock. We put the value
80 * in a declaration block since that is how we represent specified values
83 static already_AddRefed
<RawServoDeclarationBlock
> ParseProperty(
84 nsCSSPropertyID aProperty
, const nsAString
& aValue
,
85 const ParsingEnvironment
& aParsingEnvironment
,
86 ParsingMode aParsingMode
= ParsingMode::Default
);
89 * Parse a animation timing function.
91 * @param aValue The specified value.
92 * @param aUrl The parser url extra data.
93 * @param aResult The output timing function. (output)
94 * @return Whether the value was successfully parsed.
96 static bool ParseEasing(const nsAString
& aValue
, URLExtraData
* aUrl
,
97 nsTimingFunction
& aResult
);
100 * Parse a specified transform list into a gfx matrix.
102 * @param aValue The specified value.
103 * @param aContains3DTransform The output flag indicates whether this is any
104 * 3d transform function. (output)
105 * @param aResult The output matrix. (output)
106 * @return Whether the value was successfully parsed.
108 static bool ParseTransformIntoMatrix(const nsACString
& aValue
,
109 bool& aContains3DTransform
,
110 gfx::Matrix4x4
& aResult
);
113 * Parse a font shorthand for FontFaceSet matching, so we only care about
114 * FontFamily, FontStyle, FontStretch, and FontWeight.
116 * @param aValue The specified value.
117 * @param aUrl The parser url extra data.
118 * @param aList The parsed FontFamily list. (output)
119 * @param aStyle The parsed FontStyle. (output)
120 * @param aStretch The parsed FontStretch. (output)
121 * @param aWeight The parsed FontWeight. (output)
122 * @return Whether the value was successfully parsed.
124 static bool ParseFontShorthandForMatching(
125 const nsAString
& aValue
, URLExtraData
* aUrl
,
126 RefPtr
<SharedFontList
>& aList
, StyleComputedFontStyleDescriptor
& aStyle
,
127 float& aStretch
, float& aWeight
);
130 * Get a URLExtraData from a document.
132 static already_AddRefed
<URLExtraData
> GetURLExtraData(dom::Document
*);
135 * Get a ParsingEnvironment from a document.
137 static ParsingEnvironment
GetParsingEnvironment(dom::Document
*);
140 } // namespace mozilla
142 #endif // mozilla_ServoCSSParser_h