2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* style rule processor for CSS style sheets, responsible for selector
|
|
|
|
* matching and cascading
|
|
|
|
*/
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2009-08-01 08:53:40 -07:00
|
|
|
#include "nsRuleProcessorData.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
2011-12-07 22:32:11 -08:00
|
|
|
// We want page-sized arenas so there's no fragmentation involved.
|
|
|
|
#define NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE (4096)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsICSSPseudoComparator.h"
|
2011-03-10 18:48:57 -08:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2010-08-07 22:28:33 -07:00
|
|
|
#include "mozilla/css/GroupRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsCSSPseudoClasses.h"
|
2009-12-10 23:37:40 -08:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "nsQuickSort.h"
|
|
|
|
#include "nsAttrValue.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAttrName.h"
|
2007-11-19 12:08:20 -08:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2008-06-10 17:27:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
2008-07-26 09:14:48 -07:00
|
|
|
#include "nsIMediaList.h"
|
2008-09-30 20:01:53 -07:00
|
|
|
#include "nsCSSRules.h"
|
2008-11-26 19:50:16 -08:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsStyleSet.h"
|
2009-12-10 23:37:41 -08:00
|
|
|
#include "prlog.h"
|
2010-04-07 10:29:10 -07: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 09:59:13 -07:00
|
|
|
#include "mozilla/Services.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-03-29 10:29:21 -07:00
|
|
|
#include "nsNthIndexCache.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-08 19:27:12 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2010-04-30 06:12:06 -07:00
|
|
|
|
2011-05-24 23:31:59 -07:00
|
|
|
using namespace mozilla;
|
2010-04-30 06:12:06 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-11-19 12:08:20 -08:00
|
|
|
|
2008-10-21 00:15:03 -07:00
|
|
|
#define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled"
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gSupportVisitedPseudo = true;
|
2008-10-21 00:15:03 -07:00
|
|
|
|
2007-11-19 12:08:20 -08:00
|
|
|
static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-09 13:53:45 -07:00
|
|
|
#ifdef XP_WIN
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t nsCSSRuleProcessor::sWinThemeId = LookAndFeel::eWindowsTheme_Generic;
|
2010-10-09 13:53:45 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
/**
|
|
|
|
* A struct representing a given CSS rule and a particular selector
|
|
|
|
* from that rule's selector list.
|
|
|
|
*/
|
|
|
|
struct RuleSelectorPair {
|
2011-03-10 18:48:57 -08:00
|
|
|
RuleSelectorPair(css::StyleRule* aRule, nsCSSSelector* aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mRule(aRule), mSelector(aSelector) {}
|
2011-12-07 22:32:11 -08:00
|
|
|
// If this class ever grows a destructor, deal with
|
|
|
|
// PerWeightDataListItem appropriately.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
css::StyleRule* mRule;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSSelector* mSelector; // which of |mRule|'s selectors
|
2010-07-02 13:56:09 -07:00
|
|
|
};
|
|
|
|
|
2012-03-12 20:54:14 -07:00
|
|
|
#define NS_IS_ANCESTOR_OPERATOR(ch) \
|
|
|
|
((ch) == PRUnichar(' ') || (ch) == PRUnichar('>'))
|
|
|
|
|
2010-07-02 13:56:09 -07: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-12 20:54:14 -07:00
|
|
|
enum {
|
|
|
|
eMaxAncestorHashes = 4
|
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
RuleValue(const RuleSelectorPair& aRuleSelectorPair, int32_t aIndex,
|
2012-03-13 22:44:13 -07:00
|
|
|
bool aQuirksMode) :
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleSelectorPair(aRuleSelectorPair),
|
|
|
|
mIndex(aIndex)
|
2012-03-12 20:54:14 -07:00
|
|
|
{
|
2012-03-13 22:44:13 -07:00
|
|
|
CollectAncestorHashes(aQuirksMode);
|
2012-03-12 20:54:14 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mIndex; // High index means high weight/order.
|
2012-03-12 20:54:14 -07:00
|
|
|
uint32_t mAncestorSelectorHashes[eMaxAncestorHashes];
|
|
|
|
|
|
|
|
private:
|
2012-03-13 22:44:13 -07:00
|
|
|
void CollectAncestorHashes(bool aQuirksMode) {
|
2012-03-12 20:54:14 -07: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-13 22:44:13 -07: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-12 20:54:14 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 22:44:13 -07:00
|
|
|
nsAtomList* classes = sel->mClassList;
|
|
|
|
while (classes) {
|
|
|
|
mAncestorSelectorHashes[hashIndex++] = classes->mAtom->hash();
|
|
|
|
if (hashIndex == eMaxAncestorHashes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
classes = classes->mNext;
|
2012-03-12 20:54:14 -07: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;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Rule hash table
|
|
|
|
//
|
|
|
|
|
|
|
|
// Uses any of the sets of ops below.
|
|
|
|
struct RuleHashTableEntry : public PLDHashEntryHdr {
|
2011-08-08 05:34:57 -07:00
|
|
|
// If you add members that have heap allocated memory be sure to change the
|
2011-12-08 21:01:52 -08:00
|
|
|
// logic in SizeOfRuleHashTableEntry().
|
2011-10-05 19:06:37 -07:00
|
|
|
// Auto length 1, because we always have at least one entry in mRules.
|
|
|
|
nsAutoTArray<RuleValue, 1> mRules;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
struct RuleHashTagTableEntry : public RuleHashTableEntry {
|
2011-08-08 05:34:57 -07:00
|
|
|
// If you add members that have heap allocated memory be sure to change the
|
2011-12-08 21:01:52 -08:00
|
|
|
// logic in RuleHash::SizeOf{In,Ex}cludingThis.
|
2009-08-01 08:53:40 -07:00
|
|
|
nsCOMPtr<nsIAtom> mTag;
|
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashNumber
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleHash_CIHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIAtom *atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
atom->ToString(str);
|
2010-08-02 15:19:04 -07:00
|
|
|
nsContentUtils::ASCIIToLower(str);
|
2007-03-22 10:30:00 -07:00
|
|
|
return HashString(str);
|
|
|
|
}
|
|
|
|
|
2007-03-27 08:33:38 -07:00
|
|
|
typedef nsIAtom*
|
2008-10-10 08:04:34 -07:00
|
|
|
(* RuleHashGetKey) (PLDHashTable *table, const PLDHashEntryHdr *entry);
|
2007-03-27 08:33:38 -07: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-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleHash_CIMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
|
|
|
(key));
|
2007-03-27 08:33:38 -07:00
|
|
|
// Use our extra |getKey| callback to avoid code duplication.
|
|
|
|
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Check for case-sensitive match first.
|
|
|
|
if (match_atom == entry_atom)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
// Use EqualsIgnoreASCIICase instead of full on unicode case conversion
|
|
|
|
// in order to save on performance. This is only used in quirks mode
|
|
|
|
// anyway.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
return
|
|
|
|
nsContentUtils::EqualsIgnoreASCIICase(nsDependentAtomString(entry_atom),
|
|
|
|
nsDependentAtomString(match_atom));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleHash_CSMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIAtom *match_atom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>
|
|
|
|
(key));
|
2007-03-27 08:33:38 -07:00
|
|
|
// Use our extra |getKey| callback to avoid code duplication.
|
|
|
|
nsIAtom *entry_atom = ToLocalOps(table->ops)->getKey(table, hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return match_atom == entry_atom;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
new (entry) RuleHashTableEntry();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RuleHash_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
entry->~RuleHashTableEntry();
|
|
|
|
}
|
|
|
|
|
2011-10-05 19:06:37 -07: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-28 23:19:26 -07:00
|
|
|
static bool
|
2009-08-01 08:53:40 -07:00
|
|
|
RuleHash_TagTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-01 08:53:40 -07: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-28 23:19:26 -07:00
|
|
|
static bool
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_TagTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>(hdr);
|
|
|
|
new (entry) RuleHashTagTableEntry();
|
2010-07-08 09:50:18 -07:00
|
|
|
entry->mTag = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RuleHash_TagTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
2009-08-01 08:53:40 -07:00
|
|
|
{
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHashTagTableEntry* entry = static_cast<RuleHashTagTableEntry*>(hdr);
|
|
|
|
entry->~RuleHashTagTableEntry();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-05 19:06:37 -07: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 08:04:34 -07:00
|
|
|
static nsIAtom*
|
2007-03-27 08:33:38 -07:00
|
|
|
RuleHash_ClassTable_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-27 08:33:38 -07:00
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2010-07-02 13:56:09 -07:00
|
|
|
return entry->mRules[0].mSelector->mClassList->mAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static nsIAtom*
|
2007-03-27 08:33:38 -07:00
|
|
|
RuleHash_IdTable_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-27 08:33:38 -07:00
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2010-07-02 13:56:09 -07:00
|
|
|
return entry->mRules[0].mSelector->mIDList->mAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashNumber
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleHash_NameSpaceTable_HashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(key);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleHash_NameSpaceTable_MatchEntry(PLDHashTable *table,
|
|
|
|
const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const RuleHashTableEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<const RuleHashTableEntry*>(hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_PTR_TO_INT32(key) ==
|
2010-07-02 13:56:09 -07:00
|
|
|
entry->mRules[0].mSelector->mNameSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
static const PLDHashTableOps RuleHash_TagTable_Ops = {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
2009-08-01 08:53:40 -07:00
|
|
|
RuleHash_TagTable_MatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_TagTable_MoveEntry,
|
2009-08-01 08:53:40 -07:00
|
|
|
RuleHash_TagTable_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_TagTable_InitEntry
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2007-03-27 08:33:38 -07:00
|
|
|
static const RuleHashTableOps RuleHash_ClassTable_CSOps = {
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
RuleHash_CSMatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 08:33:38 -07:00
|
|
|
},
|
|
|
|
RuleHash_ClassTable_GetKey
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2007-03-27 08:33:38 -07:00
|
|
|
static const RuleHashTableOps RuleHash_ClassTable_CIOps = {
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 08:33:38 -07:00
|
|
|
},
|
|
|
|
RuleHash_ClassTable_GetKey
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2007-03-27 08:33:38 -07:00
|
|
|
static const RuleHashTableOps RuleHash_IdTable_CSOps = {
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
RuleHash_CSMatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 08:33:38 -07:00
|
|
|
},
|
|
|
|
RuleHash_IdTable_GetKey
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2007-03-27 08:33:38 -07:00
|
|
|
static const RuleHashTableOps RuleHash_IdTable_CIOps = {
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry
|
2007-03-27 08:33:38 -07:00
|
|
|
},
|
|
|
|
RuleHash_IdTable_GetKey
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-03-27 08:33:38 -07:00
|
|
|
static const PLDHashTableOps RuleHash_NameSpaceTable_Ops = {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_NameSpaceTable_HashKey,
|
|
|
|
RuleHash_NameSpaceTable_MatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
RuleHash_MoveEntry,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_ClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleHash_InitEntry
|
2007-03-22 10:30:00 -07: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 10:29:21 -07:00
|
|
|
struct NodeMatchContext;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class RuleHash {
|
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
RuleHash(bool aQuirksMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
~RuleHash();
|
2010-07-02 13:56:09 -07:00
|
|
|
void AppendRule(const RuleSelectorPair &aRuleInfo);
|
2012-11-14 11:09:01 -08:00
|
|
|
void EnumerateAllRules(Element* aElement, ElementDependentRuleProcessorData* aData,
|
2011-03-29 10:29:21 -07:00
|
|
|
NodeMatchContext& aNodeMatchContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2010-07-02 13:56:09 -07:00
|
|
|
typedef nsTArray<RuleValue> RuleValueList;
|
|
|
|
void AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
|
|
|
|
const RuleSelectorPair& aRuleInfo);
|
|
|
|
void AppendUniversalRule(const RuleSelectorPair& aRuleInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRuleCount;
|
2011-12-09 02:29:01 -08:00
|
|
|
// The hashtables are lazily initialized; we use a null .ops to
|
|
|
|
// indicate that they need initialization.
|
2007-03-22 10:30:00 -07:00
|
|
|
PLDHashTable mIdTable;
|
|
|
|
PLDHashTable mClassTable;
|
|
|
|
PLDHashTable mTagTable;
|
|
|
|
PLDHashTable mNameSpaceTable;
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleValueList mUniversalRules;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
struct EnumData {
|
|
|
|
const RuleValue* mCurValue;
|
|
|
|
const RuleValue* mEnd;
|
|
|
|
};
|
|
|
|
EnumData* mEnumList;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mEnumListSize;
|
2010-07-02 13:56:09 -07:00
|
|
|
|
2011-12-09 02:29:01 -08:00
|
|
|
bool mQuirksMode;
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
inline EnumData ToEnumData(const RuleValueList& arr) {
|
|
|
|
EnumData data = { arr.Elements(), arr.Elements() + arr.Length() };
|
|
|
|
return data;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef RULE_HASH_STATS
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mUniversalSelectors;
|
|
|
|
uint32_t mNameSpaceSelectors;
|
|
|
|
uint32_t mTagSelectors;
|
|
|
|
uint32_t mClassSelectors;
|
|
|
|
uint32_t mIdSelectors;
|
|
|
|
|
|
|
|
uint32_t mElementsMatched;
|
|
|
|
|
|
|
|
uint32_t mElementUniversalCalls;
|
|
|
|
uint32_t mElementNameSpaceCalls;
|
|
|
|
uint32_t mElementTagCalls;
|
|
|
|
uint32_t mElementClassCalls;
|
|
|
|
uint32_t mElementIdCalls;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // RULE_HASH_STATS
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
RuleHash::RuleHash(bool aQuirksMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mRuleCount(0),
|
2012-07-20 04:16:17 -07:00
|
|
|
mUniversalRules(0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mEnumList(nullptr), mEnumListSize(0),
|
2011-12-09 02:29:01 -08:00
|
|
|
mQuirksMode(aQuirksMode)
|
2007-03-22 10:30:00 -07: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-10 23:37:40 -08:00
|
|
|
mElementIdCalls(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
{
|
2009-12-10 23:37:40 -08:00
|
|
|
MOZ_COUNT_CTOR(RuleHash);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mTagTable.ops = nullptr;
|
|
|
|
mIdTable.ops = nullptr;
|
|
|
|
mClassTable.ops = nullptr;
|
|
|
|
mNameSpaceTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleHash::~RuleHash()
|
|
|
|
{
|
2009-12-10 23:37:40 -08:00
|
|
|
MOZ_COUNT_DTOR(RuleHash);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
printf(
|
|
|
|
"RuleHash(%p):\n"
|
|
|
|
" Selectors: Universal (%u) NameSpace(%u) Tag(%u) Class(%u) Id(%u)\n"
|
2009-12-10 23:37:40 -08:00
|
|
|
" Content Nodes: Elements(%u)\n"
|
2007-03-22 10:30:00 -07:00
|
|
|
" Element Calls: Universal(%u) NameSpace(%u) Tag(%u) Class(%u) Id(%u)\n"
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<void*>(this),
|
2007-03-22 10:30:00 -07:00
|
|
|
mUniversalSelectors, mNameSpaceSelectors, mTagSelectors,
|
|
|
|
mClassSelectors, mIdSelectors,
|
|
|
|
mElementsMatched,
|
|
|
|
mElementUniversalCalls, mElementNameSpaceCalls, mElementTagCalls,
|
2009-12-10 23:37:40 -08:00
|
|
|
mElementClassCalls, mElementIdCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef PRINT_UNIVERSAL_RULES
|
|
|
|
{
|
2010-07-02 13:56:09 -07:00
|
|
|
if (mUniversalRules.Length() > 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" Universal rules:\n");
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mUniversalRules.Length(); ++i) {
|
2010-07-02 13:56:09 -07:00
|
|
|
RuleValue* value = &(mUniversalRules[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString selectorText;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lineNumber = value->mRule->GetLineNumber();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
value->mRule->GetStyleSheet(*getter_AddRefs(sheet));
|
2010-05-11 13:41:47 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
value->mSelector->ToString(selectorText, cssSheet);
|
|
|
|
|
|
|
|
printf(" line %d, %s\n",
|
|
|
|
lineNumber, NS_ConvertUTF16toUTF8(selectorText).get());
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07: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.
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != mEnumList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
delete [] mEnumList;
|
|
|
|
}
|
|
|
|
// delete arena for strings and small objects
|
2011-12-09 02:29:01 -08: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);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
void RuleHash::AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
|
|
|
|
const RuleSelectorPair& aRuleInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get a new or existing entry.
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(aTable, aKey, PL_DHASH_ADD));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry)
|
|
|
|
return;
|
2012-03-13 22:44:13 -07:00
|
|
|
entry->mRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++, mQuirksMode));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
static void
|
2010-07-08 09:50:18 -07:00
|
|
|
AppendRuleToTagTable(PLDHashTable* aTable, nsIAtom* aKey,
|
|
|
|
const RuleValue& aRuleInfo)
|
2009-08-01 08:53:40 -07:00
|
|
|
{
|
|
|
|
// Get a new or exisiting entry
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleHashTagTableEntry *entry = static_cast<RuleHashTagTableEntry*>
|
|
|
|
(PL_DHashTableOperate(aTable, aKey, PL_DHASH_ADD));
|
|
|
|
if (!entry)
|
|
|
|
return;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2010-07-08 09:50:18 -07:00
|
|
|
entry->mRules.AppendElement(aRuleInfo);
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
void RuleHash::AppendUniversalRule(const RuleSelectorPair& aRuleInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-13 22:44:13 -07:00
|
|
|
mUniversalRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++, mQuirksMode));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
void RuleHash::AppendRule(const RuleSelectorPair& aRuleInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-02 13:56:09 -07:00
|
|
|
nsCSSSelector *selector = aRuleInfo.mSelector;
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != selector->mIDList) {
|
2011-12-09 02:29:01 -08:00
|
|
|
if (!mIdTable.ops) {
|
|
|
|
PL_DHashTableInit(&mIdTable,
|
|
|
|
mQuirksMode ? &RuleHash_IdTable_CIOps.ops
|
|
|
|
: &RuleHash_IdTable_CSOps.ops,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, sizeof(RuleHashTableEntry), 16);
|
2011-12-09 02:29:01 -08:00
|
|
|
}
|
2010-07-02 13:56:09 -07:00
|
|
|
AppendRuleToTable(&mIdTable, selector->mIDList->mAtom, aRuleInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mIdSelectors);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
else if (nullptr != selector->mClassList) {
|
2011-12-09 02:29:01 -08:00
|
|
|
if (!mClassTable.ops) {
|
|
|
|
PL_DHashTableInit(&mClassTable,
|
|
|
|
mQuirksMode ? &RuleHash_ClassTable_CIOps.ops
|
|
|
|
: &RuleHash_ClassTable_CSOps.ops,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, sizeof(RuleHashTableEntry), 16);
|
2011-12-09 02:29:01 -08:00
|
|
|
}
|
2010-07-02 13:56:09 -07:00
|
|
|
AppendRuleToTable(&mClassTable, selector->mClassList->mAtom, aRuleInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mClassSelectors);
|
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
else if (selector->mLowercaseTag) {
|
2012-03-13 22:44:13 -07:00
|
|
|
RuleValue ruleValue(aRuleInfo, mRuleCount++, mQuirksMode);
|
2011-12-09 02:29:01 -08:00
|
|
|
if (!mTagTable.ops) {
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops, nullptr,
|
2011-12-09 02:29:01 -08:00
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
|
|
|
}
|
2010-07-08 09:50:18 -07:00
|
|
|
AppendRuleToTagTable(&mTagTable, selector->mLowercaseTag, ruleValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mTagSelectors);
|
2009-08-01 08:53:40 -07:00
|
|
|
if (selector->mCasedTag &&
|
|
|
|
selector->mCasedTag != selector->mLowercaseTag) {
|
2010-07-08 09:50:18 -07:00
|
|
|
AppendRuleToTagTable(&mTagTable, selector->mCasedTag, ruleValue);
|
2009-08-01 08:53:40 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mTagSelectors);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (kNameSpaceID_Unknown != selector->mNameSpace) {
|
2011-12-09 02:29:01 -08:00
|
|
|
if (!mNameSpaceTable.ops) {
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops, nullptr,
|
2011-12-09 02:29:01 -08:00
|
|
|
sizeof(RuleHashTableEntry), 16);
|
|
|
|
}
|
2010-07-02 13:56:09 -07:00
|
|
|
AppendRuleToTable(&mNameSpaceTable,
|
|
|
|
NS_INT32_TO_PTR(selector->mNameSpace), aRuleInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mNameSpaceSelectors);
|
|
|
|
}
|
|
|
|
else { // universal tag selector
|
2010-07-02 13:56:09 -07:00
|
|
|
AppendUniversalRule(aRuleInfo);
|
2007-03-22 10:30:00 -07: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-02 13:56:09 -07:00
|
|
|
(var_) += (list_).Length()
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
#define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
|
|
|
|
PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
2011-03-07 09:45:25 -08:00
|
|
|
static inline
|
2012-03-12 20:54:15 -07:00
|
|
|
void ContentEnumFunc(const RuleValue &value, nsCSSSelector* selector,
|
2012-11-14 11:09:01 -08:00
|
|
|
ElementDependentRuleProcessorData* data, NodeMatchContext& nodeContext,
|
2012-03-12 20:54:15 -07:00
|
|
|
AncestorFilter *ancestorFilter);
|
2011-03-07 09:45:25 -08:00
|
|
|
|
2012-11-14 11:09:01 -08:00
|
|
|
void RuleHash::EnumerateAllRules(Element* aElement, ElementDependentRuleProcessorData* aData,
|
2011-03-29 10:29:21 -07:00
|
|
|
NodeMatchContext& aNodeContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpace = aElement->GetNameSpaceID();
|
2011-03-29 10:29:21 -07:00
|
|
|
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?");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t classCount = classList ? classList->GetAtomCount() : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// assume 1 universal, tag, id, and namespace, rather than wasting
|
|
|
|
// time counting
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t testCount = classCount + 4;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mEnumListSize < testCount) {
|
|
|
|
delete [] mEnumList;
|
2009-09-16 08:01:36 -07:00
|
|
|
mEnumListSize = NS_MAX(testCount, MIN_ENUM_LIST_SIZE);
|
2010-07-02 13:56:09 -07:00
|
|
|
mEnumList = new EnumData[mEnumListSize];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t valueCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
RULE_HASH_STAT_INCREMENT(mElementsMatched);
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
if (mUniversalRules.Length() != 0) { // universal rules
|
|
|
|
mEnumList[valueCount++] = ToEnumData(mUniversalRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(mUniversalRules, mElementUniversalCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// universal rules within the namespace
|
2011-12-09 02:29:01 -08:00
|
|
|
if (kNameSpaceID_Unknown != nameSpace && mNameSpaceTable.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 10:29:21 -07:00
|
|
|
(PL_DHashTableOperate(&mNameSpaceTable, NS_INT32_TO_PTR(nameSpace),
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-02 13:56:09 -07:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementNameSpaceCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 02:29:01 -08:00
|
|
|
if (mTagTable.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 10:29:21 -07:00
|
|
|
(PL_DHashTableOperate(&mTagTable, tag, PL_DHASH_LOOKUP));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-02 13:56:09 -07:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementTagCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 02:29:01 -08:00
|
|
|
if (id && mIdTable.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 10:29:21 -07:00
|
|
|
(PL_DHashTableOperate(&mIdTable, id, PL_DHASH_LOOKUP));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-02 13:56:09 -07:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementIdCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 02:29:01 -08:00
|
|
|
if (mClassTable.ops) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = 0; index < classCount; ++index) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
2011-03-29 10:29:21 -07:00
|
|
|
(PL_DHashTableOperate(&mClassTable, classList->AtomAt(index),
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2010-07-02 13:56:09 -07:00
|
|
|
mEnumList[valueCount++] = ToEnumData(entry->mRules);
|
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(entry->mRules, mElementClassCalls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(valueCount <= testCount, "values exceeded list size");
|
|
|
|
|
|
|
|
if (valueCount > 0) {
|
2012-03-12 20:54:15 -07:00
|
|
|
AncestorFilter *filter =
|
|
|
|
aData->mTreeMatchContext.mAncestorFilter.HasFilter() ?
|
2012-07-30 07:20:58 -07:00
|
|
|
&aData->mTreeMatchContext.mAncestorFilter : nullptr;
|
2012-03-12 20:54:15 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (filter) {
|
|
|
|
filter->AssertHasAllAncestors(aElement);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
// Merge the lists while there are still multiple lists to merge.
|
|
|
|
while (valueCount > 1) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t valueIndex = 0;
|
|
|
|
int32_t lowestRuleIndex = mEnumList[valueIndex].mCurValue->mIndex;
|
|
|
|
for (int32_t index = 1; index < valueCount; ++index) {
|
|
|
|
int32_t ruleIndex = mEnumList[index].mCurValue->mIndex;
|
2010-07-02 13:56:09 -07:00
|
|
|
if (ruleIndex < lowestRuleIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
valueIndex = index;
|
2010-07-02 13:56:09 -07:00
|
|
|
lowestRuleIndex = ruleIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-02 13:56:09 -07:00
|
|
|
const RuleValue *cur = mEnumList[valueIndex].mCurValue;
|
2012-03-12 20:54:15 -07:00
|
|
|
ContentEnumFunc(*cur, cur->mSelector, aData, aNodeContext, filter);
|
2010-07-02 13:56:09 -07:00
|
|
|
cur++;
|
|
|
|
if (cur == mEnumList[valueIndex].mEnd) {
|
|
|
|
mEnumList[valueIndex] = mEnumList[--valueCount];
|
|
|
|
} else {
|
|
|
|
mEnumList[valueIndex].mCurValue = cur;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fast loop over single value.
|
2010-07-02 13:56:09 -07:00
|
|
|
for (const RuleValue *value = mEnumList[0].mCurValue,
|
|
|
|
*end = mEnumList[0].mEnd;
|
|
|
|
value != end; ++value) {
|
2012-03-12 20:54:15 -07:00
|
|
|
ContentEnumFunc(*value, value->mSelector, aData, aNodeContext, filter);
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
static size_t
|
2011-12-15 14:59:53 -08:00
|
|
|
SizeOfRuleHashTableEntry(PLDHashEntryHdr* aHdr, nsMallocSizeOfFun aMallocSizeOf, void *)
|
2011-08-02 13:21:52 -07:00
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(aHdr);
|
2011-12-15 14:59:53 -08:00
|
|
|
return entry->mRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t
|
|
|
|
RuleHash::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-02 13:21:52 -07:00
|
|
|
{
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t n = 0;
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-09 02:29:01 -08: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-02 13:21:52 -07:00
|
|
|
|
2011-12-15 14:59:53 -08:00
|
|
|
n += mUniversalRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t
|
|
|
|
RuleHash::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-08 21:01:52 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//--------------------------------
|
|
|
|
|
2011-08-03 11:32:32 -07:00
|
|
|
// A hash table mapping atoms to lists of selectors
|
2011-04-12 19:57:42 -07:00
|
|
|
struct AtomSelectorEntry : public PLDHashEntryHdr {
|
|
|
|
nsIAtom *mAtom;
|
2011-10-05 19:06:37 -07: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 09:23:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
2010-06-18 09:23:05 -07:00
|
|
|
{
|
2011-04-12 19:57:42 -07:00
|
|
|
(static_cast<AtomSelectorEntry*>(hdr))->~AtomSelectorEntry();
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2010-06-18 09:23:05 -07:00
|
|
|
{
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelectorEntry *entry = static_cast<AtomSelectorEntry*>(hdr);
|
|
|
|
new (entry) AtomSelectorEntry();
|
|
|
|
entry->mAtom = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
|
|
|
|
2011-10-05 19:06:37 -07: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 09:23:05 -07:00
|
|
|
static nsIAtom*
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
2010-06-18 09:23:05 -07:00
|
|
|
{
|
2011-04-12 19:57:42 -07:00
|
|
|
const AtomSelectorEntry *entry = static_cast<const AtomSelectorEntry*>(hdr);
|
|
|
|
return entry->mAtom;
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
2011-08-07 19:23:36 -07:00
|
|
|
static const PLDHashTableOps AtomSelector_CSOps = {
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
2011-08-07 19:23:36 -07:00
|
|
|
PL_DHashMatchEntryStub,
|
2011-10-05 19:06:37 -07:00
|
|
|
AtomSelector_MoveEntry,
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_ClearEntry,
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_InitEntry
|
2010-06-18 09:23:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
2011-04-12 19:57:42 -07:00
|
|
|
static const RuleHashTableOps AtomSelector_CIOps = {
|
2010-06-18 09:23:05 -07:00
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
2011-10-05 19:06:37 -07:00
|
|
|
AtomSelector_MoveEntry,
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_ClearEntry,
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashFinalizeStub,
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_InitEntry
|
2010-06-18 09:23:05 -07:00
|
|
|
},
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelector_GetKey
|
2010-06-18 09:23:05 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
struct RuleCascadeData {
|
2011-09-28 23:19:26 -07:00
|
|
|
RuleCascadeData(nsIAtom *aMedium, bool aQuirksMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mRuleHash(aQuirksMode),
|
|
|
|
mStateSelectors(),
|
2010-03-25 02:22:58 -07:00
|
|
|
mSelectorDocumentStates(0),
|
2008-07-26 09:14:48 -07:00
|
|
|
mCacheKey(aMedium),
|
2012-07-30 07:20:58 -07:00
|
|
|
mNext(nullptr),
|
2009-12-10 23:37:40 -08:00
|
|
|
mQuirksMode(aQuirksMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-03 11:32:32 -07: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.
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableInit(&mAttributeSelectors, &AtomSelector_CSOps, nullptr,
|
2011-08-03 11:32:32 -07:00
|
|
|
sizeof(AtomSelectorEntry), 16);
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableInit(&mAnonBoxRules, &RuleHash_TagTable_Ops, nullptr,
|
2009-12-10 23:37:40 -08:00
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
2011-04-12 19:57:48 -07:00
|
|
|
PL_DHashTableInit(&mIdSelectors,
|
|
|
|
aQuirksMode ? &AtomSelector_CIOps.ops :
|
2011-08-07 19:23:36 -07:00
|
|
|
&AtomSelector_CSOps,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, sizeof(AtomSelectorEntry), 16);
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashTableInit(&mClassSelectors,
|
2011-04-12 19:57:42 -07:00
|
|
|
aQuirksMode ? &AtomSelector_CIOps.ops :
|
2011-08-07 19:23:36 -07:00
|
|
|
&AtomSelector_CSOps,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, sizeof(AtomSelectorEntry), 16);
|
2009-12-10 23:37:40 -08:00
|
|
|
memset(mPseudoElementRuleHashes, 0, sizeof(mPseudoElementRuleHashes));
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableInit(&mXULTreeRules, &RuleHash_TagTable_Ops, nullptr,
|
2009-12-10 23:37:40 -08:00
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~RuleCascadeData()
|
|
|
|
{
|
|
|
|
PL_DHashTableFinish(&mAttributeSelectors);
|
2009-12-10 23:37:40 -08:00
|
|
|
PL_DHashTableFinish(&mAnonBoxRules);
|
2011-04-12 19:57:48 -07:00
|
|
|
PL_DHashTableFinish(&mIdSelectors);
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashTableFinish(&mClassSelectors);
|
|
|
|
#ifdef MOZ_XUL
|
2009-12-10 23:37:40 -08:00
|
|
|
PL_DHashTableFinish(&mXULTreeRules);
|
2010-06-18 09:23:05 -07:00
|
|
|
#endif
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
|
2009-12-10 23:37:40 -08:00
|
|
|
delete mPseudoElementRuleHashes[i];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
RuleHash mRuleHash;
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleHash*
|
|
|
|
mPseudoElementRuleHashes[nsCSSPseudoElements::ePseudo_PseudoElementCount];
|
2011-12-05 20:58:15 -08:00
|
|
|
nsTArray<nsCSSRuleProcessor::StateSelector> mStateSelectors;
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates mSelectorDocumentStates;
|
2010-06-18 09:23:05 -07:00
|
|
|
PLDHashTable mClassSelectors;
|
2011-04-12 19:57:48 -07:00
|
|
|
PLDHashTable mIdSelectors;
|
2010-06-18 09:23:05 -07:00
|
|
|
nsTArray<nsCSSSelector*> mPossiblyNegatedClassSelectors;
|
2011-04-12 19:57:48 -07:00
|
|
|
nsTArray<nsCSSSelector*> mPossiblyNegatedIDSelectors;
|
2009-02-03 06:42:18 -08:00
|
|
|
PLDHashTable mAttributeSelectors;
|
2009-12-10 23:37:40 -08:00
|
|
|
PLDHashTable mAnonBoxRules;
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
PLDHashTable mXULTreeRules;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-26 19:50:16 -08:00
|
|
|
nsTArray<nsFontFaceRuleContainer> mFontFaceRules;
|
2011-04-11 23:18:43 -07:00
|
|
|
nsTArray<nsCSSKeyframesRule*> mKeyframesRules;
|
2012-08-31 14:21:28 -07:00
|
|
|
nsTArray<nsCSSPageRule*> mPageRules;
|
2008-11-25 15:22:38 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Looks up or creates the appropriate list in |mAttributeSelectors|.
|
|
|
|
// Returns null only on allocation failure.
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*>* AttributeListFor(nsIAtom* aAttribute);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey mCacheKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleCascadeData* mNext; // for a different medium
|
2009-12-10 23:37:40 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool mQuirksMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
static size_t
|
2011-12-15 14:59:53 -08:00
|
|
|
SizeOfSelectorsEntry(PLDHashEntryHdr* aHdr, nsMallocSizeOfFun aMallocSizeOf, void *)
|
2011-08-02 13:21:52 -07:00
|
|
|
{
|
2011-12-08 21:01:52 -08:00
|
|
|
AtomSelectorEntry* entry = static_cast<AtomSelectorEntry*>(aHdr);
|
2011-12-15 14:59:53 -08:00
|
|
|
return entry->mSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t
|
|
|
|
RuleCascadeData::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-02 13:21:52 -07:00
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
n += mRuleHash.SizeOfExcludingThis(aMallocSizeOf);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
|
2011-08-02 13:21:52 -07:00
|
|
|
if (mPseudoElementRuleHashes[i])
|
2011-12-08 21:01:52 -08:00
|
|
|
n += mPseudoElementRuleHashes[i]->SizeOfIncludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
}
|
|
|
|
|
2011-12-15 14:59:53 -08:00
|
|
|
n += mStateSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mIdSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mClassSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-15 14:59:53 -08:00
|
|
|
n += mPossiblyNegatedClassSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mPossiblyNegatedIDSelectors.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mAttributeSelectors,
|
|
|
|
SizeOfSelectorsEntry, aMallocSizeOf);
|
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mAnonBoxRules,
|
|
|
|
SizeOfRuleHashTableEntry, aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
#ifdef MOZ_XUL
|
2011-12-08 21:01:52 -08:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mXULTreeRules,
|
|
|
|
SizeOfRuleHashTableEntry, aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
#endif
|
|
|
|
|
2011-12-15 14:59:53 -08:00
|
|
|
n += mFontFaceRules.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mKeyframesRules.SizeOfExcludingThis(aMallocSizeOf);
|
2012-08-31 14:21:28 -07:00
|
|
|
n += mPageRules.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*>*
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleCascadeData::AttributeListFor(nsIAtom* aAttribute)
|
|
|
|
{
|
2011-08-03 11:32:32 -07:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&mAttributeSelectors, aAttribute,
|
|
|
|
PL_DHASH_ADD));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-08-03 11:32:32 -07:00
|
|
|
return &entry->mSelectors;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style rule processor implementation
|
|
|
|
//
|
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aSheetType)
|
2008-07-26 09:14:48 -07:00
|
|
|
: mSheets(aSheets)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mRuleCascades(nullptr)
|
|
|
|
, mLastPresContext(nullptr)
|
2008-11-26 19:50:16 -08:00
|
|
|
, mSheetType(aSheetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-11 13:41:47 -07:00
|
|
|
for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mSheets[i]->AddRuleProcessor(this);
|
2010-05-11 13:41:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSRuleProcessor::~nsCSSRuleProcessor()
|
|
|
|
{
|
2010-05-11 13:41:47 -07:00
|
|
|
for (sheet_array_type::size_type i = mSheets.Length(); i-- != 0; ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mSheets[i]->DropRuleProcessor(this);
|
2010-05-11 13:41:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mSheets.Clear();
|
|
|
|
ClearRuleCascades();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsCSSRuleProcessor, nsIStyleRuleProcessor)
|
|
|
|
|
2010-04-07 10:29:10 -07:00
|
|
|
/* static */ nsresult
|
2008-10-21 00:15:03 -07:00
|
|
|
nsCSSRuleProcessor::Startup()
|
|
|
|
{
|
2011-05-28 16:42:57 -07:00
|
|
|
Preferences::AddBoolVarCache(&gSupportVisitedPseudo, VISITED_PSEUDO_PREF,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2010-04-07 10:29:10 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-10-21 00:15:03 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-11-19 12:08:20 -08:00
|
|
|
InitSystemMetrics()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!sSystemMetrics, "already initialized");
|
|
|
|
|
|
|
|
sSystemMetrics = new nsTArray< nsCOMPtr<nsIAtom> >;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(sSystemMetrics, false);
|
2007-11-19 12:08:20 -08:00
|
|
|
|
2009-10-17 07:31:47 -07:00
|
|
|
/***************************************************************************
|
|
|
|
* ANY METRICS ADDED HERE SHOULD ALSO BE ADDED AS MEDIA QUERIES IN *
|
|
|
|
* nsMediaFeatures.cpp *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t metricResult =
|
2011-09-08 19:27:12 -07:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollArrowStyle);
|
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_StartBackward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_backward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
2011-09-08 19:27:12 -07:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_StartForward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_forward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
2011-09-08 19:27:12 -07:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_EndBackward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_backward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
2011-09-08 19:27:12 -07:00
|
|
|
if (metricResult & LookAndFeel::eScrollArrow_EndForward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_forward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollSliderStyle);
|
|
|
|
if (metricResult != LookAndFeel::eScrollThumbStyle_Normal) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_thumb_proportional);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ImagesInMenus);
|
2008-02-20 02:12:33 -08:00
|
|
|
if (metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_menus);
|
2008-02-20 02:12:33 -08:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ImagesInButtons);
|
2009-10-06 07:20:59 -07:00
|
|
|
if (metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_buttons);
|
2009-10-06 07:20:59 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
metricResult =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_MenuBarDrag);
|
2010-07-17 01:11:54 -07:00
|
|
|
if (metricResult) {
|
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::menubar_drag);
|
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
nsresult rv =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsDefaultTheme, &metricResult);
|
2008-04-08 11:36:53 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_default_theme);
|
2008-04-08 11:36:53 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MacGraphiteTheme, &metricResult);
|
2008-09-17 09:23:58 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::mac_graphite_theme);
|
2008-09-17 09:23:58 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MacLionTheme, &metricResult);
|
2011-08-18 01:40:27 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::mac_lion_theme);
|
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_DWMCompositor, &metricResult);
|
2008-08-12 17:44:14 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_compositor);
|
2008-08-12 17:44:14 -07:00
|
|
|
}
|
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsClassic, &metricResult);
|
2008-08-18 10:33:08 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_classic);
|
2008-08-18 10:33:08 -07:00
|
|
|
}
|
2009-08-10 19:59:06 -07:00
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_TouchEnabled, &metricResult);
|
2009-08-10 19:59:06 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::touch_enabled);
|
2009-08-10 19:59:06 -07:00
|
|
|
}
|
2008-08-18 10:33:08 -07:00
|
|
|
|
2011-09-08 19:27:12 -07:00
|
|
|
rv = LookAndFeel::GetInt(LookAndFeel::eIntID_MaemoClassic, &metricResult);
|
2009-10-04 18:31:26 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::maemo_classic);
|
2009-10-04 18:31:26 -07:00
|
|
|
}
|
|
|
|
|
2010-10-09 13:53:45 -07:00
|
|
|
#ifdef XP_WIN
|
2011-09-08 19:27:12 -07:00
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_WindowsThemeIdentifier,
|
|
|
|
&metricResult))) {
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSRuleProcessor::SetWindowsThemeIdentifier(static_cast<uint8_t>(metricResult));
|
2010-10-09 13:53:45 -07:00
|
|
|
switch(metricResult) {
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_Aero:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_aero);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaBlue:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_blue);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaOlive:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_olive);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_LunaSilver:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_luna_silver);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_Royale:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_royale);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_Zune:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_zune);
|
|
|
|
break;
|
2011-09-08 19:27:12 -07:00
|
|
|
case LookAndFeel::eWindowsTheme_Generic:
|
2010-10-09 13:53:45 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::windows_theme_generic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2008-08-05 13:02:43 -07:00
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics()
|
2007-11-19 12:08:20 -08:00
|
|
|
{
|
|
|
|
delete sSystemMetrics;
|
2012-07-30 07:20:58 -07:00
|
|
|
sSystemMetrics = nullptr;
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
2010-04-07 10:29:10 -07:00
|
|
|
/* static */ void
|
|
|
|
nsCSSRuleProcessor::Shutdown()
|
|
|
|
{
|
|
|
|
FreeSystemMetrics();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2009-10-15 17:23:19 -07:00
|
|
|
nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
|
|
|
|
{
|
|
|
|
if (!sSystemMetrics && !InitSystemMetrics()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-15 17:23:19 -07:00
|
|
|
}
|
|
|
|
return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
|
|
|
|
}
|
|
|
|
|
2010-10-09 13:53:45 -07:00
|
|
|
#ifdef XP_WIN
|
2012-08-22 08:56:38 -07:00
|
|
|
/* static */ uint8_t
|
2010-10-09 13:53:45 -07:00
|
|
|
nsCSSRuleProcessor::GetWindowsThemeIdentifier()
|
|
|
|
{
|
|
|
|
if (!sSystemMetrics)
|
|
|
|
InitSystemMetrics();
|
|
|
|
return sWinThemeId;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-29 10:29:21 -07:00
|
|
|
/* static */
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2012-03-29 23:16:22 -07:00
|
|
|
nsCSSRuleProcessor::GetContentState(Element* aElement, const TreeMatchContext& aTreeMatchContext)
|
2009-12-10 14:36:03 -08:00
|
|
|
{
|
2012-02-08 10:42:38 -08:00
|
|
|
nsEventStates state = aElement->StyleState();
|
2011-03-29 10:29:21 -07: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 02:43:43 -07:00
|
|
|
if (state.HasState(NS_EVENT_STATE_VISITED) &&
|
|
|
|
(!gSupportVisitedPseudo ||
|
|
|
|
aElement->OwnerDoc()->IsBeingUsedAsImage() ||
|
2012-03-29 23:16:22 -07:00
|
|
|
aTreeMatchContext.mUsingPrivateBrowsing)) {
|
2011-03-29 10:29:21 -07:00
|
|
|
state &= ~NS_EVENT_STATE_VISITED;
|
|
|
|
state |= NS_EVENT_STATE_UNVISITED;
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
return state;
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
|
|
|
|
2011-03-29 10:29:21 -07:00
|
|
|
/* static */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSRuleProcessor::IsLink(Element* aElement)
|
2009-12-10 14:36:03 -08:00
|
|
|
{
|
2012-02-08 10:42:38 -08:00
|
|
|
nsEventStates state = aElement->StyleState();
|
2010-10-20 04:26:32 -07:00
|
|
|
return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
|
|
|
|
2011-03-29 10:29:21 -07:00
|
|
|
/* static */
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2011-03-29 10:29:21 -07:00
|
|
|
nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
2011-11-14 10:10:22 -08:00
|
|
|
Element* aElement,
|
2012-03-29 23:16:22 -07:00
|
|
|
const TreeMatchContext& aTreeMatchContext,
|
2010-04-02 18:58:27 -07:00
|
|
|
nsRuleWalker::VisitedHandlingType aVisitedHandling,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsRelevantLink)
|
2010-04-02 18:58:27 -07:00
|
|
|
{
|
2012-03-29 23:16:22 -07:00
|
|
|
nsEventStates contentState = GetContentState(aElement, aTreeMatchContext);
|
2010-10-20 04:26:32 -07:00
|
|
|
if (contentState.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) {
|
2011-03-29 10:29:21 -07:00
|
|
|
NS_ABORT_IF_FALSE(IsLink(aElement), "IsLink() should match state");
|
2010-10-20 04:26:32 -07:00
|
|
|
contentState &= ~(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
|
2010-04-02 18:58:27 -07: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-02 18:58:26 -07: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.
|
|
|
|
//
|
2012-08-09 20:37:58 -07:00
|
|
|
// NOTE: For |mStateMask| to work correctly, it's important that any
|
2010-04-02 18:58:26 -07:00
|
|
|
// 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 04:26:32 -07:00
|
|
|
const nsEventStates mStateMask;
|
2010-04-02 18:58:26 -07:00
|
|
|
|
2010-04-02 18:58:26 -07: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-28 23:19:26 -07:00
|
|
|
const bool mIsRelevantLink;
|
2010-04-02 18:58:26 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NodeMatchContext(nsEventStates aStateMask, bool aIsRelevantLink)
|
2010-04-02 18:58:26 -07:00
|
|
|
: mStateMask(aStateMask)
|
2010-04-02 18:58:26 -07:00
|
|
|
, mIsRelevantLink(aIsRelevantLink)
|
2010-04-02 18:58:26 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ValueIncludes(const nsSubstring& aValueList,
|
2007-03-22 10:30:00 -07: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-10 17:27:00 -07:00
|
|
|
while (p != p_end && nsContentUtils::IsHTMLWhitespace(*p))
|
2007-03-22 10:30:00 -07:00
|
|
|
++p;
|
|
|
|
|
|
|
|
const PRUnichar *val_start = p;
|
|
|
|
|
|
|
|
// look for space or end
|
2008-06-10 17:27:00 -07:00
|
|
|
while (p != p_end && !nsContentUtils::IsHTMLWhitespace(*p))
|
2007-03-22 10:30:00 -07:00
|
|
|
++p;
|
|
|
|
|
|
|
|
const PRUnichar *val_end = p;
|
|
|
|
|
|
|
|
if (val_start < val_end &&
|
|
|
|
aValue.Equals(Substring(val_start, val_end), aComparator))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
++p; // we know the next character is not whitespace
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether we should apply a "global" (i.e., universal-tag)
|
|
|
|
// selector for event states in quirks mode. Note that
|
2011-03-29 10:29:21 -07:00
|
|
|
// |IsLink()| is checked separately by the caller, so we return
|
2007-03-22 10:30:00 -07:00
|
|
|
// false for |nsGkAtoms::a|, which here means a named anchor.
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool IsQuirkEventSensitive(nsIAtom *aContentTag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
return bool ((nsGkAtoms::button == aContentTag) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(nsGkAtoms::img == aContentTag) ||
|
|
|
|
(nsGkAtoms::input == aContentTag) ||
|
|
|
|
(nsGkAtoms::label == aContentTag) ||
|
|
|
|
(nsGkAtoms::select == aContentTag) ||
|
|
|
|
(nsGkAtoms::textarea == aContentTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2011-11-14 10:10:22 -08:00
|
|
|
IsSignificantChild(nsIContent* aChild, bool aTextIsSignificant,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aWhitespaceIsSignificant)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-18 22:17:07 -08:00
|
|
|
return nsStyleUtil::IsSignificantChild(aChild, aTextIsSignificant,
|
|
|
|
aWhitespaceIsSignificant);
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
static bool AttrMatchesValue(const nsAttrSelector* aAttrSelector,
|
|
|
|
const nsString& aValue, bool isHTML)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aAttrSelector, "Must have an attribute selector");
|
2008-06-10 17:27:00 -07: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 07:59:28 -07:00
|
|
|
return false;
|
2008-06-10 17:27:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsDefaultStringComparator defaultComparator;
|
2010-08-02 15:19:04 -07:00
|
|
|
const nsASCIICaseInsensitiveStringComparator ciComparator;
|
2009-09-28 23:07:45 -07:00
|
|
|
const nsStringComparator& comparator =
|
|
|
|
(aAttrSelector->mCaseSensitive || !isHTML)
|
2007-07-08 00:08:04 -07:00
|
|
|
? static_cast<const nsStringComparator&>(defaultComparator)
|
|
|
|
: static_cast<const nsStringComparator&>(ciComparator);
|
2009-09-28 23:07:45 -07:00
|
|
|
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2011-11-14 10:10:22 -08:00
|
|
|
edgeChildMatches(Element* aElement, TreeMatchContext& aTreeMatchContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool checkFirst, bool checkLast)
|
2009-12-10 23:37:41 -08:00
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-10 23:37:41 -08:00
|
|
|
if (!parent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2009-12-10 23:37:41 -08:00
|
|
|
|
|
|
|
return (!checkFirst ||
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 07:59:28 -07:00
|
|
|
GetNthIndex(aElement, false, false, true) == 1) &&
|
2009-12-10 23:37:41 -08:00
|
|
|
(!checkLast ||
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 07:59:28 -07:00
|
|
|
GetNthIndex(aElement, false, true, true) == 1);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2011-11-14 10:10:22 -08:00
|
|
|
nthChildGenericMatches(Element* aElement,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-11-14 10:10:22 -08:00
|
|
|
nsPseudoClassList* pseudoClass,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOfType, bool isFromEnd)
|
2009-12-10 23:37:41 -08:00
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-10 23:37:41 -08:00
|
|
|
if (!parent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-10 23:37:41 -08:00
|
|
|
if (isFromEnd)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2009-12-10 23:37:41 -08:00
|
|
|
else
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t index = aTreeMatchContext.mNthIndexCache.
|
2011-10-17 07:59:28 -07:00
|
|
|
GetNthIndex(aElement, isOfType, isFromEnd, false);
|
2009-12-10 23:37:41 -08:00
|
|
|
if (index <= 0) {
|
|
|
|
// Node is anonymous content (not really a child of its parent).
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t a = pseudoClass->u.mNumbers[0];
|
|
|
|
const int32_t b = pseudoClass->u.mNumbers[1];
|
2009-12-10 23:37:41 -08:00
|
|
|
// 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.
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t n = (index - b) / a;
|
2009-12-10 23:37:41 -08:00
|
|
|
return n >= 0 && (a * n == index - b);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2011-11-14 10:10:22 -08:00
|
|
|
edgeOfTypeMatches(Element* aElement, TreeMatchContext& aTreeMatchContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool checkFirst, bool checkLast)
|
2009-12-10 23:37:41 -08:00
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2009-12-10 23:37:41 -08:00
|
|
|
if (!parent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-10 23:37:41 -08:00
|
|
|
if (checkLast)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2009-12-10 23:37:41 -08:00
|
|
|
else
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (!checkFirst ||
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 07:59:28 -07:00
|
|
|
GetNthIndex(aElement, true, false, true) == 1) &&
|
2009-12-10 23:37:41 -08:00
|
|
|
(!checkLast ||
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.mNthIndexCache.
|
2011-10-17 07:59:28 -07:00
|
|
|
GetNthIndex(aElement, true, true, true) == 1);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2011-11-14 10:10:22 -08:00
|
|
|
checkGenericEmptyMatches(Element* aElement,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isWhitespaceSignificant)
|
2009-12-10 23:37:41 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *child = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = -1;
|
2009-12-10 23:37:41 -08:00
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 10:10:22 -08:00
|
|
|
aElement->SetFlags(NODE_HAS_EMPTY_SELECTOR);
|
2009-12-10 23:37:41 -08:00
|
|
|
|
|
|
|
do {
|
2011-03-29 10:29:21 -07:00
|
|
|
child = aElement->GetChildAt(++index);
|
2009-12-10 23:37:41 -08:00
|
|
|
// stop at first non-comment (and non-whitespace for
|
|
|
|
// :-moz-only-whitespace) node
|
2011-10-17 07:59:28 -07:00
|
|
|
} while (child && !IsSignificantChild(child, true, isWhitespaceSignificant));
|
2012-07-30 07:20:58 -07:00
|
|
|
return (child == nullptr);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
2012-08-09 20:37:58 -07:00
|
|
|
// Arrays of the states that are relevant for various pseudoclasses.
|
|
|
|
static const nsEventStates sPseudoClassStateDependences[] = {
|
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value) \
|
|
|
|
nsEventStates(),
|
|
|
|
#define CSS_STATE_DEPENDENT_PSEUDO_CLASS(_name, _value, _states) \
|
|
|
|
_states,
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_STATE_DEPENDENT_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.
|
|
|
|
nsEventStates(),
|
|
|
|
nsEventStates()
|
|
|
|
};
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
static const nsEventStates sPseudoClassStates[] = {
|
2009-12-10 23:37:41 -08:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value) \
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates(),
|
|
|
|
#define CSS_STATE_PSEUDO_CLASS(_name, _value, _states) \
|
|
|
|
_states,
|
2009-12-10 23:37:41 -08: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 04:26:32 -07:00
|
|
|
nsEventStates(),
|
|
|
|
nsEventStates()
|
2009-12-10 23:37:41 -08:00
|
|
|
};
|
2012-02-23 08:19:00 -08:00
|
|
|
MOZ_STATIC_ASSERT(NS_ARRAY_LENGTH(sPseudoClassStates) ==
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1,
|
|
|
|
"ePseudoClass_NotPseudoClass is no longer at the end of"
|
|
|
|
"sPseudoClassStates");
|
2009-12-10 23:37:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2012-08-09 20:37:58 -07:00
|
|
|
// because of aNodeMatchContent.mStateMask
|
2011-11-14 10:10:22 -08:00
|
|
|
static bool SelectorMatches(Element* aElement,
|
|
|
|
nsCSSSelector* aSelector,
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext& aNodeMatchContext,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2012-07-30 07:20:58 -07:00
|
|
|
bool* const aDependence = nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
{
|
2009-12-10 23:37:41 -08:00
|
|
|
NS_PRECONDITION(!aSelector->IsPseudoElement(),
|
|
|
|
"Pseudo-element snuck into SelectorMatches?");
|
2010-04-02 18:58:26 -07: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");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// namespace/tag match
|
2009-08-01 08:53:40 -07:00
|
|
|
// optimization : bail out early if we can
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((kNameSpaceID_Unknown != aSelector->mNameSpace &&
|
2011-03-29 10:29:21 -07:00
|
|
|
aElement->GetNameSpaceID() != aSelector->mNameSpace))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2011-03-29 10:29:20 -07:00
|
|
|
if (aSelector->mLowercaseTag) {
|
|
|
|
nsIAtom* selectorTag =
|
|
|
|
(aTreeMatchContext.mIsHTMLDocument && aElement->IsHTML()) ?
|
|
|
|
aSelector->mLowercaseTag : aSelector->mCasedTag;
|
2011-03-29 10:29:21 -07:00
|
|
|
if (selectorTag != aElement->Tag()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-03-29 10:29:20 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
nsAtomList* IDList = aSelector->mIDList;
|
2009-12-10 14:36:02 -08:00
|
|
|
if (IDList) {
|
2011-03-29 10:29:21 -07:00
|
|
|
nsIAtom* id = aElement->GetID();
|
|
|
|
if (id) {
|
2009-12-10 14:36:02 -08:00
|
|
|
// case sensitivity: bug 93371
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool isCaseSensitive =
|
2011-03-29 10:29:20 -07:00
|
|
|
aTreeMatchContext.mCompatMode != eCompatibility_NavQuirks;
|
2009-12-10 14:36:02 -08:00
|
|
|
|
|
|
|
if (isCaseSensitive) {
|
|
|
|
do {
|
2011-03-29 10:29:21 -07:00
|
|
|
if (IDList->mAtom != id) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
} else {
|
2010-03-08 07:45:00 -08: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 10:29:21 -07:00
|
|
|
nsDependentAtomString id1Str(id);
|
2009-12-10 14:36:02 -08:00
|
|
|
do {
|
2010-03-08 07:45:00 -08:00
|
|
|
if (!nsContentUtils::EqualsIgnoreASCIICase(id1Str,
|
|
|
|
nsDependentAtomString(IDList->mAtom))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Element has no id but we have an id selector
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
nsAtomList* classList = aSelector->mClassList;
|
2009-12-10 14:36:02 -08:00
|
|
|
if (classList) {
|
|
|
|
// test for class match
|
2011-03-29 10:29:21 -07:00
|
|
|
const nsAttrValue *elementClasses = aElement->GetClasses();
|
2009-12-10 14:36:03 -08:00
|
|
|
if (!elementClasses) {
|
|
|
|
// Element has no classes but we have a class selector
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
// case sensitivity: bug 93371
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool isCaseSensitive =
|
2011-03-29 10:29:20 -07:00
|
|
|
aTreeMatchContext.mCompatMode != eCompatibility_NavQuirks;
|
2009-12-10 14:36:02 -08:00
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
while (classList) {
|
|
|
|
if (!elementClasses->Contains(classList->mAtom,
|
|
|
|
isCaseSensitive ?
|
|
|
|
eCaseMatters : eIgnoreCase)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
2009-12-10 14:36:03 -08:00
|
|
|
classList = classList->mNext;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const bool isNegated = (aDependence != nullptr);
|
2008-02-18 22:17:07 -08: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 04:26:32 -07:00
|
|
|
NS_ASSERTION(aNodeMatchContext.mStateMask.IsEmpty() ||
|
2010-04-02 18:58:26 -07:00
|
|
|
!aTreeMatchContext.mForStyling,
|
2010-04-02 18:58:26 -07:00
|
|
|
"mForStyling must be false if we're just testing for "
|
2009-12-10 14:36:03 -08:00
|
|
|
"state-dependence");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// test for pseudo class match
|
2011-11-14 10:10:22 -08:00
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector->mPseudoClassList;
|
2009-12-10 23:37:41 -08:00
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates statesToCheck = sPseudoClassStates[pseudoClass->mType];
|
|
|
|
if (statesToCheck.IsEmpty()) {
|
2010-04-26 13:27:01 -07: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 07:59:28 -07:00
|
|
|
if (!checkGenericEmptyMatches(aElement, aTreeMatchContext, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozOnlyWhitespace:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!checkGenericEmptyMatches(aElement, aTreeMatchContext, false)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozEmptyExceptChildrenWithLocalname:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
NS_ASSERTION(pseudoClass->u.mString, "Must have string!");
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *child = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = -1;
|
2010-04-26 13:27:01 -07:00
|
|
|
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2010-05-14 22:01:45 -07: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 10:10:22 -08:00
|
|
|
aElement->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
2010-04-26 13:27:01 -07:00
|
|
|
do {
|
2011-03-29 10:29:21 -07:00
|
|
|
child = aElement->GetChildAt(++index);
|
2010-04-26 13:27:01 -07:00
|
|
|
} while (child &&
|
2011-10-17 07:59:28 -07:00
|
|
|
(!IsSignificantChild(child, true, false) ||
|
2011-03-29 10:29:21 -07:00
|
|
|
(child->GetNameSpaceID() == aElement->GetNameSpaceID() &&
|
2011-11-14 10:10:22 -08:00
|
|
|
child->Tag()->Equals(nsDependentString(pseudoClass->u.mString)))));
|
2012-07-30 07:20:58 -07:00
|
|
|
if (child != nullptr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lang:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != pseudoClass->u.mString, "null lang parameter");
|
2011-11-14 10:10:22 -08:00
|
|
|
if (!pseudoClass->u.mString || !*pseudoClass->u.mString) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-26 13:27:01 -07:00
|
|
|
|
2011-03-29 10:29:21 -07: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 12:12:45 -07:00
|
|
|
aElement->GetLang(language);
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!language.IsEmpty()) {
|
|
|
|
if (!nsStyleUtil::DashMatchCompare(language,
|
2011-11-14 10:10:22 -08:00
|
|
|
nsDependentString(pseudoClass->u.mString),
|
2011-03-29 10:29:21 -07:00
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-03-29 10:29:21 -07:00
|
|
|
}
|
|
|
|
// This pseudo-class matched; move on to the next thing
|
|
|
|
break;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIDocument* doc = aTreeMatchContext.mDocument;
|
2011-03-29 10:29:21 -07: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 10:10:22 -08:00
|
|
|
nsDependentString langString(pseudoClass->u.mString);
|
2011-03-29 10:29:21 -07:00
|
|
|
language.StripWhitespace();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t begin = 0;
|
|
|
|
int32_t len = language.Length();
|
2011-03-29 10:29:21 -07:00
|
|
|
while (begin < len) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t end = language.FindChar(PRUnichar(','), begin);
|
2011-03-29 10:29:21 -07:00
|
|
|
if (end == kNotFound) {
|
|
|
|
end = len;
|
|
|
|
}
|
|
|
|
if (nsStyleUtil::DashMatchCompare(Substring(language, begin,
|
|
|
|
end-begin),
|
|
|
|
langString,
|
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
begin = end + 1;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (begin < len) {
|
|
|
|
// This pseudo-class matched
|
2010-04-26 13:27:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-03-29 10:29:21 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-04-26 13:27:01 -07:00
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozBoundElement:
|
2011-03-29 10:29:21 -07:00
|
|
|
if (aTreeMatchContext.mScopedRoot != aElement) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_root:
|
2012-12-04 20:15:47 -08:00
|
|
|
if (aElement != aElement->OwnerDoc()->GetRootElement()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_any:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelectorList *l;
|
2010-04-26 13:27:01 -07:00
|
|
|
for (l = pseudoClass->u.mSelectors; l; l = l->mNext) {
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelector *s = l->mSelectors;
|
2010-04-26 13:27:01 -07:00
|
|
|
NS_ABORT_IF_FALSE(!s->mNext && !s->IsPseudoElement(),
|
|
|
|
"parser failed");
|
2011-03-29 10:29:21 -07:00
|
|
|
if (SelectorMatches(aElement, s, aNodeMatchContext,
|
2011-03-29 10:29:20 -07:00
|
|
|
aTreeMatchContext)) {
|
2010-04-26 13:27:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!l) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstChild:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, true, false)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstNode:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *firstNode = nullptr;
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2010-04-26 13:27:01 -07:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2010-04-26 13:27:01 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = -1;
|
2010-04-26 13:27:01 -07:00
|
|
|
do {
|
|
|
|
firstNode = parent->GetChildAt(++index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (firstNode &&
|
2011-10-17 07:59:28 -07:00
|
|
|
!IsSignificantChild(firstNode, true, false));
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (aElement != firstNode) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastChild:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, false, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastNode:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *lastNode = nullptr;
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *parent = aElement->GetParent();
|
2010-04-26 13:27:01 -07:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
2010-04-26 13:27:01 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index = parent->GetChildCount();
|
2010-04-26 13:27:01 -07:00
|
|
|
do {
|
|
|
|
lastNode = parent->GetChildAt(--index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (lastNode &&
|
2011-10-17 07:59:28 -07:00
|
|
|
!IsSignificantChild(lastNode, true, false));
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (aElement != lastNode) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyChild:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeChildMatches(aElement, aTreeMatchContext, true, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstOfType:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, true, false)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastOfType:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, false, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyOfType:
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!edgeOfTypeMatches(aElement, aTreeMatchContext, true, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthChild:
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 07:59:28 -07:00
|
|
|
false, false)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastChild:
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 07:59:28 -07:00
|
|
|
false, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthOfType:
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, false)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastOfType:
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!nthChildGenericMatches(aElement, aTreeMatchContext, pseudoClass,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, true)) {
|
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozIsHTML:
|
2011-03-29 10:29:20 -07:00
|
|
|
if (!aTreeMatchContext.mIsHTMLDocument || !aElement->IsHTML()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozSystemMetric:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCOMPtr<nsIAtom> metric = do_GetAtom(pseudoClass->u.mString);
|
|
|
|
if (!nsCSSRuleProcessor::HasSystemMetric(metric)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLocaleDir:
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool docIsRTL =
|
2011-11-14 10:10:22 -08:00
|
|
|
aTreeMatchContext.mDocument->GetDocumentState().
|
|
|
|
HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
|
2010-04-26 13:27:01 -07:00
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
nsDependentString dirString(pseudoClass->u.mString);
|
|
|
|
NS_ASSERTION(dirString.EqualsLiteral("ltr") ||
|
|
|
|
dirString.EqualsLiteral("rtl"),
|
2010-04-26 13:27:01 -07:00
|
|
|
"invalid value for -moz-locale-dir");
|
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
if (dirString.EqualsLiteral("rtl") != docIsRTL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWTheme:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() <=
|
|
|
|
nsIDocument::Doc_Theme_None) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeBrightText:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() !=
|
|
|
|
nsIDocument::Doc_Theme_Bright) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeDarkText:
|
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
if (aTreeMatchContext.mDocument->GetDocumentLWTheme() !=
|
|
|
|
nsIDocument::Doc_Theme_Dark) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozWindowInactive:
|
2011-11-14 10:10:22 -08:00
|
|
|
if (!aTreeMatchContext.mDocument->GetDocumentState().
|
|
|
|
HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-10-06 21:25:47 -07:00
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozTableBorderNonzero:
|
|
|
|
{
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!aElement->IsHTML(nsGkAtoms::table)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-10-06 21:25:47 -07:00
|
|
|
}
|
2012-11-14 14:10:08 -08:00
|
|
|
const nsAttrValue *val = aElement->GetParsedAttr(nsGkAtoms::border);
|
2010-10-06 21:25:47 -07:00
|
|
|
if (!val ||
|
|
|
|
(val->Type() == nsAttrValue::eInteger &&
|
|
|
|
val->GetIntegerValue() == 0)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-10-06 21:25:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-09 20:37:58 -07:00
|
|
|
case nsCSSPseudoClasses::ePseudoClass_dir:
|
|
|
|
{
|
|
|
|
if (aDependence) {
|
|
|
|
nsEventStates states
|
|
|
|
= sPseudoClassStateDependences[pseudoClass->mType];
|
|
|
|
if (aNodeMatchContext.mStateMask.HasAtLeastOneOfStates(states)) {
|
|
|
|
*aDependence = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we only had to consider HTML, directionality would be exclusively
|
|
|
|
// LTR or RTL, and this could be just
|
|
|
|
//
|
|
|
|
// if (dirString.EqualsLiteral("rtl") !=
|
|
|
|
// aElement->StyleState().HasState(NS_EVENT_STATE_RTL)
|
|
|
|
//
|
|
|
|
// However, in markup languages where there is no direction attribute
|
2012-09-29 13:41:10 -07:00
|
|
|
// we have to consider the possibility that neither -moz-dir(rtl) nor
|
|
|
|
// -moz-dir(ltr) matches.
|
2012-08-09 20:37:58 -07:00
|
|
|
nsEventStates state = aElement->StyleState();
|
|
|
|
bool elementIsRTL = state.HasState(NS_EVENT_STATE_RTL);
|
|
|
|
bool elementIsLTR = state.HasState(NS_EVENT_STATE_LTR);
|
|
|
|
nsDependentString dirString(pseudoClass->u.mString);
|
|
|
|
|
|
|
|
if ((dirString.EqualsLiteral("rtl") && !elementIsRTL) ||
|
|
|
|
(dirString.EqualsLiteral("ltr") && !elementIsLTR)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-12-04 20:15:47 -08:00
|
|
|
case nsCSSPseudoClasses::ePseudoClass_scope:
|
|
|
|
if (aElement != aElement->OwnerDoc()->GetRootElement()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-26 13:27:01 -07:00
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "How did that happen?");
|
2010-04-26 13:27:01 -07:00
|
|
|
}
|
2009-12-10 23:37:41 -08:00
|
|
|
} else {
|
2010-04-26 13:27:01 -07:00
|
|
|
// Bit-based pseudo-classes
|
2010-10-20 04:26:32 -07:00
|
|
|
if (statesToCheck.HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE) &&
|
2011-03-29 10:29:20 -07:00
|
|
|
aTreeMatchContext.mCompatMode == eCompatibility_NavQuirks &&
|
2011-04-22 18:36:24 -07:00
|
|
|
// global selector:
|
2009-08-01 08:53:40 -07:00
|
|
|
!aSelector->HasTagSelector() && !aSelector->mIDList &&
|
2011-04-22 18:36:24 -07:00
|
|
|
!aSelector->mClassList && !aSelector->mAttrList &&
|
2007-03-22 10:30:00 -07: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 10:29:21 -07:00
|
|
|
aElement->IsHTML() && !nsCSSRuleProcessor::IsLink(aElement) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
!IsQuirkEventSensitive(aElement->Tag())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// In quirks mode, only make certain elements sensitive to
|
|
|
|
// selectors ":hover" and ":active".
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-03-12 20:54:15 -07: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 04:26:32 -07:00
|
|
|
if (aNodeMatchContext.mStateMask.HasAtLeastOneOfStates(statesToCheck)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDependence)
|
2011-10-17 07:59:28 -07:00
|
|
|
*aDependence = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-03-29 10:29:21 -07:00
|
|
|
nsEventStates contentState =
|
|
|
|
nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
|
|
|
aElement,
|
2012-03-29 23:16:22 -07:00
|
|
|
aTreeMatchContext,
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.VisitedHandling(),
|
2010-10-20 04:26:32 -07:00
|
|
|
aNodeMatchContext.mIsRelevantLink);
|
|
|
|
if (!contentState.HasAtLeastOneOfStates(statesToCheck)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result = true;
|
2009-12-10 23:37:41 -08:00
|
|
|
if (aSelector->mAttrList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// test for attribute match
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t attrCount = aElement->GetAttrCount();
|
2011-03-29 10:29:21 -07:00
|
|
|
if (attrCount == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// if no attributes on the content, no match
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2011-11-14 10:10:22 -08:00
|
|
|
nsAttrSelector* attr = aSelector->mAttrList;
|
2009-09-28 23:07:45 -07:00
|
|
|
nsIAtom* matchAttribute;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHTML =
|
2011-03-29 10:29:20 -07:00
|
|
|
(aTreeMatchContext.mIsHTMLDocument && aElement->IsHTML());
|
|
|
|
matchAttribute = isHTML ? attr->mLowercaseAttr : attr->mCasedAttr;
|
2009-12-10 14:36:03 -08:00
|
|
|
if (attr->mNameSpace == kNameSpaceID_Unknown) {
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
result = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < attrCount; ++i) {
|
2011-03-29 10:29:21 -07:00
|
|
|
const nsAttrName* attrName = aElement->GetAttrNameAt(i);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(attrName, "GetAttrCount lied or GetAttrNameAt failed");
|
2009-09-28 23:07:45 -07:00
|
|
|
if (attrName->LocalName() != matchAttribute) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (attr->mFunction == NS_ATTR_FUNC_SET) {
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasAttr =
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2011-03-29 10:29:21 -07:00
|
|
|
aElement->GetAttr(attrName->NamespaceID(),
|
|
|
|
attrName->LocalName(), value);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hasAttr, "GetAttrNameAt lied");
|
2011-03-29 10:29:20 -07:00
|
|
|
result = AttrMatchesValue(attr, value, isHTML);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point |result| has been set by us
|
2011-10-17 07:59:28 -07:00
|
|
|
// explicitly in this loop. If it's false, we may still match
|
2007-03-22 10:30:00 -07:00
|
|
|
// -- the content may have another attribute with the same name but
|
2011-10-17 07:59:28 -07:00
|
|
|
// in a different namespace. But if it's true, we are done (we
|
2007-03-22 10:30:00 -07:00
|
|
|
// can short-circuit the boolean OR described above).
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr->mFunction == NS_ATTR_FUNC_EQUALS) {
|
|
|
|
result =
|
2011-03-29 10:29:21 -07:00
|
|
|
aElement->
|
2009-09-28 23:07:45 -07:00
|
|
|
AttrValueIs(attr->mNameSpace, matchAttribute, attr->mValue,
|
2011-03-29 10:29:20 -07:00
|
|
|
(!isHTML || attr->mCaseSensitive) ? eCaseMatters
|
|
|
|
: eIgnoreCase);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
else if (!aElement->HasAttr(attr->mNameSpace, matchAttribute)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
result = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (attr->mFunction != NS_ATTR_FUNC_SET) {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasAttr =
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2011-03-29 10:29:21 -07:00
|
|
|
aElement->GetAttr(attr->mNameSpace, matchAttribute, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hasAttr, "HasAttr lied");
|
2011-03-29 10:29:20 -07:00
|
|
|
result = AttrMatchesValue(attr, value, isHTML);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
attr = attr->mNext;
|
|
|
|
} while (attr && result);
|
|
|
|
}
|
|
|
|
}
|
2007-07-26 07:16:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// apply SelectorMatches to the negated selectors in the chain
|
|
|
|
if (!isNegated) {
|
2011-11-14 10:10:22 -08:00
|
|
|
for (nsCSSSelector *negation = aSelector->mNegations;
|
2007-03-22 10:30:00 -07:00
|
|
|
result && negation; negation = negation->mNegations) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dependence = false;
|
2011-03-29 10:29:21 -07:00
|
|
|
result = !SelectorMatches(aElement, negation, aNodeMatchContext,
|
2010-04-02 18:58:26 -07:00
|
|
|
aTreeMatchContext, &dependence);
|
2012-08-09 20:37:58 -07:00
|
|
|
// If the selector does match due to the dependence on
|
|
|
|
// aNodeMatchContext.mStateMask, 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.
|
2007-03-22 10:30:00 -07:00
|
|
|
result = result || dependence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef STATE_CHECK
|
|
|
|
|
|
|
|
// Right now, there are four operators:
|
2010-03-31 11:08:09 -07:00
|
|
|
// ' ', the descendant combinator, is greedy
|
2007-03-22 10:30:00 -07:00
|
|
|
// '~', the indirect adjacent sibling combinator, is greedy
|
|
|
|
// '+' and '>', the direct adjacent sibling and child combinators, are not
|
2010-03-31 11:08:09 -07:00
|
|
|
#define NS_IS_GREEDY_OPERATOR(ch) \
|
|
|
|
((ch) == PRUnichar(' ') || (ch) == PRUnichar('~'))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-14 10:10:22 -08:00
|
|
|
static bool SelectorMatchesTree(Element* aPrevElement,
|
|
|
|
nsCSSSelector* aSelector,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aLookForRelevantLink)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelector* selector = aSelector;
|
|
|
|
Element* prevElement = aPrevElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (selector) { // check compound selectors
|
2010-03-31 11:08:09 -07:00
|
|
|
NS_ASSERTION(!selector->mNext ||
|
|
|
|
selector->mNext->mOperator != PRUnichar(0),
|
|
|
|
"compound selector without combinator");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// for adjacent sibling combinators, the content to test against the
|
|
|
|
// selector is the previous sibling *element*
|
2012-07-30 07:20:58 -07:00
|
|
|
Element* element = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PRUnichar('+') == selector->mOperator ||
|
|
|
|
PRUnichar('~') == selector->mOperator) {
|
2010-04-02 18:58:26 -07:00
|
|
|
// The relevant link must be an ancestor of the node being matched.
|
2011-10-17 07:59:28 -07:00
|
|
|
aLookForRelevantLink = false;
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent* parent = prevElement->GetParent();
|
2011-03-29 10:29:21 -07:00
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
2011-11-14 10:10:22 -08:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2011-03-29 10:29:21 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = parent->IndexOf(prevElement);
|
2011-11-14 10:10:22 -08:00
|
|
|
while (0 <= --index) {
|
|
|
|
nsIContent* content = parent->GetChildAt(index);
|
|
|
|
if (content->IsElement()) {
|
|
|
|
element = content->AsElement();
|
2011-03-29 10:29:21 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
// for descendant combinators and child combinators, the element
|
2007-03-22 10:30:00 -07:00
|
|
|
// to test against is the parent
|
|
|
|
else {
|
2011-11-14 10:10:22 -08:00
|
|
|
nsIContent *content = prevElement->GetParent();
|
2011-03-29 10:29:21 -07:00
|
|
|
// GetParent could return a document fragment; we only want
|
|
|
|
// element parents.
|
|
|
|
if (content && content->IsElement()) {
|
|
|
|
element = content->AsElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!element) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
aLookForRelevantLink &&
|
2011-03-29 10:29:21 -07:00
|
|
|
nsCSSRuleProcessor::IsLink(element));
|
2010-04-02 18:58:26 -07: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 07:59:28 -07:00
|
|
|
aLookForRelevantLink = false;
|
2011-03-29 10:29:21 -07:00
|
|
|
aTreeMatchContext.SetHaveRelevantLink();
|
2010-04-02 18:58:26 -07:00
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (SelectorMatches(element, selector, nodeContext, aTreeMatchContext)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// to avoid greedy matching, we need to recur if this is a
|
2008-03-05 16:06:15 -08: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-20 14:52:47 -07:00
|
|
|
if (NS_IS_GREEDY_OPERATOR(selector->mOperator) &&
|
|
|
|
selector->mNext &&
|
|
|
|
selector->mNext->mOperator != selector->mOperator &&
|
2008-03-05 16:06:15 -08:00
|
|
|
!(selector->mOperator == '~' &&
|
2012-03-12 20:54:14 -07:00
|
|
|
NS_IS_ANCESTOR_OPERATOR(selector->mNext->mOperator))) {
|
2007-03-22 10:30:00 -07: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 10:29:21 -07:00
|
|
|
if (SelectorMatchesTree(element, selector, aTreeMatchContext,
|
|
|
|
aLookForRelevantLink)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
return false; // parent was required to match
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
prevElement = element;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true; // all the selectors matched.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-07 09:45:25 -08:00
|
|
|
static inline
|
2012-03-12 20:54:15 -07:00
|
|
|
void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector,
|
2012-11-14 11:09:01 -08:00
|
|
|
ElementDependentRuleProcessorData* data, NodeMatchContext& nodeContext,
|
2012-03-12 20:54:15 -07:00
|
|
|
AncestorFilter *ancestorFilter)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-02 18:58:26 -07:00
|
|
|
if (nodeContext.mIsRelevantLink) {
|
2011-03-29 10:29:21 -07:00
|
|
|
data->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-02 18:58:26 -07:00
|
|
|
}
|
2012-03-12 20:54:15 -07:00
|
|
|
if (ancestorFilter &&
|
|
|
|
!ancestorFilter->MightHaveMatchingAncestor<RuleValue::eMaxAncestorHashes>(
|
|
|
|
value.mAncestorSelectorHashes)) {
|
|
|
|
// We won't match; nothing else to do here
|
|
|
|
return;
|
|
|
|
}
|
2011-03-29 10:29:21 -07:00
|
|
|
if (SelectorMatches(data->mElement, aSelector, nodeContext,
|
|
|
|
data->mTreeMatchContext)) {
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelector *next = aSelector->mNext;
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!next || SelectorMatchesTree(data->mElement, next,
|
|
|
|
data->mTreeMatchContext,
|
2011-03-29 10:29:21 -07:00
|
|
|
!nodeContext.mIsRelevantLink)) {
|
2012-03-12 20:54:15 -07:00
|
|
|
css::StyleRule *rule = value.mRule;
|
|
|
|
rule->RuleMatched();
|
|
|
|
data->mRuleWalker->Forward(rule);
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsStyleSet will deal with the !important rule
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSRuleProcessor::RulesMatching(ElementRuleProcessorData *aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
2011-03-29 10:29:21 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2011-03-29 10:29:21 -07:00
|
|
|
cascade->mRuleHash.EnumerateAllRules(aData->mElement, aData, nodeContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSRuleProcessor::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
RuleHash* ruleHash = cascade->mPseudoElementRuleHashes[aData->mPseudoType];
|
|
|
|
if (ruleHash) {
|
2011-03-29 10:29:21 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2011-03-29 10:29:21 -07:00
|
|
|
ruleHash->EnumerateAllRules(aData->mElement, aData, nodeContext);
|
2009-12-10 23:37:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08: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-02 13:56:09 -07:00
|
|
|
nsTArray<RuleValue>& rules = entry->mRules;
|
|
|
|
for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
|
|
|
|
value != end; ++value) {
|
2009-12-11 08:13:19 -08:00
|
|
|
value->mRule->RuleMatched();
|
2011-05-23 13:45:44 -07:00
|
|
|
aData->mRuleWalker->Forward(value->mRule);
|
2009-12-10 23:37:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSRuleProcessor::RulesMatching(XULTreeRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2009-12-10 23:37:40 -08: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 10:29:21 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(),
|
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2010-07-02 13:56:09 -07:00
|
|
|
nsTArray<RuleValue>& rules = entry->mRules;
|
|
|
|
for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
|
|
|
|
value != end; ++value) {
|
2010-07-30 16:48:57 -07:00
|
|
|
if (aData->mComparator->PseudoMatches(value->mSelector)) {
|
2012-03-12 20:54:15 -07:00
|
|
|
ContentEnumFunc(*value, value->mSelector->mNext, aData, nodeContext,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr);
|
2009-12-10 23:37:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
static inline nsRestyleHint RestyleHintForOp(PRUnichar oper)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-18 09:23:05 -07:00
|
|
|
if (oper == PRUnichar('+') || oper == PRUnichar('~')) {
|
|
|
|
return eRestyle_LaterSiblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oper != PRUnichar(0)) {
|
|
|
|
return eRestyle_Subtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eRestyle_Self;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 17:43:32 -07:00
|
|
|
nsRestyleHint
|
2009-12-11 22:36:34 -08:00
|
|
|
nsCSSRuleProcessor::HasStateDependentStyle(StateRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07: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-05 20:58:15 -08:00
|
|
|
// |ComputeSelectorStateDependence| below determines which selectors are in
|
2007-03-22 10:30:00 -07:00
|
|
|
// |cascade->mStateSelectors|.
|
2010-03-31 17:43:32 -07:00
|
|
|
nsRestyleHint hint = nsRestyleHint(0);
|
2009-02-03 06:42:18 -08:00
|
|
|
if (cascade) {
|
2011-12-05 20:58:15 -08:00
|
|
|
StateSelector *iter = cascade->mStateSelectors.Elements(),
|
|
|
|
*end = iter + cascade->mStateSelectors.Length();
|
2011-10-17 07:59:28 -07:00
|
|
|
NodeMatchContext nodeContext(aData->mStateMask, false);
|
2009-02-03 06:42:18 -08:00
|
|
|
for(; iter != end; ++iter) {
|
2011-12-05 20:58:15 -08:00
|
|
|
nsCSSSelector* selector = iter->mSelector;
|
|
|
|
nsEventStates states = iter->mStates;
|
2009-02-03 06:42:18 -08:00
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
nsRestyleHint possibleChange = RestyleHintForOp(selector->mOperator);
|
2009-02-03 06:42:18 -08:00
|
|
|
|
2009-12-11 22:36:34 -08:00
|
|
|
// If hint already includes all the bits of possibleChange,
|
2009-02-03 06:42:18 -08:00
|
|
|
// don't bother calling SelectorMatches, since even if it returns false
|
2009-12-11 22:36:34 -08:00
|
|
|
// hint won't change.
|
2011-12-05 20:58:15 -08:00
|
|
|
// Also don't bother calling SelectorMatches if none of the
|
|
|
|
// states passed in are relevant here.
|
2009-12-11 22:36:34 -08:00
|
|
|
if ((possibleChange & ~hint) &&
|
2011-12-05 20:58:15 -08:00
|
|
|
states.HasAtLeastOneOfStates(aData->mStateMask) &&
|
2012-05-28 21:17:45 -07:00
|
|
|
// We can optimize away testing selectors that only involve :hover, a
|
|
|
|
// namespace, and a tag name against nodes that don't have the
|
|
|
|
// NODE_HAS_RELEVANT_HOVER_RULES flag: such a selector didn't match
|
|
|
|
// the tag name or namespace the first time around (since the :hover
|
|
|
|
// didn't set the NODE_HAS_RELEVANT_HOVER_RULES flag), so it won't
|
|
|
|
// match it now. Check for our selector only having :hover states, or
|
|
|
|
// the element having the hover rules flag, or the selector having
|
|
|
|
// some sort of non-namespace, non-tagname data in it.
|
|
|
|
(states != NS_EVENT_STATE_HOVER ||
|
|
|
|
aData->mElement->HasFlag(NODE_HAS_RELEVANT_HOVER_RULES) ||
|
|
|
|
selector->mIDList || selector->mClassList ||
|
|
|
|
// We generally expect an mPseudoClassList, since we have a :hover.
|
|
|
|
// The question is whether we have anything else in there.
|
|
|
|
(selector->mPseudoClassList &&
|
|
|
|
(selector->mPseudoClassList->mNext ||
|
|
|
|
selector->mPseudoClassList->mType !=
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_hover)) ||
|
|
|
|
selector->mAttrList || selector->mNegations) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
SelectorMatches(aData->mElement, selector, nodeContext,
|
|
|
|
aData->mTreeMatchContext) &&
|
|
|
|
SelectorMatchesTree(aData->mElement, selector->mNext,
|
|
|
|
aData->mTreeMatchContext,
|
2011-10-17 07:59:28 -07:00
|
|
|
false))
|
2010-04-02 18:58:26 -07:00
|
|
|
{
|
2010-03-31 17:43:32 -07:00
|
|
|
hint = nsRestyleHint(hint | possibleChange);
|
2009-02-03 06:42:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 22:36:34 -08:00
|
|
|
return hint;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-03-17 10:10:57 -07:00
|
|
|
nsCSSRuleProcessor::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
return cascade && cascade->mSelectorDocumentStates.HasAtLeastOneOfStates(aData->mStateMask);
|
2010-03-17 10:10:57 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct AttributeEnumData {
|
|
|
|
AttributeEnumData(AttributeRuleProcessorData *aData)
|
2010-03-31 17:43:32 -07:00
|
|
|
: data(aData), change(nsRestyleHint(0)) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
AttributeRuleProcessorData *data;
|
2010-03-31 17:43:32 -07:00
|
|
|
nsRestyleHint change;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
static void
|
|
|
|
AttributeEnumFunc(nsCSSSelector* aSelector, AttributeEnumData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-03 06:42:18 -08:00
|
|
|
AttributeRuleProcessorData *data = aData->data;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
nsRestyleHint possibleChange = RestyleHintForOp(aSelector->mOperator);
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(), false);
|
2009-02-03 06:42:18 -08:00
|
|
|
if ((possibleChange & ~(aData->change)) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
SelectorMatches(data->mElement, aSelector, nodeContext,
|
|
|
|
data->mTreeMatchContext) &&
|
|
|
|
SelectorMatchesTree(data->mElement, aSelector->mNext,
|
2011-10-17 07:59:28 -07:00
|
|
|
data->mTreeMatchContext, false)) {
|
2010-03-31 17:43:32 -07:00
|
|
|
aData->change = nsRestyleHint(aData->change | possibleChange);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-31 17:43:32 -07:00
|
|
|
nsRestyleHint
|
2009-12-10 14:36:03 -08:00
|
|
|
nsCSSRuleProcessor::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 14:36:03 -08: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.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
AttributeEnumData data(aData);
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
// Don't do our special handling of certain attributes if the attr
|
|
|
|
// hasn't changed yet.
|
|
|
|
if (aData->mAttrHasChanged) {
|
2010-03-17 10:10:57 -07:00
|
|
|
// check for the lwtheme and lwthemetextcolor attribute on root XUL elements
|
|
|
|
if ((aData->mAttribute == nsGkAtoms::lwtheme ||
|
2009-12-10 14:36:03 -08:00
|
|
|
aData->mAttribute == nsGkAtoms::lwthemetextcolor) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
aData->mElement->GetNameSpaceID() == kNameSpaceID_XUL &&
|
2011-10-18 03:53:36 -07:00
|
|
|
aData->mElement == aData->mElement->OwnerDoc()->GetRootElement())
|
2009-12-10 14:36:03 -08:00
|
|
|
{
|
2010-06-18 09:23:05 -07:00
|
|
|
data.change = nsRestyleHint(data.change | eRestyle_Subtree);
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
2011-02-08 13:30:57 -08: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 11:33:53 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
2009-12-10 14:36:03 -08: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cascade) {
|
2010-04-30 06:12:06 -07:00
|
|
|
if (aData->mAttribute == aData->mElement->GetIDAttributeName()) {
|
2011-04-12 19:57:48 -07: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 06:42:18 -08:00
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
if (aData->mAttribute == aData->mElement->GetClassAttributeName()) {
|
2011-03-29 10:29:21 -07:00
|
|
|
const nsAttrValue* elementClasses = aData->mElement->GetClasses();
|
2010-06-18 09:23:05 -07:00
|
|
|
if (elementClasses) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t atomCount = elementClasses->GetAtomCount();
|
|
|
|
for (int32_t i = 0; i < atomCount; ++i) {
|
2010-06-18 09:23:05 -07:00
|
|
|
nsIAtom* curClass = elementClasses->AtomAt(i);
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
2010-06-18 09:23:05 -07: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-19 14:16:38 -07:00
|
|
|
AttributeEnumFunc(*iter, &data);
|
2009-02-03 06:42:18 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-08-03 11:32:32 -07:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mAttributeSelectors,
|
|
|
|
aData->mAttribute, PL_DHASH_LOOKUP));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2011-08-03 11:32:32 -07:00
|
|
|
nsCSSSelector **iter = entry->mSelectors.Elements(),
|
|
|
|
**end = iter + entry->mSelectors.Length();
|
2009-02-03 06:42:18 -08:00
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
AttributeEnumFunc(*iter, &data);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
return data.change;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-07-18 14:20:40 -07:00
|
|
|
nsCSSRuleProcessor::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 09:14:48 -07:00
|
|
|
{
|
|
|
|
RuleCascadeData *old = mRuleCascades;
|
2008-08-06 10:42:56 -07: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-18 14:20:40 -07:00
|
|
|
return (old != mRuleCascades);
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSRuleProcessor::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-01 11:25:20 -07:00
|
|
|
{
|
2011-12-08 21:01:52 -08:00
|
|
|
size_t n = 0;
|
2011-12-15 14:59:53 -08:00
|
|
|
n += mSheets.SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
for (RuleCascadeData* cascade = mRuleCascades; cascade;
|
|
|
|
cascade = cascade->mNext) {
|
2011-12-08 21:01:52 -08:00
|
|
|
n += cascade->SizeOfIncludingThis(aMallocSizeOf);
|
2011-08-02 13:21:52 -07:00
|
|
|
}
|
2011-08-01 11:25:20 -07:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSRuleProcessor::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-08 21:01:52 -08:00
|
|
|
}
|
|
|
|
|
2008-11-25 15:22:38 -08:00
|
|
|
// Append all the currently-active font face rules to aArray. Return
|
|
|
|
// true for success and false for failure.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-11-25 15:22:38 -08:00
|
|
|
nsCSSRuleProcessor::AppendFontFaceRules(
|
|
|
|
nsPresContext *aPresContext,
|
2008-11-26 19:50:16 -08:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& aArray)
|
2008-11-25 15:22:38 -08:00
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
if (!aArray.AppendElements(cascade->mFontFaceRules))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-11-25 15:22:38 -08:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-11-25 15:22:38 -08:00
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
// Append all the currently-active keyframes rules to aArray. Return
|
|
|
|
// true for success and false for failure.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSRuleProcessor::AppendKeyframesRules(
|
|
|
|
nsPresContext *aPresContext,
|
|
|
|
nsTArray<nsCSSKeyframesRule*>& aArray)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
if (!aArray.AppendElements(cascade->mKeyframesRules))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2012-08-31 14:21:28 -07:00
|
|
|
// Append all the currently-active page rules to aArray. Return
|
|
|
|
// true for success and false for failure.
|
|
|
|
bool
|
|
|
|
nsCSSRuleProcessor::AppendPageRules(
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsTArray<nsCSSPageRule*>& aArray)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aPresContext);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
if (!aArray.AppendElements(cascade->mPageRules)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsCSSRuleProcessor::ClearRuleCascades()
|
|
|
|
{
|
2008-11-25 15:22:38 -08: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).
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleCascadeData *data = mRuleCascades;
|
2012-07-30 07:20:58 -07:00
|
|
|
mRuleCascades = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (data) {
|
|
|
|
RuleCascadeData *next = data->mNext;
|
|
|
|
delete data;
|
|
|
|
data = next;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-05 20:58:15 -08: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
inline
|
2011-12-05 20:58:15 -08:00
|
|
|
nsEventStates ComputeSelectorStateDependence(nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-05 20:58:15 -08:00
|
|
|
nsEventStates states;
|
2008-06-02 20:17:35 -07:00
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector.mPseudoClassList;
|
2007-03-22 10:30:00 -07:00
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
2009-12-10 23:37:41 -08:00
|
|
|
// Tree pseudo-elements overload mPseudoClassList for things that
|
|
|
|
// aren't pseudo-classes.
|
|
|
|
if (pseudoClass->mType >= nsCSSPseudoClasses::ePseudoClass_Count) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-09 20:37:58 -07:00
|
|
|
states |= sPseudoClassStateDependences[pseudoClass->mType];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-12-05 20:58:15 -08:00
|
|
|
return states;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-04-23 19:59:47 -07: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 10:42:15 -08: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 07:59:28 -07:00
|
|
|
return false;
|
2011-02-24 10:42:15 -08:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
2010-10-06 21:25:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
|
2011-02-24 10:42:15 -08:00
|
|
|
// Build mStateSelectors.
|
2011-12-05 20:58:15 -08:00
|
|
|
nsEventStates dependentStates = ComputeSelectorStateDependence(*negation);
|
|
|
|
if (!dependentStates.IsEmpty()) {
|
|
|
|
aCascade->mStateSelectors.AppendElement(
|
|
|
|
nsCSSRuleProcessor::StateSelector(dependentStates,
|
|
|
|
aSelectorInTopLevel));
|
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
|
2011-02-24 10:42:15 -08:00
|
|
|
// Build mIDSelectors
|
2011-04-12 19:57:48 -07: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 10:42:15 -08:00
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
|
2011-02-24 10:42:15 -08:00
|
|
|
// Build mClassSelectors
|
|
|
|
if (negation == aSelectorInTopLevel) {
|
|
|
|
for (nsAtomList* curClass = negation->mClassList; curClass;
|
|
|
|
curClass = curClass->mNext) {
|
2011-04-12 19:57:42 -07:00
|
|
|
AtomSelectorEntry *entry =
|
|
|
|
static_cast<AtomSelectorEntry*>(PL_DHashTableOperate(&aCascade->mClassSelectors,
|
|
|
|
curClass->mAtom,
|
|
|
|
PL_DHASH_ADD));
|
2011-02-24 10:42:15 -08:00
|
|
|
if (entry) {
|
|
|
|
entry->mSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
2011-02-24 10:42:15 -08:00
|
|
|
} else if (negation->mClassList) {
|
|
|
|
aCascade->mPossiblyNegatedClassSelectors.AppendElement(aSelectorInTopLevel);
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
|
2011-02-24 10:42:15 -08:00
|
|
|
// Build mAttributeSelectors.
|
|
|
|
for (nsAttrSelector *attr = negation->mAttrList; attr;
|
|
|
|
attr = attr->mNext) {
|
|
|
|
nsTArray<nsCSSSelector*> *array =
|
|
|
|
aCascade->AttributeListFor(attr->mCasedAttr);
|
2010-04-23 19:59:47 -07:00
|
|
|
if (!array) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
2011-02-24 10:42:15 -08:00
|
|
|
if (attr->mLowercaseAttr != attr->mCasedAttr) {
|
|
|
|
array = aCascade->AttributeListFor(attr->mLowercaseAttr);
|
|
|
|
if (!array) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-02-24 10:42:15 -08:00
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
|
2011-02-24 10:42:15 -08: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 07:59:28 -07:00
|
|
|
return false;
|
2011-02-24 10:42:15 -08:00
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-07-02 13:56:09 -07:00
|
|
|
AddRule(RuleSelectorPair* aRuleInfo, RuleCascadeData* aCascade)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleCascadeData * const cascade = aCascade;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Build the rule hash.
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aRuleInfo->mSelector->PseudoType();
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement)) {
|
2010-07-02 13:56:09 -07:00
|
|
|
cascade->mRuleHash.AppendRule(*aRuleInfo);
|
2009-12-10 23:37:40 -08:00
|
|
|
} else if (pseudoType < nsCSSPseudoElements::ePseudo_PseudoElementCount) {
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleHash*& ruleHash = cascade->mPseudoElementRuleHashes[pseudoType];
|
|
|
|
if (!ruleHash) {
|
|
|
|
ruleHash = new RuleHash(cascade->mQuirksMode);
|
|
|
|
if (!ruleHash) {
|
|
|
|
// Out of memory; give up
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-12-10 23:37:40 -08: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-02 13:56:09 -07:00
|
|
|
ruleHash->AppendRule(*aRuleInfo);
|
2009-12-10 23:37:40 -08:00
|
|
|
} else if (pseudoType == nsCSSPseudoElements::ePseudo_AnonBox) {
|
2009-12-10 23:37:40 -08: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-10 23:37:40 -08:00
|
|
|
|
|
|
|
// Index doesn't matter here, since we'll just be walking these
|
|
|
|
// rules in order; just pass 0.
|
2010-07-08 09:50:18 -07:00
|
|
|
AppendRuleToTagTable(&cascade->mAnonBoxRules,
|
|
|
|
aRuleInfo->mSelector->mLowercaseTag,
|
2012-03-13 22:44:13 -07:00
|
|
|
RuleValue(*aRuleInfo, 0, aCascade->mQuirksMode));
|
2009-12-10 23:37:40 -08:00
|
|
|
} else {
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2009-12-10 23:37:40 -08:00
|
|
|
NS_ASSERTION(pseudoType == nsCSSPseudoElements::ePseudo_XULTree,
|
|
|
|
"Unexpected pseudo type");
|
2009-12-10 23:37:40 -08:00
|
|
|
// Index doesn't matter here, since we'll just be walking these
|
|
|
|
// rules in order; just pass 0.
|
2010-07-08 09:50:18 -07:00
|
|
|
AppendRuleToTagTable(&cascade->mXULTreeRules,
|
|
|
|
aRuleInfo->mSelector->mLowercaseTag,
|
2012-03-13 22:44:13 -07:00
|
|
|
RuleValue(*aRuleInfo, 0, aCascade->mQuirksMode));
|
2009-12-10 23:37:40 -08:00
|
|
|
#else
|
|
|
|
NS_NOTREACHED("Unexpected pseudo type");
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2009-12-10 23:37:40 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
for (nsCSSSelector* selector = aRuleInfo->mSelector;
|
2007-03-22 10:30:00 -07:00
|
|
|
selector; selector = selector->mNext) {
|
2009-12-10 23:37:41 -08: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 10:42:15 -08:00
|
|
|
if (!AddSelector(cascade, selector, selector)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-07 22:32:11 -08:00
|
|
|
struct PerWeightDataListItem : public RuleSelectorPair {
|
|
|
|
PerWeightDataListItem(css::StyleRule* aRule, nsCSSSelector* aSelector)
|
|
|
|
: RuleSelectorPair(aRule, aSelector)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mNext(nullptr)
|
2011-12-07 22:32:11 -08:00
|
|
|
{}
|
|
|
|
// 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-14 14:59:20 -08:00
|
|
|
struct PerWeightData {
|
2011-12-07 22:32:11 -08:00
|
|
|
PerWeightData()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mRuleSelectorPairs(nullptr)
|
2011-12-07 22:32:11 -08:00
|
|
|
, mTail(&mRuleSelectorPairs)
|
|
|
|
{}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mWeight;
|
2011-12-07 22:32:11 -08:00
|
|
|
PerWeightDataListItem *mRuleSelectorPairs;
|
|
|
|
PerWeightDataListItem **mTail;
|
2007-12-14 14:59:20 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RuleByWeightEntry : public PLDHashEntryHdr {
|
2011-12-07 22:32:11 -08:00
|
|
|
PerWeightData data; // mWeight is key, mRuleSelectorPairs are value
|
2007-12-14 14:59:20 -08:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashNumber
|
2007-12-14 14:59:20 -08:00
|
|
|
HashIntKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
return PLDHashNumber(NS_PTR_TO_INT32(key));
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-12-14 14:59:20 -08:00
|
|
|
MatchWeightEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-14 14:59:20 -08:00
|
|
|
const RuleByWeightEntry *entry = (const RuleByWeightEntry *)hdr;
|
|
|
|
return entry->data.mWeight == NS_PTR_TO_INT32(key);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-07-02 13:56:09 -07:00
|
|
|
InitWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleByWeightEntry* entry = static_cast<RuleByWeightEntry*>(hdr);
|
|
|
|
new (entry) RuleByWeightEntry();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
static PLDHashTableOps gRulesByWeightOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
HashIntKey,
|
|
|
|
MatchWeightEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
2011-12-07 22:32:11 -08:00
|
|
|
PL_DHashClearEntryStub,
|
2007-12-14 14:59:20 -08:00
|
|
|
PL_DHashFinalizeStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
InitWeightEntry
|
2007-12-14 14:59:20 -08:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct CascadeEnumData {
|
2008-07-26 09:14:48 -07:00
|
|
|
CascadeEnumData(nsPresContext* aPresContext,
|
2008-11-26 19:50:16 -08:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& aFontFaceRules,
|
2011-04-11 23:18:43 -07:00
|
|
|
nsTArray<nsCSSKeyframesRule*>& aKeyframesRules,
|
2012-08-31 14:21:28 -07:00
|
|
|
nsTArray<nsCSSPageRule*>& aPageRules,
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey& aKey,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aSheetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mPresContext(aPresContext),
|
2008-11-25 15:22:38 -08:00
|
|
|
mFontFaceRules(aFontFaceRules),
|
2011-04-11 23:18:43 -07:00
|
|
|
mKeyframesRules(aKeyframesRules),
|
2012-08-31 14:21:28 -07:00
|
|
|
mPageRules(aPageRules),
|
2008-07-26 09:14:48 -07:00
|
|
|
mCacheKey(aKey),
|
2008-11-26 19:50:16 -08:00
|
|
|
mSheetType(aSheetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!PL_DHashTableInit(&mRulesByWeight, &gRulesByWeightOps, nullptr,
|
2007-12-14 14:59:20 -08:00
|
|
|
sizeof(RuleByWeightEntry), 64))
|
2012-07-30 07:20:58 -07:00
|
|
|
mRulesByWeight.ops = nullptr;
|
2011-12-07 22:32:11 -08:00
|
|
|
|
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "CascadeEnumDataArena",
|
|
|
|
NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE);
|
2007-12-14 14:59:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CascadeEnumData()
|
|
|
|
{
|
|
|
|
if (mRulesByWeight.ops)
|
|
|
|
PL_DHashTableFinish(&mRulesByWeight);
|
2011-12-07 22:32:11 -08:00
|
|
|
PL_FinishArenaPool(&mArena);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* mPresContext;
|
2008-11-26 19:50:16 -08:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& mFontFaceRules;
|
2011-04-11 23:18:43 -07:00
|
|
|
nsTArray<nsCSSKeyframesRule*>& mKeyframesRules;
|
2012-08-31 14:21:28 -07:00
|
|
|
nsTArray<nsCSSPageRule*>& mPageRules;
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey& mCacheKey;
|
2011-12-07 22:32:11 -08:00
|
|
|
PLArenaPool mArena;
|
2007-12-14 14:59:20 -08:00
|
|
|
// Hooray, a manual PLDHashTable since nsClassHashtable doesn't
|
|
|
|
// provide a getter that gives me a *reference* to the value.
|
2011-12-07 22:32:11 -08:00
|
|
|
PLDHashTable mRulesByWeight; // of PerWeightDataListItem linked lists
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mSheetType;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-11-25 15:22:38 -08: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-11 23:18:43 -07:00
|
|
|
* (3) add any @keyframes rules, in order, into data->mKeyframesRules.
|
2012-08-31 14:21:28 -07:00
|
|
|
* (4) add any @page rules, in order, into data->mPageRules.
|
2008-11-25 15:22:38 -08:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-07 18:23:46 -07:00
|
|
|
CascadeRuleEnumFunc(css::Rule* aRule, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t type = aRule->GetType();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
if (css::Rule::STYLE_RULE == type) {
|
2011-03-10 18:48:57 -08:00
|
|
|
css::StyleRule* styleRule = static_cast<css::StyleRule*>(aRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (nsCSSSelectorList *sel = styleRule->Selector();
|
|
|
|
sel; sel = sel->mNext) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t weight = sel->mWeight;
|
2007-12-14 14:59:20 -08:00
|
|
|
RuleByWeightEntry *entry = static_cast<RuleByWeightEntry*>(
|
|
|
|
PL_DHashTableOperate(&data->mRulesByWeight, NS_INT32_TO_PTR(weight),
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!entry)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-12-14 14:59:20 -08:00
|
|
|
entry->data.mWeight = weight;
|
2011-12-07 22:32:11 -08: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-07 18:23:46 -07:00
|
|
|
else if (css::Rule::MEDIA_RULE == type ||
|
2012-08-01 17:32:12 -07:00
|
|
|
css::Rule::DOCUMENT_RULE == type ||
|
|
|
|
css::Rule::SUPPORTS_RULE == type) {
|
2010-08-07 22:28:33 -07:00
|
|
|
css::GroupRule* groupRule = static_cast<css::GroupRule*>(aRule);
|
2008-07-26 09:14:48 -07:00
|
|
|
if (groupRule->UseForPresentation(data->mPresContext, data->mCacheKey))
|
2008-11-25 15:22:38 -08:00
|
|
|
if (!groupRule->EnumerateRulesForwards(CascadeRuleEnumFunc, aData))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-07 18:23:46 -07:00
|
|
|
else if (css::Rule::FONT_FACE_RULE == type) {
|
2008-11-25 15:22:38 -08:00
|
|
|
nsCSSFontFaceRule *fontFaceRule = static_cast<nsCSSFontFaceRule*>(aRule);
|
2008-11-26 19:50:16 -08:00
|
|
|
nsFontFaceRuleContainer *ptr = data->mFontFaceRules.AppendElement();
|
2008-11-25 15:22:38 -08:00
|
|
|
if (!ptr)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-11-26 19:50:16 -08:00
|
|
|
ptr->mRule = fontFaceRule;
|
|
|
|
ptr->mSheetType = data->mSheetType;
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
2011-04-07 18:23:46 -07:00
|
|
|
else if (css::Rule::KEYFRAMES_RULE == type) {
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframesRule *keyframesRule =
|
|
|
|
static_cast<nsCSSKeyframesRule*>(aRule);
|
|
|
|
if (!data->mKeyframesRules.AppendElement(keyframesRule)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-31 14:21:28 -07:00
|
|
|
else if (css::Rule::PAGE_RULE == type) {
|
|
|
|
nsCSSPageRule* pageRule = static_cast<nsCSSPageRule*>(aRule);
|
|
|
|
if (!data->mPageRules.AppendElement(pageRule)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSRuleProcessor::CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-14 12:05:14 -07:00
|
|
|
if (aSheet->IsApplicable() &&
|
2010-05-11 13:41:47 -07:00
|
|
|
aSheet->UseForPresentation(aData->mPresContext, aData->mCacheKey) &&
|
|
|
|
aSheet->mInner) {
|
|
|
|
nsCSSStyleSheet* child = aSheet->mInner->mFirstChild;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (child) {
|
2010-05-11 13:41:47 -07:00
|
|
|
CascadeSheet(child, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
if (!aSheet->mInner->mOrderedRules.EnumerateForwards(CascadeRuleEnumFunc,
|
|
|
|
aData))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static int CompareWeightData(const void* aArg1, const void* aArg2,
|
|
|
|
void* closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-14 14:59:20 -08:00
|
|
|
const PerWeightData* arg1 = static_cast<const PerWeightData*>(aArg1);
|
|
|
|
const PerWeightData* arg2 = static_cast<const PerWeightData*>(aArg2);
|
2007-03-22 10:30:00 -07:00
|
|
|
return arg1->mWeight - arg2->mWeight; // put lower weight first
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
struct FillWeightArrayData {
|
|
|
|
FillWeightArrayData(PerWeightData* aArrayData) :
|
2007-03-22 10:30:00 -07:00
|
|
|
mIndex(0),
|
2007-12-14 14:59:20 -08:00
|
|
|
mWeightArray(aArrayData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mIndex;
|
2007-12-14 14:59:20 -08:00
|
|
|
PerWeightData* mWeightArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2007-12-14 14:59:20 -08:00
|
|
|
FillWeightArray(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t number, void *arg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-14 14:59:20 -08:00
|
|
|
FillWeightArrayData* data = static_cast<FillWeightArrayData*>(arg);
|
|
|
|
const RuleByWeightEntry *entry = (const RuleByWeightEntry *)hdr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
data->mWeightArray[data->mIndex++] = entry->data;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
return PL_DHASH_NEXT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleCascadeData*
|
|
|
|
nsCSSRuleProcessor::GetRuleCascade(nsPresContext* aPresContext)
|
2008-07-26 09:14:48 -07: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)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-07-26 09:14:48 -07: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).)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-26 09:14:48 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
if (mSheets.Length() != 0) {
|
2007-12-13 16:24:39 -08:00
|
|
|
nsAutoPtr<RuleCascadeData> newCascade(
|
2008-07-26 09:14:48 -07:00
|
|
|
new RuleCascadeData(aPresContext->Medium(),
|
2007-12-13 16:24:39 -08:00
|
|
|
eCompatibility_NavQuirks == aPresContext->CompatibilityMode()));
|
|
|
|
if (newCascade) {
|
2008-11-25 15:22:38 -08:00
|
|
|
CascadeEnumData data(aPresContext, newCascade->mFontFaceRules,
|
2011-04-11 23:18:43 -07:00
|
|
|
newCascade->mKeyframesRules,
|
2012-08-31 14:21:28 -07:00
|
|
|
newCascade->mPageRules,
|
2008-11-25 15:22:38 -08:00
|
|
|
newCascade->mCacheKey,
|
2008-11-26 19:50:16 -08:00
|
|
|
mSheetType);
|
2007-12-14 14:59:20 -08:00
|
|
|
if (!data.mRulesByWeight.ops)
|
2008-07-26 09:14:48 -07:00
|
|
|
return; /* out of memory */
|
2010-05-11 13:41:47 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mSheets.Length(); ++i) {
|
2010-05-11 13:41:47 -07:00
|
|
|
if (!CascadeSheet(mSheets.ElementAt(i), &data))
|
|
|
|
return; /* out of memory */
|
|
|
|
}
|
2007-12-14 14:59:20 -08:00
|
|
|
|
|
|
|
// Sort the hash table of per-weight linked lists by weight.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t weightCount = data.mRulesByWeight.entryCount;
|
2007-12-14 14:59:20 -08:00
|
|
|
nsAutoArrayPtr<PerWeightData> weightArray(new PerWeightData[weightCount]);
|
|
|
|
FillWeightArrayData fwData(weightArray);
|
|
|
|
PL_DHashTableEnumerate(&data.mRulesByWeight, FillWeightArray, &fwData);
|
|
|
|
NS_QuickSort(weightArray, weightCount, sizeof(PerWeightData),
|
2012-07-30 07:20:58 -07:00
|
|
|
CompareWeightData, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
// Put things into the rule hash.
|
2007-12-14 14:59:20 -08:00
|
|
|
// The primary sort is by weight...
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < weightCount; ++i) {
|
2011-12-07 22:32:11 -08:00
|
|
|
// and the secondary sort is by order. mRuleSelectorPairs is already in
|
2010-07-02 13:56:09 -07:00
|
|
|
// the right order..
|
2011-12-07 22:32:11 -08:00
|
|
|
for (PerWeightDataListItem *cur = weightArray[i].mRuleSelectorPairs;
|
|
|
|
cur;
|
|
|
|
cur = cur->mNext) {
|
2010-07-02 13:56:09 -07:00
|
|
|
if (!AddRule(cur, newCascade))
|
2008-07-26 09:14:48 -07:00
|
|
|
return; /* out of memory */
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
// Ensure that the current one is always mRuleCascades.
|
|
|
|
newCascade->mNext = mRuleCascades;
|
|
|
|
mRuleCascades = newCascade.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-21 17:55:52 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSRuleProcessor::SelectorListMatches(Element* aElement,
|
2011-03-29 10:29:21 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelectorList* aSelectorList)
|
2008-07-21 17:55:52 -07:00
|
|
|
{
|
|
|
|
while (aSelectorList) {
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelector* sel = aSelectorList->mSelectors;
|
2008-07-21 17:55:52 -07:00
|
|
|
NS_ASSERTION(sel, "Should have *some* selectors");
|
2009-12-10 23:37:41 -08:00
|
|
|
NS_ASSERTION(!sel->IsPseudoElement(), "Shouldn't have been called");
|
2011-10-17 07:59:28 -07:00
|
|
|
NodeMatchContext nodeContext(nsEventStates(), false);
|
2011-03-29 10:29:21 -07:00
|
|
|
if (SelectorMatches(aElement, sel, nodeContext, aTreeMatchContext)) {
|
2011-11-14 10:10:22 -08:00
|
|
|
nsCSSSelector* next = sel->mNext;
|
2011-03-29 10:29:21 -07:00
|
|
|
if (!next ||
|
2011-10-17 07:59:28 -07:00
|
|
|
SelectorMatchesTree(aElement, next, aTreeMatchContext, false)) {
|
|
|
|
return true;
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aSelectorList = aSelectorList->mNext;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
2012-03-12 20:54:15 -07:00
|
|
|
|
|
|
|
// AncestorFilter out of line methods
|
|
|
|
void
|
|
|
|
AncestorFilter::Init(Element *aElement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mFilter);
|
|
|
|
MOZ_ASSERT(mHashes.IsEmpty());
|
|
|
|
|
|
|
|
mFilter = new Filter();
|
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(aElement)) {
|
2012-03-12 20:54:15 -07:00
|
|
|
MOZ_ASSERT(aElement->IsInDoc(),
|
|
|
|
"aElement must be in the document for the assumption that "
|
2012-10-09 05:31:24 -07:00
|
|
|
"GetParentNode() is non-null on all element ancestors of "
|
2012-03-12 20:54:15 -07:00
|
|
|
"aElement to be true");
|
|
|
|
// Collect up the ancestors
|
|
|
|
nsAutoTArray<Element*, 50> ancestors;
|
|
|
|
Element* cur = aElement;
|
|
|
|
do {
|
|
|
|
ancestors.AppendElement(cur);
|
2012-10-09 05:31:24 -07:00
|
|
|
nsINode* parent = cur->GetParentNode();
|
2012-03-12 20:54:15 -07:00
|
|
|
if (!parent->IsElement()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur = parent->AsElement();
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
// Now push them in reverse order.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = ancestors.Length(); i-- != 0; ) {
|
2012-03-12 20:54:15 -07:00
|
|
|
PushAncestor(ancestors[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AncestorFilter::PushAncestor(Element *aElement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFilter);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldLength = mHashes.Length();
|
2012-03-12 20:54:15 -07:00
|
|
|
|
|
|
|
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) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t classCount = classes->GetAtomCount();
|
|
|
|
for (uint32_t i = 0; i < classCount; ++i) {
|
2012-03-12 20:54:15 -07:00
|
|
|
mHashes.AppendElement(classes->AtomAt(i)->hash());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t newLength = mHashes.Length();
|
|
|
|
for (uint32_t i = oldLength; i < newLength; ++i) {
|
2012-03-12 20:54:15 -07:00
|
|
|
mFilter->add(mHashes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AncestorFilter::PopAncestor()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mPopTargets.IsEmpty());
|
|
|
|
MOZ_ASSERT(mPopTargets.Length() == mElements.Length());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t popTargetLength = mPopTargets.Length();
|
|
|
|
uint32_t newLength = mPopTargets[popTargetLength-1];
|
2012-03-12 20:54:15 -07:00
|
|
|
|
|
|
|
mPopTargets.TruncateLength(popTargetLength-1);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mElements.TruncateLength(popTargetLength-1);
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldLength = mHashes.Length();
|
|
|
|
for (uint32_t i = newLength; i < oldLength; ++i) {
|
2012-03-12 20:54:15 -07:00
|
|
|
mFilter->remove(mHashes[i]);
|
|
|
|
}
|
|
|
|
mHashes.TruncateLength(newLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AncestorFilter::AssertHasAllAncestors(Element *aElement) const
|
|
|
|
{
|
2012-10-09 05:31:24 -07:00
|
|
|
nsINode* cur = aElement->GetParentNode();
|
2012-03-12 20:54:15 -07:00
|
|
|
while (cur && cur->IsElement()) {
|
|
|
|
MOZ_ASSERT(mElements.Contains(cur));
|
2012-10-09 05:31:24 -07:00
|
|
|
cur = cur->GetParentNode();
|
2012-03-12 20:54:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|