2003-02-22 03:32:13 +03: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/. */
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
#ifndef _nsStyleContext_h_
|
|
|
|
#define _nsStyleContext_h_
|
|
|
|
|
2015-02-07 05:25:21 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-03-19 02:56:47 +03:00
|
|
|
#include "mozilla/RestyleLogging.h"
|
2017-02-17 03:41:12 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2016-03-19 02:56:47 +03:00
|
|
|
#include "mozilla/StyleContextSource.h"
|
2016-12-30 16:57:37 +03:00
|
|
|
#include "mozilla/StyleComplexColor.h"
|
2016-08-20 00:32:51 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2016-03-19 02:56:47 +03:00
|
|
|
#include "nsStyleSet.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2013-03-03 04:31:48 +04:00
|
|
|
class nsIAtom;
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2016-02-17 23:37:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
enum class CSSPseudoElementType : uint8_t;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-10-24 12:16:46 +03:00
|
|
|
extern "C" {
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
struct nsStyle##name_; \
|
|
|
|
const nsStyle##name_* Servo_GetStyle##name_( \
|
|
|
|
ServoComputedValuesBorrowedOrNull computed_values);
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
}
|
|
|
|
|
2005-02-04 23:11:00 +03: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 08:24:21 +03:00
|
|
|
* nsStyleContext are also immutable (with the additional exception of
|
|
|
|
* GetUniqueStyleData). When style data change,
|
2016-09-23 13:08:01 +03:00
|
|
|
* ElementRestyler::Restyle creates a new style context.
|
2005-02-05 08:24:21 +03: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)
|
2005-02-04 23:11:00 +03:00
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsStyleContext final
|
2003-02-22 03:32:13 +03:00
|
|
|
{
|
|
|
|
public:
|
2012-09-18 22:37:13 +04: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|.
|
2014-06-16 17:55:00 +04:00
|
|
|
* @param aSkipParentDisplayBasedStyleFixup
|
2013-02-21 11:34:58 +04:00
|
|
|
* If set, this flag indicates that we should skip
|
2016-02-17 23:37:00 +03:00
|
|
|
* the chunk of ApplyStyleFixups() that applies to
|
|
|
|
* special cases where a child element's style may
|
|
|
|
* need to be modified based on its parent's display
|
2014-06-16 17:55:00 +04:00
|
|
|
* value.
|
2012-09-18 22:37:13 +04:00
|
|
|
*/
|
2009-12-11 10:37:40 +03:00
|
|
|
nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag,
|
2016-02-17 23:37:00 +03:00
|
|
|
mozilla::CSSPseudoElementType aPseudoType,
|
2016-03-19 02:56:47 +03:00
|
|
|
already_AddRefed<nsRuleNode> aRuleNode,
|
|
|
|
bool aSkipParentDisplayBasedStyleFixup);
|
|
|
|
|
|
|
|
// Version of the above that takes a ServoComputedValues instead of a Gecko
|
|
|
|
// nsRuleNode.
|
|
|
|
nsStyleContext(nsStyleContext* aParent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
mozilla::CSSPseudoElementType aPseudoType,
|
2017-04-25 07:52:51 +03:00
|
|
|
already_AddRefed<ServoComputedValues> aComputedValues);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2016-08-17 22:28:45 +03:00
|
|
|
void* operator new(size_t sz, nsPresContext* aPresContext);
|
2010-04-07 01:52:17 +04:00
|
|
|
void Destroy();
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2015-09-17 05:08:20 +03:00
|
|
|
// These two methods are for use by ArenaRefPtr.
|
|
|
|
static mozilla::ArenaObjectID ArenaObjectID()
|
|
|
|
{
|
|
|
|
return mozilla::eArenaObjectID_nsStyleContext;
|
|
|
|
}
|
|
|
|
nsIPresShell* Arena();
|
|
|
|
|
2015-03-05 04:48:45 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* Initializes a cached pref, which is only used in DEBUG code.
|
|
|
|
*/
|
|
|
|
static void Initialize();
|
|
|
|
#endif
|
|
|
|
|
2003-02-22 07:05:05 +03:00
|
|
|
nsrefcnt AddRef() {
|
2012-09-28 10:57:33 +04:00
|
|
|
if (mRefCnt == UINT32_MAX) {
|
2008-12-28 04:58:14 +03:00
|
|
|
NS_WARNING("refcount overflow, leaking object");
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
|
2003-02-22 07:05:05 +03:00
|
|
|
return mRefCnt;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
|
|
|
|
2003-02-22 07:05:05 +03:00
|
|
|
nsrefcnt Release() {
|
2012-09-28 10:57:33 +04:00
|
|
|
if (mRefCnt == UINT32_MAX) {
|
2008-12-28 04:58:14 +03:00
|
|
|
NS_WARNING("refcount overflow, leaking object");
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
Destroy();
|
2003-02-22 07:05:05 +03:00
|
|
|
return 0;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
2003-02-22 07:05:05 +03:00
|
|
|
return mRefCnt;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
|
|
|
|
2015-02-18 01:28:53 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void FrameAddRef() {
|
|
|
|
++mFrameRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameRelease() {
|
|
|
|
--mFrameRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t FrameRefCnt() const {
|
|
|
|
return mFrameRefCnt;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-05 07:48:47 +04:00
|
|
|
bool HasSingleReference() const {
|
|
|
|
NS_ASSERTION(mRefCnt != 0,
|
|
|
|
"do not call HasSingleReference on a newly created "
|
|
|
|
"nsStyleContext with no references yet");
|
|
|
|
return mRefCnt == 1;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:56:47 +03:00
|
|
|
nsPresContext* PresContext() const {
|
|
|
|
#ifdef MOZ_STYLO
|
|
|
|
return mPresContext;
|
|
|
|
#else
|
|
|
|
return mSource.AsGeckoRuleNode()->PresContext();
|
|
|
|
#endif
|
|
|
|
}
|
2004-02-09 09:55:14 +03:00
|
|
|
|
2017-03-20 09:11:06 +03:00
|
|
|
nsStyleContext* GetParent() const {
|
|
|
|
MOZ_ASSERT(mSource.IsGeckoRuleNode(),
|
|
|
|
"This should be used only in Gecko-backed style system!");
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleContext* GetParentAllowServo() const {
|
|
|
|
return mParent;
|
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2009-10-30 00:17:56 +03:00
|
|
|
nsIAtom* GetPseudo() const { return mPseudoTag; }
|
2016-02-17 23:37:00 +03:00
|
|
|
mozilla::CSSPseudoElementType GetPseudoType() const {
|
|
|
|
return static_cast<mozilla::CSSPseudoElementType>(
|
|
|
|
mBits >> NS_STYLE_CONTEXT_TYPE_SHIFT);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2016-08-26 04:48:35 +03:00
|
|
|
bool IsAnonBox() const {
|
2017-03-09 07:41:04 +03:00
|
|
|
return
|
|
|
|
GetPseudoType() == mozilla::CSSPseudoElementType::InheritingAnonBox ||
|
|
|
|
GetPseudoType() == mozilla::CSSPseudoElementType::NonInheritingAnonBox;
|
2016-08-26 04:48:35 +03:00
|
|
|
}
|
|
|
|
bool IsPseudoElement() const { return mPseudoTag && !IsAnonBox(); }
|
|
|
|
|
|
|
|
|
2010-04-03 05:58:26 +04: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
|
2016-03-19 02:56:47 +03:00
|
|
|
// * mSource matches aSource
|
|
|
|
// * !!GetStyleIfVisited() == !!aSourceIfVisited, and, if they're
|
|
|
|
// non-null, GetStyleIfVisited()->mSource == aSourceIfVisited
|
2015-05-04 00:52:53 +03:00
|
|
|
// * RelevantLinkVisited() == aRelevantLinkVisited
|
2010-04-07 01:52:17 +04:00
|
|
|
already_AddRefed<nsStyleContext>
|
2016-03-19 02:56:47 +03:00
|
|
|
FindChildWithRules(const nsIAtom* aPseudoTag,
|
|
|
|
mozilla::NonOwningStyleContextSource aSource,
|
|
|
|
mozilla::NonOwningStyleContextSource aSourceIfVisited,
|
2015-05-04 00:52:53 +03:00
|
|
|
bool aRelevantLinkVisited);
|
2016-04-22 20:40:39 +03:00
|
|
|
|
2009-08-11 02:52:29 +04:00
|
|
|
// Does this style context or any of its ancestors have text
|
2011-04-23 09:16:41 +04:00
|
|
|
// decoration lines?
|
2016-03-14 20:27:05 +03:00
|
|
|
// Differs from nsStyleTextReset::HasTextDecorationLines, which tests
|
|
|
|
// only the data for a single context.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasTextDecorationLines() const
|
2011-04-23 09:16:41 +04:00
|
|
|
{ return !!(mBits & NS_STYLE_HAS_TEXT_DECORATION_LINES); }
|
2009-08-11 02:52:29 +04:00
|
|
|
|
2015-03-11 02:28:21 +03:00
|
|
|
// Whether any line break inside should be suppressed? If this returns
|
|
|
|
// true, the line should not be broken inside, which means inlines act
|
|
|
|
// as if nowrap is set, <br> is suppressed, and blocks are inlinized.
|
|
|
|
// This bit is propogated to all children of line partitipants. It is
|
2015-04-22 09:34:05 +03:00
|
|
|
// currently used by ruby to make its content frames unbreakable.
|
2015-05-04 00:52:53 +03:00
|
|
|
// NOTE: for nsTextFrame, use nsTextFrame::ShouldSuppressLineBreak()
|
|
|
|
// instead of this method.
|
2015-03-11 02:28:21 +03:00
|
|
|
bool ShouldSuppressLineBreak() const
|
|
|
|
{ return !!(mBits & NS_STYLE_SUPPRESS_LINEBREAK); }
|
2014-12-11 01:26:18 +03:00
|
|
|
|
2015-03-16 03:28:49 +03:00
|
|
|
// Does this style context or any of its ancestors have display:none set?
|
|
|
|
bool IsInDisplayNoneSubtree() const
|
|
|
|
{ return !!(mBits & NS_STYLE_IN_DISPLAY_NONE_SUBTREE); }
|
|
|
|
|
2016-04-22 02:18:41 +03:00
|
|
|
// Is this horizontal-in-vertical (tate-chu-yoko) text? This flag is
|
|
|
|
// only set on style contexts whose pseudo is nsCSSAnonBoxes::mozText.
|
|
|
|
bool IsTextCombined() const
|
|
|
|
{ return !!(mBits & NS_STYLE_IS_TEXT_COMBINED); }
|
|
|
|
|
2009-08-11 02:52:29 +04: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
|
2016-08-26 04:48:35 +03:00
|
|
|
// non-null for IsPseudoElement().
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasPseudoElementData() const
|
2009-08-11 02:52:29 +04:00
|
|
|
{ return !!(mBits & NS_STYLE_HAS_PSEUDO_ELEMENT_DATA); }
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2015-08-28 23:13:47 +03:00
|
|
|
bool HasChildThatUsesResetStyle() const
|
|
|
|
{ return mBits & NS_STYLE_HAS_CHILD_THAT_USES_RESET_STYLE; }
|
|
|
|
|
2010-04-03 05:58:25 +04: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 10:19:26 +04:00
|
|
|
bool RelevantLinkVisited() const
|
2010-04-03 05:58:25 +04:00
|
|
|
{ return !!(mBits & NS_STYLE_RELEVANT_LINK_VISITED); }
|
|
|
|
|
2010-06-08 23:58:26 +04:00
|
|
|
// Is this a style context for a link?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsLinkContext() const {
|
2010-06-08 23:58:26 +04:00
|
|
|
return
|
|
|
|
GetStyleIfVisited() && GetStyleIfVisited()->GetParent() == GetParent();
|
|
|
|
}
|
|
|
|
|
2010-04-06 23:42:41 +04:00
|
|
|
// Is this style context the GetStyleIfVisited() for some other style
|
|
|
|
// context?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsStyleIfVisited() const
|
2010-04-06 23:42:41 +04: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 05:58:25 +04: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 23:58:26 +04:00
|
|
|
nsStyleContext* GetStyleIfVisited() const
|
2010-04-03 05:58:25 +04:00
|
|
|
{ return mStyleIfVisited; }
|
|
|
|
|
2017-05-10 23:00:42 +03:00
|
|
|
// To be called only from nsStyleSet / ServoStyleSet.
|
2010-04-03 05:58:25 +04:00
|
|
|
void SetStyleIfVisited(already_AddRefed<nsStyleContext> aStyleIfVisited)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsStyleIfVisited(), "this context is not visited data");
|
2010-04-03 05:58:25 +04:00
|
|
|
NS_ASSERTION(!mStyleIfVisited, "should only be set once");
|
2014-03-15 23:00:15 +04:00
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
mStyleIfVisited = aStyleIfVisited;
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mStyleIfVisited->IsStyleIfVisited(),
|
|
|
|
"other context is visited data");
|
|
|
|
MOZ_ASSERT(!mStyleIfVisited->GetStyleIfVisited(),
|
|
|
|
"other context does not have visited data");
|
2010-04-03 05:58:25 +04:00
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetPseudo() == GetPseudo(),
|
|
|
|
"pseudo tag mismatch");
|
2017-05-10 23:00:42 +03:00
|
|
|
if (GetParentAllowServo() && GetParentAllowServo()->GetStyleIfVisited()) {
|
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetParentAllowServo() ==
|
|
|
|
GetParentAllowServo()->GetStyleIfVisited() ||
|
|
|
|
GetStyleIfVisited()->GetParentAllowServo() ==
|
|
|
|
GetParentAllowServo(),
|
2010-04-03 05:58:25 +04:00
|
|
|
"parent mismatch");
|
|
|
|
} else {
|
2017-05-10 23:00:42 +03:00
|
|
|
NS_ASSERTION(GetStyleIfVisited()->GetParentAllowServo() ==
|
|
|
|
GetParentAllowServo(),
|
2010-04-03 05:58:25 +04:00
|
|
|
"parent mismatch");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 03:16:46 +03:00
|
|
|
// Does any descendant of this style context have any style values
|
|
|
|
// that were computed based on this style context's ancestors?
|
|
|
|
bool HasChildThatUsesGrandancestorStyle() const
|
|
|
|
{ return !!(mBits & NS_STYLE_CHILD_USES_GRANDANCESTOR_STYLE); }
|
2014-09-05 07:48:44 +04:00
|
|
|
|
2014-09-05 07:48:44 +04:00
|
|
|
// Is this style context shared with a sibling or cousin?
|
|
|
|
// (See nsStyleSet::GetContext.)
|
|
|
|
bool IsShared() const
|
|
|
|
{ return !!(mBits & NS_STYLE_IS_SHARED); }
|
|
|
|
|
2010-03-03 02:27:21 +03:00
|
|
|
// Tell this style context to cache aStruct as the struct for aSID
|
2010-04-07 01:52:17 +04:00
|
|
|
void SetStyle(nsStyleStructID aSID, void* aStruct);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2014-09-05 07:48:44 +04:00
|
|
|
/**
|
2015-10-20 06:42:28 +03:00
|
|
|
* Returns whether this style context has cached style data for a
|
|
|
|
* given style struct and it does NOT own that struct. This can
|
|
|
|
* happen because it was inherited from the parent style context, or
|
|
|
|
* because it was stored conditionally on the rule node.
|
2014-09-05 07:48:44 +04:00
|
|
|
*/
|
2015-10-20 06:42:28 +03:00
|
|
|
bool HasCachedDependentStyleData(nsStyleStructID aSID) {
|
2015-10-23 02:57:36 +03:00
|
|
|
return mBits & nsCachedStyleData::GetBitForSID(aSID);
|
2015-10-20 06:42:28 +03:00
|
|
|
}
|
2014-09-05 07:48:44 +04:00
|
|
|
|
2016-03-19 02:56:47 +03:00
|
|
|
nsRuleNode* RuleNode() {
|
|
|
|
MOZ_RELEASE_ASSERT(mSource.IsGeckoRuleNode());
|
|
|
|
return mSource.AsGeckoRuleNode();
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:40 +04:00
|
|
|
void AddStyleBit(const uint64_t& aBit) { mBits |= aBit; }
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2003-03-13 18:29:36 +03:00
|
|
|
/*
|
|
|
|
* Get the style data for a style struct. This is the most important
|
2015-10-29 09:05:13 +03:00
|
|
|
* member function of nsStyleContext. It fills in a const pointer
|
2003-03-13 18:29:36 +03:00
|
|
|
* 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 07:42:21 +04:00
|
|
|
* The typesafe functions below are preferred to the use of this
|
2012-09-18 22:01:03 +04:00
|
|
|
* function, both because they're easier to read and because they're
|
2010-03-03 02:27:21 +03:00
|
|
|
* faster.
|
2003-03-13 18:29:36 +03:00
|
|
|
*/
|
2017-05-22 21:00:19 +03:00
|
|
|
const void* NS_FASTCALL StyleData(nsStyleStructID aSID) MOZ_NONNULL_RETURN;
|
2003-03-13 18:29:36 +03:00
|
|
|
|
2003-05-15 07:42:21 +04: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-17 01:51:02 +04:00
|
|
|
* const nsStyleBorder* StyleBorder();
|
|
|
|
* const nsStyleColor* StyleColor();
|
2003-05-15 07:42:21 +04:00
|
|
|
*/
|
2017-05-22 21:00:19 +03:00
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
const nsStyle##name_ * Style##name_() MOZ_NONNULL_RETURN { \
|
|
|
|
return DoGetStyle##name_<true>(); \
|
2010-03-03 02:27:21 +03:00
|
|
|
}
|
2003-05-15 07:42:21 +04:00
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
|
2017-02-17 03:41:12 +03:00
|
|
|
/**
|
|
|
|
* Equivalent to StyleFoo(), except that we skip the cache write during the
|
|
|
|
* servo traversal. This can cause incorrect behavior if used improperly,
|
|
|
|
* since we won't record that layout potentially depends on the values in
|
|
|
|
* this style struct. Use with care.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
const nsStyle##name_ * ThreadsafeStyle##name_() { \
|
|
|
|
if (mozilla::ServoStyleSet::IsInServoTraversal()) { \
|
|
|
|
return Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
|
|
|
} \
|
|
|
|
return Style##name_(); \
|
|
|
|
}
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
|
|
|
|
|
2010-03-03 02:27:21 +03:00
|
|
|
/**
|
2015-10-29 09:05:13 +03:00
|
|
|
* PeekStyle* is like Style* but doesn't trigger style
|
2010-03-03 02:27:21 +03:00
|
|
|
* 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 05:45:48 +04:00
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
2010-03-03 02:27:21 +03:00
|
|
|
const nsStyle##name_ * PeekStyle##name_() { \
|
2015-04-15 01:55:56 +03:00
|
|
|
return DoGetStyle##name_<false>(); \
|
2010-03-03 02:27:21 +03:00
|
|
|
}
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2012-09-07 21:13:36 +04:00
|
|
|
/**
|
|
|
|
* Compute the style changes needed during restyling when this style
|
2016-06-21 04:47:54 +03:00
|
|
|
* context is being replaced by aNewContext. (This is nonsymmetric since
|
2012-09-07 21:13:36 +04:00
|
|
|
* we optimize by skipping comparison for styles that have never been
|
|
|
|
* requested.)
|
|
|
|
*
|
|
|
|
* This method returns a change hint (see nsChangeHint.h). All change
|
2014-02-07 05:45:33 +04:00
|
|
|
* hints apply to the frame and its later continuations or ib-split
|
2012-09-07 21:13:36 +04:00
|
|
|
* siblings. Most (all of those except the "NotHandledForDescendants"
|
2017-03-21 11:33:05 +03:00
|
|
|
* hints) also apply to all descendants.
|
2014-09-05 07:48:44 +04:00
|
|
|
*
|
|
|
|
* aEqualStructs must not be null. Into it will be stored a bitfield
|
|
|
|
* representing which structs were compared to be non-equal.
|
2012-09-07 21:13:36 +04:00
|
|
|
*/
|
2016-06-21 04:47:54 +03:00
|
|
|
nsChangeHint CalcStyleDifference(nsStyleContext* aNewContext,
|
2015-08-28 23:13:47 +03:00
|
|
|
uint32_t* aEqualStructs,
|
|
|
|
uint32_t* aSamePointerStructs);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2016-07-29 05:20:45 +03:00
|
|
|
/**
|
|
|
|
* Like the above, but allows comparing ServoComputedValues instead of needing
|
|
|
|
* a full-fledged style context.
|
2016-07-26 22:14:39 +03:00
|
|
|
*/
|
2016-10-18 07:29:03 +03:00
|
|
|
nsChangeHint CalcStyleDifference(const ServoComputedValues* aNewComputedValues,
|
2016-07-26 22:14:39 +03:00
|
|
|
uint32_t* aEqualStructs,
|
|
|
|
uint32_t* aSamePointerStructs);
|
|
|
|
|
2016-07-26 21:54:05 +03:00
|
|
|
private:
|
2017-02-03 23:06:57 +03:00
|
|
|
template<class StyleContextLike>
|
2016-07-26 21:54:05 +03:00
|
|
|
nsChangeHint CalcStyleDifferenceInternal(StyleContextLike* aNewContext,
|
|
|
|
uint32_t* aEqualStructs,
|
|
|
|
uint32_t* aSamePointerStructs);
|
|
|
|
|
2016-07-29 05:20:45 +03:00
|
|
|
public:
|
2017-03-21 11:33:05 +03:00
|
|
|
/**
|
|
|
|
* Ensures the same structs are cached on this style context as would be
|
|
|
|
* done if we called aOther->CalcDifference(this).
|
|
|
|
*/
|
|
|
|
void EnsureSameStructsCached(nsStyleContext* aOldContext);
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
/**
|
|
|
|
* Get a color that depends on link-visitedness using this and
|
|
|
|
* this->GetStyleIfVisited().
|
|
|
|
*
|
2016-12-30 16:57:37 +03:00
|
|
|
* @param aField A pointer to a member variable in a style struct.
|
|
|
|
* The member variable and its style struct must have
|
|
|
|
* been listed in nsCSSVisitedDependentPropList.h.
|
2010-04-03 05:58:25 +04:00
|
|
|
*/
|
2016-12-30 16:57:37 +03:00
|
|
|
template<typename T, typename S>
|
|
|
|
nscolor GetVisitedDependentColor(T S::* aField);
|
2010-04-03 05:58:25 +04:00
|
|
|
|
2010-04-03 05:58:26 +04: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 10:19:26 +04:00
|
|
|
bool aLinkIsVisited);
|
2010-04-03 05:58:26 +04:00
|
|
|
|
2011-02-05 06:43:13 +03:00
|
|
|
/**
|
|
|
|
* Start the background image loads for this style context.
|
|
|
|
*/
|
|
|
|
void StartBackgroundImageLoads() {
|
|
|
|
// Just get our background struct; that should do the trick
|
2013-02-17 01:51:02 +04:00
|
|
|
StyleBackground();
|
2011-02-05 06:43:13 +03:00
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
/**
|
|
|
|
* Moves this style context to a new parent.
|
|
|
|
*
|
|
|
|
* This function violates style context tree immutability, and
|
|
|
|
* is a very low-level function and should only be used after verifying
|
|
|
|
* many conditions that make it safe to call.
|
|
|
|
*/
|
|
|
|
void MoveTo(nsStyleContext* aNewParent);
|
|
|
|
|
2014-09-05 07:48:46 +04:00
|
|
|
/**
|
|
|
|
* Swaps owned style struct pointers between this and aNewContext, on
|
|
|
|
* the assumption that aNewContext is the new style context for a frame
|
|
|
|
* and this is the old one. aStructs indicates which structs to consider
|
|
|
|
* swapping; only those which are owned in both this and aNewContext
|
|
|
|
* will be swapped.
|
|
|
|
*
|
|
|
|
* Additionally, if there are identical struct pointers for one of the
|
|
|
|
* structs indicated by aStructs, and it is not an owned struct on this,
|
|
|
|
* then the cached struct slot on this will be set to null. If the struct
|
|
|
|
* has been swapped on an ancestor, this style context (being the old one)
|
|
|
|
* will be left caching the struct pointer on the new ancestor, despite
|
|
|
|
* inheriting from the old ancestor. This is not normally a problem, as
|
|
|
|
* this style context will usually be destroyed by being released at the
|
|
|
|
* end of ElementRestyler::Restyle; but for style contexts held on to outside
|
|
|
|
* of the frame, we need to clear out the cached pointer so that if we need
|
|
|
|
* it again we'll re-fetch it from the new ancestor.
|
|
|
|
*/
|
|
|
|
void SwapStyleData(nsStyleContext* aNewContext, uint32_t aStructs);
|
|
|
|
|
2014-09-05 07:48:47 +04:00
|
|
|
/**
|
|
|
|
* On each descendant of this style context, clears out any cached inherited
|
|
|
|
* structs indicated in aStructs.
|
|
|
|
*/
|
|
|
|
void ClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);
|
|
|
|
|
2015-04-29 07:47:15 +03:00
|
|
|
/**
|
|
|
|
* Sets the NS_STYLE_INELIGIBLE_FOR_SHARING bit on this style context
|
|
|
|
* and its descendants. If it finds a descendant that has the bit
|
|
|
|
* already set, assumes that it can skip that subtree.
|
|
|
|
*/
|
|
|
|
void SetIneligibleForSharing();
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
#ifdef DEBUG
|
2014-11-27 09:29:45 +03:00
|
|
|
void List(FILE* out, int32_t aIndent, bool aListDescendants = true);
|
2014-09-25 09:45:36 +04:00
|
|
|
static const char* StructName(nsStyleStructID aSID);
|
2014-10-01 03:13:57 +04:00
|
|
|
static bool LookupStruct(const nsACString& aName, nsStyleStructID& aResult);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
nsCString GetCachedStyleDataAsString(uint32_t aStructs);
|
|
|
|
void LogStyleContextTree(int32_t aLoggingDepth, uint32_t aStructs);
|
|
|
|
int32_t& LoggingDepth();
|
2003-02-22 03:32:13 +03:00
|
|
|
#endif
|
|
|
|
|
2015-10-20 06:42:28 +03:00
|
|
|
/**
|
|
|
|
* Return style data that is currently cached on the style context.
|
|
|
|
* Only returns the structs we cache ourselves; never consults the
|
|
|
|
* rule tree.
|
|
|
|
*
|
|
|
|
* For "internal" use only in nsStyleContext and nsRuleNode.
|
|
|
|
*/
|
|
|
|
const void* GetCachedStyleData(nsStyleStructID aSID)
|
|
|
|
{
|
|
|
|
const void* cachedData;
|
|
|
|
if (nsCachedStyleData::IsReset(aSID)) {
|
|
|
|
if (mCachedResetData) {
|
|
|
|
cachedData = mCachedResetData->mStyleStructs[aSID];
|
|
|
|
} else {
|
|
|
|
cachedData = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cachedData = mCachedInheritedData.mStyleStructs[aSID];
|
|
|
|
}
|
|
|
|
return cachedData;
|
|
|
|
}
|
|
|
|
|
2016-03-18 23:14:07 +03:00
|
|
|
mozilla::NonOwningStyleContextSource StyleSource() const { return mSource.AsRaw(); }
|
|
|
|
|
2014-06-19 07:19:39 +04:00
|
|
|
private:
|
2014-06-24 22:00:57 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
|
|
|
~nsStyleContext();
|
|
|
|
|
2016-03-19 02:56:47 +03:00
|
|
|
// Delegated Helper constructor.
|
|
|
|
nsStyleContext(nsStyleContext* aParent,
|
|
|
|
mozilla::OwningStyleContextSource&& aSource,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
mozilla::CSSPseudoElementType aPseudoType);
|
|
|
|
|
|
|
|
// Helper post-contruct hook.
|
2017-04-25 07:52:51 +03:00
|
|
|
void FinishConstruction();
|
2016-03-19 02:56:47 +03:00
|
|
|
|
2010-04-07 01:52:17 +04:00
|
|
|
void AddChild(nsStyleContext* aChild);
|
|
|
|
void RemoveChild(nsStyleContext* aChild);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2015-02-26 08:18:15 +03:00
|
|
|
void* GetUniqueStyleData(const nsStyleStructID& aSID);
|
2015-02-26 08:18:15 +03:00
|
|
|
void* CreateEmptyStyleData(const nsStyleStructID& aSID);
|
|
|
|
|
2016-05-20 06:50:46 +03:00
|
|
|
void SetStyleBits();
|
2017-04-25 07:52:51 +03:00
|
|
|
|
|
|
|
// Only called for Gecko-backed nsStyleContexts.
|
2014-06-16 17:55:00 +04:00
|
|
|
void ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2016-03-19 02:56:47 +03:00
|
|
|
const void* StyleStructFromServoComputedValues(nsStyleStructID aSID) {
|
2016-04-27 05:34:49 +03:00
|
|
|
switch (aSID) {
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
case eStyleStruct_##name_: \
|
|
|
|
return Servo_GetStyle##name_(mSource.AsServoComputedValues());
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected nsStyleStructID value");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-03-19 02:56:47 +03:00
|
|
|
}
|
|
|
|
|
2015-02-07 05:25:21 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
struct AutoCheckDependency {
|
|
|
|
|
|
|
|
nsStyleContext* mStyleContext;
|
|
|
|
nsStyleStructID mOuterSID;
|
|
|
|
|
|
|
|
AutoCheckDependency(nsStyleContext* aContext, nsStyleStructID aInnerSID)
|
|
|
|
: mStyleContext(aContext)
|
|
|
|
{
|
|
|
|
mOuterSID = aContext->mComputingStruct;
|
|
|
|
MOZ_ASSERT(mOuterSID == nsStyleStructID_None ||
|
|
|
|
DependencyAllowed(mOuterSID, aInnerSID),
|
|
|
|
"Undeclared dependency, see generate-stylestructlist.py");
|
|
|
|
aContext->mComputingStruct = aInnerSID;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoCheckDependency()
|
|
|
|
{
|
|
|
|
mStyleContext->mComputingStruct = mOuterSID;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#define AUTO_CHECK_DEPENDENCY(sid_) \
|
|
|
|
AutoCheckDependency checkNesting_(this, sid_)
|
|
|
|
#else
|
|
|
|
#define AUTO_CHECK_DEPENDENCY(sid_)
|
|
|
|
#endif
|
|
|
|
|
2010-03-03 02:27:21 +03:00
|
|
|
// Helper functions for GetStyle* and PeekStyle*
|
2013-04-02 05:45:48 +04:00
|
|
|
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
|
2015-04-15 01:55:56 +03:00
|
|
|
template<bool aComputeData> \
|
|
|
|
const nsStyle##name_ * DoGetStyle##name_() { \
|
2016-04-27 05:34:49 +03:00
|
|
|
if (mSource.IsGeckoRuleNode()) { \
|
2017-02-21 18:56:43 +03:00
|
|
|
const nsStyle##name_ * cachedData = \
|
|
|
|
static_cast<nsStyle##name_*>( \
|
|
|
|
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]); \
|
|
|
|
if (cachedData) /* Have it cached already, yay */ \
|
|
|
|
return cachedData; \
|
|
|
|
if (!aComputeData) { \
|
|
|
|
/* We always cache inherited structs on the context when we */\
|
|
|
|
/* compute them. */ \
|
|
|
|
return nullptr; \
|
2016-08-20 00:32:51 +03:00
|
|
|
} \
|
2017-02-21 18:56:43 +03:00
|
|
|
/* Have the rulenode deal */ \
|
|
|
|
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
|
|
|
|
const nsStyle##name_ * newData = \
|
|
|
|
mSource.AsGeckoRuleNode()-> \
|
|
|
|
GetStyle##name_<aComputeData>(this, mBits); \
|
|
|
|
/* always cache inherited data on the style context; the rule */\
|
|
|
|
/* node set the bit in mBits for us if needed. */ \
|
|
|
|
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_] = \
|
|
|
|
const_cast<nsStyle##name_ *>(newData); \
|
|
|
|
return newData; \
|
|
|
|
} \
|
|
|
|
/** \
|
2017-04-28 16:03:05 +03:00
|
|
|
* Also (conservatively) set the owning bit in the parent style \
|
|
|
|
* context if we're a text node. \
|
2017-02-21 18:56:43 +03:00
|
|
|
* \
|
|
|
|
* This causes the parent element's style context to cache any \
|
|
|
|
* inherited structs we request for a text node, which means we \
|
|
|
|
* don't have to compute change hints for the text node, as \
|
|
|
|
* handling the change on the parent element is sufficient. \
|
|
|
|
* \
|
2017-04-28 16:03:05 +03:00
|
|
|
* Note, however, that we still need to request the style struct \
|
|
|
|
* of the text node itself, since we may run some fixups on it, \
|
|
|
|
* like for text-combine. \
|
2017-02-21 18:56:43 +03:00
|
|
|
* \
|
2017-04-28 16:03:05 +03:00
|
|
|
* This model is sound because for the fixed-up values to change, \
|
|
|
|
* other properties on the parent need to change too, and we'll \
|
|
|
|
* handle those change hints correctly. \
|
2017-02-21 18:56:43 +03:00
|
|
|
* \
|
2017-04-28 16:03:05 +03:00
|
|
|
* TODO(emilio): Perhaps we should remove those fixups and handle \
|
|
|
|
* those in layout instead. Those fixups are kind of expensive \
|
|
|
|
* for style sharing, and computed style of text nodes is not \
|
|
|
|
* observable. If we do that, we could assert here that the \
|
|
|
|
* inherited structs of both are the same. \
|
2017-02-21 18:56:43 +03:00
|
|
|
*/ \
|
2017-04-28 16:03:05 +03:00
|
|
|
if (mPseudoTag == nsCSSAnonBoxes::mozText && aComputeData) { \
|
2017-02-21 18:56:43 +03:00
|
|
|
MOZ_ASSERT(mParent); \
|
2017-04-28 16:03:05 +03:00
|
|
|
mParent->AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
|
2017-02-21 18:56:43 +03:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
|
|
|
|
if (!aComputeData && needToCompute) { \
|
|
|
|
return nullptr; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
const nsStyle##name_* data = \
|
|
|
|
Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
|
|
|
/* perform any remaining main thread work on the struct */ \
|
|
|
|
if (needToCompute) { \
|
2017-03-21 00:43:42 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread()); \
|
|
|
|
MOZ_ASSERT(!mozilla::ServoStyleSet::IsInServoTraversal()); \
|
2017-02-21 18:56:43 +03:00
|
|
|
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
|
2016-04-27 05:34:49 +03:00
|
|
|
/* the Servo-backed StyleContextSource owns the struct */ \
|
|
|
|
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
|
|
|
|
} \
|
2017-02-21 18:56:43 +03:00
|
|
|
return data; \
|
2010-03-03 02:27:21 +03:00
|
|
|
}
|
2017-02-21 18:56:43 +03:00
|
|
|
|
2013-04-02 05:45:48 +04:00
|
|
|
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
|
2015-04-15 01:55:56 +03:00
|
|
|
template<bool aComputeData> \
|
|
|
|
const nsStyle##name_ * DoGetStyle##name_() { \
|
2016-04-27 05:34:49 +03:00
|
|
|
if (mSource.IsGeckoRuleNode()) { \
|
2017-02-21 18:56:43 +03:00
|
|
|
if (mCachedResetData) { \
|
|
|
|
const nsStyle##name_ * cachedData = \
|
|
|
|
static_cast<nsStyle##name_*>( \
|
|
|
|
mCachedResetData->mStyleStructs[eStyleStruct_##name_]); \
|
|
|
|
if (cachedData) /* Have it cached already, yay */ \
|
|
|
|
return cachedData; \
|
|
|
|
} \
|
|
|
|
/* Have the rulenode deal */ \
|
|
|
|
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
|
|
|
|
return mSource.AsGeckoRuleNode()-> \
|
2016-04-27 05:34:49 +03:00
|
|
|
GetStyle##name_<aComputeData>(this); \
|
2017-02-21 18:56:43 +03:00
|
|
|
} \
|
|
|
|
const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
|
|
|
|
if (!aComputeData && needToCompute) { \
|
|
|
|
return nullptr; \
|
|
|
|
} \
|
|
|
|
const nsStyle##name_* data = \
|
|
|
|
Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
|
|
|
/* perform any remaining main thread work on the struct */ \
|
|
|
|
if (needToCompute) { \
|
|
|
|
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
|
|
|
|
/* the Servo-backed StyleContextSource owns the struct */ \
|
2016-04-27 05:34:49 +03:00
|
|
|
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \
|
|
|
|
} \
|
2017-02-21 18:56:43 +03:00
|
|
|
return data; \
|
2010-03-03 02:27:21 +03:00
|
|
|
}
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
|
2014-09-05 07:48:47 +04:00
|
|
|
// Helper for ClearCachedInheritedStyleDataOnDescendants.
|
|
|
|
void DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);
|
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertStructsNotUsedElsewhere(nsStyleContext* aDestroyingContext,
|
|
|
|
int32_t aLevels) const;
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 03:13:57 +04:00
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
void LogStyleContextTree(bool aFirst, uint32_t aStructs);
|
|
|
|
|
|
|
|
// This only gets called under call trees where we've already checked
|
|
|
|
// that PresContext()->RestyleManager()->ShouldLogRestyle() returned true.
|
|
|
|
// It exists here just to satisfy LOG_RESTYLE's expectations.
|
|
|
|
bool ShouldLogRestyle() { return true; }
|
|
|
|
#endif
|
|
|
|
|
2016-03-25 19:48:52 +03:00
|
|
|
RefPtr<nsStyleContext> mParent;
|
2005-02-05 08:24:21 +03:00
|
|
|
|
2006-04-28 04:09:05 +04: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 08:24:21 +03: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 03:32:13 +03:00
|
|
|
nsStyleContext* mChild;
|
|
|
|
nsStyleContext* mEmptyChild;
|
|
|
|
nsStyleContext* mPrevSibling;
|
|
|
|
nsStyleContext* mNextSibling;
|
|
|
|
|
2010-04-03 05:58:25 +04: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()).
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStyleContext> mStyleIfVisited;
|
2010-04-03 05:58:25 +04:00
|
|
|
|
2009-10-30 00:17:56 +03:00
|
|
|
// If this style context is for a pseudo-element or anonymous box,
|
|
|
|
// the relevant atom.
|
2003-02-22 03:32:13 +03:00
|
|
|
nsCOMPtr<nsIAtom> mPseudoTag;
|
|
|
|
|
2016-03-19 02:56:47 +03:00
|
|
|
// The source for our style data, either a Gecko nsRuleNode or a Servo
|
|
|
|
// ComputedValues struct. This never changes after construction, except
|
|
|
|
// when it's released and nulled out during teardown.
|
|
|
|
const mozilla::OwningStyleContextSource mSource;
|
|
|
|
|
|
|
|
#ifdef MOZ_STYLO
|
|
|
|
// In Gecko, we can get this off the rule node. We make this conditional
|
|
|
|
// on stylo builds to avoid the memory bloat on release.
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
#endif
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2010-03-03 02:27:21 +03: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|
|
2015-10-23 02:57:36 +03:00
|
|
|
// is set for a struct, that means that the pointer for that struct is
|
2016-03-19 02:56:47 +03:00
|
|
|
// owned by an ancestor or by the rule node rather than by this style context.
|
2015-10-23 02:57:36 +03: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.
|
2010-03-03 02:27:21 +03:00
|
|
|
nsResetStyleData* mCachedResetData; // Cached reset style data.
|
|
|
|
nsInheritedStyleData mCachedInheritedData; // Cached inherited style data
|
2015-10-20 06:42:28 +03:00
|
|
|
|
|
|
|
// mBits stores a number of things:
|
2015-10-23 02:57:36 +03:00
|
|
|
// - It records (using the style struct bits) which structs are
|
2016-03-19 02:56:47 +03:00
|
|
|
// inherited from the parent context or owned by the rule node (i.e.,
|
2015-10-23 02:57:36 +03:00
|
|
|
// not owned by the style context).
|
2015-10-20 06:42:28 +03:00
|
|
|
// - It also stores the additional bits listed at the top of
|
|
|
|
// nsStyleStruct.h.
|
|
|
|
uint64_t mBits;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mRefCnt;
|
2015-02-07 05:25:21 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-02-18 01:28:53 +03:00
|
|
|
uint32_t mFrameRefCnt; // number of frames that use this
|
|
|
|
// as their style context
|
|
|
|
|
2015-02-07 05:25:21 +03:00
|
|
|
nsStyleStructID mComputingStruct;
|
|
|
|
|
2015-02-07 05:25:21 +03:00
|
|
|
static bool DependencyAllowed(nsStyleStructID aOuterSID,
|
|
|
|
nsStyleStructID aInnerSID)
|
|
|
|
{
|
|
|
|
return !!(sDependencyTable[aOuterSID] &
|
|
|
|
nsCachedStyleData::GetBitForSID(aInnerSID));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t sDependencyTable[];
|
|
|
|
#endif
|
2003-02-22 03:32:13 +03:00
|
|
|
};
|
|
|
|
|
2010-04-07 01:52:17 +04:00
|
|
|
already_AddRefed<nsStyleContext>
|
2003-02-22 03:32:13 +03:00
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2016-02-17 23:37:00 +03:00
|
|
|
mozilla::CSSPseudoElementType aPseudoType,
|
2013-02-21 11:34:58 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
bool aSkipParentDisplayBasedStyleFixup);
|
2016-03-19 02:56:47 +03:00
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
mozilla::CSSPseudoElementType aPseudoType,
|
2017-04-25 07:52:51 +03:00
|
|
|
already_AddRefed<ServoComputedValues> aComputedValues);
|
2016-03-19 02:56:47 +03:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
#endif
|