2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
#ifndef mozilla_css_Declaration_h
|
|
|
|
#define mozilla_css_Declaration_h
|
|
|
|
|
|
|
|
// This header is in EXPORTS because it's used in several places in content/,
|
|
|
|
// but it's not really a public interface.
|
2013-03-15 21:31:38 -07:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
#error "This file should only be included within libxul"
|
2010-06-28 15:49:35 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "CSSVariableDeclarations.h"
|
2010-08-19 12:33:44 -07:00
|
|
|
#include "nsCSSDataBlock.h"
|
|
|
|
#include "nsCSSProperty.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSProps.h"
|
2010-08-19 12:33:44 -07:00
|
|
|
#include "nsStringFwd.h"
|
2008-01-10 12:13:24 -08:00
|
|
|
#include "nsTArray.h"
|
2010-08-19 12:33:44 -07:00
|
|
|
#include <stdio.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
// Declaration objects have unusual lifetime rules. Every declaration
|
|
|
|
// begins life in an invalid state which ends when InitializeEmpty or
|
|
|
|
// CompressFrom is called upon it. After that, it can be attached to
|
|
|
|
// exactly one style rule, and will be destroyed when that style rule
|
|
|
|
// is destroyed. A declaration becomes immutable when its style rule's
|
|
|
|
// |RuleMatched| method is called; after that, it must be copied before
|
|
|
|
// it can be modified, which is taken care of by |EnsureMutable|.
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
class Declaration {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
/**
|
2010-06-28 15:49:35 -07:00
|
|
|
* Construct an |Declaration| that is in an invalid state (null
|
2007-03-22 10:30:00 -07:00
|
|
|
* |mData|) and cannot be used until its |CompressFrom| method or
|
|
|
|
* |InitializeEmpty| method is called.
|
|
|
|
*/
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration(const Declaration& aCopy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
~Declaration();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* |ValueAppended| must be called to maintain this declaration's
|
|
|
|
* |mOrder| whenever a property is parsed into an expanded data block
|
2009-03-05 20:05:01 -08:00
|
|
|
* for this declaration. aProperty must not be a shorthand.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-07-23 11:00:34 -07:00
|
|
|
void ValueAppended(nsCSSProperty aProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void RemoveProperty(nsCSSProperty aProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasProperty(nsCSSProperty aProperty) const;
|
2010-11-24 10:31:52 -08:00
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-11 18:09:41 -08:00
|
|
|
bool HasImportantData() const {
|
|
|
|
return mImportantData || mImportantVariables;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetValueIsImportant(nsCSSProperty aProperty) const;
|
|
|
|
bool GetValueIsImportant(const nsAString& aProperty) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
/**
|
|
|
|
* Adds a custom property declaration to this object.
|
|
|
|
*
|
|
|
|
* @param aName The variable name (i.e., without the "var-" prefix).
|
|
|
|
* @param aType The type of value the variable has.
|
|
|
|
* @param aValue The value of the variable, if aType is
|
|
|
|
* CSSVariableDeclarations::eTokenStream.
|
|
|
|
* @param aIsImportant Whether the declaration is !important.
|
2013-12-11 18:09:46 -08:00
|
|
|
* @param aOverrideImportant When aIsImportant is false, whether an
|
|
|
|
* existing !important declaration will be overridden.
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
*/
|
|
|
|
void AddVariableDeclaration(const nsAString& aName,
|
|
|
|
CSSVariableDeclarations::Type aType,
|
|
|
|
const nsString& aValue,
|
2013-12-11 18:09:46 -08:00
|
|
|
bool aIsImportant,
|
|
|
|
bool aOverrideImportant);
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a custom property declaration from this object.
|
|
|
|
*
|
|
|
|
* @param aName The variable name (i.e., without the "var-" prefix).
|
|
|
|
*/
|
|
|
|
void RemoveVariableDeclaration(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a custom property declaration for a variable with
|
|
|
|
* a given name exists on this object.
|
|
|
|
*
|
|
|
|
* @param aName The variable name (i.e., without the "var-" prefix).
|
|
|
|
*/
|
|
|
|
bool HasVariableDeclaration(const nsAString& aName) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string value for a custom property declaration of a variable
|
|
|
|
* with a given name.
|
|
|
|
*
|
|
|
|
* @param aName The variable name (i.e., without the "var-" prefix).
|
|
|
|
* @param aValue Out parameter into which the variable's value will be
|
|
|
|
* stored. If the value is 'initial' or 'inherit', that exact string
|
|
|
|
* will be stored in aValue.
|
|
|
|
*/
|
|
|
|
void GetVariableDeclaration(const nsAString& aName, nsAString& aValue) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the custom property declaration for a variable with
|
|
|
|
* the given name was !important.
|
|
|
|
*/
|
|
|
|
bool GetVariableValueIsImportant(const nsAString& aName) const;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t Count() const {
|
2010-06-28 15:49:35 -07:00
|
|
|
return mOrder.Length();
|
2008-01-10 12:13:24 -08:00
|
|
|
}
|
2012-08-23 21:08:08 -07:00
|
|
|
|
|
|
|
// Returns whether we actually had a property at aIndex
|
|
|
|
bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void ToString(nsAString& aString) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-11 08:13:20 -08:00
|
|
|
nsCSSCompressedDataBlock* GetNormalBlock() const { return mData; }
|
|
|
|
nsCSSCompressedDataBlock* GetImportantBlock() const { return mImportantData; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2010-07-23 11:00:34 -07:00
|
|
|
* Initialize this declaration as holding no data. Cannot fail.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-07-23 11:00:34 -07:00
|
|
|
void InitializeEmpty();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer all of the state from |aExpandedData| into this declaration.
|
|
|
|
* After calling, |aExpandedData| should be in its initial state.
|
2012-02-19 12:49:34 -08:00
|
|
|
* Callers must make sure mOrder is updated as necessary.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
void CompressFrom(nsCSSExpandedDataBlock *aExpandedData) {
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData, "oops");
|
|
|
|
NS_ABORT_IF_FALSE(!mImportantData, "oops");
|
2010-07-23 11:00:52 -07:00
|
|
|
aExpandedData->Compress(getter_Transfers(mData),
|
|
|
|
getter_Transfers(mImportantData));
|
2009-07-09 14:50:39 -07:00
|
|
|
aExpandedData->AssertInitialState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer all of the state from this declaration into
|
|
|
|
* |aExpandedData| and put this declaration temporarily into an
|
|
|
|
* invalid state (ended by |CompressFrom| or |InitializeEmpty|) that
|
|
|
|
* should last only during parsing. During this time only
|
|
|
|
* |ValueAppended| should be called.
|
|
|
|
*/
|
|
|
|
void ExpandTo(nsCSSExpandedDataBlock *aExpandedData) {
|
2010-07-23 11:00:49 -07:00
|
|
|
AssertMutable();
|
2007-03-22 10:30:00 -07:00
|
|
|
aExpandedData->AssertInitialState();
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(mData, "oops");
|
2010-07-23 11:00:52 -07:00
|
|
|
aExpandedData->Expand(mData.forget(), mImportantData.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do what |nsIStyleRule::MapRuleInfoInto| needs to do for a style
|
|
|
|
* rule using this declaration for storage.
|
|
|
|
*/
|
|
|
|
void MapNormalRuleInfoInto(nsRuleData *aRuleData) const {
|
|
|
|
NS_ABORT_IF_FALSE(mData, "called while expanded");
|
|
|
|
mData->MapRuleInfoInto(aRuleData);
|
2013-12-11 18:09:41 -08:00
|
|
|
if (mVariables) {
|
|
|
|
mVariables->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
2010-07-23 11:00:52 -07:00
|
|
|
}
|
|
|
|
void MapImportantRuleInfoInto(nsRuleData *aRuleData) const {
|
|
|
|
NS_ABORT_IF_FALSE(mData, "called while expanded");
|
2013-12-11 18:09:41 -08:00
|
|
|
NS_ABORT_IF_FALSE(mImportantData || mImportantVariables,
|
|
|
|
"must have important data or variables");
|
|
|
|
if (mImportantData) {
|
|
|
|
mImportantData->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
if (mImportantVariables) {
|
|
|
|
mImportantVariables->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-09 14:50:39 -07:00
|
|
|
/**
|
2010-08-19 12:33:44 -07:00
|
|
|
* Attempt to replace the value for |aProperty| stored in this
|
|
|
|
* declaration with the matching value from |aFromBlock|.
|
|
|
|
* This method may only be called on a mutable declaration.
|
2011-10-17 07:59:28 -07:00
|
|
|
* It will fail (returning false) if |aProperty| is shorthand,
|
2010-08-19 12:33:44 -07:00
|
|
|
* is not already in this declaration, or does not have the indicated
|
2011-10-17 07:59:28 -07:00
|
|
|
* importance level. If it returns true, it erases the value in
|
|
|
|
* |aFromBlock|. |aChanged| is set to true if the declaration
|
|
|
|
* changed as a result of the call, and to false otherwise.
|
2009-07-09 14:50:39 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool TryReplaceValue(nsCSSProperty aProperty, bool aIsImportant,
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSExpandedDataBlock& aFromBlock,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aChanged)
|
2010-08-19 12:33:44 -07:00
|
|
|
{
|
2010-07-23 11:00:49 -07:00
|
|
|
AssertMutable();
|
2010-07-23 11:00:39 -07:00
|
|
|
NS_ABORT_IF_FALSE(mData, "called while expanded");
|
|
|
|
|
2009-07-09 14:50:39 -07:00
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
2009-07-09 14:50:39 -07:00
|
|
|
}
|
2010-07-23 11:00:39 -07:00
|
|
|
nsCSSCompressedDataBlock *block = aIsImportant ? mImportantData : mData;
|
|
|
|
// mImportantData might be null
|
|
|
|
if (!block) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
2010-07-23 11:00:39 -07:00
|
|
|
}
|
2009-07-09 14:50:39 -07:00
|
|
|
|
2010-07-23 11:00:39 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCSSCompressedDataBlock *other = aIsImportant ? mData : mImportantData;
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!other || !other->ValueFor(aProperty) ||
|
|
|
|
!block->ValueFor(aProperty),
|
2010-07-23 11:00:39 -07:00
|
|
|
"Property both important and not?");
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-19 12:33:44 -07:00
|
|
|
return block->TryReplaceValue(aProperty, aFromBlock, aChanged);
|
2009-07-09 14:50:39 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasNonImportantValueFor(nsCSSProperty aProperty) const {
|
2009-12-11 08:13:19 -08:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty), "must be longhand");
|
2010-08-19 12:33:44 -07:00
|
|
|
return !!mData->ValueFor(aProperty);
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
/**
|
|
|
|
* Return whether |this| may be modified.
|
|
|
|
*/
|
|
|
|
bool IsMutable() const {
|
|
|
|
return !mImmutable;
|
|
|
|
}
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
/**
|
2010-07-23 11:00:49 -07:00
|
|
|
* Copy |this|, if necessary to ensure that it can be modified.
|
2009-12-11 08:13:19 -08:00
|
|
|
*/
|
2010-07-23 11:00:49 -07:00
|
|
|
Declaration* EnsureMutable();
|
|
|
|
|
|
|
|
/**
|
2010-07-23 11:00:52 -07:00
|
|
|
* Crash if |this| cannot be modified.
|
2010-07-23 11:00:49 -07:00
|
|
|
*/
|
|
|
|
void AssertMutable() const {
|
|
|
|
NS_ABORT_IF_FALSE(IsMutable(), "someone forgot to call EnsureMutable");
|
|
|
|
}
|
2009-12-11 08:13:19 -08:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
/**
|
2010-08-02 15:40:35 -07:00
|
|
|
* Mark this declaration as unmodifiable. It's 'const' so it can
|
|
|
|
* be called from ToString.
|
2010-07-23 11:00:52 -07:00
|
|
|
*/
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetImmutable() const { mImmutable = true; }
|
2010-07-23 11:00:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Clear the data, in preparation for its replacement with entirely
|
|
|
|
* new data by a call to |CompressFrom|.
|
|
|
|
*/
|
|
|
|
void ClearData() {
|
2010-07-23 11:00:49 -07:00
|
|
|
AssertMutable();
|
2012-07-30 07:20:58 -07:00
|
|
|
mData = nullptr;
|
|
|
|
mImportantData = nullptr;
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mVariables = nullptr;
|
|
|
|
mImportantVariables = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mOrder.Clear();
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
mVariableOrder.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
void List(FILE* out = stdout, int32_t aIndent = 0) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2010-06-28 15:49:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2011-12-16 11:42:07 -08:00
|
|
|
Declaration& operator=(const Declaration& aCopy) MOZ_DELETE;
|
|
|
|
bool operator==(const Declaration& aCopy) const MOZ_DELETE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static void AppendImportanceToString(bool aIsImportant, nsAString& aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
// return whether there was a value in |aValue| (i.e., it had a non-null unit)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AppendValueToString(nsCSSProperty aProperty, nsAString& aResult) const;
|
2008-12-23 06:06:57 -08:00
|
|
|
// Helper for ToString with strange semantics regarding aValue.
|
2010-07-23 11:00:52 -07:00
|
|
|
void AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAutoString& aValue,
|
|
|
|
nsAString& aResult) 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-11 18:09:40 -08:00
|
|
|
// helper for ToString that serializes a custom property declaration for
|
|
|
|
// a variable with the specified name
|
|
|
|
void AppendVariableAndValueToString(const nsAString& aName,
|
|
|
|
nsAString& aResult) const;
|
2010-06-28 15:49:35 -07:00
|
|
|
|
2011-04-22 18:36:23 -07:00
|
|
|
public:
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
/**
|
|
|
|
* Returns the property at the given index in the ordered list of
|
|
|
|
* declarations. For custom properties, eCSSPropertyExtra_variable
|
|
|
|
* is returned.
|
|
|
|
*/
|
|
|
|
nsCSSProperty GetPropertyAt(uint32_t aIndex) const {
|
|
|
|
uint32_t value = mOrder[aIndex];
|
|
|
|
if (value >= eCSSProperty_COUNT) {
|
|
|
|
return eCSSPropertyExtra_variable;
|
|
|
|
}
|
|
|
|
return nsCSSProperty(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the name of the custom property at the given index in the ordered
|
|
|
|
* list of declarations.
|
|
|
|
*/
|
|
|
|
void GetCustomPropertyNameAt(uint32_t aIndex, nsAString& aResult) const {
|
|
|
|
MOZ_ASSERT(mOrder[aIndex] >= eCSSProperty_COUNT);
|
2014-01-01 21:33:57 -08:00
|
|
|
uint32_t variableIndex = mOrder[aIndex] - eCSSProperty_COUNT;
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
aResult.Truncate();
|
|
|
|
aResult.AppendLiteral("var-");
|
2014-01-01 21:33:57 -08:00
|
|
|
aResult.Append(mVariableOrder[variableIndex]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-01-02 18:19:14 -08:00
|
|
|
|
2011-04-22 18:36:23 -07:00
|
|
|
private:
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
// The order of properties in this declaration. Longhand properties are
|
|
|
|
// represented by their nsCSSProperty value, and each custom property (var-*)
|
|
|
|
// is represented by a value that begins at eCSSProperty_COUNT.
|
|
|
|
//
|
|
|
|
// Subtracting eCSSProperty_COUNT from those values that represent custom
|
|
|
|
// properties results in an index into mVariableOrder, which identifies the
|
|
|
|
// specific variable the custom property declaration is for.
|
|
|
|
nsAutoTArray<uint32_t, 8> mOrder;
|
|
|
|
|
|
|
|
// variable names of custom properties found in mOrder
|
|
|
|
nsTArray<nsString> mVariableOrder;
|
2010-07-23 11:00:49 -07:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
// never null, except while expanded, or before the first call to
|
|
|
|
// InitializeEmpty or CompressFrom.
|
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> mData;
|
2009-12-11 08:13:19 -08:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
// may be null
|
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> mImportantData;
|
2009-12-11 08:13:19 -08:00
|
|
|
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-11 18:09:40 -08:00
|
|
|
// may be null
|
|
|
|
nsAutoPtr<CSSVariableDeclarations> mVariables;
|
|
|
|
|
|
|
|
// may be null
|
|
|
|
nsAutoPtr<CSSVariableDeclarations> mImportantVariables;
|
|
|
|
|
2010-08-02 15:40:35 -07:00
|
|
|
// set by style rules when |RuleMatched| is called;
|
|
|
|
// also by ToString (hence the 'mutable').
|
2011-09-28 23:19:26 -07:00
|
|
|
mutable bool mImmutable;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
} // namespace css
|
2010-06-28 15:49:35 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
#endif /* mozilla_css_Declaration_h */
|