content/base/src/nsMappedAttributes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/src/nsMappedAttributes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * A unique per-element set of attributes that is used as an
    1.11 + * nsIStyleRule; used to implement presentational attributes.
    1.12 + */
    1.13 +
    1.14 +#ifndef nsMappedAttributes_h___
    1.15 +#define nsMappedAttributes_h___
    1.16 +
    1.17 +#include "nsAttrAndChildArray.h"
    1.18 +#include "nsMappedAttributeElement.h"
    1.19 +#include "nsIStyleRule.h"
    1.20 +#include "mozilla/Attributes.h"
    1.21 +#include "mozilla/MemoryReporting.h"
    1.22 +
    1.23 +class nsIAtom;
    1.24 +class nsHTMLStyleSheet;
    1.25 +class nsRuleWalker;
    1.26 +
    1.27 +class nsMappedAttributes MOZ_FINAL : public nsIStyleRule
    1.28 +{
    1.29 +public:
    1.30 +  nsMappedAttributes(nsHTMLStyleSheet* aSheet,
    1.31 +                     nsMapRuleToAttributesFunc aMapRuleFunc);
    1.32 +
    1.33 +  // Do not return null.
    1.34 +  void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
    1.35 +  nsMappedAttributes* Clone(bool aWillAddAttr);
    1.36 +
    1.37 +  NS_DECL_ISUPPORTS
    1.38 +
    1.39 +  void SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue);
    1.40 +  const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
    1.41 +  const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
    1.42 +
    1.43 +  uint32_t Count() const
    1.44 +  {
    1.45 +    return mAttrCount;
    1.46 +  }
    1.47 +
    1.48 +  bool Equals(const nsMappedAttributes* aAttributes) const;
    1.49 +  uint32_t HashValue() const;
    1.50 +
    1.51 +  void DropStyleSheetReference()
    1.52 +  {
    1.53 +    mSheet = nullptr;
    1.54 +  }
    1.55 +  void SetStyleSheet(nsHTMLStyleSheet* aSheet);
    1.56 +  nsHTMLStyleSheet* GetStyleSheet()
    1.57 +  {
    1.58 +    return mSheet;
    1.59 +  }
    1.60 +
    1.61 +  const nsAttrName* NameAt(uint32_t aPos) const
    1.62 +  {
    1.63 +    NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
    1.64 +    return &Attrs()[aPos].mName;
    1.65 +  }
    1.66 +  const nsAttrValue* AttrAt(uint32_t aPos) const
    1.67 +  {
    1.68 +    NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
    1.69 +    return &Attrs()[aPos].mValue;
    1.70 +  }
    1.71 +  // Remove the attr at position aPos.  The value of the attr is placed in
    1.72 +  // aValue; any value that was already in aValue is destroyed.
    1.73 +  void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
    1.74 +  const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
    1.75 +  int32_t IndexOfAttr(nsIAtom* aLocalName) const;
    1.76 +  
    1.77 +
    1.78 +  // nsIStyleRule 
    1.79 +  virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
    1.80 +#ifdef DEBUG
    1.81 +  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
    1.82 +#endif
    1.83 +
    1.84 +  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.85 +
    1.86 +private:
    1.87 +  nsMappedAttributes(const nsMappedAttributes& aCopy);
    1.88 +  ~nsMappedAttributes();
    1.89 +
    1.90 +  struct InternalAttr
    1.91 +  {
    1.92 +    nsAttrName mName;
    1.93 +    nsAttrValue mValue;
    1.94 +  };
    1.95 +
    1.96 +  /**
    1.97 +   * Due to a compiler bug in VisualAge C++ for AIX, we need to return the 
    1.98 +   * address of the first index into mAttrs here, instead of simply
    1.99 +   * returning mAttrs itself.
   1.100 +   *
   1.101 +   * See Bug 231104 for more information.
   1.102 +   */
   1.103 +  const InternalAttr* Attrs() const
   1.104 +  {
   1.105 +    return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
   1.106 +  }
   1.107 +  InternalAttr* Attrs()
   1.108 +  {
   1.109 +    return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
   1.110 +  }
   1.111 +
   1.112 +  uint16_t mAttrCount;
   1.113 +#ifdef DEBUG
   1.114 +  uint16_t mBufferSize;
   1.115 +#endif
   1.116 +  nsHTMLStyleSheet* mSheet; //weak
   1.117 +  nsMapRuleToAttributesFunc mRuleMapper;
   1.118 +  void* mAttrs[1];
   1.119 +};
   1.120 +
   1.121 +#endif /* nsMappedAttributes_h___ */

mercurial