2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2010-08-19 12:33:44 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2013-09-15 18:06:52 -07:00
|
|
|
#include "gfxFontConstants.h"
|
2014-03-21 08:06:12 -07:00
|
|
|
#include "nsStyleUtil.h"
|
2010-07-02 21:18:55 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::Declaration()
|
2011-10-17 07:59:28 -07:00
|
|
|
: mImmutable(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::Declaration(const Declaration& aCopy)
|
2008-01-10 12:13:24 -08:00
|
|
|
: mOrder(aCopy.mOrder),
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mVariableOrder(aCopy.mVariableOrder),
|
2012-07-30 07:20:58 -07:00
|
|
|
mData(aCopy.mData ? aCopy.mData->Clone() : nullptr),
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mImportantData(aCopy.mImportantData ?
|
|
|
|
aCopy.mImportantData->Clone() : nullptr),
|
|
|
|
mVariables(aCopy.mVariables ?
|
|
|
|
new CSSVariableDeclarations(*aCopy.mVariables) :
|
|
|
|
nullptr),
|
|
|
|
mImportantVariables(aCopy.mImportantVariables ?
|
|
|
|
new CSSVariableDeclarations(*aCopy.mImportantVariables) :
|
|
|
|
nullptr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mImmutable(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::~Declaration()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_DTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::ValueAppended(nsCSSProperty aProperty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 11:00:49 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData,
|
|
|
|
"should only be called while expanded");
|
2009-03-05 20:05:01 -08:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"shorthands forbidden");
|
2007-03-22 10:30:00 -07:00
|
|
|
// order IS important for CSS, so remove and add to the end
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
|
|
|
|
mOrder.AppendElement(static_cast<uint32_t>(aProperty));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::RemoveProperty(nsCSSProperty aProperty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSExpandedDataBlock data;
|
2009-12-11 08:13:19 -08:00
|
|
|
ExpandTo(&data);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "Expand didn't null things out");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2010-07-23 11:00:42 -07:00
|
|
|
data.ClearLonghandProperty(*p);
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(*p));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-23 11:00:42 -07:00
|
|
|
data.ClearLonghandProperty(aProperty);
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
CompressFrom(&data);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-11-24 10:31:52 -08: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-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-19 12:33:44 -07:00
|
|
|
Declaration::AppendValueToString(nsCSSProperty aProperty,
|
2013-09-15 16:35:49 -07:00
|
|
|
nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 11:00:29 -07:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
if (!val) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-23 11:00:29 -07:00
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2013-09-15 16:35:49 -07:00
|
|
|
val->AppendToString(aProperty, aResult, aSerialization);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-02 05:10:43 -07:00
|
|
|
// Helper to append |aString| with the shorthand sides notation used in e.g.
|
|
|
|
// 'padding'. |aProperties| and |aValues| are expected to have 4 elements.
|
|
|
|
static void
|
|
|
|
AppendSidesShorthandToString(const nsCSSProperty aProperties[],
|
|
|
|
const nsCSSValue* aValues[],
|
2013-09-15 16:35:49 -07:00
|
|
|
nsAString& aString,
|
|
|
|
nsCSSValue::Serialization aSerialization)
|
2013-07-02 05:10:43 -07:00
|
|
|
{
|
|
|
|
const nsCSSValue& value1 = *aValues[0];
|
|
|
|
const nsCSSValue& value2 = *aValues[1];
|
|
|
|
const nsCSSValue& value3 = *aValues[2];
|
|
|
|
const nsCSSValue& value4 = *aValues[3];
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(value1.GetUnit() != eCSSUnit_Null, "null value 1");
|
2013-09-15 16:35:49 -07:00
|
|
|
value1.AppendToString(aProperties[0], aString, aSerialization);
|
2013-07-02 05:10:43 -07:00
|
|
|
if (value1 != value2 || value1 != value3 || value1 != value4) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aString.Append(char16_t(' '));
|
2013-07-02 05:10:43 -07:00
|
|
|
NS_ABORT_IF_FALSE(value2.GetUnit() != eCSSUnit_Null, "null value 2");
|
2013-09-15 16:35:49 -07:00
|
|
|
value2.AppendToString(aProperties[1], aString, aSerialization);
|
2013-07-02 05:10:43 -07:00
|
|
|
if (value1 != value3 || value2 != value4) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aString.Append(char16_t(' '));
|
2013-07-02 05:10:43 -07:00
|
|
|
NS_ABORT_IF_FALSE(value3.GetUnit() != eCSSUnit_Null, "null value 3");
|
2013-09-15 16:35:49 -07:00
|
|
|
value3.AppendToString(aProperties[2], aString, aSerialization);
|
2013-07-02 05:10:43 -07:00
|
|
|
if (value2 != value4) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aString.Append(char16_t(' '));
|
2013-07-02 05:10:43 -07:00
|
|
|
NS_ABORT_IF_FALSE(value4.GetUnit() != eCSSUnit_Null, "null value 4");
|
2013-09-15 16:35:49 -07:00
|
|
|
value4.AppendToString(aProperties[3], aString, aSerialization);
|
2013-07-02 05:10:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
|
2013-09-15 16:35:49 -07:00
|
|
|
{
|
|
|
|
GetValue(aProperty, aValue, nsCSSValue::eNormalized);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::GetAuthoredValue(nsCSSProperty aProperty, nsAString& aValue) const
|
|
|
|
{
|
|
|
|
GetValue(aProperty, aValue, nsCSSValue::eAuthorSpecified);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aValue.Truncate(0);
|
|
|
|
|
|
|
|
// simple properties are easy.
|
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(aProperty, aValue, aSerialization);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-07 15:10:20 -07: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.
|
2013-10-03 11:49:19 -07:00
|
|
|
// (2) Since 'inherit', 'initial' and 'unset' 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.
|
2008-10-07 15:10:20 -07:00
|
|
|
// (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.
|
2013-12-11 18:09:46 -08:00
|
|
|
//
|
|
|
|
// Additionally, if a shorthand property was set using a value with a
|
|
|
|
// variable reference and none of its component longhand properties were
|
|
|
|
// then overridden on the declaration, we return the token stream
|
|
|
|
// assigned to the shorthand.
|
|
|
|
const nsCSSValue* tokenStream = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t totalCount = 0, importantCount = 0,
|
2013-12-11 18:09:46 -08:00
|
|
|
initialCount = 0, inheritCount = 0, unsetCount = 0,
|
|
|
|
matchingTokenStreamCount = 0;
|
2007-06-12 11:28:56 -07:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2008-10-07 15:10:20 -07:00
|
|
|
if (*p == eCSSProperty__x_system_font ||
|
2008-10-27 10:55:51 -07:00
|
|
|
nsCSSProps::PropHasFlags(*p, CSS_PROPERTY_DIRECTIONAL_SOURCE)) {
|
2008-10-07 15:10:20 -07:00
|
|
|
// The system-font subproperty and the *-source properties don't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++totalCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = mData->ValueFor(*p);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!val || !mImportantData || !mImportantData->ValueFor(*p),
|
|
|
|
"can't be in both blocks");
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!val && mImportantData) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++importantCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
val = mImportantData->ValueFor(*p);
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!val) {
|
2008-10-07 15:10:20 -07:00
|
|
|
// Case (1) above: some subproperties not specified.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (val->GetUnit() == eCSSUnit_Inherit) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++inheritCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Initial) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++initialCount;
|
2013-10-03 11:49:19 -07:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Unset) {
|
|
|
|
++unsetCount;
|
2013-12-11 18:09:46 -08:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_TokenStream &&
|
|
|
|
val->GetTokenStreamValue()->mShorthandPropertyID == aProperty) {
|
|
|
|
tokenStream = val;
|
|
|
|
++matchingTokenStreamCount;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (importantCount != 0 && importantCount != totalCount) {
|
|
|
|
// Case (3), no consistent importance.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
if (initialCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing initial up-front.
|
2013-09-15 16:35:49 -07:00
|
|
|
nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
if (inheritCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing inherit up-front.
|
2013-09-15 16:35:49 -07:00
|
|
|
nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
2013-10-03 11:49:19 -07:00
|
|
|
if (unsetCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing unset up-front.
|
2013-09-15 16:35:49 -07:00
|
|
|
nsCSSValue(eCSSUnit_Unset).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2013-10-03 11:49:19 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (initialCount != 0 || inheritCount != 0 || unsetCount != 0) {
|
|
|
|
// Case (2): partially initial, inherit or unset.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
2013-12-11 18:09:46 -08:00
|
|
|
if (tokenStream) {
|
|
|
|
if (matchingTokenStreamCount == totalCount) {
|
|
|
|
// Shorthand was specified using variable references and all of its
|
|
|
|
// longhand components were set by the shorthand.
|
|
|
|
aValue.Append(tokenStream->GetTokenStreamValue()->mTokenStream);
|
|
|
|
} else {
|
|
|
|
// In all other cases, serialize to the empty string.
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-06-12 11:28:56 -07:00
|
|
|
|
2008-12-23 06:06:57 -08:00
|
|
|
nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (aProperty) {
|
|
|
|
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 12:33:44 -07: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");
|
2013-07-02 05:11:21 -07:00
|
|
|
const nsCSSValue* vals[4] = {
|
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
|
|
|
};
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendSidesShorthandToString(subprops, vals, aValue, aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-09-09 08:21:47 -07:00
|
|
|
case eCSSProperty_border_radius:
|
2008-09-30 22:50:52 -07:00
|
|
|
case eCSSProperty__moz_outline_radius: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue* vals[4] = {
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
2008-09-30 22:50:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// For compatibility, only write a slash and the y-values
|
|
|
|
// if they're not identical to the x-values.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needY = false;
|
2013-07-02 05:10:43 -07:00
|
|
|
const nsCSSValue* xVals[4];
|
|
|
|
const nsCSSValue* yVals[4];
|
2010-08-19 12:33:44 -07:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (vals[i]->GetUnit() == eCSSUnit_Pair) {
|
2011-10-17 07:59:28 -07:00
|
|
|
needY = true;
|
2013-07-02 05:10:43 -07:00
|
|
|
xVals[i] = &vals[i]->GetPairValue().mXValue;
|
|
|
|
yVals[i] = &vals[i]->GetPairValue().mYValue;
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2013-07-02 05:10:43 -07:00
|
|
|
xVals[i] = yVals[i] = vals[i];
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendSidesShorthandToString(subprops, xVals, aValue, aSerialization);
|
2010-08-19 12:33:44 -07:00
|
|
|
if (needY) {
|
2008-09-30 22:50:52 -07:00
|
|
|
aValue.AppendLiteral(" / ");
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendSidesShorthandToString(subprops, yVals, aValue, aSerialization);
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-05-30 22:19:49 -07: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*.
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_border_image_source, aValue,
|
|
|
|
aSerialization);
|
2012-05-30 22:19:49 -07:00
|
|
|
|
|
|
|
bool sliceDefault = data->HasDefaultBorderImageSlice();
|
|
|
|
bool widthDefault = data->HasDefaultBorderImageWidth();
|
|
|
|
bool outsetDefault = data->HasDefaultBorderImageOutset();
|
|
|
|
|
|
|
|
if (!sliceDefault || !widthDefault || !outsetDefault) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_border_image_slice, aValue,
|
|
|
|
aSerialization);
|
2012-05-30 22:19:49 -07:00
|
|
|
if (!widthDefault || !outsetDefault) {
|
|
|
|
aValue.Append(NS_LITERAL_STRING(" /"));
|
|
|
|
if (!widthDefault) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_border_image_width, aValue,
|
|
|
|
aSerialization);
|
2012-05-30 22:19:49 -07:00
|
|
|
}
|
|
|
|
if (!outsetDefault) {
|
|
|
|
aValue.Append(NS_LITERAL_STRING(" / "));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_border_image_outset, aValue,
|
|
|
|
aSerialization);
|
2012-05-30 22:19:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool repeatDefault = data->HasDefaultBorderImageRepeat();
|
|
|
|
if (!repeatDefault) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_border_image_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-05-30 22:19:49 -07:00
|
|
|
}
|
2011-12-22 15:34:45 -08:00
|
|
|
break;
|
2012-05-30 22:19:49 -07:00
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
case eCSSProperty_border: {
|
2012-05-30 22:19:49 -07: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 06:06:57 -08:00
|
|
|
const nsCSSProperty* subproptables[3] = {
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_style),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_width)
|
|
|
|
};
|
2011-09-28 23:19:26 -07:00
|
|
|
bool match = true;
|
2008-12-23 06:06:57 -08:00
|
|
|
for (const nsCSSProperty** subprops = subproptables,
|
2011-10-10 22:50:08 -07:00
|
|
|
**subprops_end = ArrayEnd(subproptables);
|
2008-12-23 06:06:57 -08: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 12:33:44 -07:00
|
|
|
const nsCSSValue *firstSide = data->ValueFor((*subprops)[0]);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t side = 1; side < 4; ++side) {
|
2008-12-23 06:06:57 -08:00
|
|
|
const nsCSSValue *otherSide =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor((*subprops)[side]);
|
2008-12-23 06:06:57 -08:00
|
|
|
if (*firstSide != *otherSide)
|
2011-10-17 07:59:28 -07:00
|
|
|
match = false;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
|
|
|
// We can't express what we have in the border shorthand
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// tweak aProperty and fall through
|
2007-03-22 10:30:00 -07:00
|
|
|
aProperty = eCSSProperty_border_top;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_right:
|
|
|
|
case eCSSProperty_border_bottom:
|
|
|
|
case eCSSProperty_border_left:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_start:
|
|
|
|
case eCSSProperty_border_end:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_outline: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07: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 12:33:44 -07:00
|
|
|
const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isMozUseTextColor =
|
2008-12-23 06:06:57 -08:00
|
|
|
colorValue->GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
colorValue->GetIntValue() == NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR;
|
2013-09-15 16:35:49 -07:00
|
|
|
if (!AppendValueToString(subprops[0], aValue, aSerialization) ||
|
2014-01-04 07:02:17 -08:00
|
|
|
!(aValue.Append(char16_t(' ')),
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization)) ||
|
2008-12-23 06:06:57 -08:00
|
|
|
// Don't output a third value when it's -moz-use-text-color.
|
|
|
|
!(isMozUseTextColor ||
|
2014-01-04 07:02:17 -08:00
|
|
|
(aValue.Append(char16_t(' ')),
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[2], aValue, aSerialization)))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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 11:51:16 -07: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: {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_background: {
|
2009-02-19 21:29:21 -08: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 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_image)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2012-02-24 21:23:14 -08:00
|
|
|
const nsCSSValuePairList *repeat =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_repeat)->
|
2012-02-24 21:23:14 -08:00
|
|
|
GetPairListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *attachment =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_attachment)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2012-02-19 16:14:42 -08:00
|
|
|
const nsCSSValueList *position =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_position)->
|
2012-02-19 16:14:42 -08:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *clip =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_clip)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *origin =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_origin)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-05-28 11:09:05 -07:00
|
|
|
const nsCSSValuePairList *size =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_size)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetPairListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
for (;;) {
|
2013-09-15 16:35:49 -07:00
|
|
|
image->mValue.AppendToString(eCSSProperty_background_image, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
repeat->mXValue.AppendToString(eCSSProperty_background_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-02-24 21:23:14 -08:00
|
|
|
if (repeat->mYValue.GetUnit() != eCSSUnit_Null) {
|
2013-09-15 16:35:49 -07:00
|
|
|
repeat->mYValue.AppendToString(eCSSProperty_background_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-02-24 21:23:14 -08:00
|
|
|
}
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
attachment->mValue.AppendToString(eCSSProperty_background_attachment,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2012-02-19 16:14:42 -08:00
|
|
|
position->mValue.AppendToString(eCSSProperty_background_position,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2012-09-16 17:20:15 -07:00
|
|
|
|
|
|
|
if (size->mXValue.GetUnit() != eCSSUnit_Auto ||
|
|
|
|
size->mYValue.GetUnit() != eCSSUnit_Auto) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
aValue.Append(char16_t('/'));
|
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
size->mXValue.AppendToString(eCSSProperty_background_size, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
size->mYValue.AppendToString(eCSSProperty_background_size, aValue,
|
|
|
|
aSerialization);
|
2012-09-16 17:20:15 -07:00
|
|
|
}
|
2012-02-23 08:19:00 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(clip->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
origin->mValue.GetUnit() == eCSSUnit_Enumerated,
|
2012-02-23 08:19:00 -08:00
|
|
|
"should not have inherit/initial within list");
|
|
|
|
|
2009-02-19 21:29:21 -08:00
|
|
|
if (clip->mValue.GetIntValue() != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
origin->mValue.GetIntValue() != NS_STYLE_BG_ORIGIN_PADDING) {
|
2013-03-07 17:59:32 -08:00
|
|
|
MOZ_ASSERT(nsCSSProps::kKeywordTableTable[
|
|
|
|
eCSSProperty_background_origin] ==
|
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
|
|
|
MOZ_ASSERT(nsCSSProps::kKeywordTableTable[
|
|
|
|
eCSSProperty_background_clip] ==
|
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
2013-07-18 10:59:53 -07:00
|
|
|
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");
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
origin->mValue.AppendToString(eCSSProperty_background_origin, aValue,
|
|
|
|
aSerialization);
|
2013-03-07 17:59:32 -08:00
|
|
|
|
2009-02-19 21:29:21 -08:00
|
|
|
if (clip->mValue != origin->mValue) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
clip->mValue.AppendToString(eCSSProperty_background_clip, aValue,
|
|
|
|
aSerialization);
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image = image->mNext;
|
|
|
|
repeat = repeat->mNext;
|
|
|
|
attachment = attachment->mNext;
|
|
|
|
position = position->mNext;
|
|
|
|
clip = clip->mNext;
|
|
|
|
origin = origin->mNext;
|
2009-05-28 11:09:05 -07:00
|
|
|
size = size->mNext;
|
2009-02-19 21:29:21 -08:00
|
|
|
|
|
|
|
if (!image) {
|
2009-05-28 11:09:05 -07:00
|
|
|
if (repeat || attachment || position || clip || origin || size) {
|
2009-02-19 21:29:21 -08:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-28 11:09:05 -07:00
|
|
|
if (!repeat || !attachment || !position || !clip || !origin || !size) {
|
2009-02-19 21:29:21 -08:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(','));
|
|
|
|
aValue.Append(char16_t(' '));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-19 21:29:21 -08:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_background_color, aValue,
|
|
|
|
aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_font: {
|
2013-07-24 23:02:15 -07:00
|
|
|
// systemFont might not be present; other values are guaranteed to be
|
|
|
|
// available based on the shorthand check at the beginning of the
|
|
|
|
// function, as long as the prop is enabled
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue *systemFont =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty__x_system_font);
|
2013-07-24 23:02:15 -07:00
|
|
|
const nsCSSValue *style =
|
|
|
|
data->ValueFor(eCSSProperty_font_style);
|
|
|
|
const nsCSSValue *variant =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant);
|
|
|
|
const nsCSSValue *weight =
|
|
|
|
data->ValueFor(eCSSProperty_font_weight);
|
|
|
|
const nsCSSValue *size =
|
|
|
|
data->ValueFor(eCSSProperty_font_size);
|
|
|
|
const nsCSSValue *lh =
|
|
|
|
data->ValueFor(eCSSProperty_line_height);
|
|
|
|
const nsCSSValue *family =
|
|
|
|
data->ValueFor(eCSSProperty_font_family);
|
|
|
|
const nsCSSValue *stretch =
|
|
|
|
data->ValueFor(eCSSProperty_font_stretch);
|
|
|
|
const nsCSSValue *sizeAdjust =
|
|
|
|
data->ValueFor(eCSSProperty_font_size_adjust);
|
|
|
|
const nsCSSValue *featureSettings =
|
|
|
|
data->ValueFor(eCSSProperty_font_feature_settings);
|
|
|
|
const nsCSSValue *languageOverride =
|
|
|
|
data->ValueFor(eCSSProperty_font_language_override);
|
|
|
|
const nsCSSValue *fontKerning =
|
|
|
|
data->ValueFor(eCSSProperty_font_kerning);
|
|
|
|
const nsCSSValue *fontSynthesis =
|
|
|
|
data->ValueFor(eCSSProperty_font_synthesis);
|
|
|
|
const nsCSSValue *fontVariantAlternates =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_alternates);
|
|
|
|
const nsCSSValue *fontVariantCaps =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_caps);
|
|
|
|
const nsCSSValue *fontVariantEastAsian =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_east_asian);
|
|
|
|
const nsCSSValue *fontVariantLigatures =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_ligatures);
|
|
|
|
const nsCSSValue *fontVariantNumeric =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_numeric);
|
|
|
|
const nsCSSValue *fontVariantPosition =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_position);
|
|
|
|
|
|
|
|
// if font features are not enabled, pointers for fontVariant
|
|
|
|
// values above may be null since the shorthand check ignores them
|
2013-08-18 21:49:49 -07:00
|
|
|
// font-variant-alternates enabled ==> layout.css.font-features.enabled is true
|
2013-07-24 23:01:41 -07:00
|
|
|
bool fontFeaturesEnabled =
|
2013-08-18 21:49:49 -07:00
|
|
|
nsCSSProps::IsEnabled(eCSSProperty_font_variant_alternates);
|
2013-07-24 23:01:41 -07:00
|
|
|
|
2009-02-06 08:52:12 -08:00
|
|
|
if (systemFont &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null) {
|
2013-07-24 23:02:15 -07:00
|
|
|
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 ||
|
|
|
|
sizeAdjust->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
featureSettings->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
languageOverride->GetUnit() != eCSSUnit_System_Font ||
|
2013-07-24 23:01:41 -07:00
|
|
|
(fontFeaturesEnabled &&
|
2013-07-24 23:02:15 -07:00
|
|
|
(fontKerning->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontSynthesis->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantAlternates->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantCaps->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantEastAsian->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantLigatures->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantNumeric->GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
fontVariantPosition->GetUnit() != eCSSUnit_System_Font))) {
|
2009-02-06 08:52:12 -08:00
|
|
|
// This can't be represented as a shorthand.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-06 08:52:12 -08:00
|
|
|
}
|
2013-09-15 16:35:49 -07:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, aValue,
|
|
|
|
aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2013-07-24 23:01:41 -07:00
|
|
|
// properties reset by this shorthand property to their
|
|
|
|
// initial values but not represented in its syntax
|
2013-07-24 23:02:15 -07:00
|
|
|
if (stretch->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
stretch->GetIntValue() != NS_STYLE_FONT_STRETCH_NORMAL ||
|
|
|
|
sizeAdjust->GetUnit() != eCSSUnit_None ||
|
|
|
|
featureSettings->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
languageOverride->GetUnit() != eCSSUnit_Normal ||
|
2013-07-24 23:01:41 -07:00
|
|
|
(fontFeaturesEnabled &&
|
2013-07-24 23:02:15 -07:00
|
|
|
(fontKerning->GetIntValue() != NS_FONT_KERNING_AUTO ||
|
|
|
|
fontSynthesis->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
fontSynthesis->GetIntValue() !=
|
2013-07-24 23:01:41 -07:00
|
|
|
(NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE) ||
|
2013-07-24 23:02:15 -07:00
|
|
|
fontVariantAlternates->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantCaps->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantEastAsian->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantLigatures->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantNumeric->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantPosition->GetUnit() != eCSSUnit_Normal))) {
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:02:15 -07:00
|
|
|
if (style->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
style->GetIntValue() != NS_FONT_STYLE_NORMAL) {
|
2013-09-15 16:35:49 -07:00
|
|
|
style->AppendToString(eCSSProperty_font_style, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
2013-07-24 23:02:15 -07:00
|
|
|
if (variant->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
variant->GetIntValue() != NS_FONT_VARIANT_NORMAL) {
|
2013-09-15 16:35:49 -07:00
|
|
|
variant->AppendToString(eCSSProperty_font_variant, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
2013-07-24 23:02:15 -07:00
|
|
|
if (weight->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
weight->GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
|
2013-09-15 16:35:49 -07:00
|
|
|
weight->AppendToString(eCSSProperty_font_weight, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
2013-09-15 16:35:49 -07:00
|
|
|
size->AppendToString(eCSSProperty_font_size, aValue, aSerialization);
|
2013-07-24 23:02:15 -07:00
|
|
|
if (lh->GetUnit() != eCSSUnit_Normal) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t('/'));
|
2013-09-15 16:35:49 -07:00
|
|
|
lh->AppendToString(eCSSProperty_line_height, aValue, aSerialization);
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
family->AppendToString(eCSSProperty_font_family, aValue,
|
|
|
|
aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_list_style:
|
2013-09-15 16:35:49 -07:00
|
|
|
if (AppendValueToString(eCSSProperty_list_style_type, aValue,
|
|
|
|
aSerialization)) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
}
|
|
|
|
if (AppendValueToString(eCSSProperty_list_style_position, aValue,
|
|
|
|
aSerialization)) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
}
|
|
|
|
AppendValueToString(eCSSProperty_list_style_image, aValue,
|
|
|
|
aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eCSSProperty_overflow: {
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &xValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_x);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &yValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_y);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (xValue == yValue)
|
2013-09-15 16:35:49 -07:00
|
|
|
xValue.AppendToString(eCSSProperty_overflow_x, aValue, aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-04-22 22:16:41 -07: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.
|
2013-07-24 23:02:15 -07:00
|
|
|
const nsCSSValue *decorationColor =
|
|
|
|
data->ValueFor(eCSSProperty_text_decoration_color);
|
|
|
|
const nsCSSValue *decorationStyle =
|
|
|
|
data->ValueFor(eCSSProperty_text_decoration_style);
|
2011-04-22 22:16:41 -07:00
|
|
|
|
2013-07-24 23:02:15 -07:00
|
|
|
NS_ABORT_IF_FALSE(decorationStyle->GetUnit() == eCSSUnit_Enumerated,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad text-decoration-style unit %d",
|
2013-07-24 23:02:15 -07:00
|
|
|
decorationStyle->GetUnit()).get());
|
2011-04-22 22:16:41 -07:00
|
|
|
|
2013-07-24 23:02:15 -07:00
|
|
|
if (decorationColor->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
decorationColor->GetIntValue() != NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR ||
|
|
|
|
decorationStyle->GetIntValue() !=
|
2011-04-22 22:16:41 -07:00
|
|
|
NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_text_decoration_line, aValue,
|
|
|
|
aSerialization);
|
2011-04-22 22:16:41 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
case eCSSProperty_transition: {
|
2013-07-24 23:02:15 -07:00
|
|
|
const nsCSSValue *transProp =
|
|
|
|
data->ValueFor(eCSSProperty_transition_property);
|
|
|
|
const nsCSSValue *transDuration =
|
|
|
|
data->ValueFor(eCSSProperty_transition_duration);
|
|
|
|
const nsCSSValue *transTiming =
|
|
|
|
data->ValueFor(eCSSProperty_transition_timing_function);
|
|
|
|
const nsCSSValue *transDelay =
|
|
|
|
data->ValueFor(eCSSProperty_transition_delay);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(transDuration->GetUnit() == eCSSUnit_List ||
|
|
|
|
transDuration->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad t-duration unit %d",
|
2013-07-24 23:02:15 -07:00
|
|
|
transDuration->GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transTiming->GetUnit() == eCSSUnit_List ||
|
|
|
|
transTiming->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad t-timing unit %d",
|
2013-07-24 23:02:15 -07:00
|
|
|
transTiming->GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transDelay->GetUnit() == eCSSUnit_List ||
|
|
|
|
transDelay->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad t-delay unit %d",
|
2013-07-24 23:02:15 -07:00
|
|
|
transDelay->GetUnit()).get());
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2013-07-24 23:02:15 -07:00
|
|
|
const nsCSSValueList* dur = transDuration->GetListValue();
|
|
|
|
const nsCSSValueList* tim = transTiming->GetListValue();
|
|
|
|
const nsCSSValueList* del = transDelay->GetListValue();
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2013-07-24 23:02:15 -07:00
|
|
|
if (transProp->GetUnit() == eCSSUnit_None ||
|
|
|
|
transProp->GetUnit() == eCSSUnit_All) {
|
2010-08-19 12:33:44 -07:00
|
|
|
// 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) {
|
2013-09-15 16:35:49 -07:00
|
|
|
transProp->AppendToString(eCSSProperty_transition_property, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
aValue.Truncate();
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2013-07-24 23:02:15 -07:00
|
|
|
NS_ABORT_IF_FALSE(transProp->GetUnit() == eCSSUnit_List ||
|
|
|
|
transProp->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad t-prop unit %d",
|
2013-07-24 23:02:15 -07:00
|
|
|
transProp->GetUnit()).get());
|
|
|
|
const nsCSSValueList* pro = transProp->GetListValue();
|
2010-08-19 12:33:44 -07:00
|
|
|
for (;;) {
|
|
|
|
pro->mValue.AppendToString(eCSSProperty_transition_property,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay,
|
2013-09-15 16:35:49 -07:00
|
|
|
aValue, aSerialization);
|
2010-08-19 12:33:44 -07:00
|
|
|
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-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:18:42 -07:00
|
|
|
case eCSSProperty_animation: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_animation);
|
2011-05-09 12:02:35 -07:00
|
|
|
static const size_t numProps = 7;
|
2011-04-11 23:18:42 -07:00
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps] == eCSSProperty_UNKNOWN,
|
|
|
|
"unexpected number of subproperties");
|
|
|
|
const nsCSSValue* values[numProps];
|
|
|
|
const nsCSSValueList* lists[numProps];
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < numProps; ++i) {
|
2011-04-11 23:18:42 -07:00
|
|
|
values[i] = data->ValueFor(subprops[i]);
|
|
|
|
NS_ABORT_IF_FALSE(values[i]->GetUnit() == eCSSUnit_List ||
|
|
|
|
values[i]->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString("bad a-duration unit %d",
|
2011-04-11 23:18:42 -07:00
|
|
|
values[i]->GetUnit()).get());
|
|
|
|
lists[i] = values[i]->GetListValue();
|
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
|
2011-04-11 23:18:42 -07: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;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0;;) {
|
2013-09-15 16:35:49 -07:00
|
|
|
lists[i]->mValue.AppendToString(subprops[i], aValue, aSerialization);
|
2011-04-11 23:18:42 -07:00
|
|
|
lists[i] = lists[i]->mNext;
|
|
|
|
if (!lists[i]) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (++i == numProps) {
|
|
|
|
break;
|
|
|
|
}
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2011-04-11 23:18:42 -07:00
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < numProps; ++i) {
|
2011-04-11 23:18:42 -07:00
|
|
|
if (lists[i]) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marker: {
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &endValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_end);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &midValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_mid);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &startValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_start);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (endValue == midValue && midValue == startValue)
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(eCSSProperty_marker_end, aValue, aSerialization);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-08-22 21:18:22 -07:00
|
|
|
case eCSSProperty__moz_columns: {
|
|
|
|
// Two values, column-count and column-width, separated by a space.
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2011-08-22 21:18:22 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-07-06 17:06:23 -07:00
|
|
|
case eCSSProperty_flex: {
|
|
|
|
// flex-grow, flex-shrink, flex-basis, separated by single space
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[2], aValue, aSerialization);
|
2012-07-06 17:06:23 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-12-05 10:57:51 -08:00
|
|
|
case eCSSProperty_flex_flow: {
|
|
|
|
// flex-direction, flex-wrap, separated by single space
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ABORT_IF_FALSE(subprops[2] == eCSSProperty_UNKNOWN,
|
|
|
|
"must have exactly two subproperties");
|
|
|
|
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 07:02:17 -08:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2014-03-21 08:06:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_grid_row:
|
|
|
|
case eCSSProperty_grid_column: {
|
|
|
|
// grid-{row,column}-start, grid-{row,column}-end, separated by a slash
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ABORT_IF_FALSE(subprops[2] == eCSSProperty_UNKNOWN,
|
|
|
|
"must have exactly two subproperties");
|
|
|
|
|
|
|
|
// TODO: should we simplify when possible?
|
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_grid_area: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ABORT_IF_FALSE(subprops[4] == eCSSProperty_UNKNOWN,
|
|
|
|
"must have exactly four subproperties");
|
|
|
|
|
|
|
|
// TODO: should we simplify when possible?
|
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(subprops[2], aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(subprops[3], aValue, aSerialization);
|
2013-12-05 10:57:51 -08:00
|
|
|
break;
|
|
|
|
}
|
2014-03-21 08:06:12 -07:00
|
|
|
|
|
|
|
// This can express either grid-template-{areas,columns,rows}
|
|
|
|
// or grid-auto-{flow,columns,rows}, but not both.
|
|
|
|
case eCSSProperty_grid: {
|
|
|
|
const nsCSSValue& areasValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_areas);
|
|
|
|
const nsCSSValue& columnsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_columns);
|
|
|
|
const nsCSSValue& rowsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_rows);
|
|
|
|
|
|
|
|
const nsCSSValue& autoFlowValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_auto_flow);
|
|
|
|
const nsCSSValue& autoColumnsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_auto_columns);
|
|
|
|
const nsCSSValue& autoRowsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_auto_rows);
|
|
|
|
|
|
|
|
if (areasValue.GetUnit() == eCSSUnit_None &&
|
|
|
|
columnsValue.GetUnit() == eCSSUnit_None &&
|
|
|
|
rowsValue.GetUnit() == eCSSUnit_None) {
|
|
|
|
AppendValueToString(eCSSProperty_grid_auto_flow,
|
|
|
|
aValue, aSerialization);
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
AppendValueToString(eCSSProperty_grid_auto_columns,
|
|
|
|
aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(eCSSProperty_grid_auto_rows,
|
|
|
|
aValue, aSerialization);
|
|
|
|
break;
|
2014-03-24 06:26:04 -07:00
|
|
|
} else if (!(autoFlowValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
autoFlowValue.GetIntValue() == NS_STYLE_GRID_AUTO_FLOW_NONE &&
|
2014-03-21 08:06:12 -07:00
|
|
|
autoColumnsValue.GetUnit() == eCSSUnit_Auto &&
|
|
|
|
autoRowsValue.GetUnit() == eCSSUnit_Auto)) {
|
|
|
|
// Not serializable, bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Fall through to eCSSProperty_grid_template
|
|
|
|
}
|
2014-03-21 08:06:12 -07:00
|
|
|
case eCSSProperty_grid_template: {
|
|
|
|
const nsCSSValue& areasValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_areas);
|
|
|
|
const nsCSSValue& columnsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_columns);
|
|
|
|
const nsCSSValue& rowsValue =
|
|
|
|
*data->ValueFor(eCSSProperty_grid_template_rows);
|
|
|
|
if (areasValue.GetUnit() == eCSSUnit_None) {
|
|
|
|
AppendValueToString(eCSSProperty_grid_template_columns,
|
|
|
|
aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
AppendValueToString(eCSSProperty_grid_template_rows,
|
|
|
|
aValue, aSerialization);
|
|
|
|
break;
|
|
|
|
}
|
2014-03-31 04:31:00 -07:00
|
|
|
if (columnsValue.GetUnit() == eCSSUnit_List ||
|
|
|
|
columnsValue.GetUnit() == eCSSUnit_ListDep) {
|
|
|
|
const nsCSSValueList* columnsItem = columnsValue.GetListValue();
|
|
|
|
if (columnsItem->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
columnsItem->mValue.GetIntValue() == NS_STYLE_GRID_TEMPLATE_SUBGRID) {
|
|
|
|
// We have "grid-template-areas:[something]; grid-template-columns:subgrid"
|
|
|
|
// which isn't a value that the shorthand can express. Bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 08:06:12 -07:00
|
|
|
if (rowsValue.GetUnit() != eCSSUnit_List &&
|
|
|
|
rowsValue.GetUnit() != eCSSUnit_ListDep) {
|
|
|
|
// We have "grid-template-areas:[something]; grid-template-rows:none"
|
|
|
|
// which isn't a value that the shorthand can express. Bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const nsCSSValueList* rowsItem = rowsValue.GetListValue();
|
2014-03-31 04:31:00 -07:00
|
|
|
if (rowsItem->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
rowsItem->mValue.GetIntValue() == NS_STYLE_GRID_TEMPLATE_SUBGRID) {
|
|
|
|
// We have "grid-template-areas:[something]; grid-template-rows:subgrid"
|
|
|
|
// which isn't a value that the shorthand can express. Bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const GridTemplateAreasValue* areas = areasValue.GetGridTemplateAreas();
|
2014-03-21 08:06:12 -07:00
|
|
|
uint32_t nRowItems = 0;
|
|
|
|
while (rowsItem) {
|
|
|
|
nRowItems++;
|
|
|
|
rowsItem = rowsItem->mNext;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(nRowItems % 2 == 1, "expected an odd number of items");
|
2014-03-21 08:06:16 -07:00
|
|
|
if ((nRowItems - 1) / 2 != areas->NRows()) {
|
2014-03-21 08:06:12 -07:00
|
|
|
// Not serializable, bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (columnsValue.GetUnit() != eCSSUnit_None) {
|
|
|
|
AppendValueToString(eCSSProperty_grid_template_columns,
|
|
|
|
aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(" / ");
|
|
|
|
}
|
|
|
|
rowsItem = rowsValue.GetListValue();
|
|
|
|
uint32_t row = 0;
|
|
|
|
for (;;) {
|
|
|
|
bool addSpaceSeparator = true;
|
|
|
|
nsCSSUnit unit = rowsItem->mValue.GetUnit();
|
|
|
|
|
|
|
|
if (unit == eCSSUnit_Null) {
|
|
|
|
// Empty or omitted <line-names>. Serializes to nothing.
|
|
|
|
addSpaceSeparator = false; // Avoid a double space.
|
|
|
|
|
|
|
|
} else if (unit == eCSSUnit_List || unit == eCSSUnit_ListDep) {
|
|
|
|
// Non-empty <line-names>
|
|
|
|
aValue.AppendLiteral("(");
|
|
|
|
rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
|
|
|
|
aValue, aSerialization);
|
|
|
|
aValue.AppendLiteral(")");
|
|
|
|
|
|
|
|
} else {
|
2014-03-21 08:06:16 -07:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(areas->mTemplates[row++], aValue);
|
2014-03-21 08:06:12 -07:00
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
|
|
|
|
// <track-size>
|
|
|
|
rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
|
|
|
|
aValue, aSerialization);
|
2014-03-31 04:31:00 -07:00
|
|
|
if (rowsItem->mNext &&
|
|
|
|
rowsItem->mNext->mValue.GetUnit() == eCSSUnit_Null &&
|
|
|
|
!rowsItem->mNext->mNext) {
|
|
|
|
// Break out of the loop early to avoid a trailing space.
|
|
|
|
break;
|
|
|
|
}
|
2014-03-21 08:06:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
rowsItem = rowsItem->mNext;
|
|
|
|
if (!rowsItem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addSpaceSeparator) {
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-09-18 11:37:14 -07:00
|
|
|
case eCSSProperty__moz_transform: {
|
|
|
|
// shorthands that are just aliases with different parsing rules
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ABORT_IF_FALSE(subprops[1] == eCSSProperty_UNKNOWN,
|
|
|
|
"must have exactly one subproperty");
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2012-09-18 11:37:14 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-10-03 11:49:20 -07:00
|
|
|
case eCSSProperty_all:
|
|
|
|
// If we got here, then we didn't have all "inherit" or "initial" or
|
|
|
|
// "unset" values for all of the longhand property components of 'all'.
|
|
|
|
// There is no other possible value that is valid for all properties,
|
|
|
|
// so serialize as the empty string.
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "no other shorthands");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValueIsImportant(const nsAString& aProperty) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-07 09:14:23 -08:00
|
|
|
nsCSSProperty propID =
|
|
|
|
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eIgnoreEnabledState);
|
2010-10-17 19:36:26 -07:00
|
|
|
if (propID == eCSSProperty_UNKNOWN) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-10-17 19:36:26 -07:00
|
|
|
}
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
if (propID == eCSSPropertyExtra_variable) {
|
2014-04-01 20:32:16 -07:00
|
|
|
const nsSubstring& variableName =
|
|
|
|
Substring(aProperty, CSS_CUSTOM_NAME_PREFIX_LENGTH);
|
|
|
|
return GetVariableValueIsImportant(variableName);
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return GetValueIsImportant(propID);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValueIsImportant(nsCSSProperty aProperty) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mImportantData)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Calling ValueFor is inefficient, but we can assume '!important' is rare.
|
2008-10-07 15:10:20 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return mImportantData->ValueFor(aProperty) != nullptr;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07: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 07:59:28 -07:00
|
|
|
return false;
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAutoString& aValue,
|
|
|
|
nsAString& aResult) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07: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 06:06:57 -08:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.AppendLiteral(": ");
|
2008-12-23 06:06:57 -08:00
|
|
|
if (aValue.IsEmpty())
|
2013-09-15 16:35:49 -07:00
|
|
|
AppendValueToString(aProperty, aResult, nsCSSValue::eNormalized);
|
2008-12-23 06:06:57 -08:00
|
|
|
else
|
|
|
|
aResult.Append(aValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
if (GetValueIsImportant(aProperty)) {
|
|
|
|
aResult.AppendLiteral(" ! important");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.AppendLiteral("; ");
|
|
|
|
}
|
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
void
|
|
|
|
Declaration::AppendVariableAndValueToString(const nsAString& aName,
|
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
2014-04-01 20:32:16 -07:00
|
|
|
aResult.AppendLiteral("--");
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
aResult.Append(aName);
|
|
|
|
CSSVariableDeclarations::Type type;
|
|
|
|
nsString value;
|
|
|
|
bool important;
|
|
|
|
|
|
|
|
if (mImportantVariables && mImportantVariables->Get(aName, type, value)) {
|
|
|
|
important = true;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mVariables);
|
|
|
|
MOZ_ASSERT(mVariables->Has(aName));
|
|
|
|
mVariables->Get(aName, type, value);
|
|
|
|
important = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case CSSVariableDeclarations::eTokenStream:
|
|
|
|
if (value.IsEmpty()) {
|
|
|
|
aResult.Append(':');
|
|
|
|
} else {
|
|
|
|
aResult.AppendLiteral(": ");
|
|
|
|
aResult.Append(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInitial:
|
|
|
|
aResult.AppendLiteral("initial");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInherit:
|
|
|
|
aResult.AppendLiteral("inherit");
|
|
|
|
break;
|
|
|
|
|
2013-12-11 18:09:47 -08:00
|
|
|
case CSSVariableDeclarations::eUnset:
|
|
|
|
aResult.AppendLiteral("unset");
|
|
|
|
break;
|
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unexpected variable value type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (important) {
|
|
|
|
aResult.AppendLiteral("! important");
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral("; ");
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::ToString(nsAString& aString) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-02 15:40:35 -07: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 08:52:12 -08:00
|
|
|
nsCSSCompressedDataBlock *systemFontData =
|
|
|
|
GetValueIsImportant(eCSSProperty__x_system_font) ? mImportantData : mData;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *systemFont =
|
|
|
|
systemFontData->ValueFor(eCSSProperty__x_system_font);
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool haveSystemFont = systemFont &&
|
2009-02-06 08:52:12 -08:00
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool didSystemFont = false;
|
2009-02-06 08:52:12 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mOrder.Length();
|
|
|
|
int32_t index;
|
2008-12-23 06:06:57 -08:00
|
|
|
nsAutoTArray<nsCSSProperty, 16> shorthandsUsed;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (index = 0; index < count; index++) {
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
nsCSSProperty property = GetPropertyAt(index);
|
|
|
|
|
|
|
|
if (property == eCSSPropertyExtra_variable) {
|
|
|
|
uint32_t variableIndex = mOrder[index] - eCSSProperty_COUNT;
|
|
|
|
AppendVariableAndValueToString(mVariableOrder[variableIndex], aString);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:01:41 -07:00
|
|
|
if (!nsCSSProps::IsEnabled(property)) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doneProperty = false;
|
2008-12-23 06:06:57 -08: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 07:59:28 -07:00
|
|
|
doneProperty = true;
|
2008-12-23 06:06:57 -08:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-23 06:06:57 -08: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 07:59:28 -07:00
|
|
|
doneProperty = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
2009-02-06 08:52:12 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(shorthand != eCSSProperty_font ||
|
|
|
|
*(shorthands + 1) == eCSSProperty_UNKNOWN,
|
|
|
|
"font should always be the only containing shorthand");
|
2009-02-19 13:55:48 -08:00
|
|
|
if (shorthand == eCSSProperty_font) {
|
|
|
|
if (haveSystemFont && !didSystemFont) {
|
2009-02-06 08:52:12 -08: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.
|
2013-09-15 16:35:49 -07:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, value,
|
|
|
|
nsCSSValue::eNormalized);
|
2009-02-06 08:52:12 -08:00
|
|
|
AppendPropertyAndValueToString(eCSSProperty_font, value, aString);
|
|
|
|
value.Truncate();
|
2011-10-17 07:59:28 -07:00
|
|
|
didSystemFont = true;
|
2009-02-06 08:52:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// That we output the system font is enough for this property if:
|
2009-02-19 13:55:48 -08: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 08:52:12 -08:00
|
|
|
// (2) its value is the hidden system font value and it matches
|
2009-02-19 13:55:48 -08:00
|
|
|
// the hidden system font subproperty in importance, and
|
|
|
|
// we output the system font subproperty.
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = systemFontData->ValueFor(property);
|
2009-02-06 08:52:12 -08:00
|
|
|
if (property == eCSSProperty__x_system_font ||
|
2009-02-19 13:55:48 -08:00
|
|
|
(haveSystemFont && val && val->GetUnit() == eCSSUnit_System_Font)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
doneProperty = true;
|
2009-02-06 08:52:12 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(value.IsEmpty(), "value should be empty now");
|
2008-12-23 06:06:57 -08:00
|
|
|
AppendPropertyAndValueToString(property, value, aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (! aString.IsEmpty()) {
|
2010-08-19 12:33:44 -07:00
|
|
|
// if the string is not empty, we have trailing whitespace we
|
|
|
|
// should remove
|
2007-03-22 10:30:00 -07:00
|
|
|
aString.Truncate(aString.Length() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-08-19 12:33:44 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
Declaration::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fputs("{ ", out);
|
2007-05-16 14:17:45 -07:00
|
|
|
nsAutoString s;
|
|
|
|
ToString(s);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(s).get(), out);
|
2007-03-22 10:30:00 -07:00
|
|
|
fputs("}", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-23 21:08:08 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
Declaration::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aReturn.Truncate();
|
2008-01-10 12:13:24 -08:00
|
|
|
if (aIndex < mOrder.Length()) {
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
nsCSSProperty property = GetPropertyAt(aIndex);
|
|
|
|
if (property == eCSSPropertyExtra_variable) {
|
|
|
|
GetCustomPropertyNameAt(aIndex, aReturn);
|
|
|
|
return true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (0 <= property) {
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
|
2012-08-23 21:08:08 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 21:08:08 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::InitializeEmpty()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "already initialized");
|
2007-03-22 10:30:00 -07:00
|
|
|
mData = nsCSSCompressedDataBlock::CreateEmptyBlock();
|
|
|
|
}
|
2009-12-11 08:13:19 -08:00
|
|
|
|
2010-07-23 11:00:49 -07:00
|
|
|
Declaration*
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::EnsureMutable()
|
2009-12-11 08:13:19 -08:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(mData, "should only be called when not expanded");
|
2010-07-23 11:00:49 -07:00
|
|
|
if (!IsMutable()) {
|
2010-07-23 11:00:52 -07:00
|
|
|
return new Declaration(*this);
|
2010-07-23 11:00:49 -07:00
|
|
|
} else {
|
|
|
|
return this;
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
}
|
2010-06-28 15:49:35 -07:00
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
Declaration::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-02 18:19:14 -08:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mOrder.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mData ? mData ->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
n += mImportantData ? mImportantData->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
if (mVariables) {
|
|
|
|
n += mVariables->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (mImportantVariables) {
|
|
|
|
n += mImportantVariables->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2012-01-02 18:19:14 -08:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
bool
|
|
|
|
Declaration::HasVariableDeclaration(const nsAString& aName) const
|
|
|
|
{
|
|
|
|
return (mVariables && mVariables->Has(aName)) ||
|
|
|
|
(mImportantVariables && mImportantVariables->Has(aName));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::GetVariableDeclaration(const nsAString& aName,
|
|
|
|
nsAString& aValue) const
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
CSSVariableDeclarations::Type type;
|
|
|
|
nsString value;
|
|
|
|
|
|
|
|
if ((mImportantVariables && mImportantVariables->Get(aName, type, value)) ||
|
|
|
|
(mVariables && mVariables->Get(aName, type, value))) {
|
|
|
|
switch (type) {
|
|
|
|
case CSSVariableDeclarations::eTokenStream:
|
|
|
|
aValue.Append(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInitial:
|
|
|
|
aValue.AppendLiteral("initial");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInherit:
|
|
|
|
aValue.AppendLiteral("inherit");
|
|
|
|
break;
|
|
|
|
|
2013-12-11 18:09:47 -08:00
|
|
|
case CSSVariableDeclarations::eUnset:
|
|
|
|
aValue.AppendLiteral("unset");
|
|
|
|
break;
|
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unexpected variable value type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::AddVariableDeclaration(const nsAString& aName,
|
|
|
|
CSSVariableDeclarations::Type aType,
|
|
|
|
const nsString& aValue,
|
2013-12-11 18:09:46 -08:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant)
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsMutable());
|
|
|
|
|
|
|
|
nsTArray<nsString>::index_type index = mVariableOrder.IndexOf(aName);
|
|
|
|
if (index == nsTArray<nsString>::NoIndex) {
|
|
|
|
index = mVariableOrder.Length();
|
|
|
|
mVariableOrder.AppendElement(aName);
|
|
|
|
}
|
|
|
|
|
2013-12-11 18:09:46 -08:00
|
|
|
if (!aIsImportant && !aOverrideImportant &&
|
|
|
|
mImportantVariables && mImportantVariables->Has(aName)) {
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSVariableDeclarations* variables;
|
|
|
|
if (aIsImportant) {
|
|
|
|
if (mVariables) {
|
|
|
|
mVariables->Remove(aName);
|
|
|
|
}
|
|
|
|
if (!mImportantVariables) {
|
|
|
|
mImportantVariables = new CSSVariableDeclarations;
|
|
|
|
}
|
|
|
|
variables = mImportantVariables;
|
|
|
|
} else {
|
2013-12-11 18:09:46 -08:00
|
|
|
if (mImportantVariables) {
|
|
|
|
mImportantVariables->Remove(aName);
|
|
|
|
}
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
if (!mVariables) {
|
|
|
|
mVariables = new CSSVariableDeclarations;
|
|
|
|
}
|
|
|
|
variables = mVariables;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aType) {
|
|
|
|
case CSSVariableDeclarations::eTokenStream:
|
|
|
|
variables->PutTokenStream(aName, aValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInitial:
|
|
|
|
MOZ_ASSERT(aValue.IsEmpty());
|
|
|
|
variables->PutInitial(aName);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSSVariableDeclarations::eInherit:
|
|
|
|
MOZ_ASSERT(aValue.IsEmpty());
|
|
|
|
variables->PutInherit(aName);
|
|
|
|
break;
|
|
|
|
|
2013-12-11 18:09:47 -08:00
|
|
|
case CSSVariableDeclarations::eUnset:
|
|
|
|
MOZ_ASSERT(aValue.IsEmpty());
|
|
|
|
variables->PutUnset(aName);
|
|
|
|
break;
|
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
default:
|
2014-03-07 00:53:03 -08:00
|
|
|
MOZ_ASSERT(false, "unexpected aType value");
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t propertyIndex = index + eCSSProperty_COUNT;
|
|
|
|
mOrder.RemoveElement(propertyIndex);
|
|
|
|
mOrder.AppendElement(propertyIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::RemoveVariableDeclaration(const nsAString& aName)
|
|
|
|
{
|
|
|
|
if (mVariables) {
|
|
|
|
mVariables->Remove(aName);
|
|
|
|
}
|
|
|
|
if (mImportantVariables) {
|
|
|
|
mImportantVariables->Remove(aName);
|
|
|
|
}
|
|
|
|
nsTArray<nsString>::index_type index = mVariableOrder.IndexOf(aName);
|
|
|
|
if (index != nsTArray<nsString>::NoIndex) {
|
|
|
|
mOrder.RemoveElement(index + eCSSProperty_COUNT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Declaration::GetVariableValueIsImportant(const nsAString& aName) const
|
|
|
|
{
|
|
|
|
return mImportantVariables && mImportantVariables->Has(aName);
|
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
} // namespace mozilla::css
|
|
|
|
} // namespace mozilla
|