2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2010-08-19 23:33:44 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "gfxFontConstants.h"
|
2014-03-21 19:06:12 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2010-07-03 08:18:55 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::Declaration()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mImmutable(false)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::Declaration(const Declaration& aCopy)
|
2008-01-10 23:13:24 +03:00
|
|
|
: mOrder(aCopy.mOrder),
|
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-12 06:09:40 +04:00
|
|
|
mVariableOrder(aCopy.mVariableOrder),
|
2012-07-30 18:20:58 +04: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-12 06:09:40 +04: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 18:59:28 +04:00
|
|
|
mImmutable(false)
|
1999-06-03 05:58:11 +04:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
1999-06-03 05:58:11 +04:00
|
|
|
}
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::~Declaration()
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
2010-06-29 02:49:35 +04:00
|
|
|
MOZ_COUNT_DTOR(mozilla::css::Declaration);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::ValueAppended(nsCSSProperty aProperty)
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
2010-07-23 22:00:49 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData,
|
|
|
|
"should only be called while expanded");
|
2009-03-06 07:05:01 +03:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"shorthands forbidden");
|
2003-06-08 02:14:42 +04:00
|
|
|
// order IS important for CSS, so remove and add to the end
|
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-12 06:09:40 +04:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
|
|
|
|
mOrder.AppendElement(static_cast<uint32_t>(aProperty));
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::RemoveProperty(nsCSSProperty aProperty)
|
2002-01-16 01:43:37 +03:00
|
|
|
{
|
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-12 06:09:40 +04:00
|
|
|
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT);
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSExpandedDataBlock data;
|
2009-12-11 19:13:19 +03:00
|
|
|
ExpandTo(&data);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "Expand didn't null things out");
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2010-07-23 22:00:42 +04:00
|
|
|
data.ClearLonghandProperty(*p);
|
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-12 06:09:40 +04:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(*p));
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-23 22:00:42 +04: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-12 06:09:40 +04:00
|
|
|
mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
CompressFrom(&data);
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-24 21:31:52 +03:00
|
|
|
Declaration::HasProperty(nsCSSProperty aProperty) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
return !!val;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-19 23:33:44 +04:00
|
|
|
Declaration::AppendValueToString(nsCSSProperty aProperty,
|
2013-09-16 03:35:49 +04:00
|
|
|
nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aSerialization) const
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
2010-07-23 22:00:29 +04:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
if (!val) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-23 22:00:29 +04:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2013-09-16 03:35:49 +04:00
|
|
|
val->AppendToString(aProperty, aResult, aSerialization);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
|
2013-09-16 03:35:49 +04: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
|
1998-10-08 05:31:58 +04:00
|
|
|
{
|
|
|
|
aValue.Truncate(0);
|
1998-09-30 05:08:59 +04:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
// simple properties are easy.
|
2004-10-01 02:32:28 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(aProperty, aValue, aSerialization);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-10-08 02:10:20 +04:00
|
|
|
// DOM Level 2 Style says (when describing CSS2Properties, although
|
|
|
|
// not CSSStyleDeclaration.getPropertyValue):
|
|
|
|
// However, if there is no shorthand declaration that could be added
|
|
|
|
// to the ruleset without changing in any way the rules already
|
|
|
|
// declared in the ruleset (i.e., by adding longhand rules that were
|
|
|
|
// previously not declared in the ruleset), then the empty string
|
|
|
|
// should be returned for the shorthand property.
|
|
|
|
// This means we need to check a number of cases:
|
|
|
|
// (1) Since a shorthand sets all sub-properties, if some of its
|
|
|
|
// subproperties were not specified, we must return the empty
|
|
|
|
// string.
|
2013-10-03 22:49:19 +04: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-08 02:10:20 +04: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-12 06:09:46 +04: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 19:56:38 +04:00
|
|
|
uint32_t totalCount = 0, importantCount = 0,
|
2013-12-12 06:09:46 +04:00
|
|
|
initialCount = 0, inheritCount = 0, unsetCount = 0,
|
2014-08-14 16:36:25 +04:00
|
|
|
matchingTokenStreamCount = 0, nonMatchingTokenStreamCount = 0;
|
2007-06-12 22:28:56 +04:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2014-12-31 07:04:20 +03:00
|
|
|
if (*p == eCSSProperty__x_system_font ||
|
|
|
|
nsCSSProps::PropHasFlags(*p, CSS_PROPERTY_DIRECTIONAL_SOURCE)) {
|
|
|
|
// The system-font subproperty and the *-source properties don't count.
|
2008-10-08 02:10:20 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++totalCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = mData->ValueFor(*p);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!val || !mImportantData || !mImportantData->ValueFor(*p),
|
|
|
|
"can't be in both blocks");
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!val && mImportantData) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++importantCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
val = mImportantData->ValueFor(*p);
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!val) {
|
2008-10-08 02:10:20 +04:00
|
|
|
// Case (1) above: some subproperties not specified.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
if (val->GetUnit() == eCSSUnit_Inherit) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++inheritCount;
|
2010-08-19 23:33:44 +04:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Initial) {
|
2008-10-08 02:10:20 +04:00
|
|
|
++initialCount;
|
2013-10-03 22:49:19 +04:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Unset) {
|
|
|
|
++unsetCount;
|
2014-08-14 16:36:25 +04:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_TokenStream) {
|
|
|
|
if (val->GetTokenStreamValue()->mShorthandPropertyID == aProperty) {
|
|
|
|
tokenStream = val;
|
|
|
|
++matchingTokenStreamCount;
|
|
|
|
} else {
|
|
|
|
++nonMatchingTokenStreamCount;
|
|
|
|
}
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (importantCount != 0 && importantCount != totalCount) {
|
|
|
|
// Case (3), no consistent importance.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
if (initialCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing initial up-front.
|
2013-09-16 03:35:49 +04:00
|
|
|
nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
if (inheritCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing inherit up-front.
|
2013-09-16 03:35:49 +04:00
|
|
|
nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
2013-10-03 22:49:19 +04:00
|
|
|
if (unsetCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing unset up-front.
|
2013-09-16 03:35:49 +04:00
|
|
|
nsCSSValue(eCSSUnit_Unset).AppendToString(eCSSProperty_UNKNOWN, aValue,
|
|
|
|
nsCSSValue::eNormalized);
|
2013-10-03 22:49:19 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-14 16:36:25 +04:00
|
|
|
if (initialCount != 0 || inheritCount != 0 ||
|
|
|
|
unsetCount != 0 || nonMatchingTokenStreamCount != 0) {
|
|
|
|
// Case (2): partially initial, inherit, unset or token stream.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
2013-12-12 06:09:46 +04: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 22:28:56 +04:00
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
|
1998-10-08 05:31:58 +04:00
|
|
|
switch (aProperty) {
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_margin:
|
|
|
|
case eCSSProperty_padding:
|
|
|
|
case eCSSProperty_border_color:
|
|
|
|
case eCSSProperty_border_style:
|
|
|
|
case eCSSProperty_border_width: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[0]).Find("-top") !=
|
|
|
|
kNotFound, "first subprop must be top");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[1]).Find("-right") !=
|
|
|
|
kNotFound, "second subprop must be right");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[2]).Find("-bottom") !=
|
|
|
|
kNotFound, "third subprop must be bottom");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[3]).Find("-left") !=
|
|
|
|
kNotFound, "fourth subprop must be left");
|
2013-07-02 16:11:21 +04:00
|
|
|
const nsCSSValue* vals[4] = {
|
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
|
|
|
};
|
2014-11-22 07:28:00 +03:00
|
|
|
nsCSSValue::AppendSidesShorthandToString(subprops, vals, aValue,
|
|
|
|
aSerialization);
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2010-09-09 19:21:47 +04:00
|
|
|
case eCSSProperty_border_radius:
|
2008-10-01 09:50:52 +04:00
|
|
|
case eCSSProperty__moz_outline_radius: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue* vals[4] = {
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
2008-10-01 09:50:52 +04:00
|
|
|
};
|
2014-11-22 07:28:00 +03:00
|
|
|
nsCSSValue::AppendBasicShapeRadiusToString(subprops, vals, aValue,
|
|
|
|
aSerialization);
|
2008-10-01 09:50:52 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-05-31 09:19:49 +04:00
|
|
|
case eCSSProperty_border_image: {
|
|
|
|
// Even though there are some cases where we could omit
|
|
|
|
// 'border-image-source' (when it's none), it's probably not a
|
|
|
|
// good idea since it's likely to be confusing. It would also
|
|
|
|
// require adding the extra check that we serialize *something*.
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_source, aValue,
|
|
|
|
aSerialization);
|
2012-05-31 09:19:49 +04:00
|
|
|
|
|
|
|
bool sliceDefault = data->HasDefaultBorderImageSlice();
|
|
|
|
bool widthDefault = data->HasDefaultBorderImageWidth();
|
|
|
|
bool outsetDefault = data->HasDefaultBorderImageOutset();
|
|
|
|
|
|
|
|
if (!sliceDefault || !widthDefault || !outsetDefault) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_slice, aValue,
|
|
|
|
aSerialization);
|
2012-05-31 09:19:49 +04:00
|
|
|
if (!widthDefault || !outsetDefault) {
|
2014-05-22 07:48:50 +04:00
|
|
|
aValue.AppendLiteral(" /");
|
2012-05-31 09:19:49 +04:00
|
|
|
if (!widthDefault) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_width, aValue,
|
|
|
|
aSerialization);
|
2012-05-31 09:19:49 +04:00
|
|
|
}
|
|
|
|
if (!outsetDefault) {
|
2014-05-22 07:48:50 +04:00
|
|
|
aValue.AppendLiteral(" / ");
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_outset, aValue,
|
|
|
|
aSerialization);
|
2012-05-31 09:19:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool repeatDefault = data->HasDefaultBorderImageRepeat();
|
|
|
|
if (!repeatDefault) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_border_image_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-05-31 09:19:49 +04:00
|
|
|
}
|
2011-12-23 03:34:45 +04:00
|
|
|
break;
|
2012-05-31 09:19:49 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
case eCSSProperty_border: {
|
2012-05-31 09:19:49 +04:00
|
|
|
// If we have a non-default value for any of the properties that
|
|
|
|
// this shorthand sets but cannot specify, we have to return the
|
|
|
|
// empty string.
|
|
|
|
if (data->ValueFor(eCSSProperty_border_image_source)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
!data->HasDefaultBorderImageSlice() ||
|
|
|
|
!data->HasDefaultBorderImageWidth() ||
|
|
|
|
!data->HasDefaultBorderImageOutset() ||
|
|
|
|
!data->HasDefaultBorderImageRepeat() ||
|
|
|
|
data->ValueFor(eCSSProperty_border_top_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_right_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_bottom_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None ||
|
|
|
|
data->ValueFor(eCSSProperty_border_left_colors)->GetUnit() !=
|
|
|
|
eCSSUnit_None) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
const nsCSSProperty* subproptables[3] = {
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_style),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_width)
|
|
|
|
};
|
2011-09-29 10:19:26 +04:00
|
|
|
bool match = true;
|
2008-12-23 17:06:57 +03:00
|
|
|
for (const nsCSSProperty** subprops = subproptables,
|
2011-10-11 09:50:08 +04:00
|
|
|
**subprops_end = ArrayEnd(subproptables);
|
2008-12-23 17:06:57 +03:00
|
|
|
subprops < subprops_end; ++subprops) {
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *firstSide = data->ValueFor((*subprops)[0]);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t side = 1; side < 4; ++side) {
|
2008-12-23 17:06:57 +03:00
|
|
|
const nsCSSValue *otherSide =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor((*subprops)[side]);
|
2008-12-23 17:06:57 +03:00
|
|
|
if (*firstSide != *otherSide)
|
2011-10-17 18:59:28 +04:00
|
|
|
match = false;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
|
|
|
// We can't express what we have in the border shorthand
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// tweak aProperty and fall through
|
2003-06-08 02:14:42 +04:00
|
|
|
aProperty = eCSSProperty_border_top;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_right:
|
|
|
|
case eCSSProperty_border_bottom:
|
|
|
|
case eCSSProperty_border_left:
|
2007-07-04 22:51:16 +04:00
|
|
|
case eCSSProperty_border_start:
|
|
|
|
case eCSSProperty_border_end:
|
2008-07-19 14:38:25 +04:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline: {
|
2003-06-08 02:14:42 +04:00
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
|
2015-01-17 07:16:02 +03:00
|
|
|
NS_LITERAL_CSTRING("-color")),
|
2010-08-19 23:33:44 +04:00
|
|
|
"third subprop must be the color property");
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isMozUseTextColor =
|
2008-12-23 17:06:57 +03:00
|
|
|
colorValue->GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
colorValue->GetIntValue() == NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR;
|
2013-09-16 03:35:49 +04:00
|
|
|
if (!AppendValueToString(subprops[0], aValue, aSerialization) ||
|
2014-01-04 19:02:17 +04:00
|
|
|
!(aValue.Append(char16_t(' ')),
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization)) ||
|
2008-12-23 17:06:57 +03:00
|
|
|
// Don't output a third value when it's -moz-use-text-color.
|
|
|
|
!(isMozUseTextColor ||
|
2014-01-04 19:02:17 +04:00
|
|
|
(aValue.Append(char16_t(' ')),
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[2], aValue, aSerialization)))) {
|
2003-06-08 02:14:42 +04:00
|
|
|
aValue.Truncate();
|
1998-10-08 05:31:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_background: {
|
2009-02-20 08:29:21 +03:00
|
|
|
// We know from above that all subproperties were specified.
|
|
|
|
// However, we still can't represent that in the shorthand unless
|
|
|
|
// they're all lists of the same length. So if they're different
|
|
|
|
// lengths, we need to bail out.
|
|
|
|
// We also need to bail out if an item has background-clip and
|
|
|
|
// background-origin that are different and not the default
|
|
|
|
// values. (We omit them if they're both default.)
|
|
|
|
const nsCSSValueList *image =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_image)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2012-02-25 09:23:14 +04:00
|
|
|
const nsCSSValuePairList *repeat =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_repeat)->
|
2012-02-25 09:23:14 +04:00
|
|
|
GetPairListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *attachment =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_attachment)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2012-02-20 04:14:42 +04:00
|
|
|
const nsCSSValueList *position =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_position)->
|
2012-02-20 04:14:42 +04:00
|
|
|
GetListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *clip =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_clip)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
const nsCSSValueList *origin =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_origin)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetListValue();
|
2009-05-28 22:09:05 +04:00
|
|
|
const nsCSSValuePairList *size =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty_background_size)->
|
2010-08-19 23:33:44 +04:00
|
|
|
GetPairListValue();
|
2009-02-20 08:29:21 +03:00
|
|
|
for (;;) {
|
2013-09-16 03:35:49 +04:00
|
|
|
image->mValue.AppendToString(eCSSProperty_background_image, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
repeat->mXValue.AppendToString(eCSSProperty_background_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-02-25 09:23:14 +04:00
|
|
|
if (repeat->mYValue.GetUnit() != eCSSUnit_Null) {
|
2013-09-16 03:35:49 +04:00
|
|
|
repeat->mYValue.AppendToString(eCSSProperty_background_repeat, aValue,
|
|
|
|
aSerialization);
|
2012-02-25 09:23:14 +04:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-07-23 22:00:27 +04:00
|
|
|
attachment->mValue.AppendToString(eCSSProperty_background_attachment,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2012-02-20 04:14:42 +04:00
|
|
|
position->mValue.AppendToString(eCSSProperty_background_position,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2012-09-17 04:20:15 +04:00
|
|
|
|
|
|
|
if (size->mXValue.GetUnit() != eCSSUnit_Auto ||
|
|
|
|
size->mYValue.GetUnit() != eCSSUnit_Auto) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
aValue.Append(char16_t('/'));
|
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
size->mXValue.AppendToString(eCSSProperty_background_size, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
size->mYValue.AppendToString(eCSSProperty_background_size, aValue,
|
|
|
|
aSerialization);
|
2012-09-17 04:20:15 +04:00
|
|
|
}
|
2012-02-23 20:19:00 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(clip->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
origin->mValue.GetUnit() == eCSSUnit_Enumerated,
|
2012-02-23 20:19:00 +04:00
|
|
|
"should not have inherit/initial within list");
|
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
if (clip->mValue.GetIntValue() != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
origin->mValue.GetIntValue() != NS_STYLE_BG_ORIGIN_PADDING) {
|
2013-03-08 05:59:32 +04:00
|
|
|
MOZ_ASSERT(nsCSSProps::kKeywordTableTable[
|
|
|
|
eCSSProperty_background_origin] ==
|
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
|
|
|
MOZ_ASSERT(nsCSSProps::kKeywordTableTable[
|
|
|
|
eCSSProperty_background_clip] ==
|
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
2013-07-18 21:59:53 +04: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 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
origin->mValue.AppendToString(eCSSProperty_background_origin, aValue,
|
|
|
|
aSerialization);
|
2013-03-08 05:59:32 +04:00
|
|
|
|
2009-02-20 08:29:21 +03:00
|
|
|
if (clip->mValue != origin->mValue) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
clip->mValue.AppendToString(eCSSProperty_background_clip, aValue,
|
|
|
|
aSerialization);
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image = image->mNext;
|
|
|
|
repeat = repeat->mNext;
|
|
|
|
attachment = attachment->mNext;
|
|
|
|
position = position->mNext;
|
|
|
|
clip = clip->mNext;
|
|
|
|
origin = origin->mNext;
|
2009-05-28 22:09:05 +04:00
|
|
|
size = size->mNext;
|
2009-02-20 08:29:21 +03:00
|
|
|
|
|
|
|
if (!image) {
|
2009-05-28 22:09:05 +04:00
|
|
|
if (repeat || attachment || position || clip || origin || size) {
|
2009-02-20 08:29:21 +03:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-28 22:09:05 +04:00
|
|
|
if (!repeat || !attachment || !position || !clip || !origin || !size) {
|
2009-02-20 08:29:21 +03:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-20 08:29:21 +03:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(','));
|
|
|
|
aValue.Append(char16_t(' '));
|
1998-10-08 05:31:58 +04:00
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_background_color, aValue,
|
|
|
|
aSerialization);
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_font: {
|
2013-07-25 10:02:15 +04: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 19:52:13 +03:00
|
|
|
const nsCSSValue *systemFont =
|
2010-08-19 23:33:44 +04:00
|
|
|
data->ValueFor(eCSSProperty__x_system_font);
|
2013-07-25 10:02:15 +04:00
|
|
|
const nsCSSValue *style =
|
|
|
|
data->ValueFor(eCSSProperty_font_style);
|
|
|
|
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);
|
|
|
|
|
2009-02-06 19:52:12 +03:00
|
|
|
if (systemFont &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null) {
|
2013-07-25 10:02:15 +04:00
|
|
|
if (style->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 ||
|
2014-08-20 11:54:35 +04: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 19:52:12 +03:00
|
|
|
// This can't be represented as a shorthand.
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
2013-09-16 03:35:49 +04:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, aValue,
|
|
|
|
aSerialization);
|
2003-06-08 02:14:42 +04:00
|
|
|
} else {
|
2013-07-25 10:01:41 +04:00
|
|
|
// properties reset by this shorthand property to their
|
|
|
|
// initial values but not represented in its syntax
|
2013-07-25 10:02:15 +04: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 ||
|
2014-08-20 11:54:35 +04:00
|
|
|
fontKerning->GetIntValue() != NS_FONT_KERNING_AUTO ||
|
|
|
|
fontSynthesis->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
fontSynthesis->GetIntValue() !=
|
|
|
|
(NS_FONT_SYNTHESIS_WEIGHT | NS_FONT_SYNTHESIS_STYLE) ||
|
|
|
|
fontVariantAlternates->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantEastAsian->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantLigatures->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantNumeric->GetUnit() != eCSSUnit_Normal ||
|
|
|
|
fontVariantPosition->GetUnit() != eCSSUnit_Normal) {
|
2010-07-23 22:00:34 +04:00
|
|
|
return;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
|
|
|
|
2014-08-20 11:54:25 +04:00
|
|
|
// only a normal or small-caps values of font-variant-caps can
|
|
|
|
// be represented in the font shorthand
|
|
|
|
if (fontVariantCaps->GetUnit() != eCSSUnit_Normal &&
|
|
|
|
(fontVariantCaps->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
fontVariantCaps->GetIntValue() != NS_FONT_VARIANT_CAPS_SMALLCAPS)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:02:15 +04:00
|
|
|
if (style->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
style->GetIntValue() != NS_FONT_STYLE_NORMAL) {
|
2013-09-16 03:35:49 +04:00
|
|
|
style->AppendToString(eCSSProperty_font_style, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
2014-08-20 11:54:25 +04:00
|
|
|
if (fontVariantCaps->GetUnit() != eCSSUnit_Normal) {
|
|
|
|
fontVariantCaps->AppendToString(eCSSProperty_font_variant_caps, aValue,
|
2013-09-16 03:35:49 +04:00
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
2013-07-25 10:02:15 +04:00
|
|
|
if (weight->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
weight->GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
|
2013-09-16 03:35:49 +04:00
|
|
|
weight->AppendToString(eCSSProperty_font_weight, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
2013-09-16 03:35:49 +04:00
|
|
|
size->AppendToString(eCSSProperty_font_size, aValue, aSerialization);
|
2013-07-25 10:02:15 +04:00
|
|
|
if (lh->GetUnit() != eCSSUnit_Normal) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t('/'));
|
2013-09-16 03:35:49 +04:00
|
|
|
lh->AppendToString(eCSSProperty_line_height, aValue, aSerialization);
|
2007-06-12 22:28:56 +04:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
family->AppendToString(eCSSProperty_font_family, aValue,
|
|
|
|
aSerialization);
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2002-01-16 01:43:37 +03:00
|
|
|
}
|
2014-08-20 11:54:25 +04:00
|
|
|
case eCSSProperty_font_variant: {
|
|
|
|
const nsCSSProperty *subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
const nsCSSValue *fontVariantLigatures =
|
|
|
|
data->ValueFor(eCSSProperty_font_variant_ligatures);
|
|
|
|
|
|
|
|
// all subproperty values normal? system font?
|
|
|
|
bool normalLigs = true, normalNonLigs = true, systemFont = true,
|
|
|
|
hasSystem = false;
|
|
|
|
for (const nsCSSProperty *sp = subprops; *sp != eCSSProperty_UNKNOWN; sp++) {
|
|
|
|
const nsCSSValue *spVal = data->ValueFor(*sp);
|
|
|
|
bool isNormal = (spVal->GetUnit() == eCSSUnit_Normal);
|
|
|
|
if (*sp == eCSSProperty_font_variant_ligatures) {
|
|
|
|
normalLigs = normalLigs && isNormal;
|
|
|
|
} else {
|
|
|
|
normalNonLigs = normalNonLigs && isNormal;
|
|
|
|
}
|
|
|
|
bool isSystem = (spVal->GetUnit() == eCSSUnit_System_Font);
|
|
|
|
systemFont = systemFont && isSystem;
|
|
|
|
hasSystem = hasSystem || isSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ligsNone =
|
|
|
|
fontVariantLigatures->GetUnit() == eCSSUnit_None;
|
|
|
|
|
|
|
|
// normal, none, or system font ==> single value
|
|
|
|
if ((normalLigs && normalNonLigs) ||
|
|
|
|
(normalNonLigs && ligsNone) ||
|
|
|
|
systemFont) {
|
|
|
|
fontVariantLigatures->AppendToString(eCSSProperty_font_variant_ligatures,
|
|
|
|
aValue,
|
|
|
|
aSerialization);
|
|
|
|
} else if (ligsNone || hasSystem) {
|
|
|
|
// ligatures none but other values are non-normal ==> empty
|
|
|
|
// at least one but not all values are system font ==> empty
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// iterate over and append non-normal values
|
|
|
|
bool appendSpace = false;
|
|
|
|
for (const nsCSSProperty *sp = subprops;
|
|
|
|
*sp != eCSSProperty_UNKNOWN; sp++) {
|
|
|
|
const nsCSSValue *spVal = data->ValueFor(*sp);
|
|
|
|
if (spVal && spVal->GetUnit() != eCSSUnit_Normal) {
|
|
|
|
if (appendSpace) {
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
} else {
|
|
|
|
appendSpace = true;
|
|
|
|
}
|
|
|
|
spVal->AppendToString(*sp, aValue, aSerialization);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-07-18 04:25:28 +04:00
|
|
|
case eCSSProperty_list_style:
|
2014-06-12 05:12:00 +04:00
|
|
|
if (AppendValueToString(eCSSProperty_list_style_position, aValue,
|
2013-09-16 03:35:49 +04:00
|
|
|
aSerialization)) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
}
|
2014-06-12 05:12:00 +04:00
|
|
|
if (AppendValueToString(eCSSProperty_list_style_image, aValue,
|
2013-09-16 03:35:49 +04:00
|
|
|
aSerialization)) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
}
|
2014-06-12 05:12:00 +04:00
|
|
|
AppendValueToString(eCSSProperty_list_style_type, aValue,
|
2013-09-16 03:35:49 +04:00
|
|
|
aSerialization);
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
2004-09-05 04:04:04 +04:00
|
|
|
case eCSSProperty_overflow: {
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &xValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_x);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &yValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_y);
|
2004-09-05 04:04:04 +04:00
|
|
|
if (xValue == yValue)
|
2013-09-16 03:35:49 +04:00
|
|
|
xValue.AppendToString(eCSSProperty_overflow_x, aValue, aSerialization);
|
2004-09-05 04:04:04 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-04-23 09:16:41 +04:00
|
|
|
case eCSSProperty_text_decoration: {
|
2013-07-25 10:02:15 +04:00
|
|
|
const nsCSSValue *decorationColor =
|
|
|
|
data->ValueFor(eCSSProperty_text_decoration_color);
|
|
|
|
const nsCSSValue *decorationStyle =
|
|
|
|
data->ValueFor(eCSSProperty_text_decoration_style);
|
2011-04-23 09:16:41 +04:00
|
|
|
|
2013-07-25 10:02:15 +04:00
|
|
|
NS_ABORT_IF_FALSE(decorationStyle->GetUnit() == eCSSUnit_Enumerated,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad text-decoration-style unit %d",
|
2013-07-25 10:02:15 +04:00
|
|
|
decorationStyle->GetUnit()).get());
|
2011-04-23 09:16:41 +04:00
|
|
|
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_text_decoration_line, aValue,
|
|
|
|
aSerialization);
|
2014-11-18 13:23:09 +03:00
|
|
|
if (decorationStyle->GetIntValue() !=
|
|
|
|
NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
AppendValueToString(eCSSProperty_text_decoration_style, aValue,
|
|
|
|
aSerialization);
|
|
|
|
}
|
|
|
|
if (decorationColor->GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
decorationColor->GetIntValue() != NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR) {
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
AppendValueToString(eCSSProperty_text_decoration_color, aValue,
|
|
|
|
aSerialization);
|
|
|
|
}
|
2011-04-23 09:16:41 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-08-21 01:52:47 +04:00
|
|
|
case eCSSProperty_transition: {
|
2013-07-25 10:02:15 +04: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 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-duration unit %d",
|
2013-07-25 10:02:15 +04:00
|
|
|
transDuration->GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transTiming->GetUnit() == eCSSUnit_List ||
|
|
|
|
transTiming->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-timing unit %d",
|
2013-07-25 10:02:15 +04:00
|
|
|
transTiming->GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transDelay->GetUnit() == eCSSUnit_List ||
|
|
|
|
transDelay->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-delay unit %d",
|
2013-07-25 10:02:15 +04:00
|
|
|
transDelay->GetUnit()).get());
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2013-07-25 10:02:15 +04:00
|
|
|
const nsCSSValueList* dur = transDuration->GetListValue();
|
|
|
|
const nsCSSValueList* tim = transTiming->GetListValue();
|
|
|
|
const nsCSSValueList* del = transDelay->GetListValue();
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2013-07-25 10:02:15 +04:00
|
|
|
if (transProp->GetUnit() == eCSSUnit_None ||
|
|
|
|
transProp->GetUnit() == eCSSUnit_All) {
|
2010-08-19 23:33:44 +04: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-16 03:35:49 +04:00
|
|
|
transProp->AppendToString(eCSSProperty_transition_property, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay, aValue,
|
|
|
|
aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
} else {
|
|
|
|
aValue.Truncate();
|
2009-08-21 01:52:47 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
} else {
|
2013-07-25 10:02:15 +04:00
|
|
|
NS_ABORT_IF_FALSE(transProp->GetUnit() == eCSSUnit_List ||
|
|
|
|
transProp->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad t-prop unit %d",
|
2013-07-25 10:02:15 +04:00
|
|
|
transProp->GetUnit()).get());
|
|
|
|
const nsCSSValueList* pro = transProp->GetListValue();
|
2010-08-19 23:33:44 +04:00
|
|
|
for (;;) {
|
|
|
|
pro->mValue.AppendToString(eCSSProperty_transition_property,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2010-08-19 23:33:44 +04:00
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay,
|
2013-09-16 03:35:49 +04:00
|
|
|
aValue, aSerialization);
|
2010-08-19 23:33:44 +04: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-21 01:52:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-12 10:18:42 +04:00
|
|
|
case eCSSProperty_animation: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_animation);
|
2014-07-17 05:04:56 +04:00
|
|
|
static const size_t numProps = 8;
|
2011-04-12 10:18:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps] == eCSSProperty_UNKNOWN,
|
|
|
|
"unexpected number of subproperties");
|
|
|
|
const nsCSSValue* values[numProps];
|
|
|
|
const nsCSSValueList* lists[numProps];
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numProps; ++i) {
|
2011-04-12 10:18:42 +04:00
|
|
|
values[i] = data->ValueFor(subprops[i]);
|
|
|
|
NS_ABORT_IF_FALSE(values[i]->GetUnit() == eCSSUnit_List ||
|
|
|
|
values[i]->GetUnit() == eCSSUnit_ListDep,
|
2012-04-24 22:43:00 +04:00
|
|
|
nsPrintfCString("bad a-duration unit %d",
|
2011-04-12 10:18:42 +04:00
|
|
|
values[i]->GetUnit()).get());
|
|
|
|
lists[i] = values[i]->GetListValue();
|
|
|
|
}
|
2009-08-21 01:52:47 +04:00
|
|
|
|
2011-04-12 10:18:42 +04:00
|
|
|
for (;;) {
|
|
|
|
// We must serialize 'animation-name' last in case it has
|
|
|
|
// a value that conflicts with one of the other keyword properties.
|
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps - 1] ==
|
|
|
|
eCSSProperty_animation_name,
|
|
|
|
"animation-name must be last");
|
|
|
|
bool done = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0;;) {
|
2013-09-16 03:35:49 +04:00
|
|
|
lists[i]->mValue.AppendToString(subprops[i], aValue, aSerialization);
|
2011-04-12 10:18:42 +04:00
|
|
|
lists[i] = lists[i]->mNext;
|
|
|
|
if (!lists[i]) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (++i == numProps) {
|
|
|
|
break;
|
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2011-04-12 10:18:42 +04:00
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numProps; ++i) {
|
2011-04-12 10:18:42 +04:00
|
|
|
if (lists[i]) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-12-09 06:16:15 +03:00
|
|
|
case eCSSProperty_marker: {
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &endValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_end);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &midValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_mid);
|
2009-02-06 19:52:13 +03:00
|
|
|
const nsCSSValue &startValue =
|
2010-08-19 23:33:44 +04:00
|
|
|
*data->ValueFor(eCSSProperty_marker_start);
|
2004-12-09 06:16:15 +03:00
|
|
|
if (endValue == midValue && midValue == startValue)
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(eCSSProperty_marker_end, aValue, aSerialization);
|
2004-12-09 06:16:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-08-23 08:18:22 +04:00
|
|
|
case eCSSProperty__moz_columns: {
|
|
|
|
// Two values, column-count and column-width, separated by a space.
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2011-08-23 08:18:22 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-07-07 04:06:23 +04:00
|
|
|
case eCSSProperty_flex: {
|
|
|
|
// flex-grow, flex-shrink, flex-basis, separated by single space
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[2], aValue, aSerialization);
|
2012-07-07 04:06:23 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-12-05 22:57:51 +04: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-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2014-01-04 19:02:17 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[1], aValue, aSerialization);
|
2014-03-21 19:06:12 +04: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 22:57:51 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-03-21 19:06:12 +04: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 17:26:04 +04:00
|
|
|
} else if (!(autoFlowValue.GetUnit() == eCSSUnit_Enumerated &&
|
2014-05-06 13:45:13 +04:00
|
|
|
autoFlowValue.GetIntValue() == NS_STYLE_GRID_AUTO_FLOW_ROW &&
|
2014-03-21 19:06:12 +04:00
|
|
|
autoColumnsValue.GetUnit() == eCSSUnit_Auto &&
|
|
|
|
autoRowsValue.GetUnit() == eCSSUnit_Auto)) {
|
|
|
|
// Not serializable, bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Fall through to eCSSProperty_grid_template
|
|
|
|
}
|
2014-03-21 19:06:12 +04: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 15:31:00 +04: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 19:06:12 +04: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 15:31:00 +04: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 19:06:12 +04: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 19:06:16 +04:00
|
|
|
if ((nRowItems - 1) / 2 != areas->NRows()) {
|
2014-03-21 19:06:12 +04: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>
|
2014-05-22 07:48:51 +04:00
|
|
|
aValue.Append('(');
|
2014-03-21 19:06:12 +04:00
|
|
|
rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
|
|
|
|
aValue, aSerialization);
|
2014-05-22 07:48:51 +04:00
|
|
|
aValue.Append(')');
|
2014-03-21 19:06:12 +04:00
|
|
|
|
|
|
|
} else {
|
2014-03-21 19:06:16 +04:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(areas->mTemplates[row++], aValue);
|
2014-03-21 19:06:12 +04:00
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
|
|
|
|
// <track-size>
|
|
|
|
rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
|
|
|
|
aValue, aSerialization);
|
2014-03-31 15:31:00 +04: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 19:06:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rowsItem = rowsItem->mNext;
|
|
|
|
if (!rowsItem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addSpaceSeparator) {
|
|
|
|
aValue.Append(char16_t(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-09-18 22:37:14 +04: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-16 03:35:49 +04:00
|
|
|
AppendValueToString(subprops[0], aValue, aSerialization);
|
2012-09-18 22:37:14 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-10-03 22:49:20 +04: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;
|
1998-10-08 05:31:58 +04:00
|
|
|
default:
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "no other shorthands");
|
1998-10-08 05:31:58 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-09-30 05:08:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValueIsImportant(const nsAString& aProperty) const
|
1998-11-06 03:56:28 +03:00
|
|
|
{
|
2014-03-07 21:14:23 +04:00
|
|
|
nsCSSProperty propID =
|
|
|
|
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eIgnoreEnabledState);
|
2010-10-18 06:36:26 +04:00
|
|
|
if (propID == eCSSProperty_UNKNOWN) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-18 06:36:26 +04:00
|
|
|
}
|
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-12 06:09:40 +04:00
|
|
|
if (propID == eCSSPropertyExtra_variable) {
|
2014-04-02 07:32:16 +04: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-12 06:09:40 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
return GetValueIsImportant(propID);
|
1998-11-06 03:56:28 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::GetValueIsImportant(nsCSSProperty aProperty) const
|
1998-07-15 02:34:27 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
if (!mImportantData)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-07-15 02:34:27 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
// Calling ValueFor is inefficient, but we can assume '!important' is rare.
|
2008-10-08 02:10:20 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return mImportantData->ValueFor(aProperty) != nullptr;
|
2008-10-08 02:10:20 +04:00
|
|
|
}
|
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
|
|
|
if (*p == eCSSProperty__x_system_font) {
|
|
|
|
// The system_font subproperty doesn't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!mImportantData->ValueFor(*p)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2002-05-21 12:16:42 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-05-21 12:16:42 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 12:08:30 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAutoString& aValue,
|
|
|
|
nsAString& aResult) const
|
2001-10-24 12:08:30 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
|
|
|
|
"property enum out of range");
|
|
|
|
NS_ABORT_IF_FALSE((aProperty < eCSSProperty_COUNT_no_shorthands) ==
|
|
|
|
aValue.IsEmpty(),
|
|
|
|
"aValue should be given for shorthands but not longhands");
|
2008-12-23 17:06:57 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), aResult);
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AppendLiteral(": ");
|
2008-12-23 17:06:57 +03:00
|
|
|
if (aValue.IsEmpty())
|
2013-09-16 03:35:49 +04:00
|
|
|
AppendValueToString(aProperty, aResult, nsCSSValue::eNormalized);
|
2008-12-23 17:06:57 +03:00
|
|
|
else
|
|
|
|
aResult.Append(aValue);
|
2010-08-19 23:33:44 +04:00
|
|
|
if (GetValueIsImportant(aProperty)) {
|
|
|
|
aResult.AppendLiteral(" ! important");
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AppendLiteral("; ");
|
2001-10-24 12:08:30 +04:00
|
|
|
}
|
|
|
|
|
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-12 06:09:40 +04:00
|
|
|
void
|
|
|
|
Declaration::AppendVariableAndValueToString(const nsAString& aName,
|
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
2014-04-02 07:32:16 +04: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-12 06:09:40 +04: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-12 06:09:47 +04: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-12 06:09:40 +04:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unexpected variable value type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (important) {
|
|
|
|
aResult.AppendLiteral("! important");
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral("; ");
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::ToString(nsAString& aString) const
|
1998-07-15 02:34:27 +04:00
|
|
|
{
|
2010-08-03 02:40:35 +04:00
|
|
|
// Someone cares about this declaration's contents, so don't let it
|
|
|
|
// change from under them. See e.g. bug 338679.
|
|
|
|
SetImmutable();
|
|
|
|
|
2009-02-06 19:52:12 +03:00
|
|
|
nsCSSCompressedDataBlock *systemFontData =
|
|
|
|
GetValueIsImportant(eCSSProperty__x_system_font) ? mImportantData : mData;
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *systemFont =
|
|
|
|
systemFontData->ValueFor(eCSSProperty__x_system_font);
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool haveSystemFont = systemFont &&
|
2009-02-06 19:52:12 +03:00
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didSystemFont = false;
|
2009-02-06 19:52:12 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = mOrder.Length();
|
|
|
|
int32_t index;
|
2008-12-23 17:06:57 +03:00
|
|
|
nsAutoTArray<nsCSSProperty, 16> shorthandsUsed;
|
2003-06-08 02:14:42 +04:00
|
|
|
for (index = 0; index < count; index++) {
|
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-12 06:09:40 +04:00
|
|
|
nsCSSProperty property = GetPropertyAt(index);
|
|
|
|
|
|
|
|
if (property == eCSSPropertyExtra_variable) {
|
|
|
|
uint32_t variableIndex = mOrder[index] - eCSSProperty_COUNT;
|
|
|
|
AppendVariableAndValueToString(mVariableOrder[variableIndex], aString);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:01:41 +04:00
|
|
|
if (!nsCSSProps::IsEnabled(property)) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doneProperty = false;
|
2008-12-23 17:06:57 +03:00
|
|
|
|
|
|
|
// If we already used this property in a shorthand, skip it.
|
|
|
|
if (shorthandsUsed.Length() > 0) {
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
if (shorthandsUsed.Contains(*shorthands)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2008-12-23 17:06:57 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
// Try to use this property in a shorthand.
|
|
|
|
nsAutoString value;
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
// ShorthandsContaining returns the shorthands in order from those
|
|
|
|
// that contain the most subproperties to those that contain the
|
|
|
|
// least, which is exactly the order we want to test them.
|
|
|
|
nsCSSProperty shorthand = *shorthands;
|
|
|
|
|
2014-08-20 11:54:25 +04:00
|
|
|
GetValue(shorthand, value);
|
|
|
|
|
|
|
|
// in the system font case, skip over font-variant shorthand, since all
|
|
|
|
// subproperties are already dealt with via the font shorthand
|
|
|
|
if (shorthand == eCSSProperty_font_variant &&
|
|
|
|
value.EqualsLiteral("-moz-use-system-font")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-12-23 17:06:57 +03:00
|
|
|
// If GetValue gives us a non-empty string back, we can use that
|
|
|
|
// value; otherwise it's not possible to use this shorthand.
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
AppendPropertyAndValueToString(shorthand, value, aString);
|
|
|
|
shorthandsUsed.AppendElement(shorthand);
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2003-06-08 02:14:42 +04:00
|
|
|
break;
|
2008-12-23 17:06:57 +03:00
|
|
|
}
|
2009-02-06 19:52:12 +03:00
|
|
|
|
2009-02-20 00:55:48 +03:00
|
|
|
if (shorthand == eCSSProperty_font) {
|
|
|
|
if (haveSystemFont && !didSystemFont) {
|
2009-02-06 19:52:12 +03:00
|
|
|
// Output the shorthand font declaration that we will
|
|
|
|
// partially override later. But don't add it to
|
|
|
|
// |shorthandsUsed|, since we will have to override it.
|
2013-09-16 03:35:49 +04:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, value,
|
|
|
|
nsCSSValue::eNormalized);
|
2009-02-06 19:52:12 +03:00
|
|
|
AppendPropertyAndValueToString(eCSSProperty_font, value, aString);
|
|
|
|
value.Truncate();
|
2011-10-17 18:59:28 +04:00
|
|
|
didSystemFont = true;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// That we output the system font is enough for this property if:
|
2009-02-20 00:55:48 +03:00
|
|
|
// (1) it's the hidden system font subproperty (which either
|
|
|
|
// means we output it or we don't have it), or
|
2009-02-06 19:52:12 +03:00
|
|
|
// (2) its value is the hidden system font value and it matches
|
2009-02-20 00:55:48 +03:00
|
|
|
// the hidden system font subproperty in importance, and
|
|
|
|
// we output the system font subproperty.
|
2010-08-19 23:33:44 +04:00
|
|
|
const nsCSSValue *val = systemFontData->ValueFor(property);
|
2009-02-06 19:52:12 +03:00
|
|
|
if (property == eCSSProperty__x_system_font ||
|
2009-02-20 00:55:48 +03:00
|
|
|
(haveSystemFont && val && val->GetUnit() == eCSSUnit_System_Font)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
doneProperty = true;
|
2014-08-20 11:54:25 +04:00
|
|
|
break;
|
2009-02-06 19:52:12 +03:00
|
|
|
}
|
|
|
|
}
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2008-12-23 17:06:57 +03:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2010-08-19 23:33:44 +04:00
|
|
|
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(value.IsEmpty(), "value should be empty now");
|
2008-12-23 17:06:57 +03:00
|
|
|
AppendPropertyAndValueToString(property, value, aString);
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2001-10-24 12:08:30 +04:00
|
|
|
if (! aString.IsEmpty()) {
|
2010-08-19 23:33:44 +04:00
|
|
|
// if the string is not empty, we have trailing whitespace we
|
|
|
|
// should remove
|
2001-10-24 12:08:30 +04:00
|
|
|
aString.Truncate(aString.Length() - 1);
|
|
|
|
}
|
1998-07-15 02:34:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-08-19 23:33:44 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
Declaration::List(FILE* out, int32_t aIndent) const
|
1998-09-10 05:19:26 +04:00
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString str;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
1998-09-10 05:19:26 +04:00
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral("{ ");
|
2007-05-17 01:17:45 +04:00
|
|
|
nsAutoString s;
|
|
|
|
ToString(s);
|
2014-11-27 09:29:44 +03:00
|
|
|
AppendUTF16toUTF8(s, str);
|
|
|
|
str.AppendLiteral("}\n");
|
|
|
|
fprintf_stderr(out, "%s", str.get());
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2012-08-24 08:08:08 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
Declaration::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aReturn.Truncate();
|
2008-01-10 23:13:24 +03:00
|
|
|
if (aIndex < mOrder.Length()) {
|
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-12 06:09:40 +04:00
|
|
|
nsCSSProperty property = GetPropertyAt(aIndex);
|
|
|
|
if (property == eCSSPropertyExtra_variable) {
|
|
|
|
GetCustomPropertyNameAt(aIndex, aReturn);
|
|
|
|
return true;
|
|
|
|
}
|
1998-09-25 04:51:45 +04:00
|
|
|
if (0 <= property) {
|
2003-11-01 13:57:41 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
|
2012-08-24 08:08:08 +04:00
|
|
|
return true;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-24 08:08:08 +04:00
|
|
|
return false;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::InitializeEmpty()
|
1998-09-10 05:19:26 +04:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "already initialized");
|
2003-06-08 02:14:42 +04:00
|
|
|
mData = nsCSSCompressedDataBlock::CreateEmptyBlock();
|
1998-09-10 05:19:26 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2010-07-23 22:00:49 +04:00
|
|
|
Declaration*
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration::EnsureMutable()
|
2009-12-11 19:13:19 +03:00
|
|
|
{
|
2010-08-19 23:33:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(mData, "should only be called when not expanded");
|
2010-07-23 22:00:49 +04:00
|
|
|
if (!IsMutable()) {
|
2010-07-23 22:00:52 +04:00
|
|
|
return new Declaration(*this);
|
2010-07-23 22:00:49 +04:00
|
|
|
} else {
|
|
|
|
return this;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
2010-06-29 02:49:35 +04:00
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
Declaration::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04: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-12 06:09:40 +04:00
|
|
|
if (mVariables) {
|
|
|
|
n += mVariables->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (mImportantVariables) {
|
|
|
|
n += mImportantVariables->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2012-01-03 06:19:14 +04: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-12 06:09:40 +04: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-12 06:09:47 +04: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-12 06:09:40 +04:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unexpected variable value type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Declaration::AddVariableDeclaration(const nsAString& aName,
|
|
|
|
CSSVariableDeclarations::Type aType,
|
|
|
|
const nsString& aValue,
|
2013-12-12 06:09:46 +04: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-12 06:09:40 +04: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-12 06:09:46 +04: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-12 06:09:40 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSVariableDeclarations* variables;
|
|
|
|
if (aIsImportant) {
|
|
|
|
if (mVariables) {
|
|
|
|
mVariables->Remove(aName);
|
|
|
|
}
|
|
|
|
if (!mImportantVariables) {
|
|
|
|
mImportantVariables = new CSSVariableDeclarations;
|
|
|
|
}
|
|
|
|
variables = mImportantVariables;
|
|
|
|
} else {
|
2013-12-12 06:09:46 +04: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-12 06:09:40 +04: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-12 06:09:47 +04: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-12 06:09:40 +04:00
|
|
|
default:
|
2014-03-07 12:53:03 +04: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-12 06:09:40 +04: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-29 02:49:35 +04:00
|
|
|
} // namespace mozilla::css
|
|
|
|
} // namespace mozilla
|