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 nsIDTD_h___
7 #define nsIDTD_h___
8 
9 /**
10  * MODULE NOTES:
11  * @update  gess 7/20/98
12  *
13  * This interface defines standard interface for DTD's. Note that this
14  * isn't HTML specific. DTD's have several functions within the parser
15  * system:
16  *      1) To coordinate the consumption of an input stream via the
17  *      parser
18  *      2) To serve as proxy to represent the containment rules of the
19  *      underlying document
20  *      3) To offer autodetection services to the parser (mainly for doc
21  *      conversion)
22  * */
23 
24 #include "nsISupports.h"
25 #include "nsString.h"
26 #include "nsITokenizer.h"
27 
28 #define NS_IDTD_IID \
29 { 0x3de05873, 0xefa7, 0x410d, \
30   { 0xa4, 0x61, 0x80, 0x33, 0xaf, 0xd9, 0xe3, 0x26 } }
31 
32 enum eAutoDetectResult {
33     eUnknownDetect,
34     eValidDetect,
35     ePrimaryDetect,
36     eInvalidDetect
37 };
38 
39 enum nsDTDMode {
40     eDTDMode_unknown = 0,
41     eDTDMode_quirks,        //pre 4.0 versions
42     eDTDMode_almost_standards,
43     eDTDMode_full_standards,
44     eDTDMode_autodetect,
45     eDTDMode_fragment
46 };
47 
48 
49 class nsIContentSink;
50 class CParserContext;
51 
52 class nsIDTD : public nsISupports
53 {
54 public:
55 
56     NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDTD_IID)
57 
58     NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
59                               nsITokenizer* aTokenizer,
60                               nsIContentSink* aSink) = 0;
61 
62     /**
63      * Called by the parser after the parsing process has concluded
64      * @update  gess5/18/98
65      * @param   anErrorCode - contains error code resulting from parse process
66      * @return
67      */
68     NS_IMETHOD DidBuildModel(nsresult anErrorCode) = 0;
69 
70     /**
71      * Called (possibly repeatedly) by the parser to parse tokens and construct
72      * the document model via the sink provided to WillBuildModel.
73      *
74      * @param   aTokenizer - tokenizer providing the token stream to be parsed
75      * @param   aCountLines - informs the DTD whether to count newlines
76      *                        (not wanted, e.g., when handling document.write)
77      * @param   aCharsetPtr - address of an nsCString containing the charset
78      *                        that the DTD should use (pointer in case the DTD
79      *                        opts to ignore this parameter)
80      */
81     NS_IMETHOD BuildModel(nsITokenizer* aTokenizer, nsIContentSink* aSink) = 0;
82 
83     /**
84      * This method is called to determine whether or not a tag of one
85      * type can contain a tag of another type.
86      *
87      * @update  gess 3/25/98
88      * @param   aParent -- int tag of parent container
89      * @param   aChild -- int tag of child container
90      * @return true if parent can contain child
91      */
92     NS_IMETHOD_(bool) CanContain(int32_t aParent,int32_t aChild) const = 0;
93 
94     /**
95      * This method gets called to determine whether a given
96      * tag is itself a container
97      *
98      * @update  gess 3/25/98
99      * @param   aTag -- tag to test for containership
100      * @return  true if given tag can contain other tags
101      */
102     NS_IMETHOD_(bool) IsContainer(int32_t aTag) const = 0;
103 
104     /**
105      * Use this id you want to stop the building content model
106      * --------------[ Sets DTD to STOP mode ]----------------
107      * It's recommended to use this method in accordance with
108      * the parser's terminate() method.
109      *
110      * @update  harishd 07/22/99
111      * @param
112      * @return
113      */
114     NS_IMETHOD_(void) Terminate() = 0;
115 
116     NS_IMETHOD_(int32_t) GetType() = 0;
117 
118     /**
119      * Call this method after calling WillBuildModel to determine what mode the
120      * DTD actually is using, as it may differ from aParserContext.mDTDMode.
121      */
122     NS_IMETHOD_(nsDTDMode) GetMode() const = 0;
123 };
124 
125 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
126 
127 #define NS_DECL_NSIDTD \
128     NS_IMETHOD WillBuildModel(  const CParserContext& aParserContext, nsITokenizer* aTokenizer, nsIContentSink* aSink) override;\
129     NS_IMETHOD DidBuildModel(nsresult anErrorCode) override;\
130     NS_IMETHOD BuildModel(nsITokenizer* aTokenizer, nsIContentSink* aSink) override;\
131     NS_IMETHOD_(bool) CanContain(int32_t aParent,int32_t aChild) const override;\
132     NS_IMETHOD_(bool) IsContainer(int32_t aTag) const override;\
133     NS_IMETHOD_(void)  Terminate() override;\
134     NS_IMETHOD_(int32_t) GetType() override;\
135     NS_IMETHOD_(nsDTDMode) GetMode() const override;
136 #endif /* nsIDTD_h___ */
137