1 | #ifndef LH_MEDIA_QUERY_H |
---|---|
2 | #define LH_MEDIA_QUERY_H |
3 | |
4 | namespace litehtml |
5 | { |
6 | struct media_query_expression |
7 | { |
8 | typedef std::vector<media_query_expression> vector; |
9 | media_feature feature; |
10 | int val; |
11 | int val2; |
12 | bool check_as_bool; |
13 | |
14 | media_query_expression() |
15 | { |
16 | check_as_bool = false; |
17 | feature = media_feature_none; |
18 | val = 0; |
19 | val2 = 0; |
20 | } |
21 | |
22 | bool check(const media_features& features) const; |
23 | }; |
24 | |
25 | class media_query |
26 | { |
27 | public: |
28 | typedef std::shared_ptr<media_query> ptr; |
29 | typedef std::vector<media_query::ptr> vector; |
30 | private: |
31 | media_query_expression::vector m_expressions; |
32 | bool m_not; |
33 | media_type m_media_type; |
34 | public: |
35 | media_query(); |
36 | media_query(const media_query& val); |
37 | |
38 | static media_query::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc); |
39 | bool check(const media_features& features) const; |
40 | }; |
41 | |
42 | class media_query_list |
43 | { |
44 | public: |
45 | typedef std::shared_ptr<media_query_list> ptr; |
46 | typedef std::vector<media_query_list::ptr> vector; |
47 | private: |
48 | media_query::vector m_queries; |
49 | bool m_is_used; |
50 | public: |
51 | media_query_list(); |
52 | media_query_list(const media_query_list& val); |
53 | |
54 | static media_query_list::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc); |
55 | bool is_used() const; |
56 | bool apply_media_features(const media_features& features); // returns true if the m_is_used changed |
57 | }; |
58 | |
59 | inline media_query_list::media_query_list(const media_query_list& val) |
60 | { |
61 | m_is_used = val.m_is_used; |
62 | m_queries = val.m_queries; |
63 | } |
64 | |
65 | inline media_query_list::media_query_list() |
66 | { |
67 | m_is_used = false; |
68 | } |
69 | |
70 | inline bool media_query_list::is_used() const |
71 | { |
72 | return m_is_used; |
73 | } |
74 | |
75 | } |
76 | |
77 | #endif // LH_MEDIA_QUERY_H |
78 |