Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: Source/core/page/scrolling/ScrollingCoordinator.cpp

Issue 206603002: Add EventHandlerRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase harder. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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())) {
Ian Vollick 2014/04/08 15:40:51 It took a fair bit of reading in cc to figure out
Sami 2014/04/08 16:25:00 Yes, that could use a clarification. Added a comme
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
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 Node* node = target->toNode();
761 if (!node->inDocument())
753 continue; 762 continue;
754 763
755 if (target->isDocumentNode()) { 764 if (node->isDocumentNode()) {
756 ASSERT(target != document); 765 ASSERT(node != document);
757 accumulateDocumentTouchEventTargetRects(rects, toDocument(target)); 766 accumulateDocumentTouchEventTargetRects(rects, toDocument(node));
758 } else if (RenderObject* renderer = target->renderer()) { 767 } else if (RenderObject* renderer = node->renderer()) {
759 // If the set also contains one of our ancestor nodes then processin g 768 // If the set also contains one of our ancestor nodes then processin g
760 // this node would be redundant. 769 // this node would be redundant.
761 bool hasTouchEventTargetAncestor = false; 770 bool hasTouchEventTargetAncestor = false;
762 for (Node* ancestor = target->parentNode(); ancestor && !hasTouchEve ntTargetAncestor; ancestor = ancestor->parentNode()) { 771 for (Node* ancestor = node->parentNode(); ancestor && !hasTouchEvent TargetAncestor; ancestor = ancestor->parentNode()) {
763 if (targets->contains(ancestor)) 772 if (targets->contains(ancestor))
764 hasTouchEventTargetAncestor = true; 773 hasTouchEventTargetAncestor = true;
765 } 774 }
766 if (!hasTouchEventTargetAncestor) { 775 if (!hasTouchEventTargetAncestor) {
767 // Walk up the tree to the outermost non-composited scrollable l ayer. 776 // Walk up the tree to the outermost non-composited scrollable l ayer.
768 RenderLayer* enclosingNonCompositedScrollLayer = 0; 777 RenderLayer* enclosingNonCompositedScrollLayer = 0;
769 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) { 778 for (RenderLayer* parent = renderer->enclosingLayer(); parent && parent->compositingState() == NotComposited; parent = parent->parent()) {
770 if (parent->scrollsOverflow()) 779 if (parent->scrollsOverflow())
771 enclosingNonCompositedScrollLayer = parent; 780 enclosingNonCompositedScrollLayer = parent;
772 } 781 }
(...skipping 18 matching lines...) Expand all
791 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); 800 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects");
792 ASSERT(touchHitTestingEnabled()); 801 ASSERT(touchHitTestingEnabled());
793 802
794 Document* document = m_page->mainFrame()->document(); 803 Document* document = m_page->mainFrame()->document();
795 if (!document || !document->view()) 804 if (!document || !document->view())
796 return; 805 return;
797 806
798 accumulateDocumentTouchEventTargetRects(rects, document); 807 accumulateDocumentTouchEventTargetRects(rects, document);
799 } 808 }
800 809
801 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() 810 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 { 811 {
815 ASSERT(isMainThread()); 812 ASSERT(isMainThread());
816 ASSERT(m_page); 813 ASSERT(m_page);
817 814
818 recomputeWheelEventHandlerCountForFrameView(frameView); 815 updateHaveWheelEventHandlers();
816 }
817
818 void ScrollingCoordinator::haveScrollEventHandlersChangedForPage()
819 {
820 ASSERT(isMainThread());
821 ASSERT(m_page);
822
823 updateHaveScrollEventHandlers();
819 } 824 }
820 825
821 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView) 826 void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* fr ameView)
822 { 827 {
823 ASSERT(isMainThread()); 828 ASSERT(isMainThread());
824 ASSERT(m_page); 829 ASSERT(m_page);
825 830
826 if (!coordinatesScrollingForFrameView(frameView)) 831 if (!coordinatesScrollingForFrameView(frameView))
827 return; 832 return;
828 833
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 865
861 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) 866 void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView)
862 { 867 {
863 ASSERT(isMainThread()); 868 ASSERT(isMainThread());
864 ASSERT(m_page); 869 ASSERT(m_page);
865 870
866 if (!coordinatesScrollingForFrameView(frameView)) 871 if (!coordinatesScrollingForFrameView(frameView))
867 return; 872 return;
868 873
869 notifyLayoutUpdated(); 874 notifyLayoutUpdated();
870 recomputeWheelEventHandlerCountForFrameView(frameView); 875 updateHaveWheelEventHandlers();
876 updateHaveScrollEventHandlers();
871 } 877 }
872 878
873 #if OS(MACOSX) 879 #if OS(MACOSX)
874 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase) 880 void ScrollingCoordinator::handleWheelEventPhase(PlatformWheelEventPhase phase)
875 { 881 {
876 ASSERT(isMainThread()); 882 ASSERT(isMainThread());
877 883
878 if (!m_page) 884 if (!m_page)
879 return; 885 return;
880 886
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 bool frameIsScrollable = frameView && frameView->isScrollable(); 962 bool frameIsScrollable = frameView && frameView->isScrollable();
957 if (frameIsScrollable != m_wasFrameScrollable) 963 if (frameIsScrollable != m_wasFrameScrollable)
958 return true; 964 return true;
959 965
960 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0) 966 if (WebLayer* scrollLayer = frameView ? toWebLayer(frameView->layerForScroll ing()) : 0)
961 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( ); 967 return blink::WebSize(frameView->contentsSize()) != scrollLayer->bounds( );
962 return false; 968 return false;
963 } 969 }
964 970
965 } // namespace WebCore 971 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698