2015-05-03 19:32:37 +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-01-26 19:22:05 +00:00
|
|
|
|
2006-03-31 08:00:42 +00:00
|
|
|
/*
|
|
|
|
* A unique per-element set of attributes that is used as an
|
|
|
|
* nsIStyleRule; used to implement presentational attributes.
|
|
|
|
*/
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
#ifndef nsMappedAttributes_h___
|
|
|
|
#define nsMappedAttributes_h___
|
|
|
|
|
|
|
|
#include "nsAttrAndChildArray.h"
|
2008-01-09 09:38:28 +00:00
|
|
|
#include "nsMappedAttributeElement.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
#include "nsIStyleRule.h"
|
2012-06-19 02:30:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
|
|
|
|
class nsIAtom;
|
2004-04-12 21:56:09 +00:00
|
|
|
class nsHTMLStyleSheet;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsMappedAttributes final : public nsIStyleRule
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-04-12 21:56:09 +00:00
|
|
|
nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
2004-01-26 19:22:05 +00:00
|
|
|
nsMapRuleToAttributesFunc aMapRuleFunc);
|
2004-01-30 22:08:23 +00:00
|
|
|
|
2012-08-04 07:44:01 +00:00
|
|
|
// Do not return null.
|
2012-08-22 15:56:38 +00:00
|
|
|
void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
|
2011-09-29 06:19:26 +00:00
|
|
|
nsMappedAttributes* Clone(bool aWillAddAttr);
|
2004-01-26 19:22:05 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2012-09-06 07:14:49 +00:00
|
|
|
void SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue);
|
2004-01-26 19:22:05 +00:00
|
|
|
const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
|
2012-07-13 23:29:14 +00:00
|
|
|
const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t Count() const
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
return mAttrCount;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Equals(const nsMappedAttributes* aAttributes) const;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t HashValue() const;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
|
|
|
void DropStyleSheetReference()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mSheet = nullptr;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2004-04-12 21:56:09 +00:00
|
|
|
void SetStyleSheet(nsHTMLStyleSheet* aSheet);
|
|
|
|
nsHTMLStyleSheet* GetStyleSheet()
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
return mSheet;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
const nsAttrName* NameAt(uint32_t aPos) const
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
|
2004-01-30 22:08:23 +00:00
|
|
|
return &Attrs()[aPos].mName;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
const nsAttrValue* AttrAt(uint32_t aPos) const
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
|
2004-01-30 22:08:23 +00:00
|
|
|
return &Attrs()[aPos].mValue;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2006-11-11 00:04:46 +00:00
|
|
|
// Remove the attr at position aPos. The value of the attr is placed in
|
|
|
|
// aValue; any value that was already in aValue is destroyed.
|
2012-08-22 15:56:38 +00:00
|
|
|
void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
|
2010-03-08 15:45:00 +00:00
|
|
|
const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t IndexOfAttr(nsIAtom* aLocalName) const;
|
2004-01-26 19:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
// nsIStyleRule
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override;
|
2004-01-26 19:22:05 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2004-01-26 19:22:05 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2011-07-19 16:42:14 +00:00
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
private:
|
2004-01-30 22:08:23 +00:00
|
|
|
nsMappedAttributes(const nsMappedAttributes& aCopy);
|
2004-01-26 19:22:05 +00:00
|
|
|
~nsMappedAttributes();
|
|
|
|
|
|
|
|
struct InternalAttr
|
|
|
|
{
|
|
|
|
nsAttrName mName;
|
|
|
|
nsAttrValue mValue;
|
|
|
|
};
|
|
|
|
|
2004-01-30 22:08:23 +00:00
|
|
|
/**
|
|
|
|
* Due to a compiler bug in VisualAge C++ for AIX, we need to return the
|
|
|
|
* address of the first index into mAttrs here, instead of simply
|
|
|
|
* returning mAttrs itself.
|
|
|
|
*
|
|
|
|
* See Bug 231104 for more information.
|
|
|
|
*/
|
|
|
|
const InternalAttr* Attrs() const
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
|
2004-01-30 22:08:23 +00:00
|
|
|
}
|
|
|
|
InternalAttr* Attrs()
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
|
2004-01-30 22:08:23 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mAttrCount;
|
2004-01-30 22:08:23 +00:00
|
|
|
#ifdef DEBUG
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mBufferSize;
|
2004-01-30 22:08:23 +00:00
|
|
|
#endif
|
2004-04-12 21:56:09 +00:00
|
|
|
nsHTMLStyleSheet* mSheet; //weak
|
2004-01-26 19:22:05 +00:00
|
|
|
nsMapRuleToAttributesFunc mRuleMapper;
|
2004-01-30 22:08:23 +00:00
|
|
|
void* mAttrs[1];
|
2004-01-26 19:22:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsMappedAttributes_h___ */
|