1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef nsHtml5TokenizerLoopPolicies_h
6 #define nsHtml5TokenizerLoopPolicies_h
7 
8 /**
9  * This policy does not report tokenizer transitions anywhere. To be used
10  * when _not_ viewing source.
11  */
12 struct nsHtml5SilentPolicy {
13   static const bool reportErrors = false;
transitionnsHtml5SilentPolicy14   static int32_t transition(nsHtml5Highlighter* aHighlighter, int32_t aState,
15                             bool aReconsume, int32_t aPos) {
16     return aState;
17   }
completedNamedCharacterReferencensHtml5SilentPolicy18   static void completedNamedCharacterReference(
19       nsHtml5Highlighter* aHighlighter) {}
20 };
21 
22 /**
23  * This policy reports the tokenizer transitions to a highlighter. To be used
24  * when viewing source.
25  */
26 struct nsHtml5ViewSourcePolicy {
27   static const bool reportErrors = true;
transitionnsHtml5ViewSourcePolicy28   static int32_t transition(nsHtml5Highlighter* aHighlighter, int32_t aState,
29                             bool aReconsume, int32_t aPos) {
30     return aHighlighter->Transition(aState, aReconsume, aPos);
31   }
completedNamedCharacterReferencensHtml5ViewSourcePolicy32   static void completedNamedCharacterReference(
33       nsHtml5Highlighter* aHighlighter) {
34     aHighlighter->CompletedNamedCharacterReference();
35   }
36 };
37 
38 #endif  // nsHtml5TokenizerLoopPolicies_h
39