2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04: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-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04: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-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-08-02 18:34:55 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2004-01-08 01:30:53 +03:00
|
|
|
* Brian Ryner <bryner@brianryner.com>
|
2008-07-26 20:14:48 +04:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04: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 05:32:19 +04: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-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04: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-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the container for the style sheets that apply to a presentation, and
|
|
|
|
* the internal API that the style system exposes for creating (and
|
|
|
|
* potentially re-creating) style contexts
|
|
|
|
*/
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsNetUtil.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
1999-01-23 10:01:57 +03:00
|
|
|
#include "nsIDocument.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsStyleContext.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-02-23 20:28:25 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2004-07-28 11:08:41 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
2007-10-12 22:37:51 +04:00
|
|
|
#include "nsContentUtils.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsRuleProcessorData.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2010-04-03 05:58:27 +04:00
|
|
|
#include "nsIEventStateManager.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 17:12:06 +04:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2008-12-12 21:59:03 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(nsEmptyStyleRule, nsIStyleRule)
|
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2008-12-12 21:59:03 +03:00
|
|
|
nsEmptyStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2008-12-12 21:59:03 +03:00
|
|
|
nsEmptyStyleRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
static const nsStyleSet::sheetType gCSSSheetTypes[] = {
|
|
|
|
nsStyleSet::eAgentSheet,
|
|
|
|
nsStyleSet::eUserSheet,
|
|
|
|
nsStyleSet::eDocSheet,
|
|
|
|
nsStyleSet::eOverrideSheet
|
|
|
|
};
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::nsStyleSet()
|
|
|
|
: mRuleTree(nsnull),
|
2009-09-24 21:59:43 +04:00
|
|
|
mUnusedRuleNodeCount(0),
|
2004-01-08 22:23:12 +03:00
|
|
|
mBatching(0),
|
2003-03-06 22:14:17 +03:00
|
|
|
mInShutdown(PR_FALSE),
|
2004-08-05 15:38:42 +04:00
|
|
|
mAuthorStyleDisabled(PR_FALSE),
|
2009-01-30 07:39:23 +03:00
|
|
|
mInReconstruct(PR_FALSE),
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty(0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::Init(nsPresContext *aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2008-12-12 21:59:03 +03:00
|
|
|
mFirstLineRule = new nsEmptyStyleRule;
|
|
|
|
mFirstLetterRule = new nsEmptyStyleRule;
|
|
|
|
if (!mFirstLineRule || !mFirstLetterRule) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2004-01-08 22:23:12 +03:00
|
|
|
if (!BuildDefaultStyleData(aPresContext)) {
|
|
|
|
mDefaultStyleData.Destroy(0, aPresContext);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mRuleTree = nsRuleNode::CreateRootNode(aPresContext);
|
|
|
|
if (!mRuleTree) {
|
|
|
|
mDefaultStyleData.Destroy(0, aPresContext);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
GatherRuleProcessors(eTransitionSheet);
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
return NS_OK;
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 21:14:13 +04:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::BeginReconstruct()
|
|
|
|
{
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(!mInReconstruct, "Unmatched begin/end?");
|
2007-07-25 21:14:13 +04:00
|
|
|
NS_ASSERTION(mRuleTree, "Reconstructing before first construction?");
|
|
|
|
|
|
|
|
// Create a new rule tree root
|
|
|
|
nsRuleNode* newTree =
|
|
|
|
nsRuleNode::CreateRootNode(mRuleTree->GetPresContext());
|
|
|
|
if (!newTree)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Save the old rule tree so we can destroy it later
|
2009-01-30 07:39:23 +03:00
|
|
|
if (!mOldRuleTrees.AppendElement(mRuleTree)) {
|
|
|
|
newTree->Destroy();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-07-25 21:14:13 +04:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
// We need to keep mRoots so that the rule tree GC will only free the
|
|
|
|
// rule trees that really aren't referenced anymore (which should be
|
|
|
|
// all of them, if there are no bugs in reresolution code).
|
|
|
|
|
|
|
|
mInReconstruct = PR_TRUE;
|
2007-07-25 21:14:13 +04:00
|
|
|
mRuleTree = newTree;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSet::EndReconstruct()
|
|
|
|
{
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(mInReconstruct, "Unmatched begin/end?");
|
|
|
|
mInReconstruct = PR_FALSE;
|
2009-01-17 00:32:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
for (PRInt32 i = mRoots.Length() - 1; i >= 0; --i) {
|
|
|
|
nsRuleNode *n = mRoots[i]->GetRuleNode();
|
|
|
|
while (n->GetParent()) {
|
|
|
|
n = n->GetParent();
|
|
|
|
}
|
|
|
|
// Since nsStyleContext's mParent and mRuleNode are immutable, and
|
|
|
|
// style contexts own their parents, and nsStyleContext asserts in
|
|
|
|
// its constructor that the style context and its parent are in the
|
|
|
|
// same rule tree, we don't need to check any of the children of
|
|
|
|
// mRoots; we only need to check the rule nodes of mRoots
|
|
|
|
// themselves.
|
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(n == mRuleTree, "style context has old rule node");
|
2009-01-17 00:32:09 +03:00
|
|
|
}
|
|
|
|
#endif
|
2009-01-30 07:39:23 +03:00
|
|
|
// This *should* destroy the only element of mOldRuleTrees, but in
|
|
|
|
// case of some bugs (which would trigger the above assertions), it
|
|
|
|
// won't.
|
|
|
|
GCRuleTrees();
|
2007-07-25 21:14:13 +04:00
|
|
|
}
|
|
|
|
|
2008-11-03 05:29:51 +03:00
|
|
|
void
|
|
|
|
nsStyleSet::SetQuirkStyleSheet(nsIStyleSheet* aQuirkStyleSheet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aQuirkStyleSheet, "Must have quirk sheet if this is called");
|
|
|
|
NS_ASSERTION(!mQuirkStyleSheet, "Multiple calls to SetQuirkStyleSheet?");
|
|
|
|
NS_ASSERTION(mSheets[eAgentSheet].IndexOf(aQuirkStyleSheet) != -1,
|
|
|
|
"Quirk style sheet not one of our agent sheets?");
|
|
|
|
mQuirkStyleSheet = aQuirkStyleSheet;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
nsresult
|
2004-07-28 11:08:41 +04:00
|
|
|
nsStyleSet::GatherRuleProcessors(sheetType aType)
|
1999-10-08 07:09:31 +04:00
|
|
|
{
|
2004-07-28 11:08:41 +04:00
|
|
|
mRuleProcessors[aType] = nsnull;
|
2004-08-05 15:38:42 +04:00
|
|
|
if (mAuthorStyleDisabled && (aType == eDocSheet ||
|
2011-01-15 05:14:41 +03:00
|
|
|
aType == ePresHintSheet ||
|
2004-08-05 15:38:42 +04:00
|
|
|
aType == eStyleAttrSheet)) {
|
|
|
|
//don't regather if this level is disabled
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
if (aType == eTransitionSheet) {
|
|
|
|
// We have no sheet for the transitions level; just a rule
|
|
|
|
// processor. (XXX: We should probably do this for the other
|
|
|
|
// non-CSS levels too!)
|
|
|
|
mRuleProcessors[aType] = PresContext()->TransitionManager();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
if (mSheets[aType].Count()) {
|
2004-07-28 11:08:41 +04:00
|
|
|
switch (aType) {
|
|
|
|
case eAgentSheet:
|
|
|
|
case eUserSheet:
|
|
|
|
case eDocSheet:
|
|
|
|
case eOverrideSheet: {
|
|
|
|
// levels containing CSS stylesheets
|
|
|
|
nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
|
2010-05-12 00:41:47 +04:00
|
|
|
nsTArray<nsRefPtr<nsCSSStyleSheet> > cssSheets(sheets.Count());
|
2004-07-28 11:08:41 +04:00
|
|
|
for (PRInt32 i = 0, i_end = sheets.Count(); i < i_end; ++i) {
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
|
2004-07-28 11:08:41 +04:00
|
|
|
NS_ASSERTION(cssSheet, "not a CSS sheet");
|
2010-05-12 00:41:47 +04:00
|
|
|
cssSheets.AppendElement(cssSheet);
|
2004-07-28 11:08:41 +04:00
|
|
|
}
|
2008-11-27 06:50:16 +03:00
|
|
|
mRuleProcessors[aType] = new nsCSSRuleProcessor(cssSheets,
|
|
|
|
PRUint8(aType));
|
2004-07-28 11:08:41 +04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// levels containing non-CSS stylesheets
|
|
|
|
NS_ASSERTION(mSheets[aType].Count() == 1, "only one sheet per level");
|
|
|
|
mRuleProcessors[aType] = do_QueryInterface(mSheets[aType][0]);
|
|
|
|
break;
|
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2004-01-08 01:30:53 +03:00
|
|
|
mSheets[aType].RemoveObject(aSheet);
|
|
|
|
if (!mSheets[aType].AppendObject(aSheet))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty |= 1 << aType;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2004-01-08 01:30:53 +03:00
|
|
|
mSheets[aType].RemoveObject(aSheet);
|
|
|
|
if (!mSheets[aType].InsertObjectAt(aSheet, 0))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty |= 1 << aType;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsComplete(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Incomplete sheet being removed from style set");
|
2004-01-08 01:30:53 +03:00
|
|
|
mSheets[aType].RemoveObject(aSheet);
|
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty |= 1 << aType;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::ReplaceSheets(sheetType aType,
|
|
|
|
const nsCOMArray<nsIStyleSheet> &aNewSheets)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
mSheets[aType].Clear();
|
2004-01-08 22:23:12 +03:00
|
|
|
if (!mSheets[aType].AppendObjects(aNewSheets))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty |= 1 << aType;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 15:38:42 +04:00
|
|
|
PRBool
|
|
|
|
nsStyleSet::GetAuthorStyleDisabled()
|
|
|
|
{
|
|
|
|
return mAuthorStyleDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStyleSet::SetAuthorStyleDisabled(PRBool aStyleDisabled)
|
|
|
|
{
|
|
|
|
if (aStyleDisabled == !mAuthorStyleDisabled) {
|
|
|
|
mAuthorStyleDisabled = aStyleDisabled;
|
|
|
|
BeginUpdate();
|
|
|
|
mDirty |= 1 << eDocSheet |
|
2011-01-15 05:14:41 +03:00
|
|
|
1 << ePresHintSheet |
|
2004-08-05 15:38:42 +04:00
|
|
|
1 << eStyleAttrSheet;
|
|
|
|
return EndUpdate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
// -------- Doc Sheets
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
NS_PRECONDITION(aSheet && aDocument, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet>& docSheets = mSheets[eDocSheet];
|
|
|
|
|
|
|
|
docSheets.RemoveObject(aSheet);
|
2004-07-28 11:08:41 +04:00
|
|
|
// lowest index first
|
2004-01-08 01:30:53 +03:00
|
|
|
PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
|
|
|
PRInt32 count = docSheets.Count();
|
2004-07-28 11:08:41 +04:00
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
2004-01-08 01:30:53 +03:00
|
|
|
nsIStyleSheet* sheet = docSheets.ObjectAt(index);
|
|
|
|
PRInt32 sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (sheetDocIndex > newDocIndex)
|
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-07-28 11:08:41 +04:00
|
|
|
if (!docSheets.InsertObjectAt(aSheet, index))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(eDocSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty |= 1 << eDocSheet;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
// Batching
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::BeginUpdate()
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
++mBatching;
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::EndUpdate()
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
NS_ASSERTION(mBatching > 0, "Unbalanced EndUpdate");
|
|
|
|
if (--mBatching) {
|
|
|
|
// We're not completely done yet.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
for (int i = 0; i < eSheetTypeCount; ++i) {
|
2004-01-08 22:23:12 +03:00
|
|
|
if (mDirty & (1 << i)) {
|
2004-07-28 11:08:41 +04:00
|
|
|
nsresult rv = GatherRuleProcessors(sheetType(i));
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty = 0;
|
|
|
|
return NS_OK;
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
|
|
|
nsStyleSet::EnableQuirkStyleSheet(PRBool aEnable)
|
2000-06-03 01:45:06 +04:00
|
|
|
{
|
2008-08-06 21:42:56 +04:00
|
|
|
#ifdef DEBUG
|
2008-11-26 00:27:54 +03:00
|
|
|
PRBool oldEnabled;
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> domSheet =
|
|
|
|
do_QueryInterface(mQuirkStyleSheet);
|
|
|
|
domSheet->GetDisabled(&oldEnabled);
|
|
|
|
oldEnabled = !oldEnabled;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mQuirkStyleSheet->SetEnabled(aEnable);
|
|
|
|
#ifdef DEBUG
|
|
|
|
// This should always be OK, since SetEnabled should call
|
|
|
|
// ClearRuleCascades.
|
|
|
|
// Note that we can hit this codepath multiple times when document.open()
|
|
|
|
// (potentially implied) happens multiple times.
|
|
|
|
if (mRuleProcessors[eAgentSheet] && aEnable != oldEnabled) {
|
2008-11-03 05:29:51 +03:00
|
|
|
static_cast<nsCSSRuleProcessor*>(static_cast<nsIStyleRuleProcessor*>(
|
|
|
|
mRuleProcessors[eAgentSheet]))->AssertQuirksChangeOK();
|
|
|
|
}
|
2008-08-06 21:42:56 +04:00
|
|
|
#endif
|
2000-06-03 01:45:06 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
template<class T>
|
1999-06-15 10:15:51 +04:00
|
|
|
static PRBool
|
2004-01-08 01:30:53 +03:00
|
|
|
EnumRulesMatching(nsIStyleRuleProcessor* aProcessor, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
T* data = static_cast<T*>(aData);
|
2004-08-05 22:26:14 +04:00
|
|
|
aProcessor->RulesMatching(data);
|
1999-06-15 10:15:51 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-03-08 02:48:26 +03:00
|
|
|
/**
|
|
|
|
* |GetContext| implements sharing of style contexts (not just the data
|
|
|
|
* on the rule nodes) between siblings and cousins of the same
|
|
|
|
* generation. (It works for cousins of the same generation since
|
|
|
|
* |aParentContext| could itself be a shared context.)
|
|
|
|
*/
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-02 10:07:42 +04:00
|
|
|
nsStyleSet::GetContext(nsStyleContext* aParentContext,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// aVisitedRuleNode may be null; if it is null
|
|
|
|
// it means that we don't need to force creation
|
|
|
|
// of a StyleIfVisited. (But if we make one
|
|
|
|
// because aParentContext has one, then aRuleNode
|
|
|
|
// should be used.)
|
|
|
|
nsRuleNode* aVisitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
PRBool aIsLink,
|
|
|
|
PRBool aIsVisitedLink,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_PRECONDITION((!aPseudoTag &&
|
|
|
|
aPseudoType ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement) ||
|
|
|
|
(aPseudoTag &&
|
|
|
|
nsCSSPseudoElements::GetPseudoType(aPseudoTag) ==
|
|
|
|
aPseudoType),
|
|
|
|
"Pseudo mismatch");
|
|
|
|
|
2010-06-15 00:06:48 +04:00
|
|
|
if (aVisitedRuleNode == aRuleNode) {
|
|
|
|
// No need to force creation of a visited style in this case.
|
|
|
|
aVisitedRuleNode = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
// Ensure |aVisitedRuleNode != nsnull| corresponds to the need to
|
|
|
|
// create an if-visited style context, and that in that case, we have
|
|
|
|
// parentIfVisited set correctly.
|
|
|
|
nsStyleContext *parentIfVisited =
|
|
|
|
aParentContext ? aParentContext->GetStyleIfVisited() : nsnull;
|
|
|
|
if (parentIfVisited) {
|
|
|
|
if (!aVisitedRuleNode) {
|
|
|
|
aVisitedRuleNode = aRuleNode;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aVisitedRuleNode) {
|
|
|
|
parentIfVisited = aParentContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsLink) {
|
|
|
|
// If this node is a link, we want its visited's style context's
|
|
|
|
// parent to be the regular style context of its parent, because
|
|
|
|
// only the visitedness of the relevant link should influence style.
|
|
|
|
parentIfVisited = aParentContext;
|
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRefPtr<nsStyleContext> result;
|
2002-03-31 20:59:00 +04:00
|
|
|
if (aParentContext)
|
2010-04-03 05:58:26 +04:00
|
|
|
result = aParentContext->FindChildWithRules(aPseudoTag, aRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
aVisitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
aIsVisitedLink);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
2002-03-31 20:59:00 +04:00
|
|
|
if (result)
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "--- SharedSC %d ---\n", ++gSharedCount);
|
2002-03-31 20:59:00 +04:00
|
|
|
else
|
|
|
|
fprintf(stdout, "+++ NewSC %d +++\n", ++gNewCount);
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
2003-03-06 22:14:17 +03:00
|
|
|
if (!result) {
|
2009-12-11 10:37:40 +03:00
|
|
|
result = NS_NewStyleContext(aParentContext, aPseudoTag, aPseudoType,
|
2010-04-03 05:58:27 +04:00
|
|
|
aRuleNode, PresContext());
|
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
|
|
|
if (aVisitedRuleNode) {
|
|
|
|
nsRefPtr<nsStyleContext> resultIfVisited =
|
|
|
|
NS_NewStyleContext(parentIfVisited, aPseudoTag, aPseudoType,
|
|
|
|
aVisitedRuleNode, PresContext());
|
|
|
|
if (!resultIfVisited) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-04-30 05:15:44 +04:00
|
|
|
if (!parentIfVisited) {
|
|
|
|
mRoots.AppendElement(resultIfVisited);
|
|
|
|
}
|
2010-04-06 23:42:41 +04:00
|
|
|
resultIfVisited->SetIsStyleIfVisited();
|
2010-04-03 05:58:27 +04:00
|
|
|
result->SetStyleIfVisited(resultIfVisited.forget());
|
2010-04-03 05:58:27 +04:00
|
|
|
|
|
|
|
PRBool relevantLinkVisited =
|
|
|
|
aIsLink ? aIsVisitedLink
|
|
|
|
: (aParentContext && aParentContext->RelevantLinkVisited());
|
|
|
|
if (relevantLinkVisited) {
|
|
|
|
result->AddStyleBit(NS_STYLE_RELEVANT_LINK_VISITED);
|
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
}
|
|
|
|
if (!aParentContext)
|
2003-03-06 22:14:17 +03:00
|
|
|
mRoots.AppendElement(result);
|
|
|
|
}
|
2009-12-11 10:37:40 +03:00
|
|
|
else {
|
|
|
|
NS_ASSERTION(result->GetPseudoType() == aPseudoType, "Unexpected type");
|
|
|
|
NS_ASSERTION(result->GetPseudo() == aPseudoTag, "Unexpected pseudo");
|
|
|
|
}
|
2002-03-31 20:59:00 +04:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return result.forget();
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::AddImportantRules(nsRuleNode* aCurrLevelNode,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleNode* aLastPrevLevelNode,
|
|
|
|
nsRuleWalker* aRuleWalker)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2009-12-12 09:36:34 +03:00
|
|
|
NS_ASSERTION(aCurrLevelNode &&
|
|
|
|
aCurrLevelNode != aLastPrevLevelNode, "How did we get here?");
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
nsAutoTArray<nsIStyleRule*, 16> importantRules;
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
2009-12-11 01:36:02 +03:00
|
|
|
// We guarantee that we never walk the root node here, so no need
|
|
|
|
// to null-check GetRule().
|
|
|
|
nsIStyleRule* impRule = node->GetRule()->GetImportantRule();
|
|
|
|
if (impRule)
|
|
|
|
importantRules.AppendElement(impRule);
|
2008-07-14 00:57:38 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
NS_ASSERTION(importantRules.Length() != 0,
|
|
|
|
"Why did we think there were important rules?");
|
|
|
|
|
2008-07-14 00:57:38 +04:00
|
|
|
for (PRUint32 i = importantRules.Length(); i-- != 0; ) {
|
2009-10-03 01:06:42 +04:00
|
|
|
aRuleWalker->Forward(importantRules[i]);
|
1998-09-11 06:05:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsStyleSet::AssertNoImportantRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode)
|
|
|
|
{
|
2008-07-14 00:57:38 +04:00
|
|
|
if (!aCurrLevelNode)
|
2004-07-16 00:30:30 +04:00
|
|
|
return;
|
|
|
|
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
2009-12-11 01:36:02 +03:00
|
|
|
nsIStyleRule* rule = node->GetRule();
|
|
|
|
if (rule) {
|
|
|
|
NS_ASSERTION(!rule->GetImportantRule(), "Unexpected important rule");
|
2008-07-14 00:57:38 +04:00
|
|
|
}
|
2004-07-16 00:30:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSet::AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode)
|
|
|
|
{
|
2008-07-14 00:57:38 +04:00
|
|
|
if (!aCurrLevelNode)
|
2004-07-16 00:30:30 +04:00
|
|
|
return;
|
|
|
|
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
|
|
|
nsIStyleRule *rule = node->GetRule();
|
2011-03-11 05:48:57 +03:00
|
|
|
nsRefPtr<mozilla::css::StyleRule> cssRule(do_QueryObject(rule));
|
2008-07-14 00:57:38 +04:00
|
|
|
NS_ASSERTION(!cssRule || !cssRule->Selector(), "Unexpected CSS rule");
|
|
|
|
}
|
2004-07-16 00:30:30 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate the rules in a way that cares about the order of the rules.
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
|
2009-12-11 10:37:40 +03:00
|
|
|
void* aData, nsIContent* aContent,
|
|
|
|
nsRuleWalker* aRuleWalker)
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
|
|
|
// Cascading order:
|
|
|
|
// [least important]
|
2004-07-16 00:30:30 +04:00
|
|
|
// 1. UA normal rules = Agent normal
|
2011-01-15 05:14:41 +03:00
|
|
|
// 2. User normal rules = User normal
|
2011-01-15 05:14:41 +03:00
|
|
|
// 3. Presentation hints = PresHint normal
|
2011-01-15 05:14:41 +03:00
|
|
|
// 4. Author normal rules = Document normal
|
|
|
|
// 5. Override normal rules = Override normal
|
|
|
|
// 6. Author !important rules = Document !important
|
|
|
|
// 7. Override !important rules = Override !important
|
|
|
|
// 8. User !important rules = User !important
|
|
|
|
// 9. UA !important rules = Agent !important
|
2001-11-06 13:04:05 +03:00
|
|
|
// [most important]
|
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eAgentSheet, PR_FALSE, PR_TRUE);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eAgentSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eAgentSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastAgentRN = aRuleWalker->CurrentNode();
|
2009-12-11 01:36:02 +03:00
|
|
|
PRBool haveImportantUARules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eUserSheet, PR_FALSE, PR_TRUE);
|
2008-02-26 15:40:18 +03:00
|
|
|
PRBool skipUserStyles =
|
2009-12-11 10:37:40 +03:00
|
|
|
aContent && aContent->IsInNativeAnonymousSubtree();
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eUserSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastUserRN = aRuleWalker->CurrentNode();
|
2009-12-11 01:36:02 +03:00
|
|
|
PRBool haveImportantUserRules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2011-01-15 05:14:41 +03:00
|
|
|
aRuleWalker->SetLevel(ePresHintSheet, PR_FALSE, PR_FALSE);
|
|
|
|
if (mRuleProcessors[ePresHintSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[ePresHintSheet], aData);
|
|
|
|
nsRuleNode* lastPresHintRN = aRuleWalker->CurrentNode();
|
2004-05-05 04:30:57 +04:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eDocSheet, PR_FALSE, PR_TRUE);
|
2004-09-10 08:57:30 +04:00
|
|
|
PRBool cutOffInheritance = PR_FALSE;
|
2009-12-11 10:37:40 +03:00
|
|
|
if (mBindingManager && aContent) {
|
2001-11-06 13:04:05 +03:00
|
|
|
// We can supply additional document-level sheets that should be walked.
|
2009-12-11 10:37:40 +03:00
|
|
|
mBindingManager->WalkRules(aCollectorFunc,
|
|
|
|
static_cast<RuleProcessorData*>(aData),
|
|
|
|
&cutOffInheritance);
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && !cutOffInheritance &&
|
|
|
|
mRuleProcessors[eDocSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eDocSheet], aData);
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eStyleAttrSheet, PR_FALSE,
|
|
|
|
aRuleWalker->GetCheckForImportantRules());
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eStyleAttrSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eStyleAttrSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastDocRN = aRuleWalker->CurrentNode();
|
2009-12-11 01:36:02 +03:00
|
|
|
PRBool haveImportantDocRules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eOverrideSheet, PR_FALSE, PR_TRUE);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eOverrideSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eOverrideSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastOvrRN = aRuleWalker->CurrentNode();
|
2009-12-11 01:36:02 +03:00
|
|
|
PRBool haveImportantOverrideRules = !aRuleWalker->GetCheckForImportantRules();
|
|
|
|
|
|
|
|
if (haveImportantDocRules) {
|
|
|
|
aRuleWalker->SetLevel(eDocSheet, PR_TRUE, PR_FALSE);
|
2011-01-15 05:14:41 +03:00
|
|
|
AddImportantRules(lastDocRN, lastPresHintRN, aRuleWalker); // doc
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2011-01-15 05:14:41 +03:00
|
|
|
AssertNoImportantRules(lastDocRN, lastPresHintRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (haveImportantOverrideRules) {
|
|
|
|
aRuleWalker->SetLevel(eOverrideSheet, PR_TRUE, PR_FALSE);
|
|
|
|
AddImportantRules(lastOvrRN, lastDocRN, aRuleWalker); // override
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
AssertNoImportantRules(lastOvrRN, lastDocRN);
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
#ifdef DEBUG
|
2011-01-15 05:14:41 +03:00
|
|
|
AssertNoCSSRules(lastPresHintRN, lastUserRN);
|
|
|
|
AssertNoImportantRules(lastPresHintRN, lastUserRN); // preshints
|
2004-07-16 00:30:30 +04:00
|
|
|
#endif
|
2009-12-11 01:36:02 +03:00
|
|
|
|
|
|
|
if (haveImportantUserRules) {
|
|
|
|
aRuleWalker->SetLevel(eUserSheet, PR_TRUE, PR_FALSE);
|
2011-01-15 05:14:41 +03:00
|
|
|
AddImportantRules(lastUserRN, lastAgentRN, aRuleWalker); //user
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2011-01-15 05:14:41 +03:00
|
|
|
AssertNoImportantRules(lastUserRN, lastAgentRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (haveImportantUARules) {
|
|
|
|
aRuleWalker->SetLevel(eAgentSheet, PR_TRUE, PR_FALSE);
|
|
|
|
AddImportantRules(lastAgentRN, mRuleTree, aRuleWalker); //agent
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
AssertNoImportantRules(lastAgentRN, mRuleTree);
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
#ifdef DEBUG
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *lastImportantRN = aRuleWalker->CurrentNode();
|
2009-10-08 07:22:42 +04:00
|
|
|
#endif
|
2009-12-11 01:36:02 +03:00
|
|
|
aRuleWalker->SetLevel(eTransitionSheet, PR_FALSE, PR_FALSE);
|
2009-10-08 07:22:42 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eTransitionSheet], aData);
|
|
|
|
#ifdef DEBUG
|
2009-12-12 09:36:34 +03:00
|
|
|
AssertNoCSSRules(aRuleWalker->CurrentNode(), lastImportantRN);
|
|
|
|
AssertNoImportantRules(aRuleWalker->CurrentNode(), lastImportantRN);
|
2009-10-08 07:22:42 +04:00
|
|
|
#endif
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate all the rules in a way that doesn't care about the order
|
2004-01-14 04:36:35 +03:00
|
|
|
// of the rules and doesn't walk !important-rules.
|
2001-11-11 02:51:45 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2010-03-25 12:22:58 +03:00
|
|
|
RuleProcessorData* aData,
|
|
|
|
PRBool aWalkAllXBLStylesheets)
|
2001-11-11 02:51:45 +03:00
|
|
|
{
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eAgentSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eAgentSheet], aData);
|
2007-05-05 10:47:09 +04:00
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
PRBool skipUserStyles = aData->mElement->IsInNativeAnonymousSubtree();
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eUserSheet], aData);
|
2007-05-05 10:47:09 +04:00
|
|
|
|
2011-01-15 05:14:41 +03:00
|
|
|
if (mRuleProcessors[ePresHintSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[ePresHintSheet], aData);
|
2004-05-05 04:30:57 +04:00
|
|
|
|
2004-09-10 08:57:30 +04:00
|
|
|
PRBool cutOffInheritance = PR_FALSE;
|
2007-02-17 02:02:08 +03:00
|
|
|
if (mBindingManager) {
|
2001-11-11 02:51:45 +03:00
|
|
|
// We can supply additional document-level sheets that should be walked.
|
2010-03-25 12:22:58 +03:00
|
|
|
if (aWalkAllXBLStylesheets) {
|
|
|
|
mBindingManager->WalkAllRules(aFunc, aData);
|
|
|
|
} else {
|
|
|
|
mBindingManager->WalkRules(aFunc, aData, &cutOffInheritance);
|
|
|
|
}
|
2001-11-11 02:51:45 +03:00
|
|
|
}
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && !cutOffInheritance &&
|
|
|
|
mRuleProcessors[eDocSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eDocSheet], aData);
|
|
|
|
if (mRuleProcessors[eStyleAttrSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eStyleAttrSheet], aData);
|
|
|
|
if (mRuleProcessors[eOverrideSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eOverrideSheet], aData);
|
2009-10-08 07:22:42 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eTransitionSheet], aData);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
PRBool nsStyleSet::BuildDefaultStyleData(nsPresContext* aPresContext)
|
2003-03-13 18:29:36 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mDefaultStyleData.mResetData &&
|
|
|
|
!mDefaultStyleData.mInheritedData,
|
|
|
|
"leaking default style data");
|
|
|
|
mDefaultStyleData.mResetData = new (aPresContext) nsResetStyleData;
|
|
|
|
if (!mDefaultStyleData.mResetData)
|
|
|
|
return PR_FALSE;
|
|
|
|
mDefaultStyleData.mInheritedData = new (aPresContext) nsInheritedStyleData;
|
|
|
|
if (!mDefaultStyleData.mInheritedData)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
#define SSARG_PRESCONTEXT aPresContext
|
|
|
|
|
|
|
|
#define CREATE_DATA(name, type, args) \
|
2011-03-18 06:14:32 +03:00
|
|
|
if (!(mDefaultStyleData.m##type##Data->mStyleStructs[eStyleStruct_##name] = \
|
2003-03-13 18:29:36 +03:00
|
|
|
new (aPresContext) nsStyle##name args)) \
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
#define STYLE_STRUCT_INHERITED(name, checkdata_cb, ctor_args) \
|
|
|
|
CREATE_DATA(name, Inherited, ctor_args)
|
|
|
|
#define STYLE_STRUCT_RESET(name, checkdata_cb, ctor_args) \
|
|
|
|
CREATE_DATA(name, Reset, ctor_args)
|
|
|
|
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
|
|
|
|
#undef STYLE_STRUCT_INHERITED
|
|
|
|
#undef STYLE_STRUCT_RESET
|
|
|
|
#undef SSARG_PRESCONTEXT
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolveStyleFor(Element* aElement,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aParentContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-06-03 05:51:15 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aElement, "aElement must not be null");
|
1998-05-19 01:05:52 +04:00
|
|
|
|
2010-04-02 10:07:42 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
2011-03-29 21:29:21 +04:00
|
|
|
ElementRuleProcessorData data(PresContext(), aElement, &ruleWalker);
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
|
2010-04-02 10:07:42 +04:00
|
|
|
&ruleWalker);
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
|
|
|
nsRuleNode *visitedRuleNode = nsnull;
|
|
|
|
|
|
|
|
if (ruleWalker.HaveRelevantLink()) {
|
2011-03-29 21:29:20 +04:00
|
|
|
data.ResetForVisitedMatching();
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
|
2010-04-03 05:58:27 +04:00
|
|
|
&ruleWalker);
|
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2011-03-29 21:29:21 +04:00
|
|
|
nsCSSRuleProcessor::IsLink(aElement),
|
|
|
|
nsCSSRuleProcessor::GetContentState(aElement).
|
|
|
|
HasState(NS_EVENT_STATE_VISITED),
|
2010-04-02 10:07:42 +04:00
|
|
|
nsnull, nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 22:21:34 +04:00
|
|
|
already_AddRefed<nsStyleContext>
|
2009-08-11 02:52:29 +04:00
|
|
|
nsStyleSet::ResolveStyleForRules(nsStyleContext* aParentContext,
|
|
|
|
const nsCOMArray<nsIStyleRule> &aRules)
|
2007-07-25 22:21:34 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
2010-04-02 10:07:42 +04:00
|
|
|
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
|
|
|
// FIXME: Perhaps this should be passed in, but it probably doesn't
|
|
|
|
// matter.
|
|
|
|
ruleWalker.SetLevel(eDocSheet, PR_FALSE, PR_FALSE);
|
|
|
|
for (PRInt32 i = 0; i < aRules.Count(); i++) {
|
|
|
|
ruleWalker.Forward(aRules.ObjectAt(i));
|
2007-07-25 22:21:34 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aParentContext, ruleWalker.CurrentNode(), nsnull,
|
2010-04-03 05:58:27 +04:00
|
|
|
PR_FALSE, PR_FALSE,
|
2010-04-03 05:58:25 +04:00
|
|
|
nsnull, nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
|
|
|
|
const nsCOMArray<nsIStyleRule> &aRules)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
|
|
|
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
|
|
|
ruleWalker.SetCurrentNode(aBaseContext->GetRuleNode());
|
|
|
|
// FIXME: Perhaps this should be passed in, but it probably doesn't
|
|
|
|
// matter.
|
|
|
|
ruleWalker.SetLevel(eDocSheet, PR_FALSE, PR_FALSE);
|
|
|
|
for (PRInt32 i = 0; i < aRules.Count(); i++) {
|
|
|
|
ruleWalker.Forward(aRules.ObjectAt(i));
|
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
|
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
|
|
|
nsRuleNode *visitedRuleNode = nsnull;
|
|
|
|
|
|
|
|
if (aBaseContext->GetStyleIfVisited()) {
|
|
|
|
ruleWalker.SetCurrentNode(aBaseContext->GetStyleIfVisited()->GetRuleNode());
|
|
|
|
for (PRInt32 i = 0; i < aRules.Count(); i++) {
|
|
|
|
ruleWalker.Forward(aRules.ObjectAt(i));
|
|
|
|
}
|
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContext(aBaseContext->GetParent(), ruleNode, visitedRuleNode,
|
2010-06-08 23:58:26 +04:00
|
|
|
aBaseContext->IsLinkContext(),
|
|
|
|
aBaseContext->RelevantLinkVisited(),
|
2010-04-03 05:58:25 +04:00
|
|
|
aBaseContext->GetPseudo(),
|
|
|
|
aBaseContext->GetPseudoType());
|
2007-07-25 22:21:34 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2004-01-28 03:18:22 +03:00
|
|
|
nsStyleSet::ResolveStyleForNonElement(nsStyleContext* aParentContext)
|
2001-10-30 09:02:05 +03:00
|
|
|
{
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aParentContext, mRuleTree, nsnull,
|
2010-04-03 05:58:27 +04:00
|
|
|
PR_FALSE, PR_FALSE,
|
2010-04-02 10:07:42 +04:00
|
|
|
nsCSSAnonBoxes::mozNonElement,
|
|
|
|
nsCSSPseudoElements::ePseudo_AnonBox);
|
2001-10-30 09:02:05 +03:00
|
|
|
}
|
|
|
|
|
2008-12-12 21:59:03 +03:00
|
|
|
void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsStyleSet::WalkRestrictionRule(nsCSSPseudoElements::Type aPseudoType,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleWalker* aRuleWalker)
|
2008-12-12 21:59:03 +03:00
|
|
|
{
|
|
|
|
// This needs to match GetPseudoRestriction in nsRuleNode.cpp.
|
2009-12-11 10:37:40 +03:00
|
|
|
aRuleWalker->SetLevel(eAgentSheet, PR_FALSE, PR_FALSE);
|
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLetter)
|
|
|
|
aRuleWalker->Forward(mFirstLetterRule);
|
|
|
|
else if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLine)
|
|
|
|
aRuleWalker->Forward(mFirstLineRule);
|
2009-12-11 05:28:08 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolvePseudoElementStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aType,
|
|
|
|
nsStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
|
|
|
|
|
|
|
NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
|
|
|
|
"must have pseudo element type");
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aParentElement, "Must have parent element");
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
2010-04-30 17:12:06 +04:00
|
|
|
PseudoElementRuleProcessorData data(PresContext(), aParentElement,
|
2010-04-02 10:07:42 +04:00
|
|
|
&ruleWalker, aType);
|
2009-12-11 10:37:40 +03:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
|
|
|
nsRuleNode *visitedRuleNode = nsnull;
|
|
|
|
|
|
|
|
if (ruleWalker.HaveRelevantLink()) {
|
2011-03-29 21:29:20 +04:00
|
|
|
data.ResetForVisitedMatching();
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
|
|
|
PR_FALSE, PR_FALSE,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::GetPseudoAtom(aType), aType);
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ProbePseudoElementStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aType,
|
|
|
|
nsStyleContext* aParentContext)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
2005-06-03 05:51:15 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
|
|
|
|
"must have pseudo element type");
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aParentElement, "aParentElement must not be null");
|
2009-12-11 05:28:08 +03:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
2010-04-30 17:12:06 +04:00
|
|
|
PseudoElementRuleProcessorData data(PresContext(), aParentElement,
|
2010-04-02 10:07:42 +04:00
|
|
|
&ruleWalker, aType);
|
2009-12-11 10:37:40 +03:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
|
|
|
// not the root if there was a restriction rule
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *adjustedRoot = ruleWalker.CurrentNode();
|
2009-12-11 10:37:40 +03:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2009-12-11 05:28:08 +03:00
|
|
|
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2009-12-11 10:37:40 +03:00
|
|
|
if (ruleNode == adjustedRoot) {
|
|
|
|
return nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2003-02-23 20:28:25 +03:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nsnull;
|
|
|
|
|
|
|
|
if (ruleWalker.HaveRelevantLink()) {
|
2011-03-29 21:29:20 +04:00
|
|
|
data.ResetForVisitedMatching();
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
nsRefPtr<nsStyleContext> result =
|
2010-04-03 05:58:27 +04:00
|
|
|
GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
|
|
|
PR_FALSE, PR_FALSE,
|
2010-04-03 05:58:27 +04:00
|
|
|
pseudoTag, aType);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2003-02-23 20:28:25 +03:00
|
|
|
// For :before and :after pseudo-elements, having display: none or no
|
|
|
|
// 'content' property is equivalent to not having the pseudo-element
|
|
|
|
// at all.
|
|
|
|
if (result &&
|
2009-12-11 10:37:40 +03:00
|
|
|
(pseudoTag == nsCSSPseudoElements::before ||
|
|
|
|
pseudoTag == nsCSSPseudoElements::after)) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay *display = result->GetStyleDisplay();
|
|
|
|
const nsStyleContent *content = result->GetStyleContent();
|
2003-02-23 20:28:25 +03:00
|
|
|
// XXXldb What is contentCount for |content: ""|?
|
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_NONE ||
|
|
|
|
content->ContentCount() == 0) {
|
|
|
|
result = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
return result.forget();
|
2009-12-11 01:36:06 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool isAnonBox = nsCSSAnonBoxes::IsAnonBox(aPseudoTag)
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
&& !nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag)
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
NS_PRECONDITION(isAnonBox, "Unexpected pseudo");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
2010-04-02 10:07:42 +04:00
|
|
|
AnonBoxRuleProcessorData data(PresContext(), aPseudoTag, &ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
FileRules(EnumRulesMatching<AnonBoxRuleProcessorData>, &data, nsnull,
|
|
|
|
&ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aParentContext, ruleWalker.CurrentNode(), nsnull,
|
2010-04-03 05:58:27 +04:00
|
|
|
PR_FALSE, PR_FALSE,
|
2009-12-11 10:37:40 +03:00
|
|
|
aPseudoTag, nsCSSPseudoElements::ePseudo_AnonBox);
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolveXULTreePseudoStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsICSSPseudoComparator* aComparator)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nsnull);
|
|
|
|
|
|
|
|
NS_ASSERTION(aPseudoTag, "must have pseudo tag");
|
|
|
|
NS_ASSERTION(nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag),
|
|
|
|
"Unexpected pseudo");
|
|
|
|
|
|
|
|
nsRuleWalker ruleWalker(mRuleTree);
|
2010-04-30 17:12:06 +04:00
|
|
|
XULTreeRuleProcessorData data(PresContext(), aParentElement, &ruleWalker,
|
2009-12-11 10:37:40 +03:00
|
|
|
aPseudoTag, aComparator);
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data, aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
&ruleWalker);
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
|
|
|
nsRuleNode *visitedRuleNode = nsnull;
|
|
|
|
|
|
|
|
if (ruleWalker.HaveRelevantLink()) {
|
2011-03-29 21:29:20 +04:00
|
|
|
data.ResetForVisitedMatching();
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
|
|
|
PR_FALSE, PR_FALSE,
|
2009-12-11 10:37:40 +03:00
|
|
|
aPseudoTag, nsCSSPseudoElements::ePseudo_XULTree);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
PRBool
|
|
|
|
nsStyleSet::AppendFontFaceRules(nsPresContext* aPresContext,
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& aArray)
|
2008-11-26 02:22:38 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, PR_FALSE);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gCSSSheetTypes); ++i) {
|
|
|
|
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
|
|
|
if (ruleProc && !ruleProc->AppendFontFaceRules(aPresContext, aArray))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::BeginShutdown(nsPresContext* aPresContext)
|
2003-03-06 22:14:17 +03:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
mInShutdown = 1;
|
2003-03-06 22:14:17 +03:00
|
|
|
mRoots.Clear(); // no longer valid, since we won't keep it up to date
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::Shutdown(nsPresContext* aPresContext)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
mRuleTree->Destroy();
|
|
|
|
mRuleTree = nsnull;
|
2003-03-13 18:29:36 +03:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
// We can have old rule trees either because:
|
|
|
|
// (1) we failed the assertions in EndReconstruct, or
|
|
|
|
// (2) we're shutting down within a reconstruct (see bug 462392)
|
|
|
|
for (PRUint32 i = mOldRuleTrees.Length(); i > 0; ) {
|
|
|
|
--i;
|
|
|
|
mOldRuleTrees[i]->Destroy();
|
|
|
|
}
|
|
|
|
mOldRuleTrees.Clear();
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDefaultStyleData.Destroy(0, aPresContext);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2009-09-29 23:24:18 +04:00
|
|
|
static const PRUint32 kGCInterval = 300;
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::NotifyStyleContextDestroyed(nsPresContext* aPresContext,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aStyleContext)
|
2003-03-06 22:14:17 +03:00
|
|
|
{
|
|
|
|
if (mInShutdown)
|
2004-01-08 01:30:53 +03:00
|
|
|
return;
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2007-11-15 09:13:48 +03:00
|
|
|
// Remove style contexts from mRoots even if mOldRuleTree is non-null. This
|
|
|
|
// could be a style context from the new ruletree!
|
2003-03-06 22:14:17 +03:00
|
|
|
if (!aStyleContext->GetParent()) {
|
|
|
|
mRoots.RemoveElement(aStyleContext);
|
|
|
|
}
|
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
if (mInReconstruct)
|
2007-11-15 09:13:48 +03:00
|
|
|
return;
|
|
|
|
|
2011-01-19 05:20:35 +03:00
|
|
|
if (mUnusedRuleNodeCount >= kGCInterval) {
|
2009-01-30 07:39:23 +03:00
|
|
|
GCRuleTrees();
|
|
|
|
}
|
|
|
|
}
|
2009-01-29 23:39:19 +03:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
void
|
|
|
|
nsStyleSet::GCRuleTrees()
|
|
|
|
{
|
2009-09-24 21:59:43 +04:00
|
|
|
mUnusedRuleNodeCount = 0;
|
2009-01-30 07:39:23 +03:00
|
|
|
|
|
|
|
// Mark the style context tree by marking all style contexts which
|
|
|
|
// have no parent, which will mark all descendants. This will reach
|
|
|
|
// style contexts in the undisplayed map and "additional style
|
|
|
|
// contexts" since they are descendants of the roots.
|
|
|
|
for (PRInt32 i = mRoots.Length() - 1; i >= 0; --i) {
|
|
|
|
mRoots[i]->Mark();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sweep the rule tree.
|
2004-01-08 01:30:53 +03:00
|
|
|
#ifdef DEBUG
|
2009-01-30 07:39:23 +03:00
|
|
|
PRBool deleted =
|
2004-01-08 01:30:53 +03:00
|
|
|
#endif
|
2009-01-30 07:39:23 +03:00
|
|
|
mRuleTree->Sweep();
|
|
|
|
NS_ASSERTION(!deleted, "Root node must not be gc'd");
|
|
|
|
|
|
|
|
// Sweep the old rule trees.
|
|
|
|
for (PRUint32 i = mOldRuleTrees.Length(); i > 0; ) {
|
|
|
|
--i;
|
|
|
|
if (mOldRuleTrees[i]->Sweep()) {
|
|
|
|
// It was deleted, as it should be.
|
|
|
|
mOldRuleTrees.RemoveElementAt(i);
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("old rule tree still referenced");
|
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
}
|
2003-03-06 22:14:17 +03:00
|
|
|
}
|
|
|
|
|
2010-06-23 08:46:27 +04:00
|
|
|
static inline nsRuleNode*
|
2010-07-01 05:54:29 +04:00
|
|
|
SkipTransitionRules(nsRuleNode* aRuleNode, Element* aElement, PRBool isPseudo)
|
2010-06-23 08:46:27 +04:00
|
|
|
{
|
|
|
|
nsRuleNode* ruleNode = aRuleNode;
|
|
|
|
while (!ruleNode->IsRoot() &&
|
|
|
|
ruleNode->GetLevel() == nsStyleSet::eTransitionSheet) {
|
|
|
|
ruleNode = ruleNode->GetParent();
|
|
|
|
}
|
|
|
|
if (ruleNode != aRuleNode) {
|
|
|
|
NS_ASSERTION(aElement, "How can we have transition rules but no element?");
|
|
|
|
// Need to do an animation restyle, just like
|
|
|
|
// nsTransitionManager::WalkTransitionRule would.
|
2010-07-01 05:54:29 +04:00
|
|
|
nsRestyleHint hint = isPseudo ? eRestyle_Subtree : eRestyle_Self;
|
|
|
|
aRuleNode->GetPresContext()->PresShell()->RestyleForAnimation(aElement,
|
|
|
|
hint);
|
2010-06-23 08:46:27 +04:00
|
|
|
}
|
|
|
|
return ruleNode;
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-02 10:07:42 +04:00
|
|
|
nsStyleSet::ReparentStyleContext(nsStyleContext* aStyleContext,
|
2010-06-23 08:46:27 +04:00
|
|
|
nsStyleContext* aNewParentContext,
|
|
|
|
Element* aElement)
|
1999-09-04 03:35:41 +04:00
|
|
|
{
|
2010-04-02 10:07:42 +04:00
|
|
|
if (!aStyleContext) {
|
|
|
|
NS_NOTREACHED("must have style context");
|
|
|
|
return nsnull;
|
|
|
|
}
|
1999-09-04 03:35:41 +04:00
|
|
|
|
2010-06-23 08:46:27 +04:00
|
|
|
// This short-circuit is OK because we don't call TryStartingTransition
|
|
|
|
// during style reresolution if the style context pointer hasn't changed.
|
2010-04-02 10:07:42 +04:00
|
|
|
if (aStyleContext->GetParent() == aNewParentContext) {
|
|
|
|
aStyleContext->AddRef();
|
|
|
|
return aStyleContext;
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
|
|
|
nsIAtom* pseudoTag = aStyleContext->GetPseudo();
|
|
|
|
nsCSSPseudoElements::Type pseudoType = aStyleContext->GetPseudoType();
|
|
|
|
nsRuleNode* ruleNode = aStyleContext->GetRuleNode();
|
2010-06-23 08:46:27 +04:00
|
|
|
|
|
|
|
// Skip transition rules as needed just like
|
|
|
|
// nsTransitionManager::WalkTransitionRule would.
|
|
|
|
PRBool skipTransitionRules = PresContext()->IsProcessingRestyles() &&
|
|
|
|
!PresContext()->IsProcessingAnimationStyleChange();
|
|
|
|
if (skipTransitionRules) {
|
|
|
|
// Make sure that we're not using transition rules for our new style
|
|
|
|
// context. If we need them, an animation restyle will provide.
|
2010-07-01 05:54:29 +04:00
|
|
|
ruleNode =
|
|
|
|
SkipTransitionRules(ruleNode, aElement,
|
|
|
|
pseudoType !=
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
2010-06-23 08:46:27 +04:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode* visitedRuleNode = nsnull;
|
|
|
|
nsStyleContext* visitedContext = aStyleContext->GetStyleIfVisited();
|
2010-06-08 23:58:26 +04:00
|
|
|
// Reparenting a style context just changes where we inherit from,
|
|
|
|
// not what rules we match or what our DOM looks like. In
|
|
|
|
// particular, it doesn't change whether this is a style context for
|
|
|
|
// a link.
|
2010-04-03 05:58:27 +04:00
|
|
|
if (visitedContext) {
|
|
|
|
visitedRuleNode = visitedContext->GetRuleNode();
|
2010-06-23 08:46:27 +04:00
|
|
|
// Again, skip transition rules as needed
|
|
|
|
if (skipTransitionRules) {
|
2010-07-01 05:54:29 +04:00
|
|
|
visitedRuleNode =
|
|
|
|
SkipTransitionRules(visitedRuleNode, aElement,
|
|
|
|
pseudoType !=
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
2010-06-23 08:46:27 +04:00
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aNewParentContext, ruleNode, visitedRuleNode,
|
2010-06-08 23:58:26 +04:00
|
|
|
aStyleContext->IsLinkContext(),
|
|
|
|
aStyleContext->RelevantLinkVisited(),
|
2010-04-03 05:58:27 +04:00
|
|
|
pseudoTag, pseudoType);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
struct StatefulData : public StateRuleProcessorData {
|
2004-08-01 03:15:21 +04:00
|
|
|
StatefulData(nsPresContext* aPresContext,
|
2010-10-20 15:26:32 +04:00
|
|
|
Element* aElement, nsEventStates aStateMask)
|
2010-04-30 17:12:06 +04:00
|
|
|
: StateRuleProcessorData(aPresContext, aElement, aStateMask),
|
2010-04-01 04:43:32 +04:00
|
|
|
mHint(nsRestyleHint(0))
|
1999-04-20 04:02:22 +04:00
|
|
|
{}
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint mHint;
|
2010-03-17 20:10:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool SheetHasDocumentStateStyle(nsIStyleRuleProcessor* aProcessor,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
StatefulData* data = (StatefulData*)aData;
|
|
|
|
if (aProcessor->HasDocumentStateDependentStyle(data)) {
|
2010-04-01 04:43:32 +04:00
|
|
|
data->mHint = eRestyle_Self;
|
2010-03-17 20:10:57 +03:00
|
|
|
return PR_FALSE; // don't continue
|
|
|
|
}
|
|
|
|
return PR_TRUE; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on a document state.
|
|
|
|
PRBool
|
|
|
|
nsStyleSet::HasDocumentStateDependentStyle(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates aStateMask)
|
2010-03-17 20:10:57 +03:00
|
|
|
{
|
2010-04-30 17:12:06 +04:00
|
|
|
if (!aContent || !aContent->IsElement())
|
2010-03-17 20:10:57 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
StatefulData data(aPresContext, aContent->AsElement(), aStateMask);
|
2010-03-25 12:22:58 +03:00
|
|
|
WalkRuleProcessors(SheetHasDocumentStateStyle, &data, PR_TRUE);
|
2010-03-17 20:10:57 +03:00
|
|
|
return data.mHint != 0;
|
|
|
|
}
|
1999-04-20 04:02:22 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
static PRBool SheetHasStatefulStyle(nsIStyleRuleProcessor* aProcessor,
|
|
|
|
void *aData)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
|
|
|
StatefulData* data = (StatefulData*)aData;
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint hint = aProcessor->HasStateDependentStyle(data);
|
|
|
|
data->mHint = nsRestyleHint(data->mHint | hint);
|
1999-04-20 04:02:22 +04:00
|
|
|
return PR_TRUE; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2010-10-20 15:26:32 +04:00
|
|
|
nsStyleSet::HasStateDependentStyle(nsPresContext* aPresContext,
|
|
|
|
Element* aElement,
|
|
|
|
nsEventStates aStateMask)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
2010-05-14 21:04:51 +04:00
|
|
|
StatefulData data(aPresContext, aElement, aStateMask);
|
|
|
|
WalkRuleProcessors(SheetHasStatefulStyle, &data, PR_FALSE);
|
|
|
|
return data.mHint;
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AttributeData : public AttributeRuleProcessorData {
|
2004-08-01 03:15:21 +04:00
|
|
|
AttributeData(nsPresContext* aPresContext,
|
2010-04-30 17:12:06 +04:00
|
|
|
Element* aElement, nsIAtom* aAttribute, PRInt32 aModType,
|
2009-12-11 01:36:03 +03:00
|
|
|
PRBool aAttrHasChanged)
|
2010-04-30 17:12:06 +04:00
|
|
|
: AttributeRuleProcessorData(aPresContext, aElement, aAttribute, aModType,
|
2009-12-11 01:36:03 +03:00
|
|
|
aAttrHasChanged),
|
2010-04-01 04:43:32 +04:00
|
|
|
mHint(nsRestyleHint(0))
|
2003-02-22 19:10:53 +03:00
|
|
|
{}
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint mHint;
|
2003-02-22 19:10:53 +03:00
|
|
|
};
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
static PRBool
|
|
|
|
SheetHasAttributeStyle(nsIStyleRuleProcessor* aProcessor, void *aData)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
|
|
|
AttributeData* data = (AttributeData*)aData;
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint hint = aProcessor->HasAttributeDependentStyle(data);
|
|
|
|
data->mHint = nsRestyleHint(data->mHint | hint);
|
2003-02-22 19:10:53 +03:00
|
|
|
return PR_TRUE; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::HasAttributeDependentStyle(nsPresContext* aPresContext,
|
2010-05-14 21:04:51 +04:00
|
|
|
Element* aElement,
|
2007-07-13 00:05:45 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType,
|
2009-12-11 01:36:03 +03:00
|
|
|
PRBool aAttrHasChanged)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
2010-05-14 21:04:51 +04:00
|
|
|
AttributeData data(aPresContext, aElement, aAttribute,
|
|
|
|
aModType, aAttrHasChanged);
|
|
|
|
WalkRuleProcessors(SheetHasAttributeStyle, &data, PR_FALSE);
|
|
|
|
return data.mHint;
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStyleSet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// We can't use WalkRuleProcessors without a content node.
|
|
|
|
PRBool stylesChanged = PR_FALSE;
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(mRuleProcessors); ++i) {
|
|
|
|
nsIStyleRuleProcessor *processor = mRuleProcessors[i];
|
|
|
|
if (!processor) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-19 01:20:40 +04:00
|
|
|
PRBool thisChanged = processor->MediumFeaturesChanged(aPresContext);
|
2008-07-26 20:14:48 +04:00
|
|
|
stylesChanged = stylesChanged || thisChanged;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:49 +04:00
|
|
|
if (mBindingManager) {
|
|
|
|
PRBool thisChanged = PR_FALSE;
|
|
|
|
mBindingManager->MediumFeaturesChanged(aPresContext, &thisChanged);
|
|
|
|
stylesChanged = stylesChanged || thisChanged;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
return stylesChanged;
|
|
|
|
}
|
2009-12-31 18:56:33 +03:00
|
|
|
|
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult
|
|
|
|
nsStyleSet::EnsureUniqueInnerOnCSSSheets()
|
|
|
|
{
|
|
|
|
nsAutoTArray<nsCSSStyleSheet*, 32> queue;
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gCSSSheetTypes); ++i) {
|
|
|
|
nsCOMArray<nsIStyleSheet> &sheets = mSheets[gCSSSheetTypes[i]];
|
|
|
|
for (PRUint32 j = 0, j_end = sheets.Count(); j < j_end; ++j) {
|
|
|
|
nsCSSStyleSheet *sheet = static_cast<nsCSSStyleSheet*>(sheets[j]);
|
|
|
|
if (!queue.AppendElement(sheet)) {
|
|
|
|
return nsCSSStyleSheet::eUniqueInner_CloneFailed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-17 09:36:34 +04:00
|
|
|
if (mBindingManager) {
|
|
|
|
mBindingManager->AppendAllSheets(queue);
|
|
|
|
}
|
|
|
|
|
2009-12-31 18:56:33 +03:00
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult res =
|
|
|
|
nsCSSStyleSheet::eUniqueInner_AlreadyUnique;
|
|
|
|
while (!queue.IsEmpty()) {
|
|
|
|
PRUint32 idx = queue.Length() - 1;
|
|
|
|
nsCSSStyleSheet *sheet = queue[idx];
|
|
|
|
queue.RemoveElementAt(idx);
|
|
|
|
|
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult sheetRes =
|
|
|
|
sheet->EnsureUniqueInner();
|
|
|
|
if (sheetRes == nsCSSStyleSheet::eUniqueInner_CloneFailed) {
|
|
|
|
return sheetRes;
|
|
|
|
}
|
|
|
|
if (sheetRes == nsCSSStyleSheet::eUniqueInner_ClonedInner) {
|
|
|
|
res = sheetRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue all the sheet's children.
|
|
|
|
if (!sheet->AppendAllChildSheets(queue)) {
|
|
|
|
return nsCSSStyleSheet::eUniqueInner_CloneFailed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|