| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "heap/Handle.h" | 31 #include "heap/Handle.h" |
| 32 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 class LocalFrame; | 35 class LocalFrame; |
| 36 class MediaQueryExp; | 36 class MediaQueryExp; |
| 37 class MediaQueryResult; | 37 class MediaQueryResult; |
| 38 class MediaQuerySet; | 38 class MediaQuerySet; |
| 39 class RenderStyle; | 39 class RenderStyle; |
| 40 class MediaValues; |
| 40 | 41 |
| 41 typedef WillBeHeapVector<RefPtrWillBeMember<MediaQueryResult> > MediaQueryResult
List; | 42 typedef WillBeHeapVector<RefPtrWillBeMember<MediaQueryResult> > MediaQueryResult
List; |
| 42 | 43 |
| 43 /** | 44 // Class that evaluates css media queries as defined in |
| 44 * Class that evaluates css media queries as defined in | 45 // CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/) |
| 45 * CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/) | 46 // Special constructors are needed, if simple media queries are to be |
| 46 * Special constructors are needed, if simple media queries are to be | 47 // evaluated without knowledge of the medium features. This can happen |
| 47 * evaluated without knowledge of the medium features. This can happen | 48 // for example when parsing UA stylesheets, if evaluation is done |
| 48 * for example when parsing UA stylesheets, if evaluation is done | 49 // right after parsing. |
| 49 * right after parsing. | 50 // |
| 50 * | 51 // the boolean parameter is used to approximate results of evaluation, if |
| 51 * the boolean parameter is used to approximate results of evaluation, if | 52 // the device characteristics are not known. This can be used to prune the loadi
ng |
| 52 * the device characteristics are not known. This can be used to prune the loadi
ng | 53 // of stylesheets to only those which are probable to match. |
| 53 * of stylesheets to only those which are probable to match. | 54 |
| 54 */ | |
| 55 class MediaQueryEvaluator { | 55 class MediaQueryEvaluator { |
| 56 WTF_MAKE_NONCOPYABLE(MediaQueryEvaluator); WTF_MAKE_FAST_ALLOCATED; | 56 WTF_MAKE_NONCOPYABLE(MediaQueryEvaluator); WTF_MAKE_FAST_ALLOCATED; |
| 57 public: | 57 public: |
| 58 /** Creates evaluator which evaluates only simple media queries | 58 // Creates evaluator which evaluates only simple media queries |
| 59 * Evaluator returns true for "all", and returns value of \mediaFeatureResu
lt | 59 // Evaluator returns true for "all", and returns value of \mediaFeatureResul
t |
| 60 * for any media features | 60 // for any media features |
| 61 */ | 61 |
| 62 explicit MediaQueryEvaluator(bool mediaFeatureResult = false); | 62 explicit MediaQueryEvaluator(bool mediaFeatureResult = false); |
| 63 | 63 |
| 64 /** Creates evaluator which evaluates only simple media queries | 64 // Creates evaluator which evaluates only simple media queries |
| 65 * Evaluator returns true for acceptedMediaType and returns value of \medi
afeatureResult | 65 // Evaluator returns true for acceptedMediaType and returns value of \media
featureResult |
| 66 * for any media features | 66 // for any media features |
| 67 */ | 67 |
| 68 MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult
= false); | 68 MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult
= false); |
| 69 MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult =
false); | 69 MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult =
false); |
| 70 | 70 |
| 71 /** Creates evaluator which evaluates full media queries */ | 71 // Creates evaluator which evaluates full media queries |
| 72 MediaQueryEvaluator(const String& acceptedMediaType, LocalFrame*, RenderStyl
e*); | 72 MediaQueryEvaluator(const String& acceptedMediaType, LocalFrame*, RenderStyl
e*); |
| 73 | 73 |
| 74 // Creates evaluator which evaluates in a thread-safe manner a subset of med
ia values |
| 75 MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues&); |
| 76 |
| 74 ~MediaQueryEvaluator(); | 77 ~MediaQueryEvaluator(); |
| 75 | 78 |
| 76 bool mediaTypeMatch(const String& mediaTypeToMatch) const; | 79 bool mediaTypeMatch(const String& mediaTypeToMatch) const; |
| 77 bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const; | 80 bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const; |
| 78 | 81 |
| 79 /** Evaluates a list of media queries */ | 82 // Evaluates a list of media queries |
| 80 bool eval(const MediaQuerySet*, MediaQueryResultList* = 0) const; | 83 bool eval(const MediaQuerySet*, MediaQueryResultList* = 0) const; |
| 81 | 84 |
| 82 /** Evaluates media query subexpression, ie "and (media-feature: value)" par
t */ | 85 // Evaluates media query subexpression, ie "and (media-feature: value)" part |
| 83 bool eval(const MediaQueryExp*) const; | 86 bool eval(const MediaQueryExp*) const; |
| 84 | 87 |
| 85 private: | 88 private: |
| 86 String m_mediaType; | 89 String m_mediaType; |
| 87 LocalFrame* m_frame; // Not owned. | 90 bool m_expectedResult; |
| 88 RefPtr<RenderStyle> m_style; | 91 RefPtr<MediaValues> m_mediaValues; |
| 89 bool m_expResult; | |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 } // namespace | 94 } // namespace |
| 93 #endif | 95 #endif |
| OLD | NEW |