Bug 773296 - Part 4: Add style struct to store CSS variables. r=dbaron

This adds an nsStyleVariables on which computed variable values
will be stored.  We don't actually have any properties assigned to
nsStyleVariables; eCSSPropertyExtra_Variables which we added earlier
isn't a real property.  To avoid compiler errors for gVariableFlags
being a zero length array, we stick a dummy entry in there.

nsRuleNode::ComputeVariablesData does nothing for the moment.

nsStyleVariable nsChangeHint calculations always return 0, as later
we will compare the actual properties that reference variables to
see what changes are required for them.
This commit is contained in:
Cameron McCormack 2013-12-12 13:09:40 +11:00
parent 52ae26eb58
commit 8a80d29205
8 changed files with 115 additions and 16 deletions

View File

@ -52,6 +52,7 @@ STYLE_STRUCTS = [("INHERITED",) + x for x in [
("UserInterface", "nullptr"),
("TableBorder", "nullptr"),
("SVG", "nullptr"),
("Variables", "nullptr"),
]] + [("RESET",) + x for x in [
# Reset style structs.
("Background", "nullptr"),

View File

@ -124,6 +124,7 @@
#define CSS_PROP_COLUMN(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, Column, stylestructoffset_, animtype_)
#define CSS_PROP_SVG(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, SVG, stylestructoffset_, animtype_)
#define CSS_PROP_SVGRESET(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, SVGReset, stylestructoffset_, animtype_)
#define CSS_PROP_VARIABLES(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, Variables, stylestructoffset_, animtype_)
// For properties that are stored in the CSS backend but are not
// computed. An includer may define this in addition to CSS_PROP, but
@ -231,6 +232,10 @@
#define CSS_PROP_SVGRESET(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) /* nothing */
#define DEFINED_CSS_PROP_SVGRESET
#endif
#ifndef CSS_PROP_VARIABLES
#define CSS_PROP_VARIABLES(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) /* nothing */
#define DEFINED_CSS_PROP_VARIABLES
#endif
#ifndef CSS_PROP_BACKENDONLY
#define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_) /* nothing */
@ -3805,6 +3810,7 @@ CSS_PROP_FONT(
#undef CSS_PROP_COLUMN
#undef CSS_PROP_SVG
#undef CSS_PROP_SVGRESET
#undef CSS_PROP_VARIABLES
#ifdef DEFINED_CSS_PROP_BACKENDONLY
#undef CSS_PROP_BACKENDONLY
#undef DEFINED_CSS_PROP_BACKENDONLY
@ -3904,6 +3910,10 @@ CSS_PROP_FONT(
#undef CSS_PROP_SVGRESET
#undef DEFINED_CSS_PROP_SVGRESET
#endif
#ifdef DEFINED_CSS_PROP_VARIABLES
#undef CSS_PROP_VARIABLES
#undef DEFINED_CSS_PROP_VARIABLES
#endif
#ifdef DEFINED_CSS_PROP_BACKENDONLY
#undef CSS_PROP_BACKENDONLY
#undef DEFINED_CSS_PROP_BACKENDONLY

View File

@ -2727,6 +2727,13 @@ enum ColumnCheckCounter {
ePropertyCount_for_Column
};
enum VariablesCheckCounter {
#define CSS_PROP_VARIABLES ENUM_DATA_FOR_PROPERTY
#include "nsCSSPropList.h"
#undef CSS_PROP_VARIABLES
ePropertyCount_for_Variables
};
#undef ENUM_DATA_FOR_PROPERTY
/* static */ const size_t

View File

@ -1807,6 +1807,18 @@ static const uint32_t gColumnFlags[] = {
#undef CSS_PROP_COLUMN
};
// There are no properties in nsStyleVariables, but we can't have a
// zero length array.
static const uint32_t gVariablesFlags[] = {
0,
#define CSS_PROP_VARIABLES FLAG_DATA_FOR_PROPERTY
#include "nsCSSPropList.h"
#undef CSS_PROP_VARIABLES
};
static_assert(sizeof(gVariablesFlags) == sizeof(uint32_t),
"if nsStyleVariables has properties now you can remove the dummy "
"gVariablesFlags entry");
#undef FLAG_DATA_FOR_PROPERTY
static const uint32_t* gFlagsByStruct[] = {
@ -2301,34 +2313,36 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex
aContext->SetStyle(eStyleStruct_UIReset, ui);
return ui;
}
case eStyleStruct_XUL:
{
nsStyleXUL* xul = new (mPresContext) nsStyleXUL();
aContext->SetStyle(eStyleStruct_XUL, xul);
return xul;
}
case eStyleStruct_Column:
{
nsStyleColumn* column = new (mPresContext) nsStyleColumn(mPresContext);
aContext->SetStyle(eStyleStruct_Column, column);
return column;
}
case eStyleStruct_SVG:
{
nsStyleSVG* svg = new (mPresContext) nsStyleSVG();
aContext->SetStyle(eStyleStruct_SVG, svg);
return svg;
}
case eStyleStruct_SVGReset:
{
nsStyleSVGReset* svgReset = new (mPresContext) nsStyleSVGReset();
aContext->SetStyle(eStyleStruct_SVGReset, svgReset);
return svgReset;
}
case eStyleStruct_Variables:
{
nsStyleVariables* vars = new (mPresContext) nsStyleVariables();
aContext->SetStyle(eStyleStruct_Variables, vars);
return vars;
}
default:
/*
* unhandled case: nsStyleStructID_Length.
@ -8271,6 +8285,21 @@ nsRuleNode::ComputeSVGResetData(void* aStartStruct,
COMPUTE_END_RESET(SVGReset, svgReset)
}
const void*
nsRuleNode::ComputeVariablesData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
nsRuleNode* aHighestNode,
const RuleDetail aRuleDetail,
const bool aCanStoreInRuleTree)
{
COMPUTE_START_INHERITED(Variables, (), variables, parentVariables)
// ...
COMPUTE_END_INHERITED(Variables, variables)
}
const void*
nsRuleNode::GetStyleData(nsStyleStructID aSID,
nsStyleContext* aContext,

View File

@ -588,6 +588,13 @@ protected:
RuleDetail aRuleDetail,
const bool aCanStoreInRuleTree);
const void*
ComputeVariablesData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext, nsRuleNode* aHighestNode,
RuleDetail aRuleDetail,
const bool aCanStoreInRuleTree);
// helpers for |ComputeFontData| that need access to |mNoneBits|:
static void SetFontSize(nsPresContext* aPresContext,
const nsRuleData* aRuleData,

View File

@ -490,6 +490,7 @@ nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
DO_STRUCT_DIFFERENCE(TextReset);
DO_STRUCT_DIFFERENCE(Background);
DO_STRUCT_DIFFERENCE(Color);
DO_STRUCT_DIFFERENCE(Variables);
#undef DO_STRUCT_DIFFERENCE

View File

@ -3222,3 +3222,28 @@ nsChangeHint nsStyleUIReset::CalcDifference(const nsStyleUIReset& aOther) const
return NS_STYLE_HINT_VISUAL;
return NS_STYLE_HINT_NONE;
}
//-----------------------
// nsStyleVariables
//
nsStyleVariables::nsStyleVariables()
{
MOZ_COUNT_CTOR(nsStyleVariables);
}
nsStyleVariables::nsStyleVariables(const nsStyleVariables& aSource)
{
MOZ_COUNT_CTOR(nsStyleVariables);
}
nsStyleVariables::~nsStyleVariables(void)
{
MOZ_COUNT_DTOR(nsStyleVariables);
}
nsChangeHint
nsStyleVariables::CalcDifference(const nsStyleVariables& aOther) const
{
return nsChangeHint(0);
}

View File

@ -40,27 +40,27 @@ class imgIContainer;
// Bits for each struct.
// NS_STYLE_INHERIT_BIT defined in nsStyleStructFwd.h
#define NS_STYLE_INHERIT_MASK 0x007fffff
#define NS_STYLE_INHERIT_MASK 0x000ffffff
// Additional bits for nsStyleContext's mBits:
// See nsStyleContext::HasTextDecorationLines
#define NS_STYLE_HAS_TEXT_DECORATION_LINES 0x00800000
#define NS_STYLE_HAS_TEXT_DECORATION_LINES 0x001000000
// See nsStyleContext::HasPseudoElementData.
#define NS_STYLE_HAS_PSEUDO_ELEMENT_DATA 0x01000000
#define NS_STYLE_HAS_PSEUDO_ELEMENT_DATA 0x002000000
// See nsStyleContext::RelevantLinkIsVisited
#define NS_STYLE_RELEVANT_LINK_VISITED 0x02000000
#define NS_STYLE_RELEVANT_LINK_VISITED 0x004000000
// See nsStyleContext::IsStyleIfVisited
#define NS_STYLE_IS_STYLE_IF_VISITED 0x04000000
#define NS_STYLE_IS_STYLE_IF_VISITED 0x008000000
// See nsStyleContext::GetPseudoEnum
#define NS_STYLE_CONTEXT_TYPE_MASK 0xf8000000
#define NS_STYLE_CONTEXT_TYPE_SHIFT 27
#define NS_STYLE_CONTEXT_TYPE_MASK 0x1f0000000
#define NS_STYLE_CONTEXT_TYPE_SHIFT 28
// Additional bits for nsRuleNode's mDependentBits:
#define NS_RULE_NODE_GC_MARK 0x02000000
#define NS_RULE_NODE_USED_DIRECTLY 0x04000000
#define NS_RULE_NODE_IS_IMPORTANT 0x08000000
#define NS_RULE_NODE_LEVEL_MASK 0xf0000000
#define NS_RULE_NODE_LEVEL_SHIFT 28
#define NS_RULE_NODE_GC_MARK 0x02000000
#define NS_RULE_NODE_USED_DIRECTLY 0x04000000
#define NS_RULE_NODE_IS_IMPORTANT 0x08000000
#define NS_RULE_NODE_LEVEL_MASK 0xf0000000
#define NS_RULE_NODE_LEVEL_SHIFT 28
// The lifetime of these objects is managed by the presshell's arena.
@ -2502,4 +2502,23 @@ struct nsStyleSVGReset {
uint8_t mMaskType; // [reset] see nsStyleConsts.h
};
struct nsStyleVariables {
nsStyleVariables();
nsStyleVariables(const nsStyleVariables& aSource);
~nsStyleVariables();
void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
return aContext->AllocateFromShell(sz);
}
void Destroy(nsPresContext* aContext) {
this->~nsStyleVariables();
aContext->FreeToShell(sizeof(nsStyleVariables), this);
}
nsChangeHint CalcDifference(const nsStyleVariables& aOther) const;
static nsChangeHint MaxDifference() {
return nsChangeHint(0);
}
};
#endif /* nsStyleStruct_h___ */