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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 clipParentWebLayer = toWebLayer(parent->compositedLayerMapping()->parent ForSublayers()); | 624 clipParentWebLayer = toWebLayer(parent->compositedLayerMapping()->parent ForSublayers()); |
624 | 625 |
625 child->setClipParent(clipParentWebLayer); | 626 child->setClipParent(clipParentWebLayer); |
626 } | 627 } |
627 | 628 |
628 void ScrollingCoordinator::willDestroyRenderLayer(RenderLayer* layer) | 629 void ScrollingCoordinator::willDestroyRenderLayer(RenderLayer* layer) |
629 { | 630 { |
630 m_layersWithTouchRects.remove(layer); | 631 m_layersWithTouchRects.remove(layer); |
631 } | 632 } |
632 | 633 |
633 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) | 634 void ScrollingCoordinator::updateHaveWheelEventHandlers() |
634 { | 635 { |
635 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) | 636 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { |
636 scrollLayer->setHaveWheelEventHandlers(count > 0); | 637 LocalFrame* frame = m_page->mainFrame(); |
638 bool haveHandlers = EventHandlerRegistry::from(*frame->document())->hasE ventHandlers(EventHandlerRegistry::WheelEvent); | |
639 scrollLayer->setHaveWheelEventHandlers(haveHandlers); | |
640 } | |
637 } | 641 } |
638 | 642 |
639 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView *) | 643 void ScrollingCoordinator::updateHaveScrollEventHandlers() |
640 { | 644 { |
641 setWheelEventHandlerCount(computeCurrentWheelEventHandlerCount()); | 645 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { |
646 LocalFrame* frame = m_page->mainFrame(); | |
647 bool haveHandlers = EventHandlerRegistry::from(*frame->document())->hasE ventHandlers(EventHandlerRegistry::ScrollEvent); | |
648 scrollLayer->setHaveScrollEventHandlers(haveHandlers); | |
649 } | |
642 } | 650 } |
643 | 651 |
644 void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainTh readScrollingReasons reasons) | 652 void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainTh readScrollingReasons reasons) |
645 { | 653 { |
646 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { | 654 if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerFor Scrolling())) { |
647 m_lastMainThreadScrollingReasons = reasons; | 655 m_lastMainThreadScrollingReasons = reasons; |
648 scrollLayer->setShouldScrollOnMainThread(reasons); | 656 scrollLayer->setShouldScrollOnMainThread(reasons); |
649 } | 657 } |
650 } | 658 } |
651 | 659 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 } | 726 } |
719 } | 727 } |
720 | 728 |
721 const FrameTree& tree = frame->tree(); | 729 const FrameTree& tree = frame->tree(); |
722 for (LocalFrame* subFrame = tree.firstChild(); subFrame; subFrame = subFrame ->tree().nextSibling()) | 730 for (LocalFrame* subFrame = tree.firstChild(); subFrame; subFrame = subFrame ->tree().nextSibling()) |
723 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); | 731 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); |
724 | 732 |
725 return shouldHandleScrollGestureOnMainThreadRegion; | 733 return shouldHandleScrollGestureOnMainThreadRegion; |
726 } | 734 } |
727 | 735 |
728 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, co nst Document* document) | 736 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, Do cument* document) |
729 { | 737 { |
730 ASSERT(document); | 738 ASSERT(document); |
731 if (!document->touchEventTargets()) | 739 const EventTargetSet* targets = EventHandlerRegistry::from(*document)->event HandlerTargets(EventHandlerRegistry::TouchEvent); |
740 if (!targets) | |
732 return; | 741 return; |
733 | 742 |
734 const TouchEventTargetSet* targets = document->touchEventTargets(); | 743 // If there's a handler on the window, document, html or body element (fairl y common in practice), |
735 | |
736 // If there's a handler on the document, html or body element (fairly common in practice), | |
737 // then we can quickly mark the entire document and skip looking at any othe r handlers. | 744 // then we can quickly mark the entire document and skip looking at any othe r handlers. |
738 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's | 745 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's |
739 // reasonable to be conservative and report the whole document anyway. | 746 // reasonable to be conservative and report the whole document anyway. |
740 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { | 747 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets ->end(); ++iter) { |
741 Node* target = iter->key; | 748 EventTarget* target = iter->key; |
742 if (target == document || target == document->documentElement() || targe t == document->body()) { | 749 Node* node = target->toNode(); |
750 if (target->toDOMWindow() || node == document || node == document->docum entElement() || node == document->body()) { | |
743 if (RenderObject* renderer = document->renderer()) { | 751 if (RenderObject* renderer = document->renderer()) { |
744 renderer->computeLayerHitTestRects(rects); | 752 renderer->computeLayerHitTestRects(rects); |
745 } | 753 } |
746 return; | 754 return; |
747 } | 755 } |
748 } | 756 } |
749 | 757 |
750 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { | 758 for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets ->end(); ++iter) { |
751 const Node* target = iter->key; | 759 EventTarget* target = iter->key; |
752 if (!target->inDocument()) | 760 if (DOMWindow* window = target->toDOMWindow()) { |
Rick Byers
2014/04/03 15:33:19
Sorry I should have pointed out earlier - this can
| |
761 accumulateDocumentTouchEventTargetRects(rects, window->document()); | |
762 continue; | |
763 } | |
764 Node* node = target->toNode(); | |
765 if (!node->inDocument()) | |
753 continue; | 766 continue; |
754 | 767 |
755 if (target->isDocumentNode()) { | 768 if (node->isDocumentNode()) { |
756 ASSERT(target != document); | 769 ASSERT(node != document); |
757 accumulateDocumentTouchEventTargetRects(rects, toDocument(target)); | 770 accumulateDocumentTouchEventTargetRects(rects, toDocument(node)); |
758 } else if (RenderObject* renderer = target->renderer()) { | 771 } else if (RenderObject* renderer = node->renderer()) { |
759 // If the set also contains one of our ancestor nodes then processin g | 772 // If the set also contains one of our ancestor nodes then processin g |
760 // this node would be redundant. | 773 // this node would be redundant. |
761 bool hasTouchEventTargetAncestor = false; | 774 bool hasTouchEventTargetAncestor = false; |
762 for (Node* ancestor = target->parentNode(); ancestor && !hasTouchEve ntTargetAncestor; ancestor = ancestor->parentNode()) { | 775 for (Node* ancestor = node->parentNode(); ancestor && !hasTouchEvent TargetAncestor; ancestor = ancestor->parentNode()) { |
763 if (targets->contains(ancestor)) | 776 if (targets->contains(ancestor)) |
764 hasTouchEventTargetAncestor = true; | 777 hasTouchEventTargetAncestor = true; |
765 } | 778 } |
766 if (!hasTouchEventTargetAncestor) { | 779 if (!hasTouchEventTargetAncestor) { |
767 // Walk up the tree to the outermost non-composited scrollable l ayer. | 780 // Walk up the tree to the outermost non-composited scrollable l ayer. |
768 RenderLayer* enclosingNonCompositedScrollLayer = 0; | 781 RenderLayer* enclosingNonCompositedScrollLayer = 0; |
769 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) { | 782 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) { |
770 if (parent->scrollsOverflow()) | 783 if (parent->scrollsOverflow()) |
771 enclosingNonCompositedScrollLayer = parent; | 784 enclosingNonCompositedScrollLayer = parent; |
772 } | 785 } |
(...skipping 18 matching lines...) Expand all Loading... | |
791 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); | 804 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); |
792 ASSERT(touchHitTestingEnabled()); | 805 ASSERT(touchHitTestingEnabled()); |
793 | 806 |
794 Document* document = m_page->mainFrame()->document(); | 807 Document* document = m_page->mainFrame()->document(); |
795 if (!document || !document->view()) | 808 if (!document || !document->view()) |
796 return; | 809 return; |
797 | 810 |
798 accumulateDocumentTouchEventTargetRects(rects, document); | 811 accumulateDocumentTouchEventTargetRects(rects, document); |
799 } | 812 } |
800 | 813 |
801 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() | 814 void ScrollingCoordinator::haveWheelEventHandlersChangedForPage() |
802 { | |
803 unsigned wheelEventHandlerCount = 0; | |
804 | |
805 for (LocalFrame* frame = m_page->mainFrame(); frame; frame = frame->tree().t raverseNext()) { | |
806 if (frame->document()) | |
807 wheelEventHandlerCount += WheelController::from(*frame->document())- >wheelEventHandlerCount(); | |
808 } | |
809 | |
810 return wheelEventHandlerCount; | |
811 } | |
812 | |
813 void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* fra meView) | |
814 { | 815 { |
815 ASSERT(isMainThread()); | 816 ASSERT(isMainThread()); |
816 ASSERT(m_page); | 817 ASSERT(m_page); |
817 | 818 |
818 recomputeWheelEventHandlerCountForFrameView(frameView); | 819 updateHaveWheelEventHandlers(); |
820 } | |
821 | |
822 void ScrollingCoordinator::haveScrollEventHandlersChangedForPage() | |
823 { | |
824 ASSERT(isMainThread()); | |
825 ASSERT(m_page); | |
826 | |
827 updateHaveScrollEventHandlers(); | |
819 } | 828 } |
820 | 829 |
821 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView) | 830 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView) |
822 { | 831 { |
823 ASSERT(isMainThread()); | 832 ASSERT(isMainThread()); |
824 ASSERT(m_page); | 833 ASSERT(m_page); |
825 | 834 |
826 if (!coordinatesScrollingForFrameView(frameView)) | 835 if (!coordinatesScrollingForFrameView(frameView)) |
827 return; | 836 return; |
828 | 837 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 | 869 |
861 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) | 870 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) |
862 { | 871 { |
863 ASSERT(isMainThread()); | 872 ASSERT(isMainThread()); |
864 ASSERT(m_page); | 873 ASSERT(m_page); |
865 | 874 |
866 if (!coordinatesScrollingForFrameView(frameView)) | 875 if (!coordinatesScrollingForFrameView(frameView)) |
867 return; | 876 return; |
868 | 877 |
869 notifyLayoutUpdated(); | 878 notifyLayoutUpdated(); |
870 recomputeWheelEventHandlerCountForFrameView(frameView); | 879 updateHaveWheelEventHandlers(); |
880 updateHaveScrollEventHandlers(); | |
871 } | 881 } |
872 | 882 |
873 #if OS(MACOSX) | 883 #if OS(MACOSX) |
874 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase) | 884 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase) |
875 { | 885 { |
876 ASSERT(isMainThread()); | 886 ASSERT(isMainThread()); |
877 | 887 |
878 if (!m_page) | 888 if (!m_page) |
879 return; | 889 return; |
880 | 890 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 bool frameIsScrollable = frameView && frameView->isScrollable(); | 966 bool frameIsScrollable = frameView && frameView->isScrollable(); |
957 if (frameIsScrollable != m_wasFrameScrollable) | 967 if (frameIsScrollable != m_wasFrameScrollable) |
958 return true; | 968 return true; |
959 | 969 |
960 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0) | 970 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0) |
961 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( ); | 971 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( ); |
962 return false; | 972 return false; |
963 } | 973 } |
964 | 974 |
965 } // namespace WebCore | 975 } // namespace WebCore |
OLD | NEW |