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 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 else | 1163 else |
1164 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); | 1164 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); |
1165 scroll.x = rect.x; | 1165 scroll.x = rect.x; |
1166 scroll.y = rect.y; | 1166 scroll.y = rect.y; |
1167 | 1167 |
1168 scale = clampPageScaleFactorToLimits(scale); | 1168 scale = clampPageScaleFactorToLimits(scale); |
1169 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); | 1169 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); |
1170 scroll = clampOffsetAtScale(scroll, scale); | 1170 scroll = clampOffsetAtScale(scroll, scale); |
1171 } | 1171 } |
1172 | 1172 |
1173 static Node* findCursorDefiningAncestor(Node* node, LocalFrame* frame) | |
1174 { | |
1175 // Go up the tree to find the node that defines a mouse cursor style | |
1176 while (node) { | |
1177 // If the current node has an attached renderer, check the cursor. Other wise, go up. | |
1178 if (node->renderer()) { | |
1179 ECursor cursor = node->renderer()->style()->cursor(); | |
1180 if (cursor != CURSOR_AUTO || frame->eventHandler().useHandCursor(nod e, node->isLink())) | |
1181 break; | |
1182 } | |
1183 node = node->parentNode(); | |
1184 } | |
1185 | |
1186 return node; | |
1187 } | |
1188 | |
1173 static bool invokesHandCursor(Node* node, LocalFrame* frame) | 1189 static bool invokesHandCursor(Node* node, LocalFrame* frame) |
1174 { | 1190 { |
1175 if (!node || !node->renderer()) | 1191 if (!node || !node->renderer()) |
1176 return false; | 1192 return false; |
1177 | 1193 |
1178 ECursor cursor = node->renderer()->style()->cursor(); | 1194 ECursor cursor = node->renderer()->style()->cursor(); |
1179 return cursor == CURSOR_POINTER | 1195 return cursor == CURSOR_POINTER |
1180 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); | 1196 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); |
1181 } | 1197 } |
1182 | 1198 |
1183 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) | 1199 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) |
1184 { | 1200 { |
1185 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); | 1201 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); |
1186 | 1202 |
1187 if (!m_page || !m_page->mainFrame()) | 1203 if (!m_page || !m_page->mainFrame()) |
1188 return 0; | 1204 return 0; |
1189 | 1205 |
1190 Node* bestTouchNode = 0; | |
1191 | |
1192 // FIXME: Rely on earlier hit test instead of hit testing again. | 1206 // FIXME: Rely on earlier hit test instead of hit testing again. |
1193 GestureEventWithHitTestResults targetedEvent = m_page->deprecatedLocalMainFr ame()->eventHandler().targetGestureEvent(tapEvent, true); | 1207 GestureEventWithHitTestResults targetedEvent = |
1194 bestTouchNode = targetedEvent.hitTestResult().targetNode(); | 1208 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true); |
1209 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode(); | |
1195 | 1210 |
1196 // We might hit something like an image map that has no renderer on it | 1211 // We might hit something like an image map that has no renderer on it |
1197 // Walk up the tree until we have a node with an attached renderer | 1212 // Walk up the tree until we have a node with an attached renderer |
1198 while (bestTouchNode && !bestTouchNode->renderer()) | 1213 while (bestTouchNode && !bestTouchNode->renderer()) |
1199 bestTouchNode = bestTouchNode->parentNode(); | 1214 bestTouchNode = bestTouchNode->parentNode(); |
1200 | 1215 |
1201 // Check if we're in the subtree of a node with a hand cursor | 1216 Node* cursorDefiningAncestor = |
1202 // this is the heuristic we use to determine if we show a highlight on tap | 1217 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me()); |
1203 while (bestTouchNode && !invokesHandCursor(bestTouchNode, m_page->deprecated LocalMainFrame())) | 1218 // We show a highlight on tap only when the current node shows a hand cursor |
1204 bestTouchNode = bestTouchNode->parentNode(); | 1219 if (!cursorDefiningAncestor || !invokesHandCursor(cursorDefiningAncestor, m_ page->deprecatedLocalMainFrame())) { |
1220 return 0; | |
1221 } | |
1205 | 1222 |
1206 if (!bestTouchNode) | 1223 // We should pick the largest enclosing node with hand cursor set |
1207 return 0; | 1224 do { |
1208 | 1225 bestTouchNode = cursorDefiningAncestor; |
wjmaclean
2014/07/22 20:34:12
The logic may be correct, but the back-and-forth b
mustaq
2014/07/23 21:12:10
Done.
| |
1209 // We should pick the largest enclosing node with hand cursor set. | 1226 cursorDefiningAncestor = findCursorDefiningAncestor(bestTouchNode->paren tNode(), m_page->deprecatedLocalMainFrame()); |
1210 while (bestTouchNode->parentNode() && invokesHandCursor(bestTouchNode->paren tNode(), toLocalFrame(m_page->mainFrame()))) | 1227 } while (cursorDefiningAncestor && invokesHandCursor(cursorDefiningAncestor, m_page->deprecatedLocalMainFrame())); |
1211 bestTouchNode = bestTouchNode->parentNode(); | |
1212 | 1228 |
1213 return bestTouchNode; | 1229 return bestTouchNode; |
1214 } | 1230 } |
1215 | 1231 |
1216 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) | 1232 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) |
1217 { | 1233 { |
1218 Node* touchNode = bestTapNode(tapEvent); | 1234 Node* touchNode = bestTapNode(tapEvent); |
1219 | 1235 |
1220 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; | 1236 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; |
1221 highlightNodes.append(touchNode); | 1237 highlightNodes.append(touchNode); |
(...skipping 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4239 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); | 4255 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); |
4240 | 4256 |
4241 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4257 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4242 return false; | 4258 return false; |
4243 | 4259 |
4244 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4260 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4245 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); | 4261 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); |
4246 } | 4262 } |
4247 | 4263 |
4248 } // namespace blink | 4264 } // namespace blink |
OLD | NEW |