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 * Copyright (C) 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2013 Apple Inc. All rights reserved. |
6 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 6 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 using namespace MediaFeatureNames; | 60 using namespace MediaFeatureNames; |
61 | 61 |
62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; | 62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; |
63 | 63 |
64 using EvalFunc = bool (*)(const MediaQueryExpValue&, | 64 using EvalFunc = bool (*)(const MediaQueryExpValue&, |
65 MediaFeaturePrefix, | 65 MediaFeaturePrefix, |
66 const MediaValues&); | 66 const MediaValues&); |
67 using FunctionMap = HashMap<StringImpl*, EvalFunc>; | 67 using FunctionMap = HashMap<StringImpl*, EvalFunc>; |
68 static FunctionMap* gFunctionMap; | 68 static FunctionMap* gFunctionMap; |
69 | 69 |
70 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) | 70 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType) |
71 : m_expectedResult(mediaFeatureResult) {} | 71 : m_mediaType(acceptedMediaType) {} |
72 | |
73 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, | |
74 bool mediaFeatureResult) | |
75 : m_mediaType(acceptedMediaType), m_expectedResult(mediaFeatureResult) {} | |
76 | 72 |
77 MediaQueryEvaluator::MediaQueryEvaluator(LocalFrame* frame) | 73 MediaQueryEvaluator::MediaQueryEvaluator(LocalFrame* frame) |
78 : m_mediaValues(MediaValues::createDynamicIfFrameExists(frame)) {} | 74 : m_mediaValues(MediaValues::createDynamicIfFrameExists(frame)) {} |
79 | 75 |
80 MediaQueryEvaluator::MediaQueryEvaluator(const MediaValues& mediaValues) | 76 MediaQueryEvaluator::MediaQueryEvaluator(const MediaValues& mediaValues) |
81 : m_mediaValues(mediaValues.copy()) {} | 77 : m_mediaValues(mediaValues.copy()) {} |
82 | 78 |
83 MediaQueryEvaluator::MediaQueryEvaluator( | 79 MediaQueryEvaluator::MediaQueryEvaluator( |
84 MediaValuesInitialViewport* mediaValues) | 80 MediaValuesInitialViewport* mediaValues) |
85 : m_mediaValues(mediaValues) { | 81 : m_mediaValues(mediaValues) { |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 // Create the table. | 734 // Create the table. |
739 gFunctionMap = new FunctionMap; | 735 gFunctionMap = new FunctionMap; |
740 #define ADD_TO_FUNCTIONMAP(name) \ | 736 #define ADD_TO_FUNCTIONMAP(name) \ |
741 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); | 737 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); |
742 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); | 738 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); |
743 #undef ADD_TO_FUNCTIONMAP | 739 #undef ADD_TO_FUNCTIONMAP |
744 } | 740 } |
745 | 741 |
746 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const { | 742 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const { |
747 if (!m_mediaValues || !m_mediaValues->hasValues()) | 743 if (!m_mediaValues || !m_mediaValues->hasValues()) |
748 return m_expectedResult; | 744 return true; |
749 | 745 |
750 DCHECK(gFunctionMap); | 746 DCHECK(gFunctionMap); |
751 | 747 |
752 // Call the media feature evaluation function. Assume no prefix and let | 748 // Call the media feature evaluation function. Assume no prefix and let |
753 // trampoline functions override the prefix if prefix is used. | 749 // trampoline functions override the prefix if prefix is used. |
754 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 750 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
755 if (func) | 751 if (func) |
756 return func(expr->expValue(), NoPrefix, *m_mediaValues); | 752 return func(expr->expValue(), NoPrefix, *m_mediaValues); |
757 | 753 |
758 return false; | 754 return false; |
759 } | 755 } |
760 | 756 |
761 } // namespace blink | 757 } // namespace blink |
OLD | NEW |