Bug 1700051: part 48) Slightly simplify `mozInlineSpellWordUtil::FindRealWordContaini...
[gecko.git] / layout / style / ServoCSSParser.h
bloba7387a134f7a39ef0371385ba147d91eab7d2a94
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/AlreadyAddRefed.h"
13 #include "mozilla/gfx/Matrix.h"
14 #include "mozilla/ServoTypes.h"
15 #include "nsColor.h"
16 #include "nsCSSPropertyID.h"
17 #include "nsDOMCSSDeclaration.h"
18 #include "nsStringFwd.h"
20 struct nsCSSRect;
21 struct nsTimingFunction;
22 struct RawServoDeclarationBlock;
23 template <class T>
24 class RefPtr;
26 namespace mozilla {
28 class ServoStyleSet;
29 class SharedFontList;
30 struct URLExtraData;
31 union StyleComputedFontStyleDescriptor;
33 namespace css {
34 class Loader;
37 namespace dom {
38 class Document;
41 class ServoCSSParser {
42 public:
43 using ParsingEnvironment = nsDOMCSSDeclaration::ParsingEnvironment;
45 /**
46 * Returns whether the specified string can be parsed as a valid CSS
47 * <color> value.
49 * This includes Mozilla-specific keywords such as -moz-default-color.
51 static bool IsValidCSSColor(const nsACString& aValue);
53 /**
54 * Computes an nscolor from the given CSS <color> value.
56 * @param aStyleSet The style set whose nsPresContext will be used to
57 * compute system colors and other special color values.
58 * @param aCurrentColor The color value that currentcolor should compute to.
59 * @param aValue The CSS <color> value.
60 * @param aResultColor The resulting computed color value.
61 * @param aWasCurrentColor Whether aValue was currentcolor. Can be nullptr
62 * if the caller doesn't care.
63 * @param aLoader The CSS loader for document we're parsing a color for,
64 * so that parse errors can be reported to the console. If nullptr, errors
65 * won't be reported to the console.
66 * @return Whether aValue was successfully parsed and aResultColor was set.
68 static bool ComputeColor(ServoStyleSet* aStyleSet, nscolor aCurrentColor,
69 const nsACString& aValue, nscolor* aResultColor,
70 bool* aWasCurrentColor = nullptr,
71 css::Loader* aLoader = nullptr);
73 /**
74 * Parse a string representing a CSS property value into a
75 * RawServoDeclarationBlock.
77 * @param aProperty The property to be parsed.
78 * @param aValue The specified value.
79 * @param aParsingEnvironment All the parsing environment data we need.
80 * @param aParsingMode The paring mode we apply.
81 * @return The parsed value as a RawServoDeclarationBlock. We put the value
82 * in a declaration block since that is how we represent specified values
83 * in Servo.
85 static already_AddRefed<RawServoDeclarationBlock> ParseProperty(
86 nsCSSPropertyID aProperty, const nsACString& aValue,
87 const ParsingEnvironment& aParsingEnvironment,
88 ParsingMode aParsingMode = ParsingMode::Default);
90 /**
91 * Parse a animation timing function.
93 * @param aValue The specified value.
94 * @param aResult The output timing function. (output)
95 * @return Whether the value was successfully parsed.
97 static bool ParseEasing(const nsACString& aValue, nsTimingFunction& aResult);
99 /**
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 nsACString& 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