| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 Node* node = eventNode; | 56 Node* node = eventNode; |
| 57 while (node) { | 57 while (node) { |
| 58 // Skip the whole sub-tree if the node doesn't propagate events. | 58 // Skip the whole sub-tree if the node doesn't propagate events. |
| 59 if (node != eventNode && node->willRespondToMouseClickEvents()) { | 59 if (node != eventNode && node->willRespondToMouseClickEvents()) { |
| 60 node = NodeTraversal::nextSkippingChildren(*node, eventNode); | 60 node = NodeTraversal::nextSkippingChildren(*node, eventNode); |
| 61 continue; | 61 continue; |
| 62 } | 62 } |
| 63 result.unite(node->pixelSnappedBoundingBox()); | 63 result.unite(node->pixelSnappedBoundingBox()); |
| 64 node = NodeTraversal::next(*node, eventNode); | 64 node = NodeTraversal::next(*node, eventNode); |
| 65 } | 65 } |
| 66 return eventNode->document().view()->contentsToWindow(result); | 66 return eventNode->document().view()->contentsToRootFrame(result); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static float scoreTouchTarget(IntPoint touchPoint, int padding, IntRect bounding
Box) | 69 static float scoreTouchTarget(IntPoint touchPoint, int padding, IntRect bounding
Box) |
| 70 { | 70 { |
| 71 if (boundingBox.isEmpty()) | 71 if (boundingBox.isEmpty()) |
| 72 return 0; | 72 return 0; |
| 73 | 73 |
| 74 float reciprocalPadding = 1.f / padding; | 74 float reciprocalPadding = 1.f / padding; |
| 75 float score = 1; | 75 float score = 1; |
| 76 | 76 |
| 77 IntSize distance = boundingBox.differenceToPoint(touchPoint); | 77 IntSize distance = boundingBox.differenceToPoint(touchPoint); |
| 78 score *= std::max((padding - abs(distance.width())) * reciprocalPadding, 0.f
); | 78 score *= std::max((padding - abs(distance.width())) * reciprocalPadding, 0.f
); |
| 79 score *= std::max((padding - abs(distance.height())) * reciprocalPadding, 0.
f); | 79 score *= std::max((padding - abs(distance.height())) * reciprocalPadding, 0.
f); |
| 80 | 80 |
| 81 return score; | 81 return score; |
| 82 } | 82 } |
| 83 | 83 |
| 84 struct TouchTargetData { | 84 struct TouchTargetData { |
| 85 IntRect windowBoundingBox; | 85 IntRect windowBoundingBox; |
| 86 float score; | 86 float score; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 void findGoodTouchTargets(const IntRect& touchBox, LocalFrame* mainFrame, Vector
<IntRect>& goodTargets, WillBeHeapVector<RawPtrWillBeMember<Node>>& highlightNod
es) | 89 void findGoodTouchTargets(const IntRect& touchBoxInRootFrame, LocalFrame* mainFr
ame, Vector<IntRect>& goodTargets, WillBeHeapVector<RawPtrWillBeMember<Node>>& h
ighlightNodes) |
| 90 { | 90 { |
| 91 goodTargets.clear(); | 91 goodTargets.clear(); |
| 92 | 92 |
| 93 int touchPointPadding = ceil(std::max(touchBox.width(), touchBox.height()) *
0.5); | 93 int touchPointPadding = ceil(std::max(touchBoxInRootFrame.width(), touchBoxI
nRootFrame.height()) * 0.5); |
| 94 | 94 |
| 95 IntPoint touchPoint = touchBox.center(); | 95 IntPoint touchPoint = touchBoxInRootFrame.center(); |
| 96 IntPoint contentsPoint = mainFrame->view()->windowToContents(touchPoint); | 96 IntPoint contentsPoint = mainFrame->view()->rootFrameToContents(touchPoint); |
| 97 | 97 |
| 98 HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(conten
tsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::Lis
tBased, LayoutSize(touchPointPadding, touchPointPadding)); | 98 HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(conten
tsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::Lis
tBased, LayoutSize(touchPointPadding, touchPointPadding)); |
| 99 const WillBeHeapListHashSet<RefPtrWillBeMember<Node>>& hitResults = result.l
istBasedTestResult(); | 99 const WillBeHeapListHashSet<RefPtrWillBeMember<Node>>& hitResults = result.l
istBasedTestResult(); |
| 100 | 100 |
| 101 // Blacklist nodes that are container of disambiguated nodes. | 101 // Blacklist nodes that are container of disambiguated nodes. |
| 102 // It is not uncommon to have a clickable <div> that contains other clickabl
e objects. | 102 // It is not uncommon to have a clickable <div> that contains other clickabl
e objects. |
| 103 // This heuristic avoids excessive disambiguation in that case. | 103 // This heuristic avoids excessive disambiguation in that case. |
| 104 WillBeHeapHashSet<RawPtrWillBeMember<Node>> blackList; | 104 WillBeHeapHashSet<RawPtrWillBeMember<Node>> blackList; |
| 105 for (const auto& hitResult : hitResults) { | 105 for (const auto& hitResult : hitResults) { |
| 106 // Ignore any Nodes that can't be clicked on. | 106 // Ignore any Nodes that can't be clicked on. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Currently the scoring function uses the overlap area with the fat poi
nt as the score. | 140 // Currently the scoring function uses the overlap area with the fat poi
nt as the score. |
| 141 // We ignore the candidates that has less than 1/2 overlap (we consider
not really ambiguous enough) than the best candidate to avoid excessive popups. | 141 // We ignore the candidates that has less than 1/2 overlap (we consider
not really ambiguous enough) than the best candidate to avoid excessive popups. |
| 142 if (touchTarget.value.score < bestScore * 0.5) | 142 if (touchTarget.value.score < bestScore * 0.5) |
| 143 continue; | 143 continue; |
| 144 goodTargets.append(touchTarget.value.windowBoundingBox); | 144 goodTargets.append(touchTarget.value.windowBoundingBox); |
| 145 highlightNodes.append(touchTarget.key); | 145 highlightNodes.append(touchTarget.key); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |