2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing data from presentational
|
|
|
|
* HTML attributes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsHTMLStyleSheet.h"
|
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStates.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsRuleData.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2009-08-01 08:53:40 -07:00
|
|
|
#include "nsRuleProcessorData.h"
|
2011-03-29 10:29:21 -07:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-05-30 01:00:20 -07:00
|
|
|
#include "nsHashKeys.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "RestyleManager.h"
|
2010-04-30 06:12:06 -07:00
|
|
|
|
2013-05-30 01:00:20 -07:00
|
|
|
using namespace mozilla;
|
2010-04-30 06:12:06 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::HTMLColorRule, nsIStyleRule)
|
|
|
|
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* color = aRuleData->ValueForColor();
|
|
|
|
if (color->GetUnit() == eCSSUnit_Null &&
|
2007-11-15 19:46:42 -08:00
|
|
|
aRuleData->mPresContext->UseDocumentColors())
|
2011-03-17 20:14:31 -07:00
|
|
|
color->SetColorValue(mColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-20 13:22:35 -08:00
|
|
|
fputs("[html color rule] {}\n", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLStyleSheet::GenericTableRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-20 13:22:35 -08:00
|
|
|
fputs("[generic table rule] {}\n", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::TableTHRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* textAlign = aRuleData->ValueForTextAlign();
|
|
|
|
if (textAlign->GetUnit() == eCSSUnit_Null) {
|
|
|
|
textAlign->SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT,
|
|
|
|
eCSSUnit_Enumerated);
|
2009-02-05 19:48:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 04:43:31 -07:00
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLStyleSheet::TableQuirkColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
|
|
|
|
nsCSSValue* color = aRuleData->ValueForColor();
|
|
|
|
// We do not check UseDocumentColors() here, because we want to
|
|
|
|
// use the body color no matter what.
|
|
|
|
if (color->GetUnit() == eCSSUnit_Null)
|
|
|
|
color->SetIntValue(NS_STYLE_COLOR_INHERIT_FROM_BODY,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:00:20 -07:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::LangRule, nsIStyleRule)
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLStyleSheet::LangRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
|
|
|
|
nsCSSValue* lang = aRuleData->ValueForLang();
|
|
|
|
if (lang->GetUnit() == eCSSUnit_Null) {
|
|
|
|
lang->SetStringValue(mLang, eCSSUnit_Ident);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLStyleSheet::LangRule::List(FILE* out, int32_t aIndent) const
|
|
|
|
{
|
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
fputs("[lang rule] { language: \"", out);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(mLang).get(), out);
|
|
|
|
fputs("\" }\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
struct MappedAttrTableEntry : public PLDHashEntryHdr {
|
|
|
|
nsMappedAttributes *mAttributes;
|
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashNumber
|
2007-03-22 10:30:00 -07:00
|
|
|
MappedAttrTable_HashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
nsMappedAttributes *attributes =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMappedAttributes*>(const_cast<void*>(key));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return attributes->HashValue();
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
MappedAttrTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>(hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
entry->mAttributes->DropStyleSheetReference();
|
|
|
|
memset(entry, 0, sizeof(MappedAttrTableEntry));
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
MappedAttrTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
nsMappedAttributes *attributes =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMappedAttributes*>(const_cast<void*>(key));
|
2007-03-22 10:30:00 -07:00
|
|
|
const MappedAttrTableEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<const MappedAttrTableEntry*>(hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return attributes->Equals(entry->mAttributes);
|
|
|
|
}
|
|
|
|
|
2013-11-18 18:51:48 -08:00
|
|
|
static const PLDHashTableOps MappedAttrTable_Ops = {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
MappedAttrTable_HashKey,
|
|
|
|
MappedAttrTable_MatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
MappedAttrTable_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
2013-05-30 01:00:20 -07:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
struct LangRuleTableEntry : public PLDHashEntryHdr {
|
|
|
|
nsRefPtr<nsHTMLStyleSheet::LangRule> mRule;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashNumber
|
|
|
|
LangRuleTable_HashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
return HashString(*lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LangRuleTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
LangRuleTableEntry *entry = static_cast<LangRuleTableEntry*>(hdr);
|
|
|
|
|
|
|
|
entry->~LangRuleTableEntry();
|
|
|
|
memset(entry, 0, sizeof(LangRuleTableEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
LangRuleTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
const LangRuleTableEntry *entry = static_cast<const LangRuleTableEntry*>(hdr);
|
|
|
|
|
|
|
|
return entry->mRule->mLang == *lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
LangRuleTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
|
|
|
|
LangRuleTableEntry *entry = new (hdr) LangRuleTableEntry();
|
|
|
|
|
|
|
|
// Create the unique rule for this language
|
|
|
|
entry->mRule = new nsHTMLStyleSheet::LangRule(*lang);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-18 18:51:48 -08:00
|
|
|
static const PLDHashTableOps LangRuleTable_Ops = {
|
2013-05-30 01:00:20 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
LangRuleTable_HashKey,
|
|
|
|
LangRuleTable_MatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
LangRuleTable_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
LangRuleTable_InitEntry
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2013-06-13 22:34:37 -07:00
|
|
|
nsHTMLStyleSheet::nsHTMLStyleSheet(nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument)
|
2012-08-04 00:44:01 -07:00
|
|
|
, mTableQuirkColorRule(new TableQuirkColorRule())
|
|
|
|
, mTableTHRule(new TableTHRule())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDocument);
|
2012-07-30 07:20:58 -07:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
2013-05-30 01:00:20 -07:00
|
|
|
mLangRuleTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLStyleSheet::~nsHTMLStyleSheet()
|
|
|
|
{
|
2013-05-30 01:00:20 -07:00
|
|
|
if (mLangRuleTable.ops)
|
|
|
|
PL_DHashTableFinish(&mLangRuleTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mMappedAttrTable.ops)
|
|
|
|
PL_DHashTableFinish(&mMappedAttrTable);
|
|
|
|
}
|
|
|
|
|
2013-06-13 22:34:37 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet, nsIStyleRuleProcessor)
|
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
|
|
|
nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
nsRuleWalker *ruleWalker = aData->mRuleWalker;
|
2013-03-27 19:47:25 -07:00
|
|
|
if (aData->mElement->IsHTML() && !ruleWalker->AuthorStyleDisabled()) {
|
2011-03-29 10:29:21 -07:00
|
|
|
nsIAtom* tag = aData->mElement->Tag();
|
2010-04-30 06:12:06 -07:00
|
|
|
|
|
|
|
// if we have anchor colors, check if this is an anchor with an href
|
|
|
|
if (tag == nsGkAtoms::a) {
|
|
|
|
if (mLinkRule || mVisitedRule || mActiveRule) {
|
2011-03-29 10:29:21 -07:00
|
|
|
nsEventStates state = nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
|
|
|
aData->mElement,
|
2012-03-29 23:16:22 -07:00
|
|
|
aData->mTreeMatchContext,
|
2011-03-29 10:29:21 -07:00
|
|
|
aData->mTreeMatchContext.VisitedHandling(),
|
2010-04-30 06:12:06 -07:00
|
|
|
// If the node being matched is a link,
|
|
|
|
// it's the relevant link.
|
2011-03-29 10:29:21 -07:00
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2010-10-20 04:26:32 -07:00
|
|
|
if (mLinkRule && state.HasState(NS_EVENT_STATE_UNVISITED)) {
|
2010-04-30 06:12:06 -07:00
|
|
|
ruleWalker->Forward(mLinkRule);
|
2011-03-29 10:29:21 -07:00
|
|
|
aData->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-30 06:12:06 -07:00
|
|
|
}
|
2010-10-20 04:26:32 -07:00
|
|
|
else if (mVisitedRule && state.HasState(NS_EVENT_STATE_VISITED)) {
|
2010-04-30 06:12:06 -07:00
|
|
|
ruleWalker->Forward(mVisitedRule);
|
2011-03-29 10:29:21 -07:00
|
|
|
aData->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-30 06:12:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
// No need to add to the active rule if it's not a link
|
2011-03-29 10:29:21 -07:00
|
|
|
if (mActiveRule && nsCSSRuleProcessor::IsLink(aData->mElement) &&
|
2010-10-20 04:26:32 -07:00
|
|
|
state.HasState(NS_EVENT_STATE_ACTIVE)) {
|
2010-04-30 06:12:06 -07:00
|
|
|
ruleWalker->Forward(mActiveRule);
|
|
|
|
}
|
|
|
|
} // end link/visited/active rules
|
|
|
|
} // end A tag
|
|
|
|
// add the rule to handle text-align for a <th>
|
|
|
|
else if (tag == nsGkAtoms::th) {
|
|
|
|
ruleWalker->Forward(mTableTHRule);
|
|
|
|
}
|
|
|
|
else if (tag == nsGkAtoms::table) {
|
2011-03-29 10:29:21 -07:00
|
|
|
if (aData->mTreeMatchContext.mCompatMode == eCompatibility_NavQuirks) {
|
2011-06-01 04:43:31 -07:00
|
|
|
ruleWalker->Forward(mTableQuirkColorRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-30 06:12:06 -07:00
|
|
|
}
|
|
|
|
} // end html element
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-27 19:47:25 -07:00
|
|
|
// just get the style rules from the content. For SVG we do this even if
|
|
|
|
// author style is disabled, because SVG presentational hints aren't
|
|
|
|
// considered style.
|
|
|
|
if (!ruleWalker->AuthorStyleDisabled() || aData->mElement->IsSVG()) {
|
|
|
|
aData->mElement->WalkContentStyleRules(ruleWalker);
|
|
|
|
}
|
2013-05-30 01:00:20 -07:00
|
|
|
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#language
|
|
|
|
// says that the xml:lang attribute overrides HTML's lang attribute,
|
|
|
|
// so we need to do this after WalkContentStyleRules.
|
|
|
|
nsString lang;
|
|
|
|
if (aData->mElement->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang, lang)) {
|
|
|
|
ruleWalker->Forward(LangRuleFor(lang));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-11 22:36:34 -08:00
|
|
|
nsHTMLStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-29 10:29:21 -07:00
|
|
|
if (aData->mElement->IsHTML(nsGkAtoms::a) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement) &&
|
2010-10-20 04:26:32 -07:00
|
|
|
((mActiveRule && aData->mStateMask.HasState(NS_EVENT_STATE_ACTIVE)) ||
|
|
|
|
(mLinkRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)) ||
|
|
|
|
(mVisitedRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)))) {
|
2010-06-18 09:23:05 -07:00
|
|
|
return eRestyle_Self;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-11 22:36:34 -08:00
|
|
|
|
2010-03-31 17:43:32 -07:00
|
|
|
return nsRestyleHint(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-27 22:46:39 -08:00
|
|
|
/* virtual */ nsRestyleHint
|
|
|
|
nsHTMLStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-03-17 10:10:57 -07:00
|
|
|
nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-17 10:10:57 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-10 14:36:03 -08:00
|
|
|
nsHTMLStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 14:36:03 -08:00
|
|
|
// Do nothing on before-change checks
|
|
|
|
if (!aData->mAttrHasChanged) {
|
2010-03-31 17:43:32 -07:00
|
|
|
return nsRestyleHint(0);
|
2009-12-10 14:36:03 -08:00
|
|
|
}
|
|
|
|
|
2007-07-12 13:05:45 -07:00
|
|
|
// Note: no need to worry about whether some states changed with this
|
|
|
|
// attribute here, because we handle that under HasStateDependentStyle() as
|
|
|
|
// needed.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Result is true for |href| changes on HTML links if we have link rules.
|
2010-04-30 06:12:06 -07:00
|
|
|
Element *element = aData->mElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aData->mAttribute == nsGkAtoms::href &&
|
|
|
|
(mLinkRule || mVisitedRule || mActiveRule) &&
|
2011-03-29 10:29:21 -07:00
|
|
|
element->IsHTML(nsGkAtoms::a)) {
|
2010-06-18 09:23:05 -07:00
|
|
|
return eRestyle_Self;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't worry about the mDocumentColorRule since it only applies
|
|
|
|
// to descendants of body, when we're already reresolving.
|
|
|
|
|
|
|
|
// Handle the content style rules.
|
2010-04-30 06:12:06 -07:00
|
|
|
if (element->IsAttributeMapped(aData->mAttribute)) {
|
2010-08-25 11:54:47 -07:00
|
|
|
// cellpadding on tables is special and requires reresolving all
|
|
|
|
// the cells in the table
|
|
|
|
if (aData->mAttribute == nsGkAtoms::cellpadding &&
|
2011-03-29 10:29:21 -07:00
|
|
|
element->IsHTML(nsGkAtoms::table)) {
|
2010-08-25 11:54:47 -07:00
|
|
|
return eRestyle_Subtree;
|
|
|
|
}
|
2010-06-18 09:23:05 -07:00
|
|
|
return eRestyle_Self;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 17:43:32 -07:00
|
|
|
return nsRestyleHint(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-07-18 14:20:40 -07:00
|
|
|
nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 09:14:48 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsHTMLStyleSheet::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
|
|
|
return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsHTMLStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-08-01 11:25:20 -07:00
|
|
|
{
|
|
|
|
return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
2009-12-10 23:37:40 -08:00
|
|
|
{
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-13 22:34:37 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mDocument = aDocument; // not refcounted
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
void
|
2013-06-13 22:34:37 -07:00
|
|
|
nsHTMLStyleSheet::Reset()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mLinkRule = nullptr;
|
|
|
|
mVisitedRule = nullptr;
|
|
|
|
mActiveRule = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-30 01:00:20 -07:00
|
|
|
if (mLangRuleTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mLangRuleTable);
|
|
|
|
mLangRuleTable.ops = nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mMappedAttrTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mMappedAttrTable);
|
2012-07-30 07:20:58 -07:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-06-18 09:23:05 -07:00
|
|
|
nsHTMLStyleSheet::ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-18 09:23:05 -07:00
|
|
|
if (aRule && aRule->mColor == aColor) {
|
2010-06-25 06:59:57 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
aRule = new HTMLColorRule();
|
|
|
|
if (!aRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
aRule->mColor = aColor;
|
|
|
|
// Now make sure we restyle any links that might need it. This
|
|
|
|
// shouldn't happen often, so just rebuilding everything is ok.
|
2010-06-25 06:59:57 -07:00
|
|
|
if (mDocument && mDocument->GetShell()) {
|
2010-06-18 09:23:05 -07:00
|
|
|
Element* root = mDocument->GetRootElement();
|
|
|
|
if (root) {
|
2013-07-20 12:14:25 -07:00
|
|
|
mDocument->GetShell()->GetPresContext()->RestyleManager()->
|
2010-06-18 09:23:05 -07:00
|
|
|
PostRestyleEvent(root, eRestyle_Subtree, NS_STYLE_HINT_NONE);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-06-18 09:23:05 -07:00
|
|
|
nsHTMLStyleSheet::SetLinkColor(nscolor aColor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-18 09:23:05 -07:00
|
|
|
return ImplLinkColorSetter(mLinkRule, aColor);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
return ImplLinkColorSetter(mActiveRule, aColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor)
|
|
|
|
{
|
2010-06-18 09:23:05 -07:00
|
|
|
return ImplLinkColorSetter(mVisitedRule, aColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsMappedAttributes>
|
|
|
|
nsHTMLStyleSheet::UniqueMappedAttributes(nsMappedAttributes* aMapped)
|
|
|
|
{
|
|
|
|
if (!mMappedAttrTable.ops) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool res = PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, sizeof(MappedAttrTableEntry), 16);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!res) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_ADD));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!entry->mAttributes) {
|
|
|
|
// We added a new entry to the hashtable, so we have a new unique set.
|
|
|
|
entry->mAttributes = aMapped;
|
|
|
|
}
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<nsMappedAttributes> ret = entry->mAttributes;
|
|
|
|
return ret.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)
|
|
|
|
{
|
2012-12-23 20:45:57 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(aMapped);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mMappedAttrTable.ops, "table uninitialized");
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t entryCount = mMappedAttrTable.entryCount - 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_REMOVE);
|
|
|
|
|
|
|
|
NS_ASSERTION(entryCount == mMappedAttrTable.entryCount, "not removed");
|
|
|
|
}
|
|
|
|
|
2013-05-30 01:00:20 -07:00
|
|
|
nsIStyleRule*
|
|
|
|
nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage)
|
|
|
|
{
|
|
|
|
if (!mLangRuleTable.ops) {
|
|
|
|
bool res = PL_DHashTableInit(&mLangRuleTable, &LangRuleTable_Ops,
|
|
|
|
nullptr, sizeof(LangRuleTableEntry), 16);
|
|
|
|
if (!res) {
|
|
|
|
NS_ASSERTION(false, "out of memory");
|
|
|
|
mLangRuleTable.ops = nullptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LangRuleTableEntry *entry = static_cast<LangRuleTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mLangRuleTable, &aLanguage, PL_DHASH_ADD));
|
|
|
|
if (!entry) {
|
|
|
|
NS_ASSERTION(false, "out of memory");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return entry->mRule;
|
|
|
|
}
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
static size_t
|
|
|
|
SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
|
2013-06-23 05:03:39 -07:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-02-01 13:58:01 -08:00
|
|
|
void* aArg)
|
2011-07-19 09:40:18 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aEntry, "The entry should not be null!");
|
|
|
|
|
|
|
|
MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(aEntry);
|
|
|
|
NS_ASSERTION(entry->mAttributes, "entry->mAttributes should not be null!");
|
2012-02-01 13:58:01 -08:00
|
|
|
return entry->mAttributes->SizeOfIncludingThis(aMallocSizeOf);
|
2011-07-19 09:40:18 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsHTMLStyleSheet::DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-07-19 09:40:18 -07:00
|
|
|
{
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2011-07-19 09:40:18 -07:00
|
|
|
|
|
|
|
if (mMappedAttrTable.ops) {
|
2012-02-01 13:58:01 -08:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mMappedAttrTable,
|
|
|
|
SizeOfAttributesEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
2011-07-19 09:40:18 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mURL
|
|
|
|
// - mLinkRule
|
|
|
|
// - mVisitedRule
|
|
|
|
// - mActiveRule
|
|
|
|
// - mTableQuirkColorRule
|
|
|
|
// - mTableTHRule
|
2013-05-30 01:00:20 -07:00
|
|
|
// - mLangRuleTable
|
2012-02-01 13:58:01 -08:00
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mDocument, because it's non-owning
|
|
|
|
|
|
|
|
return n;
|
2011-07-19 09:40:18 -07:00
|
|
|
}
|