1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00: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/.
|
2000-05-02 23:07:11 +00: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.
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing data from presentational
|
|
|
|
* HTML attributes
|
|
|
|
*/
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
#include "nsMappedAttributes.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2011-04-21 17:35:52 +00:00
|
|
|
#include "nsEventStates.h"
|
1998-07-25 01:20:48 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-09-10 19:32:14 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsRuleWalker.h"
|
2004-07-20 06:11:27 +00:00
|
|
|
#include "nsRuleData.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2009-08-01 15:53:40 +00:00
|
|
|
#include "nsRuleProcessorData.h"
|
2011-03-29 17:29:21 +00:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-06-18 16:23:05 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2010-04-30 13:12:06 +00:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::HTMLColorRule, nsIStyleRule)
|
1998-07-25 01:20:48 +00:00
|
|
|
|
2010-05-20 02:28:00 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
1999-04-15 21:23:05 +00:00
|
|
|
{
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
|
2011-03-18 03:14:31 +00:00
|
|
|
nsCSSValue* color = aRuleData->ValueForColor();
|
|
|
|
if (color->GetUnit() == eCSSUnit_Null &&
|
2007-11-16 03:46:42 +00:00
|
|
|
aRuleData->mPresContext->UseDocumentColors())
|
2011-03-18 03:14:31 +00:00
|
|
|
color->SetColorValue(mColor);
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
1998-07-25 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2010-05-20 02:28:00 +00:00
|
|
|
/* virtual */ void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, int32_t aIndent) const
|
1999-07-07 04:53:36 +00:00
|
|
|
{
|
2012-11-20 19:55:14 +00:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-20 21:22:35 +00:00
|
|
|
fputs("[html color rule] {}\n", out);
|
1999-07-07 04:53:36 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2006-08-25 22:33:17 +00:00
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule)
|
1999-06-07 21:09:07 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2010-05-20 02:28:00 +00:00
|
|
|
/* virtual */ void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLStyleSheet::GenericTableRule::List(FILE* out, int32_t aIndent) const
|
2000-02-16 01:08:54 +00:00
|
|
|
{
|
2012-11-20 19:55:14 +00:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-20 21:22:35 +00:00
|
|
|
fputs("[generic table rule] {}\n", out);
|
2000-02-16 01:08:54 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2010-05-20 02:28:00 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::TableTHRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
2001-05-31 22:19:43 +00:00
|
|
|
{
|
2007-10-08 21:58:22 +00:00
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
|
2011-03-18 03:14:31 +00:00
|
|
|
nsCSSValue* textAlign = aRuleData->ValueForTextAlign();
|
|
|
|
if (textAlign->GetUnit() == eCSSUnit_Null) {
|
|
|
|
textAlign->SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT,
|
|
|
|
eCSSUnit_Enumerated);
|
2009-02-06 03:48:29 +00:00
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
1999-06-07 21:09:07 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 11:43:31 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-27 00:50:52 +00:00
|
|
|
// -----------------------------------------------------------
|
1998-07-25 01:20:48 +00:00
|
|
|
|
2002-08-17 12:17:03 +00:00
|
|
|
struct MappedAttrTableEntry : public PLDHashEntryHdr {
|
2004-01-26 19:22:05 +00:00
|
|
|
nsMappedAttributes *mAttributes;
|
1998-09-02 02:10:44 +00:00
|
|
|
};
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashNumber
|
2002-08-17 12:17:03 +00:00
|
|
|
MappedAttrTable_HashKey(PLDHashTable *table, const void *key)
|
1998-09-02 02:10:44 +00:00
|
|
|
{
|
2004-01-26 19:22:05 +00:00
|
|
|
nsMappedAttributes *attributes =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsMappedAttributes*>(const_cast<void*>(key));
|
1998-09-02 02:10:44 +00:00
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
return attributes->HashValue();
|
1998-09-02 02:10:44 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static void
|
2002-08-17 12:17:03 +00:00
|
|
|
MappedAttrTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
1998-09-02 02:10:44 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>(hdr);
|
1998-09-02 02:10:44 +00:00
|
|
|
|
2002-08-17 12:17:03 +00:00
|
|
|
entry->mAttributes->DropStyleSheetReference();
|
|
|
|
memset(entry, 0, sizeof(MappedAttrTableEntry));
|
1998-09-02 02:10:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2002-08-17 12:17:03 +00:00
|
|
|
MappedAttrTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
2004-01-26 19:22:05 +00:00
|
|
|
nsMappedAttributes *attributes =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsMappedAttributes*>(const_cast<void*>(key));
|
2002-08-17 12:17:03 +00:00
|
|
|
const MappedAttrTableEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<const MappedAttrTableEntry*>(hdr);
|
2002-08-17 12:17:03 +00:00
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
return attributes->Equals(entry->mAttributes);
|
2002-08-17 12:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashTableOps MappedAttrTable_Ops = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
MappedAttrTable_HashKey,
|
|
|
|
MappedAttrTable_MatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
MappedAttrTable_ClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
NULL
|
|
|
|
};
|
1998-09-02 02:10:44 +00:00
|
|
|
|
1998-12-29 03:38:16 +00:00
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2012-08-04 07:44:01 +00: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 14:20:58 +00:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
2001-08-04 02:43:05 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::~nsHTMLStyleSheet()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2002-08-17 12:17:03 +00:00
|
|
|
if (mMappedAttrTable.ops)
|
|
|
|
PL_DHashTableFinish(&mMappedAttrTable);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2004-08-05 18:26:14 +00:00
|
|
|
nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2010-04-30 13:12:06 +00:00
|
|
|
nsRuleWalker *ruleWalker = aData->mRuleWalker;
|
2013-03-28 02:47:25 +00:00
|
|
|
if (aData->mElement->IsHTML() && !ruleWalker->AuthorStyleDisabled()) {
|
2011-03-29 17:29:21 +00:00
|
|
|
nsIAtom* tag = aData->mElement->Tag();
|
2010-04-30 13:12:06 +00: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 17:29:21 +00:00
|
|
|
nsEventStates state = nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
|
|
|
aData->mElement,
|
2012-03-30 06:16:22 +00:00
|
|
|
aData->mTreeMatchContext,
|
2011-03-29 17:29:21 +00:00
|
|
|
aData->mTreeMatchContext.VisitedHandling(),
|
2010-04-30 13:12:06 +00:00
|
|
|
// If the node being matched is a link,
|
|
|
|
// it's the relevant link.
|
2011-03-29 17:29:21 +00:00
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement));
|
2010-10-20 11:26:32 +00:00
|
|
|
if (mLinkRule && state.HasState(NS_EVENT_STATE_UNVISITED)) {
|
2010-04-30 13:12:06 +00:00
|
|
|
ruleWalker->Forward(mLinkRule);
|
2011-03-29 17:29:21 +00:00
|
|
|
aData->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-30 13:12:06 +00:00
|
|
|
}
|
2010-10-20 11:26:32 +00:00
|
|
|
else if (mVisitedRule && state.HasState(NS_EVENT_STATE_VISITED)) {
|
2010-04-30 13:12:06 +00:00
|
|
|
ruleWalker->Forward(mVisitedRule);
|
2011-03-29 17:29:21 +00:00
|
|
|
aData->mTreeMatchContext.SetHaveRelevantLink();
|
2010-04-30 13:12:06 +00:00
|
|
|
}
|
2001-11-03 08:13:48 +00:00
|
|
|
|
2010-04-30 13:12:06 +00:00
|
|
|
// No need to add to the active rule if it's not a link
|
2011-03-29 17:29:21 +00:00
|
|
|
if (mActiveRule && nsCSSRuleProcessor::IsLink(aData->mElement) &&
|
2010-10-20 11:26:32 +00:00
|
|
|
state.HasState(NS_EVENT_STATE_ACTIVE)) {
|
2010-04-30 13:12:06 +00: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 17:29:21 +00:00
|
|
|
if (aData->mTreeMatchContext.mCompatMode == eCompatibility_NavQuirks) {
|
2011-06-01 11:43:31 +00:00
|
|
|
ruleWalker->Forward(mTableQuirkColorRule);
|
1999-06-07 21:09:07 +00:00
|
|
|
}
|
2010-04-30 13:12:06 +00:00
|
|
|
}
|
|
|
|
} // end html element
|
1998-11-03 20:33:23 +00:00
|
|
|
|
2013-03-28 02:47:25 +00: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);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
// Test if style is dependent on content state
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-12 06:36:34 +00:00
|
|
|
nsHTMLStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
2004-01-14 01:36:35 +00:00
|
|
|
{
|
2011-03-29 17:29:21 +00:00
|
|
|
if (aData->mElement->IsHTML(nsGkAtoms::a) &&
|
2011-03-29 17:29:21 +00:00
|
|
|
nsCSSRuleProcessor::IsLink(aData->mElement) &&
|
2010-10-20 11:26:32 +00: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 16:23:05 +00:00
|
|
|
return eRestyle_Self;
|
2005-08-10 20:21:44 +00:00
|
|
|
}
|
2009-12-12 06:36:34 +00:00
|
|
|
|
2010-04-01 00:43:32 +00:00
|
|
|
return nsRestyleHint(0);
|
1999-04-20 00:05:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-03-17 17:10:57 +00:00
|
|
|
nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-17 17:10:57 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-10 22:36:03 +00:00
|
|
|
nsHTMLStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2003-02-22 16:10:53 +00:00
|
|
|
{
|
2009-12-10 22:36:03 +00:00
|
|
|
// Do nothing on before-change checks
|
|
|
|
if (!aData->mAttrHasChanged) {
|
2010-04-01 00:43:32 +00:00
|
|
|
return nsRestyleHint(0);
|
2009-12-10 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 20:05:45 +00:00
|
|
|
// Note: no need to worry about whether some states changed with this
|
|
|
|
// attribute here, because we handle that under HasStateDependentStyle() as
|
|
|
|
// needed.
|
|
|
|
|
2003-02-22 16:10:53 +00:00
|
|
|
// Result is true for |href| changes on HTML links if we have link rules.
|
2010-04-30 13:12:06 +00:00
|
|
|
Element *element = aData->mElement;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aData->mAttribute == nsGkAtoms::href &&
|
2003-02-22 16:10:53 +00:00
|
|
|
(mLinkRule || mVisitedRule || mActiveRule) &&
|
2011-03-29 17:29:21 +00:00
|
|
|
element->IsHTML(nsGkAtoms::a)) {
|
2010-06-18 16:23:05 +00:00
|
|
|
return eRestyle_Self;
|
2003-02-22 16:10:53 +00:00
|
|
|
}
|
|
|
|
|
2003-06-08 19:52:22 +00:00
|
|
|
// Don't worry about the mDocumentColorRule since it only applies
|
2003-02-22 16:10:53 +00:00
|
|
|
// to descendants of body, when we're already reresolving.
|
|
|
|
|
|
|
|
// Handle the content style rules.
|
2010-04-30 13:12:06 +00:00
|
|
|
if (element->IsAttributeMapped(aData->mAttribute)) {
|
2010-08-25 18:54:47 +00:00
|
|
|
// cellpadding on tables is special and requires reresolving all
|
|
|
|
// the cells in the table
|
|
|
|
if (aData->mAttribute == nsGkAtoms::cellpadding &&
|
2011-03-29 17:29:21 +00:00
|
|
|
element->IsHTML(nsGkAtoms::table)) {
|
2010-08-25 18:54:47 +00:00
|
|
|
return eRestyle_Subtree;
|
|
|
|
}
|
2010-06-18 16:23:05 +00:00
|
|
|
return eRestyle_Self;
|
2003-02-22 16:10:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-01 00:43:32 +00:00
|
|
|
return nsRestyleHint(0);
|
2003-02-22 16:10:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-07-18 21:20:40 +00:00
|
|
|
nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 16:14:48 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-09 05:01:52 +00: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 18:25:20 +00:00
|
|
|
{
|
|
|
|
return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
|
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-11 07:37:40 +00:00
|
|
|
nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-11 07:37:40 +00:00
|
|
|
nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
1998-05-18 21:11:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 07:37:40 +00:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-11 07:37:40 +00:00
|
|
|
nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
2009-12-11 07:37:40 +00:00
|
|
|
{
|
|
|
|
}
|
2009-12-11 07:37:40 +00:00
|
|
|
#endif
|
1998-05-18 21:11:08 +00:00
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
// nsIStyleSheet api
|
2010-05-18 04:00:39 +00:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 20:18:47 +00:00
|
|
|
nsHTMLStyleSheet::GetSheetURI() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2010-05-12 20:18:47 +00:00
|
|
|
return mURL;
|
2004-09-10 06:45:59 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 04:00:39 +00:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 20:18:47 +00:00
|
|
|
nsHTMLStyleSheet::GetBaseURI() const
|
2004-09-10 06:45:59 +00:00
|
|
|
{
|
2010-05-12 20:18:47 +00:00
|
|
|
return mURL;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::GetTitle(nsString& aTitle) const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::GetType(nsString& aType) const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aType.AssignLiteral("text/html");
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::HasRules() const
|
2003-07-04 01:44:24 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true; // We have rules at all reasonable times
|
2003-07-04 01:44:24 +00:00
|
|
|
}
|
1999-06-15 06:21:47 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-05-14 19:05:14 +00:00
|
|
|
nsHTMLStyleSheet::IsApplicable() const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLStyleSheet::SetEnabled(bool aEnabled)
|
1998-11-26 01:34:53 +00:00
|
|
|
{ // these can't be disabled
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-05-14 19:05:14 +00:00
|
|
|
nsHTMLStyleSheet::IsComplete() const
|
2002-12-03 05:48:14 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2002-12-03 05:48:14 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::SetComplete()
|
2002-12-03 05:48:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-18 04:00:39 +00:00
|
|
|
/* virtual */ nsIStyleSheet*
|
2010-05-12 20:18:47 +00:00
|
|
|
nsHTMLStyleSheet::GetParentSheet() const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 04:00:39 +00:00
|
|
|
/* virtual */ nsIDocument*
|
2010-05-12 20:18:47 +00:00
|
|
|
nsHTMLStyleSheet::GetOwningDocument() const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2010-05-12 20:18:47 +00:00
|
|
|
return mDocument;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1998-12-03 20:20:35 +00:00
|
|
|
mDocument = aDocument; // not refcounted
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 04:00:39 +00:00
|
|
|
void
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet::Reset(nsIURI* aURL)
|
1999-02-03 19:38:16 +00:00
|
|
|
{
|
|
|
|
mURL = aURL;
|
2001-11-03 08:13:48 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mLinkRule = nullptr;
|
|
|
|
mVisitedRule = nullptr;
|
|
|
|
mActiveRule = nullptr;
|
1999-07-18 00:30:11 +00:00
|
|
|
|
2002-08-17 12:17:03 +00:00
|
|
|
if (mMappedAttrTable.ops) {
|
|
|
|
PL_DHashTableFinish(&mMappedAttrTable);
|
2012-07-30 14:20:58 +00:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
2002-08-17 12:17:03 +00:00
|
|
|
}
|
1999-02-03 19:38:16 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
nsresult
|
2010-06-18 16:23:05 +00:00
|
|
|
nsHTMLStyleSheet::ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor)
|
1998-07-25 01:20:48 +00:00
|
|
|
{
|
2010-06-18 16:23:05 +00:00
|
|
|
if (aRule && aRule->mColor == aColor) {
|
2010-06-25 13:59:57 +00:00
|
|
|
return NS_OK;
|
1998-07-25 01:20:48 +00:00
|
|
|
}
|
2003-02-22 19:15:46 +00:00
|
|
|
|
2010-06-18 16:23:05 +00:00
|
|
|
aRule = new HTMLColorRule();
|
|
|
|
if (!aRule)
|
2003-02-22 19:15:46 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-06-18 16:23:05 +00: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 13:59:57 +00:00
|
|
|
if (mDocument && mDocument->GetShell()) {
|
2010-06-18 16:23:05 +00:00
|
|
|
Element* root = mDocument->GetRootElement();
|
|
|
|
if (root) {
|
2010-06-25 13:59:57 +00:00
|
|
|
mDocument->GetShell()->FrameConstructor()->
|
2010-06-18 16:23:05 +00:00
|
|
|
PostRestyleEvent(root, eRestyle_Subtree, NS_STYLE_HINT_NONE);
|
|
|
|
}
|
|
|
|
}
|
1998-07-25 01:20:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
nsresult
|
2010-06-18 16:23:05 +00:00
|
|
|
nsHTMLStyleSheet::SetLinkColor(nscolor aColor)
|
1998-07-25 01:20:48 +00:00
|
|
|
{
|
2010-06-18 16:23:05 +00:00
|
|
|
return ImplLinkColorSetter(mLinkRule, aColor);
|
|
|
|
}
|
2003-02-22 19:15:46 +00:00
|
|
|
|
|
|
|
|
2010-06-18 16:23:05 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
return ImplLinkColorSetter(mActiveRule, aColor);
|
1998-07-25 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor)
|
1998-07-25 01:20:48 +00:00
|
|
|
{
|
2010-06-18 16:23:05 +00:00
|
|
|
return ImplLinkColorSetter(mVisitedRule, aColor);
|
1998-07-25 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
already_AddRefed<nsMappedAttributes>
|
|
|
|
nsHTMLStyleSheet::UniqueMappedAttributes(nsMappedAttributes* aMapped)
|
1999-07-07 01:30:43 +00:00
|
|
|
{
|
2002-08-17 12:17:03 +00:00
|
|
|
if (!mMappedAttrTable.ops) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool res = PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, sizeof(MappedAttrTableEntry), 16);
|
2002-08-17 12:17:03 +00:00
|
|
|
if (!res) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mMappedAttrTable.ops = nullptr;
|
|
|
|
return nullptr;
|
2002-08-17 12:17:03 +00:00
|
|
|
}
|
1999-07-07 01:30:43 +00:00
|
|
|
}
|
2007-07-08 07:08:04 +00:00
|
|
|
MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_ADD));
|
2002-08-17 12:17:03 +00:00
|
|
|
if (!entry)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-08-17 12:17:03 +00:00
|
|
|
if (!entry->mAttributes) {
|
|
|
|
// We added a new entry to the hashtable, so we have a new unique set.
|
|
|
|
entry->mAttributes = aMapped;
|
1999-07-07 01:30:43 +00:00
|
|
|
}
|
2013-04-22 11:15:59 +00:00
|
|
|
nsRefPtr<nsMappedAttributes> ret = entry->mAttributes;
|
|
|
|
return ret.forget();
|
1999-07-07 01:30:43 +00:00
|
|
|
}
|
1998-09-02 02:10:44 +00:00
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
void
|
|
|
|
nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)
|
1999-07-07 01:30:43 +00:00
|
|
|
{
|
2012-12-24 04:45:57 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(aMapped);
|
2002-08-17 12:17:03 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mMappedAttrTable.ops, "table uninitialized");
|
|
|
|
#ifdef DEBUG
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t entryCount = mMappedAttrTable.entryCount - 1;
|
2002-08-17 12:17:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_REMOVE);
|
|
|
|
|
|
|
|
NS_ASSERTION(entryCount == mMappedAttrTable.entryCount, "not removed");
|
1998-09-02 02:10:44 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLStyleSheet::List(FILE* out, int32_t aIndent) const
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
1999-02-05 03:57:49 +00:00
|
|
|
// Indent
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
1999-02-05 03:57:49 +00:00
|
|
|
fputs("HTML Style Sheet: ", out);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString urlSpec;
|
2002-03-06 07:48:55 +00:00
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
1999-06-27 21:17:39 +00:00
|
|
|
}
|
1999-02-05 03:57:49 +00:00
|
|
|
fputs("\n", out);
|
1998-09-17 04:07:58 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2012-02-01 21:58:01 +00:00
|
|
|
static size_t
|
|
|
|
SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aArg)
|
2011-07-19 16:40:18 +00: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 21:58:01 +00:00
|
|
|
return entry->mAttributes->SizeOfIncludingThis(aMallocSizeOf);
|
2011-07-19 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 21:58:01 +00:00
|
|
|
size_t
|
|
|
|
nsHTMLStyleSheet::DOMSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-07-19 16:40:18 +00:00
|
|
|
{
|
2012-02-01 21:58:01 +00:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2011-07-19 16:40:18 +00:00
|
|
|
|
|
|
|
if (mMappedAttrTable.ops) {
|
2012-02-01 21:58:01 +00:00
|
|
|
n += PL_DHashTableSizeOfExcludingThis(&mMappedAttrTable,
|
|
|
|
SizeOfAttributesEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
2011-07-19 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 21:58:01 +00: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 16:40:18 +00:00
|
|
|
}
|