1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* ***** END LICENSE BLOCK *****
|
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"
|
1999-02-27 10:18:21 +03:00
|
|
|
#include "nsIEventStateManager.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"
|
2009-12-27 16:48:10 +03:00
|
|
|
#include "nsIHTMLDocument.h"
|
2002-01-08 02:46:07 +03:00
|
|
|
#include "nsIDOMHTMLElement.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"
|
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)) {
|
2007-11-16 06:46:42 +03:00
|
|
|
if (aRuleData->mColorData->mColor.GetUnit() == eCSSUnit_Null &&
|
|
|
|
aRuleData->mPresContext->UseDocumentColors())
|
|
|
|
aRuleData->mColorData->mColor.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
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GenericTableRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
2000-02-16 04:08:54 +03:00
|
|
|
{
|
2001-06-01 02:19:43 +04:00
|
|
|
// Nothing to do.
|
2000-02-16 04:08:54 +03: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)) {
|
2009-02-06 06:48:29 +03:00
|
|
|
if (aRuleData->mTextData->mTextAlign.GetUnit() == eCSSUnit_Null) {
|
|
|
|
aRuleData->mTextData->mTextAlign.
|
|
|
|
SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1999-06-08 01:09:07 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PRBool
|
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();
|
2001-08-04 06:43:05 +04:00
|
|
|
if (!mTableTHRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
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
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
static nsresult GetBodyColor(nsPresContext* aPresContext, nscolor* aColor)
|
2003-06-08 23:52:22 +04:00
|
|
|
{
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *shell = aPresContext->PresShell();
|
2009-12-27 16:48:10 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(shell->GetDocument());
|
|
|
|
if (!htmlDoc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
|
|
|
|
if (!bodyContent)
|
2003-06-08 23:52:22 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame *bodyFrame = bodyContent->GetPrimaryFrame();
|
2003-06-08 23:52:22 +04:00
|
|
|
if (!bodyFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*aColor = bodyFrame->GetStyleColor()->mColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (aData->mIsHTMLContent) {
|
|
|
|
nsIAtom* tag = aData->mContentTag;
|
|
|
|
|
|
|
|
// if we have anchor colors, check if this is an anchor with an href
|
|
|
|
if (tag == nsGkAtoms::a) {
|
|
|
|
if (mLinkRule || mVisitedRule || mActiveRule) {
|
|
|
|
PRUint32 state = aData->GetContentStateForVisitedHandling(
|
|
|
|
ruleWalker->VisitedHandling(),
|
|
|
|
// If the node being matched is a link,
|
|
|
|
// it's the relevant link.
|
|
|
|
aData->IsLink());
|
|
|
|
if (mLinkRule && (state & NS_EVENT_STATE_UNVISITED)) {
|
|
|
|
ruleWalker->Forward(mLinkRule);
|
|
|
|
ruleWalker->SetHaveRelevantLink();
|
|
|
|
}
|
|
|
|
else if (mVisitedRule && (state & NS_EVENT_STATE_VISITED)) {
|
|
|
|
ruleWalker->Forward(mVisitedRule);
|
|
|
|
ruleWalker->SetHaveRelevantLink();
|
|
|
|
}
|
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
|
|
|
|
if (mActiveRule && aData->IsLink() &&
|
|
|
|
(state & NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
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) {
|
|
|
|
if (aData->mCompatMode == eCompatibility_NavQuirks) {
|
|
|
|
nscolor bodyColor;
|
|
|
|
nsresult rv =
|
|
|
|
GetBodyColor(ruleWalker->CurrentNode()->GetPresContext(),
|
|
|
|
&bodyColor);
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
(!mDocumentColorRule || bodyColor != mDocumentColorRule->mColor)) {
|
|
|
|
mDocumentColorRule = new HTMLColorRule();
|
|
|
|
if (mDocumentColorRule) {
|
|
|
|
mDocumentColorRule->mColor = bodyColor;
|
2003-06-08 23:52:22 +04:00
|
|
|
}
|
|
|
|
}
|
2010-04-30 17:12:06 +04:00
|
|
|
if (mDocumentColorRule)
|
|
|
|
ruleWalker->Forward(mDocumentColorRule);
|
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
|
|
|
{
|
2009-12-12 09:36:34 +03:00
|
|
|
if (aData->mIsHTMLContent &&
|
2006-12-26 20:47:52 +03:00
|
|
|
aData->mContentTag == nsGkAtoms::a &&
|
2009-12-11 01:36:03 +03:00
|
|
|
aData->IsLink() &&
|
2005-08-11 00:21:44 +04:00
|
|
|
((mActiveRule && (aData->mStateMask & NS_EVENT_STATE_ACTIVE)) ||
|
|
|
|
(mLinkRule && (aData->mStateMask & NS_EVENT_STATE_VISITED)) ||
|
|
|
|
(mVisitedRule && (aData->mStateMask & 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
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
2010-03-17 20:10:57 +03:00
|
|
|
nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
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) &&
|
2010-04-30 17:12:06 +04:00
|
|
|
element->IsHTML() &&
|
2006-12-26 20:47:52 +03:00
|
|
|
aData->mContentTag == 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-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
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
2010-07-19 01:20:40 +04:00
|
|
|
return PR_FALSE;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::HasRules() const
|
2003-07-04 05:44:24 +04:00
|
|
|
{
|
|
|
|
return PR_TRUE; // We have rules at all reasonable times
|
|
|
|
}
|
1999-06-15 10:21:47 +04:00
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLStyleSheet::IsApplicable() const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return PR_TRUE;
|
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::SetEnabled(PRBool aEnabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{ // these can't be disabled
|
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLStyleSheet::IsComplete() const
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return PR_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;
|
|
|
|
mDocumentColorRule = 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) {
|
|
|
|
PRBool res = PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops,
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|