OLD | NEW |
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 Loading... |
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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 eventSwallowed = true; | 661 eventSwallowed = true; |
661 | 662 |
662 m_client->didHandleGestureEvent(event, eventCancelled); | 663 m_client->didHandleGestureEvent(event, eventCancelled); |
663 return eventSwallowed; | 664 return eventSwallowed; |
664 default: | 665 default: |
665 break; | 666 break; |
666 } | 667 } |
667 | 668 |
668 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even
t); | 669 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), even
t); |
669 | 670 |
670 // Special handling for double tap and scroll events as we don't want to | 671 // FIXME: Remove redundant hit tests by pushing the call to EventHandler::ta
rgetGestureEvent |
671 // hit test for them. | 672 // up to this point and pass GestureEventWithHitTestResults around. |
672 switch (event.type) { | |
673 case WebInputEvent::GestureDoubleTap: | |
674 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor()
!= maximumPageScaleFactor()) { | |
675 m_client->cancelScheduledContentIntents(); | |
676 animateDoubleTapZoom(platformEvent.position()); | |
677 } | |
678 // GestureDoubleTap is currently only used by Android for zooming. For W
ebCore, | |
679 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub
leTap here. | |
680 eventSwallowed = true; | |
681 m_client->didHandleGestureEvent(event, eventCancelled); | |
682 return eventSwallowed; | |
683 case WebInputEvent::GestureScrollBegin: | |
684 case WebInputEvent::GesturePinchBegin: | |
685 m_client->cancelScheduledContentIntents(); | |
686 case WebInputEvent::GestureScrollEnd: | |
687 case WebInputEvent::GestureScrollUpdate: | |
688 case WebInputEvent::GestureScrollUpdateWithoutPropagation: | |
689 case WebInputEvent::GesturePinchEnd: | |
690 case WebInputEvent::GesturePinchUpdate: | |
691 case WebInputEvent::GestureFlingStart: | |
692 // Scrolling-related gesture events invoke EventHandler recursively for
each frame down | |
693 // the chain, doing a single-frame hit-test per frame. This matches hand
leWheelEvent. | |
694 // Perhaps we could simplify things by rewriting scroll handling to work
inner frame | |
695 // out, and then unify with other gesture events. | |
696 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureS
crollEvent(platformEvent); | |
697 m_client->didHandleGestureEvent(event, eventCancelled); | |
698 return eventSwallowed; | |
699 default: | |
700 break; | |
701 } | |
702 | |
703 // Hit test across all frames and do touch adjustment as necessary for the e
vent type. | |
704 GestureEventWithHitTestResults targetedEvent = | |
705 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(pl
atformEvent); | |
706 | 673 |
707 // Handle link highlighting outside the main switch to avoid getting lost in
the | 674 // Handle link highlighting outside the main switch to avoid getting lost in
the |
708 // complicated set of cases handled below. | 675 // complicated set of cases handled below. |
709 switch (event.type) { | 676 switch (event.type) { |
710 case WebInputEvent::GestureShowPress: | 677 case WebInputEvent::GestureShowPress: |
711 // Queue a highlight animation, then hand off to regular handler. | 678 // Queue a highlight animation, then hand off to regular handler. |
712 enableTapHighlightAtPoint(targetedEvent); | 679 enableTapHighlightAtPoint(platformEvent); |
713 break; | 680 break; |
714 case WebInputEvent::GestureTapCancel: | 681 case WebInputEvent::GestureTapCancel: |
715 case WebInputEvent::GestureTap: | 682 case WebInputEvent::GestureTap: |
716 case WebInputEvent::GestureLongPress: | 683 case WebInputEvent::GestureLongPress: |
717 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 684 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
718 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); | 685 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); |
719 break; | 686 break; |
720 default: | 687 default: |
721 break; | 688 break; |
722 } | 689 } |
723 | 690 |
724 switch (event.type) { | 691 switch (event.type) { |
725 case WebInputEvent::GestureTap: { | 692 case WebInputEvent::GestureTap: { |
726 m_client->cancelScheduledContentIntents(); | 693 m_client->cancelScheduledContentIntents(); |
727 // FIXME: Use targeted event here and save another hit test. | 694 if (detectContentOnTouch(platformEvent.position())) { |
728 if (detectContentOnTouch(targetedEvent.event().position())) { | |
729 eventSwallowed = true; | 695 eventSwallowed = true; |
730 break; | 696 break; |
731 } | 697 } |
732 | 698 |
733 RefPtr<PopupContainer> selectPopup; | 699 RefPtr<PopupContainer> selectPopup; |
734 selectPopup = m_selectPopup; | 700 selectPopup = m_selectPopup; |
735 hideSelectPopup(); | 701 hideSelectPopup(); |
736 ASSERT(!m_selectPopup); | 702 ASSERT(!m_selectPopup); |
737 | 703 |
738 // Don't trigger a disambiguation popup on sites designed for mobile dev
ices. | 704 // Don't trigger a disambiguation popup on sites designed for mobile dev
ices. |
(...skipping 15 matching lines...) Expand all Loading... |
754 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT
argets(scaledEvent, goodTargets)) { | 720 if (goodTargets.size() >= 2 && m_client && m_client->didTapMultipleT
argets(scaledEvent, goodTargets)) { |
755 enableTapHighlights(highlightNodes); | 721 enableTapHighlights(highlightNodes); |
756 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 722 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
757 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); | 723 m_linkHighlights[i]->startHighlightAnimationIfNeeded(); |
758 eventSwallowed = true; | 724 eventSwallowed = true; |
759 eventCancelled = true; | 725 eventCancelled = true; |
760 break; | 726 break; |
761 } | 727 } |
762 } | 728 } |
763 | 729 |
764 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(targetedEvent); | 730 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(platformEvent); |
765 | 731 |
766 if (m_selectPopup && m_selectPopup == selectPopup) { | 732 if (m_selectPopup && m_selectPopup == selectPopup) { |
767 // That tap triggered a select popup which is the same as the one th
at | 733 // That tap triggered a select popup which is the same as the one th
at |
768 // was showing before the tap. It means the user tapped the select | 734 // was showing before the tap. It means the user tapped the select |
769 // while the popup was showing, and as a result we first closed then | 735 // while the popup was showing, and as a result we first closed then |
770 // immediately reopened the select popup. It needs to be closed. | 736 // immediately reopened the select popup. It needs to be closed. |
771 hideSelectPopup(); | 737 hideSelectPopup(); |
772 } | 738 } |
773 | 739 |
774 break; | 740 break; |
775 } | 741 } |
776 case WebInputEvent::GestureTwoFingerTap: | 742 case WebInputEvent::GestureTwoFingerTap: |
777 case WebInputEvent::GestureLongPress: | 743 case WebInputEvent::GestureLongPress: |
778 case WebInputEvent::GestureLongTap: { | 744 case WebInputEvent::GestureLongTap: { |
779 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 745 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
780 break; | 746 break; |
781 | 747 |
782 m_client->cancelScheduledContentIntents(); | 748 m_client->cancelScheduledContentIntents(); |
783 m_page->contextMenuController().clearContextMenu(); | 749 m_page->contextMenuController().clearContextMenu(); |
784 m_contextMenuAllowed = true; | 750 m_contextMenuAllowed = true; |
785 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(targetedEvent); | 751 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(platformEvent); |
786 m_contextMenuAllowed = false; | 752 m_contextMenuAllowed = false; |
787 | 753 |
788 break; | 754 break; |
789 } | 755 } |
790 case WebInputEvent::GestureShowPress: | 756 case WebInputEvent::GestureShowPress: { |
| 757 m_client->cancelScheduledContentIntents(); |
| 758 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(platformEvent); |
| 759 break; |
| 760 } |
| 761 case WebInputEvent::GestureDoubleTap: |
| 762 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor()
!= maximumPageScaleFactor()) { |
| 763 m_client->cancelScheduledContentIntents(); |
| 764 animateDoubleTapZoom(platformEvent.position()); |
| 765 } |
| 766 // GestureDoubleTap is currently only used by Android for zooming. For W
ebCore, |
| 767 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub
leTap here. |
| 768 eventSwallowed = true; |
| 769 break; |
| 770 case WebInputEvent::GestureScrollBegin: |
| 771 case WebInputEvent::GesturePinchBegin: |
791 m_client->cancelScheduledContentIntents(); | 772 m_client->cancelScheduledContentIntents(); |
792 case WebInputEvent::GestureTapDown: | 773 case WebInputEvent::GestureTapDown: |
| 774 case WebInputEvent::GestureScrollEnd: |
| 775 case WebInputEvent::GestureScrollUpdate: |
| 776 case WebInputEvent::GestureScrollUpdateWithoutPropagation: |
793 case WebInputEvent::GestureTapCancel: | 777 case WebInputEvent::GestureTapCancel: |
794 case WebInputEvent::GestureTapUnconfirmed: { | 778 case WebInputEvent::GestureTapUnconfirmed: |
795 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(targetedEvent); | 779 case WebInputEvent::GesturePinchEnd: |
| 780 case WebInputEvent::GesturePinchUpdate: |
| 781 case WebInputEvent::GestureFlingStart: { |
| 782 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureE
vent(platformEvent); |
796 break; | 783 break; |
797 } | 784 } |
798 default: | 785 default: |
799 ASSERT_NOT_REACHED(); | 786 ASSERT_NOT_REACHED(); |
800 } | 787 } |
801 m_client->didHandleGestureEvent(event, eventCancelled); | 788 m_client->didHandleGestureEvent(event, eventCancelled); |
802 return eventSwallowed; | 789 return eventSwallowed; |
803 } | 790 } |
804 | 791 |
805 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar
ameters& parameters) | 792 void WebViewImpl::transferActiveWheelFlingAnimation(const WebActiveWheelFlingPar
ameters& parameters) |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 static bool showsHandCursor(Node* node, LocalFrame* frame) | 1195 static bool showsHandCursor(Node* node, LocalFrame* frame) |
1209 { | 1196 { |
1210 if (!node || !node->renderer()) | 1197 if (!node || !node->renderer()) |
1211 return false; | 1198 return false; |
1212 | 1199 |
1213 ECursor cursor = node->renderer()->style()->cursor(); | 1200 ECursor cursor = node->renderer()->style()->cursor(); |
1214 return cursor == CURSOR_POINTER | 1201 return cursor == CURSOR_POINTER |
1215 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n
ode->isLink())); | 1202 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n
ode->isLink())); |
1216 } | 1203 } |
1217 | 1204 |
1218 Node* WebViewImpl::bestTapNode(const GestureEventWithHitTestResults& targetedTap
Event) | 1205 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) |
1219 { | 1206 { |
1220 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); | 1207 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); |
1221 | 1208 |
1222 if (!m_page || !m_page->mainFrame()) | 1209 if (!m_page || !m_page->mainFrame()) |
1223 return 0; | 1210 return 0; |
1224 | 1211 |
1225 Node* bestTouchNode = targetedTapEvent.hitTestResult().targetNode(); | 1212 // FIXME: Rely on earlier hit test instead of hit testing again. |
| 1213 GestureEventWithHitTestResults targetedEvent = |
| 1214 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta
pEvent, true); |
| 1215 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode(); |
1226 | 1216 |
1227 // We might hit something like an image map that has no renderer on it | 1217 // We might hit something like an image map that has no renderer on it |
1228 // Walk up the tree until we have a node with an attached renderer | 1218 // Walk up the tree until we have a node with an attached renderer |
1229 // FIXME: This wants to walk composed tree with NodeRenderingTraversal::pare
nt(). | 1219 // FIXME: This wants to walk composed tree with NodeRenderingTraversal::pare
nt(). |
1230 while (bestTouchNode && !bestTouchNode->renderer()) | 1220 while (bestTouchNode && !bestTouchNode->renderer()) |
1231 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode); | 1221 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode); |
1232 | 1222 |
1233 Node* cursorDefiningAncestor = | 1223 Node* cursorDefiningAncestor = |
1234 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra
me()); | 1224 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra
me()); |
1235 // We show a highlight on tap only when the current node shows a hand cursor | 1225 // We show a highlight on tap only when the current node shows a hand cursor |
1236 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa
ge->deprecatedLocalMainFrame())) { | 1226 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa
ge->deprecatedLocalMainFrame())) { |
1237 return 0; | 1227 return 0; |
1238 } | 1228 } |
1239 | 1229 |
1240 // We should pick the largest enclosing node with hand cursor set. We do thi
s by first jumping | 1230 // We should pick the largest enclosing node with hand cursor set. We do thi
s by first jumping |
1241 // up to cursorDefiningAncestor (which is already known to have hand cursor
set). Then we locate | 1231 // up to cursorDefiningAncestor (which is already known to have hand cursor
set). Then we locate |
1242 // the next cursor-defining ancestor up in the the tree and repeat the jumps
as long as the node | 1232 // the next cursor-defining ancestor up in the the tree and repeat the jumps
as long as the node |
1243 // has hand cursor set. | 1233 // has hand cursor set. |
1244 do { | 1234 do { |
1245 bestTouchNode = cursorDefiningAncestor; | 1235 bestTouchNode = cursorDefiningAncestor; |
1246 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers
al::parent(bestTouchNode), | 1236 cursorDefiningAncestor = findCursorDefiningAncestor(NodeRenderingTravers
al::parent(bestTouchNode), |
1247 m_page->deprecatedLocalMainFrame()); | 1237 m_page->deprecatedLocalMainFrame()); |
1248 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m
_page->deprecatedLocalMainFrame())); | 1238 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m
_page->deprecatedLocalMainFrame())); |
1249 | 1239 |
1250 return bestTouchNode; | 1240 return bestTouchNode; |
1251 } | 1241 } |
1252 | 1242 |
1253 void WebViewImpl::enableTapHighlightAtPoint(const GestureEventWithHitTestResults
& targetedTapEvent) | 1243 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent
) |
1254 { | 1244 { |
1255 Node* touchNode = bestTapNode(targetedTapEvent); | 1245 Node* touchNode = bestTapNode(tapEvent); |
1256 | 1246 |
1257 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; | 1247 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; |
1258 highlightNodes.append(touchNode); | 1248 highlightNodes.append(touchNode); |
1259 | 1249 |
1260 enableTapHighlights(highlightNodes); | 1250 enableTapHighlights(highlightNodes); |
1261 } | 1251 } |
1262 | 1252 |
1263 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node>
>& highlightNodes) | 1253 void WebViewImpl::enableTapHighlights(WillBeHeapVector<RawPtrWillBeMember<Node>
>& highlightNodes) |
1264 { | 1254 { |
1265 if (highlightNodes.isEmpty()) | 1255 if (highlightNodes.isEmpty()) |
(...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4288 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4278 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4289 | 4279 |
4290 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4280 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4291 return false; | 4281 return false; |
4292 | 4282 |
4293 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4283 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4294 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4284 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4295 } | 4285 } |
4296 | 4286 |
4297 } // namespace blink | 4287 } // namespace blink |
OLD | NEW |