Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "mozilla/ServoBindings.h"
7 : #include "mozilla/ServoSpecifiedValues.h"
8 :
9 : namespace {
10 :
11 : #define STYLE_STRUCT(name, checkdata_cb) | NS_STYLE_INHERIT_BIT(name)
12 : const uint64_t ALL_SIDS = 0
13 : #include "nsStyleStructList.h"
14 : ;
15 : #undef STYLE_STRUCT
16 :
17 : } // anonymous namespace
18 :
19 : using namespace mozilla;
20 :
21 0 : ServoSpecifiedValues::ServoSpecifiedValues(nsPresContext* aContext,
22 0 : RawServoDeclarationBlock* aDecl)
23 :
24 : : GenericSpecifiedValues(StyleBackendType::Servo, aContext, ALL_SIDS)
25 0 : , mDecl(aDecl)
26 0 : {}
27 :
28 : bool
29 0 : ServoSpecifiedValues::PropertyIsSet(nsCSSPropertyID aId)
30 : {
31 : // We always create fresh ServoSpecifiedValues for each property
32 : // mapping, so unlike Gecko there aren't existing properties from
33 : // the cascade that we wish to avoid overwriting.
34 : //
35 : // If a property is being overwritten, that's a bug. Check for it
36 : // in debug mode (this is O(n^2) behavior since Servo will traverse
37 : // the array each time you add a new property)
38 0 : MOZ_ASSERT(!Servo_DeclarationBlock_PropertyIsSet(mDecl, aId),
39 : "Presentation attribute mappers should never attempt to set the "
40 : "same property twice");
41 0 : return false;
42 : }
43 :
44 : void
45 0 : ServoSpecifiedValues::SetIdentStringValue(nsCSSPropertyID aId,
46 : const nsString& aValue)
47 : {
48 0 : nsCOMPtr<nsIAtom> atom = NS_Atomize(aValue);
49 0 : SetIdentAtomValue(aId, atom);
50 0 : }
51 :
52 : void
53 0 : ServoSpecifiedValues::SetIdentAtomValue(nsCSSPropertyID aId, nsIAtom* aValue)
54 : {
55 0 : Servo_DeclarationBlock_SetIdentStringValue(mDecl, aId, aValue);
56 0 : if (aId == eCSSProperty__x_lang) {
57 : // This forces the lang prefs result to be cached
58 : // so that we can access them off main thread during traversal
59 0 : mPresContext->ForceCacheLang(aValue);
60 : }
61 0 : }
62 :
63 : void
64 0 : ServoSpecifiedValues::SetKeywordValue(nsCSSPropertyID aId, int32_t aValue)
65 : {
66 0 : Servo_DeclarationBlock_SetKeywordValue(mDecl, aId, aValue);
67 0 : }
68 :
69 : void
70 0 : ServoSpecifiedValues::SetIntValue(nsCSSPropertyID aId, int32_t aValue)
71 : {
72 0 : Servo_DeclarationBlock_SetIntValue(mDecl, aId, aValue);
73 0 : }
74 :
75 : void
76 0 : ServoSpecifiedValues::SetPixelValue(nsCSSPropertyID aId, float aValue)
77 : {
78 0 : Servo_DeclarationBlock_SetPixelValue(mDecl, aId, aValue);
79 0 : }
80 :
81 : void
82 0 : ServoSpecifiedValues::SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue)
83 : {
84 0 : MOZ_ASSERT(aValue.IsLengthUnit());
85 0 : Servo_DeclarationBlock_SetLengthValue(
86 0 : mDecl, aId, aValue.GetFloatValue(), aValue.GetUnit());
87 0 : }
88 :
89 : void
90 0 : ServoSpecifiedValues::SetNumberValue(nsCSSPropertyID aId, float aValue)
91 : {
92 0 : Servo_DeclarationBlock_SetNumberValue(mDecl, aId, aValue);
93 0 : }
94 :
95 : void
96 0 : ServoSpecifiedValues::SetPercentValue(nsCSSPropertyID aId, float aValue)
97 : {
98 0 : Servo_DeclarationBlock_SetPercentValue(mDecl, aId, aValue);
99 0 : }
100 :
101 : void
102 0 : ServoSpecifiedValues::SetAutoValue(nsCSSPropertyID aId)
103 : {
104 0 : Servo_DeclarationBlock_SetAutoValue(mDecl, aId);
105 0 : }
106 :
107 : void
108 0 : ServoSpecifiedValues::SetCurrentColor(nsCSSPropertyID aId)
109 : {
110 0 : Servo_DeclarationBlock_SetCurrentColor(mDecl, aId);
111 0 : }
112 :
113 : void
114 0 : ServoSpecifiedValues::SetColorValue(nsCSSPropertyID aId, nscolor aColor)
115 : {
116 0 : Servo_DeclarationBlock_SetColorValue(mDecl, aId, aColor);
117 0 : }
118 :
119 : void
120 0 : ServoSpecifiedValues::SetFontFamily(const nsString& aValue)
121 : {
122 0 : Servo_DeclarationBlock_SetFontFamily(mDecl, aValue);
123 0 : }
124 :
125 : void
126 0 : ServoSpecifiedValues::SetTextDecorationColorOverride()
127 : {
128 0 : Servo_DeclarationBlock_SetTextDecorationColorOverride(mDecl);
129 0 : }
130 :
131 : void
132 0 : ServoSpecifiedValues::SetBackgroundImage(nsAttrValue& aValue)
133 : {
134 0 : nsAutoString str;
135 0 : aValue.ToString(str);
136 0 : Servo_DeclarationBlock_SetBackgroundImage(
137 0 : mDecl, str, mPresContext->Document()->DefaultStyleAttrURLData());
138 9 : }
|