2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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 a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2010-08-19 23:33:44 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2010-07-03 08:18:55 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
// check that we can fit all the CSS properties into a PRUint8
|
|
|
|
// for the mOrder array - if not, might need to use PRUint16!
|
2012-02-23 20:19:00 +04:00
|
|
|
MOZ_STATIC_ASSERT(eCSSProperty_COUNT_no_shorthands - 1 <= PR_UINT8_MAX,
|
|
|
|
"CSS longhand property numbers no longer fit in a PRUint8");
|
2010-07-23 22:00:52 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::Declaration()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mImmutable(false)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::Declaration(const Declaration& aCopy)
|
2008-01-10 23:13:24 +03:00
|
|
|
: mOrder(aCopy.mOrder),
|
2012-07-30 18:20:58 +04:00
|
|
|
mData(aCopy.mData ? aCopy.mData->Clone() : nullptr),
|
2009-12-11 19:13:19 +03:00
|
|
|
mImportantData(aCopy.mImportantData
|
2012-07-30 18:20:58 +04:00
|
|
|
? aCopy.mImportantData->Clone() : nullptr),
|
2011-10-17 18:59:28 +04:00
|
|
|
mImmutable(false)
|
1999-06-03 05:58:11 +04:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
1999-06-03 05:58:11 +04:00
|
|
|
}
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::~Declaration()
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_DTOR(mozilla::css::Declaration);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::ValueAppended(nsCSSProperty aProperty)
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
2010-07-23 22:00:49 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData,
|
|
|
|
"should only be called while expanded");
|
2009-03-06 07:05:01 +03:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"shorthands forbidden");
|
2003-06-08 02:14:42 +04:00
|
|
|
// order IS important for CSS, so remove and add to the end
|
2009-03-06 07:05:01 +03:00
|
|
|
mOrder.RemoveElement(aProperty);
|
|
|
|
mOrder.AppendElement(aProperty);
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::RemoveProperty(nsCSSProperty aProperty)
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSExpandedDataBlock data;
|
2009-12-11 19:13:19 +03:00
|
|
|
ExpandTo(&data);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "Expand didn't null things out");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2010-07-23 22:00:42 +04:00
|
|
|
data.ClearLonghandProperty(*p);
|
2008-01-10 23:13:24 +03:00
|
|
|
mOrder.RemoveElement(*p);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-23 22:00:42 +04:00
|
|
|
data.ClearLonghandProperty(aProperty);
|
2008-01-10 23:13:24 +03:00
|
|
|
mOrder.RemoveElement(aProperty);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
CompressFrom(&data);
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-24 21:31:52 +03:00
|
|
|
Declaration::HasProperty(nsCSSProperty aProperty) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
return !!val;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-19 23:33:44 +04:00
|
|
|
Declaration::AppendValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAString& aResult) const
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2010-07-23 22:00:29 +04:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
if (!val) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-23 22:00:29 +04:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
val->AppendToString(aProperty, aResult);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
|
1998-10-08 05:31:58 +04:00
|
|
|
{
|
|
|
|
aValue.Truncate(0);
|
1998-09-30 05:08:59 +04:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
// simple properties are easy.
|
2004-10-01 02:32:28 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2003-06-08 02:14:42 +04:00
|
|
|
AppendValueToString(aProperty, aValue);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-10-08 02:10:20 +04:00
|
|
|
// DOM Level 2 Style says (when describing CSS2Properties, although
|
|
|
|
// not CSSStyleDeclaration.getPropertyValue):
|
|
|
|
// However, if there is no shorthand declaration that could be added
|
|
|
|
// to the ruleset without changing in any way the rules already
|
|
|
|
// declared in the ruleset (i.e., by adding longhand rules that were
|
|
|
|
// previously not declared in the ruleset), then the empty string
|
|
|
|
// should be returned for the shorthand property.
|
|
|
|
// This means we need to check a number of cases:
|
|
|
|
// (1) Since a shorthand sets all sub-properties, if some of its
|
|
|
|
// subproperties were not specified, we must return the empty
|
|
|
|
// string.
|
|
|
|
// (2) Since 'inherit' and 'initial' can only be specified as the
|
|
|
|
// values for entire properties, we need to return the empty
|
|
|
|
// string if some but not all of the subproperties have one of
|
|
|
|
// those values.
|
|
|
|
// (3) Since a single value only makes sense with or without
|
|
|
|
// !important, we return the empty string if some values are
|
|
|
|
// !important and some are not.
|
|
|
|
// Since we're doing this check for 'inherit' and 'initial' up front,
|
|
|
|
// we can also simplify the property serialization code by serializing
|
|
|
|
// those values up front as well.
|
|
|
|
PRUint32 totalCount = 0, importantCount = 0,
|
|
|
|
initialCount = 0, inheritCount = 0;
|
2007-06-12 22:28:56 +04:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2008-10-08 02:10:20 +04:00
|
|
|
if (*p == eCSSProperty__x_system_font ||
|
2008-10-27 20:55:51 +03:00
|
|
|
nsCSSProps::PropHasFlags(*p, CSS_PROPERTY_DIRECTIONAL_SOURCE)) {
|
2008-10-08 02:10:20 +04:00
|
|
|
// The system-font subproperty and the *-source properties don't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++totalCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = mData->ValueFor(*p);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!val || !mImportantData || !mImportantData->ValueFor(*p),
|
|
|
|
"can't be in both blocks");
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!val && mImportantData) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++importantCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
val = mImportantData->ValueFor(*p);
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!val) {
|
2008-10-08 02:10:20 +04:00
|
|
|
// Case (1) above: some subproperties not specified.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
if (val->GetUnit() == eCSSUnit_Inherit) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++inheritCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Initial) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++initialCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (importantCount != 0 && importantCount != totalCount) {
|
|
|
|
// Case (3), no consistent importance.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
if (initialCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing initial up-front.
|
2010-07-23 22:00:27 +04:00
|
|
|
nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
if (inheritCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing inherit up-front.
|
2010-07-23 22:00:27 +04:00
|
|
|
nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
if (initialCount != 0 || inheritCount != 0) {
|
|
|
|
// Case (2): partially initial or inherit.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
|
1998-10-08 05:31:58 +04:00
|
|
|
switch (aProperty) {
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_margin:
|
|
|
|
case eCSSProperty_padding:
|
|
|
|
case eCSSProperty_border_color:
|
|
|
|
case eCSSProperty_border_style:
|
|
|
|
case eCSSProperty_border_width: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[0]).Find("-top") !=
|
|
|
|
kNotFound, "first subprop must be top");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[1]).Find("-right") !=
|
|
|
|
kNotFound, "second subprop must be right");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[2]).Find("-bottom") !=
|
|
|
|
kNotFound, "third subprop must be bottom");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[3]).Find("-left") !=
|
|
|
|
kNotFound, "fourth subprop must be left");
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue &topValue = *data->ValueFor(subprops[0]);
|
|
|
|
const nsCSSValue &rightValue = *data->ValueFor(subprops[1]);
|
|
|
|
const nsCSSValue &bottomValue = *data->ValueFor(subprops[2]);
|
|
|
|
const nsCSSValue &leftValue = *data->ValueFor(subprops[3]);
|
2010-07-23 22:00:27 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(topValue.GetUnit() != eCSSUnit_Null, "null top");
|
2010-07-23 22:00:27 +04:00
|
|
|
topValue.AppendToString(subprops[0], aValue);
|
2008-12-23 17:06:57 +03:00
|
|
|
if (topValue != rightValue || topValue != leftValue ||
|
|
|
|
topValue != bottomValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(rightValue.GetUnit() != eCSSUnit_Null, "null right");
|
2010-07-23 22:00:27 +04:00
|
|
|
rightValue.AppendToString(subprops[1], aValue);
|
2008-12-23 17:06:57 +03:00
|
|
|
if (topValue != bottomValue || rightValue != leftValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(bottomValue.GetUnit() != eCSSUnit_Null, "null bottom");
|
2010-07-23 22:00:27 +04:00
|
|
|
bottomValue.AppendToString(subprops[2], aValue);
|
2008-12-23 17:06:57 +03:00
|
|
|
if (rightValue != leftValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(leftValue.GetUnit() != eCSSUnit_Null, "null left");
|
2010-07-23 22:00:27 +04:00
|
|
|
leftValue.AppendToString(subprops[3], aValue);
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
|
|
|
}
|
1998-10-08 05:31:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2010-09-09 19:21:47 +04:00
|
|
|
case eCSSProperty_border_radius:
|
2008-10-01 09:50:52 +04:00
|
|
|
case eCSSProperty__moz_outline_radius: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue* vals[4] = {
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
2008-10-01 09:50:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// For compatibility, only write a slash and the y-values
|
|
|
|
// if they're not identical to the x-values.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needY = false;
|
2010-08-19 23:33:44 +04:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (vals[i]->GetUnit() == eCSSUnit_Pair) {
|
2011-10-17 18:59:28 +04:00
|
|
|
needY = true;
|
2010-08-19 23:33:44 +04:00
|
|
|
vals[i]->GetPairValue().mXValue.AppendToString(subprops[i], aValue);
|
|
|
|
} else {
|
|
|
|
vals[i]->AppendToString(subprops[i], aValue);
|
|
|
|
}
|
|
|
|
if (i < 3)
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needY) {
|
2008-10-01 09:50:52 +04:00
|
|
|
aValue.AppendLiteral(" / ");
|
2010-08-19 23:33:44 +04:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (vals[i]->GetUnit() == eCSSUnit_Pair) {
|
|
|
|
vals[i]->GetPairValue().mYValue.AppendToString(subprops[i], aValue);
|
|
|
|
} else {
|
|
|
|
vals[i]->AppendToString(subprops[i], aValue);
|
|
|
|
}
|
|
|
|
if (i < 3)
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2008-10-01 09:50:52 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-05-31 09:19:49 +04:00
|
|
|
case eCSSProperty_border_image: {
|
|
|
|
// Even though there are some cases where we could omit
|
|
|
|
// 'border-image-source' (when it's none), it's probably not a
|
|
|
|
// good idea since it's likely to be confusing. It would also
|
|
|
|
// require adding the extra check that we serialize *something*.
|
2011-12-23 03:34:45 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_source, aValue);
|
2012-05-31 09:19:49 +04:00
|
|
|
|
|
|
|
bool sliceDefault = data->HasDefaultBorderImageSlice();
|
|
|
|
bool widthDefault = data->HasDefaultBorderImageWidth();
|
|
|
|
bool outsetDefault = data->HasDefaultBorderImageOutset();
|
|
|
|
|
|
|
|
if (!sliceDefault || !widthDefault || !outsetDefault) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_border_image_slice, aValue);
|
|
|
|
if (!widthDefault || !outsetDefault) {
|
|
|
|
aValue.Append(NS_LITERAL_STRING(" /"));
|
|
|
|
if (!widthDefault) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_border_image_width, aValue);
|
|
|
|
}
|
|
|
|
if (!outsetDefault) {
|
|
|
|
aValue.Append(NS_LITERAL_STRING(" / "));
|
|
|
|
AppendValueToString(eCSSProperty_border_image_outset, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool repeatDefault = data->HasDefaultBorderImageRepeat();
|
|
|
|
if (!repeatDefault) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_border_image_repeat, aValue);
|
|
|
|
}
|
2011-12-23 03:34:45 +04:00
|
|
|
break;
|
2012-05-31 09:19:49 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
case eCSSProperty_border: {
|
2012-05-31 09:19:49 +04:00
|
|
|
// If we have a non-default value for any of the properties that
|
|
|
|
// this shorthand sets but cannot specify, we have to return the
|
|
|
|
// empty string.
|
|
|
|
if (data->ValueFor(eCSSProperty_border_image_source)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
!data->HasDefaultBorderImageSlice() ||
|
|
|
|
!data->HasDefaultBorderImageWidth() ||
|
|
|
|
!data->HasDefaultBorderImageOutset() ||
|
|
|
|
!data->HasDefaultBorderImageRepeat() ||
|
|
|
|
data->ValueFor(eCSSProperty_border_top_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_right_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_bottom_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_left_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
const nsCSSProperty* subproptables[3] = {
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_style),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_width)
|
|
|
|
};
|
2011-09-29 10:19:26 +04:00
|
|
|
bool match = true;
|
2008-12-23 17:06:57 +03:00
|
|
|
for (const nsCSSProperty** subprops = subproptables,
|
2011-10-11 09:50:08 +04:00
|
|
|
**subprops_end = ArrayEnd(subproptables);
|
2008-12-23 17:06:57 +03:00
|
|
|
subprops < subprops_end; ++subprops) {
|
|
|
|
// Check only the first four subprops in each table, since the
|
|
|
|
// others are extras for dimensional box properties.
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *firstSide = data->ValueFor((*subprops)[0]);
|
2008-12-23 17:06:57 +03:00
|
|
|
for (PRInt32 side = 1; side < 4; ++side) {
|
|
|
|
const nsCSSValue *otherSide =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor((*subprops)[side]);
|
2008-12-23 17:06:57 +03:00
|
|
|
if (*firstSide != *otherSide)
|
2011-10-17 18:59:28 +04:00
|
|
|
match = false;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
|
|
|
// We can't express what we have in the border shorthand
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// tweak aProperty and fall through
|
2003-06-08 02:14:42 +04:00
|
|
|
aProperty = eCSSProperty_border_top;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_right:
|
|
|
|
case eCSSProperty_border_bottom:
|
|
|
|
case eCSSProperty_border_left:
|
2007-07-04 22:51:16 +04:00
|
|
|
case eCSSProperty_border_start:
|
|
|
|
case eCSSProperty_border_end:
|
2008-07-19 14:38:25 +04:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline: {
|
2003-06-08 02:14:42 +04:00
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
|
|
|
|
NS_LITERAL_CSTRING("-color")) ||
|
|
|
|
StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
|
|
|
|
NS_LITERAL_CSTRING("-color-value")),
|
|
|
|
"third subprop must be the color property");
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isMozUseTextColor =
|
2008-12-23 17:06:57 +03:00
|
|
|
colorValue->GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
colorValue->GetIntValue() == NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR;
|
2003-06-08 02:14:42 +04:00
|
|
|
if (!AppendValueToString(subprops[0], aValue) ||
|
|
|
|
!(aValue.Append(PRUnichar(' ')),
|
|
|
|
AppendValueToString(subprops[1], aValue)) ||
|
2008-12-23 17:06:57 +03:00
|
|
|
// Don't output a third value when it's -moz-use-text-color.
|
|
|
|
!(isMozUseTextColor ||
|
|
|
|
(aValue.Append(PRUnichar(' ')),
|
|
|
|
AppendValueToString(subprops[2], aValue)))) {
|
2003-06-08 02:14:42 +04:00
|
|
|
aValue.Truncate();
|
1998-10-08 05:31:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_start:
|
|
|
|
case eCSSProperty_margin_end:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_start:
|
2007-07-04 22:51:16 +04:00
|
|
|
case eCSSProperty_padding_end:
|
|
|
|
case eCSSProperty_border_left_color:
|
|
|
|
case eCSSProperty_border_left_style:
|
|
|
|
case eCSSProperty_border_left_width:
|
|
|
|
case eCSSProperty_border_right_color:
|
|
|
|
case eCSSProperty_border_right_style:
|
|
|
|
case eCSSProperty_border_right_width:
|
|
|
|
case eCSSProperty_border_start_color:
|
|
|
|
case eCSSProperty_border_start_style:
|
|
|
|
case eCSSProperty_border_start_width:
|
|
|
|
case eCSSProperty_border_end_color:
|
|
|
|
case eCSSProperty_border_end_style:
|
|
|
|
case eCSSProperty_border_end_width: {
|
2004-02-04 09:10:56 +03:00
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
2004-02-04 09:10:56 +03:00
|
|
|
AppendValueToString(subprops[0], aValue);
|
|
|
|
break;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_background: {
|
2009-02-20 08:29:21 +03:00
|
|
|
// We know from above that all subproperties were specified.
|
|
|
|
// However, we still can't represent that in the shorthand unless
|
|
|
|
// they're all lists of the same length. So if they're different
|
|
|
|
// lengths, we need to bail out.
|
|
|
|
// We also need to bail out if an item has background-clip and
|
|
|
|
// background-origin that are different and not the default
|
|
|
|
// values. (We omit them if they're both default.)
|
|
|
|
const nsCSSValueList *image =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_image)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2012-02-25 09:23:14 +04:00
|
|
|
const nsCSSValuePairList *repeat =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_repeat)->
|
2012-02-25 09:23:14 +04:00
|
|
|
GetPairListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *attachment =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_attachment)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2012-02-20 04:14:42 +04:00
|
|
|
const nsCSSValueList *position =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_position)->
|
2012-02-20 04:14:42 +04:00
|
|
|
GetListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *clip =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_clip)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *origin =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_origin)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2009-05-28 22:09:05 +04:00
|
|
|
const nsCSSValuePairList *size =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_size)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetPairListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
for (;;) {
|
2009-12-16 00:40:38 +03:00
|
|
|
if (size->mXValue.GetUnit() != eCSSUnit_Auto ||
|
|
|
|
size->mYValue.GetUnit() != eCSSUnit_Auto) {
|
|
|
|
// Non-default background-size, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-12-16 00:40:38 +03:00
|
|
|
}
|
2010-07-23 22:00:27 +04:00
|
|
|
image->mValue.AppendToString(eCSSProperty_background_image, aValue);
|
2009-02-19 04:13:25 +03:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2012-02-25 09:23:14 +04:00
|
|
|
repeat->mXValue.AppendToString(eCSSProperty_background_repeat, aValue);
|
|
|
|
if (repeat->mYValue.GetUnit() != eCSSUnit_Null) {
|
|
|
|
repeat->mYValue.AppendToString(eCSSProperty_background_repeat, aValue);
|
|
|
|
}
|
2009-02-19 18:29:28 +03:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 22:00:27 +04:00
|
|
|
attachment->mValue.AppendToString(eCSSProperty_background_attachment,
|
|
|
|
aValue);
|
2009-02-19 23:33:09 +03:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2012-02-20 04:14:42 +04:00
|
|
|
position->mValue.AppendToString(eCSSProperty_background_position,
|
|
|
|
aValue);
|
2012-02-23 20:19:00 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(clip->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
origin->mValue.GetUnit() == eCSSUnit_Enumerated,
|
2012-02-23 20:19:00 +04:00
|
|
|
"should not have inherit/initial within list");
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
if (clip->mValue.GetIntValue() != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
origin->mValue.GetIntValue() != NS_STYLE_BG_ORIGIN_PADDING) {
|
2012-02-23 20:19:00 +04:00
|
|
|
// The shorthand only has a single clip/origin value which sets
|
|
|
|
// both properties. So if they're different (and non-default),
|
|
|
|
// we can't represent the state using the shorthand.
|
|
|
|
MOZ_STATIC_ASSERT(NS_STYLE_BG_CLIP_BORDER ==
|
|
|
|
NS_STYLE_BG_ORIGIN_BORDER &&
|
|
|
|
NS_STYLE_BG_CLIP_PADDING ==
|
|
|
|
NS_STYLE_BG_ORIGIN_PADDING &&
|
|
|
|
NS_STYLE_BG_CLIP_CONTENT ==
|
|
|
|
NS_STYLE_BG_ORIGIN_CONTENT,
|
|
|
|
"bg-clip and bg-origin style constants must agree");
|
2009-02-20 08:29:21 +03:00
|
|
|
if (clip->mValue != origin->mValue) {
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 22:00:27 +04:00
|
|
|
clip->mValue.AppendToString(eCSSProperty_background_clip, aValue);
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
image = image->mNext;
|
|
|
|
repeat = repeat->mNext;
|
|
|
|
attachment = attachment->mNext;
|
|
|
|
position = position->mNext;
|
|
|
|
clip = clip->mNext;
|
|
|
|
origin = origin->mNext;
|
2009-05-28 22:09:05 +04:00
|
|
|
size = size->mNext;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
|
|
|
if (!image) {
|
2009-05-28 22:09:05 +04:00
|
|
|
if (repeat || attachment || position || clip || origin || size) {
|
2009-02-20 08:29:21 +03:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-28 22:09:05 +04:00
|
|
|
if (!repeat || !attachment || !position || !clip || !origin || !size) {
|
2009-02-20 08:29:21 +03:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(','));
|
2003-06-08 02:14:42 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
1998-10-08 05:31:58 +04:00
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_background_color, aValue);
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_font: {
|
2009-02-06 19:52:12 +03:00
|
|
|
// systemFont might not be present; the others are guaranteed to be
|
|
|
|
// based on the shorthand check at the beginning of the function
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue *systemFont =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty__x_system_font);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &style =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_style);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &variant =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_variant);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &weight =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_weight);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &size =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_size);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &lh =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_line_height);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &family =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_family);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &stretch =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_stretch);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &sizeAdjust =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_size_adjust);
|
2010-07-14 00:30:42 +04:00
|
|
|
const nsCSSValue &featureSettings =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_feature_settings);
|
2010-07-14 00:30:42 +04:00
|
|
|
const nsCSSValue &languageOverride =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_font_language_override);
|
2007-06-12 22:28:56 +04:00
|
|
|
|
2009-02-06 19:52:12 +03:00
|
|
|
if (systemFont &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null) {
|
|
|
|
if (style.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
variant.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
weight.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
size.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
lh.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
family.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
stretch.GetUnit() != eCSSUnit_System_Font ||
|
2010-07-14 00:30:42 +04:00
|
|
|
sizeAdjust.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
featureSettings.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
languageOverride.GetUnit() != eCSSUnit_System_Font) {
|
2009-02-06 19:52:12 +03:00
|
|
|
// This can't be represented as a shorthand.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
2010-07-23 22:00:27 +04:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, aValue);
|
2003-06-08 02:14:42 +04:00
|
|
|
} else {
|
2010-07-14 00:30:42 +04:00
|
|
|
// The font-stretch, font-size-adjust,
|
|
|
|
// -moz-font-feature-settings, and -moz-font-language-override
|
2008-12-23 17:06:57 +03:00
|
|
|
// properties are reset by this shorthand property to their
|
|
|
|
// initial values, but can't be represented in its syntax.
|
2009-11-15 06:16:59 +03:00
|
|
|
if (stretch.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
stretch.GetIntValue() != NS_STYLE_FONT_STRETCH_NORMAL ||
|
2010-07-14 00:30:42 +04:00
|
|
|
sizeAdjust.GetUnit() != eCSSUnit_None ||
|
|
|
|
featureSettings.GetUnit() != eCSSUnit_Normal ||
|
|
|
|
languageOverride.GetUnit() != eCSSUnit_Normal) {
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
|
|
|
|
2009-10-22 04:25:30 +04:00
|
|
|
if (style.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
style.GetIntValue() != NS_FONT_STYLE_NORMAL) {
|
2010-07-23 22:00:27 +04:00
|
|
|
style.AppendToString(eCSSProperty_font_style, aValue);
|
2007-06-12 22:28:56 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2009-10-22 04:25:30 +04:00
|
|
|
if (variant.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
variant.GetIntValue() != NS_FONT_VARIANT_NORMAL) {
|
2010-07-23 22:00:27 +04:00
|
|
|
variant.AppendToString(eCSSProperty_font_variant, aValue);
|
2007-06-12 22:28:56 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2009-11-15 06:16:59 +03:00
|
|
|
if (weight.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
weight.GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
|
2010-07-23 22:00:27 +04:00
|
|
|
weight.AppendToString(eCSSProperty_font_weight, aValue);
|
2007-06-12 22:28:56 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2010-07-23 22:00:27 +04:00
|
|
|
size.AppendToString(eCSSProperty_font_size, aValue);
|
2007-06-12 22:28:56 +04:00
|
|
|
if (lh.GetUnit() != eCSSUnit_Normal) {
|
|
|
|
aValue.Append(PRUnichar('/'));
|
2010-07-23 22:00:27 +04:00
|
|
|
lh.AppendToString(eCSSProperty_line_height, aValue);
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 22:00:27 +04:00
|
|
|
family.AppendToString(eCSSProperty_font_family, aValue);
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
1999-07-18 04:25:28 +04:00
|
|
|
case eCSSProperty_list_style:
|
2003-06-08 02:14:42 +04:00
|
|
|
if (AppendValueToString(eCSSProperty_list_style_type, aValue))
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
if (AppendValueToString(eCSSProperty_list_style_position, aValue))
|
|
|
|
aValue.Append(PRUnichar(' '));
|
1999-07-18 04:25:28 +04:00
|
|
|
AppendValueToString(eCSSProperty_list_style_image, aValue);
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
2004-09-05 04:04:04 +04:00
|
|
|
case eCSSProperty_overflow: {
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &xValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_x);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &yValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_y);
|
2004-09-05 04:04:04 +04:00
|
|
|
if (xValue == yValue)
|
2010-07-23 22:00:27 +04:00
|
|
|
xValue.AppendToString(eCSSProperty_overflow_x, aValue);
|
2004-09-05 04:04:04 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-04-23 09:16:41 +04:00
|
|
|
case eCSSProperty_text_decoration: {
|
|
|
|
// If text-decoration-color or text-decoration-style isn't initial value,
|
|
|
|
// we cannot serialize the text-decoration shorthand value.
|
|
|
|
const nsCSSValue &decorationColor =
|
|
|
|
*data->ValueFor(eCSSProperty_text_decoration_color);
|
|
|
|
const nsCSSValue &decorationStyle =
|
|
|
|
*data->ValueFor(eCSSProperty_text_decoration_style);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(decorationStyle.GetUnit() == eCSSUnit_Enumerated,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad text-decoration-style unit %d",
|
2011-04-23 09:16:41 +04:00
|
|
|
decorationStyle.GetUnit()).get());
|
|
|
|
|
|
|
|
if (decorationColor.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
decorationColor.GetIntValue() != NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR ||
|
|
|
|
decorationStyle.GetIntValue() !=
|
|
|
|
NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCSSValue &textBlink =
|
|
|
|
*data->ValueFor(eCSSProperty_text_blink);
|
|
|
|
const nsCSSValue &decorationLine =
|
|
|
|
*data->ValueFor(eCSSProperty_text_decoration_line);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(textBlink.GetUnit() == eCSSUnit_Enumerated,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad text-blink unit %d",
|
2011-04-23 09:16:41 +04:00
|
|
|
textBlink.GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(decorationLine.GetUnit() == eCSSUnit_Enumerated,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad text-decoration-line unit %d",
|
2011-04-23 09:16:41 +04:00
|
|
|
decorationLine.GetUnit()).get());
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool blinkNone = (textBlink.GetIntValue() == NS_STYLE_TEXT_BLINK_NONE);
|
|
|
|
bool lineNone =
|
2011-04-23 09:16:41 +04:00
|
|
|
(decorationLine.GetIntValue() == NS_STYLE_TEXT_DECORATION_LINE_NONE);
|
|
|
|
|
|
|
|
if (blinkNone && lineNone) {
|
|
|
|
AppendValueToString(eCSSProperty_text_decoration_line, aValue);
|
|
|
|
} else {
|
|
|
|
if (!blinkNone) {
|
|
|
|
AppendValueToString(eCSSProperty_text_blink, aValue);
|
|
|
|
}
|
|
|
|
if (!lineNone) {
|
|
|
|
if (!aValue.IsEmpty()) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
AppendValueToString(eCSSProperty_text_decoration_line, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-08-21 01:52:47 +04:00
|
|
|
case eCSSProperty_transition: {
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue &transProp =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_transition_property);
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue &transDuration =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_transition_duration);
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue &transTiming =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_transition_timing_function);
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue &transDelay =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_transition_delay);
|
2010-08-19 23:33:44 +04:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(transDuration.GetUnit() == eCSSUnit_List ||
|
|
|
|
transDuration.GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-duration unit %d",
|
2010-08-19 23:33:44 +04:00
|
|
|
transDuration.GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transTiming.GetUnit() == eCSSUnit_List ||
|
|
|
|
transTiming.GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-timing unit %d",
|
2010-08-19 23:33:44 +04:00
|
|
|
transTiming.GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transDelay.GetUnit() == eCSSUnit_List ||
|
|
|
|
transDelay.GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-delay unit %d",
|
2010-08-19 23:33:44 +04:00
|
|
|
transDelay.GetUnit()).get());
|
|
|
|
|
|
|
|
const nsCSSValueList* dur = transDuration.GetListValue();
|
|
|
|
const nsCSSValueList* tim = transTiming.GetListValue();
|
|
|
|
const nsCSSValueList* del = transDelay.GetListValue();
|
|
|
|
|
|
|
|
if (transProp.GetUnit() == eCSSUnit_None ||
|
|
|
|
transProp.GetUnit() == eCSSUnit_All) {
|
|
|
|
// If any of the other three lists has more than one element,
|
|
|
|
// we can't use the shorthand.
|
|
|
|
if (!dur->mNext && !tim->mNext && !del->mNext) {
|
|
|
|
transProp.AppendToString(eCSSProperty_transition_property, aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
|
|
|
aValue);
|
2010-08-19 23:33:44 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay, aValue);
|
2009-08-21 01:52:47 +04:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
} else {
|
|
|
|
aValue.Truncate();
|
2009-08-21 01:52:47 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(transProp.GetUnit() == eCSSUnit_List ||
|
|
|
|
transProp.GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-prop unit %d",
|
2010-08-19 23:33:44 +04:00
|
|
|
transProp.GetUnit()).get());
|
|
|
|
const nsCSSValueList* pro = transProp.GetListValue();
|
|
|
|
for (;;) {
|
|
|
|
pro->mValue.AppendToString(eCSSProperty_transition_property,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay,
|
|
|
|
aValue);
|
|
|
|
pro = pro->mNext;
|
|
|
|
dur = dur->mNext;
|
|
|
|
tim = tim->mNext;
|
|
|
|
del = del->mNext;
|
|
|
|
if (!pro || !dur || !tim || !del) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
if (pro || dur || tim || del) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
2009-08-21 01:52:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-12 10:18:42 +04:00
|
|
|
case eCSSProperty_animation: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_animation);
|
2011-05-09 23:02:35 +04:00
|
|
|
static const size_t numProps = 7;
|
2011-04-12 10:18:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps] == eCSSProperty_UNKNOWN,
|
|
|
|
"unexpected number of subproperties");
|
|
|
|
const nsCSSValue* values[numProps];
|
|
|
|
const nsCSSValueList* lists[numProps];
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
|
|
|
values[i] = data->ValueFor(subprops[i]);
|
|
|
|
NS_ABORT_IF_FALSE(values[i]->GetUnit() == eCSSUnit_List ||
|
|
|
|
values[i]->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad a-duration unit %d",
|
2011-04-12 10:18:42 +04:00
|
|
|
values[i]->GetUnit()).get());
|
|
|
|
lists[i] = values[i]->GetListValue();
|
|
|
|
}
|
2009-08-21 01:52:47 +04:00
|
|
|
|
2011-04-12 10:18:42 +04:00
|
|
|
for (;;) {
|
|
|
|
// We must serialize 'animation-name' last in case it has
|
|
|
|
// a value that conflicts with one of the other keyword properties.
|
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps - 1] ==
|
|
|
|
eCSSProperty_animation_name,
|
|
|
|
"animation-name must be last");
|
|
|
|
bool done = false;
|
|
|
|
for (PRUint32 i = 0;;) {
|
|
|
|
lists[i]->mValue.AppendToString(subprops[i], aValue);
|
|
|
|
lists[i] = lists[i]->mNext;
|
|
|
|
if (!lists[i]) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (++i == numProps) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
|
|
|
if (lists[i]) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-12-09 06:16:15 +03:00
|
|
|
case eCSSProperty_marker: {
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &endValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_end);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &midValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_mid);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &startValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_start);
|
2004-12-09 06:16:15 +03:00
|
|
|
if (endValue == midValue && midValue == startValue)
|
|
|
|
AppendValueToString(eCSSProperty_marker_end, aValue);
|
|
|
|
break;
|
|
|
|
}
|
2011-08-23 08:18:22 +04:00
|
|
|
case eCSSProperty__moz_columns: {
|
|
|
|
// Two values, column-count and column-width, separated by a space.
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
AppendValueToString(subprops[0], aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(subprops[1], aValue);
|
|
|
|
break;
|
|
|
|
}
|
2012-07-07 04:06:23 +04:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
case eCSSProperty_flex: {
|
|
|
|
// flex-grow, flex-shrink, flex-basis, separated by single space
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
|
|
|
|
AppendValueToString(subprops[0], aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(subprops[1], aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(subprops[2], aValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif // MOZ_FLEXBOX
|
1998-10-08 05:31:58 +04:00
|
|
|
default:
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "no other shorthands");
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-09-30 05:08:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValueIsImportant(const nsAString& aProperty) const
|
1998-11-06 03:56:28 +03:00
|
|
|
{
|
2012-07-14 03:59:05 +04:00
|
|
|
nsCSSProperty propID = nsCSSProps::LookupProperty(aProperty, nsCSSProps::eAny);
|
2010-10-18 06:36:26 +04:00
|
|
|
if (propID == eCSSProperty_UNKNOWN) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-18 06:36:26 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
return GetValueIsImportant(propID);
|
1998-11-06 03:56:28 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValueIsImportant(nsCSSProperty aProperty) const
|
1998-07-15 02:34:27 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
if (!mImportantData)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-07-15 02:34:27 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
// Calling ValueFor is inefficient, but we can assume '!important' is rare.
|
2008-10-08 02:10:20 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return mImportantData->ValueFor(aProperty) != nullptr;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
|
|
|
if (*p == eCSSProperty__x_system_font) {
|
|
|
|
// The system_font subproperty doesn't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!mImportantData->ValueFor(*p)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2002-05-21 12:16:42 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-05-21 12:16:42 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 12:08:30 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAutoString& aValue,
|
|
|
|
nsAString& aResult) const
|
2001-10-24 12:08:30 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
|
|
|
|
"property enum out of range");
|
|
|
|
NS_ABORT_IF_FALSE((aProperty < eCSSProperty_COUNT_no_shorthands) ==
|
|
|
|
aValue.IsEmpty(),
|
|
|
|
"aValue should be given for shorthands but not longhands");
|
2008-12-23 17:06:57 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), aResult);
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AppendLiteral(": ");
|
2008-12-23 17:06:57 +03:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
AppendValueToString(aProperty, aResult);
|
|
|
|
else
|
|
|
|
aResult.Append(aValue);
|
2010-08-19 23:33:44 +04:00
|
|
|
if (GetValueIsImportant(aProperty)) {
|
|
|
|
aResult.AppendLiteral(" ! important");
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AppendLiteral("; ");
|
2001-10-24 12:08:30 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::ToString(nsAString& aString) const
|
1998-07-15 02:34:27 +04:00
|
|
|
{
|
2010-08-03 02:40:35 +04:00
|
|
|
// Someone cares about this declaration's contents, so don't let it
|
|
|
|
// change from under them. See e.g. bug 338679.
|
|
|
|
SetImmutable();
|
|
|
|
|
2009-02-06 19:52:12 +03:00
|
|
|
nsCSSCompressedDataBlock *systemFontData =
|
|
|
|
GetValueIsImportant(eCSSProperty__x_system_font) ? mImportantData : mData;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *systemFont =
|
|
|
|
systemFontData->ValueFor(eCSSProperty__x_system_font);
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool haveSystemFont = systemFont &&
|
2009-02-06 19:52:12 +03:00
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didSystemFont = false;
|
2009-02-06 19:52:12 +03:00
|
|
|
|
2008-01-10 23:13:24 +03:00
|
|
|
PRInt32 count = mOrder.Length();
|
2003-06-08 02:14:42 +04:00
|
|
|
PRInt32 index;
|
2008-12-23 17:06:57 +03:00
|
|
|
nsAutoTArray<nsCSSProperty, 16> shorthandsUsed;
|
2003-06-08 02:14:42 +04:00
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsCSSProperty property = OrderValueAt(index);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doneProperty = false;
|
2008-12-23 17:06:57 +03:00
|
|
|
|
|
|
|
// If we already used this property in a shorthand, skip it.
|
|
|
|
if (shorthandsUsed.Length() > 0) {
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
if (shorthandsUsed.Contains(*shorthands)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2008-12-23 17:06:57 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
// Try to use this property in a shorthand.
|
|
|
|
nsAutoString value;
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
// ShorthandsContaining returns the shorthands in order from those
|
|
|
|
// that contain the most subproperties to those that contain the
|
|
|
|
// least, which is exactly the order we want to test them.
|
|
|
|
nsCSSProperty shorthand = *shorthands;
|
|
|
|
|
|
|
|
// If GetValue gives us a non-empty string back, we can use that
|
|
|
|
// value; otherwise it's not possible to use this shorthand.
|
|
|
|
GetValue(shorthand, value);
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
AppendPropertyAndValueToString(shorthand, value, aString);
|
|
|
|
shorthandsUsed.AppendElement(shorthand);
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2003-06-08 02:14:42 +04:00
|
|
|
break;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
2009-02-06 19:52:12 +03:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(shorthand != eCSSProperty_font ||
|
|
|
|
*(shorthands + 1) == eCSSProperty_UNKNOWN,
|
|
|
|
"font should always be the only containing shorthand");
|
2009-02-20 00:55:48 +03:00
|
|
|
if (shorthand == eCSSProperty_font) {
|
|
|
|
if (haveSystemFont && !didSystemFont) {
|
2009-02-06 19:52:12 +03:00
|
|
|
// Output the shorthand font declaration that we will
|
|
|
|
// partially override later. But don't add it to
|
|
|
|
// |shorthandsUsed|, since we will have to override it.
|
2010-07-23 22:00:27 +04:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, value);
|
2009-02-06 19:52:12 +03:00
|
|
|
AppendPropertyAndValueToString(eCSSProperty_font, value, aString);
|
|
|
|
value.Truncate();
|
2011-10-17 18:59:28 +04:00
|
|
|
didSystemFont = true;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// That we output the system font is enough for this property if:
|
2009-02-20 00:55:48 +03:00
|
|
|
// (1) it's the hidden system font subproperty (which either
|
|
|
|
// means we output it or we don't have it), or
|
2009-02-06 19:52:12 +03:00
|
|
|
// (2) its value is the hidden system font value and it matches
|
2009-02-20 00:55:48 +03:00
|
|
|
// the hidden system font subproperty in importance, and
|
|
|
|
// we output the system font subproperty.
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = systemFontData->ValueFor(property);
|
2009-02-06 19:52:12 +03:00
|
|
|
if (property == eCSSProperty__x_system_font ||
|
2009-02-20 00:55:48 +03:00
|
|
|
(haveSystemFont && val && val->GetUnit() == eCSSUnit_System_Font)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
|
|
|
}
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(value.IsEmpty(), "value should be empty now");
|
2008-12-23 17:06:57 +03:00
|
|
|
AppendPropertyAndValueToString(property, value, aString);
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2001-10-24 12:08:30 +04:00
|
|
|
if (! aString.IsEmpty()) {
|
2010-08-19 23:33:44 +04:00
|
|
|
// if the string is not empty, we have trailing whitespace we
|
|
|
|
// should remove
|
2001-10-24 12:08:30 +04:00
|
|
|
aString.Truncate(aString.Length() - 1);
|
|
|
|
}
|
1998-07-15 02:34:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-08-19 23:33:44 +04:00
|
|
|
void
|
|
|
|
Declaration::List(FILE* out, PRInt32 aIndent) const
|
1998-09-10 05:19:26 +04:00
|
|
|
{
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("{ ", out);
|
2007-05-17 01:17:45 +04:00
|
|
|
nsAutoString s;
|
|
|
|
ToString(s);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(s).get(), out);
|
1998-09-10 05:19:26 +04:00
|
|
|
fputs("}", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aReturn.Truncate();
|
2008-01-10 23:13:24 +03:00
|
|
|
if (aIndex < mOrder.Length()) {
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSProperty property = OrderValueAt(aIndex);
|
1998-09-25 04:51:45 +04:00
|
|
|
if (0 <= property) {
|
2003-11-01 13:57:41 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::InitializeEmpty()
|
1998-09-10 05:19:26 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "already initialized");
|
2003-06-08 02:14:42 +04:00
|
|
|
mData = nsCSSCompressedDataBlock::CreateEmptyBlock();
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2010-07-23 22:00:49 +04:00
|
|
|
Declaration*
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::EnsureMutable()
|
2009-12-11 19:13:19 +03:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mData, "should only be called when not expanded");
|
2010-07-23 22:00:49 +04:00
|
|
|
if (!IsMutable()) {
|
2010-07-23 22:00:52 +04:00
|
|
|
return new Declaration(*this);
|
2010-07-23 22:00:49 +04:00
|
|
|
} else {
|
|
|
|
return this;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
2010-06-29 02:49:35 +04:00
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
Declaration::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mOrder.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mData ? mData ->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
n += mImportantData ? mImportantData->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
} // namespace mozilla::css
|
|
|
|
} // namespace mozilla
|