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