Bug 773296 - Part 5: Map variables on a Declaration to nsRuleData. r=dbaron

This adds a CSSVariableDeclarations object to nsRuleData and adds a
MapRuleInfoInto function to CSSVariableDeclarations so the can copy
variable declarations into a nsRuleData's object.  We call that from
Declaration::Map{Normal,Important}RuleInfoInto.

We make HasImportantData return true if we have important variables
but no important non-custom properties on a declaration, since that
is used to determine whether we have a rule node for important
declarations.  This means MapImportantRuleInfoInto can no longer
assume that mImportantData is non-null.
This commit is contained in:
Cameron McCormack 2013-12-12 13:09:41 +11:00
parent 82a5ba3c0f
commit ebbf01d9ce
4 changed files with 66 additions and 3 deletions

View File

@ -3,8 +3,12 @@
* 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 */
#include "CSSVariableDeclarations.h"
#include "nsRuleData.h"
// These two special string values are used to represent specified values of
// 'initial' and 'inherit'. (Note that neither is a valid variable value.)
#define INITIAL_VALUE "!"
@ -33,6 +37,10 @@ CSSVariableDeclarations::~CSSVariableDeclarations()
CSSVariableDeclarations&
CSSVariableDeclarations::operator=(const CSSVariableDeclarations& aOther)
{
if (this == &aOther) {
return *this;
}
mVariables.Clear();
CopyVariablesFrom(aOther);
return *this;
@ -110,6 +118,35 @@ CSSVariableDeclarations::Remove(const nsAString& aName)
mVariables.Remove(aName);
}
/* static */ PLDHashOperator
CSSVariableDeclarations::EnumerateVariableForMapRuleInfoInto(
const nsAString& aName,
nsString aValue,
void* aData)
{
nsDataHashtable<nsStringHashKey, nsString>* variables =
static_cast<nsDataHashtable<nsStringHashKey, nsString>*>(aData);
if (!variables->Contains(aName)) {
variables->Put(aName, aValue);
}
return PL_DHASH_NEXT;
}
void
CSSVariableDeclarations::MapRuleInfoInto(nsRuleData* aRuleData)
{
if (!(aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Variables))) {
return;
}
if (!aRuleData->mVariables) {
aRuleData->mVariables = new CSSVariableDeclarations(*this);
} else {
mVariables.EnumerateRead(EnumerateVariableForMapRuleInfoInto,
aRuleData->mVariables.get());
}
}
static size_t
SizeOfTableEntry(const nsAString& aKey,
const nsString& aValue,

View File

@ -10,6 +10,8 @@
#include "nsDataHashtable.h"
class nsRuleData;
namespace mozilla {
class CSSVariableDeclarations
@ -96,6 +98,12 @@ public:
*/
uint32_t Count() const { return mVariables.Count(); }
/**
* Copies each variable value from this object into aRuleData, unless that
* variable already exists on aRuleData.
*/
void MapRuleInfoInto(nsRuleData* aRuleData);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
private:
@ -106,6 +114,10 @@ private:
static PLDHashOperator EnumerateVariableForCopy(const nsAString& aName,
nsString aValue,
void* aData);
static PLDHashOperator
EnumerateVariableForMapRuleInfoInto(const nsAString& aName,
nsString aValue,
void* aData);
nsDataHashtable<nsStringHashKey, nsString> mVariables;
};

View File

@ -64,7 +64,9 @@ public:
void GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
bool HasImportantData() const { return mImportantData != nullptr; }
bool HasImportantData() const {
return mImportantData || mImportantVariables;
}
bool GetValueIsImportant(nsCSSProperty aProperty) const;
bool GetValueIsImportant(const nsAString& aProperty) const;
@ -166,11 +168,20 @@ public:
void MapNormalRuleInfoInto(nsRuleData *aRuleData) const {
NS_ABORT_IF_FALSE(mData, "called while expanded");
mData->MapRuleInfoInto(aRuleData);
if (mVariables) {
mVariables->MapRuleInfoInto(aRuleData);
}
}
void MapImportantRuleInfoInto(nsRuleData *aRuleData) const {
NS_ABORT_IF_FALSE(mData, "called while expanded");
NS_ABORT_IF_FALSE(mImportantData, "must have important data");
mImportantData->MapRuleInfoInto(aRuleData);
NS_ABORT_IF_FALSE(mImportantData || mImportantVariables,
"must have important data or variables");
if (mImportantData) {
mImportantData->MapRuleInfoInto(aRuleData);
}
if (mImportantVariables) {
mImportantVariables->MapRuleInfoInto(aRuleData);
}
}
/**

View File

@ -11,6 +11,7 @@
#ifndef nsRuleData_h_
#define nsRuleData_h_
#include "mozilla/CSSVariableDeclarations.h"
#include "nsCSSProps.h"
#include "nsCSSValue.h"
#include "nsStyleStructFwd.h"
@ -44,6 +45,8 @@ struct nsRuleData
nsCSSValue* const mValueStorage; // our user owns this array
size_t mValueOffsets[nsStyleStructID_Length];
nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables;
nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage,
nsPresContext* aContext, nsStyleContext* aStyleContext);