LCOV - code coverage report
Current view: top level - dom/xul/templates - nsContentSupportMap.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 19 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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 nsContentSupportMap_h__
       7             : #define nsContentSupportMap_h__
       8             : 
       9             : #include "PLDHashTable.h"
      10             : #include "nsTemplateMatch.h"
      11             : 
      12             : /**
      13             :  * The nsContentSupportMap maintains a mapping from a "resource element"
      14             :  * in the content tree to the nsTemplateMatch that was used to instantiate it. This
      15             :  * is necessary to allow the XUL content to be built lazily. Specifically,
      16             :  * when building "resumes" on a partially-built content element, the builder
      17             :  * will walk upwards in the content tree to find the first element with an
      18             :  * 'id' attribute. This element is assumed to be the "resource element",
      19             :  * and allows the content builder to access the nsTemplateMatch (variable assignments
      20             :  * and rule information).
      21             :  */
      22             : class nsContentSupportMap {
      23             : public:
      24           0 :     nsContentSupportMap() : mMap(PLDHashTable::StubOps(), sizeof(Entry)) { }
      25           0 :     ~nsContentSupportMap() { }
      26             : 
      27           0 :     nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {
      28           0 :         PLDHashEntryHdr* hdr = mMap.Add(aElement, mozilla::fallible);
      29           0 :         if (!hdr)
      30           0 :             return NS_ERROR_OUT_OF_MEMORY;
      31             : 
      32           0 :         Entry* entry = static_cast<Entry*>(hdr);
      33           0 :         NS_ASSERTION(entry->mMatch == nullptr, "over-writing entry");
      34           0 :         entry->mContent = aElement;
      35           0 :         entry->mMatch   = aMatch;
      36           0 :         return NS_OK;
      37             :     }
      38             : 
      39           0 :     bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) {
      40           0 :         PLDHashEntryHdr* hdr = mMap.Search(aElement);
      41           0 :         if (!hdr)
      42           0 :             return false;
      43             : 
      44           0 :         Entry* entry = static_cast<Entry*>(hdr);
      45           0 :         *aMatch = entry->mMatch;
      46           0 :         return true;
      47             :     }
      48             : 
      49             :     void Remove(nsIContent* aElement);
      50             : 
      51           0 :     void Clear() { mMap.Clear(); }
      52             : 
      53             : protected:
      54             :     PLDHashTable mMap;
      55             : 
      56             :     struct Entry : public PLDHashEntryHdr {
      57             :         nsIContent*      mContent;
      58             :         nsTemplateMatch* mMatch;
      59             :     };
      60             : };
      61             : 
      62             : #endif

Generated by: LCOV version 1.13