Commit Graph

4 Commits

Author SHA1 Message Date
Cameron McCormack
5ecac4b650 Bug 773296 - Part 22: Expose variables through the nsComputedDOMStyle indexed getter. r=dbaron
This exposes the names of the custom properties on a computed style
object through its indexed property getter, just after all of the
built-in properties.
2013-12-12 13:09:45 +11:00
Cameron McCormack
3fdf3d9eee Bug 773296 - Part 19: Compare style structs even for the same rule node when variables have changed. r=dbaron
This makes updates work correctly when variable values change.
Rather than handling nsStyleVariables with a DO_STRUCT_DIFFERENCE,
we explicitly compare the two nsStyleVariables objects in
nsStyleContext::CalcStyleDifference before looking at the other
style structs.  This is because we need to force those other
style structs to be compared if variable values are changing.
nsStyleVariables::CalcDifference still returns 0, since the change in
variable values themselves doesn't require any updates.
2013-12-12 13:09:45 +11:00
Cameron McCormack
589b3b4774 Bug 773296 - Part 8: Resolve and compute CSS variables. r=dbaron
We add a new class CSSVariableResolver whose job is to take the
inherited computed variables and the specified variable declarations and
to perform cycle removal and resolution of the variables, storing the
result in the CSSVariableValues object on an nsStyleVariables.  We use
CSSVariableResolver in nsRuleNode::ComputeVariablesData.

The variable resolver does this:

  1. Asks the CSSVariableValues and CSSVariableDeclarations objects
     to add their variables to it.
  2. Calls in to a new nsCSSParser function
     EnumerateVariableReferences that informs the resolver which
     other variables a given variable references, and by doing so,
     builds a graph of variable dependencies.
  3. Removes variables involved in cyclic references using Tarjan's
     strongly connected component algorithm, setting those variables
     to have an invalid value.
  4. Calls in to a new nsCSSParser function ResolveVariableValue
     to resolve the remaining valid variables by substituting variable
     references.

We extend nsCSSParser::ParseValueWithVariables to take a callback
function to be invoked when encountering a variable reference.  This
lets EnumerateVariableReferences re-use ParseValueWithVariables.

CSSParserImpl::ResolveValueWithVariableReferences needs different
error handling behaviour from ParseValueWithVariables, so we don't
re-use it.

CSSParserImpl::AppendImpliedEOFCharacters is used to take the
value returned from nsCSSScanner::GetImpliedEOFCharacters while
resolving variable references that were declared using custom
properties that encountered EOF before being closed properly.

The SeparatorRequiredBetweenTokens helper function in nsCSSParser.cpp
implements the serialization rules in CSS Syntax Module Level 3:

https://dvcs.w3.org/hg/csswg/raw-file/3479cdefc59a/css-syntax/Overview.html#serialization
2013-12-12 13:09:41 +11:00
Cameron McCormack
0d9fb33ac3 Bug 773296 - Part 7: Add a field to nsStyleVariables to store computed variable values. r=dbaron
This defines a class CSSVariableValues which is used to store
computed variable values.  We store them a bit differently from
CSSVariableDeclarations -- here we have a hash table of variable names
to integer IDs, and then an array of variables where the array index
is the ID.  This is because later on we'll want a stable order for the
variables to return from DOM APIs.

In addition to the string value of the variable, we store the type
of the first and last token of the variable value.  This information
will be used when resolving entire variable reference containing
values, to determine when to insert "/**/" before and after a resolved
var(blah) token.

We add a CSSVariableValues member to nsStyleVariables.
2013-12-12 13:09:41 +11:00