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:
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2008-04-08 11:36:53 -07:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2008-08-12 17:44:14 -07:00
|
|
|
* Rob Arnold <robarnold@mozilla.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* style rule processor for CSS style sheets, responsible for selector
|
|
|
|
* matching and cascading
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
#define NS_RULEHASH_ARENA_BLOCK_SIZE (256)
|
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsICSSPseudoComparator.h"
|
|
|
|
#include "nsCSSRuleProcessor.h"
|
|
|
|
#include "nsICSSStyleRule.h"
|
|
|
|
#include "nsICSSGroupRule.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#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"
|
|
|
|
#include "nsAttrName.h"
|
2007-11-19 12:08:20 -08:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#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 "nsIPrivateBrowsingService.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"
|
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"
|
|
|
|
|
|
|
|
static PRBool gSupportVisitedPseudo = PR_TRUE;
|
|
|
|
|
2007-11-19 12:08:20 -08:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
|
|
|
static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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 {
|
|
|
|
RuleSelectorPair(nsICSSStyleRule* aRule, nsCSSSelector* aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mRule(aRule), mSelector(aSelector) {}
|
|
|
|
|
|
|
|
nsICSSStyleRule* mRule;
|
|
|
|
nsCSSSelector* mSelector; // which of |mRule|'s selectors
|
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 {
|
|
|
|
RuleValue(const RuleSelectorPair& aRuleSelectorPair, PRInt32 aIndex) :
|
|
|
|
RuleSelectorPair(aRuleSelectorPair),
|
|
|
|
mIndex(aIndex)
|
|
|
|
{}
|
|
|
|
PRInt32 mIndex; // High index means high weight/order.
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Rule hash table
|
|
|
|
//
|
|
|
|
|
|
|
|
// Uses any of the sets of ops below.
|
|
|
|
struct RuleHashTableEntry : public PLDHashEntryHdr {
|
2010-07-02 13:56:09 -07:00
|
|
|
nsTArray<RuleValue> mRules;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
struct RuleHashTagTableEntry : public RuleHashTableEntry {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PRBool
|
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)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PRBool
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
static PRBool
|
|
|
|
RuleHash_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
new (entry) RuleHashTableEntry();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RuleHash_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
RuleHashTableEntry* entry = static_cast<RuleHashTableEntry*>(hdr);
|
|
|
|
entry->~RuleHashTableEntry();
|
|
|
|
}
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
static PRBool
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
static PRBool
|
|
|
|
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));
|
2010-07-02 13:56:09 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PRBool
|
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,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashMoveEntryStub,
|
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,
|
|
|
|
PL_DHashMoveEntryStub,
|
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,
|
|
|
|
PL_DHashMoveEntryStub,
|
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,
|
|
|
|
PL_DHashMoveEntryStub,
|
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,
|
|
|
|
PL_DHashMoveEntryStub,
|
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,
|
|
|
|
PL_DHashMoveEntryStub,
|
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
|
|
|
|
|
|
|
|
// Enumerator callback function.
|
|
|
|
typedef void (*RuleEnumFunc)(nsICSSStyleRule* aRule,
|
|
|
|
nsCSSSelector* aSelector,
|
|
|
|
void *aData);
|
|
|
|
|
|
|
|
class RuleHash {
|
|
|
|
public:
|
|
|
|
RuleHash(PRBool aQuirksMode);
|
|
|
|
~RuleHash();
|
2010-07-02 13:56:09 -07:00
|
|
|
void AppendRule(const RuleSelectorPair &aRuleInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
void EnumerateAllRules(PRInt32 aNameSpace, nsIAtom* aTag, nsIAtom* aID,
|
|
|
|
const nsAttrValue* aClassList,
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleEnumFunc aFunc, RuleProcessorData* aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
PLArenaPool& Arena() { return mArena; }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
PRInt32 mRuleCount;
|
|
|
|
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;
|
|
|
|
PRInt32 mEnumListSize;
|
|
|
|
|
|
|
|
inline EnumData ToEnumData(const RuleValueList& arr) {
|
|
|
|
EnumData data = { arr.Elements(), arr.Elements() + arr.Length() };
|
|
|
|
return data;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PLArenaPool mArena;
|
|
|
|
|
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
PRUint32 mUniversalSelectors;
|
|
|
|
PRUint32 mNameSpaceSelectors;
|
|
|
|
PRUint32 mTagSelectors;
|
|
|
|
PRUint32 mClassSelectors;
|
|
|
|
PRUint32 mIdSelectors;
|
|
|
|
|
|
|
|
PRUint32 mElementsMatched;
|
|
|
|
|
|
|
|
PRUint32 mElementUniversalCalls;
|
|
|
|
PRUint32 mElementNameSpaceCalls;
|
|
|
|
PRUint32 mElementTagCalls;
|
|
|
|
PRUint32 mElementClassCalls;
|
|
|
|
PRUint32 mElementIdCalls;
|
|
|
|
#endif // RULE_HASH_STATS
|
|
|
|
};
|
|
|
|
|
|
|
|
RuleHash::RuleHash(PRBool aQuirksMode)
|
|
|
|
: mRuleCount(0),
|
|
|
|
mUniversalRules(nsnull),
|
|
|
|
mEnumList(nsnull), mEnumListSize(0)
|
|
|
|
#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
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "RuleHashArena", NS_RULEHASH_ARENA_BLOCK_SIZE);
|
|
|
|
|
2009-08-01 08:53:40 -07:00
|
|
|
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTagTableEntry), 64);
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashTableInit(&mIdTable,
|
2007-03-27 08:33:38 -07:00
|
|
|
aQuirksMode ? &RuleHash_IdTable_CIOps.ops
|
|
|
|
: &RuleHash_IdTable_CSOps.ops,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull, sizeof(RuleHashTableEntry), 16);
|
|
|
|
PL_DHashTableInit(&mClassTable,
|
2007-03-27 08:33:38 -07:00
|
|
|
aQuirksMode ? &RuleHash_ClassTable_CIOps.ops
|
|
|
|
: &RuleHash_ClassTable_CSOps.ops,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull, sizeof(RuleHashTableEntry), 16);
|
|
|
|
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTableEntry), 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2010-07-02 13:56:09 -07:00
|
|
|
for (PRUint32 i = 0; i < mUniversalRules.Length(); ++i) {
|
|
|
|
RuleValue* value = &(mUniversalRules[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString selectorText;
|
|
|
|
PRUint32 lineNumber = value->mRule->GetLineNumber();
|
|
|
|
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.
|
|
|
|
if (nsnull != mEnumList) {
|
|
|
|
delete [] mEnumList;
|
|
|
|
}
|
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_DHashTableFinish(&mIdTable);
|
|
|
|
PL_DHashTableFinish(&mClassTable);
|
|
|
|
PL_DHashTableFinish(&mTagTable);
|
|
|
|
PL_DHashTableFinish(&mNameSpaceTable);
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
}
|
|
|
|
|
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;
|
2010-07-02 13:56:09 -07:00
|
|
|
entry->mRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++));
|
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
|
|
|
{
|
2010-07-02 13:56:09 -07:00
|
|
|
mUniversalRules.AppendElement(RuleValue(aRuleInfo, mRuleCount++));
|
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;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsnull != selector->mIDList) {
|
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);
|
|
|
|
}
|
|
|
|
else if (nsnull != selector->mClassList) {
|
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) {
|
2010-07-08 09:50:18 -07:00
|
|
|
RuleValue ruleValue(aRuleInfo, mRuleCount++);
|
|
|
|
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) {
|
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
|
|
|
|
|
|
|
|
void RuleHash::EnumerateAllRules(PRInt32 aNameSpace, nsIAtom* aTag,
|
|
|
|
nsIAtom* aID, const nsAttrValue* aClassList,
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleEnumFunc aFunc, RuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 classCount = aClassList ? aClassList->GetAtomCount() : 0;
|
|
|
|
|
|
|
|
// assume 1 universal, tag, id, and namespace, rather than wasting
|
|
|
|
// time counting
|
|
|
|
PRInt32 testCount = classCount + 4;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 valueCount = 0;
|
|
|
|
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
|
2009-12-10 23:37:40 -08:00
|
|
|
if (kNameSpaceID_Unknown != aNameSpace && mNameSpaceTable.entryCount) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mNameSpaceTable, NS_INT32_TO_PTR(aNameSpace),
|
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
|
|
|
}
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
if (aTag && mTagTable.entryCount) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mTagTable, aTag, 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
|
|
|
}
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
if (aID && mIdTable.entryCount) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mIdTable, aID, 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
|
|
|
}
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
if (mClassTable.entryCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PRInt32 index = 0; index < classCount; ++index) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleHashTableEntry *entry = static_cast<RuleHashTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mClassTable, aClassList->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) {
|
|
|
|
// Merge the lists while there are still multiple lists to merge.
|
|
|
|
while (valueCount > 1) {
|
|
|
|
PRInt32 valueIndex = 0;
|
2010-07-02 13:56:09 -07:00
|
|
|
PRInt32 lowestRuleIndex = mEnumList[valueIndex].mCurValue->mIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PRInt32 index = 1; index < valueCount; ++index) {
|
2010-07-02 13:56:09 -07:00
|
|
|
PRInt32 ruleIndex = mEnumList[index].mCurValue->mIndex;
|
|
|
|
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;
|
2007-03-22 10:30:00 -07:00
|
|
|
(*aFunc)(cur->mRule, cur->mSelector, aData);
|
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) {
|
2007-03-22 10:30:00 -07:00
|
|
|
(*aFunc)(value->mRule, value->mSelector, aData);
|
2010-07-02 13:56:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
// Attribute selectors hash table.
|
|
|
|
struct AttributeSelectorEntry : public PLDHashEntryHdr {
|
|
|
|
nsIAtom *mAttribute;
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*> *mSelectors;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
AttributeSelectorClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>(hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete entry->mSelectors;
|
|
|
|
memset(entry, 0, table->entrySize);
|
|
|
|
}
|
|
|
|
|
2007-03-27 08:33:38 -07:00
|
|
|
static const PLDHashTableOps AttributeSelectorOps = {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
AttributeSelectorClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
// Class selectors hash table.
|
|
|
|
struct ClassSelectorEntry : public PLDHashEntryHdr {
|
|
|
|
nsIAtom *mClass;
|
|
|
|
nsTArray<nsCSSSelector*> mSelectors;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClassSelector_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
(static_cast<ClassSelectorEntry*>(hdr))->~ClassSelectorEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
ClassSelector_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
2010-07-02 13:56:09 -07:00
|
|
|
const void *key)
|
2010-06-18 09:23:05 -07:00
|
|
|
{
|
|
|
|
ClassSelectorEntry *entry = static_cast<ClassSelectorEntry*>(hdr);
|
|
|
|
new (entry) ClassSelectorEntry();
|
|
|
|
entry->mClass = const_cast<nsIAtom*>(static_cast<const nsIAtom*>(key));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIAtom*
|
|
|
|
ClassSelector_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
const ClassSelectorEntry *entry = static_cast<const ClassSelectorEntry*>(hdr);
|
|
|
|
return entry->mClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case-sensitive ops.
|
|
|
|
static const RuleHashTableOps ClassSelector_CSOps = {
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
RuleHash_CSMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
ClassSelector_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
ClassSelector_InitEntry
|
|
|
|
},
|
|
|
|
ClassSelector_GetKey
|
|
|
|
};
|
|
|
|
|
|
|
|
// Case-insensitive ops.
|
|
|
|
static const RuleHashTableOps ClassSelector_CIOps = {
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
RuleHash_CIHashKey,
|
|
|
|
RuleHash_CIMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
ClassSelector_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
ClassSelector_InitEntry
|
|
|
|
},
|
|
|
|
ClassSelector_GetKey
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
struct RuleCascadeData {
|
|
|
|
RuleCascadeData(nsIAtom *aMedium, PRBool aQuirksMode)
|
|
|
|
: mRuleHash(aQuirksMode),
|
|
|
|
mStateSelectors(),
|
2010-03-25 02:22:58 -07:00
|
|
|
mSelectorDocumentStates(0),
|
2008-07-26 09:14:48 -07:00
|
|
|
mCacheKey(aMedium),
|
2009-12-10 23:37:40 -08:00
|
|
|
mNext(nsnull),
|
|
|
|
mQuirksMode(aQuirksMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PL_DHashTableInit(&mAttributeSelectors, &AttributeSelectorOps, nsnull,
|
|
|
|
sizeof(AttributeSelectorEntry), 16);
|
2009-12-10 23:37:40 -08:00
|
|
|
PL_DHashTableInit(&mAnonBoxRules, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
sizeof(RuleHashTagTableEntry), 16);
|
2010-06-18 09:23:05 -07:00
|
|
|
PL_DHashTableInit(&mClassSelectors,
|
|
|
|
aQuirksMode ? &ClassSelector_CIOps.ops :
|
|
|
|
&ClassSelector_CSOps.ops,
|
|
|
|
nsnull, sizeof(ClassSelectorEntry), 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
|
|
|
|
PL_DHashTableInit(&mXULTreeRules, &RuleHash_TagTable_Ops, nsnull,
|
|
|
|
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);
|
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
|
2009-12-10 23:37:40 -08:00
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(mPseudoElementRuleHashes); ++i) {
|
|
|
|
delete mPseudoElementRuleHashes[i];
|
|
|
|
}
|
2007-03-22 10:30:00 -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];
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*> mStateSelectors;
|
2010-03-17 10:10:57 -07:00
|
|
|
PRUint32 mSelectorDocumentStates;
|
2010-06-18 09:23:05 -07:00
|
|
|
PLDHashTable mClassSelectors;
|
|
|
|
nsTArray<nsCSSSelector*> mPossiblyNegatedClassSelectors;
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*> mIDSelectors;
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
const PRBool mQuirksMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
nsTArray<nsCSSSelector*>*
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleCascadeData::AttributeListFor(nsIAtom* aAttribute)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&mAttributeSelectors, aAttribute, PL_DHASH_ADD));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry)
|
|
|
|
return nsnull;
|
|
|
|
if (!entry->mSelectors) {
|
2009-02-03 06:42:18 -08:00
|
|
|
if (!(entry->mSelectors = new nsTArray<nsCSSSelector*>)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashTableRawRemove(&mAttributeSelectors, entry);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
entry->mAttribute = aAttribute;
|
|
|
|
}
|
|
|
|
return entry->mSelectors;
|
|
|
|
}
|
|
|
|
|
2010-04-07 10:29:10 -07:00
|
|
|
class nsPrivateBrowsingObserver : nsIObserver,
|
|
|
|
nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPrivateBrowsingObserver();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
PRBool InPrivateBrowsing() const { return mInPrivateBrowsing; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRBool mInPrivateBrowsing;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsPrivateBrowsingObserver, nsIObserver, nsISupportsWeakReference)
|
|
|
|
|
|
|
|
nsPrivateBrowsingObserver::nsPrivateBrowsingObserver()
|
|
|
|
: mInPrivateBrowsing(PR_FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrivateBrowsingObserver::Init()
|
|
|
|
{
|
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
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
2010-06-22 09:59:57 -07:00
|
|
|
if (observerService) {
|
|
|
|
observerService->AddObserver(this, "profile-after-change", PR_TRUE);
|
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
|
|
|
observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
|
2010-06-22 09:59:57 -07:00
|
|
|
}
|
2010-04-07 10:29:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPrivateBrowsingObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC)) {
|
|
|
|
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).get())) {
|
|
|
|
mInPrivateBrowsing = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
mInPrivateBrowsing = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-06-22 09:59:57 -07:00
|
|
|
else if (!strcmp(aTopic, "profile-after-change")) {
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingService> pbService =
|
|
|
|
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
|
|
|
if (pbService)
|
|
|
|
pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
|
|
|
|
}
|
2010-04-07 10:29:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsPrivateBrowsingObserver *gPrivateBrowsingObserver = nsnull;
|
|
|
|
|
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,
|
2008-11-26 19:50:16 -08:00
|
|
|
PRUint8 aSheetType)
|
2008-07-26 09:14:48 -07:00
|
|
|
: mSheets(aSheets)
|
|
|
|
, mRuleCascades(nsnull)
|
|
|
|
, mLastPresContext(nsnull)
|
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()
|
|
|
|
{
|
|
|
|
nsContentUtils::AddBoolPrefVarCache(VISITED_PSEUDO_PREF,
|
|
|
|
&gSupportVisitedPseudo);
|
|
|
|
// We want to default to true, not false as AddBoolPrefVarCache does.
|
|
|
|
gSupportVisitedPseudo =
|
|
|
|
nsContentUtils::GetBoolPref(VISITED_PSEUDO_PREF, PR_TRUE);
|
2010-04-07 10:29:10 -07:00
|
|
|
|
|
|
|
gPrivateBrowsingObserver = new nsPrivateBrowsingObserver();
|
|
|
|
NS_ENSURE_TRUE(gPrivateBrowsingObserver, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(gPrivateBrowsingObserver);
|
|
|
|
gPrivateBrowsingObserver->Init();
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-10-21 00:15:03 -07:00
|
|
|
}
|
|
|
|
|
2007-11-19 12:08:20 -08:00
|
|
|
static PRBool
|
|
|
|
InitSystemMetrics()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!sSystemMetrics, "already initialized");
|
|
|
|
|
|
|
|
sSystemMetrics = new nsTArray< nsCOMPtr<nsIAtom> >;
|
|
|
|
NS_ENSURE_TRUE(sSystemMetrics, PR_FALSE);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILookAndFeel> lookAndFeel(do_GetService(kLookAndFeelCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2009-10-17 07:31:47 -07:00
|
|
|
/***************************************************************************
|
|
|
|
* ANY METRICS ADDED HERE SHOULD ALSO BE ADDED AS MEDIA QUERIES IN *
|
|
|
|
* nsMediaFeatures.cpp *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-11-19 12:08:20 -08:00
|
|
|
PRInt32 metricResult;
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollArrowStyle, metricResult);
|
|
|
|
if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartBackward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_backward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
if (metricResult & nsILookAndFeel::eMetric_ScrollArrowStartForward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_start_forward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndBackward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_backward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
if (metricResult & nsILookAndFeel::eMetric_ScrollArrowEndForward) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_end_forward);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollSliderStyle, metricResult);
|
|
|
|
if (metricResult != nsILookAndFeel::eMetric_ScrollThumbStyleNormal) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::scrollbar_thumb_proportional);
|
2007-11-19 12:08:20 -08:00
|
|
|
}
|
|
|
|
|
2008-02-20 02:12:33 -08:00
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ImagesInMenus, metricResult);
|
|
|
|
if (metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_menus);
|
2008-02-20 02:12:33 -08:00
|
|
|
}
|
|
|
|
|
2009-10-06 07:20:59 -07:00
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ImagesInButtons, metricResult);
|
|
|
|
if (metricResult) {
|
2009-10-15 17:23:18 -07:00
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::images_in_buttons);
|
2009-10-06 07:20:59 -07:00
|
|
|
}
|
|
|
|
|
2010-07-17 01:11:54 -07:00
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenuBarDrag, metricResult);
|
|
|
|
if (metricResult) {
|
|
|
|
sSystemMetrics->AppendElement(nsGkAtoms::menubar_drag);
|
|
|
|
}
|
|
|
|
|
2008-04-08 11:36:53 -07:00
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_WindowsDefaultTheme, metricResult);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-09-17 09:23:58 -07:00
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MacGraphiteTheme, metricResult);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_DWMCompositor, metricResult);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-08-18 10:33:08 -07:00
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_WindowsClassic, metricResult);
|
|
|
|
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
|
|
|
|
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TouchEnabled, metricResult);
|
|
|
|
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
|
|
|
|
2009-10-04 18:31:26 -07:00
|
|
|
rv = lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MaemoClassic, metricResult);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-11-19 12:08:20 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2008-08-05 13:02:43 -07:00
|
|
|
nsCSSRuleProcessor::FreeSystemMetrics()
|
2007-11-19 12:08:20 -08:00
|
|
|
{
|
|
|
|
delete sSystemMetrics;
|
|
|
|
sSystemMetrics = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-04-07 10:29:10 -07:00
|
|
|
/* static */ void
|
|
|
|
nsCSSRuleProcessor::Shutdown()
|
|
|
|
{
|
|
|
|
FreeSystemMetrics();
|
|
|
|
// Make sure we don't crash if Shutdown is called before Init
|
|
|
|
NS_IF_RELEASE(gPrivateBrowsingObserver);
|
|
|
|
}
|
|
|
|
|
2009-10-15 17:23:19 -07:00
|
|
|
/* static */ PRBool
|
|
|
|
nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
|
|
|
|
{
|
|
|
|
if (!sSystemMetrics && !InitSystemMetrics()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
RuleProcessorData::RuleProcessorData(nsPresContext* aPresContext,
|
2010-04-30 06:12:06 -07:00
|
|
|
Element* aElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRuleWalker* aRuleWalker,
|
|
|
|
nsCompatibility* aCompat /*= nsnull*/)
|
2009-12-10 14:36:03 -08:00
|
|
|
: mPresContext(aPresContext),
|
2010-04-30 06:12:06 -07:00
|
|
|
mElement(aElement),
|
2009-12-10 14:36:03 -08:00
|
|
|
mRuleWalker(aRuleWalker),
|
|
|
|
mScopedRoot(nsnull),
|
|
|
|
mPreviousSiblingData(nsnull),
|
|
|
|
mParentData(nsnull),
|
|
|
|
mLanguage(nsnull),
|
2009-12-15 16:04:12 -08:00
|
|
|
mGotContentState(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(RuleProcessorData);
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
NS_ASSERTION(aElement, "null element leaked into SelectorMatches");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
mNthIndices[0][0] = -2;
|
|
|
|
mNthIndices[0][1] = -2;
|
|
|
|
mNthIndices[1][0] = -2;
|
|
|
|
mNthIndices[1][1] = -2;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the compat. mode (unless it is provided)
|
2008-07-21 17:55:52 -07:00
|
|
|
// XXXbz is passing in the compat mode really that much of an optimization?
|
|
|
|
if (aCompat) {
|
|
|
|
mCompatMode = *aCompat;
|
|
|
|
} else if (NS_LIKELY(mPresContext)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mCompatMode = mPresContext->CompatibilityMode();
|
|
|
|
} else {
|
2010-04-30 06:12:06 -07:00
|
|
|
NS_ASSERTION(aElement->GetOwnerDoc(), "Must have document");
|
|
|
|
mCompatMode = aElement->GetOwnerDoc()->GetCompatibilityMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
NS_ASSERTION(aElement->GetOwnerDoc(), "Document-less node here?");
|
2008-07-11 14:01:22 -07:00
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
// get the tag and parent
|
2010-04-30 06:12:06 -07:00
|
|
|
mContentTag = aElement->Tag();
|
|
|
|
mParentContent = aElement->GetParent();
|
2009-12-10 23:37:40 -08:00
|
|
|
|
|
|
|
// see if there are attributes for the content
|
2010-04-30 06:12:06 -07:00
|
|
|
mHasAttributes = aElement->GetAttrCount() > 0;
|
2009-12-10 23:37:40 -08:00
|
|
|
if (mHasAttributes) {
|
|
|
|
// get the ID and classes for the content
|
2010-04-30 06:12:06 -07:00
|
|
|
mContentID = aElement->GetID();
|
|
|
|
mClasses = aElement->GetClasses();
|
2009-12-10 14:36:03 -08:00
|
|
|
} else {
|
|
|
|
mContentID = nsnull;
|
|
|
|
mClasses = nsnull;
|
2008-10-21 00:15:03 -07:00
|
|
|
}
|
2009-12-10 14:36:03 -08:00
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
// get the namespace
|
2010-04-30 06:12:06 -07:00
|
|
|
mNameSpaceID = aElement->GetNameSpaceID();
|
2009-12-10 23:37:40 -08:00
|
|
|
|
|
|
|
// check for HTMLContent status
|
|
|
|
mIsHTMLContent = (mNameSpaceID == kNameSpaceID_XHTML);
|
2010-04-30 06:12:06 -07:00
|
|
|
mIsHTML = mIsHTMLContent && aElement->IsInHTMLDocument();
|
2009-12-10 23:37:40 -08:00
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
// No need to initialize mContentState; the ContentState() accessor will handle
|
|
|
|
// that.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleProcessorData::~RuleProcessorData()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(RuleProcessorData);
|
|
|
|
|
|
|
|
// Destroy potentially long chains of previous sibling and parent data
|
|
|
|
// without more than one level of recursion.
|
|
|
|
if (mPreviousSiblingData || mParentData) {
|
|
|
|
nsAutoVoidArray destroyQueue;
|
|
|
|
destroyQueue.AppendElement(this);
|
|
|
|
|
|
|
|
do {
|
2007-07-08 00:08:04 -07:00
|
|
|
RuleProcessorData *d = static_cast<RuleProcessorData*>
|
|
|
|
(destroyQueue.FastElementAt(destroyQueue.Count() - 1));
|
2007-03-22 10:30:00 -07:00
|
|
|
destroyQueue.RemoveElementAt(destroyQueue.Count() - 1);
|
|
|
|
|
|
|
|
if (d->mPreviousSiblingData) {
|
|
|
|
destroyQueue.AppendElement(d->mPreviousSiblingData);
|
|
|
|
d->mPreviousSiblingData = nsnull;
|
|
|
|
}
|
|
|
|
if (d->mParentData) {
|
|
|
|
destroyQueue.AppendElement(d->mParentData);
|
|
|
|
d->mParentData = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d != this)
|
2008-07-21 17:55:52 -07:00
|
|
|
d->Destroy();
|
2007-03-22 10:30:00 -07:00
|
|
|
} while (destroyQueue.Count());
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString* RuleProcessorData::GetLang()
|
|
|
|
{
|
|
|
|
if (!mLanguage) {
|
2008-08-28 08:38:34 -07:00
|
|
|
mLanguage = new nsString();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mLanguage)
|
|
|
|
return nsnull;
|
2010-04-30 06:12:06 -07:00
|
|
|
for (nsIContent* content = mElement; content;
|
2007-03-22 10:30:00 -07:00
|
|
|
content = content->GetParent()) {
|
|
|
|
if (content->GetAttrCount() > 0) {
|
|
|
|
// xml:lang has precedence over lang on HTML elements (see
|
|
|
|
// XHTML1 section C.7).
|
|
|
|
PRBool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
|
2008-08-28 08:38:34 -07:00
|
|
|
*mLanguage);
|
2009-08-24 13:02:07 -07:00
|
|
|
if (!hasAttr && content->IsHTML()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
|
2008-08-28 08:38:34 -07:00
|
|
|
*mLanguage);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-28 08:38:34 -07:00
|
|
|
NS_ASSERTION(hasAttr || mLanguage->IsEmpty(),
|
|
|
|
"GetAttr that returns false should not make string non-empty");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (hasAttr) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mLanguage;
|
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
PRUint32
|
|
|
|
RuleProcessorData::ContentState()
|
|
|
|
{
|
|
|
|
if (!mGotContentState) {
|
|
|
|
mGotContentState = PR_TRUE;
|
2010-05-31 10:49:04 -07:00
|
|
|
mContentState = mPresContext ?
|
|
|
|
mPresContext->EventStateManager()->GetContentState(mElement) :
|
|
|
|
mElement->IntrinsicState();
|
2009-12-15 16:04:12 -08:00
|
|
|
|
2010-04-02 18:58:27 -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.
|
2010-04-07 10:29:10 -07:00
|
|
|
if ((!gSupportVisitedPseudo ||
|
|
|
|
gPrivateBrowsingObserver->InPrivateBrowsing()) &&
|
|
|
|
(mContentState & NS_EVENT_STATE_VISITED)) {
|
2009-12-15 16:04:12 -08:00
|
|
|
mContentState = (mContentState & ~PRUint32(NS_EVENT_STATE_VISITED)) |
|
|
|
|
NS_EVENT_STATE_UNVISITED;
|
|
|
|
}
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
|
|
|
return mContentState;
|
|
|
|
}
|
|
|
|
|
2010-03-17 10:10:57 -07:00
|
|
|
PRUint32
|
|
|
|
RuleProcessorData::DocumentState()
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
return mElement->GetOwnerDoc()->GetDocumentState();
|
2010-03-17 10:10:57 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
PRBool
|
|
|
|
RuleProcessorData::IsLink()
|
|
|
|
{
|
2009-12-15 16:04:12 -08:00
|
|
|
PRUint32 state = ContentState();
|
|
|
|
return (state & (NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) != 0;
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:27 -07:00
|
|
|
PRUint32
|
|
|
|
RuleProcessorData::GetContentStateForVisitedHandling(
|
|
|
|
nsRuleWalker::VisitedHandlingType aVisitedHandling,
|
|
|
|
PRBool aIsRelevantLink)
|
|
|
|
{
|
|
|
|
PRUint32 contentState = ContentState();
|
|
|
|
if (contentState & (NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) {
|
|
|
|
NS_ABORT_IF_FALSE(IsLink(), "IsLink() should match state");
|
|
|
|
contentState &=
|
|
|
|
~PRUint32(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
PRInt32
|
2008-06-02 20:17:35 -07:00
|
|
|
RuleProcessorData::GetNthIndex(PRBool aIsOfType, PRBool aIsFromEnd,
|
|
|
|
PRBool aCheckEdgeOnly)
|
2008-06-02 20:17:35 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mParentContent, "caller should check mParentContent");
|
|
|
|
|
|
|
|
PRInt32 &slot = mNthIndices[aIsOfType][aIsFromEnd];
|
2008-06-02 20:17:35 -07:00
|
|
|
if (slot != -2 && (slot != -1 || aCheckEdgeOnly))
|
2008-06-02 20:17:35 -07:00
|
|
|
return slot;
|
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
if (mPreviousSiblingData &&
|
|
|
|
(!aIsOfType ||
|
|
|
|
(mPreviousSiblingData->mNameSpaceID == mNameSpaceID &&
|
|
|
|
mPreviousSiblingData->mContentTag == mContentTag))) {
|
|
|
|
slot = mPreviousSiblingData->mNthIndices[aIsOfType][aIsFromEnd];
|
|
|
|
if (slot > 0) {
|
|
|
|
slot += (aIsFromEnd ? -1 : 1);
|
|
|
|
NS_ASSERTION(slot > 0, "How did that happen?");
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
PRInt32 result = 1;
|
|
|
|
nsIContent* parent = mParentContent;
|
|
|
|
|
2008-12-03 06:02:03 -08:00
|
|
|
PRUint32 childCount;
|
|
|
|
nsIContent * const * curChildPtr = parent->GetChildArray(&childCount);
|
2008-09-05 10:39:19 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsMutationGuard debugMutationGuard;
|
|
|
|
#endif
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
PRInt32 increment;
|
2008-08-18 09:47:12 -07:00
|
|
|
nsIContent * const * stopPtr;
|
2008-06-02 20:17:35 -07:00
|
|
|
if (aIsFromEnd) {
|
2008-08-18 09:47:12 -07:00
|
|
|
stopPtr = curChildPtr - 1;
|
2008-10-29 13:40:04 -07:00
|
|
|
curChildPtr = stopPtr + childCount;
|
2008-06-02 20:17:35 -07:00
|
|
|
increment = -1;
|
|
|
|
} else {
|
|
|
|
increment = 1;
|
2008-08-18 09:47:12 -07:00
|
|
|
stopPtr = curChildPtr + childCount;
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
|
2008-08-18 09:47:12 -07:00
|
|
|
for ( ; ; curChildPtr += increment) {
|
|
|
|
if (curChildPtr == stopPtr) {
|
2008-06-02 20:17:35 -07:00
|
|
|
// mContent is the root of an anonymous content subtree.
|
|
|
|
result = 0; // special value to indicate that it is not at any index
|
|
|
|
break;
|
|
|
|
}
|
2008-08-18 09:47:12 -07:00
|
|
|
nsIContent* child = *curChildPtr;
|
2010-04-30 06:12:06 -07:00
|
|
|
if (child == mElement)
|
2008-06-02 20:17:35 -07:00
|
|
|
break;
|
2010-04-30 06:12:06 -07:00
|
|
|
if (child->IsElement() &&
|
2008-06-02 20:17:35 -07:00
|
|
|
(!aIsOfType ||
|
|
|
|
(child->Tag() == mContentTag &&
|
2009-06-09 00:41:19 -07:00
|
|
|
child->GetNameSpaceID() == mNameSpaceID))) {
|
2008-06-02 20:17:35 -07:00
|
|
|
if (aCheckEdgeOnly) {
|
|
|
|
// The caller only cares whether or not the result is 1, and we
|
|
|
|
// now know it's not.
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-02 20:17:35 -07:00
|
|
|
++result;
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
|
2008-09-05 10:39:19 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(!debugMutationGuard.Mutated(0), "Unexpected mutations happened");
|
|
|
|
#endif
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
slot = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
/**
|
|
|
|
* A |TreeMatchContext| has data about matching a selector (containing
|
|
|
|
* combinators) against a node and the tree that that node is in. It
|
|
|
|
* contains both input to and output from the matching.
|
|
|
|
*/
|
|
|
|
struct TreeMatchContext {
|
|
|
|
// Is this matching operation for the creation of a style context?
|
|
|
|
// (If it is, we need to set slow selector bits on nodes indicating
|
|
|
|
// that certain restyling needs to happen.)
|
|
|
|
const PRBool mForStyling;
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
// Did this matching operation find a relevant link? (If so, we'll
|
|
|
|
// need to construct a StyleIfVisited.)
|
|
|
|
PRBool mHaveRelevantLink;
|
|
|
|
|
2010-04-02 18:58:27 -07:00
|
|
|
nsRuleWalker::VisitedHandlingType mVisitedHandling;
|
|
|
|
|
|
|
|
TreeMatchContext(PRBool aForStyling,
|
|
|
|
nsRuleWalker::VisitedHandlingType aVisitedHandling)
|
2010-04-02 18:58:26 -07:00
|
|
|
: mForStyling(aForStyling)
|
2010-04-02 18:58:26 -07:00
|
|
|
, mHaveRelevantLink(PR_FALSE)
|
2010-04-02 18:58:27 -07:00
|
|
|
, mVisitedHandling(aVisitedHandling)
|
2010-04-02 18:58:26 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
// NOTE: For |aStateMask| to work correctly, it's important that any
|
|
|
|
// change that changes multiple state bits include all those state
|
|
|
|
// bits in the notification. Otherwise, if multiple states change but
|
|
|
|
// we do separate notifications then we might determine the style is
|
|
|
|
// not state-dependent when it really is (e.g., determining that a
|
|
|
|
// :hover:active rule no longer matches when both states are unset).
|
|
|
|
const PRInt32 mStateMask;
|
|
|
|
|
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.)
|
|
|
|
const PRBool mIsRelevantLink;
|
|
|
|
|
|
|
|
NodeMatchContext(PRInt32 aStateMask, PRBool 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
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool ValueIncludes(const nsSubstring& aValueList,
|
|
|
|
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))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
++p; // we know the next character is not whitespace
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether we should apply a "global" (i.e., universal-tag)
|
|
|
|
// selector for event states in quirks mode. Note that
|
2009-12-10 14:36:03 -08:00
|
|
|
// |data.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.
|
|
|
|
inline PRBool IsQuirkEventSensitive(nsIAtom *aContentTag)
|
|
|
|
{
|
|
|
|
return PRBool ((nsGkAtoms::button == aContentTag) ||
|
|
|
|
(nsGkAtoms::img == aContentTag) ||
|
|
|
|
(nsGkAtoms::input == aContentTag) ||
|
|
|
|
(nsGkAtoms::label == aContentTag) ||
|
|
|
|
(nsGkAtoms::select == aContentTag) ||
|
|
|
|
(nsGkAtoms::textarea == aContentTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-18 22:17:07 -08:00
|
|
|
static inline PRBool
|
|
|
|
IsSignificantChild(nsIContent* aChild, PRBool aTextIsSignificant,
|
|
|
|
PRBool 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.
|
|
|
|
static PRBool AttrMatchesValue(const nsAttrSelector* aAttrSelector,
|
2009-09-28 23:07:45 -07:00
|
|
|
const nsString& aValue, PRBool 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))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
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");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:41 -08:00
|
|
|
static inline PRBool
|
2010-04-02 18:58:26 -07:00
|
|
|
edgeChildMatches(RuleProcessorData& data, TreeMatchContext& aTreeMatchContext,
|
2009-12-10 23:37:41 -08:00
|
|
|
PRBool checkFirst, PRBool checkLast)
|
|
|
|
{
|
|
|
|
nsIContent *parent = data.mParentContent;
|
|
|
|
if (!parent) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2009-12-10 23:37:41 -08:00
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
|
|
|
|
|
|
|
return (!checkFirst ||
|
|
|
|
data.GetNthIndex(PR_FALSE, PR_FALSE, PR_TRUE) == 1) &&
|
|
|
|
(!checkLast ||
|
|
|
|
data.GetNthIndex(PR_FALSE, PR_TRUE, PR_TRUE) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline PRBool
|
2010-04-02 18:58:26 -07:00
|
|
|
nthChildGenericMatches(RuleProcessorData& data,
|
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2009-12-10 23:37:41 -08:00
|
|
|
nsPseudoClassList* pseudoClass,
|
|
|
|
PRBool isOfType, PRBool isFromEnd)
|
|
|
|
{
|
|
|
|
nsIContent *parent = data.mParentContent;
|
|
|
|
if (!parent) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-10 23:37:41 -08:00
|
|
|
if (isFromEnd)
|
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
|
|
|
else
|
2010-05-14 22:01:46 -07:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const PRInt32 index = data.GetNthIndex(isOfType, isFromEnd, PR_FALSE);
|
|
|
|
if (index <= 0) {
|
|
|
|
// Node is anonymous content (not really a child of its parent).
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRInt32 a = pseudoClass->u.mNumbers[0];
|
|
|
|
const PRInt32 b = pseudoClass->u.mNumbers[1];
|
|
|
|
// result should be true if there exists n >= 0 such that
|
|
|
|
// a * n + b == index.
|
|
|
|
if (a == 0) {
|
|
|
|
return b == index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integer division in C does truncation (towards 0). So
|
|
|
|
// check that the result is nonnegative, and that there was no
|
|
|
|
// truncation.
|
|
|
|
const PRInt32 n = (index - b) / a;
|
|
|
|
return n >= 0 && (a * n == index - b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline PRBool
|
2010-04-02 18:58:26 -07:00
|
|
|
edgeOfTypeMatches(RuleProcessorData& data, TreeMatchContext& aTreeMatchContext,
|
2009-12-10 23:37:41 -08:00
|
|
|
PRBool checkFirst, PRBool checkLast)
|
|
|
|
{
|
|
|
|
nsIContent *parent = data.mParentContent;
|
|
|
|
if (!parent) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling) {
|
2009-12-10 23:37:41 -08:00
|
|
|
if (checkLast)
|
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
|
|
|
else
|
2010-05-14 22:01:46 -07:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2009-12-10 23:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (!checkFirst ||
|
|
|
|
data.GetNthIndex(PR_TRUE, PR_FALSE, PR_TRUE) == 1) &&
|
|
|
|
(!checkLast ||
|
|
|
|
data.GetNthIndex(PR_TRUE, PR_TRUE, PR_TRUE) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline PRBool
|
2010-04-02 18:58:26 -07:00
|
|
|
checkGenericEmptyMatches(RuleProcessorData& data,
|
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2009-12-10 23:37:41 -08:00
|
|
|
PRBool isWhitespaceSignificant)
|
|
|
|
{
|
|
|
|
nsIContent *child = nsnull;
|
2010-04-30 06:12:06 -07:00
|
|
|
Element *element = data.mElement;
|
2009-12-10 23:37:41 -08:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2009-12-10 23:37:41 -08:00
|
|
|
element->SetFlags(NODE_HAS_EMPTY_SELECTOR);
|
|
|
|
|
|
|
|
do {
|
|
|
|
child = element->GetChildAt(++index);
|
|
|
|
// stop at first non-comment (and non-whitespace for
|
|
|
|
// :-moz-only-whitespace) node
|
|
|
|
} while (child && !IsSignificantChild(child, PR_TRUE, isWhitespaceSignificant));
|
|
|
|
return (child == nsnull);
|
|
|
|
}
|
|
|
|
|
2010-04-26 13:27:01 -07:00
|
|
|
// An array of the bits that are relevant for various pseudoclasses.
|
|
|
|
static const PRUint32 sPseudoClassBits[] = {
|
2009-12-10 23:37:41 -08:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value) \
|
2010-04-26 13:27:01 -07:00
|
|
|
0,
|
2009-12-10 23:37:41 -08:00
|
|
|
#define CSS_STATE_PSEUDO_CLASS(_name, _value, _bit) \
|
2010-04-26 13:27:01 -07:00
|
|
|
_bit,
|
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-04-26 13:27:01 -07:00
|
|
|
0,
|
|
|
|
0
|
2009-12-10 23:37:41 -08:00
|
|
|
};
|
2010-04-26 13:27:01 -07:00
|
|
|
PR_STATIC_ASSERT(NS_ARRAY_LENGTH(sPseudoClassBits) ==
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1);
|
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
|
2009-12-10 14:36:03 -08:00
|
|
|
// because of aStateMask
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool SelectorMatches(RuleProcessorData &data,
|
|
|
|
nsCSSSelector* aSelector,
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext& aNodeMatchContext,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
2010-04-26 13:27:01 -07:00
|
|
|
PRBool* const aDependence = nsnull)
|
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 &&
|
2009-08-01 08:53:40 -07:00
|
|
|
data.mNameSpaceID != aSelector->mNameSpace))
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-09-28 23:07:45 -07:00
|
|
|
if (aSelector->mLowercaseTag &&
|
2009-12-10 14:36:03 -08:00
|
|
|
(data.mIsHTML ? aSelector->mLowercaseTag : aSelector->mCasedTag) !=
|
2009-09-28 23:07:45 -07:00
|
|
|
data.mContentTag) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:02 -08:00
|
|
|
nsAtomList* IDList = aSelector->mIDList;
|
|
|
|
if (IDList) {
|
2009-12-10 14:36:03 -08:00
|
|
|
if (data.mContentID) {
|
2009-12-10 14:36:02 -08:00
|
|
|
// case sensitivity: bug 93371
|
|
|
|
const PRBool isCaseSensitive =
|
|
|
|
data.mCompatMode != eCompatibility_NavQuirks;
|
|
|
|
|
|
|
|
if (isCaseSensitive) {
|
|
|
|
do {
|
|
|
|
if (IDList->mAtom != data.mContentID) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
nsDependentAtomString id1Str(data.mContentID);
|
2009-12-10 14:36:02 -08:00
|
|
|
do {
|
2010-03-08 07:45:00 -08:00
|
|
|
if (!nsContentUtils::EqualsIgnoreASCIICase(id1Str,
|
|
|
|
nsDependentAtomString(IDList->mAtom))) {
|
2009-12-10 14:36:02 -08:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Element has no id but we have an id selector
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomList* classList = aSelector->mClassList;
|
|
|
|
if (classList) {
|
|
|
|
// test for class match
|
2009-12-10 14:36:03 -08:00
|
|
|
const nsAttrValue *elementClasses = data.mClasses;
|
|
|
|
if (!elementClasses) {
|
|
|
|
// Element has no classes but we have a class selector
|
|
|
|
return PR_FALSE;
|
2009-12-10 14:36:02 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 14:36:03 -08:00
|
|
|
// case sensitivity: bug 93371
|
|
|
|
const PRBool isCaseSensitive =
|
|
|
|
data.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)) {
|
|
|
|
return PR_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRBool isNegated = (aDependence != nsnull);
|
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-04-02 18:58:26 -07:00
|
|
|
NS_ASSERTION(aNodeMatchContext.mStateMask == 0 ||
|
|
|
|
!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
|
2008-06-02 20:17:35 -07:00
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector->mPseudoClassList;
|
2009-12-10 23:37:41 -08:00
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
2010-04-26 13:27:01 -07:00
|
|
|
PRInt32 statesToCheck = sPseudoClassBits[pseudoClass->mType];
|
|
|
|
if (!statesToCheck) {
|
|
|
|
// keep the cases here in the same order as the list in
|
|
|
|
// nsCSSPseudoClassList.h
|
|
|
|
switch (pseudoClass->mType) {
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_empty:
|
|
|
|
if (!checkGenericEmptyMatches(data, aTreeMatchContext, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozOnlyWhitespace:
|
|
|
|
if (!checkGenericEmptyMatches(data, aTreeMatchContext, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozEmptyExceptChildrenWithLocalname:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(pseudoClass->u.mString, "Must have string!");
|
|
|
|
nsIContent *child = nsnull;
|
2010-04-30 06:12:06 -07:00
|
|
|
Element *element = data.mElement;
|
2010-04-26 13:27:01 -07:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
|
|
|
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).
|
2010-04-26 13:27:01 -07:00
|
|
|
element->SetFlags(NODE_HAS_SLOW_SELECTOR);
|
|
|
|
do {
|
|
|
|
child = element->GetChildAt(++index);
|
|
|
|
} while (child &&
|
|
|
|
(!IsSignificantChild(child, PR_TRUE, PR_FALSE) ||
|
|
|
|
(child->GetNameSpaceID() == element->GetNameSpaceID() &&
|
|
|
|
child->Tag()->Equals(nsDependentString(pseudoClass->u.mString)))));
|
|
|
|
if (child != nsnull) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lang:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != pseudoClass->u.mString, "null lang parameter");
|
|
|
|
if (!pseudoClass->u.mString || !*pseudoClass->u.mString) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
const nsString* lang = data.GetLang();
|
|
|
|
if (lang && !lang->IsEmpty()) { // null check for out-of-memory
|
|
|
|
if (!nsStyleUtil::DashMatchCompare(*lang,
|
|
|
|
nsDependentString(pseudoClass->u.mString),
|
2010-08-02 15:19:04 -07:00
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
2010-04-26 13:27:01 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// This pseudo-class matched; move on to the next thing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIDocument* doc = data.mElement->GetDocument();
|
2010-04-26 13:27:01 -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.
|
|
|
|
nsAutoString language;
|
|
|
|
doc->GetContentLanguage(language);
|
|
|
|
|
|
|
|
nsDependentString langString(pseudoClass->u.mString);
|
|
|
|
language.StripWhitespace();
|
|
|
|
PRInt32 begin = 0;
|
|
|
|
PRInt32 len = language.Length();
|
|
|
|
while (begin < len) {
|
|
|
|
PRInt32 end = language.FindChar(PRUnichar(','), begin);
|
|
|
|
if (end == kNotFound) {
|
|
|
|
end = len;
|
|
|
|
}
|
|
|
|
if (nsStyleUtil::DashMatchCompare(Substring(language, begin,
|
|
|
|
end-begin),
|
|
|
|
langString,
|
2010-08-02 15:19:04 -07:00
|
|
|
nsASCIICaseInsensitiveStringComparator())) {
|
2010-04-26 13:27:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
begin = end + 1;
|
|
|
|
}
|
|
|
|
if (begin < len) {
|
|
|
|
// This pseudo-class matched
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:41 -08:00
|
|
|
return PR_FALSE;
|
2009-12-10 18:28:08 -08:00
|
|
|
}
|
2010-04-26 13:27:01 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozBoundElement:
|
2010-04-30 06:12:06 -07:00
|
|
|
if (data.mScopedRoot != data.mElement) {
|
2010-04-26 13:27:01 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_root:
|
|
|
|
if (data.mParentContent != nsnull ||
|
2010-04-30 06:12:06 -07:00
|
|
|
data.mElement != data.mElement->GetOwnerDoc()->GetRootElement()) {
|
2010-04-26 13:27:01 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_any:
|
|
|
|
{
|
|
|
|
nsCSSSelectorList *l;
|
|
|
|
for (l = pseudoClass->u.mSelectors; l; l = l->mNext) {
|
|
|
|
nsCSSSelector *s = l->mSelectors;
|
|
|
|
NS_ABORT_IF_FALSE(!s->mNext && !s->IsPseudoElement(),
|
|
|
|
"parser failed");
|
|
|
|
if (SelectorMatches(data, s, aNodeMatchContext, aTreeMatchContext)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!l) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstChild:
|
|
|
|
if (!edgeChildMatches(data, aTreeMatchContext, PR_TRUE, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstNode:
|
|
|
|
{
|
|
|
|
nsIContent *firstNode = nsnull;
|
|
|
|
nsIContent *parent = data.mParentContent;
|
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
|
|
|
|
|
|
|
PRInt32 index = -1;
|
|
|
|
do {
|
|
|
|
firstNode = parent->GetChildAt(++index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (firstNode &&
|
|
|
|
!IsSignificantChild(firstNode, PR_TRUE, PR_FALSE));
|
|
|
|
}
|
2010-04-30 06:12:06 -07:00
|
|
|
if (data.mElement != firstNode) {
|
2010-04-26 13:27:01 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastChild:
|
|
|
|
if (!edgeChildMatches(data, aTreeMatchContext, PR_FALSE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastNode:
|
|
|
|
{
|
|
|
|
nsIContent *lastNode = nsnull;
|
|
|
|
nsIContent *parent = data.mParentContent;
|
|
|
|
if (parent) {
|
|
|
|
if (aTreeMatchContext.mForStyling)
|
|
|
|
parent->SetFlags(NODE_HAS_EDGE_CHILD_SELECTOR);
|
|
|
|
|
|
|
|
PRUint32 index = parent->GetChildCount();
|
|
|
|
do {
|
|
|
|
lastNode = parent->GetChildAt(--index);
|
|
|
|
// stop at first non-comment and non-whitespace node
|
|
|
|
} while (lastNode &&
|
|
|
|
!IsSignificantChild(lastNode, PR_TRUE, PR_FALSE));
|
|
|
|
}
|
2010-04-30 06:12:06 -07:00
|
|
|
if (data.mElement != lastNode) {
|
2010-04-26 13:27:01 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyChild:
|
|
|
|
if (!edgeChildMatches(data, aTreeMatchContext, PR_TRUE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_firstOfType:
|
|
|
|
if (!edgeOfTypeMatches(data, aTreeMatchContext, PR_TRUE, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_lastOfType:
|
|
|
|
if (!edgeOfTypeMatches(data, aTreeMatchContext, PR_FALSE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_onlyOfType:
|
|
|
|
if (!edgeOfTypeMatches(data, aTreeMatchContext, PR_TRUE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthChild:
|
|
|
|
if (!nthChildGenericMatches(data, aTreeMatchContext, pseudoClass,
|
|
|
|
PR_FALSE, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastChild:
|
|
|
|
if (!nthChildGenericMatches(data, aTreeMatchContext, pseudoClass,
|
|
|
|
PR_FALSE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthOfType:
|
|
|
|
if (!nthChildGenericMatches(data, aTreeMatchContext, pseudoClass,
|
|
|
|
PR_TRUE, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_nthLastOfType:
|
|
|
|
if (!nthChildGenericMatches(data, aTreeMatchContext, pseudoClass,
|
|
|
|
PR_TRUE, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozHasHandlerRef:
|
|
|
|
{
|
|
|
|
nsIContent *child = nsnull;
|
2010-04-30 06:12:06 -07:00
|
|
|
Element *element = data.mElement;
|
2010-04-26 13:27:01 -07:00
|
|
|
PRInt32 index = -1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
child = element->GetChildAt(++index);
|
|
|
|
if (child && child->IsHTML() &&
|
|
|
|
child->Tag() == nsGkAtoms::param &&
|
|
|
|
child->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
NS_LITERAL_STRING("pluginurl"),
|
|
|
|
eIgnoreCase)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (child);
|
|
|
|
if (!child) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozIsHTML:
|
|
|
|
if (!data.mIsHTML) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozSystemMetric:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> metric = do_GetAtom(pseudoClass->u.mString);
|
|
|
|
if (!nsCSSRuleProcessor::HasSystemMetric(metric)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLocaleDir:
|
|
|
|
{
|
|
|
|
PRBool docIsRTL =
|
|
|
|
(data.DocumentState() & NS_DOCUMENT_STATE_RTL_LOCALE) != 0;
|
|
|
|
|
|
|
|
nsDependentString dirString(pseudoClass->u.mString);
|
|
|
|
NS_ASSERTION(dirString.EqualsLiteral("ltr") ||
|
|
|
|
dirString.EqualsLiteral("rtl"),
|
|
|
|
"invalid value for -moz-locale-dir");
|
|
|
|
|
|
|
|
if (dirString.EqualsLiteral("rtl") != docIsRTL) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWTheme:
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIDocument* doc = data.mElement->GetOwnerDoc();
|
2010-04-26 13:27:01 -07:00
|
|
|
if (!doc ||
|
|
|
|
doc->GetDocumentLWTheme() <= nsIDocument::Doc_Theme_None) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeBrightText:
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIDocument* doc = data.mElement->GetOwnerDoc();
|
2010-04-26 13:27:01 -07:00
|
|
|
if (!doc ||
|
|
|
|
doc->GetDocumentLWTheme() != nsIDocument::Doc_Theme_Bright) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozLWThemeDarkText:
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIDocument* doc = data.mElement->GetOwnerDoc();
|
2010-04-26 13:27:01 -07:00
|
|
|
if (!doc ||
|
|
|
|
doc->GetDocumentLWTheme() != nsIDocument::Doc_Theme_Dark) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsCSSPseudoClasses::ePseudoClass_mozWindowInactive:
|
|
|
|
if ((data.DocumentState() & NS_DOCUMENT_STATE_WINDOW_INACTIVE) == 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "How did that happen?");
|
|
|
|
}
|
2009-12-10 23:37:41 -08:00
|
|
|
} else {
|
2010-04-26 13:27:01 -07:00
|
|
|
// Bit-based pseudo-classes
|
2009-12-15 16:04:12 -08:00
|
|
|
if ((statesToCheck & (NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
data.mCompatMode == eCompatibility_NavQuirks &&
|
|
|
|
// global selector (but don't check .class):
|
2009-08-01 08:53:40 -07:00
|
|
|
!aSelector->HasTagSelector() && !aSelector->mIDList &&
|
|
|
|
!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|:
|
2009-12-10 14:36:03 -08:00
|
|
|
data.mIsHTMLContent && !data.IsLink() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!IsQuirkEventSensitive(data.mContentTag)) {
|
|
|
|
// In quirks mode, only make certain elements sensitive to
|
|
|
|
// selectors ":hover" and ":active".
|
2009-12-10 23:37:41 -08:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aNodeMatchContext.mStateMask & statesToCheck) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDependence)
|
|
|
|
*aDependence = PR_TRUE;
|
|
|
|
} else {
|
2010-04-02 18:58:27 -07:00
|
|
|
PRUint32 contentState = data.GetContentStateForVisitedHandling(
|
|
|
|
aTreeMatchContext.mVisitedHandling,
|
|
|
|
aNodeMatchContext.mIsRelevantLink);
|
|
|
|
if (!(contentState & statesToCheck)) {
|
2009-12-10 23:37:41 -08:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:41 -08:00
|
|
|
PRBool result = PR_TRUE;
|
|
|
|
if (aSelector->mAttrList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// test for attribute match
|
2009-12-10 14:36:03 -08:00
|
|
|
if (!data.mHasAttributes) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// if no attributes on the content, no match
|
2009-12-10 14:36:03 -08:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
result = PR_TRUE;
|
|
|
|
nsAttrSelector* attr = aSelector->mAttrList;
|
2009-09-28 23:07:45 -07:00
|
|
|
nsIAtom* matchAttribute;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
2009-12-10 14:36:03 -08:00
|
|
|
matchAttribute = data.mIsHTML ? 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.
|
2010-04-30 06:12:06 -07:00
|
|
|
PRUint32 attrCount = data.mElement->GetAttrCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
result = PR_FALSE;
|
|
|
|
for (PRUint32 i = 0; i < attrCount; ++i) {
|
|
|
|
const nsAttrName* attrName =
|
2010-04-30 06:12:06 -07:00
|
|
|
data.mElement->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) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool hasAttr =
|
|
|
|
#endif
|
2010-04-30 06:12:06 -07:00
|
|
|
data.mElement->GetAttr(attrName->NamespaceID(),
|
2007-03-22 10:30:00 -07:00
|
|
|
attrName->LocalName(), value);
|
|
|
|
NS_ASSERTION(hasAttr, "GetAttrNameAt lied");
|
2009-12-10 14:36:03 -08:00
|
|
|
result = AttrMatchesValue(attr, value, data.mIsHTML);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point |result| has been set by us
|
|
|
|
// explicitly in this loop. If it's PR_FALSE, we may still match
|
|
|
|
// -- the content may have another attribute with the same name but
|
|
|
|
// in a different namespace. But if it's PR_TRUE, we are done (we
|
|
|
|
// can short-circuit the boolean OR described above).
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr->mFunction == NS_ATTR_FUNC_EQUALS) {
|
|
|
|
result =
|
2010-04-30 06:12:06 -07:00
|
|
|
data.mElement->
|
2009-09-28 23:07:45 -07:00
|
|
|
AttrValueIs(attr->mNameSpace, matchAttribute, attr->mValue,
|
2009-12-10 14:36:03 -08:00
|
|
|
(!data.mIsHTML || attr->mCaseSensitive) ? eCaseMatters
|
|
|
|
: eIgnoreCase);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-30 06:12:06 -07:00
|
|
|
else if (!data.mElement->HasAttr(attr->mNameSpace, matchAttribute)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (attr->mFunction != NS_ATTR_FUNC_SET) {
|
|
|
|
nsAutoString value;
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool hasAttr =
|
|
|
|
#endif
|
2010-04-30 06:12:06 -07:00
|
|
|
data.mElement->GetAttr(attr->mNameSpace, matchAttribute, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hasAttr, "HasAttr lied");
|
2009-12-10 14:36:03 -08:00
|
|
|
result = AttrMatchesValue(attr, value, data.mIsHTML);
|
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) {
|
|
|
|
for (nsCSSSelector *negation = aSelector->mNegations;
|
|
|
|
result && negation; negation = negation->mNegations) {
|
|
|
|
PRBool dependence = PR_FALSE;
|
2010-04-02 18:58:26 -07:00
|
|
|
result = !SelectorMatches(data, negation, aNodeMatchContext,
|
2010-04-02 18:58:26 -07:00
|
|
|
aTreeMatchContext, &dependence);
|
2009-12-10 14:36:03 -08:00
|
|
|
// If the selector does match due to the dependence on aStateMask,
|
|
|
|
// then we want to keep result true so that the final result of
|
|
|
|
// SelectorMatches is true. Doing so tells StateEnumFunc that
|
|
|
|
// there is a dependence on the state.
|
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
|
|
|
|
|
|
|
static PRBool SelectorMatchesTree(RuleProcessorData& aPrevData,
|
2008-07-21 17:55:52 -07:00
|
|
|
nsCSSSelector* aSelector,
|
2010-04-02 18:58:26 -07:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
|
|
|
PRBool aLookForRelevantLink)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSSelector* selector = aSelector;
|
|
|
|
RuleProcessorData* prevdata = &aPrevData;
|
|
|
|
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
|
|
|
// If we don't already have a RuleProcessorData for the next
|
|
|
|
// appropriate content (whether parent or previous sibling), create
|
|
|
|
// one.
|
|
|
|
|
|
|
|
// for adjacent sibling combinators, the content to test against the
|
|
|
|
// selector is the previous sibling *element*
|
|
|
|
RuleProcessorData* data;
|
|
|
|
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.
|
|
|
|
aLookForRelevantLink = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
data = prevdata->mPreviousSiblingData;
|
|
|
|
if (!data) {
|
2009-12-10 14:36:03 -08:00
|
|
|
nsIContent* parent = prevdata->mParentContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parent) {
|
2010-04-02 18:58:26 -07:00
|
|
|
if (aTreeMatchContext.mForStyling)
|
2010-05-14 22:01:46 -07:00
|
|
|
parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
2008-02-18 22:17:07 -08:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
PRInt32 index = parent->IndexOf(prevdata->mElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (0 <= --index) {
|
2010-04-30 06:12:06 -07:00
|
|
|
nsIContent* content = parent->GetChildAt(index);
|
|
|
|
if (content->IsElement()) {
|
|
|
|
data = RuleProcessorData::Create(prevdata->mPresContext,
|
|
|
|
content->AsElement(),
|
2008-07-21 17:55:52 -07:00
|
|
|
prevdata->mRuleWalker,
|
|
|
|
prevdata->mCompatMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
prevdata->mPreviousSiblingData = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// for descendant combinators and child combinators, the content
|
|
|
|
// to test against is the parent
|
|
|
|
else {
|
|
|
|
data = prevdata->mParentData;
|
|
|
|
if (!data) {
|
2009-12-10 14:36:03 -08:00
|
|
|
nsIContent *content = prevdata->mParentContent;
|
2008-06-05 16:06:34 -07:00
|
|
|
// GetParent could return a document fragment; we only want
|
|
|
|
// element parents.
|
2010-04-30 06:12:06 -07:00
|
|
|
if (content && content->IsElement()) {
|
|
|
|
data = RuleProcessorData::Create(prevdata->mPresContext,
|
|
|
|
content->AsElement(),
|
2008-07-21 17:55:52 -07:00
|
|
|
prevdata->mRuleWalker,
|
|
|
|
prevdata->mCompatMode);
|
2009-12-10 14:36:03 -08:00
|
|
|
prevdata->mParentData = data;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! data) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext nodeContext(0, aLookForRelevantLink && data->IsLink());
|
|
|
|
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.
|
|
|
|
aLookForRelevantLink = PR_FALSE;
|
|
|
|
aTreeMatchContext.mHaveRelevantLink = PR_TRUE;
|
|
|
|
}
|
2010-04-02 18:58:26 -07:00
|
|
|
if (SelectorMatches(*data, 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 == '~' &&
|
2010-03-31 11:08:09 -07:00
|
|
|
(selector->mNext->mOperator == PRUnichar(' ') ||
|
2009-08-20 14:52:47 -07:00
|
|
|
selector->mNext->mOperator == PRUnichar('>')))) {
|
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...)
|
2010-04-02 18:58:26 -07:00
|
|
|
if (SelectorMatchesTree(*data, selector, aTreeMatchContext,
|
|
|
|
aLookForRelevantLink)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)) {
|
|
|
|
return PR_FALSE; // parent was required to match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevdata = data;
|
|
|
|
}
|
|
|
|
return PR_TRUE; // all the selectors matched.
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ContentEnumFunc(nsICSSStyleRule* aRule, nsCSSSelector* aSelector,
|
|
|
|
void* aData)
|
|
|
|
{
|
2009-12-10 23:37:40 -08:00
|
|
|
RuleProcessorData* data = (RuleProcessorData*)aData;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-02 18:58:27 -07:00
|
|
|
TreeMatchContext treeContext(PR_TRUE, data->mRuleWalker->VisitedHandling());
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext nodeContext(0, data->IsLink());
|
|
|
|
if (nodeContext.mIsRelevantLink) {
|
|
|
|
treeContext.mHaveRelevantLink = PR_TRUE;
|
|
|
|
}
|
2010-04-02 18:58:26 -07:00
|
|
|
if (SelectorMatches(*data, aSelector, nodeContext, treeContext)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSSelector *next = aSelector->mNext;
|
2010-04-02 18:58:26 -07:00
|
|
|
if (!next || SelectorMatchesTree(*data, next, treeContext,
|
|
|
|
!nodeContext.mIsRelevantLink)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// for performance, require that every implementation of
|
|
|
|
// nsICSSStyleRule return the same pointer for nsIStyleRule (why
|
|
|
|
// would anything multiply inherit nsIStyleRule anyway?)
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(aRule);
|
2007-07-08 00:08:04 -07:00
|
|
|
NS_ASSERTION(static_cast<nsIStyleRule*>(aRule) == iRule.get(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Please fix QI so this performance optimization is valid");
|
|
|
|
#endif
|
2009-12-11 08:13:19 -08:00
|
|
|
aRule->RuleMatched();
|
2007-07-08 00:08:04 -07:00
|
|
|
data->mRuleWalker->Forward(static_cast<nsIStyleRule*>(aRule));
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsStyleSet will deal with the !important rule
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 18:58:27 -07:00
|
|
|
|
|
|
|
if (treeContext.mHaveRelevantLink) {
|
|
|
|
data->mRuleWalker->SetHaveRelevantLink();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
cascade->mRuleHash.EnumerateAllRules(aData->mNameSpaceID,
|
|
|
|
aData->mContentTag,
|
|
|
|
aData->mContentID,
|
|
|
|
aData->mClasses,
|
|
|
|
ContentEnumFunc,
|
|
|
|
aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
ruleHash->EnumerateAllRules(aData->mNameSpaceID,
|
|
|
|
aData->mContentTag,
|
|
|
|
aData->mContentID,
|
|
|
|
aData->mClasses,
|
|
|
|
ContentEnumFunc,
|
|
|
|
aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-10 23:37:40 -08:00
|
|
|
// for performance, require that every implementation of
|
|
|
|
// nsICSSStyleRule return the same pointer for nsIStyleRule (why
|
|
|
|
// would anything multiply inherit nsIStyleRule anyway?)
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(value->mRule);
|
|
|
|
NS_ASSERTION(static_cast<nsIStyleRule*>(value->mRule) == iRule.get(),
|
|
|
|
"Please fix QI so this performance optimization is valid");
|
|
|
|
#endif
|
2009-12-11 08:13:19 -08:00
|
|
|
value->mRule->RuleMatched();
|
2009-12-10 23:37:40 -08:00
|
|
|
aData->mRuleWalker->Forward(static_cast<nsIStyleRule*>(value->mRule));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
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)) {
|
2009-12-10 23:37:40 -08:00
|
|
|
ContentEnumFunc(value->mRule, value->mSelector->mNext,
|
|
|
|
static_cast<RuleProcessorData*>(aData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
// |IsStateSelector| below determines which selectors are in
|
|
|
|
// |cascade->mStateSelectors|.
|
2010-03-31 17:43:32 -07:00
|
|
|
nsRestyleHint hint = nsRestyleHint(0);
|
2009-02-03 06:42:18 -08:00
|
|
|
if (cascade) {
|
|
|
|
nsCSSSelector **iter = cascade->mStateSelectors.Elements(),
|
|
|
|
**end = iter + cascade->mStateSelectors.Length();
|
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
nsCSSSelector* selector = *iter;
|
|
|
|
|
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.
|
2010-04-02 18:58:27 -07:00
|
|
|
TreeMatchContext treeContext(PR_FALSE,
|
|
|
|
nsRuleWalker::eLinksVisitedOrUnvisited);
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext nodeContext(aData->mStateMask, PR_FALSE);
|
2009-12-11 22:36:34 -08:00
|
|
|
if ((possibleChange & ~hint) &&
|
2010-04-02 18:58:26 -07:00
|
|
|
SelectorMatches(*aData, selector, nodeContext, treeContext) &&
|
2010-04-02 18:58:26 -07:00
|
|
|
SelectorMatchesTree(*aData, selector->mNext, treeContext, PR_FALSE))
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2010-03-17 10:10:57 -07:00
|
|
|
PRBool
|
|
|
|
nsCSSRuleProcessor::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
|
|
|
|
|
|
|
|
return cascade && (cascade->mSelectorDocumentStates & aData->mStateMask) != 0;
|
|
|
|
}
|
|
|
|
|
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.
|
2010-04-02 18:58:27 -07:00
|
|
|
TreeMatchContext treeContext(PR_FALSE,
|
|
|
|
nsRuleWalker::eLinksVisitedOrUnvisited);
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext nodeContext(0, PR_FALSE);
|
2009-02-03 06:42:18 -08:00
|
|
|
if ((possibleChange & ~(aData->change)) &&
|
2010-04-02 18:58:26 -07:00
|
|
|
SelectorMatches(*data, aSelector, nodeContext, treeContext) &&
|
2010-04-02 18:58:26 -07:00
|
|
|
SelectorMatchesTree(*data, aSelector->mNext, treeContext, PR_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) &&
|
|
|
|
aData->mNameSpaceID == kNameSpaceID_XUL &&
|
2010-04-30 06:12:06 -07:00
|
|
|
aData->mElement == aData->mElement->GetOwnerDoc()->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
|
|
|
}
|
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()) {
|
2009-02-03 06:42:18 -08:00
|
|
|
nsCSSSelector **iter = cascade->mIDSelectors.Elements(),
|
|
|
|
**end = iter + cascade->mIDSelectors.Length();
|
|
|
|
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()) {
|
2010-06-18 09:23:05 -07:00
|
|
|
const nsAttrValue* elementClasses = aData->mClasses;
|
|
|
|
if (elementClasses) {
|
|
|
|
PRInt32 atomCount = elementClasses->GetAtomCount();
|
|
|
|
for (PRInt32 i = 0; i < atomCount; ++i) {
|
|
|
|
nsIAtom* curClass = elementClasses->AtomAt(i);
|
|
|
|
ClassSelectorEntry *entry =
|
|
|
|
static_cast<ClassSelectorEntry*>
|
|
|
|
(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
|
|
|
}
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>
|
|
|
|
(PL_DHashTableOperate(&cascade->mAttributeSelectors, aData->mAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2009-02-03 06:42:18 -08:00
|
|
|
nsCSSSelector **iter = entry->mSelectors->Elements(),
|
|
|
|
**end = iter + entry->mSelectors->Length();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ PRBool
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
PRBool
|
|
|
|
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))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_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;
|
|
|
|
mRuleCascades = nsnull;
|
|
|
|
while (data) {
|
|
|
|
RuleCascadeData *next = data->mNext;
|
|
|
|
delete data;
|
|
|
|
data = next;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This function should return true only for selectors that need to be
|
|
|
|
// checked by |HasStateDependentStyle|.
|
|
|
|
inline
|
|
|
|
PRBool IsStateSelector(nsCSSSelector& aSelector)
|
|
|
|
{
|
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;
|
|
|
|
}
|
2010-04-26 13:27:01 -07:00
|
|
|
if (sPseudoClassBits[pseudoClass->mType]) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-17 10:10:57 -07:00
|
|
|
inline
|
|
|
|
void AddSelectorDocumentStates(nsCSSSelector& aSelector, PRUint32* aStateMask)
|
|
|
|
{
|
|
|
|
for (nsPseudoClassList* pseudoClass = aSelector.mPseudoClassList;
|
|
|
|
pseudoClass; pseudoClass = pseudoClass->mNext) {
|
|
|
|
if (pseudoClass->mAtom == nsCSSPseudoClasses::mozLocaleDir) {
|
|
|
|
*aStateMask |= NS_DOCUMENT_STATE_RTL_LOCALE;
|
|
|
|
}
|
|
|
|
else if (pseudoClass->mAtom == nsCSSPseudoClasses::mozWindowInactive) {
|
|
|
|
*aStateMask |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 19:59:47 -07:00
|
|
|
static PRBool
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// Track the selectors that depend on document states.
|
|
|
|
AddSelectorDocumentStates(*aSelectorPart, &aCascade->mSelectorDocumentStates);
|
|
|
|
|
|
|
|
// Build mStateSelectors.
|
|
|
|
if (IsStateSelector(*aSelectorPart))
|
|
|
|
aCascade->mStateSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
|
|
|
|
// Build mIDSelectors
|
|
|
|
if (aSelectorPart->mIDList) {
|
|
|
|
aCascade->mIDSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build mClassSelectors
|
2010-06-18 09:23:05 -07:00
|
|
|
if (aSelectorPart == aSelectorInTopLevel) {
|
|
|
|
for (nsAtomList* curClass = aSelectorPart->mClassList; curClass;
|
|
|
|
curClass = curClass->mNext) {
|
|
|
|
ClassSelectorEntry *entry =
|
|
|
|
static_cast<ClassSelectorEntry*>(PL_DHashTableOperate(&aCascade->mClassSelectors,
|
|
|
|
curClass->mAtom,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (entry) {
|
|
|
|
entry->mSelectors.AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (aSelectorPart->mClassList) {
|
|
|
|
aCascade->mPossiblyNegatedClassSelectors.AppendElement(aSelectorInTopLevel);
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build mAttributeSelectors.
|
|
|
|
for (nsAttrSelector *attr = aSelectorPart->mAttrList; attr;
|
|
|
|
attr = attr->mNext) {
|
|
|
|
nsTArray<nsCSSSelector*> *array =
|
|
|
|
aCascade->AttributeListFor(attr->mCasedAttr);
|
|
|
|
if (!array) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
if (attr->mLowercaseAttr != attr->mCasedAttr) {
|
|
|
|
nsTArray<nsCSSSelector*> *array =
|
|
|
|
aCascade->AttributeListFor(attr->mLowercaseAttr);
|
|
|
|
if (!array) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
array->AppendElement(aSelectorInTopLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recur through any :-moz-any selectors
|
|
|
|
for (nsPseudoClassList* pseudoClass = aSelectorPart->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)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
static PRBool
|
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();
|
2009-12-10 23:37:40 -08:00
|
|
|
if (NS_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
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
RuleValue(*aRuleInfo, 0));
|
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,
|
|
|
|
RuleValue(*aRuleInfo, 0));
|
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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07: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 = selector; negation;
|
|
|
|
negation = negation->mNegations) {
|
2010-04-23 19:59:47 -07:00
|
|
|
if (!AddSelector(cascade, selector, negation)) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
struct PerWeightData {
|
|
|
|
PRInt32 mWeight;
|
2010-07-02 13:56:09 -07:00
|
|
|
nsTArray<RuleSelectorPair> mRules; // forward order
|
2007-12-14 14:59:20 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RuleByWeightEntry : public PLDHashEntryHdr {
|
|
|
|
PerWeightData data; // mWeight is key, mRules are value
|
|
|
|
};
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PRBool
|
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
|
|
|
}
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
static PRBool
|
|
|
|
InitWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
RuleByWeightEntry* entry = static_cast<RuleByWeightEntry*>(hdr);
|
|
|
|
new (entry) RuleByWeightEntry();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClearWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
RuleByWeightEntry* entry = static_cast<RuleByWeightEntry*>(hdr);
|
|
|
|
entry->~RuleByWeightEntry();
|
|
|
|
}
|
|
|
|
|
2007-12-14 14:59:20 -08:00
|
|
|
static PLDHashTableOps gRulesByWeightOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
HashIntKey,
|
|
|
|
MatchWeightEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
2010-07-02 13:56:09 -07:00
|
|
|
ClearWeightEntry,
|
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,
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey& aKey,
|
2008-11-26 19:50:16 -08:00
|
|
|
PLArenaPool& aArena,
|
|
|
|
PRUint8 aSheetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mPresContext(aPresContext),
|
2008-11-25 15:22:38 -08:00
|
|
|
mFontFaceRules(aFontFaceRules),
|
2008-07-26 09:14:48 -07:00
|
|
|
mCacheKey(aKey),
|
2008-11-26 19:50:16 -08:00
|
|
|
mArena(aArena),
|
|
|
|
mSheetType(aSheetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-14 14:59:20 -08:00
|
|
|
if (!PL_DHashTableInit(&mRulesByWeight, &gRulesByWeightOps, nsnull,
|
|
|
|
sizeof(RuleByWeightEntry), 64))
|
|
|
|
mRulesByWeight.ops = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
~CascadeEnumData()
|
|
|
|
{
|
|
|
|
if (mRulesByWeight.ops)
|
|
|
|
PL_DHashTableFinish(&mRulesByWeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* mPresContext;
|
2008-11-26 19:50:16 -08:00
|
|
|
nsTArray<nsFontFaceRuleContainer>& mFontFaceRules;
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey& mCacheKey;
|
2009-05-13 01:26:48 -07: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.
|
|
|
|
PLDHashTable mRulesByWeight; // of RuleValue* linked lists (?)
|
2008-11-26 19:50:16 -08:00
|
|
|
PRUint8 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.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool
|
2008-11-25 15:22:38 -08:00
|
|
|
CascadeRuleEnumFunc(nsICSSRule* aRule, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
2010-07-18 07:39:20 -07:00
|
|
|
PRInt32 type = aRule->GetType();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (nsICSSRule::STYLE_RULE == type) {
|
|
|
|
nsICSSStyleRule* styleRule = (nsICSSStyleRule*)aRule;
|
|
|
|
|
|
|
|
for (nsCSSSelectorList *sel = styleRule->Selector();
|
|
|
|
sel; sel = sel->mNext) {
|
|
|
|
PRInt32 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)
|
|
|
|
return PR_FALSE;
|
|
|
|
entry->data.mWeight = weight;
|
2010-07-02 13:56:09 -07:00
|
|
|
// entry->data.mRules must be in forward order.
|
|
|
|
entry->data.mRules.AppendElement(RuleSelectorPair(styleRule,
|
|
|
|
sel->mSelectors));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsICSSRule::MEDIA_RULE == type ||
|
|
|
|
nsICSSRule::DOCUMENT_RULE == type) {
|
|
|
|
nsICSSGroupRule* groupRule = (nsICSSGroupRule*)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))
|
2007-12-14 14:59:20 -08:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-11-25 15:22:38 -08:00
|
|
|
else if (nsICSSRule::FONT_FACE_RULE == type) {
|
|
|
|
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)
|
|
|
|
return PR_FALSE;
|
2008-11-26 19:50:16 -08:00
|
|
|
ptr->mRule = fontFaceRule;
|
|
|
|
ptr->mSheetType = data->mSheetType;
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-07 15:10:19 -07:00
|
|
|
/* static */ PRBool
|
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))
|
2008-09-09 11:08:11 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
PRInt32 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,
|
|
|
|
PRUint32 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,
|
|
|
|
newCascade->mCacheKey,
|
2008-11-26 19:50:16 -08:00
|
|
|
newCascade->mRuleHash.Arena(),
|
|
|
|
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
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mSheets.Length(); ++i) {
|
|
|
|
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.
|
|
|
|
PRUint32 weightCount = data.mRulesByWeight.entryCount;
|
|
|
|
nsAutoArrayPtr<PerWeightData> weightArray(new PerWeightData[weightCount]);
|
|
|
|
FillWeightArrayData fwData(weightArray);
|
|
|
|
PL_DHashTableEnumerate(&data.mRulesByWeight, FillWeightArray, &fwData);
|
|
|
|
NS_QuickSort(weightArray, weightCount, sizeof(PerWeightData),
|
|
|
|
CompareWeightData, nsnull);
|
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...
|
2010-07-02 13:56:09 -07:00
|
|
|
for (PRUint32 i = 0; i < weightCount; ++i) {
|
|
|
|
// and the secondary sort is by order. mRules are already in
|
|
|
|
// the right order..
|
|
|
|
nsTArray<RuleSelectorPair>& arr = weightArray[i].mRules;
|
|
|
|
for (RuleSelectorPair *cur = arr.Elements(),
|
|
|
|
*end = cur + arr.Length();
|
|
|
|
cur != end; ++cur) {
|
|
|
|
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
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsCSSRuleProcessor::SelectorListMatches(RuleProcessorData& aData,
|
|
|
|
nsCSSSelectorList* aSelectorList)
|
|
|
|
{
|
|
|
|
while (aSelectorList) {
|
|
|
|
nsCSSSelector* sel = aSelectorList->mSelectors;
|
|
|
|
NS_ASSERTION(sel, "Should have *some* selectors");
|
2009-12-10 23:37:41 -08:00
|
|
|
NS_ASSERTION(!sel->IsPseudoElement(), "Shouldn't have been called");
|
2010-04-02 18:58:27 -07:00
|
|
|
TreeMatchContext treeContext(PR_FALSE,
|
|
|
|
nsRuleWalker::eRelevantLinkUnvisited);
|
2010-04-02 18:58:26 -07:00
|
|
|
NodeMatchContext nodeContext(0, PR_FALSE);
|
2010-04-02 18:58:26 -07:00
|
|
|
if (SelectorMatches(aData, sel, nodeContext, treeContext)) {
|
2008-07-21 17:55:52 -07:00
|
|
|
nsCSSSelector* next = sel->mNext;
|
2010-04-02 18:58:26 -07:00
|
|
|
if (!next || SelectorMatchesTree(aData, next, treeContext, PR_FALSE)) {
|
2008-07-21 17:55:52 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aSelectorList = aSelectorList->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|