1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use ::selectors::attr::CaseSensitivity;
use ::selectors::bloom::BloomFilter;
use ::selectors::nth_index_cache::NthIndexCache;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum MatchingMode {
Normal,
ForStatelessPseudoElement,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VisitedHandlingMode {
AllLinksUnvisited,
AllLinksVisitedAndUnvisited,
RelevantLinkVisited,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum QuirksMode {
Quirks,
LimitedQuirks,
NoQuirks,
}
impl QuirksMode {
#[inline]
pub fn classes_and_ids_case_sensitivity(self) -> CaseSensitivity {
match self {
QuirksMode::NoQuirks |
QuirksMode::LimitedQuirks => CaseSensitivity::CaseSensitive,
QuirksMode::Quirks => CaseSensitivity::AsciiCaseInsensitive,
}
}
}
pub struct MatchingContext<'a> {
pub matching_mode: MatchingMode,
pub bloom_filter: Option<&'a BloomFilter>,
pub nth_index_cache: Option<&'a mut NthIndexCache>,
pub visited_handling: VisitedHandlingMode,
pub relevant_link_found: bool,
quirks_mode: QuirksMode,
classes_and_ids_case_sensitivity: CaseSensitivity,
}
impl<'a> MatchingContext<'a> {
pub fn new(matching_mode: MatchingMode,
bloom_filter: Option<&'a BloomFilter>,
nth_index_cache: Option<&'a mut NthIndexCache>,
quirks_mode: QuirksMode)
-> Self
{
Self {
matching_mode: matching_mode,
bloom_filter: bloom_filter,
nth_index_cache: nth_index_cache,
visited_handling: VisitedHandlingMode::AllLinksUnvisited,
relevant_link_found: false,
quirks_mode: quirks_mode,
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
}
}
pub fn new_for_visited(matching_mode: MatchingMode,
bloom_filter: Option<&'a BloomFilter>,
nth_index_cache: Option<&'a mut NthIndexCache>,
visited_handling: VisitedHandlingMode,
quirks_mode: QuirksMode)
-> Self
{
Self {
matching_mode: matching_mode,
bloom_filter: bloom_filter,
visited_handling: visited_handling,
relevant_link_found: false,
nth_index_cache: nth_index_cache,
quirks_mode: quirks_mode,
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
}
}
#[inline]
pub fn quirks_mode(&self) -> QuirksMode {
self.quirks_mode
}
#[inline]
pub fn classes_and_ids_case_sensitivity(&self) -> CaseSensitivity {
self.classes_and_ids_case_sensitivity
}
}