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 bool currentIsOverLink = tapIsOverLink; |
1210 | 1205 |
| 1206 Node* currentNode = NodeRenderingTraversal::parent(largestHandCursorNode); |
| 1207 while (currentNode) { |
| 1208 if (largestHandCursorNode->isLink() && !currentNode->isLink()) |
| 1209 currentIsOverLink = false; |
| 1210 |
| 1211 if (!showsHandCursor(currentNode, toLocalFrame(m_page->mainFrame()), cur
rentIsOverLink)) |
| 1212 return largestHandCursorNode; |
| 1213 |
| 1214 largestHandCursorNode = currentNode; |
| 1215 currentNode = NodeRenderingTraversal::parent(largestHandCursorNode); |
| 1216 } |
| 1217 |
| 1218 // Otherwise, bestTouchNode is an image map w/o an enclosing anchor tag. |
| 1219 largestHandCursorNode = bestTouchNode; |
| 1220 currentIsOverLink = tapIsOverLink; |
| 1221 |
| 1222 currentNode = NodeRenderingTraversal::parent(largestHandCursorNode); |
| 1223 while (currentNode) { |
| 1224 if (isHTMLMapElement(largestHandCursorNode) && !isHTMLMapElement(current
Node)) |
| 1225 currentIsOverLink = false; |
| 1226 |
| 1227 if (!showsHandCursor(currentNode, toLocalFrame(m_page->mainFrame()), cur
rentIsOverLink)) |
| 1228 return largestHandCursorNode; |
| 1229 |
| 1230 largestHandCursorNode = currentNode; |
| 1231 currentNode = NodeRenderingTraversal::parent(largestHandCursorNode); |
| 1232 } |
| 1233 |
| 1234 // Couldn't find a parent without a hand cursor |
1211 return bestTouchNode; | 1235 return bestTouchNode; |
1212 } | 1236 } |
1213 | 1237 |
1214 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent
) | 1238 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent
) |
1215 { | 1239 { |
1216 Node* touchNode = bestTapNode(tapEvent); | 1240 Node* touchNode = bestTapNode(tapEvent); |
1217 | 1241 |
1218 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; | 1242 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; |
1219 highlightNodes.append(touchNode); | 1243 highlightNodes.append(touchNode); |
1220 | 1244 |
(...skipping 3010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4231 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4255 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4232 | 4256 |
4233 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4257 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4234 return false; | 4258 return false; |
4235 | 4259 |
4236 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4260 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4237 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4261 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4238 } | 4262 } |
4239 | 4263 |
4240 } // namespace blink | 4264 } // namespace blink |
OLD | NEW |