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

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: Update hit test counts Created 6 years, 4 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 eventSwallowed = true; 650 eventSwallowed = true;
652 651
653 m_client->didHandleGestureEvent(event, eventCancelled); 652 m_client->didHandleGestureEvent(event, eventCancelled);
654 return eventSwallowed; 653 return eventSwallowed;
655 default: 654 default:
656 break; 655 break;
657 } 656 }
658 657
659 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t); 658 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t);
660 659
661 // FIXME: Remove redundant hit tests by pushing the call to EventHandler::ta rgetGestureEvent 660 HitTestResult emptyResult;
Rick Byers 2014/08/20 23:59:33 As discussed, having this "sometimes targetted but
Zeeshan Qureshi 2014/08/21 04:59:25 Done.
662 // up to this point and pass GestureEventWithHitTestResults around. 661 GestureEventWithHitTestResults targetedEvent(platformEvent, emptyResult);
662 // Hit test across all frames and do touch adjustment as necessary for the e vent type.
663 if (!platformEvent.isScrollEvent())
664 targetedEvent = m_page->deprecatedLocalMainFrame()->eventHandler().targe tGestureEvent(platformEvent);
663 665
664 // Handle link highlighting outside the main switch to avoid getting lost in the 666 // Handle link highlighting outside the main switch to avoid getting lost in the
665 // complicated set of cases handled below. 667 // complicated set of cases handled below.
666 switch (event.type) { 668 switch (event.type) {
667 case WebInputEvent::GestureShowPress: 669 case WebInputEvent::GestureShowPress:
668 // Queue a highlight animation, then hand off to regular handler. 670 // Queue a highlight animation, then hand off to regular handler.
669 enableTapHighlightAtPoint(platformEvent); 671 enableTapHighlightAtPoint(targetedEvent);
670 break; 672 break;
671 case WebInputEvent::GestureTapCancel: 673 case WebInputEvent::GestureTapCancel:
672 case WebInputEvent::GestureTap: 674 case WebInputEvent::GestureTap:
673 case WebInputEvent::GestureLongPress: 675 case WebInputEvent::GestureLongPress:
674 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 676 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
675 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 677 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
676 break; 678 break;
677 default: 679 default:
678 break; 680 break;
679 } 681 }
680 682
681 switch (event.type) { 683 switch (event.type) {
682 case WebInputEvent::GestureTap: { 684 case WebInputEvent::GestureTap: {
683 m_client->cancelScheduledContentIntents(); 685 m_client->cancelScheduledContentIntents();
684 if (detectContentOnTouch(platformEvent.position())) { 686 if (detectContentOnTouch(targetedEvent.event().position())) {
Rick Byers 2014/08/20 23:59:32 Add FIXME to use the targeted event here.
Zeeshan Qureshi 2014/08/21 04:59:25 Done.
685 eventSwallowed = true; 687 eventSwallowed = true;
686 break; 688 break;
687 } 689 }
688 690
689 RefPtr<PopupContainer> selectPopup; 691 RefPtr<PopupContainer> selectPopup;
690 selectPopup = m_selectPopup; 692 selectPopup = m_selectPopup;
691 hideSelectPopup(); 693 hideSelectPopup();
692 ASSERT(!m_selectPopup); 694 ASSERT(!m_selectPopup);
693 695
694 // Don't trigger a disambiguation popup on sites designed for mobile dev ices. 696 // Don't trigger a disambiguation popup on sites designed for mobile dev ices.
(...skipping 15 matching lines...) Expand all
710 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) { 712 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) {
711 enableTapHighlights(highlightNodes); 713 enableTapHighlights(highlightNodes);
712 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 714 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
713 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 715 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
714 eventSwallowed = true; 716 eventSwallowed = true;
715 eventCancelled = true; 717 eventCancelled = true;
716 break; 718 break;
717 } 719 }
718 } 720 }
719 721
720 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 722 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
721 723
722 if (m_selectPopup && m_selectPopup == selectPopup) { 724 if (m_selectPopup && m_selectPopup == selectPopup) {
723 // That tap triggered a select popup which is the same as the one th at 725 // That tap triggered a select popup which is the same as the one th at
724 // was showing before the tap. It means the user tapped the select 726 // was showing before the tap. It means the user tapped the select
725 // while the popup was showing, and as a result we first closed then 727 // while the popup was showing, and as a result we first closed then
726 // immediately reopened the select popup. It needs to be closed. 728 // immediately reopened the select popup. It needs to be closed.
727 hideSelectPopup(); 729 hideSelectPopup();
728 } 730 }
729 731
730 break; 732 break;
731 } 733 }
732 case WebInputEvent::GestureTwoFingerTap: 734 case WebInputEvent::GestureTwoFingerTap:
733 case WebInputEvent::GestureLongPress: 735 case WebInputEvent::GestureLongPress:
734 case WebInputEvent::GestureLongTap: { 736 case WebInputEvent::GestureLongTap: {
735 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 737 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
736 break; 738 break;
737 739
738 m_client->cancelScheduledContentIntents(); 740 m_client->cancelScheduledContentIntents();
739 m_page->contextMenuController().clearContextMenu(); 741 m_page->contextMenuController().clearContextMenu();
740 m_contextMenuAllowed = true; 742 m_contextMenuAllowed = true;
741 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 743 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
742 m_contextMenuAllowed = false; 744 m_contextMenuAllowed = false;
743 745
744 break; 746 break;
745 } 747 }
746 case WebInputEvent::GestureShowPress: { 748 case WebInputEvent::GestureShowPress: {
747 m_client->cancelScheduledContentIntents(); 749 m_client->cancelScheduledContentIntents();
748 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 750 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
749 break; 751 break;
750 } 752 }
751 case WebInputEvent::GestureDoubleTap: 753 case WebInputEvent::GestureDoubleTap:
752 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor() != maximumPageScaleFactor()) { 754 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor() != maximumPageScaleFactor()) {
753 m_client->cancelScheduledContentIntents(); 755 m_client->cancelScheduledContentIntents();
754 animateDoubleTapZoom(platformEvent.position()); 756 animateDoubleTapZoom(targetedEvent.event().position());
755 } 757 }
756 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore, 758 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore,
757 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here. 759 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here.
758 eventSwallowed = true; 760 eventSwallowed = true;
759 break; 761 break;
760 case WebInputEvent::GestureScrollBegin: 762 case WebInputEvent::GestureScrollBegin:
761 case WebInputEvent::GesturePinchBegin: 763 case WebInputEvent::GesturePinchBegin:
762 m_client->cancelScheduledContentIntents(); 764 m_client->cancelScheduledContentIntents();
763 case WebInputEvent::GestureTapDown: 765 case WebInputEvent::GestureTapDown:
764 case WebInputEvent::GestureScrollEnd: 766 case WebInputEvent::GestureScrollEnd:
765 case WebInputEvent::GestureScrollUpdate: 767 case WebInputEvent::GestureScrollUpdate:
766 case WebInputEvent::GestureScrollUpdateWithoutPropagation: 768 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
767 case WebInputEvent::GestureTapCancel: 769 case WebInputEvent::GestureTapCancel:
768 case WebInputEvent::GestureTapUnconfirmed: 770 case WebInputEvent::GestureTapUnconfirmed:
769 case WebInputEvent::GesturePinchEnd: 771 case WebInputEvent::GesturePinchEnd:
770 case WebInputEvent::GesturePinchUpdate: 772 case WebInputEvent::GesturePinchUpdate:
771 case WebInputEvent::GestureFlingStart: { 773 case WebInputEvent::GestureFlingStart: {
772 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent); 774 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent);
773 break; 775 break;
774 } 776 }
775 default: 777 default:
776 ASSERT_NOT_REACHED(); 778 ASSERT_NOT_REACHED();
777 } 779 }
778 m_client->didHandleGestureEvent(event, eventCancelled); 780 m_client->didHandleGestureEvent(event, eventCancelled);
779 return eventSwallowed; 781 return eventSwallowed;
780 } 782 }
781 783
782 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters) 784 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters)
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 static bool showsHandCursor(Node* node, LocalFrame* frame) 1184 static bool showsHandCursor(Node* node, LocalFrame* frame)
1183 { 1185 {
1184 if (!node || !node->renderer()) 1186 if (!node || !node->renderer())
1185 return false; 1187 return false;
1186 1188
1187 ECursor cursor = node->renderer()->style()->cursor(); 1189 ECursor cursor = node->renderer()->style()->cursor();
1188 return cursor == CURSOR_POINTER 1190 return cursor == CURSOR_POINTER
1189 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); 1191 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink()));
1190 } 1192 }
1191 1193
1192 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) 1194 Node* WebViewImpl::bestTapNode(const GestureEventWithHitTestResults& targetedTap Event)
1193 { 1195 {
1194 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); 1196 TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
1195 1197
1196 if (!m_page || !m_page->mainFrame()) 1198 if (!m_page || !m_page->mainFrame())
1197 return 0; 1199 return 0;
1198 1200
1199 // FIXME: Rely on earlier hit test instead of hit testing again. 1201 Node* bestTouchNode = targetedTapEvent.hitTestResult().targetNode();
1200 GestureEventWithHitTestResults targetedEvent =
1201 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true);
1202 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode();
1203 1202
1204 // We might hit something like an image map that has no renderer on it 1203 // We might hit something like an image map that has no renderer on it
1205 // Walk up the tree until we have a node with an attached renderer 1204 // Walk up the tree until we have a node with an attached renderer
1206 while (bestTouchNode && !bestTouchNode->renderer()) 1205 while (bestTouchNode && !bestTouchNode->renderer())
1207 bestTouchNode = bestTouchNode->parentNode(); 1206 bestTouchNode = bestTouchNode->parentNode();
1208 1207
1209 Node* cursorDefiningAncestor = 1208 Node* cursorDefiningAncestor =
1210 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me()); 1209 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me());
1211 // We show a highlight on tap only when the current node shows a hand cursor 1210 // We show a highlight on tap only when the current node shows a hand cursor
1212 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) { 1211 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) {
1213 return 0; 1212 return 0;
1214 } 1213 }
1215 1214
1216 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping 1215 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping
1217 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate 1216 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate
1218 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node 1217 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node
1219 // has hand cursor set. 1218 // has hand cursor set.
1220 do { 1219 do {
1221 bestTouchNode = cursorDefiningAncestor; 1220 bestTouchNode = cursorDefiningAncestor;
1222 cursorDefiningAncestor = findCursorDefiningAncestor(bestTouchNode->paren tNode(), m_page->deprecatedLocalMainFrame()); 1221 cursorDefiningAncestor = findCursorDefiningAncestor(bestTouchNode->paren tNode(), m_page->deprecatedLocalMainFrame());
1223 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame())); 1222 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame()));
1224 1223
1225 return bestTouchNode; 1224 return bestTouchNode;
1226 } 1225 }
1227 1226
1228 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) 1227 void WebViewImpl::enableTapHighlightAtPoint(const GestureEventWithHitTestResults & targetedTapEvent)
1229 { 1228 {
1230 Node* touchNode = bestTapNode(tapEvent); 1229 Node* touchNode = bestTapNode(targetedTapEvent);
1231 1230
1232 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; 1231 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes;
1233 highlightNodes.append(touchNode); 1232 highlightNodes.append(touchNode);
1234 1233
1235 enableTapHighlights(highlightNodes); 1234 enableTapHighlights(highlightNodes);
1236 } 1235 }
1237 1236
1238 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes) 1237 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes)
1239 { 1238 {
1240 if (highlightNodes.isEmpty()) 1239 if (highlightNodes.isEmpty())
(...skipping 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after
4258 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4257 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4259 4258
4260 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4259 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4261 return false; 4260 return false;
4262 4261
4263 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4262 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4264 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4263 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4265 } 4264 }
4266 4265
4267 } // namespace blink 4266 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698