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 Node* findCursorDefiningAncestor(Node* node, LocalFrame* frame) | |
1172 { | |
1173 // Go up the tree to find the node that defines a mouse cursor style | |
1174 while (node) { | |
1175 // If the current node has an attached renderer, check the cursor. Other wise, go up. | |
Rick Byers
2014/07/24 18:29:36
I'd omit this comment - the code says this very cl
mustaq
2014/07/29 18:34:50
Done.
| |
1176 if (node->renderer()) { | |
1177 ECursor cursor = node->renderer()->style()->cursor(); | |
1178 if (cursor != CURSOR_AUTO || frame->eventHandler().useHandCursor(nod e, node->isLink())) | |
Rick Byers
2014/07/24 18:29:36
I don't think this is right. If a node explicitly
mustaq
2014/07/29 18:34:50
After some experiment based on yours, it seems tha
mustaq
2014/08/08 18:24:53
After fixing the test failures caused by changes i
| |
1179 break; | |
1180 } | |
1181 node = node->parentNode(); | |
1182 } | |
1183 | |
1184 return node; | |
1185 } | |
1186 | |
1171 static bool invokesHandCursor(Node* node, LocalFrame* frame) | 1187 static bool invokesHandCursor(Node* node, LocalFrame* frame) |
1172 { | 1188 { |
1173 if (!node || !node->renderer()) | 1189 if (!node || !node->renderer()) |
1174 return false; | 1190 return false; |
1175 | 1191 |
1176 ECursor cursor = node->renderer()->style()->cursor(); | 1192 ECursor cursor = node->renderer()->style()->cursor(); |
1177 return cursor == CURSOR_POINTER | 1193 return cursor == CURSOR_POINTER |
1178 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); | 1194 || (cursor == CURSOR_AUTO && frame->eventHandler().useHandCursor(node, n ode->isLink())); |
1179 } | 1195 } |
1180 | 1196 |
1181 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) | 1197 Node* WebViewImpl::bestTapNode(const PlatformGestureEvent& tapEvent) |
1182 { | 1198 { |
1183 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); | 1199 TRACE_EVENT0("input", "WebViewImpl::bestTapNode"); |
1184 | 1200 |
1185 if (!m_page || !m_page->mainFrame()) | 1201 if (!m_page || !m_page->mainFrame()) |
1186 return 0; | 1202 return 0; |
1187 | 1203 |
1188 Node* bestTouchNode = 0; | |
1189 | |
1190 // FIXME: Rely on earlier hit test instead of hit testing again. | 1204 // FIXME: Rely on earlier hit test instead of hit testing again. |
1191 GestureEventWithHitTestResults targetedEvent = m_page->deprecatedLocalMainFr ame()->eventHandler().targetGestureEvent(tapEvent, true); | 1205 GestureEventWithHitTestResults targetedEvent = |
1192 bestTouchNode = targetedEvent.hitTestResult().targetNode(); | 1206 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(ta pEvent, true); |
1207 Node* bestTouchNode = targetedEvent.hitTestResult().targetNode(); | |
1193 | 1208 |
1194 // We might hit something like an image map that has no renderer on it | 1209 // We might hit something like an image map that has no renderer on it |
1195 // Walk up the tree until we have a node with an attached renderer | 1210 // Walk up the tree until we have a node with an attached renderer |
1196 while (bestTouchNode && !bestTouchNode->renderer()) | 1211 while (bestTouchNode && !bestTouchNode->renderer()) |
1197 bestTouchNode = bestTouchNode->parentNode(); | 1212 bestTouchNode = bestTouchNode->parentNode(); |
1198 | 1213 |
1199 // Check if we're in the subtree of a node with a hand cursor | 1214 Node* cursorDefiningAncestor = |
1200 // this is the heuristic we use to determine if we show a highlight on tap | 1215 findCursorDefiningAncestor(bestTouchNode, m_page->deprecatedLocalMainFra me()); |
1201 while (bestTouchNode && !invokesHandCursor(bestTouchNode, m_page->deprecated LocalMainFrame())) | 1216 // We show a highlight on tap only when the current node shows a hand cursor |
1202 bestTouchNode = bestTouchNode->parentNode(); | 1217 if (!cursorDefiningAncestor || !invokesHandCursor(cursorDefiningAncestor, m_ page->deprecatedLocalMainFrame())) { |
1218 return 0; | |
1219 } | |
1203 | 1220 |
1204 if (!bestTouchNode) | 1221 // We should pick the largest enclosing node with hand cursor set. We do thi s by first jumping |
1205 return 0; | 1222 // up to cursorDefiningAncestor (which is already known to have hand cursor set). Then we locate |
1206 | 1223 // the next cursor-defining ancestor up in the the tree and repeat the jumps as long as the node |
1207 // We should pick the largest enclosing node with hand cursor set. | 1224 // has hand cursor set. |
1208 while (bestTouchNode->parentNode() && invokesHandCursor(bestTouchNode->paren tNode(), toLocalFrame(m_page->mainFrame()))) | 1225 do { |
1209 bestTouchNode = bestTouchNode->parentNode(); | 1226 bestTouchNode = cursorDefiningAncestor; |
1227 cursorDefiningAncestor = findCursorDefiningAncestor(bestTouchNode->paren tNode(), m_page->deprecatedLocalMainFrame()); | |
1228 } while (cursorDefiningAncestor && invokesHandCursor(cursorDefiningAncestor, m_page->deprecatedLocalMainFrame())); | |
1210 | 1229 |
1211 return bestTouchNode; | 1230 return bestTouchNode; |
1212 } | 1231 } |
1213 | 1232 |
1214 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) | 1233 void WebViewImpl::enableTapHighlightAtPoint(const PlatformGestureEvent& tapEvent ) |
1215 { | 1234 { |
1216 Node* touchNode = bestTapNode(tapEvent); | 1235 Node* touchNode = bestTapNode(tapEvent); |
1217 | 1236 |
1218 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; | 1237 WillBeHeapVector<RawPtrWillBeMember<Node> > highlightNodes; |
1219 highlightNodes.append(touchNode); | 1238 highlightNodes.append(touchNode); |
(...skipping 3014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4234 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); | 4253 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); |
4235 | 4254 |
4236 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4255 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4237 return false; | 4256 return false; |
4238 | 4257 |
4239 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4258 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4240 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); | 4259 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); |
4241 } | 4260 } |
4242 | 4261 |
4243 } // namespace blink | 4262 } // namespace blink |
OLD | NEW |