2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-03-23 10:39:31 +03:00
|
|
|
|
|
|
|
#ifndef nsContentSupportMap_h__
|
|
|
|
#define nsContentSupportMap_h__
|
|
|
|
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
2001-03-23 10:39:31 +03:00
|
|
|
#include "nsTemplateMatch.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsContentSupportMap maintains a mapping from a "resource element"
|
|
|
|
* in the content tree to the nsTemplateMatch that was used to instantiate it. This
|
|
|
|
* is necessary to allow the XUL content to be built lazily. Specifically,
|
|
|
|
* when building "resumes" on a partially-built content element, the builder
|
|
|
|
* will walk upwards in the content tree to find the first element with an
|
|
|
|
* 'id' attribute. This element is assumed to be the "resource element",
|
|
|
|
* and allows the content builder to access the nsTemplateMatch (variable assignments
|
|
|
|
* and rule information).
|
|
|
|
*/
|
|
|
|
class nsContentSupportMap {
|
|
|
|
public:
|
2015-09-15 00:23:47 +03:00
|
|
|
nsContentSupportMap() : mMap(PLDHashTable::StubOps(), sizeof(Entry)) { }
|
2015-05-19 06:21:16 +03:00
|
|
|
~nsContentSupportMap() { }
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2001-04-04 09:00:08 +04:00
|
|
|
nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {
|
2015-09-15 00:23:12 +03:00
|
|
|
PLDHashEntryHdr* hdr = mMap.Add(aElement, mozilla::fallible);
|
2001-04-04 09:00:08 +04:00
|
|
|
if (!hdr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2015-01-23 08:05:52 +03:00
|
|
|
Entry* entry = static_cast<Entry*>(hdr);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(entry->mMatch == nullptr, "over-writing entry");
|
2001-04-04 09:00:08 +04:00
|
|
|
entry->mContent = aElement;
|
|
|
|
entry->mMatch = aMatch;
|
2015-01-23 08:05:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) {
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr* hdr = mMap.Search(aElement);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (!hdr)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2015-01-23 08:05:52 +03:00
|
|
|
Entry* entry = static_cast<Entry*>(hdr);
|
2001-04-04 09:00:08 +04:00
|
|
|
*aMatch = entry->mMatch;
|
2015-01-23 08:05:52 +03:00
|
|
|
return true;
|
|
|
|
}
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2015-05-21 07:23:55 +03:00
|
|
|
void Remove(nsIContent* aElement);
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2015-05-19 06:21:16 +03:00
|
|
|
void Clear() { mMap.Clear(); }
|
2001-03-23 10:39:31 +03:00
|
|
|
|
|
|
|
protected:
|
2015-05-20 02:46:17 +03:00
|
|
|
PLDHashTable mMap;
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2015-01-23 08:05:52 +03:00
|
|
|
struct Entry : public PLDHashEntryHdr {
|
2001-04-04 09:00:08 +04:00
|
|
|
nsIContent* mContent;
|
2001-03-23 10:39:31 +03:00
|
|
|
nsTemplateMatch* mMatch;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|