2001-09-25 05:32:19 +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/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the container for the style sheets that apply to a presentation, and
|
|
|
|
* the internal API that the style system exposes for creating (and
|
|
|
|
* potentially re-creating) style contexts
|
|
|
|
*/
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-06-26 06:52:48 +03:00
|
|
|
#include "mozilla/RuleProcessorCache.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
#include "nsIDocumentInlines.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsStyleContext.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-02-23 20:28:25 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2004-07-28 11:08:41 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2013-01-09 03:25:47 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsIContent.h"
|
2011-08-23 03:34:12 +04:00
|
|
|
#include "nsRuleData.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsRuleProcessorData.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2012-10-16 23:45:50 +04:00
|
|
|
#include "nsStyleSheetService.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-06-14 09:34:37 +04:00
|
|
|
#include "nsHTMLCSSStyleSheet.h"
|
|
|
|
#include "nsHTMLStyleSheet.h"
|
2014-09-13 17:17:35 +04:00
|
|
|
#include "SVGAttrAnimationRuleProcessor.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "nsCSSRules.h"
|
2014-08-03 06:37:44 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2014-08-03 06:37:45 +04:00
|
|
|
#include "nsIFrame.h"
|
2014-10-03 08:53:24 +04:00
|
|
|
#include "RestyleManager.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2010-04-30 17:12:06 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:06 +04:00
|
|
|
using namespace mozilla::dom;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsEmptyStyleRule, nsIStyleRule)
|
2008-12-12 21:59:03 +03:00
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2008-12-12 21:59:03 +03:00
|
|
|
nsEmptyStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsEmptyStyleRule::List(FILE* out, int32_t aIndent) const
|
2008-12-12 21:59:03 +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[empty style rule] {}\n", indentStr.get());
|
2008-12-12 21:59:03 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsInitialStyleRule, nsIStyleRule)
|
2011-08-23 03:34:12 +04:00
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsInitialStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
// Iterate over the property groups
|
|
|
|
for (nsStyleStructID sid = nsStyleStructID(0);
|
|
|
|
sid < nsStyleStructID_Length; sid = nsStyleStructID(sid + 1)) {
|
|
|
|
if (aRuleData->mSIDs & (1 << sid)) {
|
|
|
|
// Iterate over nsCSSValues within the property group
|
|
|
|
nsCSSValue * const value_start =
|
|
|
|
aRuleData->mValueStorage + aRuleData->mValueOffsets[sid];
|
|
|
|
for (nsCSSValue *value = value_start,
|
|
|
|
*value_end = value + nsCSSProps::PropertyCountInStruct(sid);
|
|
|
|
value != value_end; ++value) {
|
|
|
|
// If MathML is disabled take care not to set MathML properties (or we
|
|
|
|
// will trigger assertions in nsRuleNode)
|
|
|
|
if (sid == eStyleStruct_Font &&
|
|
|
|
!aRuleData->mPresContext->Document()->GetMathMLEnabled()) {
|
|
|
|
size_t index = value - value_start;
|
|
|
|
if (index == nsCSSProps::PropertyIndexInStruct(
|
|
|
|
eCSSProperty_script_level) ||
|
|
|
|
index == nsCSSProps::PropertyIndexInStruct(
|
|
|
|
eCSSProperty_script_size_multiplier) ||
|
|
|
|
index == nsCSSProps::PropertyIndexInStruct(
|
2013-12-02 20:49:00 +04:00
|
|
|
eCSSProperty_script_min_size) ||
|
|
|
|
index == nsCSSProps::PropertyIndexInStruct(
|
2014-01-14 18:39:50 +04:00
|
|
|
eCSSProperty_math_variant) ||
|
|
|
|
index == nsCSSProps::PropertyIndexInStruct(
|
|
|
|
eCSSProperty_math_display)) {
|
2011-08-23 03:34:12 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value->GetUnit() == eCSSUnit_Null) {
|
|
|
|
value->SetInitialValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsInitialStyleRule::List(FILE* out, int32_t aIndent) const
|
2011-08-23 03:34:12 +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[initial style rule] {}\n", indentStr.get());
|
2011-08-23 03:34:12 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsDisableTextZoomStyleRule, nsIStyleRule)
|
2013-06-29 07:28:50 +04:00
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsDisableTextZoomStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
if (!(aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Font)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCSSValue* value = aRuleData->ValueForTextZoom();
|
|
|
|
if (value->GetUnit() == eCSSUnit_Null)
|
|
|
|
value->SetNoneValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
|
|
|
nsDisableTextZoomStyleRule::List(FILE* out, int32_t aIndent) const
|
|
|
|
{
|
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[disable text zoom style rule] {}\n", indentStr.get());
|
2013-06-29 07:28:50 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 02:22:38 +03:00
|
|
|
static const nsStyleSet::sheetType gCSSSheetTypes[] = {
|
2013-08-15 08:58:37 +04:00
|
|
|
// From lowest to highest in cascading order.
|
2008-11-26 02:22:38 +03:00
|
|
|
nsStyleSet::eAgentSheet,
|
|
|
|
nsStyleSet::eUserSheet,
|
|
|
|
nsStyleSet::eDocSheet,
|
2013-01-09 03:25:47 +04:00
|
|
|
nsStyleSet::eScopedDocSheet,
|
2008-11-26 02:22:38 +03:00
|
|
|
nsStyleSet::eOverrideSheet
|
|
|
|
};
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
static bool IsCSSSheetType(nsStyleSet::sheetType aSheetType)
|
|
|
|
{
|
|
|
|
for (nsStyleSet::sheetType type : gCSSSheetTypes) {
|
|
|
|
if (type == aSheetType) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::nsStyleSet()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mRuleTree(nullptr),
|
2004-01-08 22:23:12 +03:00
|
|
|
mBatching(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mInShutdown(false),
|
|
|
|
mAuthorStyleDisabled(false),
|
|
|
|
mInReconstruct(false),
|
2013-05-20 06:59:20 +04:00
|
|
|
mInitFontFeatureValuesLookup(true),
|
2015-06-26 06:49:58 +03:00
|
|
|
mNeedsRestyleAfterEnsureUniqueInner(false),
|
2012-04-17 23:22:49 +04:00
|
|
|
mDirty(0),
|
|
|
|
mUnusedRuleNodeCount(0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
nsStyleSet::~nsStyleSet()
|
|
|
|
{
|
|
|
|
for (sheetType type : gCSSSheetTypes) {
|
|
|
|
for (uint32_t i = 0, n = mSheets[type].Length(); i < n; i++) {
|
|
|
|
static_cast<CSSStyleSheet*>(mSheets[type][i])->DropStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
2015-06-26 06:52:48 +03:00
|
|
|
|
|
|
|
// drop reference to cached rule processors
|
|
|
|
nsCSSRuleProcessor* rp;
|
|
|
|
rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[eAgentSheet].get());
|
|
|
|
if (rp) {
|
|
|
|
MOZ_ASSERT(rp->IsShared());
|
|
|
|
rp->ReleaseStyleSetRef();
|
|
|
|
}
|
|
|
|
rp = static_cast<nsCSSRuleProcessor*>(mRuleProcessors[eUserSheet].get());
|
|
|
|
if (rp) {
|
|
|
|
MOZ_ASSERT(rp->IsShared());
|
|
|
|
rp->ReleaseStyleSetRef();
|
|
|
|
}
|
2015-06-26 06:49:58 +03:00
|
|
|
}
|
|
|
|
|
2011-08-01 22:24:38 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-08-01 22:24:38 +04:00
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2011-08-01 22:25:20 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < eSheetTypeCount; i++) {
|
|
|
|
if (mRuleProcessors[i]) {
|
2015-06-26 06:52:48 +03:00
|
|
|
bool shared = false;
|
|
|
|
if (i == eAgentSheet || i == eUserSheet) {
|
|
|
|
// The only two origins we consider caching rule processors for.
|
|
|
|
nsCSSRuleProcessor* rp =
|
|
|
|
static_cast<nsCSSRuleProcessor*>(mRuleProcessors[i].get());
|
|
|
|
shared = rp->IsShared();
|
|
|
|
}
|
|
|
|
if (!shared) {
|
|
|
|
n += mRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2011-08-01 22:25:20 +04:00
|
|
|
}
|
2014-05-25 00:37:12 +04:00
|
|
|
// mSheets is a C-style array of nsCOMArrays. We do not own the sheets in
|
|
|
|
// the nsCOMArrays (either the nsLayoutStyleSheetCache singleton or our
|
|
|
|
// document owns them) so we do not count the sheets here (we pass nullptr
|
|
|
|
// as the aSizeOfElementIncludingThis argument). All we're doing here is
|
|
|
|
// counting the size of the nsCOMArrays' buffers.
|
2013-02-12 04:48:44 +04:00
|
|
|
n += mSheets[i].SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
2011-08-01 22:25:20 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 05:27:14 +04:00
|
|
|
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
|
2013-02-12 04:48:44 +04:00
|
|
|
n += mScopedDocSheetRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
n += mScopedDocSheetRuleProcessors.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
n += mRoots.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mOldRuleTrees.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
2011-08-01 22:25:20 +04:00
|
|
|
return n;
|
2011-08-01 22:24:38 +04:00
|
|
|
}
|
|
|
|
|
2013-04-01 02:08:29 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsStyleSet::Init(nsPresContext *aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2008-12-12 21:59:03 +03:00
|
|
|
mFirstLineRule = new nsEmptyStyleRule;
|
|
|
|
mFirstLetterRule = new nsEmptyStyleRule;
|
2012-11-09 14:25:52 +04:00
|
|
|
mPlaceholderRule = new nsEmptyStyleRule;
|
2013-06-29 07:28:50 +04:00
|
|
|
mDisableTextZoomStyleRule = new nsDisableTextZoomStyleRule;
|
2008-12-12 21:59:03 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mRuleTree = nsRuleNode::CreateRootNode(aPresContext);
|
1999-10-08 07:09:31 +04:00
|
|
|
|
2014-09-13 17:17:35 +04:00
|
|
|
// Make an explicit GatherRuleProcessors call for the levels that
|
|
|
|
// don't have style sheets. The other levels will have their calls
|
|
|
|
// triggered by DirtyRuleProcessors. (We should probably convert the
|
|
|
|
// ePresHintSheet and eStyleAttrSheet levels to work like this as
|
|
|
|
// well, and not implement nsIStyleSheet.)
|
2011-04-12 10:18:44 +04:00
|
|
|
GatherRuleProcessors(eAnimationSheet);
|
2009-10-08 07:22:42 +04:00
|
|
|
GatherRuleProcessors(eTransitionSheet);
|
2014-09-13 17:17:35 +04:00
|
|
|
GatherRuleProcessors(eSVGAttrAnimationSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 21:14:13 +04:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::BeginReconstruct()
|
|
|
|
{
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(!mInReconstruct, "Unmatched begin/end?");
|
2007-07-25 21:14:13 +04:00
|
|
|
NS_ASSERTION(mRuleTree, "Reconstructing before first construction?");
|
|
|
|
|
|
|
|
// Create a new rule tree root
|
2015-06-04 09:45:11 +03:00
|
|
|
nsRuleNode* newTree = nsRuleNode::CreateRootNode(mRuleTree->PresContext());
|
2007-07-25 21:14:13 +04:00
|
|
|
|
|
|
|
// Save the old rule tree so we can destroy it later
|
2009-01-30 07:39:23 +03:00
|
|
|
if (!mOldRuleTrees.AppendElement(mRuleTree)) {
|
|
|
|
newTree->Destroy();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-07-25 21:14:13 +04:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
// We need to keep mRoots so that the rule tree GC will only free the
|
|
|
|
// rule trees that really aren't referenced anymore (which should be
|
|
|
|
// all of them, if there are no bugs in reresolution code).
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInReconstruct = true;
|
2007-07-25 21:14:13 +04:00
|
|
|
mRuleTree = newTree;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSet::EndReconstruct()
|
|
|
|
{
|
2009-01-30 07:39:23 +03:00
|
|
|
NS_ASSERTION(mInReconstruct, "Unmatched begin/end?");
|
2011-10-17 18:59:28 +04:00
|
|
|
mInReconstruct = false;
|
2009-01-17 00:32:09 +03:00
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = mRoots.Length() - 1; i >= 0; --i) {
|
2009-01-17 00:32:09 +03:00
|
|
|
// Since nsStyleContext's mParent and mRuleNode are immutable, and
|
|
|
|
// style contexts own their parents, and nsStyleContext asserts in
|
|
|
|
// its constructor that the style context and its parent are in the
|
|
|
|
// same rule tree, we don't need to check any of the children of
|
|
|
|
// mRoots; we only need to check the rule nodes of mRoots
|
|
|
|
// themselves.
|
|
|
|
|
2014-10-03 08:53:22 +04:00
|
|
|
NS_ASSERTION(mRoots[i]->RuleNode()->RuleTree() == mRuleTree,
|
|
|
|
"style context has old rule node");
|
2009-01-17 00:32:09 +03:00
|
|
|
}
|
|
|
|
#endif
|
2009-01-30 07:39:23 +03:00
|
|
|
// This *should* destroy the only element of mOldRuleTrees, but in
|
|
|
|
// case of some bugs (which would trigger the above assertions), it
|
|
|
|
// won't.
|
|
|
|
GCRuleTrees();
|
2007-07-25 21:14:13 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
typedef nsDataHashtable<nsPtrHashKey<nsINode>, uint32_t> ScopeDepthCache;
|
|
|
|
|
|
|
|
// Returns the depth of a style scope element, with 1 being the depth of
|
|
|
|
// a style scope element that has no ancestor style scope elements. The
|
|
|
|
// depth does not count intervening non-scope elements.
|
|
|
|
static uint32_t
|
|
|
|
GetScopeDepth(nsINode* aScopeElement, ScopeDepthCache& aCache)
|
|
|
|
{
|
|
|
|
nsINode* parent = aScopeElement->GetParent();
|
|
|
|
if (!parent || !parent->IsElementInStyleScope()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t depth = aCache.Get(aScopeElement);
|
|
|
|
if (!depth) {
|
|
|
|
for (nsINode* n = parent; n; n = n->GetParent()) {
|
|
|
|
if (n->IsScopedStyleRoot()) {
|
|
|
|
depth = GetScopeDepth(n, aCache) + 1;
|
|
|
|
aCache.Put(aScopeElement, depth);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ScopedSheetOrder
|
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* mSheet;
|
2013-01-09 03:25:47 +04:00
|
|
|
uint32_t mDepth;
|
|
|
|
uint32_t mOrder;
|
|
|
|
|
|
|
|
bool operator==(const ScopedSheetOrder& aRHS) const
|
|
|
|
{
|
|
|
|
return mDepth == aRHS.mDepth &&
|
|
|
|
mOrder == aRHS.mOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const ScopedSheetOrder& aRHS) const
|
|
|
|
{
|
|
|
|
if (mDepth != aRHS.mDepth) {
|
|
|
|
return mDepth < aRHS.mDepth;
|
|
|
|
}
|
|
|
|
return mOrder < aRHS.mOrder;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sorts aSheets such that style sheets for ancestor scopes come
|
|
|
|
// before those for descendant scopes, and with sheets for a single
|
|
|
|
// scope in document order.
|
|
|
|
static void
|
2014-06-20 14:32:49 +04:00
|
|
|
SortStyleSheetsByScope(nsTArray<CSSStyleSheet*>& aSheets)
|
2013-01-09 03:25:47 +04:00
|
|
|
{
|
|
|
|
uint32_t n = aSheets.Length();
|
|
|
|
if (n == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeDepthCache cache;
|
|
|
|
|
|
|
|
nsTArray<ScopedSheetOrder> sheets;
|
|
|
|
sheets.SetLength(n);
|
|
|
|
|
|
|
|
// For each sheet, record the depth of its scope element and its original
|
|
|
|
// document order.
|
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
|
|
|
sheets[i].mSheet = aSheets[i];
|
|
|
|
sheets[i].mDepth = GetScopeDepth(aSheets[i]->GetScopeElement(), cache);
|
|
|
|
sheets[i].mOrder = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by depth first, then document order.
|
|
|
|
sheets.Sort();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < n; i++) {
|
|
|
|
aSheets[i] = sheets[i].mSheet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
nsresult
|
2004-07-28 11:08:41 +04:00
|
|
|
nsStyleSet::GatherRuleProcessors(sheetType aType)
|
1999-10-08 07:09:31 +04:00
|
|
|
{
|
2014-12-06 02:50:00 +03:00
|
|
|
nsCOMPtr<nsIStyleRuleProcessor> oldRuleProcessor(mRuleProcessors[aType]);
|
|
|
|
nsTArray<nsCOMPtr<nsIStyleRuleProcessor>> oldScopedDocRuleProcessors;
|
2015-06-26 06:52:48 +03:00
|
|
|
if (aType == eAgentSheet || aType == eUserSheet) {
|
|
|
|
// drop reference to cached rule processor
|
|
|
|
nsCSSRuleProcessor* rp =
|
|
|
|
static_cast<nsCSSRuleProcessor*>(mRuleProcessors[aType].get());
|
|
|
|
if (rp) {
|
|
|
|
MOZ_ASSERT(rp->IsShared());
|
|
|
|
rp->ReleaseStyleSetRef();
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mRuleProcessors[aType] = nullptr;
|
2013-01-09 03:25:47 +04:00
|
|
|
if (aType == eScopedDocSheet) {
|
2013-01-10 22:40:53 +04:00
|
|
|
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
|
2013-01-09 03:25:47 +04:00
|
|
|
nsIStyleRuleProcessor* processor = mScopedDocSheetRuleProcessors[i].get();
|
|
|
|
Element* scope =
|
|
|
|
static_cast<nsCSSRuleProcessor*>(processor)->GetScopeElement();
|
|
|
|
scope->ClearIsScopedStyleRoot();
|
|
|
|
}
|
2014-12-06 02:50:00 +03:00
|
|
|
|
|
|
|
// Clear mScopedDocSheetRuleProcessors, but save it.
|
|
|
|
oldScopedDocRuleProcessors.SwapElements(mScopedDocSheetRuleProcessors);
|
2013-01-09 03:25:47 +04:00
|
|
|
}
|
2004-08-05 15:38:42 +04:00
|
|
|
if (mAuthorStyleDisabled && (aType == eDocSheet ||
|
2013-01-09 03:25:47 +04:00
|
|
|
aType == eScopedDocSheet ||
|
2004-08-05 15:38:42 +04:00
|
|
|
aType == eStyleAttrSheet)) {
|
2013-03-28 06:47:25 +04:00
|
|
|
// Don't regather if this level is disabled. Note that we gather
|
|
|
|
// preshint sheets no matter what, but then skip them for some
|
|
|
|
// elements later if mAuthorStyleDisabled.
|
2004-08-05 15:38:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-06-14 09:34:37 +04:00
|
|
|
switch (aType) {
|
|
|
|
// handle the types for which have a rule processor that does not
|
|
|
|
// implement the style sheet interface.
|
|
|
|
case eAnimationSheet:
|
2014-09-13 17:17:35 +04:00
|
|
|
MOZ_ASSERT(mSheets[aType].IsEmpty());
|
2013-06-14 09:34:37 +04:00
|
|
|
mRuleProcessors[aType] = PresContext()->AnimationManager();
|
|
|
|
return NS_OK;
|
|
|
|
case eTransitionSheet:
|
2014-09-13 17:17:35 +04:00
|
|
|
MOZ_ASSERT(mSheets[aType].IsEmpty());
|
2013-06-14 09:34:37 +04:00
|
|
|
mRuleProcessors[aType] = PresContext()->TransitionManager();
|
|
|
|
return NS_OK;
|
|
|
|
case eStyleAttrSheet:
|
2014-09-13 17:17:35 +04:00
|
|
|
MOZ_ASSERT(mSheets[aType].IsEmpty());
|
2013-06-14 09:34:37 +04:00
|
|
|
mRuleProcessors[aType] = PresContext()->Document()->GetInlineStyleSheet();
|
|
|
|
return NS_OK;
|
|
|
|
case ePresHintSheet:
|
2014-09-13 17:17:35 +04:00
|
|
|
MOZ_ASSERT(mSheets[aType].IsEmpty());
|
|
|
|
mRuleProcessors[aType] =
|
|
|
|
PresContext()->Document()->GetAttributeStyleSheet();
|
|
|
|
return NS_OK;
|
|
|
|
case eSVGAttrAnimationSheet:
|
|
|
|
MOZ_ASSERT(mSheets[aType].IsEmpty());
|
|
|
|
mRuleProcessors[aType] =
|
|
|
|
PresContext()->Document()->GetSVGAttrAnimationRuleProcessor();
|
2013-06-14 09:34:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
default:
|
|
|
|
// keep going
|
|
|
|
break;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2013-01-09 03:25:47 +04:00
|
|
|
if (aType == eScopedDocSheet) {
|
|
|
|
// Create a rule processor for each scope.
|
|
|
|
uint32_t count = mSheets[eScopedDocSheet].Count();
|
|
|
|
if (count) {
|
|
|
|
// Gather the scoped style sheets into an array as
|
2014-06-20 14:32:49 +04:00
|
|
|
// CSSStyleSheets, and mark all of their scope elements
|
2013-01-09 03:25:47 +04:00
|
|
|
// as scoped style roots.
|
2014-06-20 14:32:49 +04:00
|
|
|
nsTArray<CSSStyleSheet*> sheets(count);
|
2013-01-10 22:40:53 +04:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> sheet =
|
2013-01-09 03:25:47 +04:00
|
|
|
do_QueryObject(mSheets[eScopedDocSheet].ObjectAt(i));
|
|
|
|
sheets.AppendElement(sheet);
|
|
|
|
|
|
|
|
Element* scope = sheet->GetScopeElement();
|
|
|
|
scope->SetIsScopedStyleRoot();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the scoped style sheets so that those for the same scope are
|
|
|
|
// adjacent and that ancestor scopes come before descendent scopes.
|
|
|
|
SortStyleSheetsByScope(sheets);
|
|
|
|
|
2014-12-06 02:50:00 +03:00
|
|
|
// Put the old scoped rule processors in a hashtable so that we
|
|
|
|
// can retrieve them efficiently, even in edge cases like the
|
|
|
|
// simultaneous removal and addition of a large number of elements
|
|
|
|
// with scoped sheets.
|
|
|
|
nsDataHashtable<nsPtrHashKey<Element>,
|
|
|
|
nsCSSRuleProcessor*> oldScopedRuleProcessorHash;
|
|
|
|
for (size_t i = oldScopedDocRuleProcessors.Length(); i-- != 0; ) {
|
|
|
|
nsCSSRuleProcessor* oldRP =
|
|
|
|
static_cast<nsCSSRuleProcessor*>(oldScopedDocRuleProcessors[i].get());
|
|
|
|
Element* scope = oldRP->GetScopeElement();
|
|
|
|
MOZ_ASSERT(!oldScopedRuleProcessorHash.Get(scope),
|
|
|
|
"duplicate rule processors for same scope element?");
|
|
|
|
oldScopedRuleProcessorHash.Put(scope, oldRP);
|
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
uint32_t start = 0, end;
|
|
|
|
do {
|
|
|
|
// Find the range of style sheets with the same scope.
|
|
|
|
Element* scope = sheets[start]->GetScopeElement();
|
|
|
|
end = start + 1;
|
|
|
|
while (end < count && sheets[end]->GetScopeElement() == scope) {
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
scope->SetIsScopedStyleRoot();
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
// Create a rule processor for the scope.
|
2014-06-20 14:32:49 +04:00
|
|
|
nsTArray<nsRefPtr<CSSStyleSheet>> sheetsForScope;
|
2013-01-09 03:25:47 +04:00
|
|
|
sheetsForScope.AppendElements(sheets.Elements() + start, end - start);
|
2014-12-06 02:50:00 +03:00
|
|
|
nsCSSRuleProcessor* oldRP = oldScopedRuleProcessorHash.Get(scope);
|
2013-01-09 03:25:47 +04:00
|
|
|
mScopedDocSheetRuleProcessors.AppendElement
|
2014-12-06 02:50:00 +03:00
|
|
|
(new nsCSSRuleProcessor(sheetsForScope, uint8_t(aType), scope,
|
|
|
|
oldRP));
|
2013-01-09 03:25:47 +04:00
|
|
|
|
|
|
|
start = end;
|
|
|
|
} while (start < count);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
if (mSheets[aType].Count()) {
|
2004-07-28 11:08:41 +04:00
|
|
|
switch (aType) {
|
|
|
|
case eAgentSheet:
|
2015-06-26 06:52:48 +03:00
|
|
|
case eUserSheet: {
|
|
|
|
// levels containing non-scoped CSS style sheets whose rule processors
|
|
|
|
// we want to re-use
|
|
|
|
nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
|
|
|
|
nsTArray<nsRefPtr<CSSStyleSheet>> cssSheets(sheets.Count());
|
|
|
|
for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) {
|
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
|
|
|
|
NS_ASSERTION(cssSheet, "not a CSS sheet");
|
|
|
|
cssSheets.AppendElement(cssSheet);
|
|
|
|
}
|
|
|
|
nsTArray<CSSStyleSheet*> cssSheetsRaw(cssSheets.Length());
|
|
|
|
for (int32_t i = 0, i_end = cssSheets.Length(); i < i_end; ++i) {
|
|
|
|
cssSheetsRaw.AppendElement(cssSheets[i]);
|
|
|
|
}
|
|
|
|
nsCSSRuleProcessor* rp =
|
|
|
|
RuleProcessorCache::GetRuleProcessor(cssSheetsRaw, PresContext());
|
|
|
|
if (!rp) {
|
|
|
|
rp = new nsCSSRuleProcessor(cssSheets, uint8_t(aType), nullptr,
|
|
|
|
static_cast<nsCSSRuleProcessor*>(
|
|
|
|
oldRuleProcessor.get()),
|
|
|
|
true /* aIsShared */);
|
|
|
|
nsTArray<css::DocumentRule*> documentRules;
|
|
|
|
nsDocumentRuleResultCacheKey cacheKey;
|
|
|
|
rp->TakeDocumentRulesAndCacheKey(PresContext(),
|
|
|
|
documentRules, cacheKey);
|
|
|
|
RuleProcessorCache::PutRuleProcessor(cssSheetsRaw,
|
|
|
|
Move(documentRules),
|
|
|
|
cacheKey, rp);
|
|
|
|
}
|
|
|
|
mRuleProcessors[aType] = rp;
|
|
|
|
rp->AddStyleSetRef();
|
|
|
|
break;
|
|
|
|
}
|
2004-07-28 11:08:41 +04:00
|
|
|
case eDocSheet:
|
|
|
|
case eOverrideSheet: {
|
2015-06-26 06:52:48 +03:00
|
|
|
// levels containing non-scoped CSS stylesheets whose rule processors
|
|
|
|
// we don't want to re-use
|
2004-07-28 11:08:41 +04:00
|
|
|
nsCOMArray<nsIStyleSheet>& sheets = mSheets[aType];
|
2014-06-20 14:32:49 +04:00
|
|
|
nsTArray<nsRefPtr<CSSStyleSheet>> cssSheets(sheets.Count());
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) {
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(sheets[i]);
|
2004-07-28 11:08:41 +04:00
|
|
|
NS_ASSERTION(cssSheet, "not a CSS sheet");
|
2010-05-12 00:41:47 +04:00
|
|
|
cssSheets.AppendElement(cssSheet);
|
2004-07-28 11:08:41 +04:00
|
|
|
}
|
2013-01-09 03:25:47 +04:00
|
|
|
mRuleProcessors[aType] =
|
2014-12-06 02:50:00 +03:00
|
|
|
new nsCSSRuleProcessor(cssSheets, uint8_t(aType), nullptr,
|
|
|
|
static_cast<nsCSSRuleProcessor*>(
|
|
|
|
oldRuleProcessor.get()));
|
2004-07-28 11:08:41 +04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// levels containing non-CSS stylesheets
|
|
|
|
NS_ASSERTION(mSheets[aType].Count() == 1, "only one sheet per level");
|
|
|
|
mRuleProcessors[aType] = do_QueryInterface(mSheets[aType][0]);
|
|
|
|
break;
|
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
static bool
|
|
|
|
IsScopedStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(aSheet);
|
|
|
|
NS_ASSERTION(cssSheet, "expected aSheet to be a CSSStyleSheet");
|
2013-01-09 03:25:47 +04:00
|
|
|
|
|
|
|
return cssSheet->GetScopeElement();
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2015-06-26 06:49:58 +03:00
|
|
|
bool present = mSheets[aType].RemoveObject(aSheet);
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mSheets[aType].AppendObject(aSheet))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
if (!present && IsCSSSheetType(aType)) {
|
|
|
|
static_cast<CSSStyleSheet*>(aSheet)->AddStyleSet(this);
|
|
|
|
}
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2015-06-26 06:49:58 +03:00
|
|
|
bool present = mSheets[aType].RemoveObject(aSheet);
|
2004-01-08 01:30:53 +03:00
|
|
|
if (!mSheets[aType].InsertObjectAt(aSheet, 0))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
if (!present && IsCSSSheetType(aType)) {
|
|
|
|
static_cast<CSSStyleSheet*>(aSheet)->AddStyleSet(this);
|
|
|
|
}
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsComplete(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Incomplete sheet being removed from style set");
|
2015-06-26 06:49:58 +03:00
|
|
|
if (mSheets[aType].RemoveObject(aSheet)) {
|
|
|
|
if (IsCSSSheetType(aType)) {
|
|
|
|
static_cast<CSSStyleSheet*>(aSheet)->DropStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::ReplaceSheets(sheetType aType,
|
|
|
|
const nsCOMArray<nsIStyleSheet> &aNewSheets)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2015-06-26 06:49:58 +03:00
|
|
|
bool cssSheetType = IsCSSSheetType(aType);
|
|
|
|
if (cssSheetType) {
|
|
|
|
for (uint32_t i = 0, n = mSheets[aType].Length(); i < n; i++) {
|
|
|
|
static_cast<CSSStyleSheet*>(mSheets[aType][i])->DropStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mSheets[aType].Clear();
|
2004-01-08 22:23:12 +03:00
|
|
|
if (!mSheets[aType].AppendObjects(aNewSheets))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
if (cssSheetType) {
|
|
|
|
for (uint32_t i = 0, n = mSheets[aType].Length(); i < n; i++) {
|
|
|
|
static_cast<CSSStyleSheet*>(mSheets[aType][i])->AddStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(aType);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-29 15:21:15 +04:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::InsertStyleSheetBefore(sheetType aType, nsIStyleSheet *aNewSheet,
|
|
|
|
nsIStyleSheet *aReferenceSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewSheet && aReferenceSheet, "null arg");
|
|
|
|
NS_ASSERTION(aNewSheet->IsApplicable(),
|
|
|
|
"Inapplicable sheet being placed in style set");
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
bool present = mSheets[aType].RemoveObject(aNewSheet);
|
2012-10-29 15:21:15 +04:00
|
|
|
int32_t idx = mSheets[aType].IndexOf(aReferenceSheet);
|
|
|
|
if (idx < 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2013-06-14 09:34:37 +04:00
|
|
|
|
2012-10-29 15:21:15 +04:00
|
|
|
if (!mSheets[aType].InsertObjectAt(aNewSheet, idx))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
if (!present && IsCSSSheetType(aType)) {
|
|
|
|
static_cast<CSSStyleSheet*>(aNewSheet)->AddStyleSet(this);
|
|
|
|
}
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStyleSet::DirtyRuleProcessors(sheetType aType)
|
|
|
|
{
|
2012-10-29 15:21:15 +04:00
|
|
|
if (!mBatching)
|
|
|
|
return GatherRuleProcessors(aType);
|
|
|
|
|
|
|
|
mDirty |= 1 << aType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-08-05 15:38:42 +04:00
|
|
|
nsStyleSet::GetAuthorStyleDisabled()
|
|
|
|
{
|
|
|
|
return mAuthorStyleDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
|
2004-08-05 15:38:42 +04:00
|
|
|
{
|
|
|
|
if (aStyleDisabled == !mAuthorStyleDisabled) {
|
|
|
|
mAuthorStyleDisabled = aStyleDisabled;
|
|
|
|
BeginUpdate();
|
|
|
|
mDirty |= 1 << eDocSheet |
|
2013-03-28 06:47:26 +04:00
|
|
|
1 << eScopedDocSheet |
|
2004-08-05 15:38:42 +04:00
|
|
|
1 << eStyleAttrSheet;
|
|
|
|
return EndUpdate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
// -------- Doc Sheets
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
NS_PRECONDITION(aSheet && aDocument, "null arg");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(aSheet->IsApplicable(),
|
2010-05-13 00:18:47 +04:00
|
|
|
"Inapplicable sheet being placed in style set");
|
2004-01-08 01:30:53 +03:00
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
sheetType type = IsScopedStyleSheet(aSheet) ?
|
|
|
|
eScopedDocSheet :
|
|
|
|
eDocSheet;
|
|
|
|
nsCOMArray<nsIStyleSheet>& sheets = mSheets[type];
|
2004-01-08 01:30:53 +03:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
bool present = sheets.RemoveObject(aSheet);
|
2012-10-16 23:45:56 +04:00
|
|
|
nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
|
2012-10-16 23:45:50 +04:00
|
|
|
|
2004-07-28 11:08:41 +04:00
|
|
|
// lowest index first
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
2012-10-16 23:45:50 +04:00
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
int32_t count = sheets.Count();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index;
|
2004-07-28 11:08:41 +04:00
|
|
|
for (index = 0; index < count; index++) {
|
2013-01-09 03:25:47 +04:00
|
|
|
nsIStyleSheet* sheet = sheets.ObjectAt(index);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (sheetDocIndex > newDocIndex)
|
|
|
|
break;
|
2012-10-16 23:45:50 +04:00
|
|
|
|
|
|
|
// If the sheet is not owned by the document it can be an author
|
2012-10-29 15:21:15 +04:00
|
|
|
// sheet registered at nsStyleSheetService or an additional author
|
|
|
|
// sheet on the document, which means the new
|
2012-10-16 23:45:50 +04:00
|
|
|
// doc sheet should end up before it.
|
|
|
|
if (sheetDocIndex < 0 &&
|
2012-10-29 15:21:15 +04:00
|
|
|
((sheetService &&
|
|
|
|
sheetService->AuthorStyleSheets()->IndexOf(sheet) >= 0) ||
|
|
|
|
sheet == aDocument->FirstAdditionalAuthorSheet()))
|
2012-10-16 23:45:50 +04:00
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2013-01-09 03:25:47 +04:00
|
|
|
if (!sheets.InsertObjectAt(aSheet, index))
|
2004-07-28 11:08:41 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
if (!present) {
|
|
|
|
static_cast<CSSStyleSheet*>(aSheet)->AddStyleSet(this);
|
|
|
|
}
|
|
|
|
|
2013-06-14 09:34:37 +04:00
|
|
|
return DirtyRuleProcessors(type);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::RemoveDocStyleSheet(nsIStyleSheet *aSheet)
|
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(aSheet);
|
2013-01-09 03:25:47 +04:00
|
|
|
bool isScoped = cssSheet && cssSheet->GetScopeElement();
|
|
|
|
return RemoveStyleSheet(isScoped ? eScopedDocSheet : eDocSheet, aSheet);
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
// Batching
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::BeginUpdate()
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
++mBatching;
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult
|
|
|
|
nsStyleSet::EndUpdate()
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
2004-01-08 22:23:12 +03:00
|
|
|
NS_ASSERTION(mBatching > 0, "Unbalanced EndUpdate");
|
|
|
|
if (--mBatching) {
|
|
|
|
// We're not completely done yet.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
for (int i = 0; i < eSheetTypeCount; ++i) {
|
2004-01-08 22:23:12 +03:00
|
|
|
if (mDirty & (1 << i)) {
|
2004-07-28 11:08:41 +04:00
|
|
|
nsresult rv = GatherRuleProcessors(sheetType(i));
|
2004-01-08 01:30:53 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
mDirty = 0;
|
|
|
|
return NS_OK;
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
template<class T>
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2004-01-08 01:30:53 +03:00
|
|
|
EnumRulesMatching(nsIStyleRuleProcessor* aProcessor, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
T* data = static_cast<T*>(aData);
|
2004-08-05 22:26:14 +04:00
|
|
|
aProcessor->RulesMatching(data);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2011-05-01 02:16:19 +04:00
|
|
|
static inline bool
|
|
|
|
IsMoreSpecificThanAnimation(nsRuleNode *aRuleNode)
|
|
|
|
{
|
|
|
|
return !aRuleNode->IsRoot() &&
|
|
|
|
(aRuleNode->GetLevel() == nsStyleSet::eTransitionSheet ||
|
2012-08-30 05:27:01 +04:00
|
|
|
aRuleNode->IsImportantRule());
|
2011-05-01 02:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsIStyleRule*
|
|
|
|
GetAnimationRule(nsRuleNode *aRuleNode)
|
|
|
|
{
|
|
|
|
nsRuleNode *n = aRuleNode;
|
|
|
|
while (IsMoreSpecificThanAnimation(n)) {
|
|
|
|
n = n->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n->IsRoot() || n->GetLevel() != nsStyleSet::eAnimationSheet) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-05-01 02:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return n->GetRule();
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsRuleNode*
|
|
|
|
ReplaceAnimationRule(nsRuleNode *aOldRuleNode,
|
|
|
|
nsIStyleRule *aOldAnimRule,
|
|
|
|
nsIStyleRule *aNewAnimRule)
|
|
|
|
{
|
|
|
|
nsTArray<nsRuleNode*> moreSpecificNodes;
|
|
|
|
|
|
|
|
nsRuleNode *n = aOldRuleNode;
|
|
|
|
while (IsMoreSpecificThanAnimation(n)) {
|
|
|
|
moreSpecificNodes.AppendElement(n);
|
|
|
|
n = n->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOldAnimRule) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(n->GetRule() == aOldAnimRule, "wrong rule");
|
|
|
|
MOZ_ASSERT(n->GetLevel() == nsStyleSet::eAnimationSheet,
|
|
|
|
"wrong level");
|
2011-05-01 02:16:19 +04:00
|
|
|
n = n->GetParent();
|
|
|
|
}
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsMoreSpecificThanAnimation(n) &&
|
|
|
|
(n->IsRoot() || n->GetLevel() != nsStyleSet::eAnimationSheet),
|
|
|
|
"wrong level");
|
2011-05-01 02:16:19 +04:00
|
|
|
|
|
|
|
if (aNewAnimRule) {
|
2011-10-17 18:59:28 +04:00
|
|
|
n = n->Transition(aNewAnimRule, nsStyleSet::eAnimationSheet, false);
|
2011-05-01 02:16:19 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = moreSpecificNodes.Length(); i-- != 0; ) {
|
2011-05-01 02:16:19 +04:00
|
|
|
nsRuleNode *oldNode = moreSpecificNodes[i];
|
|
|
|
n = n->Transition(oldNode->GetRule(), oldNode->GetLevel(),
|
|
|
|
oldNode->IsImportantRule());
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2002-03-08 02:48:26 +03:00
|
|
|
/**
|
|
|
|
* |GetContext| implements sharing of style contexts (not just the data
|
|
|
|
* on the rule nodes) between siblings and cousins of the same
|
|
|
|
* generation. (It works for cousins of the same generation since
|
|
|
|
* |aParentContext| could itself be a shared context.)
|
|
|
|
*/
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-02 10:07:42 +04:00
|
|
|
nsStyleSet::GetContext(nsStyleContext* aParentContext,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleNode* aRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// aVisitedRuleNode may be null; if it is null
|
|
|
|
// it means that we don't need to force creation
|
|
|
|
// of a StyleIfVisited. (But if we make one
|
|
|
|
// because aParentContext has one, then aRuleNode
|
|
|
|
// should be used.)
|
|
|
|
nsRuleNode* aVisitedRuleNode,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
2011-04-12 10:18:44 +04:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2013-02-01 20:02:29 +04:00
|
|
|
Element* aElementForAnimation,
|
|
|
|
uint32_t aFlags)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_PRECONDITION((!aPseudoTag &&
|
|
|
|
aPseudoType ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement) ||
|
|
|
|
(aPseudoTag &&
|
|
|
|
nsCSSPseudoElements::GetPseudoType(aPseudoTag) ==
|
|
|
|
aPseudoType),
|
|
|
|
"Pseudo mismatch");
|
|
|
|
|
2010-06-15 00:06:48 +04:00
|
|
|
if (aVisitedRuleNode == aRuleNode) {
|
|
|
|
// No need to force creation of a visited style in this case.
|
2012-07-30 18:20:58 +04:00
|
|
|
aVisitedRuleNode = nullptr;
|
2010-06-15 00:06:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
// Ensure |aVisitedRuleNode != nullptr| corresponds to the need to
|
2010-04-03 05:58:27 +04:00
|
|
|
// create an if-visited style context, and that in that case, we have
|
|
|
|
// parentIfVisited set correctly.
|
|
|
|
nsStyleContext *parentIfVisited =
|
2012-07-30 18:20:58 +04:00
|
|
|
aParentContext ? aParentContext->GetStyleIfVisited() : nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
if (parentIfVisited) {
|
|
|
|
if (!aVisitedRuleNode) {
|
|
|
|
aVisitedRuleNode = aRuleNode;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aVisitedRuleNode) {
|
|
|
|
parentIfVisited = aParentContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
if (aFlags & eIsLink) {
|
2010-04-03 05:58:27 +04:00
|
|
|
// If this node is a link, we want its visited's style context's
|
|
|
|
// parent to be the regular style context of its parent, because
|
|
|
|
// only the visitedness of the relevant link should influence style.
|
|
|
|
parentIfVisited = aParentContext;
|
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2014-08-03 06:37:42 +04:00
|
|
|
bool relevantLinkVisited = (aFlags & eIsLink) ?
|
|
|
|
(aFlags & eIsVisitedLink) :
|
|
|
|
(aParentContext && aParentContext->RelevantLinkVisited());
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRefPtr<nsStyleContext> result;
|
2015-05-04 00:52:53 +03:00
|
|
|
if (aParentContext)
|
2010-04-03 05:58:26 +04:00
|
|
|
result = aParentContext->FindChildWithRules(aPseudoTag, aRuleNode,
|
2015-05-04 00:52:53 +03:00
|
|
|
aVisitedRuleNode,
|
|
|
|
relevantLinkVisited);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
2002-03-31 20:59:00 +04:00
|
|
|
if (result)
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "--- SharedSC %d ---\n", ++gSharedCount);
|
2002-03-31 20:59:00 +04:00
|
|
|
else
|
|
|
|
fprintf(stdout, "+++ NewSC %d +++\n", ++gNewCount);
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
2003-03-06 22:14:17 +03:00
|
|
|
if (!result) {
|
2009-12-11 10:37:40 +03:00
|
|
|
result = NS_NewStyleContext(aParentContext, aPseudoTag, aPseudoType,
|
2014-05-03 17:42:33 +04:00
|
|
|
aRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
aFlags & eSkipParentDisplayBasedStyleFixup);
|
2010-04-03 05:58:27 +04:00
|
|
|
if (aVisitedRuleNode) {
|
|
|
|
nsRefPtr<nsStyleContext> resultIfVisited =
|
|
|
|
NS_NewStyleContext(parentIfVisited, aPseudoTag, aPseudoType,
|
2013-02-21 11:34:58 +04:00
|
|
|
aVisitedRuleNode,
|
2014-06-16 17:55:00 +04:00
|
|
|
aFlags & eSkipParentDisplayBasedStyleFixup);
|
2010-04-30 05:15:44 +04:00
|
|
|
if (!parentIfVisited) {
|
|
|
|
mRoots.AppendElement(resultIfVisited);
|
|
|
|
}
|
2010-04-06 23:42:41 +04:00
|
|
|
resultIfVisited->SetIsStyleIfVisited();
|
2010-04-03 05:58:27 +04:00
|
|
|
result->SetStyleIfVisited(resultIfVisited.forget());
|
2010-04-03 05:58:27 +04:00
|
|
|
|
|
|
|
if (relevantLinkVisited) {
|
|
|
|
result->AddStyleBit(NS_STYLE_RELEVANT_LINK_VISITED);
|
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
}
|
2013-02-01 20:02:29 +04:00
|
|
|
if (!aParentContext) {
|
2003-03-06 22:14:17 +03:00
|
|
|
mRoots.AppendElement(result);
|
2013-02-01 20:02:29 +04:00
|
|
|
}
|
2003-03-06 22:14:17 +03:00
|
|
|
}
|
2009-12-11 10:37:40 +03:00
|
|
|
else {
|
|
|
|
NS_ASSERTION(result->GetPseudoType() == aPseudoType, "Unexpected type");
|
|
|
|
NS_ASSERTION(result->GetPseudo() == aPseudoTag, "Unexpected pseudo");
|
|
|
|
}
|
2002-03-31 20:59:00 +04:00
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
if (aFlags & eDoAnimation) {
|
2011-04-12 10:18:44 +04:00
|
|
|
// Normally the animation manager has already added the correct
|
|
|
|
// style rule. However, if the animation-name just changed, it
|
|
|
|
// might have been wrong. So ask it to double-check based on the
|
|
|
|
// resulting style context.
|
2011-05-01 02:16:19 +04:00
|
|
|
nsIStyleRule *oldAnimRule = GetAnimationRule(aRuleNode);
|
2011-04-12 10:18:44 +04:00
|
|
|
nsIStyleRule *animRule = PresContext()->AnimationManager()->
|
|
|
|
CheckAnimationRule(result, aElementForAnimation);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(result->RuleNode() == aRuleNode,
|
|
|
|
"unexpected rule node");
|
|
|
|
MOZ_ASSERT(!result->GetStyleIfVisited() == !aVisitedRuleNode,
|
|
|
|
"unexpected visited rule node");
|
|
|
|
MOZ_ASSERT(!aVisitedRuleNode ||
|
|
|
|
result->GetStyleIfVisited()->RuleNode() == aVisitedRuleNode,
|
|
|
|
"unexpected visited rule node");
|
|
|
|
MOZ_ASSERT(!aVisitedRuleNode ||
|
|
|
|
oldAnimRule == GetAnimationRule(aVisitedRuleNode),
|
|
|
|
"animation rule mismatch between rule nodes");
|
2011-05-01 02:16:19 +04:00
|
|
|
if (oldAnimRule != animRule) {
|
|
|
|
nsRuleNode *ruleNode =
|
|
|
|
ReplaceAnimationRule(aRuleNode, oldAnimRule, animRule);
|
|
|
|
nsRuleNode *visitedRuleNode = aVisitedRuleNode
|
|
|
|
? ReplaceAnimationRule(aVisitedRuleNode, oldAnimRule, animRule)
|
2012-07-30 18:20:58 +04:00
|
|
|
: nullptr;
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!visitedRuleNode ||
|
|
|
|
GetAnimationRule(ruleNode) ==
|
|
|
|
GetAnimationRule(visitedRuleNode),
|
|
|
|
"animation rule mismatch between rule nodes");
|
2011-04-12 10:18:44 +04:00
|
|
|
result = GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2013-02-01 20:02:29 +04:00
|
|
|
aPseudoTag, aPseudoType, nullptr,
|
|
|
|
aFlags & ~eDoAnimation);
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aElementForAnimation &&
|
|
|
|
aElementForAnimation->IsHTMLElement(nsGkAtoms::body) &&
|
2011-06-01 15:43:31 +04:00
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement &&
|
|
|
|
PresContext()->CompatibilityMode() == eCompatibility_NavQuirks) {
|
|
|
|
nsIDocument* doc = aElementForAnimation->GetCurrentDoc();
|
|
|
|
if (doc && doc->GetBodyElement() == aElementForAnimation) {
|
|
|
|
// Update the prescontext's body color
|
2013-02-17 01:51:02 +04:00
|
|
|
PresContext()->SetBodyTextColor(result->StyleColor()->mColor);
|
2011-06-01 15:43:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return result.forget();
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::AddImportantRules(nsRuleNode* aCurrLevelNode,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleNode* aLastPrevLevelNode,
|
|
|
|
nsRuleWalker* aRuleWalker)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2009-12-12 09:36:34 +03:00
|
|
|
NS_ASSERTION(aCurrLevelNode &&
|
|
|
|
aCurrLevelNode != aLastPrevLevelNode, "How did we get here?");
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
nsAutoTArray<nsIStyleRule*, 16> importantRules;
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
2009-12-11 01:36:02 +03:00
|
|
|
// We guarantee that we never walk the root node here, so no need
|
2011-05-24 00:45:43 +04:00
|
|
|
// to null-check GetRule(). Furthermore, it must be a CSS rule.
|
|
|
|
NS_ASSERTION(nsRefPtr<css::StyleRule>(do_QueryObject(node->GetRule())),
|
|
|
|
"Unexpected non-CSS rule");
|
|
|
|
|
|
|
|
nsIStyleRule* impRule =
|
|
|
|
static_cast<css::StyleRule*>(node->GetRule())->GetImportantRule();
|
2009-12-11 01:36:02 +03:00
|
|
|
if (impRule)
|
|
|
|
importantRules.AppendElement(impRule);
|
2008-07-14 00:57:38 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
NS_ASSERTION(importantRules.Length() != 0,
|
|
|
|
"Why did we think there were important rules?");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = importantRules.Length(); i-- != 0; ) {
|
2009-10-03 01:06:42 +04:00
|
|
|
aRuleWalker->Forward(importantRules[i]);
|
1998-09-11 06:05:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsStyleSet::AssertNoImportantRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode)
|
|
|
|
{
|
2008-07-14 00:57:38 +04:00
|
|
|
if (!aCurrLevelNode)
|
2004-07-16 00:30:30 +04:00
|
|
|
return;
|
|
|
|
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
2011-05-24 00:45:43 +04:00
|
|
|
nsRefPtr<css::StyleRule> rule(do_QueryObject(node->GetRule()));
|
|
|
|
NS_ASSERTION(rule, "Unexpected non-CSS rule");
|
|
|
|
|
|
|
|
NS_ASSERTION(!rule->GetImportantRule(), "Unexpected important rule");
|
2004-07-16 00:30:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStyleSet::AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode)
|
|
|
|
{
|
2008-07-14 00:57:38 +04:00
|
|
|
if (!aCurrLevelNode)
|
2004-07-16 00:30:30 +04:00
|
|
|
return;
|
|
|
|
|
2008-07-14 00:57:38 +04:00
|
|
|
for (nsRuleNode *node = aCurrLevelNode; node != aLastPrevLevelNode;
|
|
|
|
node = node->GetParent()) {
|
|
|
|
nsIStyleRule *rule = node->GetRule();
|
2011-05-24 00:45:43 +04:00
|
|
|
nsRefPtr<css::StyleRule> cssRule(do_QueryObject(rule));
|
2008-07-14 00:57:38 +04:00
|
|
|
NS_ASSERTION(!cssRule || !cssRule->Selector(), "Unexpected CSS rule");
|
|
|
|
}
|
2004-07-16 00:30:30 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate the rules in a way that cares about the order of the rules.
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
|
2013-01-09 03:25:47 +04:00
|
|
|
RuleProcessorData* aData, Element* aElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsRuleWalker* aRuleWalker)
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsStyleSet", "FileRules",
|
|
|
|
js::ProfileEntry::Category::CSS);
|
2012-09-15 01:12:34 +04:00
|
|
|
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
// Cascading order:
|
|
|
|
// [least important]
|
2012-08-30 05:27:01 +04:00
|
|
|
// - UA normal rules = Agent normal
|
|
|
|
// - User normal rules = User normal
|
|
|
|
// - Presentation hints = PresHint normal
|
2014-09-13 17:17:35 +04:00
|
|
|
// - SVG Animation (highest pres hint) = SVGAttrAnimation normal
|
2012-08-30 05:27:01 +04:00
|
|
|
// - Author normal rules = Document normal
|
|
|
|
// - Override normal rules = Override normal
|
|
|
|
// - animation rules = Animation normal
|
|
|
|
// - Author !important rules = Document !important
|
|
|
|
// - Override !important rules = Override !important
|
|
|
|
// - User !important rules = User !important
|
|
|
|
// - UA !important rules = Agent !important
|
|
|
|
// - transition rules = Transition normal
|
2001-11-06 13:04:05 +03:00
|
|
|
// [most important]
|
|
|
|
|
2011-05-24 00:45:42 +04:00
|
|
|
// Save off the last rule before we start walking our agent sheets;
|
|
|
|
// this will be either the root or one of the restriction rules.
|
|
|
|
nsRuleNode* lastRestrictionRN = aRuleWalker->CurrentNode();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eAgentSheet, false, true);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eAgentSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eAgentSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastAgentRN = aRuleWalker->CurrentNode();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveImportantUARules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eUserSheet, false, true);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool skipUserStyles =
|
2013-01-09 03:25:47 +04:00
|
|
|
aElement && aElement->IsInNativeAnonymousSubtree();
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eUserSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastUserRN = aRuleWalker->CurrentNode();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveImportantUserRules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(ePresHintSheet, false, false);
|
2011-01-15 05:14:41 +03:00
|
|
|
if (mRuleProcessors[ePresHintSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[ePresHintSheet], aData);
|
2014-09-13 17:17:35 +04:00
|
|
|
|
|
|
|
aRuleWalker->SetLevel(eSVGAttrAnimationSheet, false, false);
|
|
|
|
if (mRuleProcessors[eSVGAttrAnimationSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eSVGAttrAnimationSheet], aData);
|
|
|
|
nsRuleNode* lastSVGAttrAnimationRN = aRuleWalker->CurrentNode();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eDocSheet, false, true);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cutOffInheritance = false;
|
2013-01-09 03:25:47 +04:00
|
|
|
if (mBindingManager && aElement) {
|
2001-11-06 13:04:05 +03:00
|
|
|
// We can supply additional document-level sheets that should be walked.
|
2009-12-11 10:37:40 +03:00
|
|
|
mBindingManager->WalkRules(aCollectorFunc,
|
2012-11-14 23:09:01 +04:00
|
|
|
static_cast<ElementDependentRuleProcessorData*>(aData),
|
2009-12-11 10:37:40 +03:00
|
|
|
&cutOffInheritance);
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
2013-01-09 03:25:47 +04:00
|
|
|
if (!skipUserStyles && !cutOffInheritance && // NOTE: different
|
|
|
|
mRuleProcessors[eDocSheet])
|
2013-01-08 12:36:21 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eDocSheet], aData);
|
|
|
|
nsRuleNode* lastDocRN = aRuleWalker->CurrentNode();
|
|
|
|
bool haveImportantDocRules = !aRuleWalker->GetCheckForImportantRules();
|
2013-01-09 03:25:47 +04:00
|
|
|
nsTArray<nsRuleNode*> lastScopedRNs;
|
|
|
|
nsTArray<bool> haveImportantScopedRules;
|
|
|
|
bool haveAnyImportantScopedRules = false;
|
|
|
|
if (!skipUserStyles && !cutOffInheritance &&
|
|
|
|
aElement && aElement->IsElementInStyleScope()) {
|
|
|
|
lastScopedRNs.SetLength(mScopedDocSheetRuleProcessors.Length());
|
|
|
|
haveImportantScopedRules.SetLength(mScopedDocSheetRuleProcessors.Length());
|
2013-01-10 22:40:53 +04:00
|
|
|
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) {
|
2013-01-09 03:25:47 +04:00
|
|
|
aRuleWalker->SetLevel(eScopedDocSheet, false, true);
|
|
|
|
nsCSSRuleProcessor* processor =
|
|
|
|
static_cast<nsCSSRuleProcessor*>(mScopedDocSheetRuleProcessors[i].get());
|
2013-01-09 03:25:48 +04:00
|
|
|
aData->mScope = processor->GetScopeElement();
|
2013-01-09 03:25:47 +04:00
|
|
|
(*aCollectorFunc)(mScopedDocSheetRuleProcessors[i], aData);
|
|
|
|
lastScopedRNs[i] = aRuleWalker->CurrentNode();
|
|
|
|
haveImportantScopedRules[i] = !aRuleWalker->GetCheckForImportantRules();
|
|
|
|
haveAnyImportantScopedRules = haveAnyImportantScopedRules || haveImportantScopedRules[i];
|
|
|
|
}
|
2013-01-09 03:25:48 +04:00
|
|
|
aData->mScope = nullptr;
|
2013-01-09 03:25:47 +04:00
|
|
|
}
|
|
|
|
nsRuleNode* lastScopedRN = aRuleWalker->CurrentNode();
|
|
|
|
aRuleWalker->SetLevel(eStyleAttrSheet, false, true);
|
|
|
|
if (mRuleProcessors[eStyleAttrSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eStyleAttrSheet], aData);
|
|
|
|
nsRuleNode* lastStyleAttrRN = aRuleWalker->CurrentNode();
|
|
|
|
bool haveImportantStyleAttrRules = !aRuleWalker->GetCheckForImportantRules();
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eOverrideSheet, false, true);
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eOverrideSheet])
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eOverrideSheet], aData);
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode* lastOvrRN = aRuleWalker->CurrentNode();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveImportantOverrideRules = !aRuleWalker->GetCheckForImportantRules();
|
2009-12-11 01:36:02 +03:00
|
|
|
|
2012-08-30 05:27:01 +04:00
|
|
|
// This needs to match IsMoreSpecificThanAnimation() above.
|
|
|
|
aRuleWalker->SetLevel(eAnimationSheet, false, false);
|
|
|
|
(*aCollectorFunc)(mRuleProcessors[eAnimationSheet], aData);
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
if (haveAnyImportantScopedRules) {
|
|
|
|
for (uint32_t i = lastScopedRNs.Length(); i-- != 0; ) {
|
|
|
|
aRuleWalker->SetLevel(eScopedDocSheet, true, false);
|
|
|
|
nsRuleNode* startRN = lastScopedRNs[i];
|
|
|
|
nsRuleNode* endRN = i == 0 ? lastDocRN : lastScopedRNs[i - 1];
|
|
|
|
if (haveImportantScopedRules[i]) {
|
|
|
|
AddImportantRules(startRN, endRN, aRuleWalker); // scoped
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
AssertNoImportantRules(startRN, endRN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
AssertNoImportantRules(lastScopedRN, lastDocRN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
if (haveImportantDocRules) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eDocSheet, true, false);
|
2014-09-13 17:17:35 +04:00
|
|
|
AddImportantRules(lastDocRN, lastSVGAttrAnimationRN, aRuleWalker); // doc
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2014-09-13 17:17:35 +04:00
|
|
|
AssertNoImportantRules(lastDocRN, lastSVGAttrAnimationRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
if (haveImportantStyleAttrRules) {
|
|
|
|
aRuleWalker->SetLevel(eStyleAttrSheet, true, false);
|
|
|
|
AddImportantRules(lastStyleAttrRN, lastScopedRN, aRuleWalker); // style attr
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
AssertNoImportantRules(lastStyleAttrRN, lastScopedRN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-11 01:36:02 +03:00
|
|
|
if (haveImportantOverrideRules) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eOverrideSheet, true, false);
|
2013-01-09 03:25:47 +04:00
|
|
|
AddImportantRules(lastOvrRN, lastStyleAttrRN, aRuleWalker); // override
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2013-01-09 03:25:47 +04:00
|
|
|
AssertNoImportantRules(lastOvrRN, lastStyleAttrRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
#ifdef DEBUG
|
2014-09-13 17:17:35 +04:00
|
|
|
AssertNoCSSRules(lastSVGAttrAnimationRN, lastUserRN);
|
2004-07-16 00:30:30 +04:00
|
|
|
#endif
|
2009-12-11 01:36:02 +03:00
|
|
|
|
|
|
|
if (haveImportantUserRules) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eUserSheet, true, false);
|
2011-01-15 05:14:41 +03:00
|
|
|
AddImportantRules(lastUserRN, lastAgentRN, aRuleWalker); //user
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2011-01-15 05:14:41 +03:00
|
|
|
AssertNoImportantRules(lastUserRN, lastAgentRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (haveImportantUARules) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eAgentSheet, true, false);
|
2011-05-24 00:45:42 +04:00
|
|
|
AddImportantRules(lastAgentRN, lastRestrictionRN, aRuleWalker); //agent
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2011-05-24 00:45:42 +04:00
|
|
|
AssertNoImportantRules(lastAgentRN, lastRestrictionRN);
|
2009-12-11 01:36:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2011-05-24 00:45:42 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
AssertNoCSSRules(lastRestrictionRN, mRuleTree);
|
|
|
|
#endif
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
#ifdef DEBUG
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *lastImportantRN = aRuleWalker->CurrentNode();
|
2009-10-08 07:22:42 +04:00
|
|
|
#endif
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eTransitionSheet, false, false);
|
2009-10-08 07:22:42 +04:00
|
|
|
(*aCollectorFunc)(mRuleProcessors[eTransitionSheet], aData);
|
|
|
|
#ifdef DEBUG
|
2009-12-12 09:36:34 +03:00
|
|
|
AssertNoCSSRules(aRuleWalker->CurrentNode(), lastImportantRN);
|
2009-10-08 07:22:42 +04:00
|
|
|
#endif
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate all the rules in a way that doesn't care about the order
|
2004-01-14 04:36:35 +03:00
|
|
|
// of the rules and doesn't walk !important-rules.
|
2001-11-11 02:51:45 +03:00
|
|
|
void
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
|
2012-11-14 23:09:01 +04:00
|
|
|
ElementDependentRuleProcessorData* aData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aWalkAllXBLStylesheets)
|
2001-11-11 02:51:45 +03:00
|
|
|
{
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
|
|
|
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eAgentSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eAgentSheet], aData);
|
2007-05-05 10:47:09 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool skipUserStyles = aData->mElement->IsInNativeAnonymousSubtree();
|
2007-05-05 10:47:09 +04:00
|
|
|
if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
|
2004-07-28 11:08:41 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eUserSheet], aData);
|
2007-05-05 10:47:09 +04:00
|
|
|
|
2011-01-15 05:14:41 +03:00
|
|
|
if (mRuleProcessors[ePresHintSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[ePresHintSheet], aData);
|
2013-05-20 06:59:20 +04:00
|
|
|
|
2014-09-13 17:17:35 +04:00
|
|
|
if (mRuleProcessors[eSVGAttrAnimationSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eSVGAttrAnimationSheet], aData);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cutOffInheritance = false;
|
2007-02-17 02:02:08 +03:00
|
|
|
if (mBindingManager) {
|
2001-11-11 02:51:45 +03:00
|
|
|
// We can supply additional document-level sheets that should be walked.
|
2010-03-25 12:22:58 +03:00
|
|
|
if (aWalkAllXBLStylesheets) {
|
|
|
|
mBindingManager->WalkAllRules(aFunc, aData);
|
|
|
|
} else {
|
|
|
|
mBindingManager->WalkRules(aFunc, aData, &cutOffInheritance);
|
|
|
|
}
|
2001-11-11 02:51:45 +03:00
|
|
|
}
|
2013-01-09 03:25:47 +04:00
|
|
|
if (!skipUserStyles && !cutOffInheritance) {
|
|
|
|
if (mRuleProcessors[eDocSheet]) // NOTE: different
|
|
|
|
(*aFunc)(mRuleProcessors[eDocSheet], aData);
|
|
|
|
if (aData->mElement->IsElementInStyleScope()) {
|
2013-01-10 22:40:53 +04:00
|
|
|
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++)
|
2013-01-09 03:25:47 +04:00
|
|
|
(*aFunc)(mScopedDocSheetRuleProcessors[i], aData);
|
|
|
|
}
|
|
|
|
}
|
2004-07-28 11:08:41 +04:00
|
|
|
if (mRuleProcessors[eStyleAttrSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eStyleAttrSheet], aData);
|
|
|
|
if (mRuleProcessors[eOverrideSheet])
|
|
|
|
(*aFunc)(mRuleProcessors[eOverrideSheet], aData);
|
2011-04-12 10:18:44 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eAnimationSheet], aData);
|
2011-05-01 02:16:19 +04:00
|
|
|
(*aFunc)(mRuleProcessors[eTransitionSheet], aData);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 03:28:49 +04:00
|
|
|
static void
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(TreeMatchContext& aTreeContext, Element* aElement)
|
2013-10-11 03:28:49 +04:00
|
|
|
{
|
|
|
|
if (aElement->IsElementInStyleScope()) {
|
2014-07-24 12:12:38 +04:00
|
|
|
aTreeContext.InitStyleScopes(aElement->GetParentElementCrossingShadowRoot());
|
2013-10-11 03:28:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolveStyleFor(Element* aElement,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aParentContext)
|
2011-03-29 21:29:21 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(true, nsRuleWalker::eRelevantLinkUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aElement);
|
2011-03-29 21:29:21 +04:00
|
|
|
return ResolveStyleFor(aElement, aParentContext, treeContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveStyleFor(Element* aElement,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
TreeMatchContext& aTreeMatchContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aElement, "aElement must not be null");
|
1998-05-19 01:05:52 +04:00
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.ResetForUnvisitedMatching();
|
2011-03-29 21:29:21 +04:00
|
|
|
ElementRuleProcessorData data(PresContext(), aElement, &ruleWalker,
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext);
|
2013-06-29 07:28:50 +04:00
|
|
|
WalkDisableTextZoomRule(aElement, &ruleWalker);
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
|
2010-04-02 10:07:42 +04:00
|
|
|
&ruleWalker);
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aTreeMatchContext.HaveRelevantLink()) {
|
|
|
|
aTreeMatchContext.ResetForVisitedMatching();
|
2011-03-29 21:29:21 +04:00
|
|
|
ruleWalker.Reset();
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<ElementRuleProcessorData>, &data, aElement,
|
2010-04-03 05:58:27 +04:00
|
|
|
&ruleWalker);
|
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
uint32_t flags = eDoAnimation;
|
|
|
|
if (nsCSSRuleProcessor::IsLink(aElement)) {
|
|
|
|
flags |= eIsLink;
|
|
|
|
}
|
|
|
|
if (nsCSSRuleProcessor::GetContentState(aElement, aTreeMatchContext).
|
|
|
|
HasState(NS_EVENT_STATE_VISITED)) {
|
|
|
|
flags |= eIsVisitedLink;
|
|
|
|
}
|
2014-06-16 17:55:00 +04:00
|
|
|
if (aTreeMatchContext.mSkippingParentDisplayBasedStyleFixup) {
|
|
|
|
flags |= eSkipParentDisplayBasedStyleFixup;
|
2013-02-21 11:35:03 +04:00
|
|
|
}
|
2013-02-01 20:02:29 +04:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
2013-02-01 20:02:29 +04:00
|
|
|
aElement, flags);
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 22:21:34 +04:00
|
|
|
already_AddRefed<nsStyleContext>
|
2009-08-11 02:52:29 +04:00
|
|
|
nsStyleSet::ResolveStyleForRules(nsStyleContext* aParentContext,
|
2012-10-18 01:01:56 +04:00
|
|
|
const nsTArray< nsCOMPtr<nsIStyleRule> > &aRules)
|
2007-07-25 22:21:34 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2010-04-02 10:07:42 +04:00
|
|
|
// FIXME: Perhaps this should be passed in, but it probably doesn't
|
|
|
|
// matter.
|
2011-10-17 18:59:28 +04:00
|
|
|
ruleWalker.SetLevel(eDocSheet, false, false);
|
2012-10-18 01:01:56 +04:00
|
|
|
for (uint32_t i = 0; i < aRules.Length(); i++) {
|
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(aRules.ElementAt(i));
|
2007-07-25 22:21:34 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetContext(aParentContext, ruleWalker.CurrentNode(), nullptr,
|
|
|
|
nullptr, nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
2013-02-01 20:02:29 +04:00
|
|
|
nullptr, eNoFlags);
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
|
|
|
|
const nsCOMArray<nsIStyleRule> &aRules)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2010-04-03 05:58:25 +04:00
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2013-02-17 01:04:53 +04:00
|
|
|
ruleWalker.SetCurrentNode(aBaseContext->RuleNode());
|
2014-11-17 22:39:14 +03:00
|
|
|
// This needs to be the transition sheet because that is the highest
|
|
|
|
// level of the cascade, and thus the only thing that makes sense if
|
|
|
|
// we are ever going to call ResolveStyleWithReplacement on the
|
|
|
|
// resulting context. It's also the right thing for the one case (the
|
|
|
|
// transition manager's cover rule) where we put the result of this
|
|
|
|
// function in the style context tree.
|
|
|
|
ruleWalker.SetLevel(eTransitionSheet, false, false);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < aRules.Count(); i++) {
|
2011-05-26 00:54:30 +04:00
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(aRules.ObjectAt(i));
|
2010-04-03 05:58:25 +04:00
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
|
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
|
|
|
|
if (aBaseContext->GetStyleIfVisited()) {
|
2013-02-17 01:04:53 +04:00
|
|
|
ruleWalker.SetCurrentNode(aBaseContext->GetStyleIfVisited()->RuleNode());
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < aRules.Count(); i++) {
|
2011-05-26 00:54:30 +04:00
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(aRules.ObjectAt(i));
|
2010-04-03 05:58:27 +04:00
|
|
|
}
|
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
uint32_t flags = eNoFlags;
|
|
|
|
if (aBaseContext->IsLinkContext()) {
|
|
|
|
flags |= eIsLink;
|
2014-08-03 06:37:42 +04:00
|
|
|
|
|
|
|
// GetContext handles propagating RelevantLinkVisited state from the
|
|
|
|
// parent in non-link cases; all we need to pass in is if this link
|
|
|
|
// is visited.
|
|
|
|
if (aBaseContext->RelevantLinkVisited()) {
|
|
|
|
flags |= eIsVisitedLink;
|
|
|
|
}
|
2013-02-01 20:02:29 +04:00
|
|
|
}
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aBaseContext->GetParent(), ruleNode, visitedRuleNode,
|
2010-04-03 05:58:25 +04:00
|
|
|
aBaseContext->GetPseudo(),
|
2011-04-12 10:18:44 +04:00
|
|
|
aBaseContext->GetPseudoType(),
|
2013-02-01 20:02:29 +04:00
|
|
|
nullptr, flags);
|
2007-07-25 22:21:34 +04:00
|
|
|
}
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
struct RuleNodeInfo {
|
|
|
|
nsIStyleRule* mRule;
|
|
|
|
uint8_t mLevel;
|
|
|
|
bool mIsImportant;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CascadeLevel {
|
|
|
|
uint8_t mLevel;
|
|
|
|
bool mIsImportant;
|
2014-09-13 17:17:36 +04:00
|
|
|
bool mCheckForImportantRules;
|
2014-08-03 06:37:44 +04:00
|
|
|
nsRestyleHint mLevelReplacementHint;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CascadeLevel gCascadeLevels[] = {
|
2014-09-13 17:17:36 +04:00
|
|
|
{ nsStyleSet::eAgentSheet, false, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eUserSheet, false, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::ePresHintSheet, false, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eSVGAttrAnimationSheet, false, false, eRestyle_SVGAttrAnimations },
|
|
|
|
{ nsStyleSet::eDocSheet, false, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eScopedDocSheet, false, false, nsRestyleHint(0) },
|
2015-02-19 11:22:05 +03:00
|
|
|
{ nsStyleSet::eStyleAttrSheet, false, true, eRestyle_StyleAttribute |
|
|
|
|
eRestyle_StyleAttribute_Animations },
|
2014-09-13 17:17:36 +04:00
|
|
|
{ nsStyleSet::eOverrideSheet, false, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eAnimationSheet, false, false, eRestyle_CSSAnimations },
|
|
|
|
{ nsStyleSet::eScopedDocSheet, true, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eDocSheet, true, false, nsRestyleHint(0) },
|
2015-02-19 11:22:05 +03:00
|
|
|
{ nsStyleSet::eStyleAttrSheet, true, false, eRestyle_StyleAttribute |
|
|
|
|
eRestyle_StyleAttribute_Animations },
|
2014-09-13 17:17:36 +04:00
|
|
|
{ nsStyleSet::eOverrideSheet, true, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eUserSheet, true, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eAgentSheet, true, false, nsRestyleHint(0) },
|
|
|
|
{ nsStyleSet::eTransitionSheet, false, false, eRestyle_CSSTransitions },
|
2014-08-03 06:37:44 +04:00
|
|
|
};
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
nsRuleNode*
|
|
|
|
nsStyleSet::RuleNodeWithReplacement(Element* aElement,
|
2015-02-17 01:15:05 +03:00
|
|
|
Element* aPseudoElement,
|
2014-08-03 06:37:44 +04:00
|
|
|
nsRuleNode* aOldRuleNode,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
nsRestyleHint aReplacements)
|
2014-08-03 06:37:43 +04:00
|
|
|
{
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
|
|
|
|
2015-02-17 01:15:05 +03:00
|
|
|
MOZ_ASSERT(!aPseudoElement ==
|
|
|
|
(aPseudoType >= nsCSSPseudoElements::ePseudo_PseudoElementCount ||
|
|
|
|
!(nsCSSPseudoElements::PseudoElementSupportsStyleAttribute(aPseudoType) ||
|
|
|
|
nsCSSPseudoElements::PseudoElementSupportsUserActionState(aPseudoType))),
|
|
|
|
"should have aPseudoElement only for certain pseudo elements");
|
|
|
|
|
2015-02-10 04:05:37 +03:00
|
|
|
MOZ_ASSERT(!(aReplacements & ~(eRestyle_CSSTransitions |
|
|
|
|
eRestyle_CSSAnimations |
|
|
|
|
eRestyle_SVGAttrAnimations |
|
|
|
|
eRestyle_StyleAttribute |
|
2015-02-19 11:22:05 +03:00
|
|
|
eRestyle_StyleAttribute_Animations |
|
2015-02-10 04:05:37 +03:00
|
|
|
eRestyle_Force |
|
|
|
|
eRestyle_ForceDescendants)),
|
|
|
|
"unexpected replacement bits");
|
2014-08-03 06:37:44 +04:00
|
|
|
|
2014-08-03 06:37:46 +04:00
|
|
|
// FIXME (perf): This should probably not rebuild the whole path, but
|
|
|
|
// only the path from the last change in the rule tree, like
|
|
|
|
// ReplaceAnimationRule in nsStyleSet.cpp does. (That could then
|
|
|
|
// perhaps share this code, too?)
|
2014-08-04 00:11:55 +04:00
|
|
|
// But if we do that, we'll need to pass whether we are rebuilding the
|
|
|
|
// rule tree from ElementRestyler::RestyleSelf to avoid taking that
|
|
|
|
// path when we're rebuilding the rule tree.
|
2014-08-03 06:37:46 +04:00
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
nsTArray<RuleNodeInfo> rules;
|
2014-08-03 06:37:44 +04:00
|
|
|
for (nsRuleNode* ruleNode = aOldRuleNode; !ruleNode->IsRoot();
|
2014-08-03 06:37:44 +04:00
|
|
|
ruleNode = ruleNode->GetParent()) {
|
|
|
|
RuleNodeInfo* curRule = rules.AppendElement();
|
|
|
|
curRule->mRule = ruleNode->GetRule();
|
|
|
|
curRule->mLevel = ruleNode->GetLevel();
|
|
|
|
curRule->mIsImportant = ruleNode->IsImportantRule();
|
|
|
|
}
|
2014-08-03 06:37:43 +04:00
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
|
|
|
auto rulesIndex = rules.Length();
|
|
|
|
|
2014-09-13 17:17:36 +04:00
|
|
|
// We need to transfer this information between the non-!important and
|
|
|
|
// !important phases for the style attribute level.
|
|
|
|
nsRuleNode* lastScopedRN = nullptr;
|
|
|
|
nsRuleNode* lastStyleAttrRN = nullptr;
|
|
|
|
bool haveImportantStyleAttrRules = false;
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
for (const CascadeLevel *level = gCascadeLevels,
|
|
|
|
*levelEnd = ArrayEnd(gCascadeLevels);
|
|
|
|
level != levelEnd; ++level) {
|
|
|
|
|
|
|
|
bool doReplace = level->mLevelReplacementHint & aReplacements;
|
2014-09-13 17:17:36 +04:00
|
|
|
|
|
|
|
ruleWalker.SetLevel(level->mLevel, level->mIsImportant,
|
|
|
|
level->mCheckForImportantRules && doReplace);
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
if (doReplace) {
|
2015-02-19 11:22:05 +03:00
|
|
|
switch (level->mLevel) {
|
|
|
|
case nsStyleSet::eAnimationSheet: {
|
2014-11-12 02:42:57 +03:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
nsIStyleRule* rule = PresContext()->AnimationManager()->
|
|
|
|
GetAnimationRule(aElement, aPseudoType);
|
|
|
|
if (rule) {
|
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(rule);
|
2014-08-03 06:37:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-19 11:22:05 +03:00
|
|
|
case nsStyleSet::eTransitionSheet: {
|
2014-11-12 02:42:57 +03:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_after) {
|
2014-11-20 05:48:41 +03:00
|
|
|
nsIStyleRule* rule = PresContext()->TransitionManager()->
|
|
|
|
GetAnimationRule(aElement, aPseudoType);
|
|
|
|
if (rule) {
|
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(rule);
|
|
|
|
}
|
2014-08-03 06:37:44 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-19 11:22:05 +03:00
|
|
|
case nsStyleSet::eSVGAttrAnimationSheet: {
|
2014-09-13 17:17:35 +04:00
|
|
|
SVGAttrAnimationRuleProcessor* ruleProcessor =
|
|
|
|
static_cast<SVGAttrAnimationRuleProcessor*>(
|
|
|
|
mRuleProcessors[eSVGAttrAnimationSheet].get());
|
|
|
|
if (ruleProcessor &&
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
ruleProcessor->ElementRulesMatching(aElement, &ruleWalker);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-19 11:22:05 +03:00
|
|
|
case nsStyleSet::eStyleAttrSheet: {
|
2014-09-13 17:17:36 +04:00
|
|
|
if (!level->mIsImportant) {
|
|
|
|
// First time through, we handle the non-!important rule.
|
|
|
|
nsHTMLCSSStyleSheet* ruleProcessor =
|
|
|
|
static_cast<nsHTMLCSSStyleSheet*>(
|
|
|
|
mRuleProcessors[eStyleAttrSheet].get());
|
2015-02-17 01:15:05 +03:00
|
|
|
if (ruleProcessor) {
|
2014-09-13 17:17:36 +04:00
|
|
|
lastScopedRN = ruleWalker.CurrentNode();
|
2015-02-17 01:15:05 +03:00
|
|
|
if (aPseudoType ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
ruleProcessor->ElementRulesMatching(PresContext(),
|
|
|
|
aElement,
|
|
|
|
&ruleWalker);
|
|
|
|
} else if (aPseudoType <
|
|
|
|
nsCSSPseudoElements::ePseudo_PseudoElementCount &&
|
|
|
|
nsCSSPseudoElements::
|
|
|
|
PseudoElementSupportsStyleAttribute(aPseudoType)) {
|
|
|
|
ruleProcessor->PseudoElementRulesMatching(aPseudoElement,
|
|
|
|
aPseudoType,
|
|
|
|
&ruleWalker);
|
|
|
|
}
|
2014-09-13 17:17:36 +04:00
|
|
|
lastStyleAttrRN = ruleWalker.CurrentNode();
|
|
|
|
haveImportantStyleAttrRules =
|
|
|
|
!ruleWalker.GetCheckForImportantRules();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Second time through, we handle the !important rule(s).
|
|
|
|
if (haveImportantStyleAttrRules) {
|
|
|
|
AddImportantRules(lastStyleAttrRN, lastScopedRN, &ruleWalker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-08-03 06:37:44 +04:00
|
|
|
default:
|
2014-09-13 17:17:36 +04:00
|
|
|
MOZ_ASSERT(false, "unexpected result from gCascadeLevels lookup");
|
2014-08-03 06:37:44 +04:00
|
|
|
break;
|
2014-08-03 06:37:44 +04:00
|
|
|
}
|
2014-08-03 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
while (rulesIndex != 0) {
|
|
|
|
--rulesIndex;
|
|
|
|
const RuleNodeInfo& ruleInfo = rules[rulesIndex];
|
|
|
|
|
|
|
|
if (ruleInfo.mLevel != level->mLevel ||
|
|
|
|
ruleInfo.mIsImportant != level->mIsImportant) {
|
|
|
|
++rulesIndex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!doReplace) {
|
|
|
|
ruleWalker.ForwardOnPossiblyCSSRule(ruleInfo.mRule);
|
|
|
|
}
|
2014-08-03 06:37:43 +04:00
|
|
|
}
|
2014-08-03 06:37:44 +04:00
|
|
|
}
|
2014-08-03 06:37:43 +04:00
|
|
|
|
2014-11-17 22:39:14 +03:00
|
|
|
NS_ASSERTION(rulesIndex == 0,
|
|
|
|
"rules are in incorrect cascading order, "
|
|
|
|
"which means we replaced them incorrectly");
|
|
|
|
|
2014-08-03 06:37:44 +04:00
|
|
|
return ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveStyleWithReplacement(Element* aElement,
|
2015-02-17 01:15:05 +03:00
|
|
|
Element* aPseudoElement,
|
2014-08-03 06:37:44 +04:00
|
|
|
nsStyleContext* aNewParentContext,
|
|
|
|
nsStyleContext* aOldStyleContext,
|
2015-02-17 01:15:00 +03:00
|
|
|
nsRestyleHint aReplacements,
|
|
|
|
uint32_t aFlags)
|
2014-08-03 06:37:44 +04:00
|
|
|
{
|
|
|
|
nsRuleNode* ruleNode =
|
2015-02-17 01:15:05 +03:00
|
|
|
RuleNodeWithReplacement(aElement, aPseudoElement,
|
|
|
|
aOldStyleContext->RuleNode(),
|
2014-08-03 06:37:44 +04:00
|
|
|
aOldStyleContext->GetPseudoType(), aReplacements);
|
|
|
|
|
2014-08-03 06:37:45 +04:00
|
|
|
nsRuleNode* visitedRuleNode = nullptr;
|
|
|
|
nsStyleContext* oldStyleIfVisited = aOldStyleContext->GetStyleIfVisited();
|
|
|
|
if (oldStyleIfVisited) {
|
|
|
|
if (oldStyleIfVisited->RuleNode() == aOldStyleContext->RuleNode()) {
|
|
|
|
visitedRuleNode = ruleNode;
|
|
|
|
} else {
|
|
|
|
visitedRuleNode =
|
2015-02-17 01:15:05 +03:00
|
|
|
RuleNodeWithReplacement(aElement, aPseudoElement,
|
|
|
|
oldStyleIfVisited->RuleNode(),
|
2014-08-03 06:37:45 +04:00
|
|
|
oldStyleIfVisited->GetPseudoType(),
|
|
|
|
aReplacements);
|
|
|
|
}
|
|
|
|
}
|
2014-08-03 06:37:44 +04:00
|
|
|
|
|
|
|
uint32_t flags = eNoFlags;
|
|
|
|
if (aOldStyleContext->IsLinkContext()) {
|
|
|
|
flags |= eIsLink;
|
2014-08-03 06:37:44 +04:00
|
|
|
|
|
|
|
// GetContext handles propagating RelevantLinkVisited state from the
|
|
|
|
// parent in non-link cases; all we need to pass in is if this link
|
|
|
|
// is visited.
|
|
|
|
if (aOldStyleContext->RelevantLinkVisited()) {
|
|
|
|
flags |= eIsVisitedLink;
|
|
|
|
}
|
2014-08-03 06:37:44 +04:00
|
|
|
}
|
|
|
|
|
2014-08-03 06:37:45 +04:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aOldStyleContext->GetPseudoType();
|
|
|
|
Element* elementForAnimation = nullptr;
|
2015-02-17 01:15:00 +03:00
|
|
|
if (!(aFlags & eSkipStartingAnimations) &&
|
|
|
|
(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_after)) {
|
2014-08-03 06:37:45 +04:00
|
|
|
// We want to compute a correct elementForAnimation to pass in
|
|
|
|
// because at this point the parameter is more than just the element
|
|
|
|
// for animation; it's also used for the SetBodyTextColor call when
|
|
|
|
// it's the body element.
|
|
|
|
// However, we only want to set the flag to call CheckAnimationRule
|
|
|
|
// if we're dealing with a replacement (such as style attribute
|
|
|
|
// replacement) that could lead to the animation property changing,
|
|
|
|
// and we explicitly do NOT want to call CheckAnimationRule when
|
|
|
|
// we're trying to do an animation-only update.
|
|
|
|
if (aReplacements & ~(eRestyle_CSSTransitions | eRestyle_CSSAnimations)) {
|
|
|
|
flags |= eDoAnimation;
|
|
|
|
}
|
|
|
|
elementForAnimation = aElement;
|
|
|
|
NS_ASSERTION(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
!elementForAnimation->GetPrimaryFrame() ||
|
|
|
|
elementForAnimation->GetPrimaryFrame()->StyleContext()->
|
|
|
|
GetPseudoType() ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
"aElement should be the element and not the pseudo-element");
|
|
|
|
}
|
|
|
|
|
2014-08-03 06:37:46 +04:00
|
|
|
if (aElement && aElement->IsRootOfAnonymousSubtree()) {
|
|
|
|
// For anonymous subtree roots, don't tweak "display" value based on whether
|
|
|
|
// or not the parent is styled as a flex/grid container. (If the parent
|
|
|
|
// has anonymous-subtree kids, then we know it's not actually going to get
|
|
|
|
// a flex/grid container frame, anyway.)
|
|
|
|
flags |= eSkipParentDisplayBasedStyleFixup;
|
|
|
|
}
|
|
|
|
|
2014-08-03 06:37:45 +04:00
|
|
|
return GetContext(aNewParentContext, ruleNode, visitedRuleNode,
|
2014-08-03 06:37:45 +04:00
|
|
|
aOldStyleContext->GetPseudo(), pseudoType,
|
|
|
|
elementForAnimation, flags);
|
2014-08-03 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2015-02-17 01:15:01 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveStyleWithoutAnimation(dom::Element* aTarget,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsRestyleHint aWhichToRemove)
|
|
|
|
{
|
2015-02-17 01:15:05 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCSSPseudoElements::Type pseudoType = aStyleContext->GetPseudoType();
|
|
|
|
#endif
|
|
|
|
MOZ_ASSERT(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_after,
|
|
|
|
"unexpected type for animations");
|
2015-02-17 01:15:01 +03:00
|
|
|
RestyleManager* restyleManager = PresContext()->RestyleManager();
|
|
|
|
|
|
|
|
bool oldSkipAnimationRules = restyleManager->SkipAnimationRules();
|
|
|
|
restyleManager->SetSkipAnimationRules(true);
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> result =
|
2015-02-17 01:15:05 +03:00
|
|
|
ResolveStyleWithReplacement(aTarget, nullptr, aStyleContext->GetParent(),
|
2015-02-17 01:15:01 +03:00
|
|
|
aStyleContext, aWhichToRemove,
|
|
|
|
eSkipStartingAnimations);
|
|
|
|
|
|
|
|
restyleManager->SetSkipAnimationRules(oldSkipAnimationRules);
|
|
|
|
|
|
|
|
return result.forget();
|
|
|
|
}
|
2014-08-03 06:37:43 +04:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2015-05-04 00:52:53 +03:00
|
|
|
nsStyleSet::ResolveStyleForNonElement(nsStyleContext* aParentContext)
|
2001-10-30 09:02:05 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetContext(aParentContext, mRuleTree, nullptr,
|
2010-04-02 10:07:42 +04:00
|
|
|
nsCSSAnonBoxes::mozNonElement,
|
2013-02-01 20:02:29 +04:00
|
|
|
nsCSSPseudoElements::ePseudo_AnonBox, nullptr,
|
2015-05-04 00:52:53 +03:00
|
|
|
eNoFlags);
|
2001-10-30 09:02:05 +03:00
|
|
|
}
|
|
|
|
|
2008-12-12 21:59:03 +03:00
|
|
|
void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsStyleSet::WalkRestrictionRule(nsCSSPseudoElements::Type aPseudoType,
|
2009-10-03 01:06:42 +04:00
|
|
|
nsRuleWalker* aRuleWalker)
|
2008-12-12 21:59:03 +03:00
|
|
|
{
|
|
|
|
// This needs to match GetPseudoRestriction in nsRuleNode.cpp.
|
2011-10-17 18:59:28 +04:00
|
|
|
aRuleWalker->SetLevel(eAgentSheet, false, false);
|
2009-12-11 10:37:40 +03:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLetter)
|
|
|
|
aRuleWalker->Forward(mFirstLetterRule);
|
|
|
|
else if (aPseudoType == nsCSSPseudoElements::ePseudo_firstLine)
|
|
|
|
aRuleWalker->Forward(mFirstLineRule);
|
2012-11-09 14:25:52 +04:00
|
|
|
else if (aPseudoType == nsCSSPseudoElements::ePseudo_mozPlaceholder)
|
|
|
|
aRuleWalker->Forward(mPlaceholderRule);
|
2009-12-11 05:28:08 +03:00
|
|
|
}
|
|
|
|
|
2013-06-29 07:28:50 +04:00
|
|
|
void
|
|
|
|
nsStyleSet::WalkDisableTextZoomRule(Element* aElement, nsRuleWalker* aRuleWalker)
|
|
|
|
{
|
|
|
|
aRuleWalker->SetLevel(eAgentSheet, false, false);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aElement->IsSVGElement(nsGkAtoms::text))
|
2013-06-29 07:28:50 +04:00
|
|
|
aRuleWalker->Forward(mDisableTextZoomStyleRule);
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolvePseudoElementStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aType,
|
2013-07-10 02:25:27 +04:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
Element* aPseudoElement)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
|
|
|
|
"must have pseudo element type");
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aParentElement, "Must have parent element");
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(true, nsRuleWalker::eRelevantLinkUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aParentElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aParentElement);
|
2010-04-30 17:12:06 +04:00
|
|
|
PseudoElementRuleProcessorData data(PresContext(), aParentElement,
|
2013-07-10 02:25:27 +04:00
|
|
|
&ruleWalker, aType, treeContext,
|
|
|
|
aPseudoElement);
|
2009-12-11 10:37:40 +03:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
if (treeContext.HaveRelevantLink()) {
|
|
|
|
treeContext.ResetForVisitedMatching();
|
|
|
|
ruleWalker.Reset();
|
2011-05-24 00:45:42 +04:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
2013-05-03 01:04:47 +04:00
|
|
|
uint32_t flags = eNoFlags;
|
2013-02-01 20:02:29 +04:00
|
|
|
if (aType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
aType == nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
flags |= eDoAnimation;
|
2013-05-03 01:04:47 +04:00
|
|
|
} else {
|
2014-05-03 17:42:33 +04:00
|
|
|
// Flex and grid containers don't expect to have any pseudo-element children
|
|
|
|
// aside from ::before and ::after. So if we have such a child, we're not
|
|
|
|
// actually in a flex/grid container, and we should skip flex/grid item
|
|
|
|
// style fixup.
|
2014-06-16 17:55:00 +04:00
|
|
|
flags |= eSkipParentDisplayBasedStyleFixup;
|
2013-02-01 20:02:29 +04:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2011-04-12 10:18:44 +04:00
|
|
|
nsCSSPseudoElements::GetPseudoAtom(aType), aType,
|
2013-02-01 20:02:29 +04:00
|
|
|
aParentElement, flags);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ProbePseudoElementStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aType,
|
|
|
|
nsStyleContext* aParentContext)
|
2011-03-29 21:29:21 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(true, nsRuleWalker::eRelevantLinkUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aParentElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aParentElement);
|
2011-03-29 21:29:21 +04:00
|
|
|
return ProbePseudoElementStyle(aParentElement, aType, aParentContext,
|
|
|
|
treeContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ProbePseudoElementStyle(Element* aParentElement,
|
|
|
|
nsCSSPseudoElements::Type aType,
|
|
|
|
nsStyleContext* aParentContext,
|
2013-07-10 02:25:27 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext,
|
|
|
|
Element* aPseudoElement)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
|
|
|
|
"must have pseudo element type");
|
2010-04-30 17:12:06 +04:00
|
|
|
NS_ASSERTION(aParentElement, "aParentElement must not be null");
|
2009-12-11 05:28:08 +03:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2011-03-29 21:29:21 +04:00
|
|
|
aTreeMatchContext.ResetForUnvisitedMatching();
|
2010-04-30 17:12:06 +04:00
|
|
|
PseudoElementRuleProcessorData data(PresContext(), aParentElement,
|
2013-07-10 02:25:27 +04:00
|
|
|
&ruleWalker, aType, aTreeMatchContext,
|
|
|
|
aPseudoElement);
|
2009-12-11 10:37:40 +03:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
|
|
|
// not the root if there was a restriction rule
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *adjustedRoot = ruleWalker.CurrentNode();
|
2009-12-11 10:37:40 +03:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2009-12-11 05:28:08 +03:00
|
|
|
|
2009-12-12 09:36:34 +03:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2009-12-11 10:37:40 +03:00
|
|
|
if (ruleNode == adjustedRoot) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2003-02-23 20:28:25 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
if (aTreeMatchContext.HaveRelevantLink()) {
|
|
|
|
aTreeMatchContext.ResetForVisitedMatching();
|
2011-03-29 21:29:21 +04:00
|
|
|
ruleWalker.Reset();
|
2011-05-24 00:45:42 +04:00
|
|
|
WalkRestrictionRule(aType, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<PseudoElementRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
2013-05-03 01:04:47 +04:00
|
|
|
uint32_t flags = eNoFlags;
|
2013-02-01 20:02:29 +04:00
|
|
|
if (aType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
aType == nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
flags |= eDoAnimation;
|
2013-05-03 01:04:47 +04:00
|
|
|
} else {
|
2014-05-03 17:42:33 +04:00
|
|
|
// Flex and grid containers don't expect to have any pseudo-element children
|
|
|
|
// aside from ::before and ::after. So if we have such a child, we're not
|
|
|
|
// actually in a flex/grid container, and we should skip flex/grid item
|
|
|
|
// style fixup.
|
2014-06-16 17:55:00 +04:00
|
|
|
flags |= eSkipParentDisplayBasedStyleFixup;
|
2013-02-01 20:02:29 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
nsRefPtr<nsStyleContext> result =
|
2010-04-03 05:58:27 +04:00
|
|
|
GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2011-04-12 10:18:44 +04:00
|
|
|
pseudoTag, aType,
|
2013-02-01 20:02:29 +04:00
|
|
|
aParentElement, flags);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2003-02-23 20:28:25 +03:00
|
|
|
// For :before and :after pseudo-elements, having display: none or no
|
|
|
|
// 'content' property is equivalent to not having the pseudo-element
|
|
|
|
// at all.
|
|
|
|
if (result &&
|
2009-12-11 10:37:40 +03:00
|
|
|
(pseudoTag == nsCSSPseudoElements::before ||
|
|
|
|
pseudoTag == nsCSSPseudoElements::after)) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay *display = result->StyleDisplay();
|
|
|
|
const nsStyleContent *content = result->StyleContent();
|
2003-02-23 20:28:25 +03:00
|
|
|
// XXXldb What is contentCount for |content: ""|?
|
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_NONE ||
|
|
|
|
content->ContentCount() == 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
result = nullptr;
|
2003-02-23 20:28:25 +03:00
|
|
|
}
|
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
return result.forget();
|
2009-12-11 01:36:06 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
nsStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
2015-05-28 01:18:36 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
uint32_t aFlags)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAnonBox = nsCSSAnonBoxes::IsAnonBox(aPseudoTag)
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
&& !nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag)
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
NS_PRECONDITION(isAnonBox, "Unexpected pseudo");
|
|
|
|
#endif
|
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2010-04-02 10:07:42 +04:00
|
|
|
AnonBoxRuleProcessorData data(PresContext(), aPseudoTag, &ruleWalker);
|
2012-07-30 18:20:58 +04:00
|
|
|
FileRules(EnumRulesMatching<AnonBoxRuleProcessorData>, &data, nullptr,
|
2009-12-11 10:37:40 +03:00
|
|
|
&ruleWalker);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2012-09-01 01:21:28 +04:00
|
|
|
if (aPseudoTag == nsCSSAnonBoxes::pageContent) {
|
|
|
|
// Add any @page rules that are specified.
|
|
|
|
nsTArray<nsCSSPageRule*> rules;
|
|
|
|
nsTArray<css::ImportantRule*> importantRules;
|
2015-04-17 04:09:59 +03:00
|
|
|
PresContext()->StyleSet()->AppendPageRules(rules);
|
2012-09-01 01:21:28 +04:00
|
|
|
for (uint32_t i = 0, i_end = rules.Length(); i != i_end; ++i) {
|
|
|
|
ruleWalker.Forward(rules[i]);
|
|
|
|
css::ImportantRule* importantRule = rules[i]->GetImportantRule();
|
|
|
|
if (importantRule) {
|
|
|
|
importantRules.AppendElement(importantRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0, i_end = importantRules.Length(); i != i_end; ++i) {
|
|
|
|
ruleWalker.Forward(importantRules[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetContext(aParentContext, ruleWalker.CurrentNode(), nullptr,
|
2011-04-12 10:18:44 +04:00
|
|
|
aPseudoTag, nsCSSPseudoElements::ePseudo_AnonBox,
|
2015-05-28 01:18:36 +03:00
|
|
|
nullptr, aFlags);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-30 17:12:06 +04:00
|
|
|
nsStyleSet::ResolveXULTreePseudoStyle(Element* aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsICSSPseudoComparator* aComparator)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(aPseudoTag, "must have pseudo tag");
|
|
|
|
NS_ASSERTION(nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag),
|
|
|
|
"Unexpected pseudo");
|
|
|
|
|
2013-03-28 06:47:25 +04:00
|
|
|
nsRuleWalker ruleWalker(mRuleTree, mAuthorStyleDisabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(true, nsRuleWalker::eRelevantLinkUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aParentElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aParentElement);
|
2010-04-30 17:12:06 +04:00
|
|
|
XULTreeRuleProcessorData data(PresContext(), aParentElement, &ruleWalker,
|
2011-03-29 21:29:21 +04:00
|
|
|
aPseudoTag, aComparator, treeContext);
|
2010-04-30 17:12:06 +04:00
|
|
|
FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data, aParentElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
&ruleWalker);
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
nsRuleNode *ruleNode = ruleWalker.CurrentNode();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode *visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
|
2011-03-29 21:29:21 +04:00
|
|
|
if (treeContext.HaveRelevantLink()) {
|
|
|
|
treeContext.ResetForVisitedMatching();
|
|
|
|
ruleWalker.Reset();
|
2010-04-03 05:58:27 +04:00
|
|
|
FileRules(EnumRulesMatching<XULTreeRuleProcessorData>, &data,
|
2010-04-30 17:12:06 +04:00
|
|
|
aParentElement, &ruleWalker);
|
2010-04-03 05:58:27 +04:00
|
|
|
visitedRuleNode = ruleWalker.CurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetContext(aParentContext, ruleNode, visitedRuleNode,
|
2010-04-03 05:58:27 +04:00
|
|
|
// For pseudos, |data.IsLink()| being true means that
|
|
|
|
// our parent node is a link.
|
2011-04-12 10:18:44 +04:00
|
|
|
aPseudoTag, nsCSSPseudoElements::ePseudo_XULTree,
|
2013-02-01 20:02:29 +04:00
|
|
|
nullptr, eNoFlags);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
|
2008-11-26 02:22:38 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, false);
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
2008-11-26 02:22:38 +03:00
|
|
|
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
|
2013-01-09 03:25:47 +04:00
|
|
|
if (gCSSSheetTypes[i] == eScopedDocSheet)
|
|
|
|
continue;
|
2008-11-26 02:22:38 +03:00
|
|
|
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
2015-04-17 04:09:59 +03:00
|
|
|
if (ruleProc && !ruleProc->AppendFontFaceRules(presContext, aArray))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-26 02:22:38 +03:00
|
|
|
}
|
|
|
|
|
2013-08-15 08:58:37 +04:00
|
|
|
nsCSSKeyframesRule*
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::KeyframesRuleForName(const nsString& aName)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2013-08-15 08:58:37 +04:00
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2013-08-15 08:58:37 +04:00
|
|
|
for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
|
2013-01-09 03:25:47 +04:00
|
|
|
if (gCSSSheetTypes[i] == eScopedDocSheet)
|
|
|
|
continue;
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
2013-08-15 08:58:37 +04:00
|
|
|
if (!ruleProc)
|
|
|
|
continue;
|
|
|
|
nsCSSKeyframesRule* result =
|
2015-04-17 04:09:59 +03:00
|
|
|
ruleProc->KeyframesRuleForName(presContext, aName);
|
2013-08-15 08:58:37 +04:00
|
|
|
if (result)
|
|
|
|
return result;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
2013-08-15 08:58:37 +04:00
|
|
|
return nullptr;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 05:10:00 +04:00
|
|
|
nsCSSCounterStyleRule*
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::CounterStyleRuleForName(const nsAString& aName)
|
2014-06-12 05:10:00 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, nullptr);
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
2014-06-12 05:10:00 +04:00
|
|
|
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2014-06-12 05:10:00 +04:00
|
|
|
for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
|
|
|
|
if (gCSSSheetTypes[i] == eScopedDocSheet)
|
|
|
|
continue;
|
|
|
|
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
|
|
|
if (!ruleProc)
|
|
|
|
continue;
|
|
|
|
nsCSSCounterStyleRule *result =
|
2015-04-17 04:09:59 +03:00
|
|
|
ruleProc->CounterStyleRuleForName(presContext, aName);
|
2014-06-12 05:10:00 +04:00
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
bool
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::AppendFontFeatureValuesRules(
|
2013-05-20 06:59:20 +04:00
|
|
|
nsTArray<nsCSSFontFeatureValuesRule*>& aArray)
|
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, false);
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
2013-05-20 06:59:20 +04:00
|
|
|
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2014-01-30 22:26:54 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
|
2013-05-20 06:59:20 +04:00
|
|
|
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
|
|
|
if (ruleProc &&
|
2015-04-17 04:09:59 +03:00
|
|
|
!ruleProc->AppendFontFeatureValuesRules(presContext, aArray))
|
2013-05-20 06:59:20 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxFontFeatureValueSet>
|
|
|
|
nsStyleSet::GetFontFeatureValuesLookup()
|
|
|
|
{
|
|
|
|
if (mInitFontFeatureValuesLookup) {
|
|
|
|
mInitFontFeatureValuesLookup = false;
|
|
|
|
|
|
|
|
nsTArray<nsCSSFontFeatureValuesRule*> rules;
|
2015-04-17 04:09:59 +03:00
|
|
|
AppendFontFeatureValuesRules(rules);
|
2013-05-20 06:59:20 +04:00
|
|
|
|
|
|
|
mFontFeatureValuesLookup = new gfxFontFeatureValueSet();
|
|
|
|
|
|
|
|
uint32_t i, numRules = rules.Length();
|
|
|
|
for (i = 0; i < numRules; i++) {
|
|
|
|
nsCSSFontFeatureValuesRule *rule = rules[i];
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
const nsTArray<FontFamilyName>& familyList = rule->GetFamilyList().GetFontlist();
|
2013-05-20 06:59:20 +04:00
|
|
|
const nsTArray<gfxFontFeatureValueSet::FeatureValues>&
|
|
|
|
featureValues = rule->GetFeatureValues();
|
|
|
|
|
|
|
|
// for each family
|
2014-06-06 10:09:23 +04:00
|
|
|
size_t f, numFam;
|
2013-05-20 06:59:20 +04:00
|
|
|
|
|
|
|
numFam = familyList.Length();
|
|
|
|
for (f = 0; f < numFam; f++) {
|
2014-06-06 10:09:23 +04:00
|
|
|
mFontFeatureValuesLookup->AddFontFeatureValues(familyList[f].mName,
|
|
|
|
featureValues);
|
2013-05-20 06:59:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxFontFeatureValueSet> lookup = mFontFeatureValuesLookup;
|
|
|
|
return lookup.forget();
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:21:28 +04:00
|
|
|
bool
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::AppendPageRules(nsTArray<nsCSSPageRule*>& aArray)
|
2012-09-01 01:21:28 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_FALSE(mInShutdown, false);
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
2012-09-01 01:21:28 +04:00
|
|
|
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2014-01-30 22:26:54 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
|
2013-01-09 03:25:47 +04:00
|
|
|
if (gCSSSheetTypes[i] == eScopedDocSheet)
|
|
|
|
continue;
|
2012-09-01 01:21:28 +04:00
|
|
|
nsCSSRuleProcessor* ruleProc = static_cast<nsCSSRuleProcessor*>
|
|
|
|
(mRuleProcessors[gCSSSheetTypes[i]].get());
|
2015-04-17 04:09:59 +03:00
|
|
|
if (ruleProc && !ruleProc->AppendPageRules(presContext, aArray))
|
2012-09-01 01:21:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::BeginShutdown()
|
2003-03-06 22:14:17 +03:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
mInShutdown = 1;
|
2003-03-06 22:14:17 +03:00
|
|
|
mRoots.Clear(); // no longer valid, since we won't keep it up to date
|
|
|
|
}
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::Shutdown()
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2004-01-08 01:30:53 +03:00
|
|
|
mRuleTree->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
mRuleTree = nullptr;
|
2003-03-13 18:29:36 +03:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
// We can have old rule trees either because:
|
|
|
|
// (1) we failed the assertions in EndReconstruct, or
|
|
|
|
// (2) we're shutting down within a reconstruct (see bug 462392)
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = mOldRuleTrees.Length(); i > 0; ) {
|
2009-01-30 07:39:23 +03:00
|
|
|
--i;
|
|
|
|
mOldRuleTrees[i]->Destroy();
|
|
|
|
}
|
|
|
|
mOldRuleTrees.Clear();
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint32_t kGCInterval = 300;
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
void
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::NotifyStyleContextDestroyed(nsStyleContext* aStyleContext)
|
2003-03-06 22:14:17 +03:00
|
|
|
{
|
|
|
|
if (mInShutdown)
|
2004-01-08 01:30:53 +03:00
|
|
|
return;
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2007-11-15 09:13:48 +03:00
|
|
|
// Remove style contexts from mRoots even if mOldRuleTree is non-null. This
|
|
|
|
// could be a style context from the new ruletree!
|
2003-03-06 22:14:17 +03:00
|
|
|
if (!aStyleContext->GetParent()) {
|
|
|
|
mRoots.RemoveElement(aStyleContext);
|
|
|
|
}
|
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
if (mInReconstruct)
|
2007-11-15 09:13:48 +03:00
|
|
|
return;
|
|
|
|
|
2011-01-19 05:20:35 +03:00
|
|
|
if (mUnusedRuleNodeCount >= kGCInterval) {
|
2009-01-30 07:39:23 +03:00
|
|
|
GCRuleTrees();
|
|
|
|
}
|
|
|
|
}
|
2009-01-29 23:39:19 +03:00
|
|
|
|
2009-01-30 07:39:23 +03:00
|
|
|
void
|
|
|
|
nsStyleSet::GCRuleTrees()
|
|
|
|
{
|
2009-09-24 21:59:43 +04:00
|
|
|
mUnusedRuleNodeCount = 0;
|
2009-01-30 07:39:23 +03:00
|
|
|
|
|
|
|
// Mark the style context tree by marking all style contexts which
|
|
|
|
// have no parent, which will mark all descendants. This will reach
|
|
|
|
// style contexts in the undisplayed map and "additional style
|
|
|
|
// contexts" since they are descendants of the roots.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = mRoots.Length() - 1; i >= 0; --i) {
|
2009-01-30 07:39:23 +03:00
|
|
|
mRoots[i]->Mark();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sweep the rule tree.
|
2004-01-08 01:30:53 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool deleted =
|
2004-01-08 01:30:53 +03:00
|
|
|
#endif
|
2009-01-30 07:39:23 +03:00
|
|
|
mRuleTree->Sweep();
|
|
|
|
NS_ASSERTION(!deleted, "Root node must not be gc'd");
|
|
|
|
|
|
|
|
// Sweep the old rule trees.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = mOldRuleTrees.Length(); i > 0; ) {
|
2009-01-30 07:39:23 +03:00
|
|
|
--i;
|
|
|
|
if (mOldRuleTrees[i]->Sweep()) {
|
|
|
|
// It was deleted, as it should be.
|
|
|
|
mOldRuleTrees.RemoveElementAt(i);
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("old rule tree still referenced");
|
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
}
|
2003-03-06 22:14:17 +03:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2010-04-02 10:07:42 +04:00
|
|
|
nsStyleSet::ReparentStyleContext(nsStyleContext* aStyleContext,
|
2010-06-23 08:46:27 +04:00
|
|
|
nsStyleContext* aNewParentContext,
|
2015-02-17 01:15:05 +03:00
|
|
|
Element* aElement)
|
1999-09-04 03:35:41 +04:00
|
|
|
{
|
2013-08-03 08:11:05 +04:00
|
|
|
MOZ_ASSERT(aStyleContext, "aStyleContext must not be null");
|
1999-09-04 03:35:41 +04:00
|
|
|
|
2010-06-23 08:46:27 +04:00
|
|
|
// This short-circuit is OK because we don't call TryStartingTransition
|
|
|
|
// during style reresolution if the style context pointer hasn't changed.
|
2010-04-02 10:07:42 +04:00
|
|
|
if (aStyleContext->GetParent() == aNewParentContext) {
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<nsStyleContext> ret = aStyleContext;
|
|
|
|
return ret.forget();
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
|
|
|
nsIAtom* pseudoTag = aStyleContext->GetPseudo();
|
|
|
|
nsCSSPseudoElements::Type pseudoType = aStyleContext->GetPseudoType();
|
2013-02-17 01:04:53 +04:00
|
|
|
nsRuleNode* ruleNode = aStyleContext->RuleNode();
|
2010-06-23 08:46:27 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
NS_ASSERTION(!PresContext()->RestyleManager()->SkipAnimationRules(),
|
|
|
|
"we no longer handle SkipAnimationRules()");
|
2010-06-23 08:46:27 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRuleNode* visitedRuleNode = nullptr;
|
2010-04-03 05:58:27 +04:00
|
|
|
nsStyleContext* visitedContext = aStyleContext->GetStyleIfVisited();
|
2010-06-08 23:58:26 +04:00
|
|
|
// Reparenting a style context just changes where we inherit from,
|
|
|
|
// not what rules we match or what our DOM looks like. In
|
|
|
|
// particular, it doesn't change whether this is a style context for
|
|
|
|
// a link.
|
2010-04-03 05:58:27 +04:00
|
|
|
if (visitedContext) {
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
visitedRuleNode = visitedContext->RuleNode();
|
2010-04-03 05:58:27 +04:00
|
|
|
}
|
2010-04-02 10:07:42 +04:00
|
|
|
|
2013-02-01 20:02:29 +04:00
|
|
|
uint32_t flags = eNoFlags;
|
|
|
|
if (aStyleContext->IsLinkContext()) {
|
|
|
|
flags |= eIsLink;
|
2011-05-21 00:21:27 +04:00
|
|
|
|
2014-08-03 06:37:42 +04:00
|
|
|
// GetContext handles propagating RelevantLinkVisited state from the
|
|
|
|
// parent in non-link cases; all we need to pass in is if this link
|
|
|
|
// is visited.
|
|
|
|
if (aStyleContext->RelevantLinkVisited()) {
|
|
|
|
flags |= eIsVisitedLink;
|
|
|
|
}
|
2013-02-01 20:02:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
pseudoType == nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
flags |= eDoAnimation;
|
|
|
|
}
|
|
|
|
|
2013-04-16 19:33:41 +04:00
|
|
|
if (aElement && aElement->IsRootOfAnonymousSubtree()) {
|
2014-05-03 17:42:33 +04:00
|
|
|
// For anonymous subtree roots, don't tweak "display" value based on whether
|
|
|
|
// or not the parent is styled as a flex/grid container. (If the parent
|
2013-04-16 19:33:41 +04:00
|
|
|
// has anonymous-subtree kids, then we know it's not actually going to get
|
2014-05-03 17:42:33 +04:00
|
|
|
// a flex/grid container frame, anyway.)
|
2014-06-16 17:55:00 +04:00
|
|
|
flags |= eSkipParentDisplayBasedStyleFixup;
|
2013-04-16 19:33:41 +04:00
|
|
|
}
|
|
|
|
|
2010-04-03 05:58:27 +04:00
|
|
|
return GetContext(aNewParentContext, ruleNode, visitedRuleNode,
|
2011-04-12 10:18:44 +04:00
|
|
|
pseudoTag, pseudoType,
|
2013-02-01 20:02:29 +04:00
|
|
|
aElement, flags);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:20:45 +04:00
|
|
|
struct MOZ_STACK_CLASS StatefulData : public StateRuleProcessorData {
|
2011-03-29 21:29:21 +04:00
|
|
|
StatefulData(nsPresContext* aPresContext, Element* aElement,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aStateMask, TreeMatchContext& aTreeMatchContext)
|
2011-03-29 21:29:21 +04:00
|
|
|
: StateRuleProcessorData(aPresContext, aElement, aStateMask,
|
|
|
|
aTreeMatchContext),
|
2010-04-01 04:43:32 +04:00
|
|
|
mHint(nsRestyleHint(0))
|
1999-04-20 04:02:22 +04:00
|
|
|
{}
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint mHint;
|
2010-03-17 20:10:57 +03:00
|
|
|
};
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
struct MOZ_STACK_CLASS StatefulPseudoElementData : public PseudoElementStateRuleProcessorData {
|
|
|
|
StatefulPseudoElementData(nsPresContext* aPresContext, Element* aElement,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aStateMask, nsCSSPseudoElements::Type aPseudoType,
|
2013-11-28 10:46:39 +04:00
|
|
|
TreeMatchContext& aTreeMatchContext, Element* aPseudoElement)
|
|
|
|
: PseudoElementStateRuleProcessorData(aPresContext, aElement, aStateMask,
|
|
|
|
aPseudoType, aTreeMatchContext,
|
|
|
|
aPseudoElement),
|
|
|
|
mHint(nsRestyleHint(0))
|
|
|
|
{}
|
|
|
|
nsRestyleHint mHint;
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool SheetHasDocumentStateStyle(nsIStyleRuleProcessor* aProcessor,
|
2010-03-17 20:10:57 +03:00
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
StatefulData* data = (StatefulData*)aData;
|
|
|
|
if (aProcessor->HasDocumentStateDependentStyle(data)) {
|
2010-04-01 04:43:32 +04:00
|
|
|
data->mHint = eRestyle_Self;
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // don't continue
|
2010-03-17 20:10:57 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // continue
|
2010-03-17 20:10:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on a document state.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::HasDocumentStateDependentStyle(nsIContent* aContent,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aStateMask)
|
2010-03-17 20:10:57 +03:00
|
|
|
{
|
2010-04-30 17:12:06 +04:00
|
|
|
if (!aContent || !aContent->IsElement())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-17 20:10:57 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aContent->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aContent->AsElement());
|
2015-04-17 04:09:59 +03:00
|
|
|
StatefulData data(PresContext(), aContent->AsElement(), aStateMask,
|
2011-03-29 21:29:21 +04:00
|
|
|
treeContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
WalkRuleProcessors(SheetHasDocumentStateStyle, &data, true);
|
2010-03-17 20:10:57 +03:00
|
|
|
return data.mHint != 0;
|
|
|
|
}
|
1999-04-20 04:02:22 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool SheetHasStatefulStyle(nsIStyleRuleProcessor* aProcessor,
|
2004-01-08 01:30:53 +03:00
|
|
|
void *aData)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
|
|
|
StatefulData* data = (StatefulData*)aData;
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint hint = aProcessor->HasStateDependentStyle(data);
|
|
|
|
data->mHint = nsRestyleHint(data->mHint | hint);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // continue
|
1999-04-20 04:02:22 +04:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
static bool SheetHasStatefulPseudoElementStyle(nsIStyleRuleProcessor* aProcessor,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
StatefulPseudoElementData* data = (StatefulPseudoElementData*)aData;
|
|
|
|
nsRestyleHint hint = aProcessor->HasStateDependentStyle(data);
|
|
|
|
data->mHint = nsRestyleHint(data->mHint | hint);
|
|
|
|
return true; // continue
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:02:22 +04:00
|
|
|
// Test if style is dependent on content state
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::HasStateDependentStyle(Element* aElement,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aStateMask)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aElement);
|
2015-04-17 04:09:59 +03:00
|
|
|
StatefulData data(PresContext(), aElement, aStateMask, treeContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
WalkRuleProcessors(SheetHasStatefulStyle, &data, false);
|
2010-05-14 21:04:51 +04:00
|
|
|
return data.mHint;
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
nsRestyleHint
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::HasStateDependentStyle(Element* aElement,
|
2013-11-28 10:46:39 +04:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
Element* aPseudoElement,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aStateMask)
|
2013-11-28 10:46:39 +04:00
|
|
|
{
|
|
|
|
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
|
|
|
|
aElement->OwnerDoc());
|
|
|
|
InitStyleScopes(treeContext, aElement);
|
2015-04-17 04:09:59 +03:00
|
|
|
StatefulPseudoElementData data(PresContext(), aElement, aStateMask,
|
2013-11-28 10:46:39 +04:00
|
|
|
aPseudoType, treeContext, aPseudoElement);
|
|
|
|
WalkRuleProcessors(SheetHasStatefulPseudoElementStyle, &data, false);
|
|
|
|
return data.mHint;
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:20:45 +04:00
|
|
|
struct MOZ_STACK_CLASS AttributeData : public AttributeRuleProcessorData {
|
2004-08-01 03:15:21 +04:00
|
|
|
AttributeData(nsPresContext* aPresContext,
|
2012-08-22 19:56:38 +04:00
|
|
|
Element* aElement, nsIAtom* aAttribute, int32_t aModType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAttrHasChanged, TreeMatchContext& aTreeMatchContext)
|
2010-04-30 17:12:06 +04:00
|
|
|
: AttributeRuleProcessorData(aPresContext, aElement, aAttribute, aModType,
|
2011-03-29 21:29:21 +04:00
|
|
|
aAttrHasChanged, aTreeMatchContext),
|
2010-04-01 04:43:32 +04:00
|
|
|
mHint(nsRestyleHint(0))
|
2003-02-22 19:10:53 +03:00
|
|
|
{}
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint mHint;
|
2013-05-20 06:59:20 +04:00
|
|
|
};
|
2003-02-22 19:10:53 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2004-01-08 01:30:53 +03:00
|
|
|
SheetHasAttributeStyle(nsIStyleRuleProcessor* aProcessor, void *aData)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
|
|
|
AttributeData* data = (AttributeData*)aData;
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint hint = aProcessor->HasAttributeDependentStyle(data);
|
|
|
|
data->mHint = nsRestyleHint(data->mHint | hint);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // continue
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2010-04-01 04:43:32 +04:00
|
|
|
nsRestyleHint
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::HasAttributeDependentStyle(Element* aElement,
|
2007-07-13 00:05:45 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAttrHasChanged)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
|
2011-10-18 14:53:36 +04:00
|
|
|
aElement->OwnerDoc());
|
2013-11-01 06:44:40 +04:00
|
|
|
InitStyleScopes(treeContext, aElement);
|
2015-04-17 04:09:59 +03:00
|
|
|
AttributeData data(PresContext(), aElement, aAttribute,
|
2011-03-29 21:29:21 +04:00
|
|
|
aModType, aAttrHasChanged, treeContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
WalkRuleProcessors(SheetHasAttributeStyle, &data, false);
|
2010-05-14 21:04:51 +04:00
|
|
|
return data.mHint;
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-04-17 04:09:59 +03:00
|
|
|
nsStyleSet::MediumFeaturesChanged()
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
2014-12-06 02:50:00 +03:00
|
|
|
NS_ASSERTION(mBatching == 0, "rule processors out of date");
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
// We can't use WalkRuleProcessors without a content node.
|
2015-04-17 04:09:59 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool stylesChanged = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(mRuleProcessors); ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
nsIStyleRuleProcessor *processor = mRuleProcessors[i];
|
|
|
|
if (!processor) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-17 04:09:59 +03:00
|
|
|
bool thisChanged = processor->MediumFeaturesChanged(presContext);
|
2008-07-26 20:14:48 +04:00
|
|
|
stylesChanged = stylesChanged || thisChanged;
|
|
|
|
}
|
2013-02-12 04:48:44 +04:00
|
|
|
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); ++i) {
|
|
|
|
nsIStyleRuleProcessor *processor = mScopedDocSheetRuleProcessors[i];
|
2015-04-17 04:09:59 +03:00
|
|
|
bool thisChanged = processor->MediumFeaturesChanged(presContext);
|
2013-02-12 04:48:44 +04:00
|
|
|
stylesChanged = stylesChanged || thisChanged;
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2008-07-26 20:14:49 +04:00
|
|
|
if (mBindingManager) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool thisChanged = false;
|
2015-04-17 04:09:59 +03:00
|
|
|
mBindingManager->MediumFeaturesChanged(presContext, &thisChanged);
|
2008-07-26 20:14:49 +04:00
|
|
|
stylesChanged = stylesChanged || thisChanged;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
return stylesChanged;
|
|
|
|
}
|
2009-12-31 18:56:33 +03:00
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
bool
|
2009-12-31 18:56:33 +03:00
|
|
|
nsStyleSet::EnsureUniqueInnerOnCSSSheets()
|
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
nsAutoTArray<CSSStyleSheet*, 32> queue;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
|
2009-12-31 18:56:33 +03:00
|
|
|
nsCOMArray<nsIStyleSheet> &sheets = mSheets[gCSSSheetTypes[i]];
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = 0, j_end = sheets.Count(); j < j_end; ++j) {
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* sheet = static_cast<CSSStyleSheet*>(sheets[j]);
|
2013-11-11 12:00:18 +04:00
|
|
|
queue.AppendElement(sheet);
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-17 09:36:34 +04:00
|
|
|
if (mBindingManager) {
|
|
|
|
mBindingManager->AppendAllSheets(queue);
|
|
|
|
}
|
|
|
|
|
2009-12-31 18:56:33 +03:00
|
|
|
while (!queue.IsEmpty()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t idx = queue.Length() - 1;
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* sheet = queue[idx];
|
2009-12-31 18:56:33 +03:00
|
|
|
queue.RemoveElementAt(idx);
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
sheet->EnsureUniqueInner();
|
2009-12-31 18:56:33 +03:00
|
|
|
|
|
|
|
// Enqueue all the sheet's children.
|
2013-11-11 11:59:58 +04:00
|
|
|
sheet->AppendAllChildSheets(queue);
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
2015-06-26 06:49:58 +03:00
|
|
|
|
|
|
|
bool res = mNeedsRestyleAfterEnsureUniqueInner;
|
|
|
|
mNeedsRestyleAfterEnsureUniqueInner = false;
|
2009-12-31 18:56:33 +03:00
|
|
|
return res;
|
|
|
|
}
|
2011-08-23 03:34:12 +04:00
|
|
|
|
|
|
|
nsIStyleRule*
|
|
|
|
nsStyleSet::InitialStyleRule()
|
|
|
|
{
|
|
|
|
if (!mInitialStyleRule) {
|
|
|
|
mInitialStyleRule = new nsInitialStyleRule;
|
|
|
|
}
|
|
|
|
return mInitialStyleRule;
|
|
|
|
}
|