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

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

Issue 402603005: Disable touch highlight when the touched node has no hand-cursor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reverted back to last working logic 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
« no previous file with comments | « LayoutTests/compositing/gestures/gesture-tapHighlight-nested-cursor3-expected.html ('k') | no next file » | 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 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 else 1159 else
1160 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); 1160 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth);
1161 scroll.x = rect.x; 1161 scroll.x = rect.x;
1162 scroll.y = rect.y; 1162 scroll.y = rect.y;
1163 1163
1164 scale = clampPageScaleFactorToLimits(scale); 1164 scale = clampPageScaleFactorToLimits(scale);
1165 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); 1165 scroll = mainFrameImpl()->frameView()->windowToContents(scroll);
1166 scroll = clampOffsetAtScale(scroll, scale); 1166 scroll = clampOffsetAtScale(scroll, scale);
1167 } 1167 }
1168 1168
1169 static bool invokesHandCursor(Node* node, LocalFrame* frame) 1169 static Node* findCursorDefiningAncestor(Node* node, LocalFrame* frame)
1170 {
1171 // Go up the tree to find the node that defines a mouse cursor style
1172 while (node) {
1173 if (node->renderer()) {
1174 ECursor cursor = node->renderer()->style()->cursor();
1175 if (cursor != CURSOR_AUTO || frame->eventHandler().useHandCursor(nod e, node->isLink()))
1176 break;
1177 }
1178 node = node->parentNode();
Rick Byers 2014/08/15 18:03:12 Note that you lost the NodeRenderingTraversal::par
mustaq 2014/08/18 14:01:00 Ooops, seems I accidentally reverted the suggestio
1179 }
1180
1181 return node;
1182 }
1183
1184 static bool showsHandCursor(Node* node, LocalFrame* frame)
1170 { 1185 {
1171 if (!node || !node->renderer()) 1186 if (!node || !node->renderer())
1172 return false; 1187 return false;
1173 1188
1174 ECursor cursor = node->renderer()->style()->cursor(); 1189 ECursor cursor = node->renderer()->style()->cursor();
1175 return cursor == CURSOR_POINTER 1190 return cursor == CURSOR_POINTER
1176 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); 1191 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink()));
1177 } 1192 }
1178 1193
1179 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) 1194 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent)
1180 { 1195 {
1181 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); 1196 TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
1182 1197
1183 if (!m_page || !m_page->mainFrame()) 1198 if (!m_page || !m_page->mainFrame())
1184 return 0; 1199 return 0;
1185 1200
1186 Node* bestTouchNode = 0;
1187
1188 // FIXME: Rely on earlier hit test instead of hit testing again. 1201 // FIXME: Rely on earlier hit test instead of hit testing again.
1189 GestureEventWithHitTestResults targetedEvent = m_page->deprecatedLocalMainFr ame()->eventHandler().targetGestureEvent(tapEvent, true); 1202 GestureEventWithHitTestResults targetedEvent =
1190 bestTouchNode = targetedEvent.hitTestResult().targetNode(); 1203 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true);
1204 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode();
1191 1205
1192 // We might hit something like an image map that has no renderer on it 1206 // We might hit something like an image map that has no renderer on it
1193 // Walk up the tree until we have a node with an attached renderer 1207 // Walk up the tree until we have a node with an attached renderer
1194 while (bestTouchNode && !bestTouchNode->renderer()) 1208 while (bestTouchNode && !bestTouchNode->renderer())
1195 bestTouchNode = bestTouchNode->parentNode(); 1209 bestTouchNode = bestTouchNode->parentNode();
1196 1210
1197 // Check if we're in the subtree of a node with a hand cursor 1211 Node* cursorDefiningAncestor =
1198 // this is the heuristic we use to determine if we show a highlight on tap 1212 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me());
1199 while (bestTouchNode && !invokesHandCursor(bestTouchNode, m_page->deprecated LocalMainFrame())) 1213 // We show a highlight on tap only when the current node shows a hand cursor
1200 bestTouchNode = bestTouchNode->parentNode(); 1214 if (!cursorDefiningAncestor || !showsHandCursor(cursorDefiningAncestor, m_pa ge->deprecatedLocalMainFrame())) {
1215 return 0;
1216 }
1201 1217
1202 if (!bestTouchNode) 1218 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping
1203 return 0; 1219 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate
1204 1220 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node
1205 // We should pick the largest enclosing node with hand cursor set. 1221 // has hand cursor set.
1206 while (bestTouchNode->parentNode() && invokesHandCursor(bestTouchNode->paren tNode(), toLocalFrame(m_page->mainFrame()))) 1222 do {
1207 bestTouchNode = bestTouchNode->parentNode(); 1223 bestTouchNode = cursorDefiningAncestor;
1224 cursorDefiningAncestor = findCursorDefiningAncestor(bestTouchNode->paren tNode(), m_page->deprecatedLocalMainFrame());
1225 } while (cursorDefiningAncestor && showsHandCursor(cursorDefiningAncestor, m _page->deprecatedLocalMainFrame()));
1208 1226
1209 return bestTouchNode; 1227 return bestTouchNode;
1210 } 1228 }
1211 1229
1212 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) 1230 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent )
1213 { 1231 {
1214 Node* touchNode = bestTapNode(tapEvent); 1232 Node* touchNode = bestTapNode(tapEvent);
1215 1233
1216 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; 1234 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes;
1217 highlightNodes.append(touchNode); 1235 highlightNodes.append(touchNode);
(...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after
4249 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4267 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4250 4268
4251 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4269 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4252 return false; 4270 return false;
4253 4271
4254 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4272 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4255 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4273 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4256 } 4274 }
4257 4275
4258 } // namespace blink 4276 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/compositing/gestures/gesture-tapHighlight-nested-cursor3-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698