OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 // logic is the same. The goal is to compute the best scroll offset | 654 // logic is the same. The goal is to compute the best scroll offset |
655 // in order to make an object visible within a viewport. | 655 // in order to make an object visible within a viewport. |
656 // | 656 // |
657 // In case the whole object cannot fit, you can specify a | 657 // In case the whole object cannot fit, you can specify a |
658 // subfocus - a smaller region within the object that should | 658 // subfocus - a smaller region within the object that should |
659 // be prioritized. If the whole object can fit, the subfocus is | 659 // be prioritized. If the whole object can fit, the subfocus is |
660 // ignored. | 660 // ignored. |
661 // | 661 // |
662 // Example: the viewport is scrolled to the right just enough | 662 // Example: the viewport is scrolled to the right just enough |
663 // that the object is in view. | 663 // that the object is in view. |
664 // Before: | 664 // Before: |
aboxhall
2014/10/17 19:30:09
Is this description/ascii art still accurate?
dmazzoni
2014/10/17 19:41:35
Oh - it didn't mention centering. Updated.
| |
665 // +----------Viewport---------+ | 665 // +----------Viewport---------+ |
666 // +---Object---+ | 666 // +---Object---+ |
667 // +--SubFocus--+ | 667 // +--SubFocus--+ |
668 // | 668 // |
669 // After: | 669 // After: |
670 // +----------Viewport---------+ | 670 // +----------Viewport---------+ |
671 // +---Object---+ | 671 // +---Object---+ |
672 // +--SubFocus--+ | 672 // +--SubFocus--+ |
673 // | 673 // |
674 // When constraints cannot be fully satisfied, the min | 674 // When constraints cannot be fully satisfied, the min |
675 // (left/top) position takes precedence over the max (right/bottom). | 675 // (left/top) position takes precedence over the max (right/bottom). |
676 // | 676 // |
677 // Note that the return value represents the ideal new scroll offset. | 677 // Note that the return value represents the ideal new scroll offset. |
678 // This may be out of range - the calling function should clip this | 678 // This may be out of range - the calling function should clip this |
679 // to the available range. | 679 // to the available range. |
680 static int computeBestScrollOffset(int currentScrollOffset, int subfocusMin, int subfocusMax, int objectMin, int objectMax, int viewportMin, int viewportMax) | 680 static int computeBestScrollOffset(int currentScrollOffset, int subfocusMin, int subfocusMax, int objectMin, int objectMax, int viewportMin, int viewportMax) |
681 { | 681 { |
682 int viewportSize = viewportMax - viewportMin; | 682 int viewportSize = viewportMax - viewportMin; |
683 | 683 |
684 // If the focus size is larger than the viewport size, shrink it in the | 684 // If the object size is larger than the viewport size, shrink it in the |
aboxhall
2014/10/17 19:30:09
I think 'shrink it' is a little confusing - my rea
dmazzoni
2014/10/17 19:41:35
Done.
| |
685 // direction of subfocus. | 685 // direction of subfocus. |
686 if (objectMax - objectMin > viewportSize) { | 686 if (objectMax - objectMin > viewportSize) { |
687 // Subfocus must be within focus: | 687 // Subfocus must be within focus: |
688 subfocusMin = std::max(subfocusMin, objectMin); | 688 subfocusMin = std::max(subfocusMin, objectMin); |
689 subfocusMax = std::min(subfocusMax, objectMax); | 689 subfocusMax = std::min(subfocusMax, objectMax); |
690 | 690 |
691 // Subfocus must be no larger than the viewport size; favor top/left. | 691 // Subfocus must be no larger than the viewport size; favor top/left. |
692 if (subfocusMax - subfocusMin > viewportSize) | 692 if (subfocusMax - subfocusMin > viewportSize) |
693 subfocusMax = subfocusMin + viewportSize; | 693 subfocusMax = subfocusMin + viewportSize; |
694 | 694 |
695 if (subfocusMin + viewportSize > objectMax) { | 695 // Compute the size of an object centered on the subfocus, the size of t he viewport. |
aboxhall
2014/10/17 19:30:09
Why do we want to centre it rather than keeping it
dmazzoni
2014/10/17 19:41:35
I mentioned this in the change description - does
| |
696 objectMin = objectMax - viewportSize; | 696 int centeredObjectMin = (subfocusMin + subfocusMax - viewportSize) / 2; |
697 } else { | 697 int centeredObjectMax = centeredObjectMin + viewportSize; |
698 objectMin = subfocusMin; | 698 |
699 objectMax = subfocusMin + viewportSize; | 699 objectMin = std::max(objectMin, centeredObjectMin); |
700 } | 700 objectMax = std::min(objectMax, centeredObjectMax); |
701 } | 701 } |
702 | 702 |
703 // Exit now if the focus is already within the viewport. | 703 // Exit now if the focus is already within the viewport. |
704 if (objectMin - currentScrollOffset >= viewportMin | 704 if (objectMin - currentScrollOffset >= viewportMin |
705 && objectMax - currentScrollOffset <= viewportMax) | 705 && objectMax - currentScrollOffset <= viewportMax) |
706 return currentScrollOffset; | 706 return currentScrollOffset; |
707 | 707 |
708 // Scroll left if we're too far to the right. | 708 // Center the object in the viewport. |
709 if (objectMax - currentScrollOffset > viewportMax) | 709 return (objectMin + objectMax - viewportMin - viewportMax) / 2; |
710 return objectMax - viewportMax; | |
711 | |
712 // Scroll right if we're too far to the left. | |
713 if (objectMin - currentScrollOffset < viewportMin) | |
714 return objectMin - viewportMin; | |
715 | |
716 ASSERT_NOT_REACHED(); | |
717 | |
718 // This shouldn't happen. | |
719 return currentScrollOffset; | |
720 } | 710 } |
721 | 711 |
722 void AXObject::scrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const | 712 void AXObject::scrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const |
723 { | 713 { |
724 // Search up the parent chain until we find the first one that's scrollable. | 714 // Search up the parent chain until we find the first one that's scrollable. |
725 AXObject* scrollParent = parentObject(); | 715 AXObject* scrollParent = parentObject(); |
726 ScrollableArea* scrollableArea = 0; | 716 ScrollableArea* scrollableArea = 0; |
727 while (scrollParent) { | 717 while (scrollParent) { |
728 scrollableArea = scrollParent->getScrollableAreaIfScrollable(); | 718 scrollableArea = scrollParent->getScrollableAreaIfScrollable(); |
729 if (scrollableArea) | 719 if (scrollableArea) |
(...skipping 13 matching lines...) Expand all Loading... | |
743 objectRect.x(), objectRect.maxX(), | 733 objectRect.x(), objectRect.maxX(), |
744 0, scrollVisibleRect.width()); | 734 0, scrollVisibleRect.width()); |
745 int desiredY = computeBestScrollOffset( | 735 int desiredY = computeBestScrollOffset( |
746 scrollPosition.y(), | 736 scrollPosition.y(), |
747 objectRect.y() + subfocus.y(), objectRect.y() + subfocus.maxY(), | 737 objectRect.y() + subfocus.y(), objectRect.y() + subfocus.maxY(), |
748 objectRect.y(), objectRect.maxY(), | 738 objectRect.y(), objectRect.maxY(), |
749 0, scrollVisibleRect.height()); | 739 0, scrollVisibleRect.height()); |
750 | 740 |
751 scrollParent->scrollTo(IntPoint(desiredX, desiredY)); | 741 scrollParent->scrollTo(IntPoint(desiredX, desiredY)); |
752 | 742 |
743 // Convert the subfocus into the coordinates of the scroll parent. | |
744 IntRect newSubfocus = subfocus; | |
745 IntRect newElementRect = pixelSnappedIntRect(elementRect()); | |
746 IntRect scrollParentRect = pixelSnappedIntRect(scrollParent->elementRect()); | |
747 newSubfocus.move(newElementRect.x(), newElementRect.y()); | |
748 newSubfocus.move(-scrollParentRect.x(), -scrollParentRect.y()); | |
749 | |
753 // Recursively make sure the scroll parent itself is visible. | 750 // Recursively make sure the scroll parent itself is visible. |
754 if (scrollParent->parentObject()) | 751 if (scrollParent->parentObject()) |
755 scrollParent->scrollToMakeVisible(); | 752 scrollParent->scrollToMakeVisibleWithSubFocus(newSubfocus); |
756 } | 753 } |
757 | 754 |
758 void AXObject::scrollToGlobalPoint(const IntPoint& globalPoint) const | 755 void AXObject::scrollToGlobalPoint(const IntPoint& globalPoint) const |
759 { | 756 { |
760 // Search up the parent chain and create a vector of all scrollable parent o bjects | 757 // Search up the parent chain and create a vector of all scrollable parent o bjects |
761 // and ending with this object itself. | 758 // and ending with this object itself. |
762 Vector<const AXObject*> objects; | 759 Vector<const AXObject*> objects; |
763 AXObject* parentObject; | 760 AXObject* parentObject; |
764 for (parentObject = this->parentObject(); parentObject; parentObject = paren tObject->parentObject()) { | 761 for (parentObject = this->parentObject(); parentObject; parentObject = paren tObject->parentObject()) { |
765 if (parentObject->getScrollableAreaIfScrollable()) | 762 if (parentObject->getScrollableAreaIfScrollable()) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 return ToggleButtonRole; | 893 return ToggleButtonRole; |
897 if (ariaHasPopup()) | 894 if (ariaHasPopup()) |
898 return PopUpButtonRole; | 895 return PopUpButtonRole; |
899 // We don't contemplate RadioButtonRole, as it depends on the input | 896 // We don't contemplate RadioButtonRole, as it depends on the input |
900 // type. | 897 // type. |
901 | 898 |
902 return ButtonRole; | 899 return ButtonRole; |
903 } | 900 } |
904 | 901 |
905 } // namespace blink | 902 } // namespace blink |
OLD | NEW |