Bug 575855 - Fix for transitions from fullscreen briefly show an aero basic window...
[mozilla-central.git] / parser / html / nsHtml5AtomTable.h
blobed90932b05c693b246a949be1083bcf8cc6fe4ac
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is HTML Parser C++ Translator code.
16 * The Initial Developer of the Original Code is
17 * Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2009
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Henri Sivonen <hsivonen@iki.fi>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsHtml5AtomTable_h_
39 #define nsHtml5AtomTable_h_
41 #include "nsHashKeys.h"
42 #include "nsTHashtable.h"
43 #include "nsAutoPtr.h"
44 #include "nsIAtom.h"
45 #include "nsIThread.h"
47 class nsHtml5Atom;
49 class nsHtml5AtomEntry : public nsStringHashKey
51 public:
52 nsHtml5AtomEntry(KeyTypePointer aStr);
53 nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther);
54 ~nsHtml5AtomEntry();
55 inline nsHtml5Atom* GetAtom() {
56 return mAtom;
58 private:
59 nsAutoPtr<nsHtml5Atom> mAtom;
62 /**
63 * nsHtml5AtomTable provides non-locking lookup and creation of atoms for
64 * nsHtml5Parser or nsHtml5StreamParser.
66 * The hashtable holds dynamically allocated atoms that are private to an
67 * instance of nsHtml5Parser or nsHtml5StreamParser. (Static atoms are used on
68 * interned nsHtml5ElementNames and interned nsHtml5AttributeNames. Also, when
69 * the doctype name is 'html', that identifier needs to be represented as a
70 * static atom.)
72 * Each instance of nsHtml5Parser has a single instance of nsHtml5AtomTable,
73 * and each instance of nsHtml5StreamParser has a single instance of
74 * nsHtml5AtomTable. Dynamic atoms obtained from an nsHtml5AtomTable are valid
75 * for == comparison with each other or with atoms declared in nsHtml5Atoms
76 * within the nsHtml5Tokenizer and the nsHtml5TreeBuilder instances owned by
77 * the same nsHtml5Parser/nsHtml5StreamParser instance that owns the
78 * nsHtml5AtomTable instance.
80 * Dynamic atoms (atoms whose IsStaticAtom() returns PR_FALSE) obtained from
81 * nsHtml5AtomTable must be re-obtained from another atom table when there's a
82 * need to migrate atoms from an nsHtml5Parser to its nsHtml5StreamParser
83 * (re-obtain from the other nsHtml5AtomTable), from an nsHtml5Parser to its
84 * owner nsHtml5Parser (re-obtain from the other nsHtml5AtomTable) or from the
85 * parser to the DOM (re-obtain from the application-wide atom table). To
86 * re-obtain an atom from another atom table, obtain a string from the atom
87 * using ToString(nsAString&) and look up an atom in the other table using that
88 * string.
90 * An instance of nsHtml5AtomTable that belongs to an nsHtml5Parser is only
91 * accessed from the main thread. An instance of nsHtml5AtomTable that belongs
92 * to an nsHtml5StreamParser is accessed both from the main thread and from the
93 * thread that executes the runnables of the nsHtml5StreamParser instance.
94 * However, the threads never access the nsHtml5AtomTable instance concurrently
95 * in the nsHtml5StreamParser case.
97 * Methods on the atoms obtained from nsHtml5AtomTable may be called on any
98 * thread, although they only need to be called on the main thread or on the
99 * thread working for the nsHtml5StreamParser when nsHtml5AtomTable belongs to
100 * an nsHtml5StreamParser.
102 * Dynamic atoms obtained from nsHtml5AtomTable are deleted when the
103 * nsHtml5AtomTable itself is destructed, which happens when the owner
104 * nsHtml5Parser or nsHtml5StreamParser is destructed.
106 class nsHtml5AtomTable
108 public:
109 nsHtml5AtomTable();
110 ~nsHtml5AtomTable();
113 * Must be called after the constructor before use. Returns PR_TRUE
114 * when successful and PR_FALSE on OOM failure.
116 inline PRBool Init() {
117 return mTable.Init();
121 * Obtains the atom for the given string in the scope of this atom table.
123 nsIAtom* GetAtom(const nsAString& aKey);
126 * Empties the table.
128 void Clear() {
129 mTable.Clear();
132 #ifdef DEBUG
133 void SetPermittedLookupThread(nsIThread* aThread) {
134 mPermittedLookupThread = aThread;
136 #endif
138 private:
139 nsTHashtable<nsHtml5AtomEntry> mTable;
140 #ifdef DEBUG
141 nsCOMPtr<nsIThread> mPermittedLookupThread;
142 #endif
145 #endif // nsHtml5AtomTable_h_