2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A unique per-element set of attributes that is used as an
|
|
|
|
* nsIStyleRule; used to implement presentational attributes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsMappedAttributes_h___
|
|
|
|
#define nsMappedAttributes_h___
|
|
|
|
|
|
|
|
#include "nsAttrAndChildArray.h"
|
2008-01-09 01:38:28 -08:00
|
|
|
#include "nsMappedAttributeElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStyleRule.h"
|
2012-06-18 19:30:09 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIAtom;
|
|
|
|
class nsHTMLStyleSheet;
|
|
|
|
class nsRuleWalker;
|
|
|
|
|
2012-06-18 19:30:09 -07:00
|
|
|
class nsMappedAttributes MOZ_FINAL : public nsIStyleRule
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
|
|
|
nsMapRuleToAttributesFunc aMapRuleFunc);
|
|
|
|
|
2012-08-04 00:44:01 -07:00
|
|
|
// Do not return null.
|
2012-08-22 08:56:38 -07:00
|
|
|
void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMappedAttributes* Clone(bool aWillAddAttr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2012-09-06 00:14:49 -07:00
|
|
|
void SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
|
2012-07-13 16:29:14 -07:00
|
|
|
const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t Count() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mAttrCount;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(const nsMappedAttributes* aAttributes) const;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t HashValue() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void DropStyleSheetReference()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mSheet = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
void SetStyleSheet(nsHTMLStyleSheet* aSheet);
|
|
|
|
nsHTMLStyleSheet* GetStyleSheet()
|
|
|
|
{
|
|
|
|
return mSheet;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const nsAttrName* NameAt(uint32_t aPos) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
|
|
|
|
return &Attrs()[aPos].mName;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
const nsAttrValue* AttrAt(uint32_t aPos) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
|
|
|
|
return &Attrs()[aPos].mValue;
|
|
|
|
}
|
|
|
|
// 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 08:56:38 -07:00
|
|
|
void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
|
2010-03-08 07:45:00 -08:00
|
|
|
const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t IndexOfAttr(nsIAtom* aLocalName) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
// nsIStyleRule
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2011-07-19 09:42:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsMappedAttributes(const nsMappedAttributes& aCopy);
|
|
|
|
~nsMappedAttributes();
|
|
|
|
|
|
|
|
struct InternalAttr
|
|
|
|
{
|
|
|
|
nsAttrName mName;
|
|
|
|
nsAttrValue mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 00:08:04 -07:00
|
|
|
return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
InternalAttr* Attrs()
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mAttrCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mBufferSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
nsHTMLStyleSheet* mSheet; //weak
|
|
|
|
nsMapRuleToAttributesFunc mRuleMapper;
|
|
|
|
void* mAttrs[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsMappedAttributes_h___ */
|