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

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 490783003: Reduce hit test on ShowPress by moving event targeting to WebViewImpl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase after other hit test patches Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "core/loader/DocumentLoader.h" 64 #include "core/loader/DocumentLoader.h"
65 #include "core/loader/FrameLoader.h" 65 #include "core/loader/FrameLoader.h"
66 #include "core/loader/UniqueIdentifier.h" 66 #include "core/loader/UniqueIdentifier.h"
67 #include "core/page/Chrome.h" 67 #include "core/page/Chrome.h"
68 #include "core/page/ContextMenuController.h" 68 #include "core/page/ContextMenuController.h"
69 #include "core/page/ContextMenuProvider.h" 69 #include "core/page/ContextMenuProvider.h"
70 #include "core/page/DragController.h" 70 #include "core/page/DragController.h"
71 #include "core/page/DragData.h" 71 #include "core/page/DragData.h"
72 #include "core/page/DragSession.h" 72 #include "core/page/DragSession.h"
73 #include "core/page/EventHandler.h" 73 #include "core/page/EventHandler.h"
74 #include "core/page/EventWithHitTestResults.h"
75 #include "core/page/FocusController.h" 74 #include "core/page/FocusController.h"
76 #include "core/page/FrameTree.h" 75 #include "core/page/FrameTree.h"
77 #include "core/page/InjectedStyleSheets.h" 76 #include "core/page/InjectedStyleSheets.h"
78 #include "core/page/Page.h" 77 #include "core/page/Page.h"
79 #include "core/page/PagePopupClient.h" 78 #include "core/page/PagePopupClient.h"
80 #include "core/page/PointerLockController.h" 79 #include "core/page/PointerLockController.h"
81 #include "core/page/ScopedPageLoadDeferrer.h" 80 #include "core/page/ScopedPageLoadDeferrer.h"
82 #include "core/page/TouchDisambiguation.h" 81 #include "core/page/TouchDisambiguation.h"
83 #include "core/rendering/RenderView.h" 82 #include "core/rendering/RenderView.h"
84 #include "core/rendering/RenderWidget.h" 83 #include "core/rendering/RenderWidget.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 eventSwallowed = true; 657 eventSwallowed = true;
659 658
660 m_client->didHandleGestureEvent(event, eventCancelled); 659 m_client->didHandleGestureEvent(event, eventCancelled);
661 return eventSwallowed; 660 return eventSwallowed;
662 default: 661 default:
663 break; 662 break;
664 } 663 }
665 664
666 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t); 665 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t);
667 666
668 // FIXME: Remove redundant hit tests by pushing the call to EventHandler::ta rgetGestureEvent 667 // Special handling for double tap and scroll events as we don't want to
669 // up to this point and pass GestureEventWithHitTestResults around. 668 // hit test for them.
669 switch (event.type) {
670 case WebInputEvent::GestureDoubleTap:
aelias_OOO_until_Jul13 2014/08/27 03:26:34 It seems strange to treat double-tap specially her
Zeeshan Qureshi 2014/08/27 19:37:56 The way I see it is that DoubleTap is handled dire
Rick Byers 2014/08/27 20:30:25 I agree that this CL doesn't change the special-ha
671 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor() != maximumPageScaleFactor()) {
672 m_client->cancelScheduledContentIntents();
673 animateDoubleTapZoom(platformEvent.position());
674 }
675 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore,
676 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here.
677 eventSwallowed = true;
678 m_client->didHandleGestureEvent(event, eventCancelled);
679 return eventSwallowed;
680 case WebInputEvent::GestureScrollBegin:
681 case WebInputEvent::GesturePinchBegin:
682 m_client->cancelScheduledContentIntents();
683 case WebInputEvent::GestureScrollEnd:
684 case WebInputEvent::GestureScrollUpdate:
685 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
686 case WebInputEvent::GesturePinchEnd:
687 case WebInputEvent::GesturePinchUpdate:
688 case WebInputEvent::GestureFlingStart:
689 // Scrolling-related gesture events invoke EventHandler recursively for each frame down
690 // the chain, doing a single-frame hit-test per frame. This matches hand leWheelEvent.
691 // Perhaps we could simplify things by rewriting scroll handling to work inner frame
692 // out, and then unify with other gesture events.
693 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureS crollEvent(platformEvent);
694 m_client->didHandleGestureEvent(event, eventCancelled);
695 return eventSwallowed;
696 default:
697 break;
698 }
699
700 // Hit test across all frames and do touch adjustment as necessary for the e vent type.
701 GestureEventWithHitTestResults targetedEvent =
702 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(pl atformEvent);
670 703
671 // Handle link highlighting outside the main switch to avoid getting lost in the 704 // Handle link highlighting outside the main switch to avoid getting lost in the
672 // complicated set of cases handled below. 705 // complicated set of cases handled below.
673 switch (event.type) { 706 switch (event.type) {
674 case WebInputEvent::GestureShowPress: 707 case WebInputEvent::GestureShowPress:
675 // Queue a highlight animation, then hand off to regular handler. 708 // Queue a highlight animation, then hand off to regular handler.
676 enableTapHighlightAtPoint(platformEvent); 709 enableTapHighlightAtPoint(targetedEvent);
677 break; 710 break;
678 case WebInputEvent::GestureTapCancel: 711 case WebInputEvent::GestureTapCancel:
679 case WebInputEvent::GestureTap: 712 case WebInputEvent::GestureTap:
680 case WebInputEvent::GestureLongPress: 713 case WebInputEvent::GestureLongPress:
681 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 714 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
682 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 715 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
683 break; 716 break;
684 default: 717 default:
685 break; 718 break;
686 } 719 }
687 720
688 switch (event.type) { 721 switch (event.type) {
689 case WebInputEvent::GestureTap: { 722 case WebInputEvent::GestureTap: {
690 m_client->cancelScheduledContentIntents(); 723 m_client->cancelScheduledContentIntents();
691 if (detectContentOnTouch(platformEvent.position())) { 724 // FIXME: Use targeted event here and save another hit test.
725 if (detectContentOnTouch(targetedEvent.event().position())) {
692 eventSwallowed = true; 726 eventSwallowed = true;
693 break; 727 break;
694 } 728 }
695 729
696 RefPtr<PopupContainer> selectPopup; 730 RefPtr<PopupContainer> selectPopup;
697 selectPopup = m_selectPopup; 731 selectPopup = m_selectPopup;
698 hideSelectPopup(); 732 hideSelectPopup();
699 ASSERT(!m_selectPopup); 733 ASSERT(!m_selectPopup);
700 734
701 // Don't trigger a disambiguation popup on sites designed for mobile dev ices. 735 // Don't trigger a disambiguation popup on sites designed for mobile dev ices.
(...skipping 15 matching lines...) Expand all
717 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) { 751 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) {
718 enableTapHighlights(highlightNodes); 752 enableTapHighlights(highlightNodes);
719 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 753 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
720 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 754 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
721 eventSwallowed = true; 755 eventSwallowed = true;
722 eventCancelled = true; 756 eventCancelled = true;
723 break; 757 break;
724 } 758 }
725 } 759 }
726 760
727 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 761 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
728 762
729 if (m_selectPopup && m_selectPopup == selectPopup) { 763 if (m_selectPopup && m_selectPopup == selectPopup) {
730 // That tap triggered a select popup which is the same as the one th at 764 // That tap triggered a select popup which is the same as the one th at
731 // was showing before the tap. It means the user tapped the select 765 // was showing before the tap. It means the user tapped the select
732 // while the popup was showing, and as a result we first closed then 766 // while the popup was showing, and as a result we first closed then
733 // immediately reopened the select popup. It needs to be closed. 767 // immediately reopened the select popup. It needs to be closed.
734 hideSelectPopup(); 768 hideSelectPopup();
735 } 769 }
736 770
737 break; 771 break;
738 } 772 }
739 case WebInputEvent::GestureTwoFingerTap: 773 case WebInputEvent::GestureTwoFingerTap:
740 case WebInputEvent::GestureLongPress: 774 case WebInputEvent::GestureLongPress:
741 case WebInputEvent::GestureLongTap: { 775 case WebInputEvent::GestureLongTap: {
742 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 776 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
743 break; 777 break;
744 778
745 m_client->cancelScheduledContentIntents(); 779 m_client->cancelScheduledContentIntents();
746 m_page->contextMenuController().clearContextMenu(); 780 m_page->contextMenuController().clearContextMenu();
747 m_contextMenuAllowed = true; 781 m_contextMenuAllowed = true;
748 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 782 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
749 m_contextMenuAllowed = false; 783 m_contextMenuAllowed = false;
750 784
751 break; 785 break;
752 } 786 }
753 case WebInputEvent::GestureShowPress: { 787 case WebInputEvent::GestureShowPress:
754 m_client->cancelScheduledContentIntents();
755 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent);
756 break;
757 }
758 case WebInputEvent::GestureDoubleTap:
759 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor() != maximumPageScaleFactor()) {
760 m_client->cancelScheduledContentIntents();
761 animateDoubleTapZoom(platformEvent.position());
762 }
763 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore,
764 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here.
765 eventSwallowed = true;
766 break;
767 case WebInputEvent::GestureScrollBegin:
768 case WebInputEvent::GesturePinchBegin:
769 m_client->cancelScheduledContentIntents(); 788 m_client->cancelScheduledContentIntents();
770 case WebInputEvent::GestureTapDown: 789 case WebInputEvent::GestureTapDown:
771 case WebInputEvent::GestureScrollEnd:
772 case WebInputEvent::GestureScrollUpdate:
773 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
774 case WebInputEvent::GestureTapCancel: 790 case WebInputEvent::GestureTapCancel:
775 case WebInputEvent::GestureTapUnconfirmed: 791 case WebInputEvent::GestureTapUnconfirmed: {
776 case WebInputEvent::GesturePinchEnd: 792 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
777 case WebInputEvent::GesturePinchUpdate:
778 case WebInputEvent::GestureFlingStart: {
779 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent);
780 break; 793 break;
781 } 794 }
782 default: 795 default:
783 ASSERT_NOT_REACHED(); 796 ASSERT_NOT_REACHED();
784 } 797 }
785 m_client->didHandleGestureEvent(event, eventCancelled); 798 m_client->didHandleGestureEvent(event, eventCancelled);
786 return eventSwallowed; 799 return eventSwallowed;
787 } 800 }
788 801
789 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters) 802 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters)
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 static bool showsHandCursor(Node* node, LocalFrame* frame) 1202 static bool showsHandCursor(Node* node, LocalFrame* frame)
1190 { 1203 {
1191 if (!node || !node->renderer()) 1204 if (!node || !node->renderer())
1192 return false; 1205 return false;
1193 1206
1194 ECursor cursor = node->renderer()->style()->cursor(); 1207 ECursor cursor = node->renderer()->style()->cursor();
1195 return cursor == CURSOR_POINTER 1208 return cursor == CURSOR_POINTER
1196 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); 1209 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink()));
1197 } 1210 }
1198 1211
1199 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) 1212 Node* WebViewImpl::bestTapNode(const GestureEventWithHitTestResults& targetedTap Event)
1200 { 1213 {
1201 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); 1214 TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
1202 1215
1203 if (!m_page || !m_page->mainFrame()) 1216 if (!m_page || !m_page->mainFrame())
1204 return 0; 1217 return 0;
1205 1218
1206 // FIXME: Rely on earlier hit test instead of hit testing again. 1219 Node* bestTouchNode = targetedTapEvent.hitTestResult().targetNode();
1207 GestureEventWithHitTestResults targetedEvent =
1208 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true);
1209 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode();
1210 1220
1211 // We might hit something like an image map that has no renderer on it 1221 // We might hit something like an image map that has no renderer on it
1212 // Walk up the tree until we have a node with an attached renderer 1222 // Walk up the tree until we have a node with an attached renderer
1213 while (bestTouchNode && !bestTouchNode->renderer()) 1223 while (bestTouchNode && !bestTouchNode->renderer())
1214 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode); 1224 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode);
1215 1225
1216 Node* cursorDefiningAncestor = 1226 Node* cursorDefiningAncestor =
1217 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me()); 1227 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me());
1218 // We show a highlight on tap only when the current node shows a hand cursor 1228 // We show a highlight on tap only when the current node shows a hand cursor
1219 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) { 1229 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) {
1220 return 0; 1230 return 0;
1221 } 1231 }
1222 1232
1223 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping 1233 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping
1224 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate 1234 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate
1225 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node 1235 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node
1226 // has hand cursor set. 1236 // has hand cursor set.
1227 do { 1237 do {
1228 bestTouchNode = cursorDefiningAncestor; 1238 bestTouchNode = cursorDefiningAncestor;
1229 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers al::parent(bestTouchNode), 1239 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers al::parent(bestTouchNode),
1230 m_page->deprecatedLocalMainFrame()); 1240 m_page->deprecatedLocalMainFrame());
1231 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame())); 1241 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame()));
1232 1242
1233 return bestTouchNode; 1243 return bestTouchNode;
1234 } 1244 }
1235 1245
1236 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) 1246 void WebViewImpl::enableTapHighlightAtPoint(const GestureEventWithHitTestResults & targetedTapEvent)
1237 { 1247 {
1238 Node* touchNode = bestTapNode(tapEvent); 1248 Node* touchNode = bestTapNode(targetedTapEvent);
1239 1249
1240 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; 1250 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes;
1241 highlightNodes.append(touchNode); 1251 highlightNodes.append(touchNode);
1242 1252
1243 enableTapHighlights(highlightNodes); 1253 enableTapHighlights(highlightNodes);
1244 } 1254 }
1245 1255
1246 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes) 1256 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes)
1247 { 1257 {
1248 if (highlightNodes.isEmpty()) 1258 if (highlightNodes.isEmpty())
(...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4268 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4278 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4269 4279
4270 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4280 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4271 return false; 4281 return false;
4272 4282
4273 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4283 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4274 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4284 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4275 } 4285 }
4276 4286
4277 } // namespace blink 4287 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698