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"
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "imgIRequest.h"
|
2013-12-12 06:09:44 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "nsIDocument.h"
|
2018-02-26 22:43:46 +03:00
|
|
|
#include "nsIURIMutator.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;
|
1998-10-08 05:29:29 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCSSValue::nsCSSValue(int32_t aValue, nsCSSUnit aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2018-04-05 11:27:33 +03:00
|
|
|
MOZ_ASSERT(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated,
|
2015-02-10 01:34:50 +03:00
|
|
|
"not an int value");
|
2018-04-05 11:27:33 +03:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(eCSSUnit_Percent <= aUnit, "not a float value");
|
1998-10-08 05:29:29 +04:00
|
|
|
if (eCSSUnit_Percent <= aUnit) {
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-02 00:55:13 +04:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue::nsCSSValue(const nsString& aValue, nsCSSUnit aUnit)
|
1998-10-27 02:19:59 +03:00
|
|
|
: mUnit(aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(UnitHasStringValue(), "not a string value");
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2014-03-15 23:00:15 +04:00
|
|
|
mValue.mString = BufferFromString(aValue).take();
|
1998-10-27 02:19:59 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(UnitHasArrayValue(), "bad unit");
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
nsCSSValue::nsCSSValue(mozilla::css::URLValue* aValue)
|
|
|
|
: mUnit(eCSSUnit_URL)
|
|
|
|
{
|
|
|
|
mValue.mURL = aValue;
|
|
|
|
mValue.mURL->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue)
|
|
|
|
: mUnit(eCSSUnit_GridTemplateAreas)
|
|
|
|
{
|
|
|
|
mValue.mGridTemplateAreas = aValue;
|
|
|
|
mValue.mGridTemplateAreas->AddRef();
|
|
|
|
}
|
|
|
|
|
2017-10-02 05:24:25 +03:00
|
|
|
nsCSSValue::nsCSSValue(SharedFontList* aValue)
|
2014-06-06 10:09:23 +04:00
|
|
|
: mUnit(eCSSUnit_FontFamilyList)
|
|
|
|
{
|
|
|
|
mValue.mFontFamilyList = aValue;
|
|
|
|
mValue.mFontFamilyList->AddRef();
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
nsCSSValue::nsCSSValue(FontStretch aStretch)
|
|
|
|
: mUnit(eCSSUnit_FontStretch)
|
|
|
|
{
|
|
|
|
mValue.mFontStretch = aStretch;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(FontSlantStyle aStyle)
|
|
|
|
: mUnit(eCSSUnit_FontSlantStyle)
|
|
|
|
{
|
|
|
|
mValue.mFontSlantStyle = aStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(FontWeight aWeight)
|
|
|
|
: mUnit(eCSSUnit_FontWeight)
|
|
|
|
{
|
|
|
|
mValue.mFontWeight = aWeight;
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
|
|
|
|
: mUnit(aCopy.mUnit)
|
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2008-03-13 01:05:27 +03:00
|
|
|
// nothing to do, but put this important case first
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent <= mUnit) {
|
|
|
|
mValue.mFloat = aCopy.mValue.mFloat;
|
2013-05-02 00:55:13 +04:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
2008-03-13 01:05:27 +03:00
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
mValue.mString = aCopy.mValue.mString;
|
|
|
|
mValue.mString->AddRef();
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2018-04-05 11:27:33 +03:00
|
|
|
else if (eCSSUnit_Integer <= mUnit && mUnit <= eCSSUnit_Enumerated) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mValue.mInt = aCopy.mValue.mInt;
|
|
|
|
}
|
2010-05-11 19:49:43 +04:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aCopy.mValue.mArray;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
|
|
|
mValue.mURL = aCopy.mValue.mURL;
|
|
|
|
mValue.mURL->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
mValue.mPair = aCopy.mValue.mPair;
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
|
|
|
mValue.mList = aCopy.mValue.mList;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_ListDep == mUnit) {
|
|
|
|
mValue.mListDependent = aCopy.mValue.mListDependent;
|
|
|
|
}
|
2013-12-12 06:09:44 +04:00
|
|
|
else if (eCSSUnit_SharedList == mUnit) {
|
|
|
|
mValue.mSharedList = aCopy.mValue.mSharedList;
|
|
|
|
mValue.mSharedList->AddRef();
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_PairList == mUnit) {
|
|
|
|
mValue.mPairList = aCopy.mValue.mPairList;
|
|
|
|
mValue.mPairList->AddRef();
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_PairListDep == mUnit) {
|
|
|
|
mValue.mPairListDependent = aCopy.mValue.mPairListDependent;
|
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_GridTemplateAreas == mUnit) {
|
|
|
|
mValue.mGridTemplateAreas = aCopy.mValue.mGridTemplateAreas;
|
|
|
|
mValue.mGridTemplateAreas->AddRef();
|
|
|
|
}
|
2014-06-06 10:09:23 +04:00
|
|
|
else if (eCSSUnit_FontFamilyList == mUnit) {
|
|
|
|
mValue.mFontFamilyList = aCopy.mValue.mFontFamilyList;
|
|
|
|
mValue.mFontFamilyList->AddRef();
|
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_FontStretch == mUnit) {
|
|
|
|
mValue.mFontStretch = aCopy.mValue.mFontStretch;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_FontSlantStyle == mUnit) {
|
|
|
|
mValue.mFontSlantStyle = aCopy.mValue.mFontSlantStyle;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_FontWeight == mUnit) {
|
|
|
|
mValue.mFontWeight = aCopy.mValue.mFontWeight;
|
|
|
|
}
|
2017-03-10 07:53:56 +03:00
|
|
|
else if (eCSSUnit_AtomIdent == mUnit) {
|
|
|
|
mValue.mAtom = aCopy.mValue.mAtom;
|
|
|
|
mValue.mAtom->AddRef();
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(false, "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) {
|
|
|
|
Reset();
|
|
|
|
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
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mUnit != eCSSUnit_ListDep &&
|
|
|
|
aOther.mUnit != eCSSUnit_ListDep &&
|
|
|
|
mUnit != eCSSUnit_PairListDep &&
|
|
|
|
aOther.mUnit != eCSSUnit_PairListDep,
|
|
|
|
"don't use operator== with dependent lists");
|
2010-08-19 23:33:44 +04:00
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
if (mUnit == aOther.mUnit) {
|
2010-08-19 23:33:44 +04:00
|
|
|
if (mUnit <= eCSSUnit_DummyInherit) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-28 11:29:03 +04:00
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
else if (UnitHasStringValue()) {
|
2006-12-13 18:49:36 +03:00
|
|
|
return (NS_strcmp(GetBufferValue(mValue.mString),
|
|
|
|
GetBufferValue(aOther.mValue.mString)) == 0);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2018-04-05 11:27:33 +03:00
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mInt == aOther.mValue.mInt;
|
|
|
|
}
|
2010-05-11 19:49:43 +04:00
|
|
|
else if (UnitHasArrayValue()) {
|
2005-04-02 03:07:00 +04:00
|
|
|
return *mValue.mArray == *aOther.mValue.mArray;
|
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
|
|
|
return mValue.mURL->Equals(*aOther.mValue.mURL);
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_Pair == mUnit) {
|
|
|
|
return *mValue.mPair == *aOther.mValue.mPair;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_List == mUnit) {
|
2014-10-20 07:31:39 +04:00
|
|
|
return nsCSSValueList::Equal(mValue.mList, aOther.mValue.mList);
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2013-12-12 06:09:44 +04:00
|
|
|
else if (eCSSUnit_SharedList == mUnit) {
|
|
|
|
return *mValue.mSharedList == *aOther.mValue.mSharedList;
|
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
else if (eCSSUnit_PairList == mUnit) {
|
2014-10-20 07:31:39 +04:00
|
|
|
return nsCSSValuePairList::Equal(mValue.mPairList,
|
|
|
|
aOther.mValue.mPairList);
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_GridTemplateAreas == mUnit) {
|
|
|
|
return *mValue.mGridTemplateAreas == *aOther.mValue.mGridTemplateAreas;
|
|
|
|
}
|
2014-06-06 10:09:23 +04:00
|
|
|
else if (eCSSUnit_FontFamilyList == mUnit) {
|
2017-10-02 05:24:25 +03:00
|
|
|
return mValue.mFontFamilyList->mNames ==
|
|
|
|
aOther.mValue.mFontFamilyList->mNames;
|
2014-06-06 10:09:23 +04:00
|
|
|
}
|
2018-10-09 19:44:51 +03:00
|
|
|
else if (eCSSUnit_FontStretch == mUnit) {
|
|
|
|
return mValue.mFontStretch == aOther.mValue.mFontStretch;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_FontSlantStyle == mUnit) {
|
|
|
|
return mValue.mFontSlantStyle == aOther.mValue.mFontSlantStyle;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_FontWeight == mUnit) {
|
|
|
|
return mValue.mFontWeight == aOther.mValue.mFontWeight;
|
|
|
|
}
|
2017-03-10 07:53:56 +03:00
|
|
|
else if (eCSSUnit_AtomIdent == mUnit) {
|
|
|
|
return mValue.mAtom == aOther.mValue.mAtom;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mFloat == aOther.mValue.mFloat;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2016-09-12 16:33:54 +03:00
|
|
|
double
|
|
|
|
nsCSSValue::GetAngleValueInRadians() const
|
2009-11-02 22:36:43 +03:00
|
|
|
{
|
|
|
|
double angle = GetFloatValue();
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
2016-09-12 16:33:54 +03:00
|
|
|
case eCSSUnit_Radian: return angle;
|
|
|
|
case eCSSUnit_Turn: return angle * 2 * M_PI;
|
|
|
|
case eCSSUnit_Degree: return angle * M_PI / 180.0;
|
|
|
|
case eCSSUnit_Grad: return angle * M_PI / 200.0;
|
2009-11-02 22:36:43 +03:00
|
|
|
|
2016-09-12 16:33:54 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unrecognized angular unit");
|
|
|
|
return 0.0;
|
2009-11-02 22:36:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-15 22:15:36 +03:00
|
|
|
double
|
|
|
|
nsCSSValue::GetAngleValueInDegrees() const
|
|
|
|
{
|
|
|
|
double angle = GetFloatValue();
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
|
|
|
case eCSSUnit_Degree: return angle;
|
|
|
|
case eCSSUnit_Grad: return angle * 0.9; // grad / 400 * 360
|
|
|
|
case eCSSUnit_Radian: return angle * 180.0 / M_PI; // rad / 2pi * 360
|
|
|
|
case eCSSUnit_Turn: return angle * 360.0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unrecognized angular unit");
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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: return nsPresContext::CSSPixelsToAppUnits(mValue.mFloat);
|
|
|
|
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;
|
2016-05-23 10:18:34 +03:00
|
|
|
case eCSSUnit_Quarter: scaleFactor = 96/101.6; 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
|
|
|
}
|
2010-08-13 13:58:02 +04:00
|
|
|
return nsPresContext::CSSPixelsToAppUnits(float(mValue.mFloat*scaleFactor));
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:10:10 +03:00
|
|
|
// Assert against resetting non-trivial CSS values from the parallel Servo
|
|
|
|
// traversal, since the refcounts aren't thread-safe.
|
|
|
|
// Note that the caller might be an OMTA thread, which is allowed to operate off
|
|
|
|
// main thread because it owns all of the corresponding nsCSSValues and any that
|
2017-09-19 04:26:29 +03:00
|
|
|
// they might be sharing members with. Since this can happen concurrently with
|
|
|
|
// the servo traversal, we have to use a more-precise (but slower) test.
|
|
|
|
#define DO_RELEASE(member) { \
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::IsCurrentThreadInServoTraversal()); \
|
|
|
|
mValue.member->Release(); \
|
2017-02-02 23:10:10 +03:00
|
|
|
}
|
|
|
|
|
2007-08-28 10:47:32 +04:00
|
|
|
void nsCSSValue::DoReset()
|
|
|
|
{
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2017-03-12 09:40:54 +03:00
|
|
|
mValue.mString->Release();
|
2010-05-11 19:49:43 +04:00
|
|
|
} else if (UnitHasArrayValue()) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mArray);
|
2018-10-09 19:44:51 +03:00
|
|
|
} else if (eCSSUnit_URL == mUnit) {
|
|
|
|
DO_RELEASE(mURL);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_Pair == mUnit) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mPair);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_List == mUnit) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mList);
|
2013-12-12 06:09:44 +04:00
|
|
|
} else if (eCSSUnit_SharedList == mUnit) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mSharedList);
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (eCSSUnit_PairList == mUnit) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mPairList);
|
2018-10-09 19:44:51 +03:00
|
|
|
} else if (eCSSUnit_GridTemplateAreas == mUnit) {
|
|
|
|
DO_RELEASE(mGridTemplateAreas);
|
2014-06-06 10:09:23 +04:00
|
|
|
} else if (eCSSUnit_FontFamilyList == mUnit) {
|
2017-02-02 23:10:10 +03:00
|
|
|
DO_RELEASE(mFontFamilyList);
|
2017-03-10 07:53:56 +03:00
|
|
|
} else if (eCSSUnit_AtomIdent == mUnit) {
|
|
|
|
DO_RELEASE(mAtom);
|
2007-08-28 10:47:32 +04:00
|
|
|
}
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
}
|
|
|
|
|
2017-02-02 23:10:10 +03:00
|
|
|
#undef DO_RELEASE
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsCSSValue::SetIntValue(int32_t aValue, nsCSSUnit aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2018-04-05 11:27:33 +03:00
|
|
|
MOZ_ASSERT(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated,
|
2015-02-10 01:34:50 +03:00
|
|
|
"not an int value");
|
1998-10-08 05:29:29 +04:00
|
|
|
Reset();
|
2018-04-05 11:27:33 +03:00
|
|
|
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated) {
|
1998-10-08 05:29:29 +04:00
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetPercentValue(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Percent;
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-02 00:55:13 +04:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
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;
|
|
|
|
mValue.mFloat = aValue;
|
2013-05-02 00:55:13 +04:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat));
|
2003-12-29 22:07:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
void nsCSSValue::SetStringValue(const nsString& aValue,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsCSSUnit aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
2008-08-08 03:15:40 +04:00
|
|
|
mUnit = aUnit;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(UnitHasStringValue(), "not a string unit");
|
2008-08-08 03:15:40 +04:00
|
|
|
if (UnitHasStringValue()) {
|
2014-03-15 23:00:15 +04:00
|
|
|
mValue.mString = BufferFromString(aValue).take();
|
2008-08-08 03:15:40 +04:00
|
|
|
} else
|
|
|
|
mUnit = eCSSUnit_Null;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2017-05-06 04:34:35 +03:00
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
nsCSSValue::SetAtomIdentValue(already_AddRefed<nsAtom> aValue)
|
2017-05-06 04:34:35 +03:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_AtomIdent;
|
|
|
|
mValue.mAtom = aValue.take();
|
|
|
|
}
|
|
|
|
|
2016-11-01 02:30:43 +03:00
|
|
|
void nsCSSValue::SetIntegerCoordValue(nscoord aValue)
|
|
|
|
{
|
|
|
|
SetFloatValue(nsPresContext::AppUnitsToFloatCSSPixels(aValue),
|
|
|
|
eCSSUnit_Pixel);
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
void nsCSSValue::SetArrayValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = aUnit;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(UnitHasArrayValue(), "bad unit");
|
2005-04-02 03:07:00 +04:00
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
void nsCSSValue::SetURLValue(mozilla::css::URLValue* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_URL;
|
|
|
|
mValue.mURL = aValue;
|
|
|
|
mValue.mURL->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_GridTemplateAreas;
|
|
|
|
mValue.mGridTemplateAreas = aValue;
|
|
|
|
mValue.mGridTemplateAreas->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFontFamilyListValue(already_AddRefed<SharedFontList> aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_FontFamilyList;
|
|
|
|
mValue.mFontFamilyList = aValue.take();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFontStretch(FontStretch aStretch)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_FontStretch;
|
|
|
|
mValue.mFontStretch = aStretch;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFontSlantStyle(FontSlantStyle aStyle)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_FontSlantStyle;
|
|
|
|
mValue.mFontSlantStyle = aStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFontWeight(FontWeight aWeight)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_FontWeight;
|
|
|
|
mValue.mFontWeight = aWeight;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
void nsCSSValue::SetPairValue(const nsCSSValuePair* aValue)
|
|
|
|
{
|
|
|
|
// pairs should not be used for null/inherit/initial values
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
aValue->mXValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
aValue->mYValue.GetUnit() != eCSSUnit_Unset,
|
|
|
|
"missing or inappropriate pair value");
|
2010-08-19 23:33:44 +04:00
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Pair;
|
|
|
|
mValue.mPair = new nsCSSValuePair_heap(aValue->mXValue, aValue->mYValue);
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetPairValue(const nsCSSValue& xValue,
|
|
|
|
const nsCSSValue& yValue)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(xValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Null &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
xValue.GetUnit() != eCSSUnit_Unset &&
|
|
|
|
yValue.GetUnit() != eCSSUnit_Unset,
|
|
|
|
"inappropriate pair value");
|
2010-08-19 23:33:44 +04:00
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Pair;
|
|
|
|
mValue.mPair = new nsCSSValuePair_heap(xValue, yValue);
|
|
|
|
mValue.mPair->AddRef();
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValueList* nsCSSValue::SetListValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_List;
|
|
|
|
mValue.mList = new nsCSSValueList_heap;
|
|
|
|
mValue.mList->AddRef();
|
|
|
|
return mValue.mList;
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
void nsCSSValue::SetSharedListValue(nsCSSValueSharedList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_SharedList;
|
|
|
|
mValue.mSharedList = aList;
|
|
|
|
mValue.mSharedList->AddRef();
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
void nsCSSValue::SetDependentListValue(nsCSSValueList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_ListDep;
|
|
|
|
mValue.mListDependent = aList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValue::AdoptListValue(UniquePtr<nsCSSValueList> aValue)
|
|
|
|
{
|
|
|
|
// We have to copy the first element since for owned lists the first
|
|
|
|
// element should be an nsCSSValueList_heap object.
|
|
|
|
SetListValue();
|
|
|
|
mValue.mList->mValue = std::move(aValue->mValue);
|
|
|
|
mValue.mList->mNext = aValue->mNext;
|
|
|
|
aValue->mNext = nullptr;
|
|
|
|
aValue.reset();
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSValuePairList* nsCSSValue::SetPairListValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_PairList;
|
|
|
|
mValue.mPairList = new nsCSSValuePairList_heap;
|
|
|
|
mValue.mPairList->AddRef();
|
|
|
|
return mValue.mPairList;
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
void nsCSSValue::SetDependentPairListValue(nsCSSValuePairList* aList)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
if (aList) {
|
|
|
|
mUnit = eCSSUnit_PairListDep;
|
|
|
|
mValue.mPairListDependent = aList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSValue::AdoptPairListValue(UniquePtr<nsCSSValuePairList> aValue)
|
|
|
|
{
|
|
|
|
// We have to copy the first element, since for owned pair lists, the first
|
|
|
|
// element should be an nsCSSValuePairList_heap object.
|
|
|
|
SetPairListValue();
|
|
|
|
mValue.mPairList->mXValue = std::move(aValue->mXValue);
|
|
|
|
mValue.mPairList->mYValue = std::move(aValue->mYValue);
|
|
|
|
mValue.mPairList->mNext = aValue->mNext;
|
|
|
|
aValue->mNext = nullptr;
|
|
|
|
aValue.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetAutoValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetInheritValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetInitialValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Initial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetUnsetValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Unset;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetNoneValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_None;
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
void nsCSSValue::SetAllValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_All;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetNormalValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetSystemFontValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_System_Font;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetDummyValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetDummyInheritValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_DummyInherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetCalcValue(const nsStyleCoord::CalcValue* aCalc)
|
2016-11-01 02:30:43 +03:00
|
|
|
{
|
|
|
|
RefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(1);
|
2018-10-09 19:44:51 +03:00
|
|
|
if (!aCalc->mHasPercent) {
|
|
|
|
arr->Item(0).SetIntegerCoordValue(aCalc->mLength);
|
2016-11-01 02:30:43 +03:00
|
|
|
} else {
|
2018-10-09 19:44:51 +03:00
|
|
|
nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2);
|
2016-11-01 02:30:43 +03:00
|
|
|
arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus);
|
2018-10-09 19:44:51 +03:00
|
|
|
arr2->Item(0).SetIntegerCoordValue(aCalc->mLength);
|
|
|
|
arr2->Item(1).SetPercentValue(aCalc->mPercent);
|
2016-11-01 02:30:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SetArrayValue(arr, eCSSUnit_Calc);
|
|
|
|
}
|
|
|
|
|
2017-02-03 08:41:29 +03:00
|
|
|
nsStyleCoord::CalcValue
|
|
|
|
nsCSSValue::GetCalcValue() const
|
|
|
|
{
|
2018-10-09 19:44:51 +03:00
|
|
|
MOZ_ASSERT(mUnit == eCSSUnit_Calc,
|
|
|
|
"The unit should be eCSSUnit_Calc");
|
2017-02-03 08:41:29 +03:00
|
|
|
|
|
|
|
const nsCSSValue::Array* array = GetArrayValue();
|
|
|
|
MOZ_ASSERT(array->Count() == 1,
|
|
|
|
"There should be a 1-length array");
|
|
|
|
|
|
|
|
const nsCSSValue& rootValue = array->Item(0);
|
|
|
|
|
|
|
|
nsStyleCoord::CalcValue result;
|
|
|
|
|
|
|
|
if (rootValue.GetUnit() == eCSSUnit_Pixel) {
|
2017-08-05 03:36:18 +03:00
|
|
|
result.mLength = rootValue.GetPixelLength();
|
2017-02-03 08:41:29 +03:00
|
|
|
result.mPercent = 0.0f;
|
|
|
|
result.mHasPercent = false;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(rootValue.GetUnit() == eCSSUnit_Calc_Plus,
|
|
|
|
"Calc unit should be eCSSUnit_Calc_Plus");
|
|
|
|
|
|
|
|
const nsCSSValue::Array *calcPlusArray = rootValue.GetArrayValue();
|
2017-04-28 01:52:02 +03:00
|
|
|
MOZ_ASSERT(calcPlusArray->Count() == 2,
|
2017-02-03 08:41:29 +03:00
|
|
|
"eCSSUnit_Calc_Plus should have a 2-length array");
|
|
|
|
|
|
|
|
const nsCSSValue& length = calcPlusArray->Item(0);
|
|
|
|
const nsCSSValue& percent = calcPlusArray->Item(1);
|
|
|
|
MOZ_ASSERT(length.GetUnit() == eCSSUnit_Pixel,
|
|
|
|
"The first value should be eCSSUnit_Pixel");
|
|
|
|
MOZ_ASSERT(percent.GetUnit() == eCSSUnit_Percent,
|
|
|
|
"The first value should be eCSSUnit_Percent");
|
2017-08-05 03:36:18 +03:00
|
|
|
result.mLength = length.GetPixelLength();
|
2017-02-03 08:41:29 +03:00
|
|
|
result.mPercent = percent.GetPercentValue();
|
|
|
|
result.mHasPercent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
nsCSSValue::Array*
|
|
|
|
nsCSSValue::InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs)
|
|
|
|
{
|
|
|
|
RefPtr<nsCSSValue::Array> func = Array::Create(aNumArgs + 1);
|
|
|
|
func->Item(0).SetIntValue(aFunctionId, eCSSUnit_Enumerated);
|
|
|
|
SetArrayValue(func, eCSSUnit_Function);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
|
|
|
|
{
|
|
|
|
if (mUnit != eCSSUnit_Function) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Array* func = mValue.mArray;
|
|
|
|
MOZ_ASSERT(func && func->Count() >= 1 &&
|
|
|
|
func->Item(0).GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"illegally structured function value");
|
|
|
|
|
|
|
|
nsCSSKeyword thisFunctionId = func->Item(0).GetKeywordValue();
|
|
|
|
return thisFunctionId == aFunctionId;
|
|
|
|
}
|
|
|
|
|
2006-12-13 18:49:36 +03:00
|
|
|
// static
|
2010-12-05 16:17:29 +03:00
|
|
|
already_AddRefed<nsStringBuffer>
|
2006-12-13 18:49:36 +03:00
|
|
|
nsCSSValue::BufferFromString(const nsString& aValue)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStringBuffer> buffer = nsStringBuffer::FromString(aValue);
|
2006-12-13 18:49:36 +03:00
|
|
|
if (buffer) {
|
2013-04-22 15:13:22 +04:00
|
|
|
return buffer.forget();
|
2006-12-13 18:49:36 +03:00
|
|
|
}
|
2011-05-29 02:38:48 +04:00
|
|
|
|
2012-05-04 04:14:01 +04:00
|
|
|
nsString::size_type length = aValue.Length();
|
2010-12-05 16:17:29 +03:00
|
|
|
|
|
|
|
// NOTE: Alloc prouduces a new, already-addref'd (refcnt = 1) buffer.
|
2011-05-29 02:38:48 +04:00
|
|
|
// NOTE: String buffer allocation is currently fallible.
|
2014-10-21 19:42:24 +04:00
|
|
|
size_t sz = (length + 1) * sizeof(char16_t);
|
|
|
|
buffer = nsStringBuffer::Alloc(sz);
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!buffer)) {
|
2014-10-21 19:42:24 +04:00
|
|
|
NS_ABORT_OOM(sz);
|
2006-12-13 18:49:36 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* data = static_cast<char16_t*>(buffer->Data());
|
|
|
|
nsCharTraits<char16_t>::copy(data, aValue.get(), length);
|
2011-05-29 02:38:48 +04:00
|
|
|
// Null-terminate.
|
|
|
|
data[length] = 0;
|
2013-04-22 15:13:22 +04:00
|
|
|
return buffer.forget();
|
2006-12-13 18:49:36 +03:00
|
|
|
}
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
void
|
|
|
|
nsCSSValue::AtomizeIdentValue()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mUnit == eCSSUnit_Ident);
|
|
|
|
RefPtr<nsAtom> atom = NS_Atomize(GetStringBufferValue());
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_AtomIdent;
|
|
|
|
mValue.mAtom = atom.forget().take();
|
|
|
|
}
|
|
|
|
|
2015-11-03 17:18:05 +03:00
|
|
|
/* static */ void
|
|
|
|
nsCSSValue::AppendAlignJustifyValueToString(int32_t aValue, nsAString& aResult)
|
|
|
|
{
|
|
|
|
auto legacy = aValue & NS_STYLE_ALIGN_LEGACY;
|
|
|
|
if (legacy) {
|
|
|
|
aValue &= ~legacy;
|
2018-04-19 18:50:32 +03:00
|
|
|
aResult.AppendLiteral("legacy");
|
|
|
|
if (!aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(" ");
|
2015-11-03 17:18:05 +03:00
|
|
|
}
|
2018-01-24 20:13:53 +03:00
|
|
|
// Don't serialize the 'unsafe' keyword; it's the default.
|
2016-01-05 23:27:13 +03:00
|
|
|
auto overflowPos = aValue & (NS_STYLE_ALIGN_SAFE | NS_STYLE_ALIGN_UNSAFE);
|
2018-01-24 20:13:53 +03:00
|
|
|
if (MOZ_UNLIKELY(overflowPos == NS_STYLE_ALIGN_SAFE)) {
|
|
|
|
aResult.AppendLiteral("safe ");
|
|
|
|
}
|
2015-11-03 17:18:05 +03:00
|
|
|
aValue &= ~overflowPos;
|
|
|
|
MOZ_ASSERT(!(aValue & NS_STYLE_ALIGN_FLAG_BITS),
|
|
|
|
"unknown bits in align/justify value");
|
2015-11-03 17:18:05 +03:00
|
|
|
MOZ_ASSERT((aValue != NS_STYLE_ALIGN_AUTO &&
|
2016-01-05 23:27:13 +03:00
|
|
|
aValue != NS_STYLE_ALIGN_NORMAL &&
|
2015-11-03 17:18:05 +03:00
|
|
|
aValue != NS_STYLE_ALIGN_BASELINE &&
|
|
|
|
aValue != NS_STYLE_ALIGN_LAST_BASELINE) ||
|
|
|
|
(!legacy && !overflowPos),
|
2016-11-05 04:57:07 +03:00
|
|
|
"auto/normal/baseline/'last baseline' never have any flags");
|
2016-01-05 23:27:13 +03:00
|
|
|
MOZ_ASSERT(legacy == 0 || overflowPos == 0,
|
|
|
|
"'legacy' together with <overflow-position>");
|
2016-11-05 04:57:07 +03:00
|
|
|
if (aValue == NS_STYLE_ALIGN_LAST_BASELINE) {
|
|
|
|
aResult.AppendLiteral("last ");
|
|
|
|
aValue = NS_STYLE_ALIGN_BASELINE;
|
|
|
|
}
|
2015-11-03 17:18:05 +03:00
|
|
|
const auto& kwtable(nsCSSProps::kAlignAllKeywords);
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(aValue, kwtable), aResult);
|
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
switch (GetUnit()) {
|
|
|
|
// No value: nothing extra to measure.
|
|
|
|
case eCSSUnit_Null:
|
|
|
|
case eCSSUnit_Auto:
|
|
|
|
case eCSSUnit_Inherit:
|
|
|
|
case eCSSUnit_Initial:
|
2013-10-03 22:49:17 +04:00
|
|
|
case eCSSUnit_Unset:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_None:
|
|
|
|
case eCSSUnit_Normal:
|
|
|
|
case eCSSUnit_System_Font:
|
|
|
|
case eCSSUnit_All:
|
|
|
|
case eCSSUnit_Dummy:
|
|
|
|
case eCSSUnit_DummyInherit:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// String
|
|
|
|
case eCSSUnit_String:
|
|
|
|
case eCSSUnit_Ident:
|
|
|
|
case eCSSUnit_Attr:
|
2018-10-09 19:44:51 +03:00
|
|
|
case eCSSUnit_Local_Font:
|
|
|
|
case eCSSUnit_Font_Format:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_Element:
|
|
|
|
n += mValue.mString->SizeOfIncludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Array
|
|
|
|
case eCSSUnit_Array:
|
|
|
|
case eCSSUnit_Counter:
|
|
|
|
case eCSSUnit_Counters:
|
|
|
|
case eCSSUnit_Cubic_Bezier:
|
|
|
|
case eCSSUnit_Steps:
|
2014-09-25 04:19:00 +04:00
|
|
|
case eCSSUnit_Symbols:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_Function:
|
|
|
|
case eCSSUnit_Calc:
|
|
|
|
case eCSSUnit_Calc_Plus:
|
|
|
|
case eCSSUnit_Calc_Minus:
|
|
|
|
case eCSSUnit_Calc_Times_L:
|
|
|
|
case eCSSUnit_Calc_Times_R:
|
|
|
|
case eCSSUnit_Calc_Divided:
|
|
|
|
break;
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
// URL
|
|
|
|
case eCSSUnit_URL:
|
|
|
|
n += mValue.mURL->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
// Pair
|
|
|
|
case eCSSUnit_Pair:
|
|
|
|
n += mValue.mPair->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// List
|
|
|
|
case eCSSUnit_List:
|
|
|
|
n += mValue.mList->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ListDep: not measured because it's non-owning.
|
|
|
|
case eCSSUnit_ListDep:
|
|
|
|
break;
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
// SharedList
|
|
|
|
case eCSSUnit_SharedList:
|
|
|
|
// Makes more sense not to measure, since it most cases the list
|
|
|
|
// will be shared.
|
|
|
|
break;
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
// PairList
|
|
|
|
case eCSSUnit_PairList:
|
|
|
|
n += mValue.mPairList->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// PairListDep: not measured because it's non-owning.
|
|
|
|
case eCSSUnit_PairListDep:
|
|
|
|
break;
|
|
|
|
|
2018-10-09 19:44:51 +03:00
|
|
|
// GridTemplateAreas
|
|
|
|
case eCSSUnit_GridTemplateAreas:
|
|
|
|
n += mValue.mGridTemplateAreas->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
case eCSSUnit_FontFamilyList:
|
2017-10-03 07:27:45 +03:00
|
|
|
// The SharedFontList is a refcounted object, but is unique per
|
|
|
|
// declaration. We don't measure the references from computed
|
|
|
|
// values.
|
2014-06-06 10:09:23 +04:00
|
|
|
n += mValue.mFontFamilyList->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
break;
|
|
|
|
|
2017-03-10 07:53:56 +03:00
|
|
|
// Atom is always shared, and thus should not be counted.
|
|
|
|
case eCSSUnit_AtomIdent:
|
|
|
|
break;
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
// Int: nothing extra to measure.
|
|
|
|
case eCSSUnit_Integer:
|
|
|
|
case eCSSUnit_Enumerated:
|
2018-10-09 19:44:51 +03:00
|
|
|
case eCSSUnit_FontStretch:
|
|
|
|
case eCSSUnit_FontSlantStyle:
|
|
|
|
case eCSSUnit_FontWeight:
|
2016-09-16 08:30:35 +03:00
|
|
|
break;
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
// Float: nothing extra to measure.
|
|
|
|
case eCSSUnit_Percent:
|
|
|
|
case eCSSUnit_Number:
|
2012-10-20 03:21:06 +04:00
|
|
|
case eCSSUnit_ViewportWidth:
|
|
|
|
case eCSSUnit_ViewportHeight:
|
|
|
|
case eCSSUnit_ViewportMin:
|
|
|
|
case eCSSUnit_ViewportMax:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_EM:
|
|
|
|
case eCSSUnit_XHeight:
|
|
|
|
case eCSSUnit_Char:
|
|
|
|
case eCSSUnit_RootEM:
|
|
|
|
case eCSSUnit_Point:
|
|
|
|
case eCSSUnit_Inch:
|
|
|
|
case eCSSUnit_Millimeter:
|
|
|
|
case eCSSUnit_Centimeter:
|
|
|
|
case eCSSUnit_Pica:
|
|
|
|
case eCSSUnit_Pixel:
|
2016-05-23 10:18:34 +03:00
|
|
|
case eCSSUnit_Quarter:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_Degree:
|
|
|
|
case eCSSUnit_Grad:
|
2012-02-13 05:51:58 +04:00
|
|
|
case eCSSUnit_Turn:
|
2012-01-03 06:19:14 +04:00
|
|
|
case eCSSUnit_Radian:
|
|
|
|
case eCSSUnit_Hertz:
|
|
|
|
case eCSSUnit_Kilohertz:
|
|
|
|
case eCSSUnit_Seconds:
|
|
|
|
case eCSSUnit_Milliseconds:
|
2014-03-11 02:54:13 +04:00
|
|
|
case eCSSUnit_FlexFraction:
|
2012-01-03 06:19:14 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(false, "bad nsCSSUnit");
|
2012-01-03 06:19:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:43 +04:00
|
|
|
// --- nsCSSValueList -----------------
|
|
|
|
|
|
|
|
nsCSSValueList::~nsCSSValueList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValueList);
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValueList, this, mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueList*
|
|
|
|
nsCSSValueList::Clone() const
|
|
|
|
{
|
|
|
|
nsCSSValueList* result = new nsCSSValueList(*this);
|
|
|
|
nsCSSValueList* dest = result;
|
|
|
|
const nsCSSValueList* src = this->mNext;
|
|
|
|
while (src) {
|
|
|
|
dest->mNext = new nsCSSValueList(*src);
|
|
|
|
dest = dest->mNext;
|
|
|
|
src = src->mNext;
|
|
|
|
}
|
2014-09-18 09:04:20 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(result, "shouldn't return null; supposed to be infallible");
|
2010-08-19 23:33:43 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:28:07 +04:00
|
|
|
void
|
|
|
|
nsCSSValueList::CloneInto(nsCSSValueList* aList) const
|
|
|
|
{
|
2016-01-11 02:28:35 +03:00
|
|
|
NS_ASSERTION(!aList->mNext, "Must be an empty list!");
|
|
|
|
aList->mValue = mValue;
|
|
|
|
aList->mNext = mNext ? mNext->Clone() : nullptr;
|
2011-07-23 02:28:07 +04:00
|
|
|
}
|
|
|
|
|
2014-10-20 07:31:39 +04:00
|
|
|
/* static */ bool
|
|
|
|
nsCSSValueList::Equal(const nsCSSValueList* aList1,
|
|
|
|
const nsCSSValueList* aList2)
|
2010-08-19 23:33:43 +04:00
|
|
|
{
|
2014-10-20 07:31:39 +04:00
|
|
|
if (aList1 == aList2) {
|
2010-08-19 23:33:43 +04:00
|
|
|
return true;
|
2014-10-20 07:31:39 +04:00
|
|
|
}
|
2010-08-19 23:33:43 +04:00
|
|
|
|
2014-10-20 07:31:39 +04:00
|
|
|
const nsCSSValueList *p1 = aList1, *p2 = aList2;
|
2010-08-19 23:33:43 +04:00
|
|
|
for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
|
|
|
|
if (p1->mValue != p2->mValue)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !p1 && !p2; // true if same length, false otherwise
|
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValueList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSValueList* v = this;
|
|
|
|
while (v) {
|
|
|
|
n += aMallocSizeOf(v);
|
|
|
|
n += v->mValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
v = v->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValueList_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
|
|
|
size_t n = 0;
|
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mNext ? mNext->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
}
|
2012-01-03 06:19:14 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
// --- nsCSSValueSharedList -----------------
|
|
|
|
|
|
|
|
nsCSSValueSharedList::~nsCSSValueSharedList()
|
|
|
|
{
|
|
|
|
if (mHead) {
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValueList, mHead, mNext);
|
|
|
|
delete mHead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSValueSharedList::operator==(const nsCSSValueSharedList& aOther) const
|
|
|
|
{
|
2014-10-20 07:31:39 +04:00
|
|
|
return nsCSSValueList::Equal(mHead, aOther.mHead);
|
2013-12-12 06:09:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsCSSValueSharedList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
2013-12-12 06:09:44 +04:00
|
|
|
size_t n = 0;
|
2016-02-02 07:18:16 +03:00
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mHead->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2013-12-12 06:09:44 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:43 +04:00
|
|
|
// --- nsCSSValuePair -----------------
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValuePair::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValuePair_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
|
|
|
size_t n = 0;
|
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2012-01-03 06:19:14 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:43 +04:00
|
|
|
// --- nsCSSValuePairList -----------------
|
|
|
|
|
|
|
|
nsCSSValuePairList::~nsCSSValuePairList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValuePairList);
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSValuePairList, this, mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValuePairList*
|
|
|
|
nsCSSValuePairList::Clone() const
|
|
|
|
{
|
|
|
|
nsCSSValuePairList* result = new nsCSSValuePairList(*this);
|
|
|
|
nsCSSValuePairList* dest = result;
|
|
|
|
const nsCSSValuePairList* src = this->mNext;
|
|
|
|
while (src) {
|
|
|
|
dest->mNext = new nsCSSValuePairList(*src);
|
|
|
|
dest = dest->mNext;
|
|
|
|
src = src->mNext;
|
|
|
|
}
|
2014-09-18 09:04:20 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(result, "shouldn't return null; supposed to be infallible");
|
2010-08-19 23:33:43 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-20 07:31:39 +04:00
|
|
|
/* static */ bool
|
|
|
|
nsCSSValuePairList::Equal(const nsCSSValuePairList* aList1,
|
|
|
|
const nsCSSValuePairList* aList2)
|
2010-08-19 23:33:43 +04:00
|
|
|
{
|
2014-10-20 07:31:39 +04:00
|
|
|
if (aList1 == aList2) {
|
2010-08-19 23:33:43 +04:00
|
|
|
return true;
|
2014-10-20 07:31:39 +04:00
|
|
|
}
|
2010-08-19 23:33:43 +04:00
|
|
|
|
2014-10-20 07:31:39 +04:00
|
|
|
const nsCSSValuePairList *p1 = aList1, *p2 = aList2;
|
2010-08-19 23:33:43 +04:00
|
|
|
for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
|
|
|
|
if (p1->mXValue != p2->mXValue ||
|
|
|
|
p1->mYValue != p2->mYValue)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !p1 && !p2; // true if same length, false otherwise
|
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValuePairList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSValuePairList* v = this;
|
|
|
|
while (v) {
|
|
|
|
n += aMallocSizeOf(v);
|
|
|
|
n += v->mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += v->mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
v = v->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSValuePairList_heap::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
|
|
|
size_t n = 0;
|
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mXValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mYValue.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mNext ? mNext->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
}
|
2012-01-03 06:19:14 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-03-27 23:22:39 +03:00
|
|
|
size_t
|
|
|
|
nsCSSValue::Array::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
for (size_t i = 0; i < mCount; i++) {
|
|
|
|
n += mArray[i].SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:20:56 +03:00
|
|
|
css::URLValueData::URLValueData(already_AddRefed<nsIURI> aURI,
|
2017-09-15 23:11:37 +03:00
|
|
|
ServoRawOffsetArc<RustString> aString,
|
2018-09-11 21:11:19 +03:00
|
|
|
already_AddRefed<URLExtraData> aExtraData,
|
|
|
|
CORSMode aCORSMode)
|
2018-05-30 22:15:35 +03:00
|
|
|
: mURI(std::move(aURI))
|
|
|
|
, mExtraData(std::move(aExtraData))
|
2017-09-15 23:11:37 +03:00
|
|
|
, mURIResolved(true)
|
2018-04-10 17:54:57 +03:00
|
|
|
, mString(aString)
|
2018-09-11 21:11:19 +03:00
|
|
|
, mCORSMode(aCORSMode)
|
2017-09-15 23:11:37 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mExtraData);
|
|
|
|
MOZ_ASSERT(mExtraData->GetPrincipal());
|
|
|
|
}
|
|
|
|
|
|
|
|
css::URLValueData::URLValueData(ServoRawOffsetArc<RustString> aString,
|
2018-09-11 21:11:19 +03:00
|
|
|
already_AddRefed<URLExtraData> aExtraData,
|
|
|
|
CORSMode aCORSMode)
|
2018-05-30 22:15:35 +03:00
|
|
|
: mExtraData(std::move(aExtraData))
|
2016-05-21 03:02:54 +03:00
|
|
|
, mURIResolved(false)
|
2018-04-10 17:54:57 +03:00
|
|
|
, mString(aString)
|
2018-09-11 21:11:19 +03:00
|
|
|
, mCORSMode(aCORSMode)
|
2016-05-21 03:02:54 +03:00
|
|
|
{
|
2017-03-30 10:54:48 +03:00
|
|
|
MOZ_ASSERT(mExtraData);
|
|
|
|
MOZ_ASSERT(mExtraData->GetPrincipal());
|
2007-05-03 05:15:53 +04:00
|
|
|
}
|
|
|
|
|
2017-09-15 23:11:37 +03:00
|
|
|
css::URLValueData::~URLValueData()
|
|
|
|
{
|
2018-04-10 17:54:57 +03:00
|
|
|
Servo_ReleaseArcStringData(&mString);
|
2017-09-15 23:11:37 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-10-11 09:56:11 +03:00
|
|
|
css::URLValueData::Equals(const URLValueData& aOther) const
|
2007-05-03 05:15:53 +04:00
|
|
|
{
|
2016-10-11 09:56:11 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool eq;
|
2017-03-30 10:54:48 +03:00
|
|
|
const URLExtraData* self = mExtraData;
|
|
|
|
const URLExtraData* other = aOther.mExtraData;
|
2018-04-10 17:54:57 +03:00
|
|
|
return GetString() == aOther.GetString() &&
|
2011-05-11 19:28:53 +04:00
|
|
|
(GetURI() == aOther.GetURI() || // handles null == null
|
2007-05-03 05:15:53 +04:00
|
|
|
(mURI && aOther.mURI &&
|
|
|
|
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
|
|
|
|
eq)) &&
|
2017-03-30 10:54:48 +03:00
|
|
|
(self->BaseURI() == other->BaseURI() ||
|
|
|
|
(NS_SUCCEEDED(self->BaseURI()->Equals(other->BaseURI(), &eq)) &&
|
2016-09-02 17:22:47 +03:00
|
|
|
eq)) &&
|
2017-03-30 10:54:48 +03:00
|
|
|
(self->GetPrincipal() == other->GetPrincipal() ||
|
|
|
|
self->GetPrincipal()->Equals(other->GetPrincipal())) &&
|
2017-04-10 12:25:48 +03:00
|
|
|
IsLocalRef() == aOther.IsLocalRef();
|
2007-07-19 02:17:30 +04:00
|
|
|
}
|
|
|
|
|
2016-09-02 17:22:47 +03:00
|
|
|
bool
|
|
|
|
css::URLValueData::DefinitelyEqualURIs(const URLValueData& aOther) const
|
|
|
|
{
|
2017-09-15 23:11:37 +03:00
|
|
|
if (mExtraData->BaseURI() != aOther.mExtraData->BaseURI()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 17:54:57 +03:00
|
|
|
return GetString() == aOther.GetString();
|
2016-09-02 17:22:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
css::URLValueData::DefinitelyEqualURIsAndPrincipal(
|
|
|
|
const URLValueData& aOther) const
|
|
|
|
{
|
2017-03-30 10:54:48 +03:00
|
|
|
return mExtraData->GetPrincipal() == aOther.mExtraData->GetPrincipal() &&
|
2016-09-02 17:22:47 +03:00
|
|
|
DefinitelyEqualURIs(aOther);
|
|
|
|
}
|
|
|
|
|
2017-09-15 23:11:37 +03:00
|
|
|
nsDependentCSubstring
|
2018-04-10 17:54:57 +03:00
|
|
|
css::URLValueData::GetString() const
|
2017-09-15 23:11:37 +03:00
|
|
|
{
|
2017-09-26 05:31:10 +03:00
|
|
|
const uint8_t* chars;
|
2017-09-15 23:11:37 +03:00
|
|
|
uint32_t len;
|
2018-04-10 17:54:57 +03:00
|
|
|
Servo_GetArcStringData(mString.mPtr, &chars, &len);
|
2017-09-15 23:11:37 +03:00
|
|
|
return nsDependentCSubstring(reinterpret_cast<const char*>(chars), len);
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
nsIURI*
|
2016-05-21 03:02:53 +03:00
|
|
|
css::URLValueData::GetURI() const
|
2011-05-11 19:28:53 +04:00
|
|
|
{
|
2016-09-02 17:22:47 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
if (!mURIResolved) {
|
2016-09-02 17:22:47 +03:00
|
|
|
MOZ_ASSERT(!mURI);
|
2011-05-11 19:28:53 +04:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
2018-04-10 17:54:57 +03:00
|
|
|
NS_NewURI(getter_AddRefs(newURI),
|
|
|
|
GetString(),
|
|
|
|
nullptr, mExtraData->BaseURI());
|
2018-04-10 16:20:56 +03:00
|
|
|
mURI = newURI.forget();
|
2016-09-02 17:22:47 +03:00
|
|
|
mURIResolved = true;
|
2011-05-11 19:28:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mURI;
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:25:48 +03:00
|
|
|
bool
|
|
|
|
css::URLValueData::IsLocalRef() const
|
|
|
|
{
|
|
|
|
if (mIsLocalRef.isNothing()) {
|
|
|
|
// IsLocalRefURL is O(N), use it only when IsLocalRef is called.
|
2018-04-10 17:54:57 +03:00
|
|
|
mIsLocalRef.emplace(nsContentUtils::IsLocalRefURL(GetString()));
|
2017-04-10 12:25:48 +03:00
|
|
|
}
|
|
|
|
return mIsLocalRef.value();
|
|
|
|
}
|
|
|
|
|
2017-03-07 12:31:48 +03:00
|
|
|
bool
|
|
|
|
css::URLValueData::HasRef() const
|
|
|
|
{
|
2017-07-21 11:34:20 +03:00
|
|
|
if (IsLocalRef()) {
|
2018-10-01 10:42:05 +03:00
|
|
|
return true;
|
2017-03-07 12:31:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-01 10:42:05 +03:00
|
|
|
if (nsIURI* uri = GetURI()) {
|
|
|
|
nsAutoCString ref;
|
|
|
|
nsresult rv = uri->GetRef(ref);
|
|
|
|
return NS_SUCCEEDED(rv) && !ref.IsEmpty();
|
2017-04-10 11:41:51 +03:00
|
|
|
}
|
|
|
|
|
2018-10-01 10:42:05 +03:00
|
|
|
return false;
|
2017-04-10 11:41:51 +03:00
|
|
|
}
|
|
|
|
|
2016-10-11 09:56:11 +03:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
css::URLValueData::ResolveLocalRef(nsIURI* aURI) const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> result = GetURI();
|
|
|
|
|
2017-04-10 12:25:48 +03:00
|
|
|
if (result && IsLocalRef()) {
|
2016-10-11 09:56:11 +03:00
|
|
|
nsCString ref;
|
|
|
|
mURI->GetRef(ref);
|
|
|
|
|
2018-02-26 22:43:46 +03:00
|
|
|
nsresult rv = NS_MutateURI(aURI)
|
|
|
|
.SetRef(ref)
|
|
|
|
.Finalize(result);
|
2018-06-14 14:05:43 +03:00
|
|
|
|
2018-02-26 22:43:46 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-06-14 14:05:43 +03:00
|
|
|
// If setting the ref failed, just return the original URI.
|
|
|
|
result = aURI;
|
2018-02-26 22:43:46 +03:00
|
|
|
}
|
2016-10-11 09:56:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
css::URLValueData::ResolveLocalRef(nsIContent* aContent) const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> url = aContent->GetBaseURI();
|
|
|
|
return ResolveLocalRef(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
css::URLValueData::GetSourceString(nsString& aRef) const
|
|
|
|
{
|
|
|
|
nsIURI* uri = GetURI();
|
|
|
|
if (!uri) {
|
|
|
|
aRef.Truncate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString cref;
|
2017-04-10 12:25:48 +03:00
|
|
|
if (IsLocalRef()) {
|
2016-10-11 09:56:11 +03:00
|
|
|
// XXXheycam It's possible we can just return mString in this case, since
|
|
|
|
// it should be the "#fragment" string the URLValueData was created with.
|
|
|
|
uri->GetRef(cref);
|
|
|
|
cref.Insert('#', 0);
|
|
|
|
} else {
|
|
|
|
// It's not entirely clear how to best handle failure here. Ensuring the
|
|
|
|
// string is empty seems safest.
|
|
|
|
nsresult rv = uri->GetSpec(cref);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
cref.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aRef = NS_ConvertUTF8toUTF16(cref);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
css::URLValueData::EqualsExceptRef(nsIURI* aURI) const
|
|
|
|
{
|
|
|
|
nsIURI* uri = GetURI();
|
|
|
|
if (!uri) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
uri->EqualsExceptRef(aURI, &ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-21 03:02:53 +03:00
|
|
|
size_t
|
|
|
|
css::URLValueData::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
// Measurement of the following members may be added later if DMD finds it
|
|
|
|
// is worthwhile:
|
|
|
|
// - mURI
|
2018-04-10 17:54:57 +03:00
|
|
|
// - mString
|
2017-03-30 10:54:48 +03:00
|
|
|
// - mExtraData
|
2018-04-10 17:54:57 +03:00
|
|
|
return 0;
|
2016-05-21 03:02:54 +03:00
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
css::URLValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
|
|
|
size_t n = 0;
|
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
2016-05-21 03:02:53 +03:00
|
|
|
n += URLValueData::SizeOfExcludingThis(aMallocSizeOf);
|
2016-02-02 07:18:16 +03:00
|
|
|
}
|
2012-01-03 06:19:14 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-04-10 17:54:57 +03:00
|
|
|
css::ImageValue::ImageValue(nsIURI* aURI,
|
|
|
|
ServoRawOffsetArc<RustString> aString,
|
2017-09-15 23:11:37 +03:00
|
|
|
already_AddRefed<URLExtraData> aExtraData,
|
2018-01-29 21:55:38 +03:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
CORSMode aCORSMode)
|
2018-09-11 21:11:19 +03:00
|
|
|
: URLValueData(do_AddRef(aURI), aString, std::move(aExtraData), aCORSMode)
|
2017-09-15 23:11:37 +03:00
|
|
|
{
|
2018-10-04 03:20:50 +03:00
|
|
|
LoadImage(aDocument);
|
2017-09-15 23:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
css::ImageValue::ImageValue(ServoRawOffsetArc<RustString> aString,
|
2018-01-29 21:55:38 +03:00
|
|
|
already_AddRefed<URLExtraData> aExtraData,
|
|
|
|
CORSMode aCORSMode)
|
2018-09-11 21:11:19 +03:00
|
|
|
: URLValueData(aString, std::move(aExtraData), aCORSMode)
|
2017-09-15 23:11:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-04 03:42:28 +03:00
|
|
|
imgRequestProxy*
|
|
|
|
css::ImageValue::LoadImage(nsIDocument* aDocument)
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
2016-05-21 03:02:54 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2018-10-04 03:20:50 +03:00
|
|
|
static uint64_t sNextLoadID = 1;
|
|
|
|
|
|
|
|
if (mLoadID == 0) {
|
|
|
|
mLoadID = sNextLoadID++;
|
|
|
|
}
|
|
|
|
|
2013-02-23 18:59:43 +04:00
|
|
|
// NB: If aDocument is not the original document, we may not be able to load
|
|
|
|
// images from aDocument. Instead we do the image load from the original doc
|
|
|
|
// and clone it to aDocument.
|
|
|
|
nsIDocument* loadingDoc = aDocument->GetOriginalDocument();
|
|
|
|
if (!loadingDoc) {
|
|
|
|
loadingDoc = aDocument;
|
2010-10-09 14:03:06 +04:00
|
|
|
}
|
2012-08-14 02:04:19 +04:00
|
|
|
|
2018-10-04 03:20:50 +03:00
|
|
|
// Kick off the load in the loading document.
|
|
|
|
ImageLoader::LoadImage(GetURI(),
|
|
|
|
mExtraData->GetPrincipal(),
|
|
|
|
mExtraData->GetReferrer(),
|
|
|
|
mExtraData->GetReferrerPolicy(),
|
|
|
|
loadingDoc,
|
|
|
|
this,
|
|
|
|
mCORSMode);
|
2013-02-23 18:59:43 +04:00
|
|
|
|
2018-10-04 21:32:33 +03:00
|
|
|
// Register the image in the document that's using it.
|
|
|
|
return aDocument->StyleImageLoader()->RegisterCSSImage(this);
|
2012-08-14 02:04:19 +04:00
|
|
|
}
|
|
|
|
|
2015-11-23 08:12:49 +03:00
|
|
|
css::ImageValue::~ImageValue()
|
2012-08-14 02:04:19 +04:00
|
|
|
{
|
2018-10-04 03:20:50 +03:00
|
|
|
if (mLoadID != 0) {
|
|
|
|
ImageLoader::DeregisterCSSImageFromAllLoaders(this);
|
2015-11-23 08:12:49 +03:00
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
}
|
|
|
|
|
2017-09-14 11:48:19 +03:00
|
|
|
size_t
|
|
|
|
css::ImageValue::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += css::URLValueData::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-03-11 02:54:14 +04:00
|
|
|
size_t
|
2014-03-21 19:06:13 +04:00
|
|
|
mozilla::css::GridTemplateAreasValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2014-03-11 02:54:14 +04:00
|
|
|
{
|
2016-02-02 07:18:16 +03:00
|
|
|
// Only measure it if it's unshared, to avoid double-counting.
|
|
|
|
size_t n = 0;
|
|
|
|
if (mRefCnt <= 1) {
|
|
|
|
n += aMallocSizeOf(this);
|
|
|
|
n += mNamedAreas.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mTemplates.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2014-03-11 02:54:14 +04:00
|
|
|
return n;
|
|
|
|
}
|