Line data Source code
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 : /*
8 : * Generic representation of a container of specified CSS values, which
9 : * could potentially be Servo- or Gecko- format. Used to make attribute mapping
10 : * code generic over style backends.
11 : */
12 :
13 : #ifndef mozilla_GenericSpecifiedValues_h
14 : #define mozilla_GenericSpecifiedValues_h
15 :
16 : #include "mozilla/ServoUtils.h"
17 : #include "nsCSSProps.h"
18 : #include "nsCSSValue.h"
19 : #include "nsPresContext.h"
20 :
21 : struct nsRuleData;
22 :
23 : namespace mozilla {
24 :
25 : class ServoSpecifiedValues;
26 :
27 : // This provides a common interface for attribute mappers (MapAttributesIntoRule)
28 : // to use regardless of the style backend. If the style backend is Gecko,
29 : // this will contain an nsRuleData. If it is Servo, it will be a PropertyDeclarationBlock.
30 : class GenericSpecifiedValues
31 : {
32 : protected:
33 11858 : explicit GenericSpecifiedValues(StyleBackendType aType,
34 : nsPresContext* aPresContext,
35 : uint32_t aSIDs)
36 11858 : : mType(aType)
37 : , mPresContext(aPresContext)
38 11858 : , mSIDs(aSIDs)
39 11858 : {}
40 :
41 : public:
42 216 : MOZ_DECL_STYLO_METHODS(nsRuleData, ServoSpecifiedValues)
43 :
44 : // Check if we already contain a certain longhand
45 : inline bool PropertyIsSet(nsCSSPropertyID aId);
46 : // Check if we are able to hold longhands from a given
47 : // style struct. Pass the result of NS_STYLE_INHERIT_BIT to this
48 : // function. Can accept multiple inherit bits or'd together.
49 808 : inline bool ShouldComputeStyleStruct(uint64_t aInheritBits)
50 : {
51 808 : return aInheritBits & mSIDs;
52 : }
53 :
54 12 : inline nsPresContext* PresContext() { return mPresContext; }
55 :
56 : // Set a property to an identifier (string)
57 : inline void SetIdentStringValue(nsCSSPropertyID aId, const nsString& aValue);
58 : inline void SetIdentStringValueIfUnset(nsCSSPropertyID aId,
59 : const nsString& aValue);
60 :
61 : inline void SetIdentAtomValue(nsCSSPropertyID aId, nsIAtom* aValue);
62 : inline void SetIdentAtomValueIfUnset(nsCSSPropertyID aId, nsIAtom* aValue);
63 :
64 : // Set a property to a keyword (usually NS_STYLE_* or StyleFoo::*)
65 : inline void SetKeywordValue(nsCSSPropertyID aId, int32_t aValue);
66 : inline void SetKeywordValueIfUnset(nsCSSPropertyID aId, int32_t aValue);
67 :
68 : template<typename T,
69 : typename = typename std::enable_if<std::is_enum<T>::value>::type>
70 28 : void SetKeywordValue(nsCSSPropertyID aId, T aValue)
71 : {
72 : static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
73 : "aValue must be an enum that fits within 32 bits");
74 28 : SetKeywordValue(aId, static_cast<int32_t>(aValue));
75 28 : }
76 : template<typename T,
77 : typename = typename std::enable_if<std::is_enum<T>::value>::type>
78 : void SetKeywordValueIfUnset(nsCSSPropertyID aId, T aValue)
79 : {
80 : static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
81 : "aValue must be an enum that fits within 32 bits");
82 : SetKeywordValueIfUnset(aId, static_cast<int32_t>(aValue));
83 : }
84 :
85 : // Set a property to an integer value
86 : inline void SetIntValue(nsCSSPropertyID aId, int32_t aValue);
87 : // Set a property to a pixel value
88 : inline void SetPixelValue(nsCSSPropertyID aId, float aValue);
89 : inline void SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue);
90 :
91 : inline void SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue);
92 :
93 : // Set a property to a number value
94 : inline void SetNumberValue(nsCSSPropertyID aId, float aValue);
95 :
96 : // Set a property to a percent value
97 : inline void SetPercentValue(nsCSSPropertyID aId, float aValue);
98 : inline void SetPercentValueIfUnset(nsCSSPropertyID aId, float aValue);
99 :
100 : // Set a property to `auto`
101 : inline void SetAutoValue(nsCSSPropertyID aId);
102 : inline void SetAutoValueIfUnset(nsCSSPropertyID aId);
103 :
104 : // Set a property to `currentcolor`
105 : inline void SetCurrentColor(nsCSSPropertyID aId);
106 : inline void SetCurrentColorIfUnset(nsCSSPropertyID aId);
107 :
108 : // Set a property to an RGBA nscolor value
109 : inline void SetColorValue(nsCSSPropertyID aId, nscolor aValue);
110 : inline void SetColorValueIfUnset(nsCSSPropertyID aId, nscolor aValue);
111 :
112 : // Set font-family to a string
113 : inline void SetFontFamily(const nsString& aValue);
114 : // Add a quirks-mode override to the decoration color of elements nested in <a>
115 : inline void SetTextDecorationColorOverride();
116 : inline void SetBackgroundImage(nsAttrValue& value);
117 :
118 : const mozilla::StyleBackendType mType;
119 : nsPresContext* const mPresContext;
120 : const uint32_t mSIDs;
121 : };
122 :
123 : } // namespace mozilla
124 :
125 : #endif // mozilla_GenericSpecifiedValues_h
|