1 // Copyright 2014-2017 The html5ever Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 //! Types used within the tree builder code.  Not exported to users.
11 
12 use crate::tokenizer::states::RawKind;
13 use crate::tokenizer::Tag;
14 
15 use crate::tendril::StrTendril;
16 
17 pub use self::FormatEntry::*;
18 pub use self::InsertionMode::*;
19 pub use self::InsertionPoint::*;
20 pub use self::ProcessResult::*;
21 pub use self::SplitStatus::*;
22 pub use self::Token::*;
23 
24 #[derive(PartialEq, Eq, Copy, Clone, Debug)]
25 pub enum InsertionMode {
26     Initial,
27     BeforeHtml,
28     BeforeHead,
29     InHead,
30     InHeadNoscript,
31     AfterHead,
32     InBody,
33     Text,
34     InTable,
35     InTableText,
36     InCaption,
37     InColumnGroup,
38     InTableBody,
39     InRow,
40     InCell,
41     InSelect,
42     InSelectInTable,
43     InTemplate,
44     AfterBody,
45     InFrameset,
46     AfterFrameset,
47     AfterAfterBody,
48     AfterAfterFrameset,
49 }
50 
51 #[derive(PartialEq, Eq, Copy, Clone, Debug)]
52 pub enum SplitStatus {
53     NotSplit,
54     Whitespace,
55     NotWhitespace,
56 }
57 
58 /// A subset/refinement of `tokenizer::Token`.  Everything else is handled
59 /// specially at the beginning of `process_token`.
60 #[derive(PartialEq, Eq, Clone, Debug)]
61 pub enum Token {
62     TagToken(Tag),
63     CommentToken(StrTendril),
64     CharacterTokens(SplitStatus, StrTendril),
65     NullCharacterToken,
66     EOFToken,
67 }
68 
69 pub enum ProcessResult<Handle> {
70     Done,
71     DoneAckSelfClosing,
72     SplitWhitespace(StrTendril),
73     Reprocess(InsertionMode, Token),
74     ReprocessForeign(Token),
75     Script(Handle),
76     ToPlaintext,
77     ToRawData(RawKind),
78 }
79 
80 pub enum FormatEntry<Handle> {
81     Element(Handle, Tag),
82     Marker,
83 }
84 
85 pub enum InsertionPoint<Handle> {
86     /// Insert as last child in this parent.
87     LastChild(Handle),
88     /// Insert before this following sibling.
89     BeforeSibling(Handle),
90     /// Insertion point is decided based on existence of element's parent node.
91     TableFosterParenting {
92         element: Handle,
93         prev_element: Handle,
94     },
95 }
96