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"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-06-18 09:23:05 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashTableOps MappedAttrTable_Ops = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
MappedAttrTable_HashKey,
|
|
|
|
MappedAttrTable_MatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
MappedAttrTable_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2012-08-04 00:44:01 -07:00
|
|
|
nsHTMLStyleSheet::nsHTMLStyleSheet(nsIURI* aURL, nsIDocument* aDocument)
|
|
|
|
: mURL(aURL)
|
|
|
|
, mDocument(aDocument)
|
|
|
|
, mTableQuirkColorRule(new TableQuirkColorRule())
|
|
|
|
, mTableTHRule(new TableTHRule())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aURL);
|
|
|
|
MOZ_ASSERT(aDocument);
|
2012-07-30 07:20:58 -07:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLStyleSheet::~nsHTMLStyleSheet()
|
|
|
|
{
|
|
|
|
if (mMappedAttrTable.ops)
|
|
|
|
PL_DHashTableFinish(&mMappedAttrTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
|
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsHTMLStyleSheet::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
nsHTMLStyleSheet::SizeOfIncludingThis(nsMallocSizeOfFun 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
|
|
|
|
|
|
|
// nsIStyleSheet api
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLStyleSheet::GetSheetURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLStyleSheet::GetBaseURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType.AssignLiteral("text/html");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::HasRules() const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true; // We have rules at all reasonable times
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-05-14 12:05:14 -07:00
|
|
|
nsHTMLStyleSheet::IsApplicable() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLStyleSheet::SetEnabled(bool aEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{ // these can't be disabled
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-05-14 12:05:14 -07:00
|
|
|
nsHTMLStyleSheet::IsComplete() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::SetComplete()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIStyleSheet*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLStyleSheet::GetParentSheet() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIDocument*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLStyleSheet::GetOwningDocument() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ 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
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLStyleSheet::Reset(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
mURL = aURL;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mLinkRule = nullptr;
|
|
|
|
mVisitedRule = nullptr;
|
|
|
|
mActiveRule = 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) {
|
2010-06-25 06:59:57 -07:00
|
|
|
mDocument->GetShell()->FrameConstructor()->
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLStyleSheet::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fputs("HTML Style Sheet: ", out);
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString urlSpec;
|
2007-03-22 10:30:00 -07:00
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
static size_t
|
|
|
|
SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
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
|
|
|
|
nsHTMLStyleSheet::DOMSizeOfIncludingThis(nsMallocSizeOfFun 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
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mDocument, because it's non-owning
|
|
|
|
|
|
|
|
return n;
|
2011-07-19 09:40:18 -07:00
|
|
|
}
|