KHtml

css_mediaquery.h
1 /*
2  * CSS Media Query
3  *
4  * Copyright (C) 2006 Kimmo Kinnunen <[email protected]>.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef css_mediaquery_h
29 #define css_mediaquery_h
30 
31 #include "dom/dom_string.h"
32 #include "css/css_valueimpl.h"
33 
34 class KHTMLPart;
35 
36 namespace DOM
37 {
38 class MediaListImpl;
39 class ValueList;
40 }
41 
42 namespace khtml
43 {
44 
45 class MediaQueryExp;
46 
47 class MediaQuery
48 {
49 public:
50  enum Restrictor {
51  Only, Not, None
52  };
53 
54  MediaQuery(Restrictor r, const DOM::DOMString &mediaType, QList<MediaQueryExp *> *exprs);
55  ~MediaQuery();
56 
57  Restrictor restrictor() const
58  {
59  return m_restrictor;
60  }
61  const QList<MediaQueryExp *> *expressions() const
62  {
63  return m_expressions;
64  }
65  DOM::DOMString mediaType() const
66  {
67  return m_mediaType;
68  }
69  bool operator==(const MediaQuery &other) const;
70  void append(MediaQueryExp *newExp)
71  {
72  m_expressions->append(newExp);
73  }
74  DOM::DOMString cssText() const;
75 
76 private:
77  Restrictor m_restrictor;
78  DOM::DOMString m_mediaType;
79  QList<MediaQueryExp *> *m_expressions;
80 };
81 
82 class CSSStyleSelector;
83 class RenderStyle;
84 class MediaQueryExp;
85 
99 {
100 public:
105  MediaQueryEvaluator(bool mediaFeatureResult = false);
106 
111  MediaQueryEvaluator(const DOM::DOMString &acceptedMediaType, bool mediaFeatureResult = false);
112  MediaQueryEvaluator(const char *acceptedMediaType, bool mediaFeatureResult = false);
113 
116  MediaQueryEvaluator(const DOM::DOMString &acceptedMediaType, KHTMLPart *, RenderStyle *);
117 
119 
120  bool mediaTypeMatch(const DOM::DOMString &mediaTypeToMatch) const;
121  bool mediaTypeMatchSpecific(const char *mediaTypeToMatch) const;
122 
124  bool eval(const DOM::MediaListImpl *, CSSStyleSelector * = nullptr) const;
125 
127  bool eval(const MediaQueryExp *) const;
128 
129  static void cleanup();
130 
131 private:
132  DOM::DOMString m_mediaType;
133  KHTMLPart *m_part; // not owned
134  RenderStyle *m_style; // not owned
135  bool m_expResult;
136 };
137 
138 class MediaQueryExp
139 {
140 public:
141  MediaQueryExp(const DOM::DOMString &mediaFeature, DOM::ValueList *values);
142  ~MediaQueryExp();
143 
144  DOM::DOMString mediaFeature() const
145  {
146  return m_mediaFeature;
147  }
148 
149  DOM::CSSValueImpl *value() const
150  {
151  return m_value;
152  }
153 
154  bool operator==(const MediaQueryExp &other) const
155  {
156  return (other.m_mediaFeature == m_mediaFeature)
157  && ((!other.m_value && !m_value)
158  || (other.m_value && m_value && other.m_value->cssText() == m_value->cssText()));
159  }
160 
161  bool isViewportDependent() const
162  {
163  return m_viewportDependent;
164  }
165 
166 private:
167  bool m_viewportDependent;
168  DOM::DOMString m_mediaFeature;
169  DOM::CSSValueImpl *m_value;
170 };
171 
172 } // namespace
173 
174 #endif
This file is part of the HTML rendering engine for KDE.
This class is khtml&#39;s main class.
Definition: khtml_part.h:208
QVector< V > values(const QMultiHash< K, V > &c)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
the StyleSelector implementation for CSS.
This library provides a full-featured HTML parser and widget.
Class that evaluates css media queries as defined in CSS3 Module "Media Queries" (https://www.w3.org/TR/css3-mediaqueries/) Special constructors are needed, if simple media queries are to be evaluated without knowledge of the medium features.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:45:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.