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

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: Fixed logic with all tests passing. 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
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 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 else 1162 else
1163 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); 1163 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth);
1164 scroll.x = rect.x; 1164 scroll.x = rect.x;
1165 scroll.y = rect.y; 1165 scroll.y = rect.y;
1166 1166
1167 scale = clampPageScaleFactorToLimits(scale); 1167 scale = clampPageScaleFactorToLimits(scale);
1168 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); 1168 scroll = mainFrameImpl()->frameView()->windowToContents(scroll);
1169 scroll = clampOffsetAtScale(scroll, scale); 1169 scroll = clampOffsetAtScale(scroll, scale);
1170 } 1170 }
1171 1171
1172 static bool invokesHandCursor(Node* node, LocalFrame* frame) 1172 static bool showsHandCursor(Node* node, LocalFrame* frame, bool isOverLink)
1173 { 1173 {
1174 if (!node || !node->renderer()) 1174 if (!node || !node->renderer())
1175 return false; 1175 return false;
1176 1176
1177 ECursor cursor = node->renderer()->style()->cursor(); 1177 ECursor cursor = node->renderer()->style()->cursor();
1178 return cursor == CURSOR_POINTER 1178 return cursor == CURSOR_POINTER
1179 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); 1179 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, i sOverLink));
1180 } 1180 }
1181 1181
1182 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) 1182 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent)
1183 { 1183 {
1184 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); 1184 TRACE_EVENT0("input", "WebViewImpl::bestTapNode");
1185 1185
1186 if (!m_page || !m_page->mainFrame()) 1186 if (!m_page || !m_page->mainFrame())
1187 return 0; 1187 return 0;
1188 1188
1189 Node* bestTouchNode = 0; 1189 // FIXME: Rely on earlier hit test instead of hit testing again.
1190 GestureEventWithHitTestResults targetedEvent =
1191 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true);
1192 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode();
1193 bool isOverLink = targetedEvent.hitTestResult().isOverLink();
1190 1194
1191 // FIXME: Rely on earlier hit test instead of hit testing again. 1195 // Walk up the tree until we have an element node with an attached renderer
1192 GestureEventWithHitTestResults targetedEvent = m_page->deprecatedLocalMainFr ame()->eventHandler().targetGestureEvent(tapEvent, true); 1196 while (bestTouchNode && (!bestTouchNode->isElementNode() || !bestTouchNode-> renderer()))
1193 bestTouchNode = targetedEvent.hitTestResult().targetNode();
1194
1195 // We might hit something like an image map that has no renderer on it
1196 // Walk up the tree until we have a node with an attached renderer
1197 while (bestTouchNode && !bestTouchNode->renderer())
1198 bestTouchNode = bestTouchNode->parentNode(); 1197 bestTouchNode = bestTouchNode->parentNode();
1199 1198
1200 // Check if we're in the subtree of a node with a hand cursor 1199 // We show a highlight on tap only when the current node shows a hand cursor
1201 // this is the heuristic we use to determine if we show a highlight on tap 1200 if (!showsHandCursor(bestTouchNode, m_page->deprecatedLocalMainFrame(), isOv erLink)) {
Rick Byers 2014/07/30 15:35:51 nit: omit braces for single-line if (http://www.ch
mustaq 2014/07/30 16:40:44 Done.
1202 while (bestTouchNode && !invokesHandCursor(bestTouchNode, m_page->deprecated LocalMainFrame())) 1201 return 0;
1203 bestTouchNode = bestTouchNode->parentNode(); 1202 }
1204 1203
1205 if (!bestTouchNode) 1204 // We should pick the largest enclosing node with a hand cursor set.
1206 return 0; 1205 Node* parentNode;
1207 1206 while ((parentNode = bestTouchNode->parentNode()) != 0) {
Rick Byers 2014/07/30 15:35:51 style nit: don't explicitly compare pointers to 0,
Rick Byers 2014/07/30 15:35:52 minor issue I should have mentioned earlier: pleas
mustaq 2014/07/30 16:40:44 Missed this, sorry. I wanted to avoid double-paren
mustaq 2014/07/30 16:40:44 Done fixing this method. Not sure what other thin
Rick Byers 2014/07/30 17:50:28 No, I just meant in this method (on this line, and
1208 // We should pick the largest enclosing node with hand cursor set. 1207 if (bestTouchNode->isLink() && !parentNode->isLink())
Rick Byers 2014/07/30 15:35:51 Note the impact here on this case (which we should
mustaq 2014/07/30 16:40:44 Acknowledged.
mustaq 2014/07/31 19:29:55 Added a test for this. On 2014/07/30 15:35:51, Ri
1209 while (bestTouchNode->parentNode() && invokesHandCursor(bestTouchNode->paren tNode(), toLocalFrame(m_page->mainFrame()))) 1208 break;
1210 bestTouchNode = bestTouchNode->parentNode(); 1209 if (!showsHandCursor(parentNode, toLocalFrame(m_page->mainFrame()), pare ntNode->isLink()))
Rick Byers 2014/07/30 15:35:51 What about a case like this: <a> <span>My <b>li
mustaq 2014/07/30 16:40:45 Using isOverLink here instead of parentNode->isLin
Rick Byers 2014/07/30 17:50:28 Oh, interesting. Note that there's a TODO in that
1210 break;
1211 bestTouchNode = parentNode;
1212 }
1211 1213
1212 return bestTouchNode; 1214 return bestTouchNode;
1213 } 1215 }
1214 1216
1215 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) 1217 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent )
1216 { 1218 {
1217 Node* touchNode = bestTapNode(tapEvent); 1219 Node* touchNode = bestTapNode(tapEvent);
1218 1220
1219 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; 1221 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes;
1220 highlightNodes.append(touchNode); 1222 highlightNodes.append(touchNode);
(...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4240 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4242 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4241 4243
4242 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4244 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4243 return false; 4245 return false;
4244 4246
4245 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4247 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4246 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4248 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4247 } 4249 }
4248 4250
4249 } // namespace blink 4251 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698