2010-07-23 22:00:21 +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/. */
|
2010-07-23 22:00:21 +04:00
|
|
|
|
|
|
|
#include "nsRuleData.h"
|
2011-03-18 06:14:31 +03:00
|
|
|
|
2017-05-30 04:10:25 +03:00
|
|
|
#include "nsAttrValueInlines.h"
|
2017-01-27 03:51:01 +03:00
|
|
|
#include "nsCSSParser.h"
|
2013-05-07 22:48:59 +04:00
|
|
|
#include "mozilla/Poison.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2012-04-12 04:17:44 +04:00
|
|
|
|
2017-02-14 22:23:06 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2011-03-18 06:14:31 +03:00
|
|
|
inline size_t
|
|
|
|
nsRuleData::GetPoisonOffset()
|
|
|
|
{
|
|
|
|
// Fill in mValueOffsets such that mValueStorage + mValueOffsets[i]
|
|
|
|
// will yield the frame poison value for all uninitialized value
|
|
|
|
// offsets.
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(sizeof(uintptr_t) == sizeof(size_t),
|
|
|
|
"expect uintptr_t and size_t to be the same size");
|
|
|
|
static_assert(uintptr_t(-1) > uintptr_t(0),
|
|
|
|
"expect uintptr_t to be unsigned");
|
2017-06-16 04:57:29 +03:00
|
|
|
static_assert(size_t(-1) > size_t(0), "expect size_t to be unsigned");
|
2013-05-07 22:48:59 +04:00
|
|
|
uintptr_t framePoisonValue = mozPoisonValue();
|
2012-04-12 04:17:44 +04:00
|
|
|
return size_t(framePoisonValue - uintptr_t(mValueStorage)) /
|
2011-03-18 06:14:31 +03:00
|
|
|
sizeof(nsCSSValue);
|
|
|
|
}
|
|
|
|
|
2017-06-16 04:57:29 +03:00
|
|
|
nsRuleData::nsRuleData(uint32_t aSIDs,
|
|
|
|
nsCSSValue* aValueStorage,
|
|
|
|
nsPresContext* aContext,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
: GenericSpecifiedValues(StyleBackendType::Gecko, aContext, aSIDs)
|
|
|
|
, mStyleContext(aStyleContext)
|
|
|
|
, mValueStorage(aValueStorage)
|
2011-03-18 06:14:31 +03:00
|
|
|
{
|
2011-04-04 15:41:02 +04:00
|
|
|
#ifndef MOZ_VALGRIND
|
2011-03-18 06:14:31 +03:00
|
|
|
size_t framePoisonOffset = GetPoisonOffset();
|
|
|
|
for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
|
|
|
|
mValueOffsets[i] = framePoisonOffset;
|
|
|
|
}
|
2011-04-04 15:41:02 +04:00
|
|
|
#endif
|
2011-03-18 06:14:31 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
void
|
|
|
|
nsRuleData::SetFontFamily(const nsString& aValue)
|
|
|
|
{
|
|
|
|
nsCSSValue* family = ValueForFontFamily();
|
|
|
|
nsCSSParser parser;
|
|
|
|
parser.ParseFontFamilyListString(aValue, nullptr, 0, *family);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRuleData::SetTextDecorationColorOverride()
|
|
|
|
{
|
|
|
|
nsCSSValue* decoration = ValueForTextDecorationLine();
|
|
|
|
int32_t newValue = NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL;
|
|
|
|
if (decoration->GetUnit() == eCSSUnit_Enumerated) {
|
|
|
|
newValue |= decoration->GetIntValue();
|
|
|
|
}
|
|
|
|
decoration->SetIntValue(newValue, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
2017-04-10 10:28:48 +03:00
|
|
|
void
|
|
|
|
nsRuleData::SetBackgroundImage(nsAttrValue& aValue)
|
|
|
|
{
|
|
|
|
nsCSSValue* backImage = ValueForBackgroundImage();
|
|
|
|
// If the value is an image, or it is a URL and we attempted a load,
|
|
|
|
// put it in the style tree.
|
|
|
|
if (aValue.Type() == nsAttrValue::eURL) {
|
|
|
|
aValue.LoadImage(mPresContext->Document());
|
|
|
|
}
|
|
|
|
if (aValue.Type() == nsAttrValue::eImage) {
|
|
|
|
nsCSSValueList* list = backImage->SetListValue();
|
|
|
|
list->mValue.SetImageValue(aValue.GetImageValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 06:14:31 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsRuleData::~nsRuleData()
|
|
|
|
{
|
2011-04-04 15:41:02 +04:00
|
|
|
#ifndef MOZ_VALGRIND
|
2011-03-18 06:14:31 +03:00
|
|
|
// assert nothing in mSIDs has poison value
|
|
|
|
size_t framePoisonOffset = GetPoisonOffset();
|
|
|
|
for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(mSIDs & (1 << i)) || mValueOffsets[i] != framePoisonOffset,
|
|
|
|
"value in SIDs was left with poison offset");
|
2011-03-18 06:14:31 +03:00
|
|
|
}
|
2011-04-04 15:41:02 +04:00
|
|
|
#endif
|
2011-03-18 06:14:31 +03:00
|
|
|
}
|
|
|
|
#endif
|