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

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

Issue 509173004: Revert of Reduce hit test on ShowPress by moving event targeting to WebViewImpl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/LinkHighlightTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
74 #include "core/page/FocusController.h" 75 #include "core/page/FocusController.h"
75 #include "core/page/FrameTree.h" 76 #include "core/page/FrameTree.h"
76 #include "core/page/InjectedStyleSheets.h" 77 #include "core/page/InjectedStyleSheets.h"
77 #include "core/page/Page.h" 78 #include "core/page/Page.h"
78 #include "core/page/PagePopupClient.h" 79 #include "core/page/PagePopupClient.h"
79 #include "core/page/PointerLockController.h" 80 #include "core/page/PointerLockController.h"
80 #include "core/page/ScopedPageLoadDeferrer.h" 81 #include "core/page/ScopedPageLoadDeferrer.h"
81 #include "core/page/TouchDisambiguation.h" 82 #include "core/page/TouchDisambiguation.h"
82 #include "core/rendering/RenderView.h" 83 #include "core/rendering/RenderView.h"
83 #include "core/rendering/RenderWidget.h" 84 #include "core/rendering/RenderWidget.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 eventSwallowed = true; 658 eventSwallowed = true;
658 659
659 m_client->didHandleGestureEvent(event, eventCancelled); 660 m_client->didHandleGestureEvent(event, eventCancelled);
660 return eventSwallowed; 661 return eventSwallowed;
661 default: 662 default:
662 break; 663 break;
663 } 664 }
664 665
665 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t); 666 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even t);
666 667
667 // Special handling for double tap and scroll events as we don't want to 668 // FIXME: Remove redundant hit tests by pushing the call to EventHandler::ta rgetGestureEvent
668 // hit test for them. 669 // up to this point and pass GestureEventWithHitTestResults around.
669 switch (event.type) {
670 case WebInputEvent::GestureDoubleTap:
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);
703 670
704 // Handle link highlighting outside the main switch to avoid getting lost in the 671 // Handle link highlighting outside the main switch to avoid getting lost in the
705 // complicated set of cases handled below. 672 // complicated set of cases handled below.
706 switch (event.type) { 673 switch (event.type) {
707 case WebInputEvent::GestureShowPress: 674 case WebInputEvent::GestureShowPress:
708 // Queue a highlight animation, then hand off to regular handler. 675 // Queue a highlight animation, then hand off to regular handler.
709 enableTapHighlightAtPoint(targetedEvent); 676 enableTapHighlightAtPoint(platformEvent);
710 break; 677 break;
711 case WebInputEvent::GestureTapCancel: 678 case WebInputEvent::GestureTapCancel:
712 case WebInputEvent::GestureTap: 679 case WebInputEvent::GestureTap:
713 case WebInputEvent::GestureLongPress: 680 case WebInputEvent::GestureLongPress:
714 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 681 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
715 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 682 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
716 break; 683 break;
717 default: 684 default:
718 break; 685 break;
719 } 686 }
720 687
721 switch (event.type) { 688 switch (event.type) {
722 case WebInputEvent::GestureTap: { 689 case WebInputEvent::GestureTap: {
723 m_client->cancelScheduledContentIntents(); 690 m_client->cancelScheduledContentIntents();
724 // FIXME: Use targeted event here and save another hit test. 691 if (detectContentOnTouch(platformEvent.position())) {
725 if (detectContentOnTouch(targetedEvent.event().position())) {
726 eventSwallowed = true; 692 eventSwallowed = true;
727 break; 693 break;
728 } 694 }
729 695
730 RefPtr<PopupContainer> selectPopup; 696 RefPtr<PopupContainer> selectPopup;
731 selectPopup = m_selectPopup; 697 selectPopup = m_selectPopup;
732 hideSelectPopup(); 698 hideSelectPopup();
733 ASSERT(!m_selectPopup); 699 ASSERT(!m_selectPopup);
734 700
735 // Don't trigger a disambiguation popup on sites designed for mobile dev ices. 701 // Don't trigger a disambiguation popup on sites designed for mobile dev ices.
(...skipping 15 matching lines...) Expand all
751 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) { 717 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT argets(scaledEvent, goodTargets)) {
752 enableTapHighlights(highlightNodes); 718 enableTapHighlights(highlightNodes);
753 for (size_t i = 0; i < m_linkHighlights.size(); ++i) 719 for (size_t i = 0; i < m_linkHighlights.size(); ++i)
754 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); 720 m_linkHighlights[i]->startHighlightAnimationIfNeeded();
755 eventSwallowed = true; 721 eventSwallowed = true;
756 eventCancelled = true; 722 eventCancelled = true;
757 break; 723 break;
758 } 724 }
759 } 725 }
760 726
761 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent); 727 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent);
762 728
763 if (m_selectPopup && m_selectPopup == selectPopup) { 729 if (m_selectPopup && m_selectPopup == selectPopup) {
764 // That tap triggered a select popup which is the same as the one th at 730 // That tap triggered a select popup which is the same as the one th at
765 // was showing before the tap. It means the user tapped the select 731 // was showing before the tap. It means the user tapped the select
766 // while the popup was showing, and as a result we first closed then 732 // while the popup was showing, and as a result we first closed then
767 // immediately reopened the select popup. It needs to be closed. 733 // immediately reopened the select popup. It needs to be closed.
768 hideSelectPopup(); 734 hideSelectPopup();
769 } 735 }
770 736
771 break; 737 break;
772 } 738 }
773 case WebInputEvent::GestureTwoFingerTap: 739 case WebInputEvent::GestureTwoFingerTap:
774 case WebInputEvent::GestureLongPress: 740 case WebInputEvent::GestureLongPress:
775 case WebInputEvent::GestureLongTap: { 741 case WebInputEvent::GestureLongTap: {
776 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 742 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
777 break; 743 break;
778 744
779 m_client->cancelScheduledContentIntents(); 745 m_client->cancelScheduledContentIntents();
780 m_page->contextMenuController().clearContextMenu(); 746 m_page->contextMenuController().clearContextMenu();
781 m_contextMenuAllowed = true; 747 m_contextMenuAllowed = true;
782 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent); 748 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent);
783 m_contextMenuAllowed = false; 749 m_contextMenuAllowed = false;
784 750
785 break; 751 break;
786 } 752 }
787 case WebInputEvent::GestureShowPress: 753 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:
788 m_client->cancelScheduledContentIntents(); 769 m_client->cancelScheduledContentIntents();
789 case WebInputEvent::GestureTapDown: 770 case WebInputEvent::GestureTapDown:
771 case WebInputEvent::GestureScrollEnd:
772 case WebInputEvent::GestureScrollUpdate:
773 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
790 case WebInputEvent::GestureTapCancel: 774 case WebInputEvent::GestureTapCancel:
791 case WebInputEvent::GestureTapUnconfirmed: { 775 case WebInputEvent::GestureTapUnconfirmed:
792 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(targetedEvent); 776 case WebInputEvent::GesturePinchEnd:
777 case WebInputEvent::GesturePinchUpdate:
778 case WebInputEvent::GestureFlingStart: {
779 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE vent(platformEvent);
793 break; 780 break;
794 } 781 }
795 default: 782 default:
796 ASSERT_NOT_REACHED(); 783 ASSERT_NOT_REACHED();
797 } 784 }
798 m_client->didHandleGestureEvent(event, eventCancelled); 785 m_client->didHandleGestureEvent(event, eventCancelled);
799 return eventSwallowed; 786 return eventSwallowed;
800 } 787 }
801 788
802 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters) 789 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar ameters& parameters)
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 static bool showsHandCursor(Node* node, LocalFrame* frame) 1189 static bool showsHandCursor(Node* node, LocalFrame* frame)
1203 { 1190 {
1204 if (!node || !node->renderer()) 1191 if (!node || !node->renderer())
1205 return false; 1192 return false;
1206 1193
1207 ECursor cursor = node->renderer()->style()->cursor(); 1194 ECursor cursor = node->renderer()->style()->cursor();
1208 return cursor == CURSOR_POINTER 1195 return cursor == CURSOR_POINTER
1209 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); 1196 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink()));
1210 } 1197 }
1211 1198
1212 Node* WebViewImpl::bestTapNode(const GestureEventWithHitTestResults& targetedTap Event) 1199 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent)
1213 { 1200 {
1214 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); 1201 TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
1215 1202
1216 if (!m_page || !m_page->mainFrame()) 1203 if (!m_page || !m_page->mainFrame())
1217 return 0; 1204 return 0;
1218 1205
1219 Node* bestTouchNode = targetedTapEvent.hitTestResult().targetNode(); 1206 // FIXME: Rely on earlier hit test instead of hit testing again.
1207 GestureEventWithHitTestResults targetedEvent =
1208 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true);
1209 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode();
1220 1210
1221 // We might hit something like an image map that has no renderer on it 1211 // We might hit something like an image map that has no renderer on it
1222 // Walk up the tree until we have a node with an attached renderer 1212 // Walk up the tree until we have a node with an attached renderer
1223 while (bestTouchNode && !bestTouchNode->renderer()) 1213 while (bestTouchNode && !bestTouchNode->renderer())
1224 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode); 1214 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode);
1225 1215
1226 Node* cursorDefiningAncestor = 1216 Node* cursorDefiningAncestor =
1227 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me()); 1217 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me());
1228 // We show a highlight on tap only when the current node shows a hand cursor 1218 // We show a highlight on tap only when the current node shows a hand cursor
1229 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) { 1219 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) {
1230 return 0; 1220 return 0;
1231 } 1221 }
1232 1222
1233 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping 1223 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping
1234 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate 1224 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate
1235 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node 1225 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node
1236 // has hand cursor set. 1226 // has hand cursor set.
1237 do { 1227 do {
1238 bestTouchNode = cursorDefiningAncestor; 1228 bestTouchNode = cursorDefiningAncestor;
1239 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers al::parent(bestTouchNode), 1229 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers al::parent(bestTouchNode),
1240 m_page->deprecatedLocalMainFrame()); 1230 m_page->deprecatedLocalMainFrame());
1241 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame())); 1231 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame()));
1242 1232
1243 return bestTouchNode; 1233 return bestTouchNode;
1244 } 1234 }
1245 1235
1246 void WebViewImpl::enableTapHighlightAtPoint(const GestureEventWithHitTestResults & targetedTapEvent) 1236 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent )
1247 { 1237 {
1248 Node* touchNode = bestTapNode(targetedTapEvent); 1238 Node* touchNode = bestTapNode(tapEvent);
1249 1239
1250 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; 1240 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes;
1251 highlightNodes.append(touchNode); 1241 highlightNodes.append(touchNode);
1252 1242
1253 enableTapHighlights(highlightNodes); 1243 enableTapHighlights(highlightNodes);
1254 } 1244 }
1255 1245
1256 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes) 1246 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNodes)
1257 { 1247 {
1258 if (highlightNodes.isEmpty()) 1248 if (highlightNodes.isEmpty())
(...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4268 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4279 4269
4280 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4270 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4281 return false; 4271 return false;
4282 4272
4283 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4273 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4284 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4274 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4285 } 4275 }
4286 4276
4287 } // namespace blink 4277 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/LinkHighlightTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698