2003-02-22 00:32:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
#ifndef _nsStyleContext_h_
|
|
|
|
#define _nsStyleContext_h_
|
|
|
|
|
|
|
|
#include "nsRuleNode.h"
|
2009-12-11 07:37:40 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2013-03-03 00:31:48 +00:00
|
|
|
class nsIAtom;
|
2004-07-31 23:15:21 +00:00
|
|
|
class nsPresContext;
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2005-02-04 20:11:00 +00:00
|
|
|
/**
|
|
|
|
* An nsStyleContext represents the computed style data for an element.
|
|
|
|
* The computed style data are stored in a set of structs (see
|
|
|
|
* nsStyleStruct.h) that are cached either on the style context or in
|
|
|
|
* the rule tree (see nsRuleNode.h for a description of this caching and
|
|
|
|
* how the cached structs are shared).
|
|
|
|
*
|
|
|
|
* Since the data in |nsIStyleRule|s and |nsRuleNode|s are immutable
|
|
|
|
* (with a few exceptions, like system color changes), the data in an
|
2005-02-05 05:24:21 +00:00
|
|
|
* nsStyleContext are also immutable (with the additional exception of
|
|
|
|
* GetUniqueStyleData). When style data change,
|
2005-02-04 20:11:00 +00:00
|
|
|
* nsFrameManager::ReResolveStyleContext creates a new style context.
|
2005-02-05 05:24:21 +00:00
|
|
|
*
|
|
|
|
* Style contexts are reference counted. References are generally held
|
|
|
|
* by:
|
|
|
|
* 1. the |nsIFrame|s that are using the style context and
|
|
|
|
* 2. any *child* style contexts (this might be the reverse of
|
|
|
|
* expectation, but it makes sense in this case)
|
|
|
|
* Style contexts participate in the mark phase of rule node garbage
|
|
|
|
* collection.
|
2005-02-04 20:11:00 +00:00
|
|
|
*/
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
class nsStyleContext
|
|
|
|
{
|
|
|
|
public:
|
2012-09-18 18:37:13 +00:00
|
|
|
/**
|
|
|
|
* Create a new style context.
|
|
|
|
* @param aParent The parent of a style context is used for CSS
|
|
|
|
* inheritance. When the element or pseudo-element
|
|
|
|
* this style context represents the style data of
|
|
|
|
* inherits a CSS property, the value comes from the
|
|
|
|
* parent style context. This means style context
|
|
|
|
* parentage must match the definitions of inheritance
|
|
|
|
* in the CSS specification.
|
|
|
|
* @param aPseudoTag The pseudo-element or anonymous box for which
|
|
|
|
* this style context represents style. Null if
|
|
|
|
* this style context is for a normal DOM element.
|
|
|
|
* @param aPseudoType Must match aPseudoTag.
|
|
|
|
* @param aRuleNode A rule node representing the ordered sequence of
|
|
|
|
* rules that any element, pseudo-element, or
|
|
|
|
* anonymous box that this style context is for
|
|
|
|
* matches. See |nsRuleNode| and |nsIStyleRule|.
|
2013-02-21 07:34:58 +00:00
|
|
|
* @param aSkipFlexItemStyleFixup
|
|
|
|
* If set, this flag indicates that we should skip
|
|
|
|
* the chunk of ApplyStyleFixups() that modifies flex
|
|
|
|
* items' display values.
|
2012-09-18 18:37:13 +00:00
|
|
|
*/
|
2009-12-11 07:37:40 +00:00
|
|
|
nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2013-02-21 07:34:58 +00:00
|
|
|
nsRuleNode* aRuleNode,
|
|
|
|
bool aSkipFlexItemStyleFixup);
|
2010-04-06 21:52:17 +00:00
|
|
|
~nsStyleContext();
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-04-06 21:52:17 +00:00
|
|
|
void* operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW;
|
|
|
|
void Destroy();
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2003-02-22 04:05:05 +00:00
|
|
|
nsrefcnt AddRef() {
|
2012-09-28 06:57:33 +00:00
|
|
|
if (mRefCnt == UINT32_MAX) {
|
2008-12-28 01:58:14 +00:00
|
|
|
NS_WARNING("refcount overflow, leaking object");
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2003-02-22 00:32:13 +00:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
|
2003-02-22 04:05:05 +00:00
|
|
|
return mRefCnt;
|
2003-02-22 00:32:13 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:05:05 +00:00
|
|
|
nsrefcnt Release() {
|
2012-09-28 06:57:33 +00:00
|
|
|
if (mRefCnt == UINT32_MAX) {
|
2008-12-28 01:58:14 +00:00
|
|
|
NS_WARNING("refcount overflow, leaking object");
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2003-02-22 00:32:13 +00:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
Destroy();
|
2003-02-22 04:05:05 +00:00
|
|
|
return 0;
|
2003-02-22 00:32:13 +00:00
|
|
|
}
|
2003-02-22 04:05:05 +00:00
|
|
|
return mRefCnt;
|
2003-02-22 00:32:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 21:04:54 +00:00
|
|
|
nsPresContext* PresContext() const { return mRuleNode->PresContext(); }
|
2004-02-09 06:55:14 +00:00
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* GetParent() const { return mParent; }
|
|
|
|
|
2009-10-29 21:17:56 +00:00
|
|
|
nsIAtom* GetPseudo() const { return mPseudoTag; }
|
2009-12-11 07:37:40 +00:00
|
|
|
nsCSSPseudoElements::Type GetPseudoType() const {
|
|
|
|
return static_cast<nsCSSPseudoElements::Type>(mBits >>
|
|
|
|
NS_STYLE_CONTEXT_TYPE_SHIFT);
|
|
|
|
}
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
// Find, if it already exists *and is easily findable* (i.e., near the
|
|
|
|
// start of the child list), a style context whose:
|
|
|
|
// * GetPseudo() matches aPseudoTag
|
2013-02-16 21:04:53 +00:00
|
|
|
// * RuleNode() matches aRules
|
2010-04-03 01:58:26 +00:00
|
|
|
// * !GetStyleIfVisited() == !aRulesIfVisited, and, if they're
|
2013-02-16 21:04:53 +00:00
|
|
|
// non-null, GetStyleIfVisited()->RuleNode() == aRulesIfVisited
|
2010-04-03 01:58:26 +00:00
|
|
|
// * RelevantLinkVisited() == aRelevantLinkVisited
|
2010-04-06 21:52:17 +00:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-03 01:58:26 +00:00
|
|
|
FindChildWithRules(const nsIAtom* aPseudoTag, nsRuleNode* aRules,
|
|
|
|
nsRuleNode* aRulesIfVisited,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aRelevantLinkVisited);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
// Does this style context or any of its ancestors have text
|
2011-04-23 05:16:41 +00:00
|
|
|
// decoration lines?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasTextDecorationLines() const
|
2011-04-23 05:16:41 +00:00
|
|
|
{ return !!(mBits & NS_STYLE_HAS_TEXT_DECORATION_LINES); }
|
2009-08-10 22:52:29 +00:00
|
|
|
|
|
|
|
// Does this style context represent the style for a pseudo-element or
|
|
|
|
// inherit data from such a style context? Whether this returns true
|
|
|
|
// is equivalent to whether it or any of its ancestors returns
|
2009-10-29 21:17:56 +00:00
|
|
|
// non-null for GetPseudo.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasPseudoElementData() const
|
2009-08-10 22:52:29 +00:00
|
|
|
{ return !!(mBits & NS_STYLE_HAS_PSEUDO_ELEMENT_DATA); }
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
// Is the only link whose visitedness is allowed to influence the
|
|
|
|
// style of the node this style context is for (which is that element
|
|
|
|
// or its nearest ancestor that is a link) visited?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool RelevantLinkVisited() const
|
2010-04-03 01:58:25 +00:00
|
|
|
{ return !!(mBits & NS_STYLE_RELEVANT_LINK_VISITED); }
|
|
|
|
|
2010-06-08 19:58:26 +00:00
|
|
|
// Is this a style context for a link?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsLinkContext() const {
|
2010-06-08 19:58:26 +00:00
|
|
|
return
|
|
|
|
GetStyleIfVisited() && GetStyleIfVisited()->GetParent() == GetParent();
|
|
|
|
}
|
|
|
|
|
2010-04-06 19:42:41 +00:00
|
|
|
// Is this style context the GetStyleIfVisited() for some other style
|
|
|
|
// context?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsStyleIfVisited() const
|
2010-04-06 19:42:41 +00:00
|
|
|
{ return !!(mBits & NS_STYLE_IS_STYLE_IF_VISITED); }
|
|
|
|
|
|
|
|
// Tells this style context that it should return true from
|
|
|
|
// IsStyleIfVisited.
|
|
|
|
void SetIsStyleIfVisited()
|
|
|
|
{ mBits |= NS_STYLE_IS_STYLE_IF_VISITED; }
|
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
// Return the style context whose style data should be used for the R,
|
|
|
|
// G, and B components of color, background-color, and border-*-color
|
|
|
|
// if RelevantLinkIsVisited().
|
|
|
|
//
|
|
|
|
// GetPseudo() and GetPseudoType() on this style context return the
|
|
|
|
// same as on |this|, and its depth in the tree (number of GetParent()
|
|
|
|
// calls until null is returned) is the same as |this|, since its
|
|
|
|
// parent is either |this|'s parent or |this|'s parent's
|
|
|
|
// style-if-visited.
|
|
|
|
//
|
|
|
|
// Structs on this context should never be examined without also
|
|
|
|
// examining the corresponding struct on |this|. Doing so will likely
|
|
|
|
// both (1) lead to a privacy leak and (2) lead to dynamic change bugs
|
|
|
|
// related to the Peek code in nsStyleContext::CalcStyleDifference.
|
2010-06-08 19:58:26 +00:00
|
|
|
nsStyleContext* GetStyleIfVisited() const
|
2010-04-03 01:58:25 +00:00
|
|
|
{ return mStyleIfVisited; }
|
|
|
|
|
|
|
|
// To be called only from nsStyleSet.
|
|
|
|
void SetStyleIfVisited(already_AddRefed<nsStyleContext> aStyleIfVisited)
|
|
|
|
{
|
2010-04-06 19:42:41 +00:00
|
|
|
NS_ABORT_IF_FALSE(!IsStyleIfVisited(), "this context is not visited data");
|
|
|
|
NS_ABORT_IF_FALSE(aStyleIfVisited.get()->IsStyleIfVisited(),
|
|
|
|
"other context is visited data");
|
|
|
|
NS_ABORT_IF_FALSE(!aStyleIfVisited.get()->GetStyleIfVisited(),
|
|
|
|
"other context does not have visited data");
|
2010-04-03 01:58:25 +00:00
|
|
|
NS_ASSERTION(!mStyleIfVisited, "should only be set once");
|
|
|
|
mStyleIfVisited = aStyleIfVisited;
|
|
|
|
|
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetPseudo() == GetPseudo(),
|
|
|
|
"pseudo tag mismatch");
|
|
|
|
if (GetParent() && GetParent()->GetStyleIfVisited()) {
|
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetParent() ==
|
|
|
|
GetParent()->GetStyleIfVisited() ||
|
|
|
|
GetStyleIfVisited()->GetParent() == GetParent(),
|
|
|
|
"parent mismatch");
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetParent() == GetParent(),
|
|
|
|
"parent mismatch");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
// Tell this style context to cache aStruct as the struct for aSID
|
2010-04-06 21:52:17 +00:00
|
|
|
void SetStyle(nsStyleStructID aSID, void* aStruct);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
// Setters for inherit structs only, since rulenode only sets those eagerly.
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
|
2010-03-02 23:27:21 +00:00
|
|
|
void SetStyle##name_ (nsStyle##name_ * aStruct) { \
|
2011-03-18 03:14:32 +00:00
|
|
|
void *& slot = \
|
|
|
|
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]; \
|
|
|
|
NS_ASSERTION(!slot || \
|
2010-03-02 23:27:21 +00:00
|
|
|
(mBits & \
|
|
|
|
nsCachedStyleData::GetBitForSID(eStyleStruct_##name_)), \
|
|
|
|
"Going to leak styledata"); \
|
2011-03-18 03:14:32 +00:00
|
|
|
slot = aStruct; \
|
2010-03-02 23:27:21 +00:00
|
|
|
}
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) /* nothing */
|
2010-03-02 23:27:21 +00:00
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
|
2013-02-16 21:04:53 +00:00
|
|
|
nsRuleNode* RuleNode() { return mRuleNode; }
|
2012-08-22 15:56:38 +00:00
|
|
|
void AddStyleBit(const uint32_t& aBit) { mBits |= aBit; }
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2003-03-06 19:14:17 +00:00
|
|
|
/*
|
|
|
|
* Mark this style context's rule node (and its ancestors) to prevent
|
|
|
|
* it from being garbage collected.
|
|
|
|
*/
|
2010-04-06 21:52:17 +00:00
|
|
|
void Mark();
|
2003-03-06 19:14:17 +00:00
|
|
|
|
2003-03-13 15:29:36 +00:00
|
|
|
/*
|
|
|
|
* Get the style data for a style struct. This is the most important
|
|
|
|
* member function of nsIStyleContext. It fills in a const pointer
|
|
|
|
* to a style data struct that is appropriate for the style context's
|
|
|
|
* frame. This struct may be shared with other contexts (either in
|
|
|
|
* the rule tree or the style context tree), so it should not be
|
|
|
|
* modified.
|
|
|
|
*
|
|
|
|
* This function will NOT return null (even when out of memory) when
|
|
|
|
* given a valid style struct ID, so the result does not need to be
|
|
|
|
* null-checked.
|
|
|
|
*
|
2003-05-15 03:42:21 +00:00
|
|
|
* The typesafe functions below are preferred to the use of this
|
2012-09-18 18:01:03 +00:00
|
|
|
* function, both because they're easier to read and because they're
|
2010-03-02 23:27:21 +00:00
|
|
|
* faster.
|
2003-03-13 15:29:36 +00:00
|
|
|
*/
|
2013-02-16 21:51:03 +00:00
|
|
|
const void* NS_FASTCALL StyleData(nsStyleStructID aSID);
|
2003-03-13 15:29:36 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
/**
|
|
|
|
* Define typesafe getter functions for each style struct by
|
|
|
|
* preprocessing the list of style structs. These functions are the
|
|
|
|
* preferred way to get style data. The macro creates functions like:
|
2013-02-16 21:51:02 +00:00
|
|
|
* const nsStyleBorder* StyleBorder();
|
|
|
|
* const nsStyleColor* StyleColor();
|
2003-05-15 03:42:21 +00:00
|
|
|
*/
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyle##name_ * Style##name_() { \
|
|
|
|
return DoGetStyle##name_(true); \
|
2010-03-02 23:27:21 +00:00
|
|
|
}
|
2003-05-15 03:42:21 +00:00
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
/**
|
|
|
|
* PeekStyle* is like GetStyle* but doesn't trigger style
|
|
|
|
* computation if the data is not cached on either the style context
|
|
|
|
* or the rule node.
|
|
|
|
*
|
|
|
|
* Perhaps this shouldn't be a public nsStyleContext API.
|
|
|
|
*/
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
2010-03-02 23:27:21 +00:00
|
|
|
const nsStyle##name_ * PeekStyle##name_() { \
|
2013-02-16 21:51:02 +00:00
|
|
|
return DoGetStyle##name_(false); \
|
2010-03-02 23:27:21 +00:00
|
|
|
}
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-04-06 21:52:17 +00:00
|
|
|
void* GetUniqueStyleData(const nsStyleStructID& aSID);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2012-09-07 17:13:36 +00:00
|
|
|
/**
|
|
|
|
* Compute the style changes needed during restyling when this style
|
|
|
|
* context is being replaced by aOther. (This is nonsymmetric since
|
|
|
|
* we optimize by skipping comparison for styles that have never been
|
|
|
|
* requested.)
|
|
|
|
*
|
|
|
|
* This method returns a change hint (see nsChangeHint.h). All change
|
|
|
|
* hints apply to the frame and its later continuations or special
|
|
|
|
* siblings. Most (all of those except the "NotHandledForDescendants"
|
|
|
|
* hints) also apply to all descendants. The caller must pass in any
|
|
|
|
* non-inherited hints that resulted from the parent style context's
|
|
|
|
* style change. The caller *may* pass more hints than needed, but
|
|
|
|
* must not pass less than needed; therefore if the caller doesn't
|
|
|
|
* know, the caller should pass
|
|
|
|
* nsChangeHint_Hints_NotHandledForDescendants.
|
|
|
|
*/
|
|
|
|
nsChangeHint CalcStyleDifference(nsStyleContext* aOther,
|
|
|
|
nsChangeHint aParentHintsNotHandledForDescendants);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
/**
|
|
|
|
* Get a color that depends on link-visitedness using this and
|
|
|
|
* this->GetStyleIfVisited().
|
|
|
|
*
|
|
|
|
* aProperty must be a color-valued property that nsStyleAnimation
|
|
|
|
* knows how to extract. It must also be a property that we know to
|
|
|
|
* do change handling for in nsStyleContext::CalcDifference.
|
2010-04-03 01:58:26 +00:00
|
|
|
*
|
|
|
|
* Note that if aProperty is eCSSProperty_border_*_color, this
|
|
|
|
* function handles -moz-use-text-color.
|
2010-04-03 01:58:25 +00:00
|
|
|
*/
|
2010-04-06 21:52:17 +00:00
|
|
|
nscolor GetVisitedDependentColor(nsCSSProperty aProperty);
|
2010-04-03 01:58:25 +00:00
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
/**
|
|
|
|
* aColors should be a two element array of nscolor in which the first
|
|
|
|
* color is the unvisited color and the second is the visited color.
|
|
|
|
*
|
|
|
|
* Combine the R, G, and B components of whichever of aColors should
|
|
|
|
* be used based on aLinkIsVisited with the A component of aColors[0].
|
|
|
|
*/
|
|
|
|
static nscolor CombineVisitedColors(nscolor *aColors,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aLinkIsVisited);
|
2010-04-03 01:58:26 +00:00
|
|
|
|
2010-07-03 04:18:55 +00:00
|
|
|
/**
|
|
|
|
* Allocate a chunk of memory that is scoped to the lifetime of this
|
|
|
|
* style context, i.e., memory that will automatically be freed when
|
|
|
|
* this style context is destroyed. This is intended for allocations
|
|
|
|
* that are stored on this style context or its style structs. (Use
|
|
|
|
* on style structs is fine since any style context to which this
|
|
|
|
* context's style structs are shared will be a descendant of this
|
|
|
|
* style context and thus keep it alive.)
|
|
|
|
*
|
|
|
|
* This currently allocates the memory out of the pres shell arena.
|
|
|
|
*
|
|
|
|
* It would be relatively straightforward to write a Free method
|
|
|
|
* for the underlying implementation, but we don't need it (or the
|
|
|
|
* overhead of making a doubly-linked list or other structure to
|
|
|
|
* support it).
|
|
|
|
*
|
|
|
|
* WARNING: Memory allocated using this method cannot be stored in the
|
|
|
|
* rule tree, since rule nodes may outlive the style context.
|
|
|
|
*/
|
|
|
|
void* Alloc(size_t aSize);
|
|
|
|
|
2011-02-05 03:43:13 +00:00
|
|
|
/**
|
|
|
|
* Start the background image loads for this style context.
|
|
|
|
*/
|
|
|
|
void StartBackgroundImageLoads() {
|
|
|
|
// Just get our background struct; that should do the trick
|
2013-02-16 21:51:02 +00:00
|
|
|
StyleBackground();
|
2011-02-05 03:43:13 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
#ifdef DEBUG
|
2012-08-22 15:56:38 +00:00
|
|
|
void List(FILE* out, int32_t aIndent);
|
2003-02-22 00:32:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2010-04-06 21:52:17 +00:00
|
|
|
void AddChild(nsStyleContext* aChild);
|
|
|
|
void RemoveChild(nsStyleContext* aChild);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2013-02-21 07:34:58 +00:00
|
|
|
void ApplyStyleFixups(bool aSkipFlexItemStyleFixup);
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-07-03 04:18:55 +00:00
|
|
|
void FreeAllocations(nsPresContext* aPresContext);
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
// Helper function that GetStyleData and GetUniqueStyleData use. Only
|
|
|
|
// returns the structs we cache ourselves; never consults the ruletree.
|
|
|
|
inline const void* GetCachedStyleData(nsStyleStructID aSID);
|
|
|
|
|
|
|
|
// Helper functions for GetStyle* and PeekStyle*
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
|
|
|
|
const nsStyle##name_ * DoGetStyle##name_(bool aComputeData) { \
|
2010-03-02 23:27:21 +00:00
|
|
|
const nsStyle##name_ * cachedData = \
|
2011-03-18 03:14:32 +00:00
|
|
|
static_cast<nsStyle##name_*>( \
|
|
|
|
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]); \
|
2010-03-02 23:27:21 +00:00
|
|
|
if (cachedData) /* Have it cached already, yay */ \
|
|
|
|
return cachedData; \
|
|
|
|
/* Have the rulenode deal */ \
|
|
|
|
return mRuleNode->GetStyle##name_(this, aComputeData); \
|
|
|
|
}
|
2013-04-02 01:45:48 +00:00
|
|
|
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
|
|
|
|
const nsStyle##name_ * DoGetStyle##name_(bool aComputeData) { \
|
2011-03-18 03:14:32 +00:00
|
|
|
const nsStyle##name_ * cachedData = mCachedResetData \
|
|
|
|
? static_cast<nsStyle##name_*>( \
|
|
|
|
mCachedResetData->mStyleStructs[eStyleStruct_##name_]) \
|
2013-04-02 01:45:48 +00:00
|
|
|
: nullptr; \
|
2010-03-02 23:27:21 +00:00
|
|
|
if (cachedData) /* Have it cached already, yay */ \
|
|
|
|
return cachedData; \
|
|
|
|
/* Have the rulenode deal */ \
|
|
|
|
return mRuleNode->GetStyle##name_(this, aComputeData); \
|
|
|
|
}
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
nsStyleContext* const mParent; // STRONG
|
2005-02-05 05:24:21 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
// Children are kept in two circularly-linked lists. The list anchor
|
|
|
|
// is not part of the list (null for empty), and we point to the first
|
|
|
|
// child.
|
2005-02-05 05:24:21 +00:00
|
|
|
// mEmptyChild for children whose rule node is the root rule node, and
|
|
|
|
// mChild for other children. The order of children is not
|
|
|
|
// meaningful.
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* mChild;
|
|
|
|
nsStyleContext* mEmptyChild;
|
|
|
|
nsStyleContext* mPrevSibling;
|
|
|
|
nsStyleContext* mNextSibling;
|
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
// Style to be used instead for the R, G, and B components of color,
|
|
|
|
// background-color, and border-*-color if the nearest ancestor link
|
|
|
|
// element is visited (see RelevantLinkVisited()).
|
|
|
|
nsRefPtr<nsStyleContext> mStyleIfVisited;
|
|
|
|
|
2009-10-29 21:17:56 +00:00
|
|
|
// If this style context is for a pseudo-element or anonymous box,
|
|
|
|
// the relevant atom.
|
2003-02-22 00:32:13 +00:00
|
|
|
nsCOMPtr<nsIAtom> mPseudoTag;
|
|
|
|
|
2005-02-04 20:11:00 +00:00
|
|
|
// The rule node is the node in the lexicographic tree of rule nodes
|
|
|
|
// (the "rule tree") that indicates which style rules are used to
|
|
|
|
// compute the style data, and in what cascading order. The least
|
|
|
|
// specific rule matched is the one whose rule node is a child of the
|
|
|
|
// root of the rule tree, and the most specific rule matched is the
|
|
|
|
// |mRule| member of |mRuleNode|.
|
2005-02-05 05:24:21 +00:00
|
|
|
nsRuleNode* const mRuleNode;
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2010-07-03 04:18:55 +00:00
|
|
|
// Private to nsStyleContext::Alloc and FreeAllocations.
|
|
|
|
struct AllocationHeader {
|
|
|
|
AllocationHeader* mNext;
|
|
|
|
size_t mSize;
|
|
|
|
|
|
|
|
void* mStorageStart; // ensure the storage is at least pointer-aligned
|
|
|
|
};
|
|
|
|
AllocationHeader* mAllocations;
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
// mCachedInheritedData and mCachedResetData point to both structs that
|
|
|
|
// are owned by this style context and structs that are owned by one of
|
|
|
|
// this style context's ancestors (which are indirectly owned since this
|
|
|
|
// style context owns a reference to its parent). If the bit in |mBits|
|
|
|
|
// is set for a struct, that means that the pointer for that struct is
|
2010-03-02 23:27:21 +00:00
|
|
|
// owned by an ancestor or by mRuleNode rather than by this style context.
|
2010-03-02 23:27:21 +00:00
|
|
|
// Since style contexts typically have some inherited data but only sometimes
|
|
|
|
// have reset data, we always allocate the mCachedInheritedData, but only
|
|
|
|
// sometimes allocate the mCachedResetData.
|
|
|
|
nsResetStyleData* mCachedResetData; // Cached reset style data.
|
|
|
|
nsInheritedStyleData mCachedInheritedData; // Cached inherited style data
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mBits; // Which structs are inherited from the
|
2010-03-02 23:27:21 +00:00
|
|
|
// parent context or owned by mRuleNode.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mRefCnt;
|
2003-02-22 00:32:13 +00:00
|
|
|
};
|
|
|
|
|
2010-04-06 21:52:17 +00:00
|
|
|
already_AddRefed<nsStyleContext>
|
2003-02-22 00:32:13 +00:00
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2009-12-11 07:37:40 +00:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2013-02-21 07:34:58 +00:00
|
|
|
nsRuleNode* aRuleNode,
|
|
|
|
bool aSkipFlexItemStyleFixup);
|
2003-02-22 00:32:13 +00:00
|
|
|
#endif
|