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 /* representation of simple property values within CSS declarations */
9 #include "nsCSSValue.h"
11 #include "mozilla/CORSMode.h"
12 #include "mozilla/FontPropertyTypes.h"
13 #include "mozilla/ServoBindings.h"
14 #include "mozilla/ServoStyleSet.h"
15 #include "mozilla/ServoTypes.h"
16 #include "mozilla/StyleSheetInlines.h"
17 #include "mozilla/Likely.h"
18 #include "mozilla/MemoryReporting.h"
19 #include "mozilla/css/ImageLoader.h"
20 #include "gfxFontConstants.h"
21 #include "imgRequestProxy.h"
22 #include "mozilla/dom/Document.h"
23 #include "nsCSSProps.h"
24 #include "nsNetUtil.h"
25 #include "nsPresContext.h"
26 #include "nsStyleUtil.h"
27 #include "nsDeviceContext.h"
28 #include "nsContentUtils.h"
30 using namespace mozilla
;
31 using namespace mozilla::css
;
32 using namespace mozilla::dom
;
34 nsCSSValue::nsCSSValue(float aValue
, nsCSSUnit aUnit
) : mUnit(aUnit
) {
35 MOZ_ASSERT(eCSSUnit_Null
== aUnit
, "not a float value");
37 MOZ_ASSERT(!std::isnan(mValue
));
40 nsCSSValue::nsCSSValue(const nsCSSValue
& aCopy
) : mUnit(aCopy
.mUnit
) {
41 if (eCSSUnit_Null
!= mUnit
) {
42 mValue
= aCopy
.mValue
;
43 MOZ_ASSERT(!std::isnan(mValue
));
45 MOZ_ASSERT_UNREACHABLE("unknown unit");
49 nsCSSValue
& nsCSSValue::operator=(const nsCSSValue
& aCopy
) {
52 new (this) nsCSSValue(aCopy
);
57 nsCSSValue
& nsCSSValue::operator=(nsCSSValue
&& aOther
) {
58 MOZ_ASSERT(this != &aOther
, "Self assigment with rvalue reference");
62 mValue
= aOther
.mValue
;
63 aOther
.mUnit
= eCSSUnit_Null
;
68 bool nsCSSValue::operator==(const nsCSSValue
& aOther
) const {
69 if (mUnit
!= aOther
.mUnit
) {
72 return mValue
== aOther
.mValue
;
75 nscoord
nsCSSValue::GetPixelLength() const {
76 MOZ_ASSERT(IsPixelLengthUnit(), "not a fixed length unit");
81 return nsPresContext::CSSPixelsToAppUnits(mValue
);
86 scaleFactor
= 4 / 3.0;
91 case eCSSUnit_Millimeter
:
92 scaleFactor
= 96 / 25.4;
94 case eCSSUnit_Centimeter
:
95 scaleFactor
= 96 / 2.54;
97 case eCSSUnit_Quarter
:
98 scaleFactor
= 96 / 101.6;
101 NS_ERROR("should never get here");
104 return nsPresContext::CSSPixelsToAppUnits(float(mValue
* scaleFactor
));
107 void nsCSSValue::SetPercentValue(float aValue
) {
109 mUnit
= eCSSUnit_Percent
;
111 MOZ_ASSERT(!std::isnan(mValue
));
114 void nsCSSValue::SetFloatValue(float aValue
, nsCSSUnit aUnit
) {
115 MOZ_ASSERT(IsFloatUnit(aUnit
), "not a float value");
117 if (IsFloatUnit(aUnit
)) {
120 MOZ_ASSERT(!std::isnan(mValue
));