OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... | |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "core/page/scrolling/ScrollingCoordinator.h" | 28 #include "core/page/scrolling/ScrollingCoordinator.h" |
29 | 29 |
30 #include "RuntimeEnabledFeatures.h" | 30 #include "RuntimeEnabledFeatures.h" |
31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
32 #include "core/dom/EventHandlerRegistry.h" | |
32 #include "core/dom/FullscreenElementStack.h" | 33 #include "core/dom/FullscreenElementStack.h" |
33 #include "core/dom/Node.h" | 34 #include "core/dom/Node.h" |
34 #include "core/dom/WheelController.h" | 35 #include "core/frame/DOMWindow.h" |
35 #include "core/html/HTMLElement.h" | |
36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
39 #include "core/html/HTMLElement.h" | |
39 #include "core/page/Page.h" | 40 #include "core/page/Page.h" |
40 #include "core/plugins/PluginView.h" | 41 #include "core/plugins/PluginView.h" |
41 #include "core/rendering/RenderGeometryMap.h" | 42 #include "core/rendering/RenderGeometryMap.h" |
42 #include "core/rendering/RenderView.h" | 43 #include "core/rendering/RenderView.h" |
43 #include "core/rendering/compositing/CompositedLayerMapping.h" | 44 #include "core/rendering/compositing/CompositedLayerMapping.h" |
44 #include "core/rendering/compositing/RenderLayerCompositor.h" | 45 #include "core/rendering/compositing/RenderLayerCompositor.h" |
45 #include "platform/TraceEvent.h" | 46 #include "platform/TraceEvent.h" |
46 #include "platform/exported/WebScrollbarImpl.h" | 47 #include "platform/exported/WebScrollbarImpl.h" |
47 #include "platform/exported/WebScrollbarThemeGeometryNative.h" | 48 #include "platform/exported/WebScrollbarThemeGeometryNative.h" |
48 #include "platform/geometry/Region.h" | 49 #include "platform/geometry/Region.h" |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 { | 625 { |
625 m_layersWithTouchRects.remove(layer); | 626 m_layersWithTouchRects.remove(layer); |
626 } | 627 } |
627 | 628 |
628 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) | 629 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) |
629 { | 630 { |
630 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) | 631 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) |
631 scrollLayer->setHaveWheelEventHandlers(count > 0); | 632 scrollLayer->setHaveWheelEventHandlers(count > 0); |
632 } | 633 } |
633 | 634 |
634 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView *) | 635 void ScrollingCoordinator::setScrollEventHandlerCount(unsigned count) |
635 { | 636 { |
636 setWheelEventHandlerCount(computeCurrentWheelEventHandlerCount()); | 637 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) |
638 scrollLayer->setHaveScrollEventHandlers(count > 0); | |
639 } | |
640 | |
641 void ScrollingCoordinator::updateWheelEventHandlerCountForFrameView(FrameView*) | |
642 { | |
643 LocalFrame* frame = m_page->mainFrame(); | |
644 unsigned count = EventHandlerRegistry::from(*frame->document())->eventHandle rCount(EventHandlerRegistry::WheelEvent); | |
645 setWheelEventHandlerCount(count); | |
646 } | |
647 | |
648 void ScrollingCoordinator::updateScrollEventHandlerCountForFrameView(FrameView*) | |
649 { | |
650 LocalFrame* frame = m_page->mainFrame(); | |
651 unsigned count = EventHandlerRegistry::from(*frame->document())->eventHandle rCount(EventHandlerRegistry::ScrollEvent); | |
Rick Byers
2014/03/27 16:43:31
why all this work with 'counts' when this function
Sami
2014/04/02 19:58:05
Yeah, the more I looked at this the more obvious i
| |
652 setScrollEventHandlerCount(count); | |
637 } | 653 } |
638 | 654 |
639 void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainTh readScrollingReasons reasons) | 655 void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainTh readScrollingReasons reasons) |
640 { | 656 { |
641 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { | 657 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { |
642 m_lastMainThreadScrollingReasons = reasons; | 658 m_lastMainThreadScrollingReasons = reasons; |
643 scrollLayer->setShouldScrollOnMainThread(reasons); | 659 scrollLayer->setShouldScrollOnMainThread(reasons); |
644 } | 660 } |
645 } | 661 } |
646 | 662 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 } | 729 } |
714 } | 730 } |
715 | 731 |
716 const FrameTree& tree = frame->tree(); | 732 const FrameTree& tree = frame->tree(); |
717 for (LocalFrame* subFrame = tree.firstChild(); subFrame; subFrame = subFrame ->tree().nextSibling()) | 733 for (LocalFrame* subFrame = tree.firstChild(); subFrame; subFrame = subFrame ->tree().nextSibling()) |
718 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); | 734 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); |
719 | 735 |
720 return shouldHandleScrollGestureOnMainThreadRegion; | 736 return shouldHandleScrollGestureOnMainThreadRegion; |
721 } | 737 } |
722 | 738 |
723 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, co nst Document* document) | 739 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, Do cument* document) |
724 { | 740 { |
725 ASSERT(document); | 741 ASSERT(document); |
726 if (!document->touchEventTargets()) | 742 const EventTargetSet* targets = EventHandlerRegistry::from(*document)->event HandlerTargets(EventHandlerRegistry::TouchEvent); |
743 if (!targets) | |
727 return; | 744 return; |
728 | 745 |
729 const TouchEventTargetSet* targets = document->touchEventTargets(); | 746 // If there's a handler on the window, document, html or body element (fairl y common in practice), |
730 | |
731 // If there's a handler on the document, html or body element (fairly common in practice), | |
732 // then we can quickly mark the entire document and skip looking at any othe r handlers. | 747 // then we can quickly mark the entire document and skip looking at any othe r handlers. |
733 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's | 748 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's |
734 // reasonable to be conservative and report the whole document anyway. | 749 // reasonable to be conservative and report the whole document anyway. |
735 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { | 750 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets ->end(); ++iter) { |
736 Node* target = iter->key; | 751 EventTarget* target = iter->key; |
737 if (target == document || target == document->documentElement() || targe t == document->body()) { | 752 Node* node = target->toNode(); |
753 if (target->toDOMWindow() || node == document || node == document->docum entElement() || node == document->body()) { | |
738 if (RenderObject* renderer = document->renderer()) { | 754 if (RenderObject* renderer = document->renderer()) { |
739 renderer->computeLayerHitTestRects(rects); | 755 renderer->computeLayerHitTestRects(rects); |
740 } | 756 } |
741 return; | 757 return; |
742 } | 758 } |
743 } | 759 } |
744 | 760 |
745 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { | 761 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets ->end(); ++iter) { |
746 const Node* target = iter->key; | 762 EventTarget* target = iter->key; |
747 if (!target->inDocument()) | 763 Node* node = target->toDOMWindow() ? target->toDOMWindow()->document() : target->toNode(); |
Rick Byers
2014/03/27 16:43:31
Would be simpler to just combine this with the "if
Sami
2014/04/02 19:58:05
Done.
| |
764 if (!node->inDocument()) | |
748 continue; | 765 continue; |
749 | 766 |
750 if (target->isDocumentNode()) { | 767 if (node->isDocumentNode()) { |
751 ASSERT(target != document); | 768 ASSERT(node != document); |
752 accumulateDocumentTouchEventTargetRects(rects, toDocument(target)); | 769 accumulateDocumentTouchEventTargetRects(rects, toDocument(node)); |
753 } else if (RenderObject* renderer = target->renderer()) { | 770 } else if (RenderObject* renderer = node->renderer()) { |
754 // If the set also contains one of our ancestor nodes then processin g | 771 // If the set also contains one of our ancestor nodes then processin g |
755 // this node would be redundant. | 772 // this node would be redundant. |
756 bool hasTouchEventTargetAncestor = false; | 773 bool hasTouchEventTargetAncestor = false; |
757 for (Node* ancestor = target->parentNode(); ancestor && !hasTouchEve ntTargetAncestor; ancestor = ancestor->parentNode()) { | 774 for (Node* ancestor = node->parentNode(); ancestor && !hasTouchEvent TargetAncestor; ancestor = ancestor->parentNode()) { |
758 if (targets->contains(ancestor)) | 775 if (targets->contains(ancestor)) |
759 hasTouchEventTargetAncestor = true; | 776 hasTouchEventTargetAncestor = true; |
760 } | 777 } |
761 if (!hasTouchEventTargetAncestor) { | 778 if (!hasTouchEventTargetAncestor) { |
762 // Walk up the tree to the outermost non-composited scrollable l ayer. | 779 // Walk up the tree to the outermost non-composited scrollable l ayer. |
763 RenderLayer* enclosingNonCompositedScrollLayer = 0; | 780 RenderLayer* enclosingNonCompositedScrollLayer = 0; |
764 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) { | 781 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) { |
765 if (parent->scrollsOverflow()) | 782 if (parent->scrollsOverflow()) |
766 enclosingNonCompositedScrollLayer = parent; | 783 enclosingNonCompositedScrollLayer = parent; |
767 } | 784 } |
(...skipping 18 matching lines...) Expand all Loading... | |
786 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); | 803 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); |
787 ASSERT(touchHitTestingEnabled()); | 804 ASSERT(touchHitTestingEnabled()); |
788 | 805 |
789 Document* document = m_page->mainFrame()->document(); | 806 Document* document = m_page->mainFrame()->document(); |
790 if (!document || !document->view()) | 807 if (!document || !document->view()) |
791 return; | 808 return; |
792 | 809 |
793 accumulateDocumentTouchEventTargetRects(rects, document); | 810 accumulateDocumentTouchEventTargetRects(rects, document); |
794 } | 811 } |
795 | 812 |
796 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() | |
797 { | |
798 unsigned wheelEventHandlerCount = 0; | |
799 | |
800 for (LocalFrame* frame = m_page->mainFrame(); frame; frame = frame->tree().t raverseNext()) { | |
801 if (frame->document()) | |
802 wheelEventHandlerCount += WheelController::from(*frame->document())- >wheelEventHandlerCount(); | |
803 } | |
804 | |
805 return wheelEventHandlerCount; | |
806 } | |
807 | |
808 void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* fra meView) | 813 void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* fra meView) |
809 { | 814 { |
810 ASSERT(isMainThread()); | 815 ASSERT(isMainThread()); |
811 ASSERT(m_page); | 816 ASSERT(m_page); |
812 | 817 |
813 recomputeWheelEventHandlerCountForFrameView(frameView); | 818 updateWheelEventHandlerCountForFrameView(frameView); |
819 } | |
820 | |
821 void ScrollingCoordinator::frameViewScrollEventHandlerCountChanged(FrameView* fr ameView) | |
822 { | |
823 ASSERT(isMainThread()); | |
824 ASSERT(m_page); | |
825 | |
826 updateScrollEventHandlerCountForFrameView(frameView); | |
814 } | 827 } |
815 | 828 |
816 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView) | 829 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView) |
817 { | 830 { |
818 ASSERT(isMainThread()); | 831 ASSERT(isMainThread()); |
819 ASSERT(m_page); | 832 ASSERT(m_page); |
820 | 833 |
821 if (!coordinatesScrollingForFrameView(frameView)) | 834 if (!coordinatesScrollingForFrameView(frameView)) |
822 return; | 835 return; |
823 | 836 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 | 868 |
856 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) | 869 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) |
857 { | 870 { |
858 ASSERT(isMainThread()); | 871 ASSERT(isMainThread()); |
859 ASSERT(m_page); | 872 ASSERT(m_page); |
860 | 873 |
861 if (!coordinatesScrollingForFrameView(frameView)) | 874 if (!coordinatesScrollingForFrameView(frameView)) |
862 return; | 875 return; |
863 | 876 |
864 notifyLayoutUpdated(); | 877 notifyLayoutUpdated(); |
865 recomputeWheelEventHandlerCountForFrameView(frameView); | 878 updateWheelEventHandlerCountForFrameView(frameView); |
879 updateScrollEventHandlerCountForFrameView(frameView); | |
866 } | 880 } |
867 | 881 |
868 #if OS(MACOSX) | 882 #if OS(MACOSX) |
869 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase) | 883 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase) |
870 { | 884 { |
871 ASSERT(isMainThread()); | 885 ASSERT(isMainThread()); |
872 | 886 |
873 if (!m_page) | 887 if (!m_page) |
874 return; | 888 return; |
875 | 889 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 bool frameIsScrollable = frameView && frameView->isScrollable(); | 965 bool frameIsScrollable = frameView && frameView->isScrollable(); |
952 if (frameIsScrollable != m_wasFrameScrollable) | 966 if (frameIsScrollable != m_wasFrameScrollable) |
953 return true; | 967 return true; |
954 | 968 |
955 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0) | 969 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0) |
956 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( ); | 970 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( ); |
957 return false; | 971 return false; |
958 } | 972 } |
959 | 973 |
960 } // namespace WebCore | 974 } // namespace WebCore |
OLD | NEW |