LCOV - code coverage report
Current view: top level - parser/htmlparser - nsHTMLTags.h (source / functions) Hit Total Coverage
Test: output.info Lines: 16 16 100.0 %
Date: 2017-07-14 16:53:18 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef nsHTMLTags_h___
       7             : #define nsHTMLTags_h___
       8             : 
       9             : #include "nsString.h"
      10             : #include "plhash.h"
      11             : 
      12             : class nsIAtom;
      13             : 
      14             : /*
      15             :    Declare the enum list using the magic of preprocessing
      16             :    enum values are "eHTMLTag_foo" (where foo is the tag)
      17             : 
      18             :    To change the list of tags, see nsHTMLTagList.h
      19             : 
      20             :    These enum values are used as the index of array in various places.
      21             :    If we change the structure of the enum by adding entries to it or removing
      22             :    entries from it _directly_, not via nsHTMLTagList.h, don't forget to update
      23             :    dom/bindings/BindingUtils.cpp and dom/html/nsHTMLContentSink.cpp as well.
      24             :  */
      25             : #define HTML_TAG(_tag, _classname, _interfacename) eHTMLTag_##_tag,
      26             : #define HTML_OTHER(_tag) eHTMLTag_##_tag,
      27             : enum nsHTMLTag {
      28             :   /* this enum must be first and must be zero */
      29             :   eHTMLTag_unknown = 0,
      30             : #include "nsHTMLTagList.h"
      31             : 
      32             :   /* can't be moved into nsHTMLTagList since gcc3.4 doesn't like a
      33             :      comma at the end of enum list*/
      34             :   eHTMLTag_userdefined
      35             : };
      36             : #undef HTML_TAG
      37             : #undef HTML_OTHER
      38             : 
      39             : // All tags before eHTMLTag_text are HTML tags
      40             : #define NS_HTML_TAG_MAX int32_t(eHTMLTag_text - 1)
      41             : 
      42             : class nsHTMLTags {
      43             : public:
      44             :   static void RegisterAtoms(void);
      45             :   static nsresult AddRefTable(void);
      46             :   static void ReleaseTable(void);
      47             : 
      48             :   // Functions for converting string or atom to id
      49             :   static nsHTMLTag LookupTag(const nsAString& aTagName);
      50         826 :   static nsHTMLTag CaseSensitiveLookupTag(const char16_t* aTagName)
      51             :   {
      52         826 :     NS_ASSERTION(gTagTable, "no lookup table, needs addref");
      53         826 :     NS_ASSERTION(aTagName, "null tagname!");
      54             : 
      55         826 :     void* tag = PL_HashTableLookupConst(gTagTable, aTagName);
      56             : 
      57         826 :     return tag ? (nsHTMLTag)NS_PTR_TO_INT32(tag) : eHTMLTag_userdefined;
      58             :   }
      59         352 :   static nsHTMLTag CaseSensitiveLookupTag(nsIAtom* aTagName)
      60             :   {
      61         352 :     NS_ASSERTION(gTagAtomTable, "no lookup table, needs addref");
      62         352 :     NS_ASSERTION(aTagName, "null tagname!");
      63             : 
      64         352 :     void* tag = PL_HashTableLookupConst(gTagAtomTable, aTagName);
      65             : 
      66         352 :     return tag ? (nsHTMLTag)NS_PTR_TO_INT32(tag) : eHTMLTag_userdefined;
      67             :   }
      68             : 
      69             :   // Functions for converting an id to a string or atom
      70         280 :   static const char16_t *GetStringValue(nsHTMLTag aEnum)
      71             :   {
      72         554 :     return aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX ?
      73         554 :       nullptr : sTagUnicodeTable[aEnum - 1];
      74             :   }
      75         280 :   static nsIAtom *GetAtom(nsHTMLTag aEnum)
      76             :   {
      77         554 :     return aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX ?
      78         554 :       nullptr : sTagAtomTable[aEnum - 1];
      79             :   }
      80             : 
      81             : #ifdef DEBUG
      82             :   static void TestTagTable();
      83             : #endif
      84             : 
      85             : private:
      86             :   static nsIAtom* sTagAtomTable[eHTMLTag_userdefined - 1];
      87             :   static const char16_t* const sTagUnicodeTable[];
      88             : 
      89             :   static int32_t gTableRefCount;
      90             :   static PLHashTable* gTagTable;
      91             :   static PLHashTable* gTagAtomTable;
      92             : };
      93             : 
      94             : #define eHTMLTags nsHTMLTag
      95             : 
      96             : #endif /* nsHTMLTags_h___ */

Generated by: LCOV version 1.13