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(crate) use self::FormatEntry::*; |
18 | pub(crate) use self::InsertionMode::*; |
19 | pub(crate) use self::InsertionPoint::*; |
20 | pub(crate) use self::ProcessResult::*; |
21 | pub(crate) use self::SplitStatus::*; |
22 | pub(crate) use self::Token::*; |
23 | |
24 | #[derive (PartialEq, Eq, Copy, Clone, Debug)] |
25 | pub(crate) 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(crate) 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 | #[allow (clippy::enum_variant_names)] |
62 | pub(crate) enum Token { |
63 | TagToken(Tag), |
64 | CommentToken(StrTendril), |
65 | CharacterTokens(SplitStatus, StrTendril), |
66 | NullCharacterToken, |
67 | EOFToken, |
68 | } |
69 | |
70 | pub(crate) enum ProcessResult<Handle> { |
71 | Done, |
72 | DoneAckSelfClosing, |
73 | SplitWhitespace(StrTendril), |
74 | Reprocess(InsertionMode, Token), |
75 | #[allow (dead_code)] // FIXME |
76 | ReprocessForeign(Token), |
77 | Script(Handle), |
78 | ToPlaintext, |
79 | ToRawData(RawKind), |
80 | } |
81 | |
82 | pub(crate) enum FormatEntry<Handle> { |
83 | Element(Handle, Tag), |
84 | Marker, |
85 | } |
86 | |
87 | pub(crate) enum InsertionPoint<Handle> { |
88 | /// Insert as last child in this parent. |
89 | LastChild(Handle), |
90 | #[allow (dead_code)] // FIXME |
91 | /// Insert before this following sibling. |
92 | BeforeSibling(Handle), |
93 | /// Insertion point is decided based on existence of element's parent node. |
94 | TableFosterParenting { |
95 | element: Handle, |
96 | prev_element: Handle, |
97 | }, |
98 | } |
99 | |