Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp

Issue 2432153005: Always evaluate media features to true without MediaValues. (Closed)
Patch Set: DCHECK(view). Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698