2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2001-05-31 22:19:43 +00:00
|
|
|
* David Hyatt <hyatt@netscape.com>
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-02-07 09:57:26 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsString.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
|
2000-03-31 07:08:36 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-01-07 22:30:53 +00:00
|
|
|
#include "nsStyleSet.h"
|
2000-03-31 07:08:36 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
#include "nsRuleNode.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2009-12-11 07:37:40 +00:00
|
|
|
#include "prlog.h"
|
2010-04-03 01:58:25 +00:00
|
|
|
#include "nsStyleAnimation.h"
|
2005-04-29 15:44:38 +00:00
|
|
|
|
2000-06-21 20:44:59 +00:00
|
|
|
#ifdef DEBUG
|
2001-05-31 22:19:43 +00:00
|
|
|
// #define NOISY_DEBUG
|
2001-05-03 13:20:48 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
//----------------------------------------------------------------------
|
2001-05-03 13:20:48 +00:00
|
|
|
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext::nsStyleContext(nsStyleContext* aParent,
|
2001-12-02 00:44:45 +00:00
|
|
|
nsIAtom* aPseudoTag,
|
2009-12-11 07:37:40 +00:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2001-12-02 00:44:45 +00:00
|
|
|
nsRuleNode* aRuleNode,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* aPresContext)
|
2005-02-05 05:24:21 +00:00
|
|
|
: mParent(aParent),
|
2001-05-31 22:19:43 +00:00
|
|
|
mChild(nsnull),
|
|
|
|
mEmptyChild(nsnull),
|
|
|
|
mPseudoTag(aPseudoTag),
|
2001-12-02 00:44:45 +00:00
|
|
|
mRuleNode(aRuleNode),
|
2010-07-03 04:18:55 +00:00
|
|
|
mAllocations(nsnull),
|
2010-03-02 23:27:21 +00:00
|
|
|
mCachedResetData(nsnull),
|
2009-12-11 07:37:40 +00:00
|
|
|
mBits(((PRUint32)aPseudoType) << NS_STYLE_CONTEXT_TYPE_SHIFT),
|
2003-02-22 00:32:13 +00:00
|
|
|
mRefCnt(0)
|
1999-09-03 23:34:20 +00:00
|
|
|
{
|
2009-12-11 07:37:40 +00:00
|
|
|
PR_STATIC_ASSERT((PR_UINT32_MAX >> NS_STYLE_CONTEXT_TYPE_SHIFT) >
|
|
|
|
nsCSSPseudoElements::ePseudo_MAX);
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
mNextSibling = this;
|
|
|
|
mPrevSibling = this;
|
2001-12-02 00:44:45 +00:00
|
|
|
if (mParent) {
|
2003-02-22 00:32:13 +00:00
|
|
|
mParent->AddRef();
|
2006-04-28 00:09:05 +00:00
|
|
|
mParent->AddChild(this);
|
2009-01-16 21:32:09 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsRuleNode *r1 = mParent->GetRuleNode(), *r2 = aRuleNode;
|
|
|
|
while (r1->GetParent())
|
|
|
|
r1 = r1->GetParent();
|
|
|
|
while (r2->GetParent())
|
|
|
|
r2 = r2->GetParent();
|
2009-01-30 04:39:23 +00:00
|
|
|
NS_ASSERTION(r1 == r2, "must be in the same rule tree as parent");
|
2009-01-16 21:32:09 +00:00
|
|
|
#endif
|
1999-02-27 07:11:42 +00:00
|
|
|
}
|
2001-05-03 13:20:48 +00:00
|
|
|
|
2001-07-25 06:33:06 +00:00
|
|
|
ApplyStyleFixups(aPresContext);
|
2002-07-09 04:10:10 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
#define eStyleStruct_LastItem (nsStyleStructID_Length - 1)
|
|
|
|
NS_ASSERTION(NS_STYLE_INHERIT_MASK & NS_STYLE_INHERIT_BIT(LastItem),
|
2002-07-09 04:10:10 +00:00
|
|
|
"NS_STYLE_INHERIT_MASK must be bigger, and other bits shifted");
|
2006-04-28 00:09:05 +00:00
|
|
|
#undef eStyleStruct_LastItem
|
2009-09-24 17:59:43 +00:00
|
|
|
|
|
|
|
mRuleNode->AddRef();
|
2001-05-03 13:20:48 +00:00
|
|
|
}
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
nsStyleContext::~nsStyleContext()
|
2001-05-03 13:20:48 +00:00
|
|
|
{
|
2001-05-31 22:19:43 +00:00
|
|
|
NS_ASSERTION((nsnull == mChild) && (nsnull == mEmptyChild), "destructing context with children");
|
2001-05-03 13:20:48 +00:00
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext *presContext = mRuleNode->GetPresContext();
|
2003-03-06 19:14:17 +00:00
|
|
|
|
2009-09-24 17:59:43 +00:00
|
|
|
mRuleNode->Release();
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
presContext->PresShell()->StyleSet()->
|
|
|
|
NotifyStyleContextDestroyed(presContext, this);
|
2003-03-06 19:14:17 +00:00
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
if (mParent) {
|
|
|
|
mParent->RemoveChild(this);
|
2003-02-22 00:32:13 +00:00
|
|
|
mParent->Release();
|
1999-02-27 07:11:42 +00:00
|
|
|
}
|
2001-02-07 09:57:26 +00:00
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
// Free up our data structs.
|
2010-03-02 23:27:21 +00:00
|
|
|
mCachedInheritedData.DestroyStructs(mBits, presContext);
|
|
|
|
if (mCachedResetData) {
|
|
|
|
mCachedResetData->Destroy(mBits, presContext);
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2010-07-03 04:18:55 +00:00
|
|
|
|
|
|
|
FreeAllocations(presContext);
|
2001-02-07 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
void nsStyleContext::AddChild(nsStyleContext* aChild)
|
2001-02-07 09:57:26 +00:00
|
|
|
{
|
2006-04-28 00:09:05 +00:00
|
|
|
NS_ASSERTION(aChild->mPrevSibling == aChild &&
|
|
|
|
aChild->mNextSibling == aChild,
|
|
|
|
"child already in a child list");
|
|
|
|
|
|
|
|
nsStyleContext **list = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
|
|
|
|
|
|
|
// Insert at the beginning of the list. See also FindChildWithRules.
|
|
|
|
if (*list) {
|
|
|
|
// Link into existing elements, if there are any.
|
|
|
|
aChild->mNextSibling = (*list);
|
|
|
|
aChild->mPrevSibling = (*list)->mPrevSibling;
|
|
|
|
(*list)->mPrevSibling->mNextSibling = aChild;
|
|
|
|
(*list)->mPrevSibling = aChild;
|
2001-02-07 09:57:26 +00:00
|
|
|
}
|
2006-04-28 00:09:05 +00:00
|
|
|
(*list) = aChild;
|
2001-02-07 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
void nsStyleContext::RemoveChild(nsStyleContext* aChild)
|
2001-02-07 09:57:26 +00:00
|
|
|
{
|
2002-02-17 01:53:40 +00:00
|
|
|
NS_PRECONDITION(nsnull != aChild && this == aChild->mParent, "bad argument");
|
2001-02-07 09:57:26 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
nsStyleContext **list = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
|
|
|
|
|
|
|
if (aChild->mPrevSibling != aChild) { // has siblings
|
|
|
|
if ((*list) == aChild) {
|
|
|
|
(*list) = (*list)->mNextSibling;
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2006-04-28 00:09:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION((*list) == aChild, "bad sibling pointers");
|
|
|
|
(*list) = nsnull;
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2006-04-28 00:09:05 +00:00
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
aChild->mPrevSibling->mNextSibling = aChild->mNextSibling;
|
|
|
|
aChild->mNextSibling->mPrevSibling = aChild->mPrevSibling;
|
|
|
|
aChild->mNextSibling = aChild;
|
|
|
|
aChild->mPrevSibling = aChild;
|
1999-10-16 04:05:59 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
already_AddRefed<nsStyleContext>
|
2001-05-31 22:19:43 +00:00
|
|
|
nsStyleContext::FindChildWithRules(const nsIAtom* aPseudoTag,
|
2010-04-03 01:58:26 +00:00
|
|
|
nsRuleNode* aRuleNode,
|
|
|
|
nsRuleNode* aRulesIfVisited,
|
|
|
|
PRBool aRelevantLinkVisited)
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
2010-04-03 01:58:26 +00:00
|
|
|
NS_ABORT_IF_FALSE(aRulesIfVisited || !aRelevantLinkVisited,
|
|
|
|
"aRelevantLinkVisited should only be set when we have a separate style");
|
2001-05-31 22:19:43 +00:00
|
|
|
PRUint32 threshold = 10; // The # of siblings we're willing to examine
|
|
|
|
// before just giving this whole thing up.
|
2001-05-03 13:20:48 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
nsStyleContext* result = nsnull;
|
|
|
|
nsStyleContext *list = aRuleNode->IsRoot() ? mEmptyChild : mChild;
|
|
|
|
|
|
|
|
if (list) {
|
|
|
|
nsStyleContext *child = list;
|
|
|
|
do {
|
2010-04-03 01:58:26 +00:00
|
|
|
if (child->mRuleNode == aRuleNode &&
|
|
|
|
child->mPseudoTag == aPseudoTag &&
|
2010-04-06 19:42:41 +00:00
|
|
|
!child->IsStyleIfVisited() &&
|
2010-04-03 01:58:26 +00:00
|
|
|
child->RelevantLinkVisited() == aRelevantLinkVisited) {
|
|
|
|
PRBool match = PR_FALSE;
|
|
|
|
if (aRulesIfVisited) {
|
|
|
|
match = child->GetStyleIfVisited() &&
|
|
|
|
child->GetStyleIfVisited()->mRuleNode == aRulesIfVisited;
|
|
|
|
} else {
|
|
|
|
match = !child->GetStyleIfVisited();
|
|
|
|
}
|
|
|
|
if (match) {
|
|
|
|
result = child;
|
|
|
|
break;
|
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2006-04-28 00:09:05 +00:00
|
|
|
child = child->mNextSibling;
|
|
|
|
threshold--;
|
|
|
|
if (threshold == 0)
|
|
|
|
break;
|
|
|
|
} while (child != list);
|
1998-10-27 03:03:02 +00:00
|
|
|
}
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
if (result) {
|
|
|
|
if (result != list) {
|
|
|
|
// Move result to the front of the list.
|
|
|
|
RemoveChild(result);
|
|
|
|
AddChild(result);
|
|
|
|
}
|
2003-02-22 00:32:13 +00:00
|
|
|
|
2006-04-28 00:09:05 +00:00
|
|
|
// Add reference for the caller.
|
|
|
|
result->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1998-06-05 06:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
const void* nsStyleContext::GetCachedStyleData(nsStyleStructID aSID)
|
1998-04-21 00:02:44 +00:00
|
|
|
{
|
2010-03-02 23:27:21 +00:00
|
|
|
const void* cachedData;
|
|
|
|
PRBool isReset = nsCachedStyleData::IsReset(aSID);
|
|
|
|
if (isReset) {
|
|
|
|
if (mCachedResetData) {
|
|
|
|
char* slot = reinterpret_cast<char*>(mCachedResetData) +
|
|
|
|
nsCachedStyleData::gInfo[aSID].mInheritResetOffset;
|
|
|
|
cachedData = *reinterpret_cast<void**>(slot);
|
|
|
|
} else {
|
|
|
|
cachedData = nsnull;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char* slot = reinterpret_cast<char*>(&mCachedInheritedData) +
|
|
|
|
nsCachedStyleData::gInfo[aSID].mInheritResetOffset;
|
|
|
|
cachedData = *reinterpret_cast<void**>(slot);
|
2006-12-12 17:44:45 +00:00
|
|
|
}
|
2010-03-02 23:27:21 +00:00
|
|
|
return cachedData;
|
|
|
|
}
|
2006-12-12 17:44:45 +00:00
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
const void* nsStyleContext::GetStyleData(nsStyleStructID aSID)
|
2001-11-14 08:19:13 +00:00
|
|
|
{
|
2010-03-02 23:27:21 +00:00
|
|
|
const void* cachedData = GetCachedStyleData(aSID);
|
2001-11-14 08:19:13 +00:00
|
|
|
if (cachedData)
|
|
|
|
return cachedData; // We have computed data stored on this node in the context tree.
|
2010-03-02 23:27:21 +00:00
|
|
|
return mRuleNode->GetStyleData(aSID, this, PR_TRUE); // Our rule node will take care of it for us.
|
1999-02-27 07:11:42 +00:00
|
|
|
}
|
1998-12-07 18:51:26 +00:00
|
|
|
|
2001-05-31 22:19:43 +00: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 20:56:49 +00:00
|
|
|
void*
|
2004-02-09 06:55:14 +00:00
|
|
|
nsStyleContext::GetUniqueStyleData(const nsStyleStructID& aSID)
|
2000-06-21 20:44:59 +00:00
|
|
|
{
|
2004-02-09 06:55:14 +00: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.)
|
2008-01-10 20:56:49 +00:00
|
|
|
const void *current = GetStyleData(aSID);
|
2004-02-09 06:55:14 +00:00
|
|
|
if (!mChild && !mEmptyChild &&
|
|
|
|
!(mBits & nsCachedStyleData::GetBitForSID(aSID)) &&
|
2010-03-02 23:27:21 +00:00
|
|
|
GetCachedStyleData(aSID))
|
2008-01-10 20:56:49 +00:00
|
|
|
return const_cast<void*>(current);
|
2004-02-09 06:55:14 +00:00
|
|
|
|
2008-01-10 20:56:49 +00:00
|
|
|
void* result;
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2001-05-31 22:19:43 +00:00
|
|
|
switch (aSID) {
|
2004-02-09 06:55:14 +00:00
|
|
|
|
|
|
|
#define UNIQUE_CASE(c_) \
|
|
|
|
case eStyleStruct_##c_: \
|
|
|
|
result = new (presContext) nsStyle##c_( \
|
2007-07-11 08:46:44 +00:00
|
|
|
* static_cast<const nsStyle##c_ *>(current)); \
|
2001-12-14 03:47:02 +00:00
|
|
|
break;
|
2004-02-09 06:55:14 +00:00
|
|
|
|
|
|
|
UNIQUE_CASE(Display)
|
|
|
|
UNIQUE_CASE(Background)
|
|
|
|
UNIQUE_CASE(Text)
|
|
|
|
UNIQUE_CASE(TextReset)
|
|
|
|
|
|
|
|
#undef UNIQUE_CASE
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
default:
|
2010-06-17 20:28:38 +00:00
|
|
|
NS_ERROR("Struct type not supported. Please find another way to do this if you can!");
|
2004-02-09 06:55:14 +00:00
|
|
|
return nsnull;
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 21:03:04 +00:00
|
|
|
if (!result) {
|
2008-01-10 20:56:49 +00:00
|
|
|
NS_WARNING("Ran out of memory while trying to allocate memory for a unique style struct! "
|
2005-07-19 21:03:04 +00:00
|
|
|
"Returning the non-unique data.");
|
2008-01-10 20:56:49 +00:00
|
|
|
return const_cast<void*>(current);
|
2005-07-19 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 06:55:14 +00:00
|
|
|
SetStyle(aSID, result);
|
|
|
|
mBits &= ~nsCachedStyleData::GetBitForSID(aSID);
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
return result;
|
2000-06-21 20:44:59 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
void
|
2008-01-10 20:56:49 +00:00
|
|
|
nsStyleContext::SetStyle(nsStyleStructID aSID, void* aStruct)
|
2000-12-15 06:09:50 +00:00
|
|
|
{
|
2001-05-31 22:19:43 +00:00
|
|
|
// This method should only be called from nsRuleNode! It is not a public
|
|
|
|
// method!
|
|
|
|
|
2002-07-09 04:10:10 +00:00
|
|
|
NS_ASSERTION(aSID >= 0 && aSID < nsStyleStructID_Length, "out of bounds");
|
|
|
|
|
|
|
|
// NOTE: nsCachedStyleData::GetStyleData works roughly the same way.
|
2002-08-06 13:46:35 +00:00
|
|
|
// See the comments there (in nsRuleNode.h) for more details about
|
|
|
|
// what this is doing and why.
|
|
|
|
|
2010-03-02 23:27:21 +00:00
|
|
|
char* dataSlot;
|
|
|
|
if (nsCachedStyleData::IsReset(aSID)) {
|
|
|
|
if (!mCachedResetData) {
|
|
|
|
mCachedResetData = new (mRuleNode->GetPresContext()) nsResetStyleData;
|
|
|
|
// XXXbz And if that fails?
|
2001-12-02 00:44:45 +00:00
|
|
|
}
|
2010-03-02 23:27:21 +00:00
|
|
|
dataSlot = reinterpret_cast<char*>(mCachedResetData) +
|
|
|
|
nsCachedStyleData::gInfo[aSID].mInheritResetOffset;
|
|
|
|
} else {
|
|
|
|
dataSlot = reinterpret_cast<char*>(&mCachedInheritedData) +
|
|
|
|
nsCachedStyleData::gInfo[aSID].mInheritResetOffset;
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
2009-08-10 14:54:21 +00:00
|
|
|
NS_ASSERTION(!*reinterpret_cast<void**>(dataSlot) ||
|
|
|
|
(mBits & nsCachedStyleData::GetBitForSID(aSID)),
|
2009-08-07 14:38:44 +00:00
|
|
|
"Going to leak style data");
|
2008-01-10 20:56:49 +00:00
|
|
|
*reinterpret_cast<void**>(dataSlot) = aStruct;
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
|
|
|
|
2001-07-25 06:33:06 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsStyleContext::ApplyStyleFixups(nsPresContext* aPresContext)
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
2001-07-25 06:33:06 +00: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.
|
|
|
|
if (mParent && mParent->HasTextDecorations())
|
|
|
|
mBits |= NS_STYLE_HAS_TEXT_DECORATIONS;
|
|
|
|
else {
|
|
|
|
// We might have defined a decoration.
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleTextReset* text = GetStyleTextReset();
|
2001-07-25 06:33:06 +00:00
|
|
|
if (text->mTextDecoration != NS_STYLE_TEXT_DECORATION_NONE &&
|
|
|
|
text->mTextDecoration != NS_STYLE_TEXT_DECORATION_OVERRIDE_ALL)
|
|
|
|
mBits |= NS_STYLE_HAS_TEXT_DECORATIONS;
|
|
|
|
}
|
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
if ((mParent && mParent->HasPseudoElementData()) || mPseudoTag) {
|
|
|
|
mBits |= NS_STYLE_HAS_PSEUDO_ELEMENT_DATA;
|
|
|
|
}
|
|
|
|
|
2005-07-20 12:03:15 +00:00
|
|
|
// Correct tables.
|
|
|
|
const nsStyleDisplay* disp = GetStyleDisplay();
|
|
|
|
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.
|
|
|
|
const nsStyleText* text = GetStyleText();
|
|
|
|
|
|
|
|
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 18:21:41 +00: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) {
|
|
|
|
if (disp->mDisplay != NS_STYLE_DISPLAY_NONE &&
|
|
|
|
disp->mDisplay != NS_STYLE_DISPLAY_BLOCK &&
|
|
|
|
disp->mDisplay != NS_STYLE_DISPLAY_TABLE) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsStyleDisplay *mutable_display = static_cast<nsStyleDisplay*>
|
|
|
|
(GetUniqueStyleData(eStyleStruct_Display));
|
2004-07-17 18:21:41 +00:00
|
|
|
if (mutable_display->mDisplay == NS_STYLE_DISPLAY_INLINE_TABLE)
|
|
|
|
mutable_display->mDisplay = NS_STYLE_DISPLAY_TABLE;
|
|
|
|
else
|
|
|
|
mutable_display->mDisplay = NS_STYLE_DISPLAY_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
2004-12-30 21:56:11 +00:00
|
|
|
|
|
|
|
// Computer User Interface style, to trigger loads of cursors
|
|
|
|
GetStyleUserInterface();
|
2001-07-25 06:33:06 +00:00
|
|
|
}
|
2001-07-18 22:48:35 +00:00
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsChangeHint
|
|
|
|
nsStyleContext::CalcStyleDifference(nsStyleContext* aOther)
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
2003-02-22 00:32:13 +00:00
|
|
|
nsChangeHint hint = NS_STYLE_HINT_NONE;
|
2003-03-16 00:20:21 +00: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 19:52:46 +00: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 00:20:21 +00:00
|
|
|
|
|
|
|
// If our rule nodes are the same, then we are looking at the same
|
|
|
|
// style data. 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.
|
|
|
|
PRBool compare = mRuleNode != aOther->mRuleNode;
|
|
|
|
|
2003-03-16 04:51:56 +00:00
|
|
|
#define DO_STRUCT_DIFFERENCE(struct_) \
|
|
|
|
PR_BEGIN_MACRO \
|
2004-10-01 03:33:05 +00:00
|
|
|
NS_ASSERTION(NS_IsHintSubset(nsStyle##struct_::MaxDifference(), maxHint), \
|
|
|
|
"Struct placed in the wrong maxHint section"); \
|
2010-03-02 23:27:21 +00:00
|
|
|
const nsStyle##struct_* this##struct_ = PeekStyle##struct_(); \
|
2003-03-16 04:51:56 +00:00
|
|
|
if (this##struct_) { \
|
2006-12-12 17:44:45 +00:00
|
|
|
const nsStyle##struct_* other##struct_ = aOther->GetStyle##struct_(); \
|
2009-11-18 13:25:02 +00:00
|
|
|
if ((compare || nsStyle##struct_::ForceCompare()) && \
|
2003-03-16 04:51:56 +00:00
|
|
|
!NS_IsHintSubset(maxHint, hint) && \
|
|
|
|
this##struct_ != other##struct_) { \
|
2004-10-01 03:33:05 +00:00
|
|
|
NS_ASSERTION(NS_IsHintSubset( \
|
|
|
|
this##struct_->CalcDifference(*other##struct_), \
|
|
|
|
nsStyle##struct_::MaxDifference()), \
|
|
|
|
"CalcDifference() returned bigger hint than MaxDifference()"); \
|
2003-03-16 04:51:56 +00:00
|
|
|
NS_UpdateHint(hint, this##struct_->CalcDifference(*other##struct_)); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2003-03-16 00:20:21 +00:00
|
|
|
// We begin by examining those style structs that are capable of
|
|
|
|
// causing the maximal difference, a FRAMECHANGE.
|
|
|
|
// FRAMECHANGE Structs: Display, XUL, Content, UserInterface,
|
2009-06-13 09:16:34 +00:00
|
|
|
// Visibility, Outline, TableBorder, Table, Text, UIReset, Quotes
|
2010-07-15 21:07:53 +00:00
|
|
|
nsChangeHint maxHint = nsChangeHint(NS_STYLE_HINT_FRAMECHANGE |
|
2010-08-02 03:07:04 +00:00
|
|
|
nsChangeHint_UpdateTransformLayer | nsChangeHint_UpdateOpacityLayer);
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Display);
|
2010-07-15 21:07:53 +00:00
|
|
|
|
|
|
|
maxHint = nsChangeHint(NS_STYLE_HINT_FRAMECHANGE |
|
|
|
|
nsChangeHint_UpdateCursor);
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(XUL);
|
2004-06-17 11:57:37 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Column);
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Content);
|
|
|
|
DO_STRUCT_DIFFERENCE(UserInterface);
|
|
|
|
DO_STRUCT_DIFFERENCE(Visibility);
|
2004-07-16 16:56:21 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Outline);
|
2004-09-11 06:13:47 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(TableBorder);
|
2004-10-01 03:33:05 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Table);
|
|
|
|
DO_STRUCT_DIFFERENCE(UIReset);
|
2009-06-13 09:16:34 +00: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 05:38:33 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(List);
|
2003-03-16 00:20:21 +00:00
|
|
|
// If the quotes implementation is ever going to change we might not need
|
|
|
|
// a framechange here and a reflow should be sufficient. See bug 35768.
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Quotes);
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2008-08-06 00:55:07 +00:00
|
|
|
maxHint = nsChangeHint(NS_STYLE_HINT_REFLOW | nsChangeHint_UpdateEffects);
|
|
|
|
DO_STRUCT_DIFFERENCE(SVGReset);
|
2008-10-01 00:51:05 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(SVG);
|
2008-08-06 00:55:07 +00:00
|
|
|
|
2003-03-16 00:20:21 +00:00
|
|
|
// At this point, we know that the worst kind of damage we could do is
|
|
|
|
// a reflow.
|
|
|
|
maxHint = NS_STYLE_HINT_REFLOW;
|
|
|
|
|
|
|
|
// The following structs cause (as their maximal difference) a reflow
|
|
|
|
// to occur. REFLOW Structs: Font, Margin, Padding, Border, List,
|
2004-10-01 03:33:05 +00:00
|
|
|
// Position, Text, TextReset
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Font);
|
|
|
|
DO_STRUCT_DIFFERENCE(Margin);
|
|
|
|
DO_STRUCT_DIFFERENCE(Padding);
|
|
|
|
DO_STRUCT_DIFFERENCE(Border);
|
|
|
|
DO_STRUCT_DIFFERENCE(Position);
|
|
|
|
DO_STRUCT_DIFFERENCE(TextReset);
|
2003-03-16 00:20:21 +00:00
|
|
|
|
2010-08-13 13:33:37 +00:00
|
|
|
// Most backgrounds only require a re-render (i.e., a VISUAL change), but
|
|
|
|
// backgrounds using -moz-element need to reset SVG effects, too.
|
|
|
|
maxHint = nsChangeHint(NS_STYLE_HINT_VISUAL | nsChangeHint_UpdateEffects);
|
|
|
|
DO_STRUCT_DIFFERENCE(Background);
|
2003-03-16 00:20:21 +00:00
|
|
|
|
2010-08-13 13:33:37 +00:00
|
|
|
// Color only needs a repaint.
|
|
|
|
maxHint = NS_STYLE_HINT_VISUAL;
|
2003-03-16 04:51:56 +00:00
|
|
|
DO_STRUCT_DIFFERENCE(Color);
|
|
|
|
|
|
|
|
#undef DO_STRUCT_DIFFERENCE
|
2000-06-21 20:44:59 +00:00
|
|
|
|
2010-04-03 01:58:25 +00: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.
|
|
|
|
PRBool change = PR_FALSE;
|
|
|
|
|
|
|
|
// 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()) {
|
|
|
|
if (thisVis->GetStyleColor()->mColor !=
|
|
|
|
otherVis->GetStyleColor()->mColor) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleBackground()) {
|
|
|
|
if (thisVis->GetStyleBackground()->mBackgroundColor !=
|
|
|
|
otherVis->GetStyleBackground()->mBackgroundColor) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleBorder()) {
|
|
|
|
const nsStyleBorder *thisVisBorder = thisVis->GetStyleBorder();
|
|
|
|
const nsStyleBorder *otherVisBorder = otherVis->GetStyleBorder();
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
PRBool thisFG, otherFG;
|
|
|
|
nscolor thisColor, otherColor;
|
|
|
|
thisVisBorder->GetBorderColor(side, thisColor, thisFG);
|
|
|
|
otherVisBorder->GetBorderColor(side, otherColor, otherFG);
|
|
|
|
if (thisFG != otherFG || (!thisFG && thisColor != otherColor)) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleOutline()) {
|
|
|
|
const nsStyleOutline *thisVisOutline = thisVis->GetStyleOutline();
|
|
|
|
const nsStyleOutline *otherVisOutline = otherVis->GetStyleOutline();
|
|
|
|
PRBool haveColor;
|
|
|
|
nscolor thisColor, otherColor;
|
|
|
|
if (thisVisOutline->GetOutlineInitialColor() !=
|
|
|
|
otherVisOutline->GetOutlineInitialColor() ||
|
|
|
|
(haveColor = thisVisOutline->GetOutlineColor(thisColor)) !=
|
|
|
|
otherVisOutline->GetOutlineColor(otherColor) ||
|
|
|
|
(haveColor && thisColor != otherColor)) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleColumn()) {
|
|
|
|
const nsStyleColumn *thisVisColumn = thisVis->GetStyleColumn();
|
|
|
|
const nsStyleColumn *otherVisColumn = otherVis->GetStyleColumn();
|
|
|
|
if (thisVisColumn->mColumnRuleColor != otherVisColumn->mColumnRuleColor ||
|
|
|
|
thisVisColumn->mColumnRuleColorIsForeground !=
|
|
|
|
otherVisColumn->mColumnRuleColorIsForeground) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis| (see above).
|
|
|
|
if (!change && PeekStyleSVG()) {
|
|
|
|
const nsStyleSVG *thisVisSVG = thisVis->GetStyleSVG();
|
|
|
|
const nsStyleSVG *otherVisSVG = otherVis->GetStyleSVG();
|
|
|
|
if (thisVisSVG->mFill != otherVisSVG->mFill ||
|
|
|
|
thisVisSVG->mStroke != otherVisSVG->mStroke) {
|
|
|
|
change = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change) {
|
|
|
|
NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
return hint;
|
2000-06-21 20:44:59 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:14:17 +00: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 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2001-05-31 22:19:43 +00:00
|
|
|
void nsStyleContext::List(FILE* out, PRInt32 aIndent)
|
1998-05-18 21:04:26 +00:00
|
|
|
{
|
|
|
|
// Indent
|
1999-07-05 18:43:38 +00:00
|
|
|
PRInt32 ix;
|
|
|
|
for (ix = aIndent; --ix >= 0; ) fputs(" ", out);
|
2002-09-30 14:18:27 +00:00
|
|
|
fprintf(out, "%p(%d) parent=%p ",
|
2003-02-22 00:32:13 +00:00
|
|
|
(void*)this, mRefCnt, (void *)mParent);
|
2001-12-02 00:44:45 +00:00
|
|
|
if (mPseudoTag) {
|
1998-11-03 20:18:40 +00:00
|
|
|
nsAutoString buffer;
|
|
|
|
mPseudoTag->ToString(buffer);
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
|
1998-11-03 20:18:40 +00:00
|
|
|
fputs(" ", out);
|
|
|
|
}
|
2001-10-17 00:25:26 +00:00
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
if (mRuleNode) {
|
2001-10-17 00:25:26 +00:00
|
|
|
fputs("{\n", out);
|
2001-10-24 00:01:09 +00:00
|
|
|
nsRuleNode* ruleNode = mRuleNode;
|
2001-10-17 00:25:26 +00:00
|
|
|
while (ruleNode) {
|
2003-06-20 01:22:44 +00:00
|
|
|
nsIStyleRule *styleRule = ruleNode->GetRule();
|
2001-10-17 00:25:26 +00:00
|
|
|
if (styleRule) {
|
|
|
|
styleRule->List(out, aIndent + 1);
|
|
|
|
}
|
2001-10-24 00:01:09 +00:00
|
|
|
ruleNode = ruleNode->GetParent();
|
2001-10-17 00:25:26 +00:00
|
|
|
}
|
|
|
|
for (ix = aIndent; --ix >= 0; ) fputs(" ", out);
|
|
|
|
fputs("}\n", out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("{}\n", out);
|
|
|
|
}
|
|
|
|
|
1998-06-26 05:49:01 +00:00
|
|
|
if (nsnull != mChild) {
|
2001-05-31 22:19:43 +00:00
|
|
|
nsStyleContext* child = mChild;
|
1998-06-26 05:49:01 +00:00
|
|
|
do {
|
|
|
|
child->List(out, aIndent + 1);
|
1998-07-17 05:43:31 +00:00
|
|
|
child = child->mNextSibling;
|
1998-06-26 05:49:01 +00:00
|
|
|
} while (mChild != child);
|
|
|
|
}
|
1998-10-08 01:27:38 +00:00
|
|
|
if (nsnull != mEmptyChild) {
|
2001-05-31 22:19:43 +00:00
|
|
|
nsStyleContext* child = mEmptyChild;
|
1998-11-03 20:18:40 +00:00
|
|
|
do {
|
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
child = child->mNextSibling;
|
|
|
|
} while (mEmptyChild != child);
|
1998-10-08 01:27:38 +00:00
|
|
|
}
|
1998-05-18 21:04:26 +00:00
|
|
|
}
|
2000-12-07 15:31:40 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-31 22:19:43 +00: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-07-31 23:15:21 +00:00
|
|
|
nsStyleContext::operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
|
|
|
// Check the recycle list first.
|
2004-04-13 00:28:44 +00:00
|
|
|
return aPresContext->AllocateFromShell(sz);
|
2001-05-31 22:19:43 +00: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.
|
2010-03-25 13:17:11 +00:00
|
|
|
nsRefPtr<nsPresContext> presContext = mRuleNode->GetPresContext();
|
2001-05-31 22:19:43 +00: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.
|
|
|
|
presContext->FreeToShell(sizeof(nsStyleContext), this);
|
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
1998-11-03 20:18:40 +00:00
|
|
|
nsIAtom* aPseudoTag,
|
2009-12-11 07:37:40 +00:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2001-10-24 00:01:09 +00:00
|
|
|
nsRuleNode* aRuleNode,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* aPresContext)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2009-12-11 07:37:40 +00:00
|
|
|
nsStyleContext* context =
|
|
|
|
new (aPresContext) nsStyleContext(aParentContext, aPseudoTag, aPseudoType,
|
|
|
|
aRuleNode, aPresContext);
|
2003-02-22 00:32:13 +00:00
|
|
|
if (context)
|
|
|
|
context->AddRef();
|
|
|
|
return context;
|
2000-06-21 20:44:59 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 01:58:25 +00:00
|
|
|
static nscolor ExtractColor(nsCSSProperty aProperty,
|
|
|
|
nsStyleContext *aStyleContext)
|
|
|
|
{
|
|
|
|
nsStyleAnimation::Value val;
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool success =
|
|
|
|
#endif
|
|
|
|
nsStyleAnimation::ExtractComputedValue(aProperty, aStyleContext, val);
|
|
|
|
NS_ABORT_IF_FALSE(success,
|
|
|
|
"aProperty must be extractable by nsStyleAnimation");
|
|
|
|
return val.GetColorValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ColorIndexSet {
|
|
|
|
PRUint8 colorIndex, alphaIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
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 ||
|
|
|
|
aProperty == eCSSProperty_fill ||
|
|
|
|
aProperty == eCSSProperty_stroke,
|
|
|
|
"we need to add to nsStyleContext::CalcStyleDifference");
|
|
|
|
|
|
|
|
nscolor colors[2];
|
|
|
|
colors[0] = ExtractColor(aProperty, this);
|
|
|
|
|
|
|
|
nsStyleContext *visitedStyle = this->GetStyleIfVisited();
|
|
|
|
if (!visitedStyle) {
|
|
|
|
return colors[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
colors[1] = ExtractColor(aProperty, visitedStyle);
|
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
return nsStyleContext::CombineVisitedColors(colors,
|
|
|
|
this->RelevantLinkVisited());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscolor
|
|
|
|
nsStyleContext::CombineVisitedColors(nscolor *aColors, PRBool aLinkIsVisited)
|
|
|
|
{
|
2010-04-06 22:32:52 +00: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.
|
|
|
|
aLinkIsVisited = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-03 01:58:25 +00: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 01:58:26 +00:00
|
|
|
gVisitedIndices[aLinkIsVisited ? 1 : 0];
|
2010-04-03 01:58:25 +00:00
|
|
|
|
2010-04-03 01:58:26 +00:00
|
|
|
nscolor colorColor = aColors[set.colorIndex];
|
|
|
|
nscolor alphaColor = aColors[set.alphaIndex];
|
2010-04-03 01:58:25 +00:00
|
|
|
return NS_RGBA(NS_GET_R(colorColor), NS_GET_G(colorColor),
|
|
|
|
NS_GET_B(colorColor), NS_GET_A(alphaColor));
|
|
|
|
}
|
2010-07-03 04:18:55 +00:00
|
|
|
|
|
|
|
void*
|
|
|
|
nsStyleContext::Alloc(size_t aSize)
|
|
|
|
{
|
|
|
|
nsIPresShell *shell = PresContext()->PresShell();
|
|
|
|
|
|
|
|
aSize += offsetof(AllocationHeader, mStorageStart);
|
|
|
|
AllocationHeader *alloc =
|
|
|
|
static_cast<AllocationHeader*>(shell->AllocateMisc(aSize));
|
|
|
|
|
|
|
|
alloc->mSize = aSize; // NOTE: inflated by header
|
|
|
|
|
|
|
|
alloc->mNext = mAllocations;
|
|
|
|
mAllocations = alloc;
|
|
|
|
|
|
|
|
return static_cast<void*>(&alloc->mStorageStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleContext::FreeAllocations(nsPresContext *aPresContext)
|
|
|
|
{
|
|
|
|
nsIPresShell *shell = aPresContext->PresShell();
|
|
|
|
|
|
|
|
for (AllocationHeader *alloc = mAllocations, *next; alloc; alloc = next) {
|
|
|
|
next = alloc->mNext;
|
|
|
|
shell->FreeMisc(alloc->mSize, alloc);
|
|
|
|
}
|
|
|
|
}
|