summaryrefslogtreecommitdiffstats
path: root/layout/style/nsCSSValue.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /layout/style/nsCSSValue.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/style/nsCSSValue.cpp')
-rw-r--r--layout/style/nsCSSValue.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp
new file mode 100644
index 0000000000..5d815c25f2
--- /dev/null
+++ b/layout/style/nsCSSValue.cpp
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* representation of simple property values within CSS declarations */
+
+#include "nsCSSValue.h"
+
+#include "mozilla/CORSMode.h"
+#include "mozilla/FontPropertyTypes.h"
+#include "mozilla/ServoBindings.h"
+#include "mozilla/ServoStyleSet.h"
+#include "mozilla/ServoTypes.h"
+#include "mozilla/StyleSheetInlines.h"
+#include "mozilla/Likely.h"
+#include "mozilla/MemoryReporting.h"
+#include "mozilla/css/ImageLoader.h"
+#include "gfxFontConstants.h"
+#include "imgRequestProxy.h"
+#include "mozilla/dom/Document.h"
+#include "nsCSSProps.h"
+#include "nsNetUtil.h"
+#include "nsPresContext.h"
+#include "nsStyleUtil.h"
+#include "nsDeviceContext.h"
+#include "nsContentUtils.h"
+
+using namespace mozilla;
+using namespace mozilla::css;
+using namespace mozilla::dom;
+
+nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit) : mUnit(aUnit) {
+ MOZ_ASSERT(eCSSUnit_Null == aUnit, "not a float value");
+ mValue = aValue;
+ MOZ_ASSERT(!std::isnan(mValue));
+}
+
+nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) : mUnit(aCopy.mUnit) {
+ if (eCSSUnit_Null != mUnit) {
+ mValue = aCopy.mValue;
+ MOZ_ASSERT(!std::isnan(mValue));
+ } else {
+ MOZ_ASSERT_UNREACHABLE("unknown unit");
+ }
+}
+
+nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) {
+ if (this != &aCopy) {
+ this->~nsCSSValue();
+ new (this) nsCSSValue(aCopy);
+ }
+ return *this;
+}
+
+nsCSSValue& nsCSSValue::operator=(nsCSSValue&& aOther) {
+ MOZ_ASSERT(this != &aOther, "Self assigment with rvalue reference");
+
+ Reset();
+ mUnit = aOther.mUnit;
+ mValue = aOther.mValue;
+ aOther.mUnit = eCSSUnit_Null;
+
+ return *this;
+}
+
+bool nsCSSValue::operator==(const nsCSSValue& aOther) const {
+ if (mUnit != aOther.mUnit) {
+ return false;
+ }
+ return mValue == aOther.mValue;
+}
+
+nscoord nsCSSValue::GetPixelLength() const {
+ MOZ_ASSERT(IsPixelLengthUnit(), "not a fixed length unit");
+
+ double scaleFactor;
+ switch (mUnit) {
+ case eCSSUnit_Pixel:
+ return nsPresContext::CSSPixelsToAppUnits(mValue);
+ case eCSSUnit_Pica:
+ scaleFactor = 16.0;
+ break;
+ case eCSSUnit_Point:
+ scaleFactor = 4 / 3.0;
+ break;
+ case eCSSUnit_Inch:
+ scaleFactor = 96.0;
+ break;
+ case eCSSUnit_Millimeter:
+ scaleFactor = 96 / 25.4;
+ break;
+ case eCSSUnit_Centimeter:
+ scaleFactor = 96 / 2.54;
+ break;
+ case eCSSUnit_Quarter:
+ scaleFactor = 96 / 101.6;
+ break;
+ default:
+ NS_ERROR("should never get here");
+ return 0;
+ }
+ return nsPresContext::CSSPixelsToAppUnits(float(mValue * scaleFactor));
+}
+
+void nsCSSValue::SetPercentValue(float aValue) {
+ Reset();
+ mUnit = eCSSUnit_Percent;
+ mValue = aValue;
+ MOZ_ASSERT(!std::isnan(mValue));
+}
+
+void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit) {
+ MOZ_ASSERT(IsFloatUnit(aUnit), "not a float value");
+ Reset();
+ if (IsFloatUnit(aUnit)) {
+ mUnit = aUnit;
+ mValue = aValue;
+ MOZ_ASSERT(!std::isnan(mValue));
+ }
+}