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"
|
2004-01-26 22:22:05 +03:00
|
|
|
#include "nsMappedAttributes.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.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"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsRuleProcessorData.h"
|
2011-03-29 21:29:21 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-05-30 12:00:20 +04:00
|
|
|
#include "nsHashKeys.h"
|
2016-08-17 22:28:45 +03:00
|
|
|
#include "mozilla/OperatorNewExtensions.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/RestyleManagerHandle.h"
|
|
|
|
#include "mozilla/RestyleManagerHandleInlines.h"
|
2010-04-30 17:12:06 +04:00
|
|
|
|
2013-05-30 12:00:20 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:06 +04:00
|
|
|
using namespace mozilla::dom;
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(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
|
|
|
}
|
|
|
|
|
2015-11-17 07:09:55 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::HTMLColorRule::MightMapInheritedStyleData()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:29:21 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::HTMLColorRule::
|
2016-08-17 04:37:48 +03:00
|
|
|
GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue)
|
2016-08-16 08:29:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, int32_t aIndent) const
|
1999-07-07 08:53:36 +04:00
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString indentStr;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
indentStr.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s[html color rule] {}\n", indentStr.get());
|
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
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHTMLStyleSheet::GenericTableRule::List(FILE* out, int32_t aIndent) const
|
2000-02-16 04:08:54 +03:00
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString indentStr;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
indentStr.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s[generic table rule] {}\n", indentStr.get());
|
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
|
|
|
}
|
|
|
|
|
2015-11-17 07:09:55 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::TableTHRule::MightMapInheritedStyleData()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:29:21 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::TableTHRule::
|
2016-08-17 04:37:48 +03:00
|
|
|
GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue)
|
2016-08-16 08:29:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 07:09:55 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::TableQuirkColorRule::MightMapInheritedStyleData()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:29:21 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::TableQuirkColorRule::
|
2016-08-17 04:37:48 +03:00
|
|
|
GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue)
|
2016-08-16 08:29:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-30 12:00:20 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLStyleSheet::LangRule, nsIStyleRule)
|
2013-05-30 12:00:20 +04:00
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLStyleSheet::LangRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
|
|
|
|
nsCSSValue* lang = aRuleData->ValueForLang();
|
|
|
|
if (lang->GetUnit() == eCSSUnit_Null) {
|
|
|
|
lang->SetStringValue(mLang, eCSSUnit_Ident);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 07:09:55 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::LangRule::MightMapInheritedStyleData()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:29:21 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
nsHTMLStyleSheet::LangRule::
|
2016-08-17 04:37:48 +03:00
|
|
|
GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue)
|
2016-08-16 08:29:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-30 12:00:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLStyleSheet::LangRule::List(FILE* out, int32_t aIndent) const
|
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString str;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral("[lang rule] { language: \"");
|
|
|
|
AppendUTF16toUTF8(mLang, str);
|
|
|
|
str.AppendLiteral("\" }\n");
|
|
|
|
fprintf_stderr(out, "%s", str.get());
|
2013-05-30 12:00:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
2016-03-16 07:33:44 +03:00
|
|
|
MappedAttrTable_HashKey(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
|
2016-03-16 07:33:44 +03:00
|
|
|
MappedAttrTable_MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2002-08-17 16:17:03 +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));
|
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
|
|
|
}
|
|
|
|
|
2013-11-19 06:51:48 +04:00
|
|
|
static const PLDHashTableOps MappedAttrTable_Ops = {
|
2002-08-17 16:17:03 +04:00
|
|
|
MappedAttrTable_HashKey,
|
|
|
|
MappedAttrTable_MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
2002-08-17 16:17:03 +04:00
|
|
|
MappedAttrTable_ClearEntry,
|
2013-05-30 12:00:20 +04:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
struct LangRuleTableEntry : public PLDHashEntryHdr {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHTMLStyleSheet::LangRule> mRule;
|
2013-05-30 12:00:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
LangRuleTable_HashKey(const void *key)
|
2013-05-30 12:00:20 +04:00
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
return HashString(*lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LangRuleTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
|
|
|
|
{
|
|
|
|
LangRuleTableEntry *entry = static_cast<LangRuleTableEntry*>(hdr);
|
|
|
|
|
|
|
|
entry->~LangRuleTableEntry();
|
|
|
|
memset(entry, 0, sizeof(LangRuleTableEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
LangRuleTable_MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2013-05-30 12:00:20 +04:00
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
const LangRuleTableEntry *entry = static_cast<const LangRuleTableEntry*>(hdr);
|
|
|
|
|
|
|
|
return entry->mRule->mLang == *lang;
|
|
|
|
}
|
|
|
|
|
2015-02-11 20:46:40 +03:00
|
|
|
static void
|
|
|
|
LangRuleTable_InitEntry(PLDHashEntryHdr *hdr, const void *key)
|
2013-05-30 12:00:20 +04:00
|
|
|
{
|
|
|
|
const nsString *lang = static_cast<const nsString*>(key);
|
|
|
|
|
2016-08-17 22:28:45 +03:00
|
|
|
LangRuleTableEntry *entry = new (KnownNotNull, hdr) LangRuleTableEntry();
|
2013-05-30 12:00:20 +04:00
|
|
|
|
|
|
|
// Create the unique rule for this language
|
|
|
|
entry->mRule = new nsHTMLStyleSheet::LangRule(*lang);
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:51:48 +04:00
|
|
|
static const PLDHashTableOps LangRuleTable_Ops = {
|
2013-05-30 12:00:20 +04:00
|
|
|
LangRuleTable_HashKey,
|
|
|
|
LangRuleTable_MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
2013-05-30 12:00:20 +04:00
|
|
|
LangRuleTable_ClearEntry,
|
|
|
|
LangRuleTable_InitEntry
|
2002-08-17 16:17:03 +04:00
|
|
|
};
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
nsHTMLStyleSheet::nsHTMLStyleSheet(nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument)
|
2012-08-04 11:44:01 +04:00
|
|
|
, mTableQuirkColorRule(new TableQuirkColorRule())
|
|
|
|
, mTableTHRule(new TableTHRule())
|
2015-05-19 06:43:18 +03:00
|
|
|
, mMappedAttrTable(&MappedAttrTable_Ops, sizeof(MappedAttrTableEntry))
|
|
|
|
, mLangRuleTable(&LangRuleTable_Ops, sizeof(LangRuleTableEntry))
|
2012-08-04 11:44:01 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDocument);
|
2001-08-04 06:43:05 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLStyleSheet, 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;
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!ruleWalker->AuthorStyleDisabled()) {
|
2010-04-30 17:12:06 +04:00
|
|
|
// if we have anchor colors, check if this is an anchor with an href
|
2015-03-03 14:09:00 +03:00
|
|
|
if (aData->mElement->IsHTMLElement(nsGkAtoms::a)) {
|
2010-04-30 17:12:06 +04:00
|
|
|
if (mLinkRule || mVisitedRule || mActiveRule) {
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state =
|
|
|
|
nsCSSRuleProcessor::GetContentStateForVisitedHandling(
|
2011-03-29 21:29:21 +04:00
|
|
|
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>
|
2015-03-03 14:09:00 +03:00
|
|
|
else if (aData->mElement->IsHTMLElement(nsGkAtoms::th)) {
|
2010-04-30 17:12:06 +04:00
|
|
|
ruleWalker->Forward(mTableTHRule);
|
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
else if (aData->mElement->IsHTMLElement(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
|
|
|
|
2013-03-28 06:47:25 +04: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.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!ruleWalker->AuthorStyleDisabled() || aData->mElement->IsSVGElement()) {
|
2013-03-28 06:47:25 +04:00
|
|
|
aData->mElement->WalkContentStyleRules(ruleWalker);
|
|
|
|
}
|
2013-05-30 12:00:20 +04:00
|
|
|
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#language
|
|
|
|
// says that the xml:lang attribute overrides HTML's lang attribute,
|
|
|
|
// so we need to do this after WalkContentStyleRules.
|
|
|
|
nsString lang;
|
|
|
|
if (aData->mElement->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang, lang)) {
|
|
|
|
ruleWalker->Forward(LangRuleFor(lang));
|
|
|
|
}
|
2015-05-25 03:40:00 +03:00
|
|
|
|
|
|
|
// Set the language to "x-math" on the <math> element, so that appropriate
|
|
|
|
// font settings are used for MathML.
|
|
|
|
if (aData->mElement->IsMathMLElement(nsGkAtoms::math)) {
|
|
|
|
nsGkAtoms::x_math->ToString(lang);
|
|
|
|
ruleWalker->Forward(LangRuleFor(lang));
|
|
|
|
}
|
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
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aData->mElement->IsHTMLElement(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
|
|
|
}
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
/* virtual */ nsRestyleHint
|
|
|
|
nsHTMLStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
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
|
2015-08-05 15:42:21 +03:00
|
|
|
nsHTMLStyleSheet::HasAttributeDependentStyle(
|
|
|
|
AttributeRuleProcessorData* aData,
|
|
|
|
RestyleHintData& aRestyleHintDataResult)
|
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) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
element->IsHTMLElement(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 &&
|
2015-03-03 14:08:59 +03:00
|
|
|
element->IsHTMLElement(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
|
2013-06-23 16:03:39 +04:00
|
|
|
nsHTMLStyleSheet::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-09 09:01:52 +04:00
|
|
|
{
|
|
|
|
return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsHTMLStyleSheet::SizeOfIncludingThis(MallocSizeOf 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
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
void
|
2013-06-14 09:34:37 +04:00
|
|
|
nsHTMLStyleSheet::Reset()
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mLinkRule = nullptr;
|
|
|
|
mVisitedRule = nullptr;
|
|
|
|
mActiveRule = nullptr;
|
1999-07-18 04:30:11 +04:00
|
|
|
|
2015-05-19 06:43:18 +03:00
|
|
|
mLangRuleTable.Clear();
|
|
|
|
mMappedAttrTable.Clear();
|
1999-02-03 22:38:16 +03:00
|
|
|
}
|
|
|
|
|
2004-04-13 01:56:09 +04:00
|
|
|
nsresult
|
2015-10-18 08:24:48 +03:00
|
|
|
nsHTMLStyleSheet::ImplLinkColorSetter(RefPtr<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) {
|
2013-07-20 23:14:25 +04:00
|
|
|
mDocument->GetShell()->GetPresContext()->RestyleManager()->
|
2016-07-17 17:20:21 +03:00
|
|
|
PostRestyleEvent(root, eRestyle_Subtree, nsChangeHint(0));
|
2010-06-18 20:23:05 +04:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2015-09-15 00:23:12 +03:00
|
|
|
auto entry = static_cast<MappedAttrTableEntry*>
|
|
|
|
(mMappedAttrTable.Add(aMapped, fallible));
|
2002-08-17 16:17:03 +04:00
|
|
|
if (!entry)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
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
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMappedAttributes> ret = entry->mAttributes;
|
2013-04-22 15:15:59 +04:00
|
|
|
return ret.forget();
|
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
|
|
|
{
|
2012-12-24 08:45:57 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(aMapped);
|
2002-08-17 16:17:03 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-08-26 03:56:33 +04:00
|
|
|
uint32_t entryCount = mMappedAttrTable.EntryCount() - 1;
|
2002-08-17 16:17:03 +04:00
|
|
|
#endif
|
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mMappedAttrTable.Remove(aMapped);
|
2002-08-17 16:17:03 +04:00
|
|
|
|
2014-08-26 03:56:33 +04:00
|
|
|
NS_ASSERTION(entryCount == mMappedAttrTable.EntryCount(), "not removed");
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
2013-05-30 12:00:20 +04:00
|
|
|
nsIStyleRule*
|
|
|
|
nsHTMLStyleSheet::LangRuleFor(const nsString& aLanguage)
|
|
|
|
{
|
2015-09-15 00:23:12 +03:00
|
|
|
auto entry =
|
|
|
|
static_cast<LangRuleTableEntry*>(mLangRuleTable.Add(&aLanguage, fallible));
|
2013-05-30 12:00:20 +04:00
|
|
|
if (!entry) {
|
|
|
|
NS_ASSERTION(false, "out of memory");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return entry->mRule;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:58:01 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsHTMLStyleSheet::DOMSizeOfIncludingThis(MallocSizeOf 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
|
|
|
|
2015-07-30 08:28:20 +03:00
|
|
|
n += mMappedAttrTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
for (auto iter = mMappedAttrTable.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto entry = static_cast<MappedAttrTableEntry*>(iter.Get());
|
|
|
|
n += entry->mAttributes->SizeOfIncludingThis(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
|
2013-05-30 12:00:20 +04:00
|
|
|
// - mLangRuleTable
|
2012-02-02 01:58:01 +04:00
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mDocument, because it's non-owning
|
|
|
|
|
|
|
|
return n;
|
2011-07-19 20:40:18 +04:00
|
|
|
}
|