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 #include "mozilla/ServoBindings.h"
8 #include "mozilla/ServoSpecifiedValues.h"
9 
10 using namespace mozilla;
11 
PropertyIsSet(nsCSSPropertyID aId)12 bool ServoSpecifiedValues::PropertyIsSet(nsCSSPropertyID aId) {
13   return Servo_DeclarationBlock_PropertyIsSet(mDecl, aId);
14 }
15 
SetIdentStringValue(nsCSSPropertyID aId,const nsString & aValue)16 void ServoSpecifiedValues::SetIdentStringValue(nsCSSPropertyID aId,
17                                                const nsString& aValue) {
18   RefPtr<nsAtom> atom = NS_Atomize(aValue);
19   SetIdentAtomValue(aId, atom);
20 }
21 
SetIdentAtomValue(nsCSSPropertyID aId,nsAtom * aValue)22 void ServoSpecifiedValues::SetIdentAtomValue(nsCSSPropertyID aId,
23                                              nsAtom* aValue) {
24   Servo_DeclarationBlock_SetIdentStringValue(mDecl, aId, aValue);
25   if (aId == eCSSProperty__x_lang) {
26     // This forces the lang prefs result to be cached so that we can access them
27     // off main thread during traversal.
28     //
29     // FIXME(emilio): Can we move mapped attribute declarations across
30     // documents? Isn't this wrong in that case? This is pretty out of place
31     // anyway.
32     if (nsPresContext* pc = mDocument->GetPresContext()) {
33       pc->ForceCacheLang(aValue);
34     }
35   }
36 }
37 
SetKeywordValue(nsCSSPropertyID aId,int32_t aValue)38 void ServoSpecifiedValues::SetKeywordValue(nsCSSPropertyID aId,
39                                            int32_t aValue) {
40   Servo_DeclarationBlock_SetKeywordValue(mDecl, aId, aValue);
41 }
42 
SetIntValue(nsCSSPropertyID aId,int32_t aValue)43 void ServoSpecifiedValues::SetIntValue(nsCSSPropertyID aId, int32_t aValue) {
44   Servo_DeclarationBlock_SetIntValue(mDecl, aId, aValue);
45 }
46 
SetPixelValue(nsCSSPropertyID aId,float aValue)47 void ServoSpecifiedValues::SetPixelValue(nsCSSPropertyID aId, float aValue) {
48   Servo_DeclarationBlock_SetPixelValue(mDecl, aId, aValue);
49 }
50 
SetLengthValue(nsCSSPropertyID aId,nsCSSValue aValue)51 void ServoSpecifiedValues::SetLengthValue(nsCSSPropertyID aId,
52                                           nsCSSValue aValue) {
53   MOZ_ASSERT(aValue.IsLengthUnit());
54   Servo_DeclarationBlock_SetLengthValue(mDecl, aId, aValue.GetFloatValue(),
55                                         aValue.GetUnit());
56 }
57 
SetNumberValue(nsCSSPropertyID aId,float aValue)58 void ServoSpecifiedValues::SetNumberValue(nsCSSPropertyID aId, float aValue) {
59   Servo_DeclarationBlock_SetNumberValue(mDecl, aId, aValue);
60 }
61 
SetPercentValue(nsCSSPropertyID aId,float aValue)62 void ServoSpecifiedValues::SetPercentValue(nsCSSPropertyID aId, float aValue) {
63   Servo_DeclarationBlock_SetPercentValue(mDecl, aId, aValue);
64 }
65 
SetAutoValue(nsCSSPropertyID aId)66 void ServoSpecifiedValues::SetAutoValue(nsCSSPropertyID aId) {
67   Servo_DeclarationBlock_SetAutoValue(mDecl, aId);
68 }
69 
SetCurrentColor(nsCSSPropertyID aId)70 void ServoSpecifiedValues::SetCurrentColor(nsCSSPropertyID aId) {
71   Servo_DeclarationBlock_SetCurrentColor(mDecl, aId);
72 }
73 
SetColorValue(nsCSSPropertyID aId,nscolor aColor)74 void ServoSpecifiedValues::SetColorValue(nsCSSPropertyID aId, nscolor aColor) {
75   Servo_DeclarationBlock_SetColorValue(mDecl, aId, aColor);
76 }
77 
SetFontFamily(const nsString & aValue)78 void ServoSpecifiedValues::SetFontFamily(const nsString& aValue) {
79   Servo_DeclarationBlock_SetFontFamily(mDecl, aValue);
80 }
81 
SetTextDecorationColorOverride()82 void ServoSpecifiedValues::SetTextDecorationColorOverride() {
83   Servo_DeclarationBlock_SetTextDecorationColorOverride(mDecl);
84 }
85 
SetBackgroundImage(nsAttrValue & aValue)86 void ServoSpecifiedValues::SetBackgroundImage(nsAttrValue& aValue) {
87   if (aValue.Type() != nsAttrValue::eURL &&
88       aValue.Type() != nsAttrValue::eImage) {
89     return;
90   }
91   nsAutoString str;
92   aValue.ToString(str);
93   Servo_DeclarationBlock_SetBackgroundImage(
94       mDecl, str, mDocument->DefaultStyleAttrURLData());
95 }
96