Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "core/dom/NodeComputedStyle.h" | 44 #include "core/dom/NodeComputedStyle.h" |
| 45 #include "core/frame/FrameHost.h" | 45 #include "core/frame/FrameHost.h" |
| 46 #include "core/frame/FrameView.h" | 46 #include "core/frame/FrameView.h" |
| 47 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
| 48 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
| 49 #include "core/frame/UseCounter.h" | 49 #include "core/frame/UseCounter.h" |
| 50 #include "core/inspector/InspectorInstrumentation.h" | 50 #include "core/inspector/InspectorInstrumentation.h" |
| 51 #include "core/style/ComputedStyle.h" | 51 #include "core/style/ComputedStyle.h" |
| 52 #include "platform/RuntimeEnabledFeatures.h" | 52 #include "platform/RuntimeEnabledFeatures.h" |
| 53 #include "platform/geometry/FloatRect.h" | 53 #include "platform/geometry/FloatRect.h" |
| 54 #include "platform/graphics/ColorSpace.h" | |
| 54 #include "public/platform/PointerProperties.h" | 55 #include "public/platform/PointerProperties.h" |
| 55 #include "public/platform/ShapeProperties.h" | 56 #include "public/platform/ShapeProperties.h" |
| 56 #include "public/platform/WebDisplayMode.h" | 57 #include "public/platform/WebDisplayMode.h" |
| 57 #include "wtf/HashMap.h" | 58 #include "wtf/HashMap.h" |
| 58 | 59 |
| 59 namespace blink { | 60 namespace blink { |
| 60 | 61 |
| 61 using namespace MediaFeatureNames; | 62 using namespace MediaFeatureNames; |
| 62 | 63 |
| 63 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; | 64 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 | 747 |
| 747 if (!value.isID) | 748 if (!value.isID) |
| 748 return false; | 749 return false; |
| 749 | 750 |
| 750 // If a platform interface supplies progressive/interlace info for TVs in the | 751 // If a platform interface supplies progressive/interlace info for TVs in the |
| 751 // future, it needs to be handled here. For now, assume a modern TV with | 752 // future, it needs to be handled here. For now, assume a modern TV with |
| 752 // progressive display. | 753 // progressive display. |
| 753 return (value.id == CSSValueProgressive); | 754 return (value.id == CSSValueProgressive); |
| 754 } | 755 } |
| 755 | 756 |
| 757 static bool colorGamutMediaFeatureEval(const MediaQueryExpValue& value, | |
| 758 MediaFeaturePrefix, | |
| 759 const MediaValues& mediaValues) { | |
| 760 // isValid() is false if there is no parameter. Without parameter we should | |
| 761 // return true to indicate that colorGamutMediaFeature is enabled in the | |
| 762 // browser. | |
| 763 if (!value.isValid()) | |
| 764 return true; | |
| 765 | |
| 766 if (!value.isID) | |
| 767 return false; | |
| 768 | |
| 769 DCHECK(value.id == CSSValueSRGB || value.id == CSSValueP3 || | |
| 770 value.id == CSSValueRec2020); | |
| 771 | |
| 772 ColorSpaceGamut gamut = mediaValues.colorGamut(); | |
| 773 switch (gamut) { | |
| 774 case ColorSpaceGamut::Unknown: | |
| 775 case ColorSpaceGamut::LessThanNTSC: | |
| 776 case ColorSpaceGamut::NTSC: | |
| 777 case ColorSpaceGamut::SRGB: | |
| 778 return value.id == CSSValueSRGB; | |
| 779 case ColorSpaceGamut::AlmostP3: | |
| 780 case ColorSpaceGamut::P3: | |
| 781 case ColorSpaceGamut::AdobeRGB: | |
| 782 case ColorSpaceGamut::Wide: | |
| 783 return value.id == CSSValueSRGB || value.id == CSSValueP3; | |
| 784 case ColorSpaceGamut::BT2020: | |
| 785 case ColorSpaceGamut::ProPhoto: | |
| 786 case ColorSpaceGamut::UltraWide: | |
| 787 return value.id == CSSValueSRGB || value.id == CSSValueP3 || | |
| 788 value.id == CSSValueRec2020; | |
| 789 case ColorSpaceGamut::End: | |
|
Yoav Weiss
2017/01/27 12:13:38
Potential nit: Can we use `default:` here and avoi
mlamouri (slow - plz ping)
2017/01/27 16:54:29
I prefer to avoid `default` so if a new value gets
hubbe
2017/01/27 18:19:37
I think it would be easier to just do something li
mlamouri (slow - plz ping)
2017/01/27 18:54:17
That is true but because `value.id` isn't a "restr
| |
| 790 NOTREACHED(); | |
| 791 return false; | |
| 792 } | |
| 793 | |
| 794 return false; | |
| 795 } | |
| 796 | |
| 756 void MediaQueryEvaluator::init() { | 797 void MediaQueryEvaluator::init() { |
| 757 // Create the table. | 798 // Create the table. |
| 758 gFunctionMap = new FunctionMap; | 799 gFunctionMap = new FunctionMap; |
| 759 #define ADD_TO_FUNCTIONMAP(name) \ | 800 #define ADD_TO_FUNCTIONMAP(name) \ |
| 760 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); | 801 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); |
| 761 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); | 802 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); |
| 762 #undef ADD_TO_FUNCTIONMAP | 803 #undef ADD_TO_FUNCTIONMAP |
| 763 } | 804 } |
| 764 | 805 |
| 765 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const { | 806 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const { |
| 766 if (!m_mediaValues || !m_mediaValues->hasValues()) | 807 if (!m_mediaValues || !m_mediaValues->hasValues()) |
| 767 return true; | 808 return true; |
| 768 | 809 |
| 769 DCHECK(gFunctionMap); | 810 DCHECK(gFunctionMap); |
| 770 | 811 |
| 771 // Call the media feature evaluation function. Assume no prefix and let | 812 // Call the media feature evaluation function. Assume no prefix and let |
| 772 // trampoline functions override the prefix if prefix is used. | 813 // trampoline functions override the prefix if prefix is used. |
| 773 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 814 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
| 774 if (func) | 815 if (func) |
| 775 return func(expr->expValue(), NoPrefix, *m_mediaValues); | 816 return func(expr->expValue(), NoPrefix, *m_mediaValues); |
| 776 | 817 |
| 777 return false; | 818 return false; |
| 778 } | 819 } |
| 779 | 820 |
| 780 } // namespace blink | 821 } // namespace blink |
| OLD | NEW |