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"
|
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
|
|
|
|
1999-04-16 01:23:05 +04:00
|
|
|
NS_IMETHODIMP
|
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-09-02 06:10:44 +04:00
|
|
|
return NS_OK;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-08-30 00:20:38 +04:00
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, PRInt32 aIndent) const
|
1999-07-07 08:53:36 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2000-02-16 04:08:54 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GenericTableRule::List(FILE* out, PRInt32 aIndent) const
|
2000-02-16 04:08:54 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
: mURL(nsnull),
|
1998-12-03 23:20:35 +03:00
|
|
|
mDocument(nsnull),
|
1998-07-25 05:20:48 +04:00
|
|
|
mLinkRule(nsnull),
|
|
|
|
mVisitedRule(nsnull),
|
1999-07-07 08:53:36 +04:00
|
|
|
mActiveRule(nsnull),
|
2006-08-26 02:33:17 +04:00
|
|
|
mDocumentColorRule(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;
|
|
|
|
NS_ADDREF(mTableTHRule);
|
|
|
|
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
|
|
|
{
|
1999-12-29 22:28:06 +03:00
|
|
|
NS_IF_RELEASE(mURL);
|
2004-10-31 20:33:50 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mLinkRule);
|
|
|
|
NS_IF_RELEASE(mVisitedRule);
|
|
|
|
NS_IF_RELEASE(mActiveRule);
|
|
|
|
NS_IF_RELEASE(mDocumentColorRule);
|
|
|
|
NS_IF_RELEASE(mTableTHRule);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-11-02 03:41:51 +03:00
|
|
|
nsIContent *content = aData->mContent;
|
2001-11-03 11:13:48 +03:00
|
|
|
|
2005-11-02 03:41:51 +03:00
|
|
|
if (content) {
|
2001-11-11 02:51:45 +03:00
|
|
|
nsRuleWalker *ruleWalker = aData->mRuleWalker;
|
2003-06-11 02:09:58 +04:00
|
|
|
if (aData->mIsHTMLContent) {
|
2001-11-11 02:51:45 +03:00
|
|
|
nsIAtom* tag = aData->mContentTag;
|
2001-11-03 11:13:48 +03:00
|
|
|
|
1999-02-27 04:34:55 +03:00
|
|
|
// if we have anchor colors, check if this is an anchor with an href
|
2006-12-26 20:47:52 +03:00
|
|
|
if (tag == nsGkAtoms::a) {
|
2000-07-28 03:17:53 +04:00
|
|
|
if (mLinkRule || mVisitedRule || mActiveRule) {
|
2009-12-16 03:04:12 +03:00
|
|
|
PRUint32 state = aData->ContentState();
|
|
|
|
if (mLinkRule && (state & NS_EVENT_STATE_UNVISITED)) {
|
|
|
|
ruleWalker->Forward(mLinkRule);
|
|
|
|
}
|
|
|
|
else if (mVisitedRule && (state & NS_EVENT_STATE_VISITED)) {
|
|
|
|
ruleWalker->Forward(mVisitedRule);
|
|
|
|
}
|
2001-11-03 11:13:48 +03:00
|
|
|
|
2009-12-16 03:04:12 +03: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);
|
1999-02-27 10:18:21 +03:00
|
|
|
}
|
2000-07-28 03:17:53 +04:00
|
|
|
} // end link/visited/active rules
|
1999-02-27 10:18:21 +03:00
|
|
|
} // end A tag
|
2001-07-06 18:17:08 +04:00
|
|
|
// add the rule to handle text-align for a <th>
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (tag == nsGkAtoms::th) {
|
2001-11-11 02:51:45 +03:00
|
|
|
ruleWalker->Forward(mTableTHRule);
|
2001-07-06 18:17:08 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (tag == nsGkAtoms::table) {
|
2003-06-08 23:52:22 +04:00
|
|
|
if (aData->mCompatMode == eCompatibility_NavQuirks) {
|
|
|
|
nscolor bodyColor;
|
2003-06-20 05:22:44 +04:00
|
|
|
nsresult rv =
|
2009-12-12 09:36:34 +03:00
|
|
|
GetBodyColor(ruleWalker->CurrentNode()->GetPresContext(),
|
2003-06-20 05:22:44 +04:00
|
|
|
&bodyColor);
|
2003-06-08 23:52:22 +04:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
(!mDocumentColorRule || bodyColor != mDocumentColorRule->mColor)) {
|
2004-10-31 20:33:50 +03:00
|
|
|
NS_IF_RELEASE(mDocumentColorRule);
|
|
|
|
mDocumentColorRule = new HTMLColorRule();
|
2003-06-08 23:52:22 +04:00
|
|
|
if (mDocumentColorRule) {
|
|
|
|
NS_ADDREF(mDocumentColorRule);
|
|
|
|
mDocumentColorRule->mColor = bodyColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDocumentColorRule)
|
|
|
|
ruleWalker->Forward(mDocumentColorRule);
|
|
|
|
}
|
1999-06-08 01:09:07 +04:00
|
|
|
}
|
2001-11-03 11:13:48 +03: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
|
2005-11-02 03:41:51 +03:00
|
|
|
content->WalkContentStyleRules(ruleWalker);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
// Test if style is dependent on content state
|
2009-12-12 09:36:34 +03:00
|
|
|
nsReStyleHint
|
|
|
|
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)))) {
|
2009-12-12 09:36:34 +03:00
|
|
|
return eReStyle_Self;
|
2005-08-11 00:21:44 +04:00
|
|
|
}
|
2009-12-12 09:36:34 +03:00
|
|
|
|
|
|
|
return nsReStyleHint(0);
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
2010-03-17 20:10:57 +03:00
|
|
|
PRBool
|
|
|
|
nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
nsReStyleHint
|
|
|
|
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) {
|
|
|
|
return nsReStyleHint(0);
|
|
|
|
}
|
|
|
|
|
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.
|
2005-11-02 03:41:51 +03:00
|
|
|
nsIContent *content = aData->mContent;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aData->mAttribute == nsGkAtoms::href &&
|
2003-02-22 19:10:53 +03:00
|
|
|
(mLinkRule || mVisitedRule || mActiveRule) &&
|
2005-11-02 03:41:51 +03:00
|
|
|
content &&
|
2009-08-25 00:02:07 +04:00
|
|
|
content->IsHTML() &&
|
2006-12-26 20:47:52 +03:00
|
|
|
aData->mContentTag == nsGkAtoms::a) {
|
2009-12-11 01:36:03 +03: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.
|
2005-11-02 03:41:51 +03:00
|
|
|
if (content && content->IsAttributeMapped(aData->mAttribute)) {
|
2009-12-11 01:36:03 +03:00
|
|
|
return eReStyle_Self;
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 01:36:03 +03:00
|
|
|
return nsReStyleHint(0);
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext,
|
|
|
|
PRBool* aRulesChanged)
|
|
|
|
{
|
|
|
|
*aRulesChanged = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-11 01:36:06 +03:00
|
|
|
NS_IMETHODIMP
|
2009-12-11 10:37:40 +03:00
|
|
|
nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
1998-05-19 01:11:08 +04:00
|
|
|
{
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-19 01:11:08 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_IMETHODIMP
|
2009-12-11 10:37:40 +03:00
|
|
|
nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
NS_IMETHODIMP
|
2004-09-10 10:45:59 +04:00
|
|
|
nsHTMLStyleSheet::GetSheetURI(nsIURI** aSheetURI) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-09-10 10:45:59 +04:00
|
|
|
*aSheetURI = mURL;
|
|
|
|
NS_IF_ADDREF(*aSheetURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLStyleSheet::GetBaseURI(nsIURI** aBaseURI) const
|
|
|
|
{
|
|
|
|
*aBaseURI = mURL;
|
|
|
|
NS_IF_ADDREF(*aBaseURI);
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GetTitle(nsString& aTitle) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-04 05:44:24 +04:00
|
|
|
NS_IMETHODIMP_(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
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GetApplicable(PRBool& aApplicable) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
aApplicable = PR_TRUE;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GetComplete(PRBool& aComplete) const
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
aComplete = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::SetComplete()
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GetParentSheet(nsIStyleSheet*& aParent) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-13 01:56:09 +04:00
|
|
|
nsHTMLStyleSheet::GetOwningDocument(nsIDocument*& aDocument) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
aDocument = mDocument;
|
2001-11-03 11:13:48 +03:00
|
|
|
NS_IF_ADDREF(aDocument);
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
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;
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-25 05:20:48 +04:00
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::Reset(nsIURI* aURL)
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
2001-11-03 11:13:48 +03:00
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
NS_IF_RELEASE(mLinkRule);
|
|
|
|
NS_IF_RELEASE(mVisitedRule);
|
|
|
|
NS_IF_RELEASE(mActiveRule);
|
|
|
|
NS_IF_RELEASE(mDocumentColorRule);
|
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
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::GetLinkColor(nscolor& aColor)
|
1999-07-07 08:53:36 +04:00
|
|
|
{
|
2001-11-03 11:13:48 +03:00
|
|
|
if (!mLinkRule) {
|
1999-07-07 08:53:36 +04:00
|
|
|
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aColor = mLinkRule->mColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::GetActiveLinkColor(nscolor& aColor)
|
1999-07-07 08:53:36 +04:00
|
|
|
{
|
2001-11-03 11:13:48 +03:00
|
|
|
if (!mActiveRule) {
|
1999-07-07 08:53:36 +04:00
|
|
|
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aColor = mActiveRule->mColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::GetVisitedLinkColor(nscolor& aColor)
|
1999-07-07 08:53:36 +04:00
|
|
|
{
|
2001-11-03 11:13:48 +03:00
|
|
|
if (!mVisitedRule) {
|
1999-07-07 08:53:36 +04:00
|
|
|
return NS_HTML_STYLE_PROPERTY_NOT_THERE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aColor = mVisitedRule->mColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetLinkColor(nscolor aColor)
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
2003-02-22 22:15:46 +03:00
|
|
|
if (mLinkRule) {
|
|
|
|
if (mLinkRule->mColor == aColor)
|
|
|
|
return NS_OK;
|
|
|
|
NS_RELEASE(mLinkRule);
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
2003-02-22 22:15:46 +03:00
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
mLinkRule = new HTMLColorRule();
|
2003-02-22 22:15:46 +03:00
|
|
|
if (!mLinkRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mLinkRule);
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
mLinkRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 08:53:36 +04:00
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor)
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
2003-02-22 22:15:46 +03:00
|
|
|
if (mActiveRule) {
|
|
|
|
if (mActiveRule->mColor == aColor)
|
|
|
|
return NS_OK;
|
|
|
|
NS_RELEASE(mActiveRule);
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
2003-02-22 22:15:46 +03:00
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
mActiveRule = new HTMLColorRule();
|
2003-02-22 22:15:46 +03:00
|
|
|
if (!mActiveRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mActiveRule);
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
mActiveRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor)
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
2003-02-22 22:15:46 +03:00
|
|
|
if (mVisitedRule) {
|
|
|
|
if (mVisitedRule->mColor == aColor)
|
|
|
|
return NS_OK;
|
|
|
|
NS_RELEASE(mVisitedRule);
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
2003-02-22 22:15:46 +03:00
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
mVisitedRule = new HTMLColorRule();
|
2003-02-22 22:15:46 +03:00
|
|
|
if (!mVisitedRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mVisitedRule);
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
mVisitedRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
2004-04-13 01:56:09 +04:00
|
|
|
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
|
|
|
}
|