2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* representation of simple property values within CSS declarations */
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
#include "nsCSSValue.h"
|
2010-08-19 23:33:43 +04:00
|
|
|
|
2018-01-26 01:14:13 +03:00
|
|
|
#include "mozilla/CORSMode.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2017-09-15 23:11:37 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2017-02-02 23:10:10 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2017-09-15 23:11:37 +03:00
|
|
|
#include "mozilla/ServoTypes.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2013-12-12 06:09:44 +04:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "mozilla/css/ImageLoader.h"
|
|
|
|
#include "gfxFontConstants.h"
|
|
|
|
#include "imgRequestProxy.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2010-08-19 23:33:43 +04:00
|
|
|
#include "nsCSSProps.h"
|
2011-05-11 19:28:53 +04:00
|
|
|
#include "nsNetUtil.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "nsPresContext.h"
|
2013-12-12 06:09:44 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2013-09-23 15:55:35 +04:00
|
|
|
#include "nsDeviceContext.h"
|
2016-11-02 11:58:31 +03:00
|
|
|
#include "nsContentUtils.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2013-11-15 06:42:57 +04:00
|
|
|
using namespace mozilla;
|
2016-12-01 21:37:44 +03:00
|
|
|
using namespace mozilla::css;
|
2019-01-02 16:05:23 +03:00
|
|
|
using namespace mozilla::dom;
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit) : mUnit(aUnit) {
|
2023-07-20 19:51:56 +03:00
|
|
|
MOZ_ASSERT(eCSSUnit_Null == aUnit, "not a float value");
|
|
|
|
mValue = aValue;
|
|
|
|
MOZ_ASSERT(!std::isnan(mValue));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) : mUnit(aCopy.mUnit) {
|
2023-07-20 19:51:56 +03:00
|
|
|
if (eCSSUnit_Null != mUnit) {
|
|
|
|
mValue = aCopy.mValue;
|
|
|
|
MOZ_ASSERT(!std::isnan(mValue));
|
1998-10-08 05:29:29 +04:00
|
|
|
} else {
|
2019-05-19 03:47:18 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unknown unit");
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) {
|
2005-04-03 20:47:01 +04:00
|
|
|
if (this != &aCopy) {
|
2019-05-19 03:47:18 +03:00
|
|
|
this->~nsCSSValue();
|
2005-04-03 20:47:01 +04:00
|
|
|
new (this) nsCSSValue(aCopy);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-05-20 03:09:28 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsCSSValue::operator==(const nsCSSValue& aOther) const {
|
2019-05-19 03:47:18 +03:00
|
|
|
if (mUnit != aOther.mUnit) {
|
|
|
|
return false;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2023-07-20 19:51:56 +03:00
|
|
|
return mValue == aOther.mValue;
|
2016-10-15 22:15:36 +03:00
|
|
|
}
|
|
|
|
|
2010-08-13 13:58:01 +04:00
|
|
|
nscoord nsCSSValue::GetPixelLength() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(IsPixelLengthUnit(), "not a fixed length unit");
|
2010-08-13 13:58:01 +04:00
|
|
|
|
2010-08-13 13:58:02 +04:00
|
|
|
double scaleFactor;
|
2010-08-13 13:58:01 +04:00
|
|
|
switch (mUnit) {
|
2010-08-13 13:58:02 +04:00
|
|
|
case eCSSUnit_Pixel:
|
2023-07-20 19:51:56 +03:00
|
|
|
return nsPresContext::CSSPixelsToAppUnits(mValue);
|
2010-08-13 13:58:02 +04:00
|
|
|
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;
|
2016-05-23 10:18:34 +03:00
|
|
|
break;
|
|
|
|
case eCSSUnit_Quarter:
|
|
|
|
scaleFactor = 96 / 101.6;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2010-08-13 13:58:01 +04:00
|
|
|
default:
|
|
|
|
NS_ERROR("should never get here");
|
|
|
|
return 0;
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
2023-07-20 19:51:56 +03:00
|
|
|
return nsPresContext::CSSPixelsToAppUnits(float(mValue * scaleFactor));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetPercentValue(float aValue) {
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Percent;
|
2023-07-20 19:51:56 +03:00
|
|
|
mValue = aValue;
|
|
|
|
MOZ_ASSERT(!std::isnan(mValue));
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit) {
|
2016-07-20 10:14:05 +03:00
|
|
|
MOZ_ASSERT(IsFloatUnit(aUnit), "not a float value");
|
2003-12-29 22:07:53 +03:00
|
|
|
Reset();
|
2016-07-20 10:14:05 +03:00
|
|
|
if (IsFloatUnit(aUnit)) {
|
2003-12-29 22:07:53 +03:00
|
|
|
mUnit = aUnit;
|
2023-07-20 19:51:56 +03:00
|
|
|
mValue = aValue;
|
|
|
|
MOZ_ASSERT(!std::isnan(mValue));
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
|
|
|
}
|