2001-09-25 05:32:19 +04: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/. */
|
2001-02-07 12:57:26 +03:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsString.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
#include "nsRuleNode.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2014-09-05 07:48:45 +04:00
|
|
|
#include "nsIDocument.h"
|
2014-11-27 10:39:43 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2005-04-29 19:44:38 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef DEBUG
|
2001-06-01 02:19:43 +04:00
|
|
|
// #define NOISY_DEBUG
|
2001-05-03 17:20:48 +04:00
|
|
|
#endif
|
|
|
|
|
2012-08-05 05:01:19 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
//----------------------------------------------------------------------
|
2001-05-03 17:20:48 +04:00
|
|
|
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext::nsStyleContext(nsStyleContext* aParent,
|
2001-12-02 03:44:45 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2013-02-21 11:34:58 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
bool aSkipParentDisplayBasedStyleFixup)
|
2005-02-05 08:24:21 +03:00
|
|
|
: mParent(aParent),
|
2012-07-30 18:20:58 +04:00
|
|
|
mChild(nullptr),
|
|
|
|
mEmptyChild(nullptr),
|
2001-06-01 02:19:43 +04:00
|
|
|
mPseudoTag(aPseudoTag),
|
2001-12-02 03:44:45 +03:00
|
|
|
mRuleNode(aRuleNode),
|
2012-07-30 18:20:58 +04:00
|
|
|
mCachedResetData(nullptr),
|
2013-12-12 06:09:40 +04:00
|
|
|
mBits(((uint64_t)aPseudoType) << NS_STYLE_CONTEXT_TYPE_SHIFT),
|
2003-02-22 03:32:13 +03:00
|
|
|
mRefCnt(0)
|
1999-09-04 03:34:20 +04:00
|
|
|
{
|
2012-02-23 20:19:00 +04:00
|
|
|
// This check has to be done "backward", because if it were written the
|
|
|
|
// more natural way it wouldn't fail even when it needed to.
|
2013-12-12 06:09:40 +04:00
|
|
|
static_assert((UINT64_MAX >> NS_STYLE_CONTEXT_TYPE_SHIFT) >=
|
2013-07-18 21:59:53 +04:00
|
|
|
nsCSSPseudoElements::ePseudo_MAX,
|
2013-12-12 06:09:40 +04:00
|
|
|
"pseudo element bits no longer fit in a uint64_t");
|
2013-02-17 01:04:53 +04:00
|
|
|
MOZ_ASSERT(aRuleNode);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
mNextSibling = this;
|
|
|
|
mPrevSibling = this;
|
2001-12-02 03:44:45 +03:00
|
|
|
if (mParent) {
|
2003-02-22 03:32:13 +03:00
|
|
|
mParent->AddRef();
|
2006-04-28 04:09:05 +04:00
|
|
|
mParent->AddChild(this);
|
2009-01-17 00:32:09 +03:00
|
|
|
#ifdef DEBUG
|
2013-02-17 01:04:53 +04:00
|
|
|
nsRuleNode *r1 = mParent->RuleNode(), *r2 = aRuleNode;
|
2009-01-17 00:32:09 +03:00
|
|
|
while (r1->GetParent())
|
|
|
|
r1 = r1->GetParent();
|
|
|
|
while (r2->GetParent())
|
|
|
|
r2 = r2->GetParent();
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(r1 == r2, "must be in the same rule tree as parent");
|
2009-01-17 00:32:09 +03:00
|
|
|
#endif
|
1999-02-27 10:11:42 +03:00
|
|
|
}
|
2001-05-03 17:20:48 +04:00
|
|
|
|
2012-11-07 23:55:53 +04:00
|
|
|
mRuleNode->AddRef();
|
|
|
|
mRuleNode->SetUsedDirectly(); // before ApplyStyleFixups()!
|
|
|
|
|
2014-06-16 17:55:00 +04:00
|
|
|
ApplyStyleFixups(aSkipParentDisplayBasedStyleFixup);
|
2002-07-09 08:10:10 +04:00
|
|
|
|
2006-04-28 04:09:05 +04:00
|
|
|
#define eStyleStruct_LastItem (nsStyleStructID_Length - 1)
|
|
|
|
NS_ASSERTION(NS_STYLE_INHERIT_MASK & NS_STYLE_INHERIT_BIT(LastItem),
|
2002-07-09 08:10:10 +04:00
|
|
|
"NS_STYLE_INHERIT_MASK must be bigger, and other bits shifted");
|
2006-04-28 04:09:05 +04:00
|
|
|
#undef eStyleStruct_LastItem
|
2001-05-03 17:20:48 +04:00
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nsStyleContext::~nsStyleContext()
|
2001-05-03 17:20:48 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION((nullptr == mChild) && (nullptr == mEmptyChild), "destructing context with children");
|
2001-05-03 17:20:48 +04:00
|
|
|
|
2013-02-17 01:04:54 +04:00
|
|
|
nsPresContext *presContext = mRuleNode->PresContext();
|
2014-10-03 08:53:23 +04:00
|
|
|
nsStyleSet* styleSet = presContext->PresShell()->StyleSet();
|
|
|
|
|
|
|
|
NS_ASSERTION(styleSet->GetRuleTree() == mRuleNode->RuleTree() ||
|
|
|
|
styleSet->IsInRuleTreeReconstruct(),
|
|
|
|
"destroying style context from old rule tree too late");
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#if 0
|
|
|
|
// Assert that the style structs we are about to destroy are not referenced
|
|
|
|
// anywhere else in the style context tree. These checks are expensive,
|
|
|
|
// which is why they are not enabled even #ifdef DEBUG.
|
|
|
|
nsStyleContext* root = this;
|
|
|
|
while (root->mParent) {
|
|
|
|
root = root->mParent;
|
|
|
|
}
|
|
|
|
root->AssertStructsNotUsedElsewhere(this,
|
|
|
|
std::numeric_limits<int32_t>::max());
|
|
|
|
#else
|
|
|
|
// In DEBUG builds we perform a more limited check just of the children
|
|
|
|
// of this style context.
|
|
|
|
AssertStructsNotUsedElsewhere(this, 2);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-09-24 21:59:43 +04:00
|
|
|
mRuleNode->Release();
|
|
|
|
|
2014-10-03 08:53:23 +04:00
|
|
|
styleSet->NotifyStyleContextDestroyed(presContext, this);
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
if (mParent) {
|
|
|
|
mParent->RemoveChild(this);
|
2003-02-22 03:32:13 +03:00
|
|
|
mParent->Release();
|
1999-02-27 10:11:42 +03:00
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Free up our data structs.
|
2010-03-03 02:27:21 +03:00
|
|
|
mCachedInheritedData.DestroyStructs(mBits, presContext);
|
|
|
|
if (mCachedResetData) {
|
|
|
|
mCachedResetData->Destroy(mBits, presContext);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsStyleContext::AssertStructsNotUsedElsewhere(
|
|
|
|
nsStyleContext* aDestroyingContext,
|
|
|
|
int32_t aLevels) const
|
|
|
|
{
|
|
|
|
if (aLevels == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* data;
|
|
|
|
|
2014-09-05 07:48:47 +04:00
|
|
|
if (mBits & NS_STYLE_IS_GOING_AWAY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
if (this != aDestroyingContext) {
|
|
|
|
nsInheritedStyleData& destroyingInheritedData =
|
|
|
|
aDestroyingContext->mCachedInheritedData;
|
|
|
|
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb) \
|
|
|
|
data = destroyingInheritedData.mStyleStructs[eStyleStruct_##name_]; \
|
|
|
|
if (data && \
|
|
|
|
!(aDestroyingContext->mBits & NS_STYLE_INHERIT_BIT(name_)) && \
|
|
|
|
(mCachedInheritedData.mStyleStructs[eStyleStruct_##name_] == data)) { \
|
2014-09-25 09:45:36 +04:00
|
|
|
printf_stderr("style struct %p found on style context %p\n", data, this);\
|
2014-09-05 07:48:45 +04:00
|
|
|
nsString url; \
|
|
|
|
PresContext()->Document()->GetURL(url); \
|
2014-09-25 09:45:36 +04:00
|
|
|
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
|
2014-09-05 07:48:45 +04:00
|
|
|
MOZ_ASSERT(false, "destroying " #name_ " style struct still present " \
|
|
|
|
"in style context tree"); \
|
|
|
|
}
|
|
|
|
#define STYLE_STRUCT_RESET(name_, checkdata_cb)
|
|
|
|
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
|
|
|
|
if (mCachedResetData) {
|
|
|
|
nsResetStyleData* destroyingResetData =
|
|
|
|
aDestroyingContext->mCachedResetData;
|
|
|
|
if (destroyingResetData) {
|
|
|
|
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_)
|
|
|
|
#define STYLE_STRUCT_RESET(name_, checkdata_cb) \
|
|
|
|
data = destroyingResetData->mStyleStructs[eStyleStruct_##name_]; \
|
|
|
|
if (data && \
|
|
|
|
!(aDestroyingContext->mBits & NS_STYLE_INHERIT_BIT(name_)) && \
|
|
|
|
(mCachedResetData->mStyleStructs[eStyleStruct_##name_] == data)) { \
|
2014-09-25 09:45:36 +04:00
|
|
|
printf_stderr("style struct %p found on style context %p\n", data, \
|
|
|
|
this); \
|
2014-09-05 07:48:45 +04:00
|
|
|
nsString url; \
|
|
|
|
PresContext()->Document()->GetURL(url); \
|
2014-09-25 09:45:36 +04:00
|
|
|
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
|
2014-09-05 07:48:45 +04:00
|
|
|
MOZ_ASSERT(false, "destroying " #name_ " style struct still present "\
|
|
|
|
"in style context tree"); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mChild) {
|
|
|
|
const nsStyleContext* child = mChild;
|
|
|
|
do {
|
|
|
|
child->AssertStructsNotUsedElsewhere(aDestroyingContext, aLevels - 1);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (child != mChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEmptyChild) {
|
|
|
|
const nsStyleContext* child = mEmptyChild;
|
|
|
|
do {
|
|
|
|
child->AssertStructsNotUsedElsewhere(aDestroyingContext, aLevels - 1);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (child != mEmptyChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-28 04:09:05 +04:00
|
|
|
void nsStyleContext::AddChild(nsStyleContext* aChild)
|
2001-02-07 12:57:26 +03:00
|
|
|
{
|
2006-04-28 04:09:05 +04:00
|
|
|
NS_ASSERTION(aChild->mPrevSibling == aChild &&
|
|
|
|
aChild->mNextSibling == aChild,
|
|
|
|
"child already in a child list");
|
|
|
|
|
2013-05-06 19:05:44 +04:00
|
|
|
nsStyleContext **listPtr = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
|
|
|
// Explicitly dereference listPtr so that compiler doesn't have to know that mNextSibling
|
|
|
|
// etc. don't alias with what ever listPtr points at.
|
|
|
|
nsStyleContext *list = *listPtr;
|
2006-04-28 04:09:05 +04:00
|
|
|
|
|
|
|
// Insert at the beginning of the list. See also FindChildWithRules.
|
2013-05-06 19:05:44 +04:00
|
|
|
if (list) {
|
2006-04-28 04:09:05 +04:00
|
|
|
// Link into existing elements, if there are any.
|
2013-05-06 19:05:44 +04:00
|
|
|
aChild->mNextSibling = list;
|
|
|
|
aChild->mPrevSibling = list->mPrevSibling;
|
|
|
|
list->mPrevSibling->mNextSibling = aChild;
|
|
|
|
list->mPrevSibling = aChild;
|
2001-02-07 12:57:26 +03:00
|
|
|
}
|
2013-05-06 19:05:44 +04:00
|
|
|
(*listPtr) = aChild;
|
2001-02-07 12:57:26 +03:00
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void nsStyleContext::RemoveChild(nsStyleContext* aChild)
|
2001-02-07 12:57:26 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aChild && this == aChild->mParent, "bad argument");
|
2001-02-07 12:57:26 +03:00
|
|
|
|
2006-04-28 04:09:05 +04:00
|
|
|
nsStyleContext **list = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
|
|
|
|
|
|
|
if (aChild->mPrevSibling != aChild) { // has siblings
|
|
|
|
if ((*list) == aChild) {
|
|
|
|
(*list) = (*list)->mNextSibling;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2006-04-28 04:09:05 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION((*list) == aChild, "bad sibling pointers");
|
2012-07-30 18:20:58 +04:00
|
|
|
(*list) = nullptr;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2006-04-28 04:09:05 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
aChild->mPrevSibling->mNextSibling = aChild->mNextSibling;
|
|
|
|
aChild->mNextSibling->mPrevSibling = aChild->mPrevSibling;
|
|
|
|
aChild->mNextSibling = aChild;
|
|
|
|
aChild->mPrevSibling = aChild;
|
1999-10-16 08:05:59 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:45 +04:00
|
|
|
void
|
|
|
|
nsStyleContext::MoveTo(nsStyleContext* aNewParent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNewParent != mParent);
|
|
|
|
|
|
|
|
// Assertions checking for visited style are just to avoid some tricky
|
|
|
|
// cases we can't be bothered handling at the moment.
|
|
|
|
MOZ_ASSERT(!IsStyleIfVisited());
|
|
|
|
MOZ_ASSERT(!aNewParent->IsStyleIfVisited());
|
|
|
|
|
|
|
|
nsStyleContext* oldParent = mParent;
|
|
|
|
|
|
|
|
aNewParent->AddRef();
|
|
|
|
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
|
|
|
|
mParent = aNewParent;
|
|
|
|
mParent->AddChild(this);
|
|
|
|
|
|
|
|
oldParent->Release();
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2001-06-01 02:19:43 +04:00
|
|
|
nsStyleContext::FindChildWithRules(const nsIAtom* aPseudoTag,
|
2010-04-03 05:58:26 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
|
|
|
nsRuleNode* aRulesIfVisited,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRelevantLinkVisited)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t threshold = 10; // The # of siblings we're willing to examine
|
2001-06-01 02:19:43 +04:00
|
|
|
// before just giving this whole thing up.
|
2001-05-03 17:20:48 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsStyleContext> result;
|
2006-04-28 04:09:05 +04:00
|
|
|
nsStyleContext *list = aRuleNode->IsRoot() ? mEmptyChild : mChild;
|
|
|
|
|
|
|
|
if (list) {
|
|
|
|
nsStyleContext *child = list;
|
|
|
|
do {
|
2010-04-03 05:58:26 +04:00
|
|
|
if (child->mRuleNode == aRuleNode &&
|
|
|
|
child->mPseudoTag == aPseudoTag &&
|
2010-04-06 23:42:41 +04:00
|
|
|
!child->IsStyleIfVisited() &&
|
2010-04-03 05:58:26 +04:00
|
|
|
child->RelevantLinkVisited() == aRelevantLinkVisited) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool match = false;
|
2010-04-03 05:58:26 +04:00
|
|
|
if (aRulesIfVisited) {
|
|
|
|
match = child->GetStyleIfVisited() &&
|
|
|
|
child->GetStyleIfVisited()->mRuleNode == aRulesIfVisited;
|
|
|
|
} else {
|
|
|
|
match = !child->GetStyleIfVisited();
|
|
|
|
}
|
|
|
|
if (match) {
|
|
|
|
result = child;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2006-04-28 04:09:05 +04:00
|
|
|
child = child->mNextSibling;
|
|
|
|
threshold--;
|
|
|
|
if (threshold == 0)
|
|
|
|
break;
|
|
|
|
} while (child != list);
|
1998-10-27 06:03:02 +03:00
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2006-04-28 04:09:05 +04:00
|
|
|
if (result) {
|
|
|
|
if (result != list) {
|
|
|
|
// Move result to the front of the list.
|
|
|
|
RemoveChild(result);
|
|
|
|
AddChild(result);
|
|
|
|
}
|
2014-09-05 07:48:44 +04:00
|
|
|
result->mBits |= NS_STYLE_IS_SHARED;
|
2006-04-28 04:09:05 +04:00
|
|
|
}
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return result.forget();
|
1998-06-05 10:01:55 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:44 +04:00
|
|
|
/* static */ bool
|
|
|
|
nsStyleContext::ListContainsStyleContextThatUsesGrandancestorStyle(const nsStyleContext* aHead)
|
|
|
|
{
|
|
|
|
if (aHead) {
|
|
|
|
const nsStyleContext* child = aHead;
|
|
|
|
do {
|
|
|
|
if (child->UsesGrandancestorStyle()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (child != aHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsStyleContext::HasChildThatUsesGrandancestorStyle() const
|
|
|
|
{
|
|
|
|
return ListContainsStyleContextThatUsesGrandancestorStyle(mEmptyChild) ||
|
|
|
|
ListContainsStyleContextThatUsesGrandancestorStyle(mChild);
|
|
|
|
}
|
|
|
|
|
2010-03-03 02:27:21 +03:00
|
|
|
const void* nsStyleContext::GetCachedStyleData(nsStyleStructID aSID)
|
1998-04-21 04:02:44 +04:00
|
|
|
{
|
2010-03-03 02:27:21 +03:00
|
|
|
const void* cachedData;
|
2011-03-18 06:14:32 +03:00
|
|
|
if (nsCachedStyleData::IsReset(aSID)) {
|
2010-03-03 02:27:21 +03:00
|
|
|
if (mCachedResetData) {
|
2011-03-18 06:14:32 +03:00
|
|
|
cachedData = mCachedResetData->mStyleStructs[aSID];
|
2010-03-03 02:27:21 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
cachedData = nullptr;
|
2010-03-03 02:27:21 +03:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-18 06:14:32 +03:00
|
|
|
cachedData = mCachedInheritedData.mStyleStructs[aSID];
|
2006-12-12 20:44:45 +03:00
|
|
|
}
|
2010-03-03 02:27:21 +03:00
|
|
|
return cachedData;
|
|
|
|
}
|
2006-12-12 20:44:45 +03:00
|
|
|
|
2013-02-17 01:51:03 +04:00
|
|
|
const void* nsStyleContext::StyleData(nsStyleStructID aSID)
|
2001-11-14 11:19:13 +03:00
|
|
|
{
|
2010-03-03 02:27:21 +03:00
|
|
|
const void* cachedData = GetCachedStyleData(aSID);
|
2001-11-14 11:19:13 +03:00
|
|
|
if (cachedData)
|
|
|
|
return cachedData; // We have computed data stored on this node in the context tree.
|
2011-10-17 18:59:28 +04:00
|
|
|
return mRuleNode->GetStyleData(aSID, this, true); // Our rule node will take care of it for us.
|
1999-02-27 10:11:42 +03:00
|
|
|
}
|
1998-12-07 21:51:26 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// This is an evil evil function, since it forces you to alloc your own separate copy of
|
|
|
|
// style data! Do not use this function unless you absolutely have to! You should avoid
|
|
|
|
// this at all costs! -dwh
|
2008-01-10 23:56:49 +03:00
|
|
|
void*
|
2004-02-09 09:55:14 +03:00
|
|
|
nsStyleContext::GetUniqueStyleData(const nsStyleStructID& aSID)
|
2000-06-22 00:44:59 +04:00
|
|
|
{
|
2004-02-09 09:55:14 +03:00
|
|
|
// If we already own the struct and no kids could depend on it, then
|
|
|
|
// just return it. (We leak in this case if there are kids -- and this
|
|
|
|
// function really shouldn't be called for style contexts that could
|
|
|
|
// have kids depending on the data. ClearStyleData would be OK, but
|
|
|
|
// this test for no mChild or mEmptyChild doesn't catch that case.)
|
2013-02-17 01:51:03 +04:00
|
|
|
const void *current = StyleData(aSID);
|
2004-02-09 09:55:14 +03:00
|
|
|
if (!mChild && !mEmptyChild &&
|
|
|
|
!(mBits & nsCachedStyleData::GetBitForSID(aSID)) &&
|
2010-03-03 02:27:21 +03:00
|
|
|
GetCachedStyleData(aSID))
|
2008-01-10 23:56:49 +03:00
|
|
|
return const_cast<void*>(current);
|
2004-02-09 09:55:14 +03:00
|
|
|
|
2008-01-10 23:56:49 +03:00
|
|
|
void* result;
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *presContext = PresContext();
|
2001-06-01 02:19:43 +04:00
|
|
|
switch (aSID) {
|
2004-02-09 09:55:14 +03:00
|
|
|
|
|
|
|
#define UNIQUE_CASE(c_) \
|
|
|
|
case eStyleStruct_##c_: \
|
|
|
|
result = new (presContext) nsStyle##c_( \
|
2007-07-11 12:46:44 +04:00
|
|
|
* static_cast<const nsStyle##c_ *>(current)); \
|
2001-12-14 06:47:02 +03:00
|
|
|
break;
|
2004-02-09 09:55:14 +03:00
|
|
|
|
|
|
|
UNIQUE_CASE(Display)
|
|
|
|
UNIQUE_CASE(Background)
|
|
|
|
UNIQUE_CASE(Text)
|
|
|
|
UNIQUE_CASE(TextReset)
|
|
|
|
|
|
|
|
#undef UNIQUE_CASE
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
default:
|
2010-06-18 00:28:38 +04:00
|
|
|
NS_ERROR("Struct type not supported. Please find another way to do this if you can!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2004-02-09 09:55:14 +03:00
|
|
|
SetStyle(aSID, result);
|
2013-12-12 06:09:40 +04:00
|
|
|
mBits &= ~static_cast<uint64_t>(nsCachedStyleData::GetBitForSID(aSID));
|
2004-02-09 09:55:14 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
return result;
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
2008-01-10 23:56:49 +03:00
|
|
|
nsStyleContext::SetStyle(nsStyleStructID aSID, void* aStruct)
|
2000-12-15 09:09:50 +03:00
|
|
|
{
|
2001-06-01 02:19:43 +04:00
|
|
|
// This method should only be called from nsRuleNode! It is not a public
|
|
|
|
// method!
|
|
|
|
|
2002-07-09 08:10:10 +04:00
|
|
|
NS_ASSERTION(aSID >= 0 && aSID < nsStyleStructID_Length, "out of bounds");
|
|
|
|
|
|
|
|
// NOTE: nsCachedStyleData::GetStyleData works roughly the same way.
|
2002-08-06 17:46:35 +04:00
|
|
|
// See the comments there (in nsRuleNode.h) for more details about
|
|
|
|
// what this is doing and why.
|
|
|
|
|
2011-03-18 06:14:32 +03:00
|
|
|
void** dataSlot;
|
2010-03-03 02:27:21 +03:00
|
|
|
if (nsCachedStyleData::IsReset(aSID)) {
|
|
|
|
if (!mCachedResetData) {
|
2013-02-17 01:04:54 +04:00
|
|
|
mCachedResetData = new (mRuleNode->PresContext()) nsResetStyleData;
|
2001-12-02 03:44:45 +03:00
|
|
|
}
|
2011-03-18 06:14:32 +03:00
|
|
|
dataSlot = &mCachedResetData->mStyleStructs[aSID];
|
2010-03-03 02:27:21 +03:00
|
|
|
} else {
|
2011-03-18 06:14:32 +03:00
|
|
|
dataSlot = &mCachedInheritedData.mStyleStructs[aSID];
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-03-18 06:14:32 +03:00
|
|
|
NS_ASSERTION(!*dataSlot || (mBits & nsCachedStyleData::GetBitForSID(aSID)),
|
2009-08-07 18:38:44 +04:00
|
|
|
"Going to leak style data");
|
2011-03-18 06:14:32 +03:00
|
|
|
*dataSlot = aStruct;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2001-07-25 10:33:06 +04:00
|
|
|
void
|
2014-06-16 17:55:00 +04:00
|
|
|
nsStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2001-07-25 10:33:06 +04:00
|
|
|
// See if we have any text decorations.
|
|
|
|
// First see if our parent has text decorations. If our parent does, then we inherit the bit.
|
2011-04-23 09:16:41 +04:00
|
|
|
if (mParent && mParent->HasTextDecorationLines()) {
|
|
|
|
mBits |= NS_STYLE_HAS_TEXT_DECORATION_LINES;
|
|
|
|
} else {
|
2001-07-25 10:33:06 +04:00
|
|
|
// We might have defined a decoration.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleTextReset* text = StyleTextReset();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t decorationLine = text->mTextDecorationLine;
|
2011-04-23 09:16:41 +04:00
|
|
|
if (decorationLine != NS_STYLE_TEXT_DECORATION_LINE_NONE &&
|
|
|
|
decorationLine != NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL) {
|
|
|
|
mBits |= NS_STYLE_HAS_TEXT_DECORATION_LINES;
|
|
|
|
}
|
2001-07-25 10:33:06 +04:00
|
|
|
}
|
|
|
|
|
2009-08-11 02:52:29 +04:00
|
|
|
if ((mParent && mParent->HasPseudoElementData()) || mPseudoTag) {
|
|
|
|
mBits |= NS_STYLE_HAS_PSEUDO_ELEMENT_DATA;
|
|
|
|
}
|
|
|
|
|
2005-07-20 16:03:15 +04:00
|
|
|
// Correct tables.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
2005-07-20 16:03:15 +04:00
|
|
|
if (disp->mDisplay == NS_STYLE_DISPLAY_TABLE) {
|
|
|
|
// -moz-center and -moz-right are used for HTML's alignment
|
|
|
|
// This is covering the <div align="right"><table>...</table></div> case.
|
|
|
|
// In this case, we don't want to inherit the text alignment into the table.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleText* text = StyleText();
|
2005-07-20 16:03:15 +04:00
|
|
|
|
|
|
|
if (text->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER ||
|
|
|
|
text->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT)
|
|
|
|
{
|
|
|
|
nsStyleText* uniqueText = (nsStyleText*)GetUniqueStyleData(eStyleStruct_Text);
|
|
|
|
uniqueText->mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-17 22:21:41 +04:00
|
|
|
// CSS2.1 section 9.2.4 specifies fixups for the 'display' property of
|
|
|
|
// the root element. We can't implement them in nsRuleNode because we
|
|
|
|
// don't want to store all display structs that aren't 'block',
|
|
|
|
// 'inline', or 'table' in the style context tree on the off chance
|
|
|
|
// that the root element has its style reresolved later. So do them
|
|
|
|
// here if needed, by changing the style data, so that other code
|
|
|
|
// doesn't get confused by looking at the style data.
|
|
|
|
if (!mParent) {
|
2014-02-15 22:42:37 +04:00
|
|
|
uint8_t displayVal = disp->mDisplay;
|
|
|
|
nsRuleNode::EnsureBlockDisplay(displayVal, true);
|
|
|
|
if (displayVal != disp->mDisplay) {
|
|
|
|
nsStyleDisplay *mutable_display =
|
|
|
|
static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
|
|
|
|
|
2011-10-29 11:04:20 +04:00
|
|
|
// If we're in this code, then mOriginalDisplay doesn't matter
|
|
|
|
// for purposes of the cascade (because this nsStyleDisplay
|
|
|
|
// isn't living in the ruletree anyway), and for determining
|
|
|
|
// hypothetical boxes it's better to have mOriginalDisplay
|
|
|
|
// matching mDisplay here.
|
2014-02-15 22:42:37 +04:00
|
|
|
mutable_display->mOriginalDisplay = mutable_display->mDisplay =
|
|
|
|
displayVal;
|
2004-07-17 22:21:41 +04:00
|
|
|
}
|
|
|
|
}
|
2004-12-31 00:56:11 +03:00
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
// Adjust the "display" values of flex and grid items (but not for raw text,
|
2012-11-07 23:28:59 +04:00
|
|
|
// placeholders, or table-parts). CSS3 Flexbox section 4 says:
|
|
|
|
// # The computed 'display' of a flex item is determined
|
|
|
|
// # by applying the table in CSS 2.1 Chapter 9.7.
|
|
|
|
// ...which converts inline-level elements to their block-level equivalents.
|
2014-07-23 06:08:13 +04:00
|
|
|
// Any direct children of elements with Ruby display values which are
|
|
|
|
// block-level are converted to their inline-level equivalents.
|
2014-06-16 17:55:00 +04:00
|
|
|
if (!aSkipParentDisplayBasedStyleFixup && mParent) {
|
2014-11-20 21:24:09 +03:00
|
|
|
// Skip display:contents ancestors to reach the potential container.
|
|
|
|
// (If there are only display:contents ancestors between this node and
|
|
|
|
// a flex/grid container ancestor, then this node is a flex/grid item, since
|
|
|
|
// its parent *in the frame tree* will be the flex/grid container. So we treat
|
|
|
|
// it like a flex/grid item here.)
|
|
|
|
nsStyleContext* containerContext = mParent;
|
|
|
|
const nsStyleDisplay* containerDisp = containerContext->StyleDisplay();
|
|
|
|
while (containerDisp->mDisplay == NS_STYLE_DISPLAY_CONTENTS) {
|
|
|
|
if (!containerContext->GetParent()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
containerContext = containerContext->GetParent();
|
|
|
|
containerDisp = containerContext->StyleDisplay();
|
|
|
|
}
|
|
|
|
if (containerDisp->IsFlexOrGridDisplayType() &&
|
2012-11-07 23:28:59 +04:00
|
|
|
GetPseudo() != nsCSSAnonBoxes::mozNonElement) {
|
|
|
|
uint8_t displayVal = disp->mDisplay;
|
|
|
|
// Skip table parts.
|
|
|
|
// NOTE: This list needs to be kept in sync with
|
|
|
|
// nsCSSFrameConstructor.cpp's "sDisplayData" array -- specifically,
|
|
|
|
// this should be the list of display-values that have
|
|
|
|
// FCDATA_DESIRED_PARENT_TYPE_TO_BITS specified in that array.
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CAPTION != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_ROW_GROUP != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_HEADER_GROUP != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_COLUMN != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_ROW != displayVal &&
|
|
|
|
NS_STYLE_DISPLAY_TABLE_CELL != displayVal) {
|
|
|
|
|
|
|
|
// NOTE: Technically, we shouldn't modify the 'display' value of
|
2014-05-03 17:42:33 +04:00
|
|
|
// positioned elements, since they aren't flex/grid items. However,
|
|
|
|
// we don't need to worry about checking for that, because if we're
|
|
|
|
// positioned, we'll have already been through a call to
|
|
|
|
// EnsureBlockDisplay() in nsRuleNode, so this call here won't change
|
|
|
|
// anything. So we're OK.
|
2012-11-07 23:28:59 +04:00
|
|
|
nsRuleNode::EnsureBlockDisplay(displayVal);
|
|
|
|
if (displayVal != disp->mDisplay) {
|
|
|
|
NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle(),
|
|
|
|
"We shouldn't be changing the display value of "
|
|
|
|
"positioned content (and we should have already "
|
|
|
|
"converted its display value to be block-level...)");
|
|
|
|
nsStyleDisplay *mutable_display =
|
|
|
|
static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
|
|
|
|
mutable_display->mDisplay = displayVal;
|
|
|
|
}
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
|
|
|
} else if (containerDisp->IsRubyDisplayType()) {
|
2014-07-23 06:08:13 +04:00
|
|
|
uint8_t displayVal = disp->mDisplay;
|
|
|
|
nsRuleNode::EnsureInlineDisplay(displayVal);
|
|
|
|
// The display change should only occur for "in-flow" children
|
|
|
|
if (displayVal != disp->mDisplay &&
|
|
|
|
!disp->IsOutOfFlowStyle()) {
|
|
|
|
nsStyleDisplay *mutable_display =
|
|
|
|
static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
|
|
|
|
mutable_display->mDisplay = displayVal;
|
2012-11-07 23:28:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-07 08:33:26 +04:00
|
|
|
// Compute User Interface style, to trigger loads of cursors
|
2013-02-17 01:51:02 +04:00
|
|
|
StyleUserInterface();
|
2001-07-25 10:33:06 +04:00
|
|
|
}
|
2001-07-19 02:48:35 +04:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsChangeHint
|
2012-09-07 21:13:36 +04:00
|
|
|
nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
|
2014-09-05 07:48:44 +04:00
|
|
|
nsChangeHint aParentHintsNotHandledForDescendants,
|
|
|
|
uint32_t* aEqualStructs)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsStyleContext", "CalcStyleDifference",
|
|
|
|
js::ProfileEntry::Category::CSS);
|
2012-09-15 01:12:34 +04:00
|
|
|
|
2012-09-07 21:13:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(NS_IsHintSubset(aParentHintsNotHandledForDescendants,
|
|
|
|
nsChangeHint_Hints_NotHandledForDescendants),
|
|
|
|
"caller is passing inherited hints, but shouldn't be");
|
|
|
|
|
2014-09-05 07:48:44 +04:00
|
|
|
static_assert(nsStyleStructID_Length <= 32,
|
|
|
|
"aEqualStructs is not big enough");
|
|
|
|
|
|
|
|
*aEqualStructs = 0;
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsChangeHint hint = NS_STYLE_HINT_NONE;
|
2003-03-16 03:20:21 +03:00
|
|
|
NS_ENSURE_TRUE(aOther, hint);
|
|
|
|
// We must always ensure that we populate the structs on the new style
|
|
|
|
// context that are filled in on the old context, so that if we get
|
|
|
|
// two style changes in succession, the second of which causes a real
|
2008-02-08 22:52:46 +03:00
|
|
|
// style change, the PeekStyleData doesn't return null (implying that
|
|
|
|
// nobody ever looked at that struct's data). In other words, we
|
|
|
|
// can't skip later structs if we get a big change up front, because
|
|
|
|
// we could later get a small change in one of those structs that we
|
|
|
|
// don't want to miss.
|
2003-03-16 03:20:21 +03:00
|
|
|
|
2012-09-07 21:13:36 +04:00
|
|
|
// If our rule nodes are the same, then any differences in style data
|
|
|
|
// are already accounted for by differences on ancestors. We know
|
|
|
|
// this because CalcStyleDifference is always called on two style
|
|
|
|
// contexts that point to the same element, so we know that our
|
|
|
|
// position in the style context tree is the same and our position in
|
|
|
|
// the rule node tree is also the same.
|
2012-09-07 21:13:36 +04:00
|
|
|
// However, if there were noninherited style change hints on the
|
|
|
|
// parent, we might produce these same noninherited hints on this
|
|
|
|
// style context's frame due to 'inherit' values, so we do need to
|
|
|
|
// compare.
|
|
|
|
// (Things like 'em' units are handled by the change hint produced
|
|
|
|
// by font-size changing, so we don't need to worry about them like
|
|
|
|
// we worry about 'inherit' values.)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool compare = mRuleNode != aOther->mRuleNode;
|
2013-12-12 06:09:45 +04:00
|
|
|
|
|
|
|
// If we had any change in variable values, then we'll need to examine
|
|
|
|
// all of the other style structs too, even if the new style context has
|
|
|
|
// the same rule node as the old one.
|
|
|
|
const nsStyleVariables* thisVariables = PeekStyleVariables();
|
|
|
|
if (thisVariables) {
|
|
|
|
const nsStyleVariables* otherVariables = aOther->StyleVariables();
|
2014-09-05 07:48:44 +04:00
|
|
|
if (thisVariables->mVariables == otherVariables->mVariables) {
|
|
|
|
*aEqualStructs |= nsCachedStyleData::GetBitForSID(eStyleStruct_Variables);
|
|
|
|
} else {
|
2013-12-12 06:09:45 +04:00
|
|
|
compare = true;
|
|
|
|
}
|
2014-09-05 07:48:44 +04:00
|
|
|
} else {
|
|
|
|
*aEqualStructs |= nsCachedStyleData::GetBitForSID(eStyleStruct_Variables);
|
2013-12-12 06:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugOnly<int> styleStructCount = 1; // count Variables already
|
2003-03-16 03:20:21 +03:00
|
|
|
|
2003-03-16 07:51:56 +03:00
|
|
|
#define DO_STRUCT_DIFFERENCE(struct_) \
|
|
|
|
PR_BEGIN_MACRO \
|
2010-03-03 02:27:21 +03:00
|
|
|
const nsStyle##struct_* this##struct_ = PeekStyle##struct_(); \
|
2003-03-16 07:51:56 +03:00
|
|
|
if (this##struct_) { \
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyle##struct_* other##struct_ = aOther->Style##struct_(); \
|
2012-09-07 21:13:36 +04:00
|
|
|
nsChangeHint maxDifference = nsStyle##struct_::MaxDifference(); \
|
2014-01-03 06:39:54 +04:00
|
|
|
nsChangeHint maxDifferenceNeverInherited = \
|
|
|
|
nsStyle##struct_::MaxDifferenceNeverInherited(); \
|
2014-09-05 07:48:44 +04:00
|
|
|
if (this##struct_ == other##struct_) { \
|
|
|
|
/* The very same struct, so we know that there will be no */ \
|
|
|
|
/* differences. */ \
|
|
|
|
*aEqualStructs |= NS_STYLE_INHERIT_BIT(struct_); \
|
|
|
|
} else if (compare || \
|
|
|
|
(NS_SubtractHint(maxDifference, \
|
|
|
|
maxDifferenceNeverInherited) & \
|
|
|
|
aParentHintsNotHandledForDescendants)) { \
|
|
|
|
nsChangeHint difference = \
|
|
|
|
this##struct_->CalcDifference(*other##struct_); \
|
|
|
|
NS_ASSERTION(NS_IsHintSubset(difference, maxDifference), \
|
|
|
|
"CalcDifference() returned bigger hint than " \
|
|
|
|
"MaxDifference()"); \
|
|
|
|
NS_UpdateHint(hint, difference); \
|
|
|
|
if (!difference) { \
|
|
|
|
*aEqualStructs |= NS_STYLE_INHERIT_BIT(struct_); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
/* We still must call CalcDifference to see if there were any */ \
|
|
|
|
/* changes so that we can set *aEqualStructs appropriately. */ \
|
|
|
|
nsChangeHint difference = \
|
|
|
|
this##struct_->CalcDifference(*other##struct_); \
|
|
|
|
NS_ASSERTION(NS_IsHintSubset(difference, maxDifference), \
|
|
|
|
"CalcDifference() returned bigger hint than " \
|
|
|
|
"MaxDifference()"); \
|
|
|
|
if (!difference) { \
|
|
|
|
*aEqualStructs |= NS_STYLE_INHERIT_BIT(struct_); \
|
|
|
|
} \
|
2003-03-16 07:51:56 +03:00
|
|
|
} \
|
2014-09-05 07:48:44 +04:00
|
|
|
} else { \
|
|
|
|
*aEqualStructs |= NS_STYLE_INHERIT_BIT(struct_); \
|
2003-03-16 07:51:56 +03:00
|
|
|
} \
|
2013-05-27 10:48:19 +04:00
|
|
|
styleStructCount++; \
|
2003-03-16 07:51:56 +03:00
|
|
|
PR_END_MACRO
|
|
|
|
|
2012-09-07 21:13:36 +04:00
|
|
|
// In general, we want to examine structs starting with those that can
|
|
|
|
// cause the largest style change, down to those that can cause the
|
|
|
|
// smallest. This lets us skip later ones if we already have a hint
|
|
|
|
// that subsumes their MaxDifference. (As the hints get
|
|
|
|
// finer-grained, this optimization is becoming less useful, though.)
|
2003-03-16 07:51:56 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Display);
|
|
|
|
DO_STRUCT_DIFFERENCE(XUL);
|
2004-06-17 15:57:37 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Column);
|
2003-03-16 07:51:56 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Content);
|
|
|
|
DO_STRUCT_DIFFERENCE(UserInterface);
|
|
|
|
DO_STRUCT_DIFFERENCE(Visibility);
|
2012-02-07 15:31:37 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Outline);
|
2004-09-11 10:13:47 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(TableBorder);
|
2004-10-01 07:33:05 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Table);
|
|
|
|
DO_STRUCT_DIFFERENCE(UIReset);
|
2009-06-13 13:16:34 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Text);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(List);
|
2003-03-16 07:51:56 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Quotes);
|
2008-08-06 04:55:07 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(SVGReset);
|
2008-10-01 04:51:05 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(SVG);
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-06 08:53:48 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Position);
|
2003-03-16 07:51:56 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Font);
|
|
|
|
DO_STRUCT_DIFFERENCE(Margin);
|
|
|
|
DO_STRUCT_DIFFERENCE(Padding);
|
|
|
|
DO_STRUCT_DIFFERENCE(Border);
|
|
|
|
DO_STRUCT_DIFFERENCE(TextReset);
|
2010-08-13 17:33:37 +04:00
|
|
|
DO_STRUCT_DIFFERENCE(Background);
|
2003-03-16 07:51:56 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Color);
|
|
|
|
|
|
|
|
#undef DO_STRUCT_DIFFERENCE
|
2000-06-22 00:44:59 +04:00
|
|
|
|
2013-05-27 10:48:19 +04:00
|
|
|
MOZ_ASSERT(styleStructCount == nsStyleStructID_Length,
|
|
|
|
"missing a call to DO_STRUCT_DIFFERENCE");
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
// Note that we do not check whether this->RelevantLinkVisited() !=
|
|
|
|
// aOther->RelevantLinkVisited(); we don't need to since
|
|
|
|
// nsCSSFrameConstructor::DoContentStateChanged always adds
|
|
|
|
// nsChangeHint_RepaintFrame for NS_EVENT_STATE_VISITED changes (and
|
|
|
|
// needs to, since HasStateDependentStyle probably doesn't work right
|
|
|
|
// for NS_EVENT_STATE_VISITED). Hopefully this doesn't actually
|
|
|
|
// expose whether links are visited to performance tests since all
|
|
|
|
// link coloring happens asynchronously at a time when it's hard for
|
|
|
|
// the page to measure.
|
|
|
|
// However, we do need to compute the larger of the changes that can
|
|
|
|
// happen depending on whether the link is visited or unvisited, since
|
|
|
|
// doing only the one that's currently appropriate would expose which
|
|
|
|
// links are in history to easy performance measurement. Therefore,
|
|
|
|
// here, we add nsChangeHint_RepaintFrame hints (the maximum for
|
|
|
|
// things that can depend on :visited) for the properties on which we
|
|
|
|
// call GetVisitedDependentColor.
|
|
|
|
nsStyleContext *thisVis = GetStyleIfVisited(),
|
|
|
|
*otherVis = aOther->GetStyleIfVisited();
|
|
|
|
if (!thisVis != !otherVis) {
|
|
|
|
// One style context has a style-if-visited and the other doesn't.
|
|
|
|
// Presume a difference.
|
|
|
|
NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
|
|
|
|
} else if (thisVis && !NS_IsHintSubset(nsChangeHint_RepaintFrame, hint)) {
|
|
|
|
// Both style contexts have a style-if-visited.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool change = false;
|
2010-04-03 05:58:25 +04:00
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis|, since callers may look
|
|
|
|
// at a struct on |this| without looking at the same struct on
|
|
|
|
// |thisVis| (including this function if we skip one of these checks
|
|
|
|
// due to change being true already or due to the old style context
|
|
|
|
// not having a style-if-visited), but not the other way around.
|
|
|
|
if (PeekStyleColor()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (thisVis->StyleColor()->mColor !=
|
|
|
|
otherVis->StyleColor()->mColor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleBackground()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (thisVis->StyleBackground()->mBackgroundColor !=
|
|
|
|
otherVis->StyleBackground()->mBackgroundColor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleBorder()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder *thisVisBorder = thisVis->StyleBorder();
|
|
|
|
const nsStyleBorder *otherVisBorder = otherVis->StyleBorder();
|
2010-04-03 05:58:25 +04:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool thisFG, otherFG;
|
2010-04-03 05:58:25 +04:00
|
|
|
nscolor thisColor, otherColor;
|
|
|
|
thisVisBorder->GetBorderColor(side, thisColor, thisFG);
|
|
|
|
otherVisBorder->GetBorderColor(side, otherColor, otherFG);
|
|
|
|
if (thisFG != otherFG || (!thisFG && thisColor != otherColor)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleOutline()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleOutline *thisVisOutline = thisVis->StyleOutline();
|
|
|
|
const nsStyleOutline *otherVisOutline = otherVis->StyleOutline();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveColor;
|
2010-04-03 05:58:25 +04:00
|
|
|
nscolor thisColor, otherColor;
|
|
|
|
if (thisVisOutline->GetOutlineInitialColor() !=
|
|
|
|
otherVisOutline->GetOutlineInitialColor() ||
|
|
|
|
(haveColor = thisVisOutline->GetOutlineColor(thisColor)) !=
|
|
|
|
otherVisOutline->GetOutlineColor(otherColor) ||
|
|
|
|
(haveColor && thisColor != otherColor)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleColumn()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleColumn *thisVisColumn = thisVis->StyleColumn();
|
|
|
|
const nsStyleColumn *otherVisColumn = otherVis->StyleColumn();
|
2010-04-03 05:58:25 +04:00
|
|
|
if (thisVisColumn->mColumnRuleColor != otherVisColumn->mColumnRuleColor ||
|
|
|
|
thisVisColumn->mColumnRuleColorIsForeground !=
|
|
|
|
otherVisColumn->mColumnRuleColorIsForeground) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 16:26:35 +04:00
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleTextReset()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleTextReset *thisVisTextReset = thisVis->StyleTextReset();
|
|
|
|
const nsStyleTextReset *otherVisTextReset = otherVis->StyleTextReset();
|
2011-03-31 16:26:35 +04:00
|
|
|
nscolor thisVisDecColor, otherVisDecColor;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool thisVisDecColorIsFG, otherVisDecColorIsFG;
|
2011-03-31 16:26:35 +04:00
|
|
|
thisVisTextReset->GetDecorationColor(thisVisDecColor,
|
|
|
|
thisVisDecColorIsFG);
|
|
|
|
otherVisTextReset->GetDecorationColor(otherVisDecColor,
|
|
|
|
otherVisDecColorIsFG);
|
|
|
|
if (thisVisDecColorIsFG != otherVisDecColorIsFG ||
|
|
|
|
(!thisVisDecColorIsFG && thisVisDecColor != otherVisDecColor)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2011-03-31 16:26:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleSVG()) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG *thisVisSVG = thisVis->StyleSVG();
|
|
|
|
const nsStyleSVG *otherVisSVG = otherVis->StyleSVG();
|
2010-04-03 05:58:25 +04:00
|
|
|
if (thisVisSVG->mFill != otherVisSVG->mFill ||
|
|
|
|
thisVisSVG->mStroke != otherVisSVG->mStroke) {
|
2011-10-17 18:59:28 +04:00
|
|
|
change = true;
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change) {
|
|
|
|
NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 07:48:43 +04:00
|
|
|
return NS_SubtractHint(hint, nsChangeHint_NeutralChange);
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
2003-03-06 22:14:17 +03:00
|
|
|
void
|
|
|
|
nsStyleContext::Mark()
|
|
|
|
{
|
|
|
|
// Mark our rule node.
|
|
|
|
mRuleNode->Mark();
|
|
|
|
|
|
|
|
// Mark our children (i.e., tell them to mark their rule nodes, etc.).
|
|
|
|
if (mChild) {
|
|
|
|
nsStyleContext* child = mChild;
|
|
|
|
do {
|
|
|
|
child->Mark();
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mChild != child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEmptyChild) {
|
|
|
|
nsStyleContext* child = mEmptyChild;
|
|
|
|
do {
|
|
|
|
child->Mark();
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mEmptyChild != child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2014-11-27 09:29:45 +03:00
|
|
|
void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
|
1998-05-19 01:04:26 +04:00
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString str;
|
1998-05-19 01:04:26 +04:00
|
|
|
// Indent
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t ix;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (ix = aIndent; --ix >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
str.Append(nsPrintfCString("%p(%d) parent=%p ",
|
|
|
|
(void*)this, mRefCnt, (void *)mParent));
|
2001-12-02 03:44:45 +03:00
|
|
|
if (mPseudoTag) {
|
1998-11-03 23:18:40 +03:00
|
|
|
nsAutoString buffer;
|
|
|
|
mPseudoTag->ToString(buffer);
|
2014-11-27 09:29:44 +03:00
|
|
|
AppendUTF16toUTF8(buffer, str);
|
|
|
|
str.Append(' ');
|
1998-11-03 23:18:40 +03:00
|
|
|
}
|
2001-10-17 04:25:26 +04:00
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
if (mRuleNode) {
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s{\n", str.get());
|
|
|
|
str.Truncate();
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode* ruleNode = mRuleNode;
|
2001-10-17 04:25:26 +04:00
|
|
|
while (ruleNode) {
|
2003-06-20 05:22:44 +04:00
|
|
|
nsIStyleRule *styleRule = ruleNode->GetRule();
|
2001-10-17 04:25:26 +04:00
|
|
|
if (styleRule) {
|
|
|
|
styleRule->List(out, aIndent + 1);
|
|
|
|
}
|
2001-10-24 04:01:09 +04:00
|
|
|
ruleNode = ruleNode->GetParent();
|
2001-10-17 04:25:26 +04:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
for (ix = aIndent; --ix >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s}\n", str.get());
|
2001-10-17 04:25:26 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s{}\n", str.get());
|
2001-10-17 04:25:26 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 09:29:45 +03:00
|
|
|
if (aListDescendants) {
|
|
|
|
if (nullptr != mChild) {
|
|
|
|
nsStyleContext* child = mChild;
|
|
|
|
do {
|
|
|
|
child->List(out, aIndent + 1, aListDescendants);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mChild != child);
|
|
|
|
}
|
|
|
|
if (nullptr != mEmptyChild) {
|
|
|
|
nsStyleContext* child = mEmptyChild;
|
|
|
|
do {
|
|
|
|
child->List(out, aIndent + 1, aListDescendants);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mEmptyChild != child);
|
|
|
|
}
|
1998-10-08 05:27:38 +04:00
|
|
|
}
|
1998-05-19 01:04:26 +04:00
|
|
|
}
|
2000-12-07 18:31:40 +03:00
|
|
|
#endif
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Overloaded new operator. Initializes the memory to 0 and relies on an arena
|
|
|
|
// (which comes from the presShell) to perform the allocation.
|
|
|
|
void*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleContext::operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
|
|
|
// Check the recycle list first.
|
2012-06-06 21:35:40 +04:00
|
|
|
return aPresContext->PresShell()->AllocateByObjectID(nsPresArena::nsStyleContext_id, sz);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overridden to prevent the global delete from being called, since the memory
|
|
|
|
// came out of an nsIArena instead of the global delete operator's heap.
|
|
|
|
void
|
|
|
|
nsStyleContext::Destroy()
|
|
|
|
{
|
|
|
|
// Get the pres context from our rule node.
|
2013-02-17 01:04:54 +04:00
|
|
|
nsRefPtr<nsPresContext> presContext = mRuleNode->PresContext();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// Call our destructor.
|
|
|
|
this->~nsStyleContext();
|
|
|
|
|
|
|
|
// Don't let the memory be freed, since it will be recycled
|
|
|
|
// instead. Don't call the global operator delete.
|
2012-06-06 21:35:40 +04:00
|
|
|
presContext->PresShell()->FreeByObjectID(nsPresArena::nsStyleContext_id, this);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
1998-11-03 23:18:40 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2013-02-21 11:34:58 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
bool aSkipParentDisplayBasedStyleFixup)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsStyleContext> context =
|
2013-02-17 01:04:54 +04:00
|
|
|
new (aRuleNode->PresContext())
|
2013-02-21 11:34:58 +04:00
|
|
|
nsStyleContext(aParentContext, aPseudoTag, aPseudoType, aRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
aSkipParentDisplayBasedStyleFixup);
|
2013-04-22 15:15:59 +04:00
|
|
|
return context.forget();
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 05:01:19 +04:00
|
|
|
static inline void
|
|
|
|
ExtractAnimationValue(nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue& aResult)
|
2010-04-03 05:58:25 +04:00
|
|
|
{
|
2012-08-05 05:01:19 +04:00
|
|
|
DebugOnly<bool> success =
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext,
|
|
|
|
aResult);
|
2010-04-03 05:58:25 +04:00
|
|
|
NS_ABORT_IF_FALSE(success,
|
2014-06-24 10:29:54 +04:00
|
|
|
"aProperty must be extractable by StyleAnimationValue");
|
2012-08-05 05:01:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nscolor
|
|
|
|
ExtractColor(nsCSSProperty aProperty,
|
|
|
|
nsStyleContext *aStyleContext)
|
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue val;
|
2012-08-05 05:01:19 +04:00
|
|
|
ExtractAnimationValue(aProperty, aStyleContext, val);
|
2010-04-03 05:58:25 +04:00
|
|
|
return val.GetColorValue();
|
|
|
|
}
|
|
|
|
|
2012-08-05 05:01:19 +04:00
|
|
|
static nscolor
|
|
|
|
ExtractColorLenient(nsCSSProperty aProperty,
|
|
|
|
nsStyleContext *aStyleContext)
|
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue val;
|
2012-08-05 05:01:19 +04:00
|
|
|
ExtractAnimationValue(aProperty, aStyleContext, val);
|
2014-06-24 10:29:54 +04:00
|
|
|
if (val.GetUnit() == StyleAnimationValue::eUnit_Color) {
|
2012-08-05 05:01:19 +04:00
|
|
|
return val.GetColorValue();
|
|
|
|
}
|
|
|
|
return NS_RGBA(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
struct ColorIndexSet {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t colorIndex, alphaIndex;
|
2010-04-03 05:58:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const ColorIndexSet gVisitedIndices[2] = { { 0, 0 }, { 1, 0 } };
|
|
|
|
|
|
|
|
nscolor
|
|
|
|
nsStyleContext::GetVisitedDependentColor(nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aProperty == eCSSProperty_color ||
|
|
|
|
aProperty == eCSSProperty_background_color ||
|
|
|
|
aProperty == eCSSProperty_border_top_color ||
|
|
|
|
aProperty == eCSSProperty_border_right_color_value ||
|
|
|
|
aProperty == eCSSProperty_border_bottom_color ||
|
|
|
|
aProperty == eCSSProperty_border_left_color_value ||
|
|
|
|
aProperty == eCSSProperty_outline_color ||
|
|
|
|
aProperty == eCSSProperty__moz_column_rule_color ||
|
2011-03-31 16:26:35 +04:00
|
|
|
aProperty == eCSSProperty_text_decoration_color ||
|
2010-04-03 05:58:25 +04:00
|
|
|
aProperty == eCSSProperty_fill ||
|
|
|
|
aProperty == eCSSProperty_stroke,
|
|
|
|
"we need to add to nsStyleContext::CalcStyleDifference");
|
|
|
|
|
2012-08-05 05:01:19 +04:00
|
|
|
bool isPaintProperty = aProperty == eCSSProperty_fill ||
|
|
|
|
aProperty == eCSSProperty_stroke;
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
nscolor colors[2];
|
2012-08-05 05:01:19 +04:00
|
|
|
colors[0] = isPaintProperty ? ExtractColorLenient(aProperty, this)
|
|
|
|
: ExtractColor(aProperty, this);
|
2010-04-03 05:58:25 +04:00
|
|
|
|
|
|
|
nsStyleContext *visitedStyle = this->GetStyleIfVisited();
|
|
|
|
if (!visitedStyle) {
|
|
|
|
return colors[0];
|
|
|
|
}
|
|
|
|
|
2012-08-05 05:01:19 +04:00
|
|
|
colors[1] = isPaintProperty ? ExtractColorLenient(aProperty, visitedStyle)
|
|
|
|
: ExtractColor(aProperty, visitedStyle);
|
2010-04-03 05:58:25 +04:00
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
return nsStyleContext::CombineVisitedColors(colors,
|
|
|
|
this->RelevantLinkVisited());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscolor
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStyleContext::CombineVisitedColors(nscolor *aColors, bool aLinkIsVisited)
|
2010-04-03 05:58:26 +04:00
|
|
|
{
|
2010-04-07 02:32:52 +04:00
|
|
|
if (NS_GET_A(aColors[1]) == 0) {
|
|
|
|
// If the style-if-visited is transparent, then just use the
|
|
|
|
// unvisited style rather than using the (meaningless) color
|
|
|
|
// components of the visited style along with a potentially
|
|
|
|
// non-transparent alpha value.
|
2011-10-17 18:59:28 +04:00
|
|
|
aLinkIsVisited = false;
|
2010-04-07 02:32:52 +04:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:25 +04:00
|
|
|
// NOTE: We want this code to have as little timing dependence as
|
|
|
|
// possible on whether this->RelevantLinkVisited() is true.
|
|
|
|
const ColorIndexSet &set =
|
2010-04-03 05:58:26 +04:00
|
|
|
gVisitedIndices[aLinkIsVisited ? 1 : 0];
|
2010-04-03 05:58:25 +04:00
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
nscolor colorColor = aColors[set.colorIndex];
|
|
|
|
nscolor alphaColor = aColors[set.alphaIndex];
|
2010-04-03 05:58:25 +04:00
|
|
|
return NS_RGBA(NS_GET_R(colorColor), NS_GET_G(colorColor),
|
|
|
|
NS_GET_B(colorColor), NS_GET_A(alphaColor));
|
|
|
|
}
|
2010-07-03 08:18:55 +04:00
|
|
|
|
2014-01-03 06:39:54 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* static */ void
|
|
|
|
nsStyleContext::AssertStyleStructMaxDifferenceValid()
|
|
|
|
{
|
|
|
|
#define STYLE_STRUCT(name, checkdata_cb) \
|
|
|
|
MOZ_ASSERT(NS_IsHintSubset(nsStyle##name::MaxDifferenceNeverInherited(), \
|
|
|
|
nsStyle##name::MaxDifference()));
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
}
|
2014-09-25 09:45:36 +04:00
|
|
|
|
|
|
|
/* static */ const char*
|
|
|
|
nsStyleContext::StructName(nsStyleStructID aSID)
|
|
|
|
{
|
|
|
|
switch (aSID) {
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb) \
|
|
|
|
case eStyleStruct_##name_: \
|
|
|
|
return #name_;
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
2014-10-01 03:13:57 +04:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsStyleContext::LookupStruct(const nsACString& aName, nsStyleStructID& aResult)
|
|
|
|
{
|
|
|
|
if (false)
|
|
|
|
;
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
else if (aName.EqualsLiteral(#name_)) \
|
|
|
|
aResult = eStyleStruct_##name_;
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-03 06:39:54 +04:00
|
|
|
#endif
|
2014-09-05 07:48:44 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsStyleContext::HasSameCachedStyleData(nsStyleContext* aOther,
|
|
|
|
nsStyleStructID aSID)
|
|
|
|
{
|
|
|
|
return GetCachedStyleData(aSID) == aOther->GetCachedStyleData(aSID);
|
|
|
|
}
|
2014-09-05 07:48:46 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::SwapStyleData(nsStyleContext* aNewContext, uint32_t aStructs)
|
|
|
|
{
|
|
|
|
static_assert(nsStyleStructID_Length <= 32, "aStructs is not big enough");
|
|
|
|
|
|
|
|
for (nsStyleStructID i = nsStyleStructID_Inherited_Start;
|
|
|
|
i < nsStyleStructID_Inherited_Start + nsStyleStructID_Inherited_Count;
|
|
|
|
i = nsStyleStructID(i + 1)) {
|
|
|
|
uint32_t bit = nsCachedStyleData::GetBitForSID(i);
|
|
|
|
if (!(aStructs & bit)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
void*& thisData = mCachedInheritedData.mStyleStructs[i];
|
|
|
|
void*& otherData = aNewContext->mCachedInheritedData.mStyleStructs[i];
|
|
|
|
if (mBits & bit) {
|
|
|
|
if (thisData == otherData) {
|
|
|
|
thisData = nullptr;
|
|
|
|
}
|
|
|
|
} else if (!(aNewContext->mBits & bit) && thisData && otherData) {
|
|
|
|
std::swap(thisData, otherData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsStyleStructID i = nsStyleStructID_Reset_Start;
|
|
|
|
i < nsStyleStructID_Reset_Start + nsStyleStructID_Reset_Count;
|
|
|
|
i = nsStyleStructID(i + 1)) {
|
|
|
|
uint32_t bit = nsCachedStyleData::GetBitForSID(i);
|
|
|
|
if (!(aStructs & bit)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!mCachedResetData) {
|
|
|
|
mCachedResetData = new (mRuleNode->PresContext()) nsResetStyleData;
|
|
|
|
}
|
|
|
|
if (!aNewContext->mCachedResetData) {
|
|
|
|
aNewContext->mCachedResetData =
|
|
|
|
new (mRuleNode->PresContext()) nsResetStyleData;
|
|
|
|
}
|
|
|
|
void*& thisData = mCachedResetData->mStyleStructs[i];
|
|
|
|
void*& otherData = aNewContext->mCachedResetData->mStyleStructs[i];
|
|
|
|
if (mBits & bit) {
|
|
|
|
if (thisData == otherData) {
|
|
|
|
thisData = nullptr;
|
|
|
|
}
|
|
|
|
} else if (!(aNewContext->mBits & bit) && thisData && otherData) {
|
|
|
|
std::swap(thisData, otherData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 07:48:47 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::ClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs)
|
|
|
|
{
|
|
|
|
if (mChild) {
|
|
|
|
nsStyleContext* child = mChild;
|
|
|
|
do {
|
|
|
|
child->DoClearCachedInheritedStyleDataOnDescendants(aStructs);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mChild != child);
|
|
|
|
}
|
|
|
|
if (mEmptyChild) {
|
|
|
|
nsStyleContext* child = mEmptyChild;
|
|
|
|
do {
|
|
|
|
child->DoClearCachedInheritedStyleDataOnDescendants(aStructs);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mEmptyChild != child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs)
|
|
|
|
{
|
|
|
|
for (nsStyleStructID i = nsStyleStructID_Inherited_Start;
|
|
|
|
i < nsStyleStructID_Inherited_Start + nsStyleStructID_Inherited_Count;
|
|
|
|
i = nsStyleStructID(i + 1)) {
|
|
|
|
uint32_t bit = nsCachedStyleData::GetBitForSID(i);
|
|
|
|
if (aStructs & bit) {
|
|
|
|
if (!(mBits & bit) && mCachedInheritedData.mStyleStructs[i]) {
|
|
|
|
aStructs &= ~bit;
|
|
|
|
} else {
|
|
|
|
mCachedInheritedData.mStyleStructs[i] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCachedResetData) {
|
|
|
|
for (nsStyleStructID i = nsStyleStructID_Reset_Start;
|
|
|
|
i < nsStyleStructID_Reset_Start + nsStyleStructID_Reset_Count;
|
|
|
|
i = nsStyleStructID(i + 1)) {
|
|
|
|
uint32_t bit = nsCachedStyleData::GetBitForSID(i);
|
|
|
|
if (aStructs & bit) {
|
|
|
|
if (!(mBits & bit) && mCachedResetData->mStyleStructs[i]) {
|
|
|
|
aStructs &= ~bit;
|
|
|
|
} else {
|
|
|
|
mCachedResetData->mStyleStructs[i] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aStructs == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearCachedInheritedStyleDataOnDescendants(aStructs);
|
|
|
|
}
|
2014-10-01 03:13:57 +04:00
|
|
|
|
|
|
|
#ifdef RESTYLE_LOGGING
|
|
|
|
nsCString
|
|
|
|
nsStyleContext::GetCachedStyleDataAsString(uint32_t aStructs)
|
|
|
|
{
|
|
|
|
nsCString structs;
|
|
|
|
for (nsStyleStructID i = nsStyleStructID(0);
|
|
|
|
i < nsStyleStructID_Length;
|
|
|
|
i = nsStyleStructID(i + 1)) {
|
|
|
|
if (aStructs & nsCachedStyleData::GetBitForSID(i)) {
|
|
|
|
const void* data = GetCachedStyleData(i);
|
|
|
|
if (!structs.IsEmpty()) {
|
|
|
|
structs.Append(' ');
|
|
|
|
}
|
|
|
|
structs.AppendPrintf("%s=%p", StructName(i), data);
|
|
|
|
if (HasCachedInheritedStyleData(i)) {
|
|
|
|
structs.AppendLiteral("(dependent)");
|
|
|
|
} else {
|
|
|
|
structs.AppendLiteral("(owned)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return structs;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t&
|
|
|
|
nsStyleContext::LoggingDepth()
|
|
|
|
{
|
|
|
|
static int32_t depth = 0;
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::LogStyleContextTree(int32_t aLoggingDepth, uint32_t aStructs)
|
|
|
|
{
|
|
|
|
LoggingDepth() = aLoggingDepth;
|
|
|
|
LogStyleContextTree(true, aStructs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::LogStyleContextTree(bool aFirst, uint32_t aStructs)
|
|
|
|
{
|
|
|
|
nsCString structs = GetCachedStyleDataAsString(aStructs);
|
|
|
|
if (!structs.IsEmpty()) {
|
|
|
|
structs.Append(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString pseudo;
|
|
|
|
if (mPseudoTag) {
|
|
|
|
nsAutoString pseudoTag;
|
|
|
|
mPseudoTag->ToString(pseudoTag);
|
|
|
|
AppendUTF16toUTF8(pseudoTag, pseudo);
|
|
|
|
pseudo.Append(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString flags;
|
|
|
|
if (IsStyleIfVisited()) {
|
|
|
|
flags.AppendLiteral("IS_STYLE_IF_VISITED ");
|
|
|
|
}
|
|
|
|
if (UsesGrandancestorStyle()) {
|
|
|
|
flags.AppendLiteral("USES_GRANDANCESTOR_STYLE ");
|
|
|
|
}
|
|
|
|
if (IsShared()) {
|
|
|
|
flags.AppendLiteral("IS_SHARED ");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString parent;
|
|
|
|
if (aFirst) {
|
|
|
|
parent.AppendPrintf("parent=%p ", mParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_RESTYLE("%p(%d) %s%s%s%s",
|
|
|
|
this, mRefCnt,
|
|
|
|
structs.get(), pseudo.get(), flags.get(), parent.get());
|
|
|
|
|
|
|
|
LOG_RESTYLE_INDENT();
|
|
|
|
|
|
|
|
if (nullptr != mChild) {
|
|
|
|
nsStyleContext* child = mChild;
|
|
|
|
do {
|
|
|
|
child->LogStyleContextTree(false, aStructs);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mChild != child);
|
|
|
|
}
|
|
|
|
if (nullptr != mEmptyChild) {
|
|
|
|
nsStyleContext* child = mEmptyChild;
|
|
|
|
do {
|
|
|
|
child->LogStyleContextTree(false, aStructs);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mEmptyChild != child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|