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
|
|
|
|
*/
|
|
|
|
|
2010-06-29 02:49:35 +04: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-16 08:31:38 +04:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
#error "This file should only be included within libxul"
|
2010-06-29 02:49:35 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +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
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "CSSVariableDeclarations.h"
|
2010-08-19 23:33:44 +04:00
|
|
|
#include "nsCSSDataBlock.h"
|
|
|
|
#include "nsCSSProperty.h"
|
1999-07-18 04:33:53 +04:00
|
|
|
#include "nsCSSProps.h"
|
2010-08-19 23:33:44 +04:00
|
|
|
#include "nsStringFwd.h"
|
2008-01-10 23:13:24 +03:00
|
|
|
#include "nsTArray.h"
|
2010-08-19 23:33:44 +04:00
|
|
|
#include <stdio.h>
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2010-07-23 22:00:52 +04: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-29 02:49:35 +04:00
|
|
|
class Declaration {
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
2003-06-08 02:14:42 +04:00
|
|
|
/**
|
2010-06-29 02:49:35 +04:00
|
|
|
* Construct an |Declaration| that is in an invalid state (null
|
2003-06-08 02:14:42 +04:00
|
|
|
* |mData|) and cannot be used until its |CompressFrom| method or
|
|
|
|
* |InitializeEmpty| method is called.
|
|
|
|
*/
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration();
|
2000-04-20 17:00:08 +04:00
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
Declaration(const Declaration& aCopy);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
~Declaration();
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
/**
|
|
|
|
* |ValueAppended| must be called to maintain this declaration's
|
|
|
|
* |mOrder| whenever a property is parsed into an expanded data block
|
2009-03-06 07:05:01 +03:00
|
|
|
* for this declaration. aProperty must not be a shorthand.
|
2003-06-08 02:14:42 +04:00
|
|
|
*/
|
2010-07-23 22:00:34 +04:00
|
|
|
void ValueAppended(nsCSSProperty aProperty);
|
1998-06-26 09:51:55 +04:00
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void RemoveProperty(nsCSSProperty aProperty);
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasProperty(nsCSSProperty aProperty) const;
|
2010-11-24 21:31:52 +03:00
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
|
2013-09-16 03:35:49 +04:00
|
|
|
void GetAuthoredValue(nsCSSProperty aProperty, nsAString& aValue) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-12-12 06:09:41 +04:00
|
|
|
bool HasImportantData() const {
|
|
|
|
return mImportantData || mImportantVariables;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetValueIsImportant(nsCSSProperty aProperty) const;
|
|
|
|
bool GetValueIsImportant(const nsAString& aProperty) const;
|
1998-09-25 04:51:45 +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
|
|
|
/**
|
|
|
|
* Adds a custom property declaration to this object.
|
|
|
|
*
|
2014-04-02 07:32:16 +04:00
|
|
|
* @param aName The variable name (i.e., without the "--" prefix).
|
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
|
|
|
* @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-12 06:09:46 +04: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-12 06:09:40 +04:00
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a custom property declaration from this object.
|
|
|
|
*
|
2014-04-02 07:32:16 +04:00
|
|
|
* @param aName The variable name (i.e., without the "--" prefix).
|
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 RemoveVariableDeclaration(const nsAString& aName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a custom property declaration for a variable with
|
|
|
|
* a given name exists on this object.
|
|
|
|
*
|
2014-04-02 07:32:16 +04:00
|
|
|
* @param aName The variable name (i.e., without the "--" prefix).
|
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 HasVariableDeclaration(const nsAString& aName) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string value for a custom property declaration of a variable
|
|
|
|
* with a given name.
|
|
|
|
*
|
2014-04-02 07:32:16 +04:00
|
|
|
* @param aName The variable name (i.e., without the "--" prefix).
|
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
|
|
|
* @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 19:56:38 +04:00
|
|
|
uint32_t Count() const {
|
2010-06-29 02:49:35 +04:00
|
|
|
return mOrder.Length();
|
2008-01-10 23:13:24 +03:00
|
|
|
}
|
2012-08-24 08:08:08 +04:00
|
|
|
|
|
|
|
// Returns whether we actually had a property at aIndex
|
|
|
|
bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
|
1998-06-26 09:51:55 +04:00
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
void ToString(nsAString& aString) const;
|
1998-09-10 05:19:26 +04:00
|
|
|
|
2009-12-11 19:13:20 +03:00
|
|
|
nsCSSCompressedDataBlock* GetNormalBlock() const { return mData; }
|
|
|
|
nsCSSCompressedDataBlock* GetImportantBlock() const { return mImportantData; }
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
/**
|
2010-07-23 22:00:34 +04:00
|
|
|
* Initialize this declaration as holding no data. Cannot fail.
|
2003-06-08 02:14:42 +04:00
|
|
|
*/
|
2010-07-23 22:00:34 +04:00
|
|
|
void InitializeEmpty();
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer all of the state from |aExpandedData| into this declaration.
|
|
|
|
* After calling, |aExpandedData| should be in its initial state.
|
2012-02-20 00:49:34 +04:00
|
|
|
* Callers must make sure mOrder is updated as necessary.
|
2003-06-08 02:14:42 +04:00
|
|
|
*/
|
|
|
|
void CompressFrom(nsCSSExpandedDataBlock *aExpandedData) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mData, "oops");
|
|
|
|
MOZ_ASSERT(!mImportantData, "oops");
|
2010-07-23 22:00:52 +04:00
|
|
|
aExpandedData->Compress(getter_Transfers(mData),
|
2014-12-19 06:32:34 +03:00
|
|
|
getter_Transfers(mImportantData),
|
|
|
|
mOrder);
|
2009-07-10 01:50:39 +04:00
|
|
|
aExpandedData->AssertInitialState();
|
2003-06-08 02:14:42 +04: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 22:00:49 +04:00
|
|
|
AssertMutable();
|
2003-06-08 02:14:42 +04:00
|
|
|
aExpandedData->AssertInitialState();
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mData, "oops");
|
2010-07-23 22:00:52 +04: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 {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mData, "called while expanded");
|
2010-07-23 22:00:52 +04:00
|
|
|
mData->MapRuleInfoInto(aRuleData);
|
2013-12-12 06:09:41 +04:00
|
|
|
if (mVariables) {
|
|
|
|
mVariables->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
2010-07-23 22:00:52 +04:00
|
|
|
}
|
|
|
|
void MapImportantRuleInfoInto(nsRuleData *aRuleData) const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mData, "called while expanded");
|
|
|
|
MOZ_ASSERT(mImportantData || mImportantVariables,
|
|
|
|
"must have important data or variables");
|
2013-12-12 06:09:41 +04:00
|
|
|
if (mImportantData) {
|
|
|
|
mImportantData->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
if (mImportantVariables) {
|
|
|
|
mImportantVariables->MapRuleInfoInto(aRuleData);
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 01:50:39 +04:00
|
|
|
/**
|
2010-08-19 23:33:44 +04: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 18:59:28 +04:00
|
|
|
* It will fail (returning false) if |aProperty| is shorthand,
|
2010-08-19 23:33:44 +04:00
|
|
|
* is not already in this declaration, or does not have the indicated
|
2011-10-17 18:59:28 +04: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-10 01:50:39 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool TryReplaceValue(nsCSSProperty aProperty, bool aIsImportant,
|
2010-08-19 23:33:44 +04:00
|
|
|
nsCSSExpandedDataBlock& aFromBlock,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aChanged)
|
2010-08-19 23:33:44 +04:00
|
|
|
{
|
2010-07-23 22:00:49 +04:00
|
|
|
AssertMutable();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mData, "called while expanded");
|
2010-07-23 22:00:39 +04:00
|
|
|
|
2009-07-10 01:50:39 +04:00
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
2009-07-10 01:50:39 +04:00
|
|
|
}
|
2010-07-23 22:00:39 +04:00
|
|
|
nsCSSCompressedDataBlock *block = aIsImportant ? mImportantData : mData;
|
|
|
|
// mImportantData might be null
|
|
|
|
if (!block) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aChanged = false;
|
|
|
|
return false;
|
2010-07-23 22:00:39 +04:00
|
|
|
}
|
2009-07-10 01:50:39 +04:00
|
|
|
|
2010-07-23 22:00:39 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCSSCompressedDataBlock *other = aIsImportant ? mData : mImportantData;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!other || !other->ValueFor(aProperty) ||
|
|
|
|
!block->ValueFor(aProperty),
|
|
|
|
"Property both important and not?");
|
2010-07-23 22:00:39 +04:00
|
|
|
}
|
|
|
|
#endif
|
2010-08-19 23:33:44 +04:00
|
|
|
return block->TryReplaceValue(aProperty, aFromBlock, aChanged);
|
2009-07-10 01:50:39 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasNonImportantValueFor(nsCSSProperty aProperty) const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty), "must be longhand");
|
2010-08-19 23:33:44 +04:00
|
|
|
return !!mData->ValueFor(aProperty);
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
/**
|
|
|
|
* Return whether |this| may be modified.
|
|
|
|
*/
|
|
|
|
bool IsMutable() const {
|
|
|
|
return !mImmutable;
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
/**
|
2010-07-23 22:00:49 +04:00
|
|
|
* Copy |this|, if necessary to ensure that it can be modified.
|
2009-12-11 19:13:19 +03:00
|
|
|
*/
|
2010-07-23 22:00:49 +04:00
|
|
|
Declaration* EnsureMutable();
|
|
|
|
|
|
|
|
/**
|
2010-07-23 22:00:52 +04:00
|
|
|
* Crash if |this| cannot be modified.
|
2010-07-23 22:00:49 +04:00
|
|
|
*/
|
|
|
|
void AssertMutable() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(IsMutable(), "someone forgot to call EnsureMutable");
|
2010-07-23 22:00:49 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
/**
|
2010-08-03 02:40:35 +04:00
|
|
|
* Mark this declaration as unmodifiable. It's 'const' so it can
|
|
|
|
* be called from ToString.
|
2010-07-23 22:00:52 +04:00
|
|
|
*/
|
2011-10-17 18:59:28 +04:00
|
|
|
void SetImmutable() const { mImmutable = true; }
|
2010-07-23 22:00:52 +04:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
/**
|
|
|
|
* Clear the data, in preparation for its replacement with entirely
|
|
|
|
* new data by a call to |CompressFrom|.
|
|
|
|
*/
|
|
|
|
void ClearData() {
|
2010-07-23 22:00:49 +04:00
|
|
|
AssertMutable();
|
2012-07-30 18:20:58 +04: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-12 06:09:40 +04:00
|
|
|
mVariables = nullptr;
|
|
|
|
mImportantVariables = nullptr;
|
2005-04-29 00:19:24 +04: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-12 06:09:40 +04:00
|
|
|
mVariableOrder.Clear();
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
void List(FILE* out = stdout, int32_t aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2010-06-29 02:49:35 +04:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
Declaration& operator=(const Declaration& aCopy) = delete;
|
|
|
|
bool operator==(const Declaration& aCopy) const = delete;
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2013-09-16 03:35:49 +04:00
|
|
|
void GetValue(nsCSSProperty aProperty, nsAString& aValue,
|
|
|
|
nsCSSValue::Serialization aValueSerialization) const;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static void AppendImportanceToString(bool aIsImportant, nsAString& aString);
|
2003-06-08 02:14:42 +04:00
|
|
|
// return whether there was a value in |aValue| (i.e., it had a non-null unit)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool AppendValueToString(nsCSSProperty aProperty, nsAString& aResult) const;
|
2013-09-16 03:35:49 +04:00
|
|
|
bool AppendValueToString(nsCSSProperty aProperty, nsAString& aResult,
|
|
|
|
nsCSSValue::Serialization aValueSerialization) const;
|
2008-12-23 17:06:57 +03:00
|
|
|
// Helper for ToString with strange semantics regarding aValue.
|
2010-07-23 22:00:52 +04: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-12 06:09:40 +04: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-29 02:49:35 +04:00
|
|
|
|
2011-04-23 05:36:23 +04: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-12 06:09:40 +04: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-02 09:33:57 +04: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-12 06:09:40 +04:00
|
|
|
aResult.Truncate();
|
2014-04-02 07:32:16 +04:00
|
|
|
aResult.AppendLiteral("--");
|
2014-01-02 09:33:57 +04:00
|
|
|
aResult.Append(mVariableOrder[variableIndex]);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-01-03 06:19:14 +04:00
|
|
|
|
2011-04-23 05:36:23 +04: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-12 06:09:40 +04:00
|
|
|
// The order of properties in this declaration. Longhand properties are
|
2014-04-02 07:32:16 +04:00
|
|
|
// represented by their nsCSSProperty value, and each custom property (--*)
|
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
|
|
|
// 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 22:00:49 +04:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
// never null, except while expanded, or before the first call to
|
|
|
|
// InitializeEmpty or CompressFrom.
|
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> mData;
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
// may be null
|
|
|
|
nsAutoPtr<nsCSSCompressedDataBlock> mImportantData;
|
2009-12-11 19:13:19 +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
|
|
|
// may be null
|
|
|
|
nsAutoPtr<CSSVariableDeclarations> mVariables;
|
|
|
|
|
|
|
|
// may be null
|
|
|
|
nsAutoPtr<CSSVariableDeclarations> mImportantVariables;
|
|
|
|
|
2010-08-03 02:40:35 +04:00
|
|
|
// set by style rules when |RuleMatched| is called;
|
|
|
|
// also by ToString (hence the 'mutable').
|
2011-09-29 10:19:26 +04:00
|
|
|
mutable bool mImmutable;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
} // namespace css
|
2010-06-29 02:49:35 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#endif /* mozilla_css_Declaration_h */
|