| OLD | NEW |
| 1 /* | 1 /* |
| 2 * CSS Media Query Evaluator | 2 * CSS Media Query Evaluator |
| 3 * | 3 * |
| 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. | 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef MediaQueryEvaluator_h | 28 #ifndef MediaQueryEvaluator_h |
| 29 #define MediaQueryEvaluator_h | 29 #define MediaQueryEvaluator_h |
| 30 | 30 |
| 31 #include "wtf/RefCounted.h" |
| 31 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 32 | 33 |
| 33 namespace WebCore { | 34 namespace WebCore { |
| 34 class Frame; | 35 class Frame; |
| 35 class MediaQueryExp; | 36 class MediaQueryExp; |
| 36 class MediaQuerySet; | 37 class MediaQuerySet; |
| 37 class RenderStyle; | 38 class RenderStyle; |
| 38 class StyleResolver; | 39 class StyleResolver; |
| 40 class Document; |
| 41 |
| 42 class MediaValues : public RefCounted<MediaValues> { |
| 43 public: |
| 44 // Should return a pointer that auto destructs when copied |
| 45 static PassRefPtr<MediaValues> create(Document*); |
| 46 static PassRefPtr<MediaValues> copy(const MediaValues*); |
| 47 |
| 48 int getViewportWidth() { return m_viewportWidth; } |
| 49 int getViewportHeight() { return m_viewportHeight; } |
| 50 int getDeviceWidth() { return m_deviceWidth; } |
| 51 int getDeviceHeight() { return m_deviceHeight; } |
| 52 float getPixelRatio() { return m_pixelRatio; } |
| 53 int getColorBitsPerComponent() { return m_colorBitsPerComponent; } |
| 54 int getMonochromeBitsPerComponent() { return m_monochromeBitsPerComponent; } |
| 55 int getPointer() { return m_pointer; } |
| 56 int getDefaultFontSize() { return m_defaultFontSize; } |
| 57 bool getThreeDEnabled() { return m_threeDEnabled; } |
| 58 String getMediaType() { return m_mediaType; } |
| 59 |
| 60 private: |
| 61 MediaValues(int viewportWidth, |
| 62 int viewportHeight, |
| 63 int deviceWidth, |
| 64 int deviceHeight, |
| 65 float pixelRatio, |
| 66 int colorBitsPerComponent, |
| 67 int monochromeBitsPerComponent, |
| 68 int pointer, |
| 69 int defaultFontSize, |
| 70 int threeDEnabled, |
| 71 String mediaType) |
| 72 : m_viewportWidth(viewportWidth) |
| 73 , m_viewportHeight(viewportHeight) |
| 74 , m_deviceWidth(deviceWidth) |
| 75 , m_deviceHeight(deviceHeight) |
| 76 , m_pixelRatio(pixelRatio) |
| 77 , m_colorBitsPerComponent(colorBitsPerComponent) |
| 78 , m_monochromeBitsPerComponent(monochromeBitsPerComponent) |
| 79 , m_pointer(pointer) |
| 80 , m_defaultFontSize(defaultFontSize) |
| 81 , m_threeDEnabled(threeDEnabled) |
| 82 , m_mediaType(mediaType.isolatedCopy()) |
| 83 { |
| 84 } |
| 85 |
| 86 int m_viewportWidth; |
| 87 int m_viewportHeight; |
| 88 int m_deviceWidth; |
| 89 int m_deviceHeight; |
| 90 float m_pixelRatio; |
| 91 int m_colorBitsPerComponent; |
| 92 int m_monochromeBitsPerComponent; |
| 93 int m_pointer; |
| 94 int m_defaultFontSize; |
| 95 bool m_threeDEnabled; |
| 96 String m_mediaType; |
| 97 }; |
| 39 | 98 |
| 40 /** | 99 /** |
| 41 * Class that evaluates css media queries as defined in | 100 * Class that evaluates css media queries as defined in |
| 42 * CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/) | 101 * CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/) |
| 43 * Special constructors are needed, if simple media queries are to be | 102 * Special constructors are needed, if simple media queries are to be |
| 44 * evaluated without knowledge of the medium features. This can happen | 103 * evaluated without knowledge of the medium features. This can happen |
| 45 * for example when parsing UA stylesheets, if evaluation is done | 104 * for example when parsing UA stylesheets, if evaluation is done |
| 46 * right after parsing. | 105 * right after parsing. |
| 47 * | 106 * |
| 48 * the boolean parameter is used to approximate results of evaluation, if | 107 * the boolean parameter is used to approximate results of evaluation, if |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 /** Creates evaluator which evaluates only simple media queries | 120 /** Creates evaluator which evaluates only simple media queries |
| 62 * Evaluator returns true for acceptedMediaType and returns value of \medi
afeatureResult | 121 * Evaluator returns true for acceptedMediaType and returns value of \medi
afeatureResult |
| 63 * for any media features | 122 * for any media features |
| 64 */ | 123 */ |
| 65 MediaQueryEvaluator(const AtomicString& acceptedMediaType, bool mediaFeature
Result = false); | 124 MediaQueryEvaluator(const AtomicString& acceptedMediaType, bool mediaFeature
Result = false); |
| 66 MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult =
false); | 125 MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult =
false); |
| 67 | 126 |
| 68 /** Creates evaluator which evaluates full media queries */ | 127 /** Creates evaluator which evaluates full media queries */ |
| 69 MediaQueryEvaluator(const AtomicString& acceptedMediaType, Frame*, RenderSty
le*); | 128 MediaQueryEvaluator(const AtomicString& acceptedMediaType, Frame*, RenderSty
le*); |
| 70 | 129 |
| 130 /** Creates evaluator which evaluates in a thread-safe manner a subset of me
dia values |
| 131 */ |
| 132 MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues* , bo
ol mediaFeatureResult); |
| 133 |
| 71 ~MediaQueryEvaluator(); | 134 ~MediaQueryEvaluator(); |
| 72 | 135 |
| 73 bool mediaTypeMatch(const AtomicString& mediaTypeToMatch) const; | 136 bool mediaTypeMatch(const AtomicString& mediaTypeToMatch) const; |
| 74 bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const; | 137 bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const; |
| 75 | 138 |
| 76 /** Evaluates a list of media queries */ | 139 /** Evaluates a list of media queries */ |
| 77 bool eval(const MediaQuerySet*, StyleResolver* = 0) const; | 140 bool eval(const MediaQuerySet*, StyleResolver* = 0) const; |
| 78 | 141 |
| 79 /** Evaluates media query subexpression, ie "and (media-feature: value)" par
t */ | 142 /** Evaluates media query subexpression, ie "and (media-feature: value)" par
t */ |
| 80 bool eval(const MediaQueryExp*) const; | 143 bool eval(const MediaQueryExp*) const; |
| 81 | 144 |
| 82 private: | 145 private: |
| 83 AtomicString m_mediaType; | 146 AtomicString m_mediaType; |
| 84 Frame* m_frame; // Not owned. | 147 Frame* m_frame; // Not owned. |
| 85 RefPtr<RenderStyle> m_style; | 148 RefPtr<RenderStyle> m_style; |
| 86 bool m_expResult; | 149 bool m_expResult; |
| 150 RefPtr<MediaValues> m_mediaValues; |
| 87 }; | 151 }; |
| 88 | 152 |
| 89 } // namespace | 153 } // namespace |
| 90 #endif | 154 #endif |
| OLD | NEW |