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 02:09:40 +00:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* CSS Custom Property assignments for a Declaration at a given priority */
|
|
|
|
|
|
|
|
#ifndef mozilla_CSSVariableDeclarations_h
|
|
|
|
#define mozilla_CSSVariableDeclarations_h
|
|
|
|
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
|
2013-12-12 02:09:41 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class CSSVariableResolver;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace mozilla
|
2014-06-19 00:57:51 +00:00
|
|
|
struct nsRuleData;
|
2013-12-12 02:09:41 +00: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 02:09:40 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class CSSVariableDeclarations
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSVariableDeclarations();
|
|
|
|
CSSVariableDeclarations(const CSSVariableDeclarations& aOther);
|
|
|
|
#ifdef DEBUG
|
|
|
|
~CSSVariableDeclarations();
|
|
|
|
#endif
|
|
|
|
CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this set of variable declarations includes a variable
|
|
|
|
* with a given name.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name).
|
|
|
|
*/
|
|
|
|
bool Has(const nsAString& aName) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the type of a variable value.
|
|
|
|
*/
|
|
|
|
enum Type {
|
|
|
|
eTokenStream, // a stream of CSS tokens (the usual type for variables)
|
|
|
|
eInitial, // 'initial'
|
2013-12-12 02:09:47 +00:00
|
|
|
eInherit, // 'inherit'
|
|
|
|
eUnset // 'unset'
|
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 02:09:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of a variable in this set of variable declarations.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name).
|
|
|
|
* @param aType Out parameter into which the type of the variable value will
|
|
|
|
* be stored.
|
|
|
|
* @param aValue Out parameter into which the value of the variable will
|
2013-12-12 02:09:47 +00:00
|
|
|
* be stored. If the variable is 'initial', 'inherit' or 'unset', this will
|
|
|
|
* be the empty string.
|
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 02:09:40 +00:00
|
|
|
* @return Whether a variable with the given name was found. When false
|
|
|
|
* is returned, aType and aValue will not be modified.
|
|
|
|
*/
|
|
|
|
bool Get(const nsAString& aName, Type& aType, nsString& aValue) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds or modifies an existing entry in this set of variable declarations
|
|
|
|
* to have the value 'initial'.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name) whose value is to be set.
|
|
|
|
*/
|
|
|
|
void PutInitial(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds or modifies an existing entry in this set of variable declarations
|
|
|
|
* to have the value 'inherit'.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name) whose value is to be set.
|
|
|
|
*/
|
|
|
|
void PutInherit(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds or modifies an existing entry in this set of variable declarations
|
2013-12-12 02:09:47 +00:00
|
|
|
* to have the value 'unset'.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
2013-12-12 02:09:47 +00:00
|
|
|
* be part of the custom property name) whose value is to be set.
|
|
|
|
*/
|
|
|
|
void PutUnset(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds or modifies an existing entry in this set of variable declarations
|
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 02:09:40 +00:00
|
|
|
* to have a token stream value.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name) whose value is to be set.
|
|
|
|
* @param aTokenStream The CSS token stream.
|
|
|
|
*/
|
|
|
|
void PutTokenStream(const nsAString& aName, const nsString& aTokenStream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an entry in this set of variable declarations.
|
|
|
|
*
|
2014-04-02 03:32:16 +00:00
|
|
|
* @param aName The variable name (not including any "--" prefix that would
|
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 02:09:40 +00:00
|
|
|
* be part of the custom property name) whose entry is to be removed.
|
|
|
|
*/
|
|
|
|
void Remove(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of entries in this set of variable declarations.
|
|
|
|
*/
|
|
|
|
uint32_t Count() const { return mVariables.Count(); }
|
|
|
|
|
2013-12-12 02:09:41 +00:00
|
|
|
/**
|
|
|
|
* Copies each variable value from this object into aRuleData, unless that
|
|
|
|
* variable already exists on aRuleData.
|
|
|
|
*/
|
|
|
|
void MapRuleInfoInto(nsRuleData* aRuleData);
|
|
|
|
|
2013-12-12 02:09:41 +00:00
|
|
|
/**
|
|
|
|
* Copies the variables from this object into aResolver, marking them as
|
|
|
|
* specified values.
|
|
|
|
*/
|
|
|
|
void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
|
|
|
|
|
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 02:09:40 +00:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Adds all the variable declarations from aOther into this object.
|
|
|
|
*/
|
|
|
|
void CopyVariablesFrom(const CSSVariableDeclarations& aOther);
|
|
|
|
|
|
|
|
nsDataHashtable<nsStringHashKey, nsString> mVariables;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|