2006-04-04 03:52:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2008-04-08 22:36:53 +04:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2008-08-13 04:44:14 +04:00
|
|
|
* Rob Arnold <robarnold@mozilla.com>
|
2006-04-04 03:52:17 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* style rule processor for CSS style sheets, responsible for selector
|
|
|
|
* matching and cascading
|
|
|
|
*/
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsRuleProcessorData.h"
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
2011-12-08 10:32:11 +04:00
|
|
|
// We want page-sized arenas so there's no fragmentation involved.
|
|
|
|
#define NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE (4096)
|
2006-04-04 03:52:17 +04:00
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsICSSPseudoComparator.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2010-08-08 09:28:33 +04:00
|
|
|
#include "mozilla/css/GroupRule.h"
|
2006-04-04 03:52:17 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-21 21:35:52 +04:00
|
|
|
#include "nsEventStateManager.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2006-04-04 03:52:17 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsCSSPseudoClasses.h"
|
2009-12-11 10:37:40 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2006-07-19 08:36:36 +04:00
|
|
|
#include "nsIContent.h"
|
2006-04-04 03:52:17 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "nsQuickSort.h"
|
|
|
|
#include "nsAttrValue.h"
|
|
|
|
#include "nsAttrName.h"
|
2007-11-19 23:08:20 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2008-06-11 04:27:00 +04:00
|
|
|
#include "nsContentUtils.h"
|
2008-07-26 20:14:48 +04:00
|
|
|
#include "nsIMediaList.h"
|
2008-10-01 07:01:53 +04:00
|
|
|
#include "nsCSSRules.h"
|
2008-11-27 06:50:16 +03:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsStyleSet.h"
|
2009-12-11 10:37:41 +03:00
|
|
|
#include "prlog.h"
|
2010-04-07 21:29:10 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsNetCID.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-10-07 08:25:47 +04:00
|
|
|
#include "nsGenericElement.h"
|
2011-03-29 21:29:21 +04:00
|
|
|
#include "nsNthIndexCache.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-09 06:27:12 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2010-04-30 17:12:06 +04:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:06 +04:00
|
|
|
using namespace mozilla::dom;
|
2007-11-19 23:08:20 +03:00
|
|
|
|
2008-10-21 11:15:03 +04:00
|
|
|
#define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled"
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gSupportVisitedPseudo = true;
|
2008-10-21 11:15:03 +04:00
|
|
|
|
2007-11-19 23:08:20 +03:00
|
|
|
static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-10-10 00:53:45 +04:00
|
|
|
#ifdef XP_WIN
|
2011-09-09 06:27:12 +04:00
|
|
|
PRUint8 nsCSSRuleProcessor::sWinThemeId = LookAndFeel::eWindowsTheme_Generic;
|
2010-10-10 00:53:45 +04:00
|
|
|
#endif
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
/**
|
|
|
|
* A struct representing a given CSS rule and a particular selector
|
|
|
|
* from that rule's selector list.
|
|
|
|
*/
|
|
|
|
struct RuleSelectorPair {
|
2011-03-11 05:48:57 +03:00
|
|
|
RuleSelectorPair(css::StyleRule* aRule, nsCSSSelector* aSelector)
|
2006-04-04 03:52:17 +04:00
|
|
|
: mRule(aRule), mSelector(aSelector) {}
|
2011-12-08 10:32:11 +04:00
|
|
|
// If this class ever grows a destructor, deal with
|
|
|
|
// PerWeightDataListItem appropriately.
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
css::StyleRule* mRule;
|
2006-04-04 03:52:17 +04:00
|
|
|
nsCSSSelector* mSelector; // which of |mRule|'s selectors
|
2010-07-03 00:56:09 +04:00
|
|
|
};
|
|
|
|
|
2012-03-13 07:54:14 +04:00
|
|
|
#define NS_IS_ANCESTOR_OPERATOR(ch) \
|
|
|
|
((ch) == PRUnichar(' ') || (ch) == PRUnichar('>'))
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
/**
|
|
|
|
* A struct representing a particular rule in an ordered list of rules
|
|
|
|
* (the ordering depending on the weight of mSelector and the order of
|
|
|
|
* our rules to start with).
|
|
|
|
*/
|
|
|
|
struct RuleValue : RuleSelectorPair {
|
2012-03-13 07:54:14 +04:00
|
|
|
enum {
|
|
|
|
eMaxAncestorHashes = 4
|
|
|
|
};
|
|
|
|
|
2012-03-14 09:44:13 +04:00
|
|
|
RuleValue(const RuleSelectorPair& aRuleSelectorPair, PRInt32 aIndex,
|
|
|
|
bool aQuirksMode) :
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleSelectorPair(aRuleSelectorPair),
|
|
|
|
mIndex(aIndex)
|
2012-03-13 07:54:14 +04:00
|
|
|
{
|
2012-03-14 09:44:13 +04:00
|
|
|
CollectAncestorHashes(aQuirksMode);
|
2012-03-13 07:54:14 +04:00
|
|
|
}
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
PRInt32 mIndex; // High index means high weight/order.
|
2012-03-13 07:54:14 +04:00
|
|
|
uint32_t mAncestorSelectorHashes[eMaxAncestorHashes];
|
|
|
|
|
|
|
|
private:
|
2012-03-14 09:44:13 +04:00
|
|
|
void CollectAncestorHashes(bool aQuirksMode) {
|
2012-03-13 07:54:14 +04:00
|
|
|
// Collect up our mAncestorSelectorHashes. It's not clear whether it's
|
|
|
|
// better to stop once we've found eMaxAncestorHashes of them or to keep
|
|
|
|
// going and preferentially collect information from selectors higher up the
|
|
|
|
// chain... Let's do the former for now.
|
|
|
|
size_t hashIndex = 0;
|
|
|
|
for (nsCSSSelector* sel = mSelector->mNext; sel; sel = sel->mNext) {
|
|
|
|
if (!NS_IS_ANCESTOR_OPERATOR(sel->mOperator)) {
|
|
|
|
// |sel| is going to select something that's not actually one of our
|
|
|
|
// ancestors, so don't add it to mAncestorSelectorHashes. But keep
|
|
|
|
// going, because it'll select a sibling of one of our ancestors, so its
|
|
|
|
// ancestors would be our ancestors too.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-14 09:44:13 +04:00
|
|
|
// Now sel is supposed to select one of our ancestors. Grab
|
|
|
|
// whatever info we can from it into mAncestorSelectorHashes.
|
|
|
|
// But in qurks mode, don't grab IDs and classes because those
|
|
|
|
// need to be matched case-insensitively.
|
|
|
|
if (!aQuirksMode) {
|
|
|
|
nsAtomList* ids = sel->mIDList;
|
|
|
|
while (ids) {
|
|
|
|
mAncestorSelectorHashes[hashIndex++] = ids->mAtom->hash();
|
|
|
|
if (hashIndex == eMaxAncestorHashes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ids = ids->mNext;
|
2012-03-13 07:54:14 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 09:44:13 +04:00
|
|
|
nsAtomList* classes = sel->mClassList;
|
|
|
|
while (classes) {
|
|
|
|
mAncestorSelectorHashes[hashIndex++] = classes->mAtom->hash();
|
|
|
|
if (hashIndex == eMaxAncestorHashes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
classes = classes->mNext;
|
2012-03-13 07:54:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only put in the tag name if it's all-lowercase. Otherwise we run into
|
|
|
|
// trouble because we may test the wrong one of mLowercaseTag and
|
|
|
|
// mCasedTag against the filter.
|
|
|
|
if (sel->mLowercaseTag && sel->mCasedTag == sel->mLowercaseTag) {
|
|
|
|
mAncestorSelectorHashes[hashIndex++] = sel->mLowercaseTag->hash();
|
|
|
|
if (hashIndex == eMaxAncestorHashes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (hashIndex != eMaxAncestorHashes) {
|
|
|
|
mAncestorSelectorHashes[hashIndex++] = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Rule hash table
|
|
|
|
//
|
|
|
|
|
|
|
|
// Uses any of the sets of ops below.
|
|
|
|
struct RuleHashTableEntry : public PLDHashEntryHdr {
|
2011-08-08 16:34:57 +04:00
|
|
|
// If you add members that have heap allocated memory be sure to change the
|
2011-12-09 09:01:52 +04:00
|
|
|
// logic in SizeOfRuleHashTableEntry().
|
2011-10-06 06:06:37 +04:00
|
|
|
// Auto length 1, because we always have at least one entry in mRules.
|
|
|
|
nsAutoTArray<RuleValue, 1> mRules;
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
struct RuleHashTagTableEntry : public RuleHashTableEntry {
|
2011-08-08 16:34:57 +04:00
|
|
|
// If you add members that have heap allocated memory be sure to change the
|
2011-12-09 09:01:52 +04:00
|
|
|
// logic in RuleHash::SizeOf{In,Ex}cludingThis.
|
2009-08-01 19:53:40 +04:00
|
|
|
nsCOMPtr<nsIAtom> mTag;
|
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleHash_CIHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIAtom *atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
atom->ToString(str);
|
2010-08-03 02:19:04 +04:00
|
|
|
nsContentUtils::ASCIIToLower(str);
|
2006-04-04 03:52:17 +04:00
|
|
|
return HashString(str);
|
|
|
|
}
|
|
|
|
|
2007-03-27 19:33:38 +04:00
|
|
|
typedef nsIAtom*
|
2008-10-10 19:04:34 +04:00
|
|
|
(* RuleHashGetKey) (PLDHashTable *table, const PLDHashEntryHdr *entry);
|
2007-03-27 19:33:38 +04:00
|
|
|
|
|
|
|
struct RuleHashTableOps {
|
|
|
|
PLDHashTableOps ops;
|
|
|
|
// Extra callback to avoid duplicating the matchEntry callback for
|
|
|
|
// each table. (There used to be a getKey callback in
|
|
|
|
// PLDHashTableOps.)
|
|
|
|
RuleHashGetKey getKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const RuleHashTableOps*
|
|
|
|
ToLocalOps(const PLDHashTableOps *aOps)
|
|
|
|
{
|
|
|
|
return (const RuleHashTableOps*)
|
|
|
|
(((const char*) aOps) - offsetof(RuleHashTableOps, ops));
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleHash_CIMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
|
|
|
(key));
|
2007-03-27 19:33:38 +04:00
|
|
|
// Use our extra |getKey| callback to avoid code duplication.
|
|
|
|
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// Check for case-sensitive match first.
|
|
|
|
if (match_atom == entry_atom)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
// Use EqualsIgnoreASCIICase instead of full on unicode case conversion
|
|
|
|
// in order to save on performance. This is only used in quirks mode
|
|
|
|
// anyway.
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
return
|
|
|
|
nsContentUtils::EqualsIgnoreASCIICase(nsDependentAtomString(entry_atom),
|
|
|
|
nsDependentAtomString(match_atom));
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleHash_CSMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
|
|
|
(key));
|
2007-03-27 19:33:38 +04:00
|
|
|
// Use our extra |getKey| callback to avoid code duplication.
|
|
|
|
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
return match_atom == entry_atom;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
new (entry) RuleHashTableEntry();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RuleHash_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
entry->~RuleHashTableEntry();
|
|
|
|
}
|
|
|
|
|
2011-10-06 06:06:37 +04:00
|
|
|
static void
|
|
|
|
RuleHash_MoveEntry(PLDHashTable *table, const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(from != to, "This is not going to work!");
|
|
|
|
RuleHashTableEntry *oldEntry =
|
|
|
|
const_cast<RuleHashTableEntry*>(
|
|
|
|
static_cast<const RuleHashTableEntry*>(from));
|
|
|
|
RuleHashTableEntry *newEntry = new (to) RuleHashTableEntry();
|
|
|
|
newEntry->mRules.SwapElements(oldEntry->mRules);
|
|
|
|
oldEntry->~RuleHashTableEntry();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2009-08-01 19:53:40 +04:00
|
|
|
RuleHash_TagTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2009-08-01 19:53:40 +04:00
|
|
|
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
|
|
|
(key));
|
|
|
|
nsIAtom *entry_atom = static_cast<const RuleHashTagTableEntry*>(hdr)->mTag;
|
|
|
|
|
|
|
|
return match_atom == entry_atom;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_TagTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>(hdr);
|
|
|
|
new (entry) RuleHashTagTableEntry();
|
2010-07-08 20:50:18 +04:00
|
|
|
entry->mTag = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RuleHash_TagTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
2009-08-01 19:53:40 +04:00
|
|
|
{
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>(hdr);
|
|
|
|
entry->~RuleHashTagTableEntry();
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-10-06 06:06:37 +04:00
|
|
|
static void
|
|
|
|
RuleHash_TagTable_MoveEntry(PLDHashTable *table, const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(from != to, "This is not going to work!");
|
|
|
|
RuleHashTagTableEntry *oldEntry =
|
|
|
|
const_cast<RuleHashTagTableEntry*>(
|
|
|
|
static_cast<const RuleHashTagTableEntry*>(from));
|
|
|
|
RuleHashTagTableEntry *newEntry = new (to) RuleHashTagTableEntry();
|
|
|
|
newEntry->mTag.swap(oldEntry->mTag);
|
|
|
|
newEntry->mRules.SwapElements(oldEntry->mRules);
|
|
|
|
oldEntry->~RuleHashTagTableEntry();
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static nsIAtom*
|
2007-03-27 19:33:38 +04:00
|
|
|
RuleHash_ClassTable_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-03-27 19:33:38 +04:00
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2010-07-03 00:56:09 +04:00
|
|
|
return entry->mRules[0].mSelector->mClassList->mAtom;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static nsIAtom*
|
2007-03-27 19:33:38 +04:00
|
|
|
RuleHash_IdTable_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-03-27 19:33:38 +04:00
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2010-07-03 00:56:09 +04:00
|
|
|
return entry->mRules[0].mSelector->mIDList->mAtom;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleHash_NameSpaceTable_HashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(key);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleHash_NameSpaceTable_MatchEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
return NS_PTR_TO_INT32(key) ==
|
2010-07-03 00:56:09 +04:00
|
|
|
entry->mRules[0].mSelector->mNameSpace;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
static const PLDHashTableOps RuleHash_TagTable_Ops = {
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
2009-08-01 19:53:40 +04:00
|
|
|
RuleHash_TagTable_MatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_TagTable_MoveEntry,
|
2009-08-01 19:53:40 +04:00
|
|
|
RuleHash_TagTable_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_TagTable_InitEntry
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2007-03-27 19:33:38 +04:00
|
|
|
static const RuleHashTableOps RuleHash_ClassTable_CSOps = {
|
|
|
|
{
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
RuleHash_CSMatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 19:33:38 +04:00
|
|
|
},
|
|
|
|
RuleHash_ClassTable_GetKey
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2007-03-27 19:33:38 +04:00
|
|
|
static const RuleHashTableOps RuleHash_ClassTable_CIOps = {
|
|
|
|
{
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 19:33:38 +04:00
|
|
|
},
|
|
|
|
RuleHash_ClassTable_GetKey
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2007-03-27 19:33:38 +04:00
|
|
|
static const RuleHashTableOps RuleHash_IdTable_CSOps = {
|
|
|
|
{
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
RuleHash_CSMatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 19:33:38 +04:00
|
|
|
},
|
|
|
|
RuleHash_IdTable_GetKey
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2007-03-27 19:33:38 +04:00
|
|
|
static const RuleHashTableOps RuleHash_IdTable_CIOps = {
|
|
|
|
{
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 19:33:38 +04:00
|
|
|
},
|
|
|
|
RuleHash_IdTable_GetKey
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
2007-03-27 19:33:38 +04:00
|
|
|
static const PLDHashTableOps RuleHash_NameSpaceTable_Ops = {
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_NameSpaceTable_HashKey,
|
|
|
|
RuleHash_NameSpaceTable_MatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_ClearEntry,
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleHash_InitEntry
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef RULE_HASH_STATS
|
|
|
|
#undef PRINT_UNIVERSAL_RULES
|
|
|
|
|
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
#define RULE_HASH_STAT_INCREMENT(var_) PR_BEGIN_MACRO ++(var_); PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define RULE_HASH_STAT_INCREMENT(var_) PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
struct NodeMatchContext;
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
class RuleHash {
|
|
|
|
public:
|
2011-09-29 10:19:26 +04:00
|
|
|
RuleHash(bool aQuirksMode);
|
2006-04-04 03:52:17 +04:00
|
|
|
~RuleHash();
|
2010-07-03 00:56:09 +04:00
|
|
|
void AppendRule(const RuleSelectorPair &aRuleInfo);
|
2011-11-14 22:10:22 +04:00
|
|
|
void EnumerateAllRules(Element* aElement, RuleProcessorData* aData,
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext& aNodeMatchContext);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
protected:
|
2010-07-03 00:56:09 +04:00
|
|
|
typedef nsTArray<RuleValue> RuleValueList;
|
|
|
|
void AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
|
|
|
|
const RuleSelectorPair& aRuleInfo);
|
|
|
|
void AppendUniversalRule(const RuleSelectorPair& aRuleInfo);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
PRInt32 mRuleCount;
|
2011-12-09 14:29:01 +04:00
|
|
|
// The hashtables are lazily initialized; we use a null .ops to
|
|
|
|
// indicate that they need initialization.
|
2006-04-04 03:52:17 +04:00
|
|
|
PLDHashTable mIdTable;
|
|
|
|
PLDHashTable mClassTable;
|
|
|
|
PLDHashTable mTagTable;
|
|
|
|
PLDHashTable mNameSpaceTable;
|
2010-07-03 00:56:09 +04:00
|
|
|
RuleValueList mUniversalRules;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
struct EnumData {
|
|
|
|
const RuleValue* mCurValue;
|
|
|
|
const RuleValue* mEnd;
|
|
|
|
};
|
|
|
|
EnumData* mEnumList;
|
|
|
|
PRInt32 mEnumListSize;
|
|
|
|
|
2011-12-09 14:29:01 +04:00
|
|
|
bool mQuirksMode;
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
inline EnumData ToEnumData(const RuleValueList& arr) {
|
|
|
|
EnumData data = { arr.Elements(), arr.Elements() + arr.Length() };
|
|
|
|
return data;
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
PRUint32 mUniversalSelectors;
|
|
|
|
PRUint32 mNameSpaceSelectors;
|
|
|
|
PRUint32 mTagSelectors;
|
|
|
|
PRUint32 mClassSelectors;
|
|
|
|
PRUint32 mIdSelectors;
|
|
|
|
|
|
|
|
PRUint32 mElementsMatched;
|
|
|
|
|
|
|
|
PRUint32 mElementUniversalCalls;
|
|
|
|
PRUint32 mElementNameSpaceCalls;
|
|
|
|
PRUint32 mElementTagCalls;
|
|
|
|
PRUint32 mElementClassCalls;
|
|
|
|
PRUint32 mElementIdCalls;
|
|
|
|
#endif // RULE_HASH_STATS
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
RuleHash::RuleHash(bool aQuirksMode)
|
2006-04-04 03:52:17 +04:00
|
|
|
: mRuleCount(0),
|
|
|
|
mUniversalRules(nsnull),
|
2011-12-09 14:29:01 +04:00
|
|
|
mEnumList(nsnull), mEnumListSize(0),
|
|
|
|
mQuirksMode(aQuirksMode)
|
2006-04-04 03:52:17 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
,
|
|
|
|
mUniversalSelectors(0),
|
|
|
|
mNameSpaceSelectors(0),
|
|
|
|
mTagSelectors(0),
|
|
|
|
mClassSelectors(0),
|
|
|
|
mIdSelectors(0),
|
|
|
|
mElementsMatched(0),
|
|
|
|
mElementUniversalCalls(0),
|
|
|
|
mElementNameSpaceCalls(0),
|
|
|
|
mElementTagCalls(0),
|
|
|
|
mElementClassCalls(0),
|
2009-12-11 10:37:40 +03:00
|
|
|
mElementIdCalls(0)
|
2006-04-04 03:52:17 +04:00
|
|
|
#endif
|
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
MOZ_COUNT_CTOR(RuleHash);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2011-12-09 14:29:01 +04:00
|
|
|
mTagTable.ops = nsnull;
|
|
|
|
mIdTable.ops = nsnull;
|
|
|
|
mClassTable.ops = nsnull;
|
|
|
|
mNameSpaceTable.ops = nsnull;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleHash::~RuleHash()
|
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
MOZ_COUNT_DTOR(RuleHash);
|
2006-04-04 03:52:17 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
printf(
|
|
|
|
"RuleHash(%p):\n"
|
|
|
|
" Selectors: Universal (%u) NameSpace(%u) Tag(%u) Class(%u) Id(%u)\n"
|
2009-12-11 10:37:40 +03:00
|
|
|
" Content Nodes: Elements(%u)\n"
|
2006-04-04 03:52:17 +04:00
|
|
|
" Element Calls: Universal(%u) NameSpace(%u) Tag(%u) Class(%u) Id(%u)\n"
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<void*>(this),
|
2006-04-04 03:52:17 +04:00
|
|
|
mUniversalSelectors, mNameSpaceSelectors, mTagSelectors,
|
|
|
|
mClassSelectors, mIdSelectors,
|
|
|
|
mElementsMatched,
|
|
|
|
mElementUniversalCalls, mElementNameSpaceCalls, mElementTagCalls,
|
2009-12-11 10:37:40 +03:00
|
|
|
mElementClassCalls, mElementIdCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
#ifdef PRINT_UNIVERSAL_RULES
|
|
|
|
{
|
2010-07-03 00:56:09 +04:00
|
|
|
if (mUniversalRules.Length() > 0) {
|
2006-04-04 03:52:17 +04:00
|
|
|
printf(" Universal rules:\n");
|
2010-07-03 00:56:09 +04:00
|
|
|
for (PRUint32 i = 0; i < mUniversalRules.Length(); ++i) {
|
|
|
|
RuleValue* value = &(mUniversalRules[i]);
|
2006-04-04 03:52:17 +04:00
|
|
|
nsAutoString selectorText;
|
|
|
|
PRUint32 lineNumber = value->mRule->GetLineNumber();
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
value->mRule->GetStyleSheet(*getter_AddRefs(sheet));
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
|
2006-04-04 03:52:17 +04:00
|
|
|
value->mSelector->ToString(selectorText, cssSheet);
|
|
|
|
|
|
|
|
printf(" line %d, %s\n",
|
|
|
|
lineNumber, NS_ConvertUTF16toUTF8(selectorText).get());
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // PRINT_UNIVERSAL_RULES
|
|
|
|
#endif // RULE_HASH_STATS
|
|
|
|
// Rule Values are arena allocated no need to delete them. Their destructor
|
|
|
|
// isn't doing any cleanup. So we dont even bother to enumerate through
|
|
|
|
// the hash tables and call their destructors.
|
|
|
|
if (nsnull != mEnumList) {
|
|
|
|
delete [] mEnumList;
|
|
|
|
}
|
|
|
|
// delete arena for strings and small objects
|
2011-12-09 14:29:01 +04:00
|
|
|
if (mIdTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mIdTable);
|
|
|
|
}
|
|
|
|
if (mClassTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mClassTable);
|
|
|
|
}
|
|
|
|
if (mTagTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mTagTable);
|
|
|
|
}
|
|
|
|
if (mNameSpaceTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mNameSpaceTable);
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
void RuleHash::AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
|
|
|
|
const RuleSelectorPair& aRuleInfo)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
// Get a new or existing entry.
|
2007-07-08 11:08:04 +04:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(aTable, aKey, PL_DHASH_ADD));
|
2006-04-04 03:52:17 +04:00
|
|
|
if (!entry)
|
|
|
|
return;
|
2012-03-14 09:44:13 +04:00
|
|
|
entry->mRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++, mQuirksMode));
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
static void
|
2010-07-08 20:50:18 +04:00
|
|
|
AppendRuleToTagTable(PLDHashTable* aTable, nsIAtom* aKey,
|
|
|
|
const RuleValue& aRuleInfo)
|
2009-08-01 19:53:40 +04:00
|
|
|
{
|
|
|
|
// Get a new or exisiting entry
|
2009-12-11 10:37:40 +03:00
|
|
|
RuleHashTagTableEntry *entry = static_cast<RuleHashTagTableEntry*>
|
|
|
|
(PL_DHashTableOperate(aTable, aKey, PL_DHASH_ADD));
|
|
|
|
if (!entry)
|
|
|
|
return;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
2010-07-08 20:50:18 +04:00
|
|
|
entry->mRules.AppendElement(aRuleInfo);
|
2009-08-01 19:53:40 +04:00
|
|
|
}
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
void RuleHash::AppendUniversalRule(const RuleSelectorPair& aRuleInfo)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2012-03-14 09:44:13 +04:00
|
|
|
mUniversalRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++, mQuirksMode));
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2010-07-03 00:56:09 +04:00
|
|
|
nsCSSSelector *selector = aRuleInfo.mSelector;
|
2006-04-04 03:52:17 +04:00
|
|
|
if (nsnull != selector->mIDList) {
|
2011-12-09 14:29:01 +04:00
|
|
|
if (!mIdTable.ops) {
|
|
|
|
PL_DHashTableInit(&mIdTable,
|
|
|
|
mQuirksMode ? &RuleHash_IdTable_CIOps.ops
|
|
|
|
: &RuleHash_IdTable_CSOps.ops,
|
|
|
|
nsnull, sizeof(RuleHashTableEntry), 16);
|
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
AppendRuleToTable(&mIdTable, selector->mIDList->mAtom, aRuleInfo);
|
2006-04-04 03:52:17 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mIdSelectors);
|
|
|
|
}
|
|
|
|
else if (nsnull != selector->mClassList) {
|
2011-12-09 14:29:01 +04:00
|
|
|
if (!mClassTable.ops) {
|
|
|
|
PL_DHashTableInit(&mClassTable,
|
|
|
|
mQuirksMode ? &RuleHash_ClassTable_CIOps.ops
|
|
|
|
: &RuleHash_ClassTable_CSOps.ops,
|
|
|
|
nsnull, sizeof(RuleHashTableEntry), 16);
|
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
AppendRuleToTable(&mClassTable, selector->mClassList->mAtom, aRuleInfo);
|
2006-04-04 03:52:17 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mClassSelectors);
|
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
else if (selector->mLowercaseTag) {
|
2012-03-14 09:44:13 +04:00
|
|
|
RuleValue ruleValue(aRuleInfo, mRuleCount++, mQuirksMode);
|
2011-12-09 14:29:01 +04:00
|
|
|
if (!mTagTable.ops) {
|
|
|
|
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
|
|
|
}
|
2010-07-08 20:50:18 +04:00
|
|
|
AppendRuleToTagTable(&mTagTable, selector->mLowercaseTag, ruleValue);
|
2006-04-04 03:52:17 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mTagSelectors);
|
2009-08-01 19:53:40 +04:00
|
|
|
if (selector->mCasedTag &&
|
|
|
|
selector->mCasedTag != selector->mLowercaseTag) {
|
2010-07-08 20:50:18 +04:00
|
|
|
AppendRuleToTagTable(&mTagTable, selector->mCasedTag, ruleValue);
|
2009-08-01 19:53:40 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mTagSelectors);
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
else if (kNameSpaceID_Unknown != selector->mNameSpace) {
|
2011-12-09 14:29:01 +04:00
|
|
|
if (!mNameSpaceTable.ops) {
|
|
|
|
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTableEntry), 16);
|
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
AppendRuleToTable(&mNameSpaceTable,
|
|
|
|
NS_INT32_TO_PTR(selector->mNameSpace), aRuleInfo);
|
2006-04-04 03:52:17 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mNameSpaceSelectors);
|
|
|
|
}
|
|
|
|
else { // universal tag selector
|
2010-07-03 00:56:09 +04:00
|
|
|
AppendUniversalRule(aRuleInfo);
|
2006-04-04 03:52:17 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mUniversalSelectors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// this should cover practically all cases so we don't need to reallocate
|
|
|
|
#define MIN_ENUM_LIST_SIZE 8
|
|
|
|
|
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
#define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
|
2010-07-03 00:56:09 +04:00
|
|
|
(var_) += (list_).Length()
|
2006-04-04 03:52:17 +04:00
|
|
|
#else
|
|
|
|
#define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
|
|
|
|
PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
2011-03-07 20:45:25 +03:00
|
|
|
static inline
|
2012-03-13 07:54:15 +04:00
|
|
|
void ContentEnumFunc(const RuleValue &value, nsCSSSelector* selector,
|
|
|
|
RuleProcessorData* data, NodeMatchContext& nodeContext,
|
|
|
|
AncestorFilter *ancestorFilter);
|
2011-03-07 20:45:25 +03:00
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
void RuleHash::EnumerateAllRules(Element* aElement, RuleProcessorData* aData,
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext& aNodeContext)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2011-03-29 21:29:21 +04:00
|
|
|
PRInt32 nameSpace = aElement->GetNameSpaceID();
|
|
|
|
nsIAtom* tag = aElement->Tag();
|
|
|
|
nsIAtom* id = aElement->GetID();
|
|
|
|
const nsAttrValue* classList = aElement->GetClasses();
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(tag, "How could we not have a tag?");
|
|
|
|
|
|
|
|
PRInt32 classCount = classList ? classList->GetAtomCount() : 0;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// assume 1 universal, tag, id, and namespace, rather than wasting
|
|
|
|
// time counting
|
|
|
|
PRInt32 testCount = classCount + 4;
|
|
|
|
|
|
|
|
if (mEnumListSize < testCount) {
|
|
|
|
delete [] mEnumList;
|
2009-09-16 19:01:36 +04:00
|
|
|
mEnumListSize = NS_MAX(testCount, MIN_ENUM_LIST_SIZE);
|
2010-07-03 00:56:09 +04:00
|
|
|
mEnumList = new EnumData[mEnumListSize];
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 valueCount = 0;
|
|
|
|
RULE_HASH_STAT_INCREMENT(mElementsMatched);
|
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
if (mUniversalRules.Length() != 0) { // universal rules
|
|
|
|
mEnumList[valueCount++] = ToEnumData(mUniversalRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(mUniversalRules, mElementUniversalCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
// universal rules within the namespace
|
2011-12-09 14:29:01 +04:00
|
|
|
if (kNameSpaceID_Unknown != nameSpace && mNameSpaceTable.ops) {
|
2007-07-08 11:08:04 +04:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 21:29:21 +04:00
|
|
|
(PL_DHashTableOperate(&mNameSpaceTable, NS_INT32_TO_PTR(nameSpace),
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementNameSpaceCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 14:29:01 +04:00
|
|
|
if (mTagTable.ops) {
|
2007-07-08 11:08:04 +04:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 21:29:21 +04:00
|
|
|
(PL_DHashTableOperate(&mTagTable, tag, PL_DHASH_LOOKUP));
|
2006-04-04 03:52:17 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementTagCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 14:29:01 +04:00
|
|
|
if (id && mIdTable.ops) {
|
2007-07-08 11:08:04 +04:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 21:29:21 +04:00
|
|
|
(PL_DHashTableOperate(&mIdTable, id, PL_DHASH_LOOKUP));
|
2006-04-04 03:52:17 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementIdCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 14:29:01 +04:00
|
|
|
if (mClassTable.ops) {
|
2006-04-04 03:52:17 +04:00
|
|
|
for (PRInt32 index = 0; index < classCount; ++index) {
|
2007-07-08 11:08:04 +04:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 21:29:21 +04:00
|
|
|
(PL_DHashTableOperate(&mClassTable, classList->AtomAt(index),
|
2006-04-04 03:52:17 +04:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementClassCalls);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(valueCount <= testCount, "values exceeded list size");
|
|
|
|
|
|
|
|
if (valueCount > 0) {
|
2012-03-13 07:54:15 +04:00
|
|
|
AncestorFilter *filter =
|
|
|
|
aData->mTreeMatchContext.mAncestorFilter.HasFilter() ?
|
|
|
|
&aData->mTreeMatchContext.mAncestorFilter : nsnull;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (filter) {
|
|
|
|
filter->AssertHasAllAncestors(aElement);
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-04 03:52:17 +04:00
|
|
|
// Merge the lists while there are still multiple lists to merge.
|
|
|
|
while (valueCount > 1) {
|
|
|
|
PRInt32 valueIndex = 0;
|
2010-07-03 00:56:09 +04:00
|
|
|
PRInt32 lowestRuleIndex = mEnumList[valueIndex].mCurValue->mIndex;
|
2006-04-04 03:52:17 +04:00
|
|
|
for (PRInt32 index = 1; index < valueCount; ++index) {
|
2010-07-03 00:56:09 +04:00
|
|
|
PRInt32 ruleIndex = mEnumList[index].mCurValue->mIndex;
|
|
|
|
if (ruleIndex < lowestRuleIndex) {
|
2006-04-04 03:52:17 +04:00
|
|
|
valueIndex = index;
|
2010-07-03 00:56:09 +04:00
|
|
|
lowestRuleIndex = ruleIndex;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2010-07-03 00:56:09 +04:00
|
|
|
const RuleValue *cur = mEnumList[valueIndex].mCurValue;
|
2012-03-13 07:54:15 +04:00
|
|
|
ContentEnumFunc(*cur, cur->mSelector, aData, aNodeContext, filter);
|
2010-07-03 00:56:09 +04:00
|
|
|
cur++;
|
|
|
|
if (cur == mEnumList[valueIndex].mEnd) {
|
|
|
|
mEnumList[valueIndex] = mEnumList[--valueCount];
|
|
|
|
} else {
|
|
|
|
mEnumList[valueIndex].mCurValue = cur;
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fast loop over single value.
|
2010-07-03 00:56:09 +04:00
|
|
|
for (const RuleValue *value = mEnumList[0].mCurValue,
|
|
|
|
*end = mEnumList[0].mEnd;
|
|
|
|
value != end; ++value) {
|
2012-03-13 07:54:15 +04:00
|
|
|
ContentEnumFunc(*value, value->mSelector, aData, aNodeContext, filter);
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
static size_t
|
2011-12-16 02:59:53 +04:00
|
|
|
SizeOfRuleHashTableEntry(PLDHashEntryHdr* aHdr, nsMallocSizeOfFun aMallocSizeOf, void *)
|
2011-08-03 00:21:52 +04:00
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(aHdr);
|
2011-12-16 02:59:53 +04:00
|
|
|
return entry->mRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t
|
|
|
|
RuleHash::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-03 00:21:52 +04:00
|
|
|
{
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t n = 0;
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-09 14:29:01 +04:00
|
|
|
if (mIdTable.ops) {
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mIdTable,
|
|
|
|
SizeOfRuleHashTableEntry,
|
|
|
|
aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mClassTable.ops) {
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mClassTable,
|
|
|
|
SizeOfRuleHashTableEntry,
|
|
|
|
aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTagTable.ops) {
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mTagTable,
|
|
|
|
SizeOfRuleHashTableEntry,
|
|
|
|
aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNameSpaceTable.ops) {
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mNameSpaceTable,
|
|
|
|
SizeOfRuleHashTableEntry,
|
|
|
|
aMallocSizeOf);
|
|
|
|
}
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-16 02:59:53 +04:00
|
|
|
n += mUniversalRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t
|
|
|
|
RuleHash::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-09 09:01:52 +04:00
|
|
|
}
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
//--------------------------------
|
|
|
|
|
2011-08-03 22:32:32 +04:00
|
|
|
// A hash table mapping atoms to lists of selectors
|
2011-04-13 06:57:42 +04:00
|
|
|
struct AtomSelectorEntry : public PLDHashEntryHdr {
|
|
|
|
nsIAtom *mAtom;
|
2011-10-06 06:06:37 +04:00
|
|
|
// Auto length 2, because a decent fraction of these arrays ends up
|
|
|
|
// with 2 elements, and each entry is cheap.
|
|
|
|
nsAutoTArray<nsCSSSelector*, 2> mSelectors;
|
2010-06-18 20:23:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
2010-06-18 20:23:05 +04:00
|
|
|
{
|
2011-04-13 06:57:42 +04:00
|
|
|
(static_cast<AtomSelectorEntry*>(hdr))->~AtomSelectorEntry();
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2010-06-18 20:23:05 +04:00
|
|
|
{
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelectorEntry *entry = static_cast<AtomSelectorEntry*>(hdr);
|
|
|
|
new (entry) AtomSelectorEntry();
|
|
|
|
entry->mAtom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
|
|
|
|
2011-10-06 06:06:37 +04:00
|
|
|
static void
|
|
|
|
AtomSelector_MoveEntry(PLDHashTable *table, const PLDHashEntryHdr *from,
|
|
|
|
PLDHashEntryHdr *to)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(from != to, "This is not going to work!");
|
|
|
|
AtomSelectorEntry *oldEntry =
|
|
|
|
const_cast<AtomSelectorEntry*>(static_cast<const AtomSelectorEntry*>(from));
|
|
|
|
AtomSelectorEntry *newEntry = new (to) AtomSelectorEntry();
|
|
|
|
newEntry->mAtom = oldEntry->mAtom;
|
|
|
|
newEntry->mSelectors.SwapElements(oldEntry->mSelectors);
|
|
|
|
oldEntry->~AtomSelectorEntry();
|
|
|
|
}
|
|
|
|
|
2010-06-18 20:23:05 +04:00
|
|
|
static nsIAtom*
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2010-06-18 20:23:05 +04:00
|
|
|
{
|
2011-04-13 06:57:42 +04:00
|
|
|
const AtomSelectorEntry *entry = static_cast<const AtomSelectorEntry*>(hdr);
|
|
|
|
return entry->mAtom;
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2011-08-08 06:23:36 +04:00
|
|
|
static const PLDHashTableOps AtomSelector_CSOps = {
|
2010-06-18 20:23:05 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
2011-08-08 06:23:36 +04:00
|
|
|
PL_DHashMatchEntryStub,
|
2011-10-06 06:06:37 +04:00
|
|
|
AtomSelector_MoveEntry,
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_ClearEntry,
|
2010-06-18 20:23:05 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_InitEntry
|
2010-06-18 20:23:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2011-04-13 06:57:42 +04:00
|
|
|
static const RuleHashTableOps AtomSelector_CIOps = {
|
2010-06-18 20:23:05 +04:00
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-06 06:06:37 +04:00
|
|
|
AtomSelector_MoveEntry,
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_ClearEntry,
|
2010-06-18 20:23:05 +04:00
|
|
|
PL_DHashFinalizeStub,
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_InitEntry
|
2010-06-18 20:23:05 +04:00
|
|
|
},
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelector_GetKey
|
2010-06-18 20:23:05 +04:00
|
|
|
};
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
struct RuleCascadeData {
|
2011-09-29 10:19:26 +04:00
|
|
|
RuleCascadeData(nsIAtom *aMedium, bool aQuirksMode)
|
2006-04-04 03:52:17 +04:00
|
|
|
: mRuleHash(aQuirksMode),
|
|
|
|
mStateSelectors(),
|
2010-03-25 12:22:58 +03:00
|
|
|
mSelectorDocumentStates(0),
|
2008-07-26 20:14:48 +04:00
|
|
|
mCacheKey(aMedium),
|
2009-12-11 10:37:40 +03:00
|
|
|
mNext(nsnull),
|
|
|
|
mQuirksMode(aQuirksMode)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2011-08-03 22:32:32 +04:00
|
|
|
// mAttributeSelectors is matching on the attribute _name_, not the value,
|
|
|
|
// and we case-fold names at parse-time, so this is a case-sensitive match.
|
2011-08-08 06:23:36 +04:00
|
|
|
PL_DHashTableInit(&mAttributeSelectors, &AtomSelector_CSOps, nsnull,
|
2011-08-03 22:32:32 +04:00
|
|
|
sizeof(AtomSelectorEntry), 16);
|
2009-12-11 10:37:40 +03:00
|
|
|
PL_DHashTableInit(&mAnonBoxRules, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
2011-04-13 06:57:48 +04:00
|
|
|
PL_DHashTableInit(&mIdSelectors,
|
|
|
|
aQuirksMode ? &AtomSelector_CIOps.ops :
|
2011-08-08 06:23:36 +04:00
|
|
|
&AtomSelector_CSOps,
|
2011-04-13 06:57:48 +04:00
|
|
|
nsnull, sizeof(AtomSelectorEntry), 16);
|
2010-06-18 20:23:05 +04:00
|
|
|
PL_DHashTableInit(&mClassSelectors,
|
2011-04-13 06:57:42 +04:00
|
|
|
aQuirksMode ? &AtomSelector_CIOps.ops :
|
2011-08-08 06:23:36 +04:00
|
|
|
&AtomSelector_CSOps,
|
2011-04-13 06:57:42 +04:00
|
|
|
nsnull, sizeof(AtomSelectorEntry), 16);
|
2009-12-11 10:37:40 +03:00
|
|
|
memset(mPseudoElementRuleHashes, 0, sizeof(mPseudoElementRuleHashes));
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
PL_DHashTableInit(&mXULTreeRules, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
|
|
|
#endif
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~RuleCascadeData()
|
|
|
|
{
|
|
|
|
PL_DHashTableFinish(&mAttributeSelectors);
|
2009-12-11 10:37:40 +03:00
|
|
|
PL_DHashTableFinish(&mAnonBoxRules);
|
2011-04-13 06:57:48 +04:00
|
|
|
PL_DHashTableFinish(&mIdSelectors);
|
2010-06-18 20:23:05 +04:00
|
|
|
PL_DHashTableFinish(&mClassSelectors);
|
|
|
|
#ifdef MOZ_XUL
|
2009-12-11 10:37:40 +03:00
|
|
|
PL_DHashTableFinish(&mXULTreeRules);
|
2010-06-18 20:23:05 +04:00
|
|
|
#endif
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
|
2009-12-11 10:37:40 +03:00
|
|
|
delete mPseudoElementRuleHashes[i];
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
RuleHash mRuleHash;
|
2009-12-11 10:37:40 +03:00
|
|
|
RuleHash*
|
|
|
|
mPseudoElementRuleHashes[nsCSSPseudoElements::ePseudo_PseudoElementCount];
|
2011-12-06 08:58:15 +04:00
|
|
|
nsTArray<nsCSSRuleProcessor::StateSelector> mStateSelectors;
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates mSelectorDocumentStates;
|
2010-06-18 20:23:05 +04:00
|
|
|
PLDHashTable mClassSelectors;
|
2011-04-13 06:57:48 +04:00
|
|
|
PLDHashTable mIdSelectors;
|
2010-06-18 20:23:05 +04:00
|
|
|
nsTArray<nsCSSSelector*> mPossiblyNegatedClassSelectors;
|
2011-04-13 06:57:48 +04:00
|
|
|
nsTArray<nsCSSSelector*> mPossiblyNegatedIDSelectors;
|
2009-02-03 17:42:18 +03:00
|
|
|
PLDHashTable mAttributeSelectors;
|
2009-12-11 10:37:40 +03:00
|
|
|
PLDHashTable mAnonBoxRules;
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
PLDHashTable mXULTreeRules;
|
|
|
|
#endif
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer> mFontFaceRules;
|
2011-04-12 10:18:43 +04:00
|
|
|
nsTArray<nsCSSKeyframesRule*> mKeyframesRules;
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
// Looks up or creates the appropriate list in |mAttributeSelectors|.
|
|
|
|
// Returns null only on allocation failure.
|
2009-02-03 17:42:18 +03:00
|
|
|
nsTArray<nsCSSSelector*>* AttributeListFor(nsIAtom* aAttribute);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQueryResultCacheKey mCacheKey;
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleCascadeData* mNext; // for a different medium
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool mQuirksMode;
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
static size_t
|
2011-12-16 02:59:53 +04:00
|
|
|
SizeOfSelectorsEntry(PLDHashEntryHdr* aHdr, nsMallocSizeOfFun aMallocSizeOf, void *)
|
2011-08-03 00:21:52 +04:00
|
|
|
{
|
2011-12-09 09:01:52 +04:00
|
|
|
AtomSelectorEntry* entry = static_cast<AtomSelectorEntry*>(aHdr);
|
2011-12-16 02:59:53 +04:00
|
|
|
return entry->mSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t
|
|
|
|
RuleCascadeData::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-03 00:21:52 +04:00
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
n += mRuleHash.SizeOfExcludingThis(aMallocSizeOf);
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
|
2011-08-03 00:21:52 +04:00
|
|
|
if (mPseudoElementRuleHashes[i])
|
2011-12-09 09:01:52 +04:00
|
|
|
n += mPseudoElementRuleHashes[i]->SizeOfIncludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 02:59:53 +04:00
|
|
|
n += mStateSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mIdSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mClassSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-16 02:59:53 +04:00
|
|
|
n += mPossiblyNegatedClassSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mPossiblyNegatedIDSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mAttributeSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mAnonBoxRules,
|
|
|
|
SizeOfRuleHashTableEntry, aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
#ifdef MOZ_XUL
|
2011-12-09 09:01:52 +04:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mXULTreeRules,
|
|
|
|
SizeOfRuleHashTableEntry, aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
#endif
|
|
|
|
|
2011-12-16 02:59:53 +04:00
|
|
|
n += mFontFaceRules.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mKeyframesRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
nsTArray<nsCSSSelector*>*
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleCascadeData::AttributeListFor(nsIAtom* aAttribute)
|
|
|
|
{
|
2011-08-03 22:32:32 +04:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&mAttributeSelectors, aAttribute,
|
|
|
|
PL_DHASH_ADD));
|
2006-04-04 03:52:17 +04:00
|
|
|
if (!entry)
|
|
|
|
return nsnull;
|
2011-08-03 22:32:32 +04:00
|
|
|
return &entry->mSelectors;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style rule processor implementation
|
|
|
|
//
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
|
2008-11-27 06:50:16 +03:00
|
|
|
PRUint8 aSheetType)
|
2008-07-26 20:14:48 +04:00
|
|
|
: mSheets(aSheets)
|
|
|
|
, mRuleCascades(nsnull)
|
|
|
|
, mLastPresContext(nsnull)
|
2008-11-27 06:50:16 +03:00
|
|
|
, mSheetType(aSheetType)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2010-05-12 00:41:47 +04:00
|
|
|
for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
|
2006-04-04 03:52:17 +04:00
|
|
|
mSheets[i]->AddRuleProcessor(this);
|
2010-05-12 00:41:47 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSRuleProcessor::~nsCSSRuleProcessor()
|
|
|
|
{
|
2010-05-12 00:41:47 +04:00
|
|
|
for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
|
2006-04-04 03:52:17 +04:00
|
|
|
mSheets[i]->DropRuleProcessor(this);
|
2010-05-12 00:41:47 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
mSheets.Clear();
|
|
|
|
ClearRuleCascades();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsCSSRuleProcessor, nsIStyleRuleProcessor)
|
|
|
|
|
2010-04-07 21:29:10 +04:00
|
|
|
/* static */ nsresult
|
2008-10-21 11:15:03 +04:00
|
|
|
nsCSSRuleProcessor::Startup()
|
|
|
|
{
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::AddBoolVarCache(&gSupportVisitedPseudo, VISITED_PSEUDO_PREF,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2010-04-07 21:29:10 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-10-21 11:15:03 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-11-19 23:08:20 +03:00
|
|
|
InitSystemMetrics()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!sSystemMetrics, "already initialized");
|
|
|
|
|
|
|
|
sSystemMetrics = new nsTArray< nsCOMPtr<nsIAtom> >;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(sSystemMetrics, false);
|
2007-11-19 23:08:20 +03:00
|
|
|
|
2009-10-17 18:31:47 +04:00
|
|
|
/***************************************************************************
|
|
|
|
* ANY METRICS ADDED HERE SHOULD ALSO BE ADDED AS MEDIA QUERIES IN *
|
|
|
|
* nsMediaFeatures.cpp *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
PRInt32 metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollArrowStyle);
|
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_StartBackward) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_backward);
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
2011-09-09 06:27:12 +04:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_StartForward) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_forward);
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
2011-09-09 06:27:12 +04:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_EndBackward) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_backward);
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
2011-09-09 06:27:12 +04:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_EndForward) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_forward);
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollSliderStyle);
|
|
|
|
if (metricResult != LookAndFeel::eScrollThumbStyle_Normal) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_thumb_proportional);
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ImagesInMenus);
|
2008-02-20 13:12:33 +03:00
|
|
|
if (metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_menus);
|
2008-02-20 13:12:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ImagesInButtons);
|
2009-10-06 18:20:59 +04:00
|
|
|
if (metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_buttons);
|
2009-10-06 18:20:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_MenuBarDrag);
|
2010-07-17 12:11:54 +04:00
|
|
|
if (metricResult) {
|
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::menubar_drag);
|
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
nsresult rv =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsDefaultTheme, &metricResult);
|
2008-04-08 22:36:53 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_default_theme);
|
2008-04-08 22:36:53 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MacGraphiteTheme, &metricResult);
|
2008-09-17 20:23:58 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::mac_graphite_theme);
|
2008-09-17 20:23:58 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MacLionTheme, &metricResult);
|
2011-08-18 12:40:27 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::mac_lion_theme);
|
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_DWMCompositor, &metricResult);
|
2008-08-13 04:44:14 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_compositor);
|
2008-08-13 04:44:14 +04:00
|
|
|
}
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsClassic, &metricResult);
|
2008-08-18 21:33:08 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_classic);
|
2008-08-18 21:33:08 +04:00
|
|
|
}
|
2009-08-11 06:59:06 +04:00
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_TouchEnabled, &metricResult);
|
2009-08-11 06:59:06 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::touch_enabled);
|
2009-08-11 06:59:06 +04:00
|
|
|
}
|
2008-08-18 21:33:08 +04:00
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MaemoClassic, &metricResult);
|
2009-10-05 05:31:26 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-16 04:23:18 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::maemo_classic);
|
2009-10-05 05:31:26 +04:00
|
|
|
}
|
|
|
|
|
2010-10-10 00:53:45 +04:00
|
|
|
#ifdef XP_WIN
|
2011-09-09 06:27:12 +04:00
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsThemeIdentifier,
|
|
|
|
&metricResult))) {
|
2010-10-10 00:53:45 +04:00
|
|
|
nsCSSRuleProcessor::SetWindowsThemeIdentifier(static_cast<PRUint8>(metricResult));
|
|
|
|
switch(metricResult) {
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_Aero:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_aero);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaBlue:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_blue);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaOlive:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_olive);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaSilver:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_silver);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_Royale:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_royale);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_Zune:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_zune);
|
|
|
|
break;
|
2011-09-09 06:27:12 +04:00
|
|
|
case LookAndFeel::eWindowsTheme_Generic:
|
2010-10-10 00:53:45 +04:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_generic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-11-19 23:08:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2008-08-06 00:02:43 +04:00
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics()
|
2007-11-19 23:08:20 +03:00
|
|
|
{
|
|
|
|
delete sSystemMetrics;
|
|
|
|
sSystemMetrics = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:29:10 +04:00
|
|
|
/* static */ void
|
|
|
|
nsCSSRuleProcessor::Shutdown()
|
|
|
|
{
|
|
|
|
FreeSystemMetrics();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2009-10-16 04:23:19 +04:00
|
|
|
nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
|
|
|
|
{
|
|
|
|
if (!sSystemMetrics && !InitSystemMetrics()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-16 04:23:19 +04:00
|
|
|
}
|
|
|
|
return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
|
|
|
|
}
|
|
|
|
|
2010-10-10 00:53:45 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
/* static */ PRUint8
|
|
|
|
nsCSSRuleProcessor::GetWindowsThemeIdentifier()
|
|
|
|
{
|
|
|
|
if (!sSystemMetrics)
|
|
|
|
InitSystemMetrics();
|
|
|
|
return sWinThemeId;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
/* static */
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates
|
2012-03-30 10:16:22 +04:00
|
|
|
nsCSSRuleProcessor::GetContentState(Element* aElement, const TreeMatchContext& aTreeMatchContext)
|
2009-12-11 01:36:03 +03:00
|
|
|
{
|
2012-02-08 22:42:38 +04:00
|
|
|
nsEventStates state = aElement->StyleState();
|
2011-03-29 21:29:21 +04:00
|
|
|
|
|
|
|
// If we are not supposed to mark visited links as such, be sure to
|
|
|
|
// flip the bits appropriately. We want to do this here, rather
|
|
|
|
// than in GetContentStateForVisitedHandling, so that we don't
|
|
|
|
// expose that :visited support is disabled to the Web page.
|
2011-10-29 13:43:43 +04:00
|
|
|
if (state.HasState(NS_EVENT_STATE_VISITED) &&
|
|
|
|
(!gSupportVisitedPseudo ||
|
|
|
|
aElement->OwnerDoc()->IsBeingUsedAsImage() ||
|
2012-03-30 10:16:22 +04:00
|
|
|
aTreeMatchContext.mUsingPrivateBrowsing)) {
|
2011-03-29 21:29:21 +04:00
|
|
|
state &= ~NS_EVENT_STATE_VISITED;
|
|
|
|
state |= NS_EVENT_STATE_UNVISITED;
|
2009-12-11 01:36:03 +03:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
return state;
|
2009-12-11 01:36:03 +03:00
|
|
|
}
|
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSRuleProcessor::IsLink(Element* aElement)
|
2009-12-11 01:36:03 +03:00
|
|
|
{
|
2012-02-08 22:42:38 +04:00
|
|
|
nsEventStates state = aElement->StyleState();
|
2010-10-20 15:26:32 +04:00
|
|
|
return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
|
2009-12-11 01:36:03 +03:00
|
|
|
}
|
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
/* static */
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates
|
2011-03-29 21:29:21 +04:00
|
|
|
nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
2011-11-14 22:10:22 +04:00
|
|
|
Element* aElement,
|
2012-03-30 10:16:22 +04:00
|
|
|
const TreeMatchContext& aTreeMatchContext,
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleWalker::VisitedHandlingType aVisitedHandling,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsRelevantLink)
|
2010-04-03 05:58:27 +04:00
|
|
|
{
|
2012-03-30 10:16:22 +04:00
|
|
|
nsEventStates contentState = GetContentState(aElement, aTreeMatchContext);
|
2010-10-20 15:26:32 +04:00
|
|
|
if (contentState.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) {
|
2011-03-29 21:29:21 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsLink(aElement), "IsLink() should match state");
|
2010-10-20 15:26:32 +04:00
|
|
|
contentState &= ~(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
|
2010-04-03 05:58:27 +04:00
|
|
|
if (aIsRelevantLink) {
|
|
|
|
switch (aVisitedHandling) {
|
|
|
|
case nsRuleWalker::eRelevantLinkUnvisited:
|
|
|
|
contentState |= NS_EVENT_STATE_UNVISITED;
|
|
|
|
break;
|
|
|
|
case nsRuleWalker::eRelevantLinkVisited:
|
|
|
|
contentState |= NS_EVENT_STATE_VISITED;
|
|
|
|
break;
|
|
|
|
case nsRuleWalker::eLinksVisitedOrUnvisited:
|
|
|
|
contentState |= NS_EVENT_STATE_UNVISITED | NS_EVENT_STATE_VISITED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contentState |= NS_EVENT_STATE_UNVISITED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contentState;
|
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
/**
|
|
|
|
* A |NodeMatchContext| has data about matching a selector (without
|
|
|
|
* combinators) against a single node. It contains only input to the
|
|
|
|
* matching.
|
|
|
|
*
|
|
|
|
* Unlike |RuleProcessorData|, which is similar, a |NodeMatchContext|
|
|
|
|
* can vary depending on the selector matching process. In other words,
|
|
|
|
* there might be multiple NodeMatchContexts corresponding to a single
|
|
|
|
* node, but only one possible RuleProcessorData.
|
|
|
|
*/
|
|
|
|
struct NodeMatchContext {
|
|
|
|
// In order to implement nsCSSRuleProcessor::HasStateDependentStyle,
|
|
|
|
// we need to be able to see if a node might match an
|
|
|
|
// event-state-dependent selector for any value of that event state.
|
|
|
|
// So mStateMask contains the states that should NOT be tested.
|
|
|
|
//
|
|
|
|
// NOTE: For |aStateMask| to work correctly, it's important that any
|
|
|
|
// change that changes multiple state bits include all those state
|
|
|
|
// bits in the notification. Otherwise, if multiple states change but
|
|
|
|
// we do separate notifications then we might determine the style is
|
|
|
|
// not state-dependent when it really is (e.g., determining that a
|
|
|
|
// :hover:active rule no longer matches when both states are unset).
|
2010-10-20 15:26:32 +04:00
|
|
|
const nsEventStates mStateMask;
|
2010-04-03 05:58:26 +04:00
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
// Is this link the unique link whose visitedness can affect the style
|
|
|
|
// of the node being matched? (That link is the nearest link to the
|
|
|
|
// node being matched that is itself or an ancestor.)
|
|
|
|
//
|
|
|
|
// Always false when TreeMatchContext::mForStyling is false. (We
|
|
|
|
// could figure it out for SelectorListMatches, but we're starting
|
|
|
|
// from the middle of the selector list when doing
|
|
|
|
// Has{Attribute,State}DependentStyle, so we can't tell. So when
|
|
|
|
// mForStyling is false, we have to assume we don't know.)
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool mIsRelevantLink;
|
2010-04-03 05:58:26 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NodeMatchContext(nsEventStates aStateMask, bool aIsRelevantLink)
|
2010-04-03 05:58:26 +04:00
|
|
|
: mStateMask(aStateMask)
|
2010-04-03 05:58:26 +04:00
|
|
|
, mIsRelevantLink(aIsRelevantLink)
|
2010-04-03 05:58:26 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ValueIncludes(const nsSubstring& aValueList,
|
2006-04-04 03:52:17 +04:00
|
|
|
const nsSubstring& aValue,
|
|
|
|
const nsStringComparator& aComparator)
|
|
|
|
{
|
|
|
|
const PRUnichar *p = aValueList.BeginReading(),
|
|
|
|
*p_end = aValueList.EndReading();
|
|
|
|
|
|
|
|
while (p < p_end) {
|
|
|
|
// skip leading space
|
2008-06-11 04:27:00 +04:00
|
|
|
while (p != p_end && nsContentUtils::IsHTMLWhitespace(*p))
|
2006-04-04 03:52:17 +04:00
|
|
|
++p;
|
|
|
|
|
|
|
|
const PRUnichar *val_start = p;
|
|
|
|
|
|
|
|
// look for space or end
|
2008-06-11 04:27:00 +04:00
|
|
|
while (p != p_end && !nsContentUtils::IsHTMLWhitespace(*p))
|
2006-04-04 03:52:17 +04:00
|
|
|
++p;
|
|
|
|
|
|
|
|
const PRUnichar *val_end = p;
|
|
|
|
|
|
|
|
if (val_start < val_end &&
|
|
|
|
aValue.Equals(Substring(val_start, val_end), aComparator))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
++p; // we know the next character is not whitespace
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether we should apply a "global" (i.e., universal-tag)
|
|
|
|
// selector for event states in quirks mode. Note that
|
2011-03-29 21:29:21 +04:00
|
|
|
// |IsLink()| is checked separately by the caller, so we return
|
2006-12-26 20:47:52 +03:00
|
|
|
// false for |nsGkAtoms::a|, which here means a named anchor.
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsQuirkEventSensitive(nsIAtom *aContentTag)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
return bool ((nsGkAtoms::button == aContentTag) ||
|
2006-12-26 20:47:52 +03:00
|
|
|
(nsGkAtoms::img == aContentTag) ||
|
|
|
|
(nsGkAtoms::input == aContentTag) ||
|
|
|
|
(nsGkAtoms::label == aContentTag) ||
|
|
|
|
(nsGkAtoms::select == aContentTag) ||
|
|
|
|
(nsGkAtoms::textarea == aContentTag));
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2011-11-14 22:10:22 +04:00
|
|
|
IsSignificantChild(nsIContent* aChild, bool aTextIsSignificant,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aWhitespaceIsSignificant)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2008-02-19 09:17:07 +03:00
|
|
|
return nsStyleUtil::IsSignificantChild(aChild, aTextIsSignificant,
|
|
|
|
aWhitespaceIsSignificant);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function is to be called once we have fetched a value for an attribute
|
|
|
|
// whose namespace and name match those of aAttrSelector. This function
|
|
|
|
// performs comparisons on the value only, based on aAttrSelector->mFunction.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool AttrMatchesValue(const nsAttrSelector* aAttrSelector,
|
|
|
|
const nsString& aValue, bool isHTML)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aAttrSelector, "Must have an attribute selector");
|
2008-06-11 04:27:00 +04:00
|
|
|
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2008Apr/0038.html
|
|
|
|
// *= (CONTAINSMATCH) ~= (INCLUDES) ^= (BEGINSMATCH) $= (ENDSMATCH)
|
|
|
|
// all accept the empty string, but match nothing.
|
|
|
|
if (aAttrSelector->mValue.IsEmpty() &&
|
|
|
|
(aAttrSelector->mFunction == NS_ATTR_FUNC_INCLUDES ||
|
|
|
|
aAttrSelector->mFunction == NS_ATTR_FUNC_ENDSMATCH ||
|
|
|
|
aAttrSelector->mFunction == NS_ATTR_FUNC_BEGINSMATCH ||
|
|
|
|
aAttrSelector->mFunction == NS_ATTR_FUNC_CONTAINSMATCH))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-06-11 04:27:00 +04:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
const nsDefaultStringComparator defaultComparator;
|
2010-08-03 02:19:04 +04:00
|
|
|
const nsASCIICaseInsensitiveStringComparator ciComparator;
|
2009-09-29 10:07:45 +04:00
|
|
|
const nsStringComparator& comparator =
|
|
|
|
(aAttrSelector->mCaseSensitive || !isHTML)
|
2007-07-08 11:08:04 +04:00
|
|
|
? static_cast<const nsStringComparator&>(defaultComparator)
|
|
|
|
: static_cast<const nsStringComparator&>(ciComparator);
|
2009-09-29 10:07:45 +04:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
switch (aAttrSelector->mFunction) {
|
|
|
|
case NS_ATTR_FUNC_EQUALS:
|
|
|
|
return aValue.Equals(aAttrSelector->mValue, comparator);
|
|
|
|
case NS_ATTR_FUNC_INCLUDES:
|
|
|
|
return ValueIncludes(aValue, aAttrSelector->mValue, comparator);
|
|
|
|
case NS_ATTR_FUNC_DASHMATCH:
|
|
|
|
return nsStyleUtil::DashMatchCompare(aValue, aAttrSelector->mValue, comparator);
|
|
|
|
case NS_ATTR_FUNC_ENDSMATCH:
|
|
|
|
return StringEndsWith(aValue, aAttrSelector->mValue, comparator);
|
|
|
|
case NS_ATTR_FUNC_BEGINSMATCH:
|
|
|
|
return StringBeginsWith(aValue, aAttrSelector->mValue, comparator);
|
|
|
|
case NS_ATTR_FUNC_CONTAINSMATCH:
|
|
|
|
return FindInReadable(aAttrSelector->mValue, aValue, comparator);
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Shouldn't be ending up here");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2011-11-14 22:10:22 +04:00
|
|
|
edgeChildMatches(Element* aElement, TreeMatchContext& aTreeMatchContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool checkFirst, bool checkLast)
|
2009-12-11 10:37:41 +03:00
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-11 10:37:41 +03:00
|
|
|
if (!parent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2009-12-11 10:37:41 +03:00
|
|
|
|
|
|
|
return (!checkFirst ||
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNthIndex(aElement, false, false, true) == 1) &&
|
2009-12-11 10:37:41 +03:00
|
|
|
(!checkLast ||
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNthIndex(aElement, false, true, true) == 1);
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2011-11-14 22:10:22 +04:00
|
|
|
nthChildGenericMatches(Element* aElement,
|
2010-04-03 05:58:26 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-11-14 22:10:22 +04:00
|
|
|
nsPseudoClassList* pseudoClass,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isOfType, bool isFromEnd)
|
2009-12-11 10:37:41 +03:00
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-11 10:37:41 +03:00
|
|
|
if (!parent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-11 10:37:41 +03:00
|
|
|
if (isFromEnd)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2009-12-11 10:37:41 +03:00
|
|
|
else
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
const PRInt32 index = aTreeMatchContext.mNthIndexCache.
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNthIndex(aElement, isOfType, isFromEnd, false);
|
2009-12-11 10:37:41 +03:00
|
|
|
if (index <= 0) {
|
|
|
|
// Node is anonymous content (not really a child of its parent).
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const PRInt32 a = pseudoClass->u.mNumbers[0];
|
|
|
|
const PRInt32 b = pseudoClass->u.mNumbers[1];
|
|
|
|
// result should be true if there exists n >= 0 such that
|
|
|
|
// a * n + b == index.
|
|
|
|
if (a == 0) {
|
|
|
|
return b == index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integer division in C does truncation (towards 0). So
|
|
|
|
// check that the result is nonnegative, and that there was no
|
|
|
|
// truncation.
|
|
|
|
const PRInt32 n = (index - b) / a;
|
|
|
|
return n >= 0 && (a * n == index - b);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2011-11-14 22:10:22 +04:00
|
|
|
edgeOfTypeMatches(Element* aElement, TreeMatchContext& aTreeMatchContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool checkFirst, bool checkLast)
|
2009-12-11 10:37:41 +03:00
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-11 10:37:41 +03:00
|
|
|
if (!parent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-11 10:37:41 +03:00
|
|
|
if (checkLast)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2009-12-11 10:37:41 +03:00
|
|
|
else
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (!checkFirst ||
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNthIndex(aElement, true, false, true) == 1) &&
|
2009-12-11 10:37:41 +03:00
|
|
|
(!checkLast ||
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNthIndex(aElement, true, true, true) == 1);
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2011-11-14 22:10:22 +04:00
|
|
|
checkGenericEmptyMatches(Element* aElement,
|
2010-04-03 05:58:26 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isWhitespaceSignificant)
|
2009-12-11 10:37:41 +03:00
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *child = nsnull;
|
2009-12-11 10:37:41 +03:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 22:10:22 +04:00
|
|
|
aElement->SetFlags(NODE_HAS_EMPTY_SELECTOR);
|
2009-12-11 10:37:41 +03:00
|
|
|
|
|
|
|
do {
|
2011-03-29 21:29:21 +04:00
|
|
|
child = aElement->GetChildAt(++index);
|
2009-12-11 10:37:41 +03:00
|
|
|
// stop at first non-comment (and non-whitespace for
|
|
|
|
// :-moz-only-whitespace) node
|
2011-10-17 18:59:28 +04:00
|
|
|
} while (child && !IsSignificantChild(child, true, isWhitespaceSignificant));
|
2009-12-11 10:37:41 +03:00
|
|
|
return (child == nsnull);
|
|
|
|
}
|
|
|
|
|
2010-10-20 15:26:32 +04:00
|
|
|
// An array of the states that are relevant for various pseudoclasses.
|
|
|
|
static const nsEventStates sPseudoClassStates[] = {
|
2009-12-11 10:37:41 +03:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value) \
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates(),
|
|
|
|
#define CSS_STATE_PSEUDO_CLASS(_name, _value, _states) \
|
|
|
|
_states,
|
2009-12-11 10:37:41 +03:00
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_STATE_PSEUDO_CLASS
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
// Add more entries for our fake values to make sure we can't
|
|
|
|
// index out of bounds into this array no matter what.
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates(),
|
|
|
|
nsEventStates()
|
2009-12-11 10:37:41 +03:00
|
|
|
};
|
2012-02-23 20:19:00 +04:00
|
|
|
MOZ_STATIC_ASSERT(NS_ARRAY_LENGTH(sPseudoClassStates) ==
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1,
|
|
|
|
"ePseudoClass_NotPseudoClass is no longer at the end of"
|
|
|
|
"sPseudoClassStates");
|
2009-12-11 10:37:41 +03:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
// |aDependence| has two functions:
|
|
|
|
// * when non-null, it indicates that we're processing a negation,
|
|
|
|
// which is done only when SelectorMatches calls itself recursively
|
|
|
|
// * what it points to should be set to true whenever a test is skipped
|
2009-12-11 01:36:03 +03:00
|
|
|
// because of aStateMask
|
2011-11-14 22:10:22 +04:00
|
|
|
static bool SelectorMatches(Element* aElement,
|
|
|
|
nsCSSSelector* aSelector,
|
2010-04-03 05:58:26 +04:00
|
|
|
NodeMatchContext& aNodeMatchContext,
|
2010-04-03 05:58:26 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* const aDependence = nsnull)
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
{
|
2009-12-11 10:37:41 +03:00
|
|
|
NS_PRECONDITION(!aSelector->IsPseudoElement(),
|
|
|
|
"Pseudo-element snuck into SelectorMatches?");
|
2010-04-03 05:58:26 +04:00
|
|
|
NS_ABORT_IF_FALSE(aTreeMatchContext.mForStyling ||
|
|
|
|
!aNodeMatchContext.mIsRelevantLink,
|
|
|
|
"mIsRelevantLink should be set to false when mForStyling "
|
|
|
|
"is false since we don't know how to set it correctly in "
|
|
|
|
"Has(Attribute|State)DependentStyle");
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
// namespace/tag match
|
2009-08-01 19:53:40 +04:00
|
|
|
// optimization : bail out early if we can
|
2006-04-04 03:52:17 +04:00
|
|
|
if ((kNameSpaceID_Unknown != aSelector->mNameSpace &&
|
2011-03-29 21:29:21 +04:00
|
|
|
aElement->GetNameSpaceID() != aSelector->mNameSpace))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-08-01 19:53:40 +04:00
|
|
|
|
2011-03-29 21:29:20 +04:00
|
|
|
if (aSelector->mLowercaseTag) {
|
|
|
|
nsIAtom* selectorTag =
|
|
|
|
(aTreeMatchContext.mIsHTMLDocument && aElement->IsHTML()) ?
|
|
|
|
aSelector->mLowercaseTag : aSelector->mCasedTag;
|
2011-03-29 21:29:21 +04:00
|
|
|
if (selectorTag != aElement->Tag()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-03-29 21:29:20 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
nsAtomList* IDList = aSelector->mIDList;
|
2009-12-11 01:36:02 +03:00
|
|
|
if (IDList) {
|
2011-03-29 21:29:21 +04:00
|
|
|
nsIAtom* id = aElement->GetID();
|
|
|
|
if (id) {
|
2009-12-11 01:36:02 +03:00
|
|
|
// case sensitivity: bug 93371
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool isCaseSensitive =
|
2011-03-29 21:29:20 +04:00
|
|
|
aTreeMatchContext.mCompatMode != eCompatibility_NavQuirks;
|
2009-12-11 01:36:02 +03:00
|
|
|
|
|
|
|
if (isCaseSensitive) {
|
|
|
|
do {
|
2011-03-29 21:29:21 +04:00
|
|
|
if (IDList->mAtom != id) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
} else {
|
2010-03-08 18:45:00 +03:00
|
|
|
// Use EqualsIgnoreASCIICase instead of full on unicode case conversion
|
|
|
|
// in order to save on performance. This is only used in quirks mode
|
|
|
|
// anyway.
|
2011-03-29 21:29:21 +04:00
|
|
|
nsDependentAtomString id1Str(id);
|
2009-12-11 01:36:02 +03:00
|
|
|
do {
|
2010-03-08 18:45:00 +03:00
|
|
|
if (!nsContentUtils::EqualsIgnoreASCIICase(id1Str,
|
|
|
|
nsDependentAtomString(IDList->mAtom))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Element has no id but we have an id selector
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
nsAtomList* classList = aSelector->mClassList;
|
2009-12-11 01:36:02 +03:00
|
|
|
if (classList) {
|
|
|
|
// test for class match
|
2011-03-29 21:29:21 +04:00
|
|
|
const nsAttrValue *elementClasses = aElement->GetClasses();
|
2009-12-11 01:36:03 +03:00
|
|
|
if (!elementClasses) {
|
|
|
|
// Element has no classes but we have a class selector
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
// case sensitivity: bug 93371
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool isCaseSensitive =
|
2011-03-29 21:29:20 +04:00
|
|
|
aTreeMatchContext.mCompatMode != eCompatibility_NavQuirks;
|
2009-12-11 01:36:02 +03:00
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
while (classList) {
|
|
|
|
if (!elementClasses->Contains(classList->mAtom,
|
|
|
|
isCaseSensitive ?
|
|
|
|
eCaseMatters : eIgnoreCase)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
2009-12-11 01:36:03 +03:00
|
|
|
classList = classList->mNext;
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool isNegated = (aDependence != nsnull);
|
2008-02-19 09:17:07 +03:00
|
|
|
// The selectors for which we set node bits are, unfortunately, early
|
|
|
|
// in this function (because they're pseudo-classes, which are
|
|
|
|
// generally quick to test, and thus earlier). If they were later,
|
|
|
|
// we'd probably avoid setting those bits in more cases where setting
|
|
|
|
// them is unnecessary.
|
2010-10-20 15:26:32 +04:00
|
|
|
NS_ASSERTION(aNodeMatchContext.mStateMask.IsEmpty() ||
|
2010-04-03 05:58:26 +04:00
|
|
|
!aTreeMatchContext.mForStyling,
|
2010-04-03 05:58:26 +04:00
|
|
|
"mForStyling must be false if we're just testing for "
|
2009-12-11 01:36:03 +03:00
|
|
|
"state-dependence");
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// test for pseudo class match
|
2011-11-14 22:10:22 +04:00
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector->mPseudoClassList;
|
2009-12-11 10:37:41 +03:00
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
2010-10-20 15:26:32 +04:00
|
|
|
nsEventStates statesToCheck = sPseudoClassStates[pseudoClass->mType];
|
|
|
|
if (statesToCheck.IsEmpty()) {
|
2010-04-27 00:27:01 +04:00
|
|
|
// keep the cases here in the same order as the list in
|
|
|
|
// nsCSSPseudoClassList.h
|
|
|
|
switch (pseudoClass->mType) {
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_empty:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!checkGenericEmptyMatches(aElement, aTreeMatchContext, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozOnlyWhitespace:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!checkGenericEmptyMatches(aElement, aTreeMatchContext, false)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozEmptyExceptChildrenWithLocalname:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
NS_ASSERTION(pseudoClass->u.mString, "Must have string!");
|
|
|
|
nsIContent *child = nsnull;
|
2010-04-27 00:27:01 +04:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2010-05-15 09:01:45 +04:00
|
|
|
// FIXME: This isn't sufficient to handle:
|
|
|
|
// :-moz-empty-except-children-with-localname() + E
|
|
|
|
// :-moz-empty-except-children-with-localname() ~ E
|
|
|
|
// because we don't know to restyle the grandparent of the
|
|
|
|
// inserted/removed element (as in bug 534804 for :empty).
|
2011-11-14 22:10:22 +04:00
|
|
|
aElement->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2010-04-27 00:27:01 +04:00
|
|
|
do {
|
2011-03-29 21:29:21 +04:00
|
|
|
child = aElement->GetChildAt(++index);
|
2010-04-27 00:27:01 +04:00
|
|
|
} while (child &&
|
2011-10-17 18:59:28 +04:00
|
|
|
(!IsSignificantChild(child, true, false) ||
|
2011-03-29 21:29:21 +04:00
|
|
|
(child->GetNameSpaceID() == aElement->GetNameSpaceID() &&
|
2011-11-14 22:10:22 +04:00
|
|
|
child->Tag()->Equals(nsDependentString(pseudoClass->u.mString)))));
|
2010-04-27 00:27:01 +04:00
|
|
|
if (child != nsnull) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lang:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
NS_ASSERTION(nsnull != pseudoClass->u.mString, "null lang parameter");
|
|
|
|
if (!pseudoClass->u.mString || !*pseudoClass->u.mString) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-27 00:27:01 +04:00
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
// We have to determine the language of the current element. Since
|
|
|
|
// this is currently no property and since the language is inherited
|
|
|
|
// from the parent we have to be prepared to look at all parent
|
|
|
|
// nodes. The language itself is encoded in the LANG attribute.
|
|
|
|
nsAutoString language;
|
2011-08-12 23:12:45 +04:00
|
|
|
aElement->GetLang(language);
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!language.IsEmpty()) {
|
|
|
|
if (!nsStyleUtil::DashMatchCompare(language,
|
2011-11-14 22:10:22 +04:00
|
|
|
nsDependentString(pseudoClass->u.mString),
|
2011-03-29 21:29:21 +04:00
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-03-29 21:29:21 +04:00
|
|
|
}
|
|
|
|
// This pseudo-class matched; move on to the next thing
|
|
|
|
break;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIDocument* doc = aTreeMatchContext.mDocument;
|
2011-03-29 21:29:21 +04:00
|
|
|
if (doc) {
|
|
|
|
// Try to get the language from the HTTP header or if this
|
|
|
|
// is missing as well from the preferences.
|
|
|
|
// The content language can be a comma-separated list of
|
|
|
|
// language codes.
|
|
|
|
doc->GetContentLanguage(language);
|
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
nsDependentString langString(pseudoClass->u.mString);
|
2011-03-29 21:29:21 +04:00
|
|
|
language.StripWhitespace();
|
|
|
|
PRInt32 begin = 0;
|
|
|
|
PRInt32 len = language.Length();
|
|
|
|
while (begin < len) {
|
|
|
|
PRInt32 end = language.FindChar(PRUnichar(','), begin);
|
|
|
|
if (end == kNotFound) {
|
|
|
|
end = len;
|
|
|
|
}
|
|
|
|
if (nsStyleUtil::DashMatchCompare(Substring(language, begin,
|
|
|
|
end-begin),
|
|
|
|
langString,
|
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
begin = end + 1;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (begin < len) {
|
|
|
|
// This pseudo-class matched
|
2010-04-27 00:27:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-03-29 21:29:21 +04:00
|
|
|
}
|
|
|
|
break;
|
2010-04-27 00:27:01 +04:00
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozBoundElement:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aTreeMatchContext.mScopedRoot != aElement) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_root:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aElement->GetParent() ||
|
2011-10-18 14:53:36 +04:00
|
|
|
aElement != aElement->OwnerDoc()->GetRootElement()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_any:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelectorList *l;
|
2010-04-27 00:27:01 +04:00
|
|
|
for (l = pseudoClass->u.mSelectors; l; l = l->mNext) {
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelector *s = l->mSelectors;
|
2010-04-27 00:27:01 +04:00
|
|
|
NS_ABORT_IF_FALSE(!s->mNext && !s->IsPseudoElement(),
|
|
|
|
"parser failed");
|
2011-03-29 21:29:21 +04:00
|
|
|
if (SelectorMatches(aElement, s, aNodeMatchContext,
|
2011-03-29 21:29:20 +04:00
|
|
|
aTreeMatchContext)) {
|
2010-04-27 00:27:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!l) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstChild:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, true, false)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstNode:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *firstNode = nsnull;
|
|
|
|
nsIContent *parent = aElement->GetParent();
|
2010-04-27 00:27:01 +04:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2010-04-27 00:27:01 +04:00
|
|
|
|
|
|
|
PRInt32 index = -1;
|
|
|
|
do {
|
|
|
|
firstNode = parent->GetChildAt(++index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (firstNode &&
|
2011-10-17 18:59:28 +04:00
|
|
|
!IsSignificantChild(firstNode, true, false));
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aElement != firstNode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastChild:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, false, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastNode:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *lastNode = nsnull;
|
|
|
|
nsIContent *parent = aElement->GetParent();
|
2010-04-27 00:27:01 +04:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2010-04-27 00:27:01 +04:00
|
|
|
|
|
|
|
PRUint32 index = parent->GetChildCount();
|
|
|
|
do {
|
|
|
|
lastNode = parent->GetChildAt(--index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (lastNode &&
|
2011-10-17 18:59:28 +04:00
|
|
|
!IsSignificantChild(lastNode, true, false));
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aElement != lastNode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyChild:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, true, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstOfType:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, true, false)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastOfType:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, false, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyOfType:
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, true, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthChild:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, false)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastChild:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 18:59:28 +04:00
|
|
|
false, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthOfType:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastOfType:
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, true)) {
|
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozHasHandlerRef:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *child = nsnull;
|
2010-04-27 00:27:01 +04:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
|
|
|
do {
|
2011-03-29 21:29:21 +04:00
|
|
|
child = aElement->GetChildAt(++index);
|
2010-04-27 00:27:01 +04:00
|
|
|
if (child && child->IsHTML() &&
|
|
|
|
child->Tag() == nsGkAtoms::param &&
|
|
|
|
child->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
NS_LITERAL_STRING("pluginurl"),
|
|
|
|
eIgnoreCase)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (child);
|
|
|
|
if (!child) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozIsHTML:
|
2011-03-29 21:29:20 +04:00
|
|
|
if (!aTreeMatchContext.mIsHTMLDocument || !aElement->IsHTML()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozSystemMetric:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCOMPtr<nsIAtom> metric = do_GetAtom(pseudoClass->u.mString);
|
|
|
|
if (!nsCSSRuleProcessor::HasSystemMetric(metric)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLocaleDir:
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool docIsRTL =
|
2011-11-14 22:10:22 +04:00
|
|
|
aTreeMatchContext.mDocument->GetDocumentState().
|
|
|
|
HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
|
2010-04-27 00:27:01 +04:00
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
nsDependentString dirString(pseudoClass->u.mString);
|
|
|
|
NS_ASSERTION(dirString.EqualsLiteral("ltr") ||
|
|
|
|
dirString.EqualsLiteral("rtl"),
|
2010-04-27 00:27:01 +04:00
|
|
|
"invalid value for -moz-locale-dir");
|
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
if (dirString.EqualsLiteral("rtl") != docIsRTL) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWTheme:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() <=
|
|
|
|
nsIDocument::Doc_Theme_None) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeBrightText:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() !=
|
|
|
|
nsIDocument::Doc_Theme_Bright) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeDarkText:
|
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() !=
|
|
|
|
nsIDocument::Doc_Theme_Dark) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozWindowInactive:
|
2011-11-14 22:10:22 +04:00
|
|
|
if (!aTreeMatchContext.mDocument->GetDocumentState().
|
|
|
|
HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-10-07 08:25:47 +04:00
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozTableBorderNonzero:
|
|
|
|
{
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!aElement->IsHTML(nsGkAtoms::table)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
2011-11-14 22:10:22 +04:00
|
|
|
nsGenericElement *ge = static_cast<nsGenericElement*>(aElement);
|
2010-10-07 08:25:47 +04:00
|
|
|
const nsAttrValue *val = ge->GetParsedAttr(nsGkAtoms::border);
|
|
|
|
if (!val ||
|
|
|
|
(val->Type() == nsAttrValue::eInteger &&
|
|
|
|
val->GetIntegerValue() == 0)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-27 00:27:01 +04:00
|
|
|
default:
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "How did that happen?");
|
2010-04-27 00:27:01 +04:00
|
|
|
}
|
2009-12-11 10:37:41 +03:00
|
|
|
} else {
|
2010-04-27 00:27:01 +04:00
|
|
|
// Bit-based pseudo-classes
|
2010-10-20 15:26:32 +04:00
|
|
|
if (statesToCheck.HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE) &&
|
2011-03-29 21:29:20 +04:00
|
|
|
aTreeMatchContext.mCompatMode == eCompatibility_NavQuirks &&
|
2011-04-23 05:36:24 +04:00
|
|
|
// global selector:
|
2009-08-01 19:53:40 +04:00
|
|
|
!aSelector->HasTagSelector() && !aSelector->mIDList &&
|
2011-04-23 05:36:24 +04:00
|
|
|
!aSelector->mClassList && !aSelector->mAttrList &&
|
2006-04-04 03:52:17 +04:00
|
|
|
// This (or the other way around) both make :not() asymmetric
|
|
|
|
// in quirks mode (and it's hard to work around since we're
|
|
|
|
// testing the current mNegations, not the first
|
|
|
|
// (unnegated)). This at least makes it closer to the spec.
|
|
|
|
!isNegated &&
|
|
|
|
// important for |IsQuirkEventSensitive|:
|
2011-03-29 21:29:21 +04:00
|
|
|
aElement->IsHTML() && !nsCSSRuleProcessor::IsLink(aElement) &&
|
2011-03-29 21:29:21 +04:00
|
|
|
!IsQuirkEventSensitive(aElement->Tag())) {
|
2006-04-04 03:52:17 +04:00
|
|
|
// In quirks mode, only make certain elements sensitive to
|
|
|
|
// selectors ":hover" and ":active".
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
} else {
|
2012-03-13 07:54:15 +04:00
|
|
|
if (aTreeMatchContext.mForStyling &&
|
|
|
|
statesToCheck.HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER)) {
|
|
|
|
// Mark the element as having :hover-dependent style
|
|
|
|
aElement->SetFlags(NODE_HAS_RELEVANT_HOVER_RULES);
|
|
|
|
}
|
2010-10-20 15:26:32 +04:00
|
|
|
if (aNodeMatchContext.mStateMask.HasAtLeastOneOfStates(statesToCheck)) {
|
2006-04-04 03:52:17 +04:00
|
|
|
if (aDependence)
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDependence = true;
|
2006-04-04 03:52:17 +04:00
|
|
|
} else {
|
2011-03-29 21:29:21 +04:00
|
|
|
nsEventStates contentState =
|
|
|
|
nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
|
|
|
aElement,
|
2012-03-30 10:16:22 +04:00
|
|
|
aTreeMatchContext,
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.VisitedHandling(),
|
2010-10-20 15:26:32 +04:00
|
|
|
aNodeMatchContext.mIsRelevantLink);
|
|
|
|
if (!contentState.HasAtLeastOneOfStates(statesToCheck)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool result = true;
|
2009-12-11 10:37:41 +03:00
|
|
|
if (aSelector->mAttrList) {
|
2006-04-04 03:52:17 +04:00
|
|
|
// test for attribute match
|
2011-03-29 21:29:21 +04:00
|
|
|
PRUint32 attrCount = aElement->GetAttrCount();
|
|
|
|
if (attrCount == 0) {
|
2006-04-04 03:52:17 +04:00
|
|
|
// if no attributes on the content, no match
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
result = true;
|
2011-11-14 22:10:22 +04:00
|
|
|
nsAttrSelector* attr = aSelector->mAttrList;
|
2009-09-29 10:07:45 +04:00
|
|
|
nsIAtom* matchAttribute;
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
do {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHTML =
|
2011-03-29 21:29:20 +04:00
|
|
|
(aTreeMatchContext.mIsHTMLDocument && aElement->IsHTML());
|
|
|
|
matchAttribute = isHTML ? attr->mLowercaseAttr : attr->mCasedAttr;
|
2009-12-11 01:36:03 +03:00
|
|
|
if (attr->mNameSpace == kNameSpaceID_Unknown) {
|
2006-04-04 03:52:17 +04:00
|
|
|
// Attr selector with a wildcard namespace. We have to examine all
|
|
|
|
// the attributes on our content node.... This sort of selector is
|
|
|
|
// essentially a boolean OR, over all namespaces, of equivalent attr
|
|
|
|
// selectors with those namespaces. So to evaluate whether it
|
|
|
|
// matches, evaluate for each namespace (the only namespaces that
|
|
|
|
// have a chance at matching, of course, are ones that the element
|
|
|
|
// actually has attributes in), short-circuiting if we ever match.
|
2011-10-17 18:59:28 +04:00
|
|
|
result = false;
|
2006-04-04 03:52:17 +04:00
|
|
|
for (PRUint32 i = 0; i < attrCount; ++i) {
|
2011-03-29 21:29:21 +04:00
|
|
|
const nsAttrName* attrName = aElement->GetAttrNameAt(i);
|
2006-04-04 03:52:17 +04:00
|
|
|
NS_ASSERTION(attrName, "GetAttrCount lied or GetAttrNameAt failed");
|
2009-09-29 10:07:45 +04:00
|
|
|
if (attrName->LocalName() != matchAttribute) {
|
2006-04-04 03:52:17 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (attr->mFunction == NS_ATTR_FUNC_SET) {
|
2011-10-17 18:59:28 +04:00
|
|
|
result = true;
|
2006-04-04 03:52:17 +04:00
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasAttr =
|
2006-04-04 03:52:17 +04:00
|
|
|
#endif
|
2011-03-29 21:29:21 +04:00
|
|
|
aElement->GetAttr(attrName->NamespaceID(),
|
|
|
|
attrName->LocalName(), value);
|
2006-04-04 03:52:17 +04:00
|
|
|
NS_ASSERTION(hasAttr, "GetAttrNameAt lied");
|
2011-03-29 21:29:20 +04:00
|
|
|
result = AttrMatchesValue(attr, value, isHTML);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point |result| has been set by us
|
2011-10-17 18:59:28 +04:00
|
|
|
// explicitly in this loop. If it's false, we may still match
|
2006-04-04 03:52:17 +04:00
|
|
|
// -- the content may have another attribute with the same name but
|
2011-10-17 18:59:28 +04:00
|
|
|
// in a different namespace. But if it's true, we are done (we
|
2006-04-04 03:52:17 +04:00
|
|
|
// can short-circuit the boolean OR described above).
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr->mFunction == NS_ATTR_FUNC_EQUALS) {
|
|
|
|
result =
|
2011-03-29 21:29:21 +04:00
|
|
|
aElement->
|
2009-09-29 10:07:45 +04:00
|
|
|
AttrValueIs(attr->mNameSpace, matchAttribute, attr->mValue,
|
2011-03-29 21:29:20 +04:00
|
|
|
(!isHTML || attr->mCaseSensitive) ? eCaseMatters
|
|
|
|
: eIgnoreCase);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
else if (!aElement->HasAttr(attr->mNameSpace, matchAttribute)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
result = false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
else if (attr->mFunction != NS_ATTR_FUNC_SET) {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasAttr =
|
2006-04-04 03:52:17 +04:00
|
|
|
#endif
|
2011-03-29 21:29:21 +04:00
|
|
|
aElement->GetAttr(attr->mNameSpace, matchAttribute, value);
|
2006-04-04 03:52:17 +04:00
|
|
|
NS_ASSERTION(hasAttr, "HasAttr lied");
|
2011-03-29 21:29:20 +04:00
|
|
|
result = AttrMatchesValue(attr, value, isHTML);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
attr = attr->mNext;
|
|
|
|
} while (attr && result);
|
|
|
|
}
|
|
|
|
}
|
2007-07-26 18:16:19 +04:00
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
// apply SelectorMatches to the negated selectors in the chain
|
|
|
|
if (!isNegated) {
|
2011-11-14 22:10:22 +04:00
|
|
|
for (nsCSSSelector *negation = aSelector->mNegations;
|
2006-04-04 03:52:17 +04:00
|
|
|
result && negation; negation = negation->mNegations) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dependence = false;
|
2011-03-29 21:29:21 +04:00
|
|
|
result = !SelectorMatches(aElement, negation, aNodeMatchContext,
|
2010-04-03 05:58:26 +04:00
|
|
|
aTreeMatchContext, &dependence);
|
2009-12-11 01:36:03 +03:00
|
|
|
// If the selector does match due to the dependence on aStateMask,
|
|
|
|
// then we want to keep result true so that the final result of
|
|
|
|
// SelectorMatches is true. Doing so tells StateEnumFunc that
|
|
|
|
// there is a dependence on the state.
|
2006-04-04 03:52:17 +04:00
|
|
|
result = result || dependence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef STATE_CHECK
|
|
|
|
|
|
|
|
// Right now, there are four operators:
|
2010-03-31 22:08:09 +04:00
|
|
|
// ' ', the descendant combinator, is greedy
|
2006-04-04 03:52:17 +04:00
|
|
|
// '~', the indirect adjacent sibling combinator, is greedy
|
|
|
|
// '+' and '>', the direct adjacent sibling and child combinators, are not
|
2010-03-31 22:08:09 +04:00
|
|
|
#define NS_IS_GREEDY_OPERATOR(ch) \
|
|
|
|
((ch) == PRUnichar(' ') || (ch) == PRUnichar('~'))
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
static bool SelectorMatchesTree(Element* aPrevElement,
|
|
|
|
nsCSSSelector* aSelector,
|
2010-04-03 05:58:26 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aLookForRelevantLink)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelector* selector = aSelector;
|
|
|
|
Element* prevElement = aPrevElement;
|
2006-04-04 03:52:17 +04:00
|
|
|
while (selector) { // check compound selectors
|
2010-03-31 22:08:09 +04:00
|
|
|
NS_ASSERTION(!selector->mNext ||
|
|
|
|
selector->mNext->mOperator != PRUnichar(0),
|
|
|
|
"compound selector without combinator");
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
// for adjacent sibling combinators, the content to test against the
|
|
|
|
// selector is the previous sibling *element*
|
2011-11-14 22:10:22 +04:00
|
|
|
Element* element = nsnull;
|
2006-04-04 03:52:17 +04:00
|
|
|
if (PRUnichar('+') == selector->mOperator ||
|
|
|
|
PRUnichar('~') == selector->mOperator) {
|
2010-04-03 05:58:26 +04:00
|
|
|
// The relevant link must be an ancestor of the node being matched.
|
2011-10-17 18:59:28 +04:00
|
|
|
aLookForRelevantLink = false;
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent* parent = prevElement->GetParent();
|
2011-03-29 21:29:21 +04:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 22:10:22 +04:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2011-03-29 21:29:21 +04:00
|
|
|
|
2011-11-14 22:10:22 +04:00
|
|
|
PRInt32 index = parent->IndexOf(prevElement);
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsIContent* content = parent->GetChildAt(index);
|
|
|
|
if (content->IsElement()) {
|
|
|
|
element = content->AsElement();
|
2011-03-29 21:29:21 +04:00
|
|
|
break;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
// for descendant combinators and child combinators, the element
|
2006-04-04 03:52:17 +04:00
|
|
|
// to test against is the parent
|
|
|
|
else {
|
2011-11-14 22:10:22 +04:00
|
|
|
nsIContent *content = prevElement->GetParent();
|
2011-03-29 21:29:21 +04:00
|
|
|
// GetParent could return a document fragment; we only want
|
|
|
|
// element parents.
|
|
|
|
if (content && content->IsElement()) {
|
|
|
|
element = content->AsElement();
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!element) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
aLookForRelevantLink &&
|
2011-03-29 21:29:21 +04:00
|
|
|
nsCSSRuleProcessor::IsLink(element));
|
2010-04-03 05:58:26 +04:00
|
|
|
if (nodeContext.mIsRelevantLink) {
|
|
|
|
// If we find an ancestor of the matched node that is a link
|
|
|
|
// during the matching process, then it's the relevant link (see
|
|
|
|
// constructor call above).
|
|
|
|
// Since we are still matching against selectors that contain
|
|
|
|
// :visited (they'll just fail), we will always find such a node
|
|
|
|
// during the selector matching process if there is a relevant
|
|
|
|
// link that can influence selector matching.
|
2011-10-17 18:59:28 +04:00
|
|
|
aLookForRelevantLink = false;
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.SetHaveRelevantLink();
|
2010-04-03 05:58:26 +04:00
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (SelectorMatches(element, selector, nodeContext, aTreeMatchContext)) {
|
2006-04-04 03:52:17 +04:00
|
|
|
// to avoid greedy matching, we need to recur if this is a
|
2008-03-06 03:06:15 +03:00
|
|
|
// descendant or general sibling combinator and the next
|
|
|
|
// combinator is different, but we can make an exception for
|
|
|
|
// sibling, then parent, since a sibling's parent is always the
|
|
|
|
// same.
|
2009-08-21 01:52:47 +04:00
|
|
|
if (NS_IS_GREEDY_OPERATOR(selector->mOperator) &&
|
|
|
|
selector->mNext &&
|
|
|
|
selector->mNext->mOperator != selector->mOperator &&
|
2008-03-06 03:06:15 +03:00
|
|
|
!(selector->mOperator == '~' &&
|
2012-03-13 07:54:14 +04:00
|
|
|
NS_IS_ANCESTOR_OPERATOR(selector->mNext->mOperator))) {
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// pretend the selector didn't match, and step through content
|
|
|
|
// while testing the same selector
|
|
|
|
|
|
|
|
// This approach is slightly strange in that when it recurs
|
|
|
|
// it tests from the top of the content tree, down. This
|
|
|
|
// doesn't matter much for performance since most selectors
|
|
|
|
// don't match. (If most did, it might be faster...)
|
2011-03-29 21:29:21 +04:00
|
|
|
if (SelectorMatchesTree(element, selector, aTreeMatchContext,
|
|
|
|
aLookForRelevantLink)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
selector = selector->mNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// for adjacent sibling and child combinators, if we didn't find
|
|
|
|
// a match, we're done
|
|
|
|
if (!NS_IS_GREEDY_OPERATOR(selector->mOperator)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // parent was required to match
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
prevElement = element;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // all the selectors matched.
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-03-07 20:45:25 +03:00
|
|
|
static inline
|
2012-03-13 07:54:15 +04:00
|
|
|
void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector,
|
|
|
|
RuleProcessorData* data, NodeMatchContext& nodeContext,
|
|
|
|
AncestorFilter *ancestorFilter)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2010-04-03 05:58:26 +04:00
|
|
|
if (nodeContext.mIsRelevantLink) {
|
2011-03-29 21:29:21 +04:00
|
|
|
data->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-03 05:58:26 +04:00
|
|
|
}
|
2012-03-13 07:54:15 +04:00
|
|
|
if (ancestorFilter &&
|
|
|
|
!ancestorFilter->MightHaveMatchingAncestor<RuleValue::eMaxAncestorHashes>(
|
|
|
|
value.mAncestorSelectorHashes)) {
|
|
|
|
// We won't match; nothing else to do here
|
|
|
|
return;
|
|
|
|
}
|
2011-03-29 21:29:21 +04:00
|
|
|
if (SelectorMatches(data->mElement, aSelector, nodeContext,
|
|
|
|
data->mTreeMatchContext)) {
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelector *next = aSelector->mNext;
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!next || SelectorMatchesTree(data->mElement, next,
|
|
|
|
data->mTreeMatchContext,
|
2011-03-29 21:29:21 +04:00
|
|
|
!nodeContext.mIsRelevantLink)) {
|
2012-03-13 07:54:15 +04:00
|
|
|
css::StyleRule *rule = value.mRule;
|
|
|
|
rule->RuleMatched();
|
|
|
|
data->mRuleWalker->Forward(rule);
|
2006-04-04 03:52:17 +04:00
|
|
|
// nsStyleSet will deal with the !important rule
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2006-04-04 03:52:17 +04:00
|
|
|
nsCSSRuleProcessor::RulesMatching(ElementRuleProcessorData *aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2011-03-29 21:29:21 +04:00
|
|
|
cascade->mRuleHash.EnumerateAllRules(aData->mElement, aData, nodeContext);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSRuleProcessor::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
RuleHash* ruleHash = cascade->mPseudoElementRuleHashes[aData->mPseudoType];
|
|
|
|
if (ruleHash) {
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2011-03-29 21:29:21 +04:00
|
|
|
ruleHash->EnumerateAllRules(aData->mElement, aData, nodeContext);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSRuleProcessor::RulesMatching(AnonBoxRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
if (cascade && cascade->mAnonBoxRules.entryCount) {
|
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mAnonBoxRules, aData->mPseudoTag,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
nsTArray<RuleValue>& rules = entry->mRules;
|
|
|
|
for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
|
|
|
|
value != end; ++value) {
|
2009-12-11 19:13:19 +03:00
|
|
|
value->mRule->RuleMatched();
|
2011-05-24 00:45:44 +04:00
|
|
|
aData->mRuleWalker->Forward(value->mRule);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSRuleProcessor::RulesMatching(XULTreeRuleProcessorData* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
if (cascade && cascade->mXULTreeRules.entryCount) {
|
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mXULTreeRules, aData->mPseudoTag,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2011-03-29 21:29:21 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2010-07-03 00:56:09 +04:00
|
|
|
nsTArray<RuleValue>& rules = entry->mRules;
|
|
|
|
for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
|
|
|
|
value != end; ++value) {
|
2010-07-31 03:48:57 +04:00
|
|
|
if (aData->mComparator->PseudoMatches(value->mSelector)) {
|
2012-03-13 07:54:15 +04:00
|
|
|
ContentEnumFunc(*value, value->mSelector->mNext, aData, nodeContext,
|
|
|
|
nsnull);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2009-12-11 10:37:40 +03:00
|
|
|
#endif
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-06-18 20:23:05 +04:00
|
|
|
static inline nsRestyleHint RestyleHintForOp(PRUnichar oper)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2010-06-18 20:23:05 +04:00
|
|
|
if (oper == PRUnichar('+') || oper == PRUnichar('~')) {
|
|
|
|
return eRestyle_LaterSiblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oper != PRUnichar(0)) {
|
|
|
|
return eRestyle_Subtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eRestyle_Self;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2009-12-12 09:36:34 +03:00
|
|
|
nsCSSRuleProcessor::HasStateDependentStyle(StateRuleProcessorData* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
// Look up the content node in the state rule list, which points to
|
|
|
|
// any (CSS2 definition) simple selector (whether or not it is the
|
|
|
|
// subject) that has a state pseudo-class on it. This means that this
|
|
|
|
// code will be matching selectors that aren't real selectors in any
|
|
|
|
// stylesheet (e.g., if there is a selector "body > p:hover > a", then
|
|
|
|
// "body > p:hover" will be in |cascade->mStateSelectors|). Note that
|
2011-12-06 08:58:15 +04:00
|
|
|
// |ComputeSelectorStateDependence| below determines which selectors are in
|
2006-04-04 03:52:17 +04:00
|
|
|
// |cascade->mStateSelectors|.
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint hint = nsRestyleHint(0);
|
2009-02-03 17:42:18 +03:00
|
|
|
if (cascade) {
|
2011-12-06 08:58:15 +04:00
|
|
|
StateSelector *iter = cascade->mStateSelectors.Elements(),
|
|
|
|
*end = iter + cascade->mStateSelectors.Length();
|
2011-10-17 18:59:28 +04:00
|
|
|
NodeMatchContext nodeContext(aData->mStateMask, false);
|
2009-02-03 17:42:18 +03:00
|
|
|
for(; iter != end; ++iter) {
|
2011-12-06 08:58:15 +04:00
|
|
|
nsCSSSelector* selector = iter->mSelector;
|
|
|
|
nsEventStates states = iter->mStates;
|
2009-02-03 17:42:18 +03:00
|
|
|
|
2010-06-18 20:23:05 +04:00
|
|
|
nsRestyleHint possibleChange = RestyleHintForOp(selector->mOperator);
|
2009-02-03 17:42:18 +03:00
|
|
|
|
2009-12-12 09:36:34 +03:00
|
|
|
// If hint already includes all the bits of possibleChange,
|
2009-02-03 17:42:18 +03:00
|
|
|
// don't bother calling SelectorMatches, since even if it returns false
|
2009-12-12 09:36:34 +03:00
|
|
|
// hint won't change.
|
2011-12-06 08:58:15 +04:00
|
|
|
// Also don't bother calling SelectorMatches if none of the
|
|
|
|
// states passed in are relevant here.
|
2009-12-12 09:36:34 +03:00
|
|
|
if ((possibleChange & ~hint) &&
|
2011-12-06 08:58:15 +04:00
|
|
|
states.HasAtLeastOneOfStates(aData->mStateMask) &&
|
2011-03-29 21:29:21 +04:00
|
|
|
SelectorMatches(aData->mElement, selector, nodeContext,
|
|
|
|
aData->mTreeMatchContext) &&
|
|
|
|
SelectorMatchesTree(aData->mElement, selector->mNext,
|
|
|
|
aData->mTreeMatchContext,
|
2011-10-17 18:59:28 +04:00
|
|
|
false))
|
2010-04-03 05:58:26 +04:00
|
|
|
{
|
2010-04-01 04:43:32 +04:00
|
|
|
hint = nsRestyleHint(hint | possibleChange);
|
2009-02-03 17:42:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-12 09:36:34 +03:00
|
|
|
return hint;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-03-17 20:10:57 +03:00
|
|
|
nsCSSRuleProcessor::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2010-10-20 15:26:32 +04:00
|
|
|
return cascade && cascade->mSelectorDocumentStates.HasAtLeastOneOfStates(aData->mStateMask);
|
2010-03-17 20:10:57 +03:00
|
|
|
}
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
struct AttributeEnumData {
|
|
|
|
AttributeEnumData(AttributeRuleProcessorData *aData)
|
2010-04-01 04:43:32 +04:00
|
|
|
: data(aData), change(nsRestyleHint(0)) {}
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
AttributeRuleProcessorData *data;
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint change;
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
static void
|
|
|
|
AttributeEnumFunc(nsCSSSelector* aSelector, AttributeEnumData* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2009-02-03 17:42:18 +03:00
|
|
|
AttributeRuleProcessorData *data = aData->data;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-06-18 20:23:05 +04:00
|
|
|
nsRestyleHint possibleChange = RestyleHintForOp(aSelector->mOperator);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// If enumData->change already includes all the bits of possibleChange, don't
|
|
|
|
// bother calling SelectorMatches, since even if it returns false
|
|
|
|
// enumData->change won't change.
|
2011-10-17 18:59:28 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(), false);
|
2009-02-03 17:42:18 +03:00
|
|
|
if ((possibleChange & ~(aData->change)) &&
|
2011-03-29 21:29:21 +04:00
|
|
|
SelectorMatches(data->mElement, aSelector, nodeContext,
|
|
|
|
data->mTreeMatchContext) &&
|
|
|
|
SelectorMatchesTree(data->mElement, aSelector->mNext,
|
2011-10-17 18:59:28 +04:00
|
|
|
data->mTreeMatchContext, false)) {
|
2010-04-01 04:43:32 +04:00
|
|
|
aData->change = nsRestyleHint(aData->change | possibleChange);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2009-12-11 01:36:03 +03:00
|
|
|
nsCSSRuleProcessor::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2009-12-11 01:36:03 +03:00
|
|
|
// We could try making use of aData->mModType, but :not rules make it a bit
|
|
|
|
// of a pain to do so... So just ignore it for now.
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
AttributeEnumData data(aData);
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
// Don't do our special handling of certain attributes if the attr
|
|
|
|
// hasn't changed yet.
|
|
|
|
if (aData->mAttrHasChanged) {
|
2010-03-17 20:10:57 +03:00
|
|
|
// check for the lwtheme and lwthemetextcolor attribute on root XUL elements
|
|
|
|
if ((aData->mAttribute == nsGkAtoms::lwtheme ||
|
2009-12-11 01:36:03 +03:00
|
|
|
aData->mAttribute == nsGkAtoms::lwthemetextcolor) &&
|
2011-03-29 21:29:21 +04:00
|
|
|
aData->mElement->GetNameSpaceID() == kNameSpaceID_XUL &&
|
2011-10-18 14:53:36 +04:00
|
|
|
aData->mElement == aData->mElement->OwnerDoc()->GetRootElement())
|
2009-12-11 01:36:03 +03:00
|
|
|
{
|
2010-06-18 20:23:05 +04:00
|
|
|
data.change = nsRestyleHint(data.change | eRestyle_Subtree);
|
2009-12-11 01:36:03 +03:00
|
|
|
}
|
2011-02-09 00:30:57 +03:00
|
|
|
|
|
|
|
// We don't know the namespace of the attribute, and xml:lang applies to
|
|
|
|
// all elements. If the lang attribute changes, we need to restyle our
|
|
|
|
// whole subtree, since the :lang selector on our descendants can examine
|
|
|
|
// our lang attribute.
|
|
|
|
if (aData->mAttribute == nsGkAtoms::lang) {
|
|
|
|
data.change = nsRestyleHint(data.change | eRestyle_Subtree);
|
|
|
|
}
|
2009-07-29 22:33:53 +04:00
|
|
|
}
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
// Since we get both before and after notifications for attributes, we
|
|
|
|
// don't have to ignore aData->mAttribute while matching. Just check
|
|
|
|
// whether we have selectors relevant to aData->mAttribute that we
|
|
|
|
// match. If this is the before change notification, that will catch
|
|
|
|
// rules we might stop matching; if the after change notification, the
|
|
|
|
// ones we might have started matching.
|
2006-04-04 03:52:17 +04:00
|
|
|
if (cascade) {
|
2010-04-30 17:12:06 +04:00
|
|
|
if (aData->mAttribute == aData->mElement->GetIDAttributeName()) {
|
2011-04-13 06:57:48 +04:00
|
|
|
nsIAtom* id = aData->mElement->GetID();
|
|
|
|
if (id) {
|
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mIdSelectors,
|
|
|
|
id, PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
nsCSSSelector **iter = entry->mSelectors.Elements(),
|
|
|
|
**end = iter + entry->mSelectors.Length();
|
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelector **iter = cascade->mPossiblyNegatedIDSelectors.Elements(),
|
|
|
|
**end = iter + cascade->mPossiblyNegatedIDSelectors.Length();
|
2009-02-03 17:42:18 +03:00
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
if (aData->mAttribute == aData->mElement->GetClassAttributeName()) {
|
2011-03-29 21:29:21 +04:00
|
|
|
const nsAttrValue* elementClasses = aData->mElement->GetClasses();
|
2010-06-18 20:23:05 +04:00
|
|
|
if (elementClasses) {
|
|
|
|
PRInt32 atomCount = elementClasses->GetAtomCount();
|
|
|
|
for (PRInt32 i = 0; i < atomCount; ++i) {
|
|
|
|
nsIAtom* curClass = elementClasses->AtomAt(i);
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
2010-06-18 20:23:05 +04:00
|
|
|
(PL_DHashTableOperate(&cascade->mClassSelectors,
|
|
|
|
curClass, PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
nsCSSSelector **iter = entry->mSelectors.Elements(),
|
|
|
|
**end = iter + entry->mSelectors.Length();
|
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelector **iter = cascade->mPossiblyNegatedClassSelectors.Elements(),
|
|
|
|
**end = iter +
|
|
|
|
cascade->mPossiblyNegatedClassSelectors.Length();
|
|
|
|
for (; iter != end; ++iter) {
|
2010-06-20 01:16:38 +04:00
|
|
|
AttributeEnumFunc(*iter, &data);
|
2009-02-03 17:42:18 +03:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-08-03 22:32:32 +04:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mAttributeSelectors,
|
|
|
|
aData->mAttribute, PL_DHASH_LOOKUP));
|
2006-04-04 03:52:17 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2011-08-03 22:32:32 +04:00
|
|
|
nsCSSSelector **iter = entry->mSelectors.Elements(),
|
|
|
|
**end = iter + entry->mSelectors.Length();
|
2009-02-03 17:42:18 +03:00
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
return data.change;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2010-07-19 01:20:40 +04:00
|
|
|
nsCSSRuleProcessor::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
RuleCascadeData *old = mRuleCascades;
|
2008-08-06 21:42:56 +04:00
|
|
|
// We don't want to do anything if there aren't any sets of rules
|
|
|
|
// cached yet (or somebody cleared them and is thus responsible for
|
|
|
|
// rebuilding things), since we should not build the rule cascade too
|
|
|
|
// early (e.g., before we know whether the quirk style sheet should be
|
|
|
|
// enabled). And if there's nothing cached, it doesn't matter if
|
|
|
|
// anything changed. See bug 448281.
|
|
|
|
if (old) {
|
|
|
|
RefreshRuleCascade(aPresContext);
|
|
|
|
}
|
2010-07-19 01:20:40 +04:00
|
|
|
return (old != mRuleCascades);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSRuleProcessor::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-01 22:25:20 +04:00
|
|
|
{
|
2011-12-09 09:01:52 +04:00
|
|
|
size_t n = 0;
|
2011-12-16 02:59:53 +04:00
|
|
|
n += mSheets.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
for (RuleCascadeData* cascade = mRuleCascades; cascade;
|
|
|
|
cascade = cascade->mNext) {
|
2011-12-09 09:01:52 +04:00
|
|
|
n += cascade->SizeOfIncludingThis(aMallocSizeOf);
|
2011-08-03 00:21:52 +04:00
|
|
|
}
|
2011-08-01 22:25:20 +04:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSRuleProcessor::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-09 09:01:52 +04:00
|
|
|
}
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
// Append all the currently-active font face rules to aArray. Return
|
|
|
|
// true for success and false for failure.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-11-26 02:22:38 +03:00
|
|
|
nsCSSRuleProcessor::AppendFontFaceRules(
|
|
|
|
nsPresContext *aPresContext,
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& aArray)
|
2008-11-26 02:22:38 +03:00
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
if (!aArray.AppendElements(cascade->mFontFaceRules))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
// Append all the currently-active keyframes rules to aArray. Return
|
|
|
|
// true for success and false for failure.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSRuleProcessor::AppendKeyframesRules(
|
|
|
|
nsPresContext *aPresContext,
|
|
|
|
nsTArray<nsCSSKeyframesRule*>& aArray)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
if (!aArray.AppendElements(cascade->mKeyframesRules))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSRuleProcessor::ClearRuleCascades()
|
|
|
|
{
|
2008-11-26 02:22:38 +03:00
|
|
|
// We rely on our caller (perhaps indirectly) to do something that
|
|
|
|
// will rebuild style data and the user font set (either
|
|
|
|
// nsIPresShell::ReconstructStyleData or
|
|
|
|
// nsPresContext::RebuildAllStyleData).
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleCascadeData *data = mRuleCascades;
|
|
|
|
mRuleCascades = nsnull;
|
|
|
|
while (data) {
|
|
|
|
RuleCascadeData *next = data->mNext;
|
|
|
|
delete data;
|
|
|
|
data = next;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-06 08:58:15 +04:00
|
|
|
// This function should return the set of states that this selector
|
|
|
|
// depends on; this is used to implement HasStateDependentStyle. It
|
|
|
|
// does NOT recur down into things like :not and :-moz-any.
|
2006-04-04 03:52:17 +04:00
|
|
|
inline
|
2011-12-06 08:58:15 +04:00
|
|
|
nsEventStates ComputeSelectorStateDependence(nsCSSSelector& aSelector)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2011-12-06 08:58:15 +04:00
|
|
|
nsEventStates states;
|
2008-06-03 07:17:35 +04:00
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector.mPseudoClassList;
|
2006-04-04 03:52:17 +04:00
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
2009-12-11 10:37:41 +03:00
|
|
|
// Tree pseudo-elements overload mPseudoClassList for things that
|
|
|
|
// aren't pseudo-classes.
|
|
|
|
if (pseudoClass->mType >= nsCSSPseudoClasses::ePseudoClass_Count) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 08:58:15 +04:00
|
|
|
states |= sPseudoClassStates[pseudoClass->mType];
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-12-06 08:58:15 +04:00
|
|
|
return states;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-04-24 06:59:47 +04:00
|
|
|
AddSelector(RuleCascadeData* aCascade,
|
|
|
|
// The part between combinators at the top level of the selector
|
|
|
|
nsCSSSelector* aSelectorInTopLevel,
|
|
|
|
// The part we should look through (might be in :not or :-moz-any())
|
|
|
|
nsCSSSelector* aSelectorPart)
|
|
|
|
{
|
2011-02-24 21:42:15 +03:00
|
|
|
// It's worth noting that this loop over negations isn't quite
|
|
|
|
// optimal for two reasons. One, we could add something to one of
|
|
|
|
// these lists twice, which means we'll check it twice, but I don't
|
|
|
|
// think that's worth worrying about. (We do the same for multiple
|
|
|
|
// attribute selectors on the same attribute.) Two, we don't really
|
|
|
|
// need to check negations past the first in the current
|
|
|
|
// implementation (and they're rare as well), but that might change
|
|
|
|
// in the future if :not() is extended.
|
|
|
|
for (nsCSSSelector* negation = aSelectorPart; negation;
|
|
|
|
negation = negation->mNegations) {
|
|
|
|
// Track both document states and attribute dependence in pseudo-classes.
|
|
|
|
for (nsPseudoClassList* pseudoClass = negation->mPseudoClassList;
|
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
|
|
|
switch (pseudoClass->mType) {
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLocaleDir: {
|
|
|
|
aCascade->mSelectorDocumentStates |= NS_DOCUMENT_STATE_RTL_LOCALE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozWindowInactive: {
|
|
|
|
aCascade->mSelectorDocumentStates |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozTableBorderNonzero: {
|
|
|
|
nsTArray<nsCSSSelector*> *array =
|
|
|
|
aCascade->AttributeListFor(nsGkAtoms::border);
|
|
|
|
if (!array) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-24 21:42:15 +03:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
|
2011-02-24 21:42:15 +03:00
|
|
|
// Build mStateSelectors.
|
2011-12-06 08:58:15 +04:00
|
|
|
nsEventStates dependentStates = ComputeSelectorStateDependence(*negation);
|
|
|
|
if (!dependentStates.IsEmpty()) {
|
|
|
|
aCascade->mStateSelectors.AppendElement(
|
|
|
|
nsCSSRuleProcessor::StateSelector(dependentStates,
|
|
|
|
aSelectorInTopLevel));
|
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
|
2011-02-24 21:42:15 +03:00
|
|
|
// Build mIDSelectors
|
2011-04-13 06:57:48 +04:00
|
|
|
if (negation == aSelectorInTopLevel) {
|
|
|
|
for (nsAtomList* curID = negation->mIDList; curID;
|
|
|
|
curID = curID->mNext) {
|
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>(PL_DHashTableOperate(&aCascade->mIdSelectors,
|
|
|
|
curID->mAtom,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (entry) {
|
|
|
|
entry->mSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (negation->mIDList) {
|
|
|
|
aCascade->mPossiblyNegatedIDSelectors.AppendElement(aSelectorInTopLevel);
|
2011-02-24 21:42:15 +03:00
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
|
2011-02-24 21:42:15 +03:00
|
|
|
// Build mClassSelectors
|
|
|
|
if (negation == aSelectorInTopLevel) {
|
|
|
|
for (nsAtomList* curClass = negation->mClassList; curClass;
|
|
|
|
curClass = curClass->mNext) {
|
2011-04-13 06:57:42 +04:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>(PL_DHashTableOperate(&aCascade->mClassSelectors,
|
|
|
|
curClass->mAtom,
|
|
|
|
PL_DHASH_ADD));
|
2011-02-24 21:42:15 +03:00
|
|
|
if (entry) {
|
|
|
|
entry->mSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
2011-02-24 21:42:15 +03:00
|
|
|
} else if (negation->mClassList) {
|
|
|
|
aCascade->mPossiblyNegatedClassSelectors.AppendElement(aSelectorInTopLevel);
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
|
2011-02-24 21:42:15 +03:00
|
|
|
// Build mAttributeSelectors.
|
|
|
|
for (nsAttrSelector *attr = negation->mAttrList; attr;
|
|
|
|
attr = attr->mNext) {
|
|
|
|
nsTArray<nsCSSSelector*> *array =
|
|
|
|
aCascade->AttributeListFor(attr->mCasedAttr);
|
2010-04-24 06:59:47 +04:00
|
|
|
if (!array) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
2011-02-24 21:42:15 +03:00
|
|
|
if (attr->mLowercaseAttr != attr->mCasedAttr) {
|
|
|
|
array = aCascade->AttributeListFor(attr->mLowercaseAttr);
|
|
|
|
if (!array) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-24 21:42:15 +03:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 21:42:15 +03:00
|
|
|
// Recur through any :-moz-any selectors
|
|
|
|
for (nsPseudoClassList* pseudoClass = negation->mPseudoClassList;
|
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
|
|
|
if (pseudoClass->mType == nsCSSPseudoClasses::ePseudoClass_any) {
|
|
|
|
for (nsCSSSelectorList *l = pseudoClass->u.mSelectors; l; l = l->mNext) {
|
|
|
|
nsCSSSelector *s = l->mSelectors;
|
|
|
|
if (!AddSelector(aCascade, aSelectorInTopLevel, s)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-02-24 21:42:15 +03:00
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-03 00:56:09 +04:00
|
|
|
AddRule(RuleSelectorPair* aRuleInfo, RuleCascadeData* aCascade)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
RuleCascadeData * const cascade = aCascade;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
// Build the rule hash.
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aRuleInfo->mSelector->PseudoType();
|
2009-12-11 10:37:40 +03:00
|
|
|
if (NS_LIKELY(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement)) {
|
2010-07-03 00:56:09 +04:00
|
|
|
cascade->mRuleHash.AppendRule(*aRuleInfo);
|
2009-12-11 10:37:40 +03:00
|
|
|
} else if (pseudoType < nsCSSPseudoElements::ePseudo_PseudoElementCount) {
|
2009-12-11 10:37:40 +03:00
|
|
|
RuleHash*& ruleHash = cascade->mPseudoElementRuleHashes[pseudoType];
|
|
|
|
if (!ruleHash) {
|
|
|
|
ruleHash = new RuleHash(cascade->mQuirksMode);
|
|
|
|
if (!ruleHash) {
|
|
|
|
// Out of memory; give up
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(aRuleInfo->mSelector->mNext,
|
|
|
|
"Must have mNext; parser screwed up");
|
|
|
|
NS_ASSERTION(aRuleInfo->mSelector->mNext->mOperator == '>',
|
|
|
|
"Unexpected mNext combinator");
|
|
|
|
aRuleInfo->mSelector = aRuleInfo->mSelector->mNext;
|
2010-07-03 00:56:09 +04:00
|
|
|
ruleHash->AppendRule(*aRuleInfo);
|
2009-12-11 10:37:40 +03:00
|
|
|
} else if (pseudoType == nsCSSPseudoElements::ePseudo_AnonBox) {
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_ASSERTION(!aRuleInfo->mSelector->mCasedTag &&
|
|
|
|
!aRuleInfo->mSelector->mIDList &&
|
|
|
|
!aRuleInfo->mSelector->mClassList &&
|
|
|
|
!aRuleInfo->mSelector->mPseudoClassList &&
|
|
|
|
!aRuleInfo->mSelector->mAttrList &&
|
|
|
|
!aRuleInfo->mSelector->mNegations &&
|
|
|
|
!aRuleInfo->mSelector->mNext &&
|
|
|
|
aRuleInfo->mSelector->mNameSpace == kNameSpaceID_Unknown,
|
|
|
|
"Parser messed up with anon box selector");
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
// Index doesn't matter here, since we'll just be walking these
|
|
|
|
// rules in order; just pass 0.
|
2010-07-08 20:50:18 +04:00
|
|
|
AppendRuleToTagTable(&cascade->mAnonBoxRules,
|
|
|
|
aRuleInfo->mSelector->mLowercaseTag,
|
2012-03-14 09:44:13 +04:00
|
|
|
RuleValue(*aRuleInfo, 0, aCascade->mQuirksMode));
|
2009-12-11 10:37:40 +03:00
|
|
|
} else {
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_ASSERTION(pseudoType == nsCSSPseudoElements::ePseudo_XULTree,
|
|
|
|
"Unexpected pseudo type");
|
2009-12-11 10:37:40 +03:00
|
|
|
// Index doesn't matter here, since we'll just be walking these
|
|
|
|
// rules in order; just pass 0.
|
2010-07-08 20:50:18 +04:00
|
|
|
AppendRuleToTagTable(&cascade->mXULTreeRules,
|
|
|
|
aRuleInfo->mSelector->mLowercaseTag,
|
2012-03-14 09:44:13 +04:00
|
|
|
RuleValue(*aRuleInfo, 0, aCascade->mQuirksMode));
|
2009-12-11 10:37:40 +03:00
|
|
|
#else
|
|
|
|
NS_NOTREACHED("Unexpected pseudo type");
|
2009-12-11 10:37:40 +03:00
|
|
|
#endif
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
for (nsCSSSelector* selector = aRuleInfo->mSelector;
|
2006-04-04 03:52:17 +04:00
|
|
|
selector; selector = selector->mNext) {
|
2009-12-11 10:37:41 +03:00
|
|
|
if (selector->IsPseudoElement()) {
|
|
|
|
NS_ASSERTION(!selector->mNegations, "Shouldn't have negations");
|
|
|
|
// Make sure these selectors don't end up in the hashtables we use to
|
|
|
|
// match against actual elements, no matter what. Normally they wouldn't
|
|
|
|
// anyway, but trees overload mPseudoClassList with weird stuff.
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-24 21:42:15 +03:00
|
|
|
if (!AddSelector(cascade, selector, selector)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 10:32:11 +04:00
|
|
|
struct PerWeightDataListItem : public RuleSelectorPair {
|
|
|
|
PerWeightDataListItem(css::StyleRule* aRule, nsCSSSelector* aSelector)
|
|
|
|
: RuleSelectorPair(aRule, aSelector)
|
|
|
|
, mNext(nsnull)
|
|
|
|
{}
|
|
|
|
// No destructor; these are arena-allocated
|
|
|
|
|
|
|
|
|
|
|
|
// Placement new to arena allocate the PerWeightDataListItem
|
|
|
|
void *operator new(size_t aSize, PLArenaPool &aArena) CPP_THROW_NEW {
|
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &aArena, aSize);
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
PerWeightDataListItem *mNext;
|
|
|
|
};
|
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
struct PerWeightData {
|
2011-12-08 10:32:11 +04:00
|
|
|
PerWeightData()
|
|
|
|
: mRuleSelectorPairs(nsnull)
|
|
|
|
, mTail(&mRuleSelectorPairs)
|
|
|
|
{}
|
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
PRInt32 mWeight;
|
2011-12-08 10:32:11 +04:00
|
|
|
PerWeightDataListItem *mRuleSelectorPairs;
|
|
|
|
PerWeightDataListItem **mTail;
|
2007-12-15 01:59:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RuleByWeightEntry : public PLDHashEntryHdr {
|
2011-12-08 10:32:11 +04:00
|
|
|
PerWeightData data; // mWeight is key, mRuleSelectorPairs are value
|
2007-12-15 01:59:20 +03:00
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2007-12-15 01:59:20 +03:00
|
|
|
HashIntKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
return PLDHashNumber(NS_PTR_TO_INT32(key));
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-12-15 01:59:20 +03:00
|
|
|
MatchWeightEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-12-15 01:59:20 +03:00
|
|
|
const RuleByWeightEntry *entry = (const RuleByWeightEntry *)hdr;
|
|
|
|
return entry->data.mWeight == NS_PTR_TO_INT32(key);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-03 00:56:09 +04:00
|
|
|
InitWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleByWeightEntry* entry = static_cast<RuleByWeightEntry*>(hdr);
|
|
|
|
new (entry) RuleByWeightEntry();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
static PLDHashTableOps gRulesByWeightOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
HashIntKey,
|
|
|
|
MatchWeightEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
2011-12-08 10:32:11 +04:00
|
|
|
PL_DHashClearEntryStub,
|
2007-12-15 01:59:20 +03:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-03 00:56:09 +04:00
|
|
|
InitWeightEntry
|
2007-12-15 01:59:20 +03:00
|
|
|
};
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
struct CascadeEnumData {
|
2008-07-26 20:14:48 +04:00
|
|
|
CascadeEnumData(nsPresContext* aPresContext,
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& aFontFaceRules,
|
2011-04-12 10:18:43 +04:00
|
|
|
nsTArray<nsCSSKeyframesRule*>& aKeyframesRules,
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQueryResultCacheKey& aKey,
|
2008-11-27 06:50:16 +03:00
|
|
|
PRUint8 aSheetType)
|
2006-04-04 03:52:17 +04:00
|
|
|
: mPresContext(aPresContext),
|
2008-11-26 02:22:38 +03:00
|
|
|
mFontFaceRules(aFontFaceRules),
|
2011-04-12 10:18:43 +04:00
|
|
|
mKeyframesRules(aKeyframesRules),
|
2008-07-26 20:14:48 +04:00
|
|
|
mCacheKey(aKey),
|
2008-11-27 06:50:16 +03:00
|
|
|
mSheetType(aSheetType)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-12-15 01:59:20 +03:00
|
|
|
if (!PL_DHashTableInit(&mRulesByWeight, &gRulesByWeightOps, nsnull,
|
|
|
|
sizeof(RuleByWeightEntry), 64))
|
|
|
|
mRulesByWeight.ops = nsnull;
|
2011-12-08 10:32:11 +04:00
|
|
|
|
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "CascadeEnumDataArena",
|
|
|
|
NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE);
|
2007-12-15 01:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~CascadeEnumData()
|
|
|
|
{
|
|
|
|
if (mRulesByWeight.ops)
|
|
|
|
PL_DHashTableFinish(&mRulesByWeight);
|
2011-12-08 10:32:11 +04:00
|
|
|
PL_FinishArenaPool(&mArena);
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* mPresContext;
|
2008-11-27 06:50:16 +03:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& mFontFaceRules;
|
2011-04-12 10:18:43 +04:00
|
|
|
nsTArray<nsCSSKeyframesRule*>& mKeyframesRules;
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQueryResultCacheKey& mCacheKey;
|
2011-12-08 10:32:11 +04:00
|
|
|
PLArenaPool mArena;
|
2007-12-15 01:59:20 +03:00
|
|
|
// Hooray, a manual PLDHashTable since nsClassHashtable doesn't
|
|
|
|
// provide a getter that gives me a *reference* to the value.
|
2011-12-08 10:32:11 +04:00
|
|
|
PLDHashTable mRulesByWeight; // of PerWeightDataListItem linked lists
|
2008-11-27 06:50:16 +03:00
|
|
|
PRUint8 mSheetType;
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
/*
|
|
|
|
* This enumerates style rules in a sheet (and recursively into any
|
|
|
|
* grouping rules) in order to:
|
|
|
|
* (1) add any style rules, in order, into data->mRulesByWeight (for
|
|
|
|
* the primary CSS cascade), where they are separated by weight
|
|
|
|
* but kept in order per-weight, and
|
|
|
|
* (2) add any @font-face rules, in order, into data->mFontFaceRules.
|
2011-04-12 10:18:43 +04:00
|
|
|
* (3) add any @keyframes rules, in order, into data->mKeyframesRules.
|
2008-11-26 02:22:38 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-04-08 05:23:46 +04:00
|
|
|
CascadeRuleEnumFunc(css::Rule* aRule, void* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
2010-07-18 18:39:20 +04:00
|
|
|
PRInt32 type = aRule->GetType();
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
if (css::Rule::STYLE_RULE == type) {
|
2011-03-11 05:48:57 +03:00
|
|
|
css::StyleRule* styleRule = static_cast<css::StyleRule*>(aRule);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
|
|
|
for (nsCSSSelectorList *sel = styleRule->Selector();
|
|
|
|
sel; sel = sel->mNext) {
|
|
|
|
PRInt32 weight = sel->mWeight;
|
2007-12-15 01:59:20 +03:00
|
|
|
RuleByWeightEntry *entry = static_cast<RuleByWeightEntry*>(
|
|
|
|
PL_DHashTableOperate(&data->mRulesByWeight, NS_INT32_TO_PTR(weight),
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!entry)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-12-15 01:59:20 +03:00
|
|
|
entry->data.mWeight = weight;
|
2011-12-08 10:32:11 +04:00
|
|
|
// entry->data.mRuleSelectorPairs should be linked in forward order;
|
|
|
|
// entry->data.mTail is the slot to write to.
|
|
|
|
PerWeightDataListItem *newItem =
|
|
|
|
new (data->mArena) PerWeightDataListItem(styleRule, sel->mSelectors);
|
|
|
|
if (newItem) {
|
|
|
|
*(entry->data.mTail) = newItem;
|
|
|
|
entry->data.mTail = &newItem->mNext;
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-04-08 05:23:46 +04:00
|
|
|
else if (css::Rule::MEDIA_RULE == type ||
|
|
|
|
css::Rule::DOCUMENT_RULE == type) {
|
2010-08-08 09:28:33 +04:00
|
|
|
css::GroupRule* groupRule = static_cast<css::GroupRule*>(aRule);
|
2008-07-26 20:14:48 +04:00
|
|
|
if (groupRule->UseForPresentation(data->mPresContext, data->mCacheKey))
|
2008-11-26 02:22:38 +03:00
|
|
|
if (!groupRule->EnumerateRulesForwards(CascadeRuleEnumFunc, aData))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-04-08 05:23:46 +04:00
|
|
|
else if (css::Rule::FONT_FACE_RULE == type) {
|
2008-11-26 02:22:38 +03:00
|
|
|
nsCSSFontFaceRule *fontFaceRule = static_cast<nsCSSFontFaceRule*>(aRule);
|
2008-11-27 06:50:16 +03:00
|
|
|
nsFontFaceRuleContainer *ptr = data->mFontFaceRules.AppendElement();
|
2008-11-26 02:22:38 +03:00
|
|
|
if (!ptr)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-27 06:50:16 +03:00
|
|
|
ptr->mRule = fontFaceRule;
|
|
|
|
ptr->mSheetType = data->mSheetType;
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
2011-04-08 05:23:46 +04:00
|
|
|
else if (css::Rule::KEYFRAMES_RULE == type) {
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSKeyframesRule *keyframesRule =
|
|
|
|
static_cast<nsCSSKeyframesRule*>(aRule);
|
|
|
|
if (!data->mKeyframesRules.AppendElement(keyframesRule)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSRuleProcessor::CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2010-05-14 23:05:14 +04:00
|
|
|
if (aSheet->IsApplicable() &&
|
2010-05-12 00:41:47 +04:00
|
|
|
aSheet->UseForPresentation(aData->mPresContext, aData->mCacheKey) &&
|
|
|
|
aSheet->mInner) {
|
|
|
|
nsCSSStyleSheet* child = aSheet->mInner->mFirstChild;
|
2006-04-04 03:52:17 +04:00
|
|
|
while (child) {
|
2010-05-12 00:41:47 +04:00
|
|
|
CascadeSheet(child, aData);
|
2006-04-04 03:52:17 +04:00
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
if (!aSheet->mInner->mOrderedRules.EnumerateForwards(CascadeRuleEnumFunc,
|
|
|
|
aData))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int CompareWeightData(const void* aArg1, const void* aArg2,
|
|
|
|
void* closure)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-12-15 01:59:20 +03:00
|
|
|
const PerWeightData* arg1 = static_cast<const PerWeightData*>(aArg1);
|
|
|
|
const PerWeightData* arg2 = static_cast<const PerWeightData*>(aArg2);
|
2006-04-04 03:52:17 +04:00
|
|
|
return arg1->mWeight - arg2->mWeight; // put lower weight first
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
struct FillWeightArrayData {
|
|
|
|
FillWeightArrayData(PerWeightData* aArrayData) :
|
2006-04-04 03:52:17 +04:00
|
|
|
mIndex(0),
|
2007-12-15 01:59:20 +03:00
|
|
|
mWeightArray(aArrayData)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
PRInt32 mIndex;
|
2007-12-15 01:59:20 +03:00
|
|
|
PerWeightData* mWeightArray;
|
2006-04-04 03:52:17 +04:00
|
|
|
};
|
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2007-12-15 01:59:20 +03:00
|
|
|
FillWeightArray(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2007-12-15 01:59:20 +03:00
|
|
|
FillWeightArrayData* data = static_cast<FillWeightArrayData*>(arg);
|
|
|
|
const RuleByWeightEntry *entry = (const RuleByWeightEntry *)hdr;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
data->mWeightArray[data->mIndex++] = entry->data;
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2007-12-15 01:59:20 +03:00
|
|
|
return PL_DHASH_NEXT;
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
RuleCascadeData*
|
|
|
|
nsCSSRuleProcessor::GetRuleCascade(nsPresContext* aPresContext)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
// If anything changes about the presentation context, we will be
|
|
|
|
// notified. Otherwise, our cache is valid if mLastPresContext
|
|
|
|
// matches aPresContext. (The only rule processors used for multiple
|
|
|
|
// pres contexts are for XBL. These rule processors are probably less
|
|
|
|
// likely to have @media rules, and thus the cache is pretty likely to
|
|
|
|
// hit instantly even when we're switching between pres contexts.)
|
|
|
|
|
|
|
|
if (!mRuleCascades || aPresContext != mLastPresContext) {
|
|
|
|
RefreshRuleCascade(aPresContext);
|
|
|
|
}
|
|
|
|
mLastPresContext = aPresContext;
|
|
|
|
|
|
|
|
return mRuleCascades;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRuleProcessor::RefreshRuleCascade(nsPresContext* aPresContext)
|
2006-04-04 03:52:17 +04:00
|
|
|
{
|
2008-07-26 20:14:48 +04:00
|
|
|
// Having RuleCascadeData objects be per-medium (over all variation
|
|
|
|
// caused by media queries, handled through mCacheKey) works for now
|
|
|
|
// since nsCSSRuleProcessor objects are per-document. (For a given
|
|
|
|
// set of stylesheets they can vary based on medium (@media) or
|
|
|
|
// document (@-moz-document).)
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
for (RuleCascadeData **cascadep = &mRuleCascades, *cascade;
|
|
|
|
(cascade = *cascadep); cascadep = &cascade->mNext) {
|
|
|
|
if (cascade->mCacheKey.Matches(aPresContext)) {
|
|
|
|
// Ensure that the current one is always mRuleCascades.
|
|
|
|
*cascadep = cascade->mNext;
|
|
|
|
cascade->mNext = mRuleCascades;
|
|
|
|
mRuleCascades = cascade;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
if (mSheets.Length() != 0) {
|
2007-12-14 03:24:39 +03:00
|
|
|
nsAutoPtr<RuleCascadeData> newCascade(
|
2008-07-26 20:14:48 +04:00
|
|
|
new RuleCascadeData(aPresContext->Medium(),
|
2007-12-14 03:24:39 +03:00
|
|
|
eCompatibility_NavQuirks == aPresContext->CompatibilityMode()));
|
|
|
|
if (newCascade) {
|
2008-11-26 02:22:38 +03:00
|
|
|
CascadeEnumData data(aPresContext, newCascade->mFontFaceRules,
|
2011-04-12 10:18:43 +04:00
|
|
|
newCascade->mKeyframesRules,
|
2008-11-26 02:22:38 +03:00
|
|
|
newCascade->mCacheKey,
|
2008-11-27 06:50:16 +03:00
|
|
|
mSheetType);
|
2007-12-15 01:59:20 +03:00
|
|
|
if (!data.mRulesByWeight.ops)
|
2008-07-26 20:14:48 +04:00
|
|
|
return; /* out of memory */
|
2010-05-12 00:41:47 +04:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mSheets.Length(); ++i) {
|
|
|
|
if (!CascadeSheet(mSheets.ElementAt(i), &data))
|
|
|
|
return; /* out of memory */
|
|
|
|
}
|
2007-12-15 01:59:20 +03:00
|
|
|
|
|
|
|
// Sort the hash table of per-weight linked lists by weight.
|
|
|
|
PRUint32 weightCount = data.mRulesByWeight.entryCount;
|
|
|
|
nsAutoArrayPtr<PerWeightData> weightArray(new PerWeightData[weightCount]);
|
|
|
|
FillWeightArrayData fwData(weightArray);
|
|
|
|
PL_DHashTableEnumerate(&data.mRulesByWeight, FillWeightArray, &fwData);
|
|
|
|
NS_QuickSort(weightArray, weightCount, sizeof(PerWeightData),
|
|
|
|
CompareWeightData, nsnull);
|
2006-04-04 03:52:17 +04:00
|
|
|
|
2010-07-03 00:56:09 +04:00
|
|
|
// Put things into the rule hash.
|
2007-12-15 01:59:20 +03:00
|
|
|
// The primary sort is by weight...
|
2010-07-03 00:56:09 +04:00
|
|
|
for (PRUint32 i = 0; i < weightCount; ++i) {
|
2011-12-08 10:32:11 +04:00
|
|
|
// and the secondary sort is by order. mRuleSelectorPairs is already in
|
2010-07-03 00:56:09 +04:00
|
|
|
// the right order..
|
2011-12-08 10:32:11 +04:00
|
|
|
for (PerWeightDataListItem *cur = weightArray[i].mRuleSelectorPairs;
|
|
|
|
cur;
|
|
|
|
cur = cur->mNext) {
|
2010-07-03 00:56:09 +04:00
|
|
|
if (!AddRule(cur, newCascade))
|
2008-07-26 20:14:48 +04:00
|
|
|
return; /* out of memory */
|
2010-07-03 00:56:09 +04:00
|
|
|
}
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
// Ensure that the current one is always mRuleCascades.
|
|
|
|
newCascade->mNext = mRuleCascades;
|
|
|
|
mRuleCascades = newCascade.forget();
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
return;
|
2006-04-04 03:52:17 +04:00
|
|
|
}
|
2008-07-22 04:55:52 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSRuleProcessor::SelectorListMatches(Element* aElement,
|
2011-03-29 21:29:21 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelectorList* aSelectorList)
|
2008-07-22 04:55:52 +04:00
|
|
|
{
|
|
|
|
while (aSelectorList) {
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelector* sel = aSelectorList->mSelectors;
|
2008-07-22 04:55:52 +04:00
|
|
|
NS_ASSERTION(sel, "Should have *some* selectors");
|
2009-12-11 10:37:41 +03:00
|
|
|
NS_ASSERTION(!sel->IsPseudoElement(), "Shouldn't have been called");
|
2011-10-17 18:59:28 +04:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(), false);
|
2011-03-29 21:29:21 +04:00
|
|
|
if (SelectorMatches(aElement, sel, nodeContext, aTreeMatchContext)) {
|
2011-11-14 22:10:22 +04:00
|
|
|
nsCSSSelector* next = sel->mNext;
|
2011-03-29 21:29:21 +04:00
|
|
|
if (!next ||
|
2011-10-17 18:59:28 +04:00
|
|
|
SelectorMatchesTree(aElement, next, aTreeMatchContext, false)) {
|
|
|
|
return true;
|
2008-07-22 04:55:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aSelectorList = aSelectorList->mNext;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-22 04:55:52 +04:00
|
|
|
}
|
2012-03-13 07:54:15 +04:00
|
|
|
|
|
|
|
// AncestorFilter out of line methods
|
|
|
|
void
|
|
|
|
AncestorFilter::Init(Element *aElement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mFilter);
|
|
|
|
MOZ_ASSERT(mHashes.IsEmpty());
|
|
|
|
|
|
|
|
mFilter = new Filter();
|
|
|
|
|
|
|
|
if (NS_LIKELY(aElement)) {
|
|
|
|
MOZ_ASSERT(aElement->IsInDoc(),
|
|
|
|
"aElement must be in the document for the assumption that "
|
|
|
|
"GetNodeParent() is non-null on all element ancestors of "
|
|
|
|
"aElement to be true");
|
|
|
|
// Collect up the ancestors
|
|
|
|
nsAutoTArray<Element*, 50> ancestors;
|
|
|
|
Element* cur = aElement;
|
|
|
|
do {
|
|
|
|
ancestors.AppendElement(cur);
|
|
|
|
nsINode* parent = cur->GetNodeParent();
|
|
|
|
if (!parent->IsElement()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur = parent->AsElement();
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
// Now push them in reverse order.
|
|
|
|
for (PRUint32 i = ancestors.Length(); i-- != 0; ) {
|
|
|
|
PushAncestor(ancestors[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AncestorFilter::PushAncestor(Element *aElement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFilter);
|
|
|
|
|
|
|
|
PRUint32 oldLength = mHashes.Length();
|
|
|
|
|
|
|
|
mPopTargets.AppendElement(oldLength);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mElements.AppendElement(aElement);
|
|
|
|
#endif
|
|
|
|
mHashes.AppendElement(aElement->Tag()->hash());
|
|
|
|
nsIAtom *id = aElement->GetID();
|
|
|
|
if (id) {
|
|
|
|
mHashes.AppendElement(id->hash());
|
|
|
|
}
|
|
|
|
const nsAttrValue *classes = aElement->GetClasses();
|
|
|
|
if (classes) {
|
|
|
|
PRUint32 classCount = classes->GetAtomCount();
|
|
|
|
for (PRUint32 i = 0; i < classCount; ++i) {
|
|
|
|
mHashes.AppendElement(classes->AtomAt(i)->hash());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 newLength = mHashes.Length();
|
|
|
|
for (PRUint32 i = oldLength; i < newLength; ++i) {
|
|
|
|
mFilter->add(mHashes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AncestorFilter::PopAncestor()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPopTargets.IsEmpty());
|
|
|
|
MOZ_ASSERT(mPopTargets.Length() == mElements.Length());
|
|
|
|
|
|
|
|
PRUint32 popTargetLength = mPopTargets.Length();
|
|
|
|
PRUint32 newLength = mPopTargets[popTargetLength-1];
|
|
|
|
|
|
|
|
mPopTargets.TruncateLength(popTargetLength-1);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mElements.TruncateLength(popTargetLength-1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRUint32 oldLength = mHashes.Length();
|
|
|
|
for (PRUint32 i = newLength; i < oldLength; ++i) {
|
|
|
|
mFilter->remove(mHashes[i]);
|
|
|
|
}
|
|
|
|
mHashes.TruncateLength(newLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AncestorFilter::AssertHasAllAncestors(Element *aElement) const
|
|
|
|
{
|
|
|
|
nsINode* cur = aElement->GetNodeParent();
|
|
|
|
while (cur && cur->IsElement()) {
|
|
|
|
MOZ_ASSERT(mElements.Contains(cur));
|
|
|
|
cur = cur->GetNodeParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|