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