2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-07-20 06:11:27 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/*
|
|
|
|
* temporary (expanded) representation of property-value pairs used to
|
2010-07-23 18:00:21 +00:00
|
|
|
* hold data from matched rules during style data computation.
|
2006-03-25 05:47:31 +00:00
|
|
|
*/
|
|
|
|
|
2004-07-20 06:11:27 +00:00
|
|
|
#ifndef nsRuleData_h_
|
|
|
|
#define nsRuleData_h_
|
|
|
|
|
2013-12-12 02:09:41 +00:00
|
|
|
#include "mozilla/CSSVariableDeclarations.h"
|
2017-01-26 21:39:13 +00:00
|
|
|
#include "mozilla/GenericSpecifiedValues.h"
|
2015-06-23 01:48:18 +00:00
|
|
|
#include "mozilla/RuleNodeCacheConditions.h"
|
2015-10-19 23:16:20 +00:00
|
|
|
#include "mozilla/SheetType.h"
|
2016-06-07 20:10:18 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2010-07-23 18:00:21 +00:00
|
|
|
#include "nsCSSProps.h"
|
2013-09-16 01:06:52 +00:00
|
|
|
#include "nsCSSValue.h"
|
2007-04-28 16:01:24 +00:00
|
|
|
#include "nsStyleStructFwd.h"
|
2010-07-23 18:00:21 +00:00
|
|
|
|
2007-04-28 16:01:24 +00:00
|
|
|
class nsPresContext;
|
|
|
|
struct nsRuleData;
|
2010-07-23 18:00:21 +00:00
|
|
|
|
2017-07-26 16:21:35 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class GeckoStyleContext;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-10-08 05:10:58 +00:00
|
|
|
typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
|
2004-07-20 06:11:27 +00:00
|
|
|
|
2017-06-16 01:57:29 +00:00
|
|
|
struct nsRuleData final : mozilla::GenericSpecifiedValues
|
2004-07-20 06:11:27 +00:00
|
|
|
{
|
2015-06-23 01:48:18 +00:00
|
|
|
mozilla::RuleNodeCacheConditions mConditions;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsImportantRule;
|
2015-10-19 23:16:20 +00:00
|
|
|
mozilla::SheetType mLevel;
|
2017-07-26 16:21:35 +00:00
|
|
|
mozilla::GeckoStyleContext* const mStyleContext;
|
2010-07-23 18:00:21 +00:00
|
|
|
|
2011-03-18 03:14:31 +00:00
|
|
|
// We store nsCSSValues needed to compute the data for one or more
|
|
|
|
// style structs (specified by the bitfield mSIDs). These are stored
|
|
|
|
// in a single array allocation (which our caller allocates; see
|
|
|
|
// AutoCSSValueArray) The offset of each property |prop| in
|
|
|
|
// mValueStorage is the sum of
|
|
|
|
// mValueOffsets[nsCSSProps::kSIDTable[prop]] and
|
|
|
|
// nsCSSProps::PropertyIndexInStruct(prop). The only place we gather
|
|
|
|
// more than one style struct's data at a time is
|
|
|
|
// nsRuleNode::HasAuthorSpecifiedRules; therefore some code that we
|
|
|
|
// know is not called from HasAuthorSpecifiedRules assumes that the
|
|
|
|
// mValueOffsets for the one struct in mSIDs is zero.
|
2011-03-18 03:14:31 +00:00
|
|
|
nsCSSValue* const mValueStorage; // our user owns this array
|
2011-03-18 03:14:31 +00:00
|
|
|
size_t mValueOffsets[nsStyleStructID_Length];
|
2004-07-20 06:11:27 +00:00
|
|
|
|
2013-12-12 02:09:41 +00:00
|
|
|
nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables;
|
|
|
|
|
2017-06-16 01:57:29 +00:00
|
|
|
nsRuleData(uint32_t aSIDs,
|
|
|
|
nsCSSValue* aValueStorage,
|
|
|
|
nsPresContext* aContext,
|
2017-07-26 16:21:35 +00:00
|
|
|
mozilla::GeckoStyleContext* aStyleContext);
|
2011-03-18 03:14:31 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
~nsRuleData();
|
|
|
|
#else
|
|
|
|
~nsRuleData() {}
|
|
|
|
#endif
|
2010-07-23 18:00:21 +00:00
|
|
|
|
|
|
|
/**
|
2010-08-19 19:33:44 +00:00
|
|
|
* Return a pointer to the value object within |this| corresponding
|
2011-03-18 03:14:30 +00:00
|
|
|
* to property |aProperty|.
|
|
|
|
*
|
|
|
|
* This function must only be called if the given property is in
|
|
|
|
* mSIDs.
|
2010-07-23 18:00:21 +00:00
|
|
|
*/
|
2016-08-17 01:37:48 +00:00
|
|
|
nsCSSValue* ValueFor(nsCSSPropertyID aProperty)
|
2011-03-18 03:14:31 +00:00
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"invalid or shorthand property");
|
2011-03-18 03:14:31 +00:00
|
|
|
|
|
|
|
nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty];
|
|
|
|
size_t indexInStruct = nsCSSProps::PropertyIndexInStruct(aProperty);
|
|
|
|
|
|
|
|
// This should really be nsCachedStyleData::GetBitForSID, but we can't
|
|
|
|
// include that here since it includes us.
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mSIDs & (1 << sid),
|
|
|
|
"calling nsRuleData::ValueFor on property not in mSIDs");
|
2017-06-16 01:57:29 +00:00
|
|
|
MOZ_ASSERT(indexInStruct != size_t(-1), "logical property");
|
2011-03-18 03:14:31 +00:00
|
|
|
|
|
|
|
return mValueStorage + mValueOffsets[sid] + indexInStruct;
|
|
|
|
}
|
2011-03-18 03:14:30 +00:00
|
|
|
|
2017-06-16 01:57:29 +00:00
|
|
|
const nsCSSValue* ValueFor(nsCSSPropertyID aProperty) const
|
|
|
|
{
|
2011-03-18 03:14:31 +00:00
|
|
|
return const_cast<nsRuleData*>(this)->ValueFor(aProperty);
|
|
|
|
}
|
|
|
|
|
2011-03-18 03:14:30 +00:00
|
|
|
/**
|
|
|
|
* Getters like ValueFor(aProperty), but for each property by name
|
|
|
|
* (ValueForBackgroundColor, etc.), and more efficient than ValueFor.
|
|
|
|
* These use the names used for the property on DOM interfaces (the
|
|
|
|
* 'method' field in nsCSSPropList.h).
|
|
|
|
*
|
|
|
|
* Like ValueFor(), the caller must check that the property is within
|
|
|
|
* mSIDs.
|
|
|
|
*/
|
2013-03-25 16:24:21 +00:00
|
|
|
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_
|
2012-05-10 01:29:37 +00:00
|
|
|
#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
|
|
|
|
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
|
2011-03-18 03:14:30 +00:00
|
|
|
nsCSSValue* ValueFor##method_() { \
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mSIDs & NS_STYLE_INHERIT_BIT(stylestruct_), \
|
|
|
|
"Calling nsRuleData::ValueFor" #method_ " without " \
|
|
|
|
"NS_STYLE_INHERIT_BIT(" #stylestruct_ " in mSIDs."); \
|
2011-03-18 03:14:31 +00:00
|
|
|
nsStyleStructID sid = eStyleStruct_##stylestruct_; \
|
|
|
|
size_t indexInStruct = \
|
|
|
|
nsCSSProps::PropertyIndexInStruct(eCSSProperty_##id_); \
|
2015-10-20 05:22:34 +00:00
|
|
|
MOZ_ASSERT(indexInStruct != size_t(-1), \
|
|
|
|
"logical property"); \
|
2011-03-18 03:14:31 +00:00
|
|
|
return mValueStorage + mValueOffsets[sid] + indexInStruct; \
|
2011-03-18 03:14:30 +00:00
|
|
|
} \
|
|
|
|
const nsCSSValue* ValueFor##method_() const { \
|
2011-03-18 03:14:31 +00:00
|
|
|
return const_cast<nsRuleData*>(this)->ValueFor##method_(); \
|
2011-03-18 03:14:30 +00:00
|
|
|
}
|
2015-01-17 04:16:01 +00:00
|
|
|
#define CSS_PROP_LIST_EXCLUDE_LOGICAL
|
2011-03-18 03:14:30 +00:00
|
|
|
#include "nsCSSPropList.h"
|
2015-01-17 04:16:01 +00:00
|
|
|
#undef CSS_PROP_LIST_EXCLUDE_LOGICAL
|
2011-03-18 03:14:30 +00:00
|
|
|
#undef CSS_PROP
|
2013-03-25 16:24:21 +00:00
|
|
|
#undef CSS_PROP_PUBLIC_OR_PRIVATE
|
2011-03-18 03:14:30 +00:00
|
|
|
|
2017-01-26 21:39:13 +00:00
|
|
|
// GenericSpecifiedValues overrides
|
2017-06-16 01:57:29 +00:00
|
|
|
bool PropertyIsSet(nsCSSPropertyID aId)
|
|
|
|
{
|
2017-01-26 21:39:13 +00:00
|
|
|
return ValueFor(aId)->GetUnit() != eCSSUnit_Null;
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetIdentStringValue(nsCSSPropertyID aId, const nsString& aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetStringValue(aValue, eCSSUnit_Ident);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
void SetIdentAtomValue(nsCSSPropertyID aId, nsAtom* aValue)
|
2017-06-15 19:48:26 +00:00
|
|
|
{
|
2017-10-02 22:05:19 +00:00
|
|
|
RefPtr<nsAtom> atom = aValue;
|
2017-06-15 19:48:26 +00:00
|
|
|
ValueFor(aId)->SetAtomIdentValue(atom.forget());
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetKeywordValue(nsCSSPropertyID aId, int32_t aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetIntValue(aValue, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetIntValue(nsCSSPropertyID aId, int32_t aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetIntValue(aValue, eCSSUnit_Integer);
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetPixelValue(nsCSSPropertyID aId, float aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetFloatValue(aValue, eCSSUnit_Pixel);
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue)
|
|
|
|
{
|
2017-04-10 07:28:48 +00:00
|
|
|
nsCSSValue* val = ValueFor(aId);
|
|
|
|
*val = aValue;
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetNumberValue(nsCSSPropertyID aId, float aValue)
|
|
|
|
{
|
2017-04-10 07:28:48 +00:00
|
|
|
ValueFor(aId)->SetFloatValue(aValue, eCSSUnit_Number);
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetPercentValue(nsCSSPropertyID aId, float aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetPercentValue(aValue);
|
|
|
|
}
|
|
|
|
|
2017-01-27 00:51:01 +00:00
|
|
|
void SetAutoValue(nsCSSPropertyID aId) {
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetAutoValue();
|
|
|
|
}
|
|
|
|
|
2017-06-16 01:57:29 +00:00
|
|
|
void SetCurrentColor(nsCSSPropertyID aId)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:42:15 +00:00
|
|
|
void SetColorValue(nsCSSPropertyID aId, nscolor aValue)
|
|
|
|
{
|
2017-01-27 00:51:01 +00:00
|
|
|
ValueFor(aId)->SetColorValue(aValue);
|
|
|
|
}
|
|
|
|
|
2017-01-27 00:51:01 +00:00
|
|
|
void SetFontFamily(const nsString& aValue);
|
|
|
|
void SetTextDecorationColorOverride();
|
2017-04-10 07:28:48 +00:00
|
|
|
void SetBackgroundImage(nsAttrValue& aValue);
|
2017-01-27 00:51:01 +00:00
|
|
|
|
2011-03-18 03:14:31 +00:00
|
|
|
private:
|
|
|
|
inline size_t GetPoisonOffset();
|
2004-07-20 06:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|