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 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 break; | 690 break; |
691 default: | 691 default: |
692 result = false; | 692 result = false; |
693 break; | 693 break; |
694 } | 694 } |
695 | 695 |
696 return result; | 696 return result; |
697 } | 697 } |
698 #endif // ENABLE(VIEW_MODE_CSS_MEDIA) | 698 #endif // ENABLE(VIEW_MODE_CSS_MEDIA) |
699 | 699 |
700 enum PointerDeviceType { TouchPointer, MousePointer, NoPointer, UnknownPointer }
; | |
701 | |
702 static PointerDeviceType leastCapablePrimaryPointerDeviceType(Frame* frame) | |
703 { | |
704 if (frame->settings()->deviceSupportsTouch()) | |
705 return TouchPointer; | |
706 | |
707 // FIXME: We should also try to determine if we know we have a mouse. | |
708 // When we do this, we'll also need to differentiate between known not to | |
709 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer). | |
710 // We could also take into account other preferences like accessibility | |
711 // settings to decide which of the available pointers should be considered | |
712 // "primary". | |
713 | |
714 return UnknownPointer; | |
715 } | |
716 | |
717 static bool hoverMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, M
ediaFeaturePrefix) | 700 static bool hoverMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, M
ediaFeaturePrefix) |
718 { | 701 { |
719 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame); | 702 int pointer = frame->settings()->primaryPointerDevices(); |
720 | 703 |
721 // If we're on a port that hasn't explicitly opted into providing pointer de
vice information | 704 // If we're on a port that hasn't explicitly opted into providing pointer de
vice information |
722 // (or otherwise can't be confident in the pointer hardware available), then
behave exactly | 705 // (or otherwise can't be confident in the pointer hardware available), then
behave exactly |
723 // as if this feature feature isn't supported. | 706 // as if this feature feature isn't supported. |
724 if (pointer == UnknownPointer) | 707 if (pointer == PointerDeviceUnknown) |
725 return false; | 708 return false; |
726 | 709 |
727 float number = 1; | 710 float number = 1; |
728 if (value) { | 711 if (value) { |
729 if (!numberValue(value, number)) | 712 if (!numberValue(value, number)) |
730 return false; | 713 return false; |
731 } | 714 } |
732 | 715 |
733 return (pointer == NoPointer && !number) | 716 if (pointer & (PointerDeviceTouch | PointerDeviceNone)) |
734 || (pointer == TouchPointer && !number) | 717 return !number; |
735 || (pointer == MousePointer && number == 1); | 718 else if (pointer & PointerDeviceMouse) |
| 719 return number == 1; |
| 720 else |
| 721 return false; |
736 } | 722 } |
737 | 723 |
738 static bool pointerMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame,
MediaFeaturePrefix) | 724 static bool pointerMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame,
MediaFeaturePrefix) |
739 { | 725 { |
740 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame); | 726 int pointer = frame->settings()->primaryPointerDevices(); |
741 | 727 |
742 // If we're on a port that hasn't explicitly opted into providing pointer de
vice information | 728 // If we're on a port that hasn't explicitly opted into providing pointer de
vice information |
743 // (or otherwise can't be confident in the pointer hardware available), then
behave exactly | 729 // (or otherwise can't be confident in the pointer hardware available), then
behave exactly |
744 // as if this feature feature isn't supported. | 730 // as if this feature feature isn't supported. |
745 if (pointer == UnknownPointer) | 731 if (pointer == PointerDeviceUnknown) |
746 return false; | 732 return false; |
747 | 733 |
748 if (!value) | 734 if (!value) |
749 return pointer != NoPointer; | 735 return !(pointer & PointerDeviceNone); |
750 | 736 |
751 if (!value->isPrimitiveValue()) | 737 if (!value->isPrimitiveValue()) |
752 return false; | 738 return false; |
753 | 739 |
754 const int id = static_cast<CSSPrimitiveValue*>(value)->getIdent(); | 740 const int id = static_cast<CSSPrimitiveValue*>(value)->getIdent(); |
755 return (pointer == NoPointer && id == CSSValueNone) | 741 |
756 || (pointer == TouchPointer && id == CSSValueCoarse) | 742 if (pointer & PointerDeviceNone) |
757 || (pointer == MousePointer && id == CSSValueFine); | 743 return id == CSSValueNone; |
| 744 else if (pointer & PointerDeviceTouch) |
| 745 return id == CSSValueCoarse; |
| 746 else if (pointer & PointerDeviceMouse) |
| 747 return id == CSSValueFine; |
| 748 else |
| 749 return false; |
758 } | 750 } |
759 | 751 |
760 static void createFunctionMap() | 752 static void createFunctionMap() |
761 { | 753 { |
762 // Create the table. | 754 // Create the table. |
763 gFunctionMap = new FunctionMap; | 755 gFunctionMap = new FunctionMap; |
764 #define ADD_TO_FUNCTIONMAP(name, str) \ | 756 #define ADD_TO_FUNCTIONMAP(name, str) \ |
765 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); | 757 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); |
766 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); | 758 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); |
767 #undef ADD_TO_FUNCTIONMAP | 759 #undef ADD_TO_FUNCTIONMAP |
(...skipping 14 matching lines...) Expand all Loading... |
782 // and let trampoline functions override the prefix if prefix is | 774 // and let trampoline functions override the prefix if prefix is |
783 // used | 775 // used |
784 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 776 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
785 if (func) | 777 if (func) |
786 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 778 return func(expr->value(), m_style.get(), m_frame, NoPrefix); |
787 | 779 |
788 return false; | 780 return false; |
789 } | 781 } |
790 | 782 |
791 } // namespace | 783 } // namespace |
OLD | NEW |