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 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 else | 1161 else |
1162 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); | 1162 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); |
1163 scroll.x = rect.x; | 1163 scroll.x = rect.x; |
1164 scroll.y = rect.y; | 1164 scroll.y = rect.y; |
1165 | 1165 |
1166 scale = clampPageScaleFactorToLimits(scale); | 1166 scale = clampPageScaleFactorToLimits(scale); |
1167 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); | 1167 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); |
1168 scroll = clampOffsetAtScale(scroll, scale); | 1168 scroll = clampOffsetAtScale(scroll, scale); |
1169 } | 1169 } |
1170 | 1170 |
1171 static bool invokesHandCursor(Node* node, LocalFrame* frame) | 1171 static bool showsHandCursor(Node* node, LocalFrame* frame, bool isOverLink) |
1172 { | 1172 { |
1173 if (!node || !node->renderer()) | 1173 if (!node || !node->renderer()) |
1174 return false; | 1174 return false; |
1175 | 1175 |
1176 ECursor cursor = node->renderer()->style()->cursor(); | 1176 ECursor cursor = node->renderer()->style()->cursor(); |
1177 return cursor == CURSOR_POINTER | 1177 return cursor == CURSOR_POINTER |
1178 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); | 1178 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, i sOverLink)); |
1179 } | 1179 } |
1180 | 1180 |
1181 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) | 1181 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) |
1182 { | 1182 { |
1183 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); | 1183 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); |
1184 | 1184 |
1185 if (!m_page || !m_page->mainFrame()) | 1185 if (!m_page || !m_page->mainFrame()) |
1186 return 0; | 1186 return 0; |
1187 | 1187 |
1188 Node* bestTouchNode = 0; | 1188 // FIXME: Rely on earlier hit test instead of hit testing again. |
1189 GestureEventWithHitTestResults targetedEvent = | |
1190 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true); | |
1191 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode(); | |
1192 bool tapIsOverLink = targetedEvent.hitTestResult().isOverLink(); | |
1189 | 1193 |
1190 // FIXME: Rely on earlier hit test instead of hit testing again. | 1194 // Walk up the tree until we have an element node with an attached renderer |
1191 GestureEventWithHitTestResults targetedEvent = m_page->deprecatedLocalMainFr ame()->eventHandler().targetGestureEvent(tapEvent, true); | 1195 while (bestTouchNode && (!bestTouchNode->isElementNode() || !bestTouchNode-> renderer())) |
1192 bestTouchNode = targetedEvent.hitTestResult().targetNode(); | 1196 bestTouchNode = NodeRenderingTraversal::parent(bestTouchNode); |
1193 | 1197 |
1194 // We might hit something like an image map that has no renderer on it | 1198 // We show a highlight on tap only when the current node shows a hand cursor |
1195 // Walk up the tree until we have a node with an attached renderer | 1199 if (!showsHandCursor(bestTouchNode, m_page->deprecatedLocalMainFrame(), tapI sOverLink)) |
1196 while (bestTouchNode && !bestTouchNode->renderer()) | |
1197 bestTouchNode = bestTouchNode->parentNode(); | |
1198 | |
1199 // Check if we're in the subtree of a node with a hand cursor | |
1200 // this is the heuristic we use to determine if we show a highlight on tap | |
1201 while (bestTouchNode && !invokesHandCursor(bestTouchNode, m_page->deprecated LocalMainFrame())) | |
1202 bestTouchNode = bestTouchNode->parentNode(); | |
1203 | |
1204 if (!bestTouchNode) | |
1205 return 0; | 1200 return 0; |
1206 | 1201 |
1207 // We should pick the largest enclosing node with hand cursor set. | 1202 // Find the largest enclosing node with a hand cursor set |
1208 while (bestTouchNode->parentNode() && invokesHandCursor(bestTouchNode->paren tNode(), toLocalFrame(m_page->mainFrame()))) | 1203 Node* largestHandCursorNode = bestTouchNode; |
1209 bestTouchNode = bestTouchNode->parentNode(); | 1204 Node* currentNode; |
1205 bool currentIsOverLink = tapIsOverLink; | |
1206 while ((currentNode = NodeRenderingTraversal::parent(largestHandCursorNode)) ) { | |
Rick Byers
2014/07/31 20:15:10
d'oh - looks like my suggestion to remove the '!=
mustaq
2014/07/31 21:04:48
Yeah, the msvc failures plus the style requirement
| |
1207 if (largestHandCursorNode->isLink() && !currentNode->isLink()) | |
1208 currentIsOverLink = false; | |
1210 | 1209 |
1210 if (!showsHandCursor(currentNode, toLocalFrame(m_page->mainFrame()), cur rentIsOverLink)) | |
1211 break; | |
Rick Byers
2014/07/31 20:15:10
nit: rather than break and test below, you can sim
mustaq
2014/07/31 21:04:48
Done, thanks.
| |
1212 | |
1213 largestHandCursorNode = currentNode; | |
1214 } | |
1215 | |
1216 if (currentNode) | |
1217 return largestHandCursorNode; | |
1218 | |
1219 // Otherwise, bestTouchNode is an image map w/o an enclosing anchor tag. | |
Rick Byers
2014/07/31 20:15:10
Ah, interesting. Doing another pass like this see
mustaq
2014/07/31 21:04:48
HitTestResult::isOverLink() returns true for both
| |
1220 largestHandCursorNode = bestTouchNode; | |
1221 currentIsOverLink = tapIsOverLink; | |
1222 while ((currentNode = NodeRenderingTraversal::parent(largestHandCursorNode)) ) { | |
1223 if (isHTMLMapElement(largestHandCursorNode) && !isHTMLMapElement(current Node)) | |
1224 currentIsOverLink = false; | |
1225 | |
1226 if (!showsHandCursor(currentNode, toLocalFrame(m_page->mainFrame()), cur rentIsOverLink)) | |
1227 break; | |
Rick Byers
2014/07/31 20:15:10
same as above
mustaq
2014/07/31 21:04:48
Done.
| |
1228 | |
1229 largestHandCursorNode = currentNode; | |
1230 } | |
1231 | |
1232 if (currentNode) | |
1233 return largestHandCursorNode; | |
1234 | |
1235 // Couldn't find a parent with a hand cursor | |
Rick Byers
2014/07/31 20:15:10
nit: you mean 'without' not 'with', right?
mustaq
2014/07/31 21:04:48
Good catch!
| |
1211 return bestTouchNode; | 1236 return bestTouchNode; |
1212 } | 1237 } |
1213 | 1238 |
1214 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) | 1239 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) |
1215 { | 1240 { |
1216 Node* touchNode = bestTapNode(tapEvent); | 1241 Node* touchNode = bestTapNode(tapEvent); |
1217 | 1242 |
1218 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; | 1243 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; |
1219 highlightNodes.append(touchNode); | 1244 highlightNodes.append(touchNode); |
1220 | 1245 |
(...skipping 3010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4231 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); | 4256 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); |
4232 | 4257 |
4233 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4258 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4234 return false; | 4259 return false; |
4235 | 4260 |
4236 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4261 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4237 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); | 4262 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); |
4238 } | 4263 } |
4239 | 4264 |
4240 } // namespace blink | 4265 } // namespace blink |
OLD | NEW |