Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: sky/engine/core/page/TouchAdjustment.cpp

Issue 711233002: Remove some dead code around touch events and zooming. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/page/TouchAdjustment.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 2 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (element->isMouseFocusable()) 90 if (element->isMouseFocusable())
91 return true; 91 return true;
92 } 92 }
93 if (RenderStyle* renderStyle = node->renderStyle()) { 93 if (RenderStyle* renderStyle = node->renderStyle()) {
94 if (renderStyle->affectedByActive() || renderStyle->affectedByHover()) 94 if (renderStyle->affectedByActive() || renderStyle->affectedByHover())
95 return true; 95 return true;
96 } 96 }
97 return false; 97 return false;
98 } 98 }
99 99
100 bool nodeIsZoomTarget(Node* node)
101 {
102 if (node->isTextNode() || node->isShadowRoot())
103 return false;
104
105 ASSERT(node->renderer());
106 return node->renderer()->isBox();
107 }
108
109 static inline void appendQuadsToSubtargetList(Vector<FloatQuad>& quads, Node* no de, SubtargetGeometryList& subtargets) 100 static inline void appendQuadsToSubtargetList(Vector<FloatQuad>& quads, Node* no de, SubtargetGeometryList& subtargets)
110 { 101 {
111 Vector<FloatQuad>::const_iterator it = quads.begin(); 102 Vector<FloatQuad>::const_iterator it = quads.begin();
112 const Vector<FloatQuad>::const_iterator end = quads.end(); 103 const Vector<FloatQuad>::const_iterator end = quads.end();
113 for (; it != end; ++it) 104 for (; it != end; ++it)
114 subtargets.append(SubtargetGeometry(node, *it)); 105 subtargets.append(SubtargetGeometry(node, *it));
115 } 106 }
116 107
117 static inline void appendBasicSubtargetsForNode(Node* node, SubtargetGeometryLis t& subtargets) 108 static inline void appendBasicSubtargetsForNode(Node* node, SubtargetGeometryLis t& subtargets)
118 { 109 {
119 // Node guaranteed to have renderer due to check in node filter. 110 // Node guaranteed to have renderer due to check in node filter.
120 ASSERT(node->renderer()); 111 ASSERT(node->renderer());
121 112
122 Vector<FloatQuad> quads; 113 Vector<FloatQuad> quads;
123 node->renderer()->absoluteQuads(quads); 114 node->renderer()->absoluteQuads(quads);
124 115
125 appendQuadsToSubtargetList(quads, node, subtargets); 116 appendQuadsToSubtargetList(quads, node, subtargets);
126 } 117 }
127 118
128 static inline void appendZoomableSubtargets(Node* node, SubtargetGeometryList& s ubtargets)
129 {
130 RenderBox* renderer = toRenderBox(node->renderer());
131 ASSERT(renderer);
132
133 Vector<FloatQuad> quads;
134 FloatRect borderBoxRect = renderer->borderBoxRect();
135 FloatRect contentBoxRect = renderer->contentBoxRect();
136 quads.append(renderer->localToAbsoluteQuad(borderBoxRect));
137 if (borderBoxRect != contentBoxRect)
138 quads.append(renderer->localToAbsoluteQuad(contentBoxRect));
139 // FIXME: For RenderBlocks, add column boxes and content boxes cleared for f loats.
140
141 Vector<FloatQuad>::const_iterator it = quads.begin();
142 const Vector<FloatQuad>::const_iterator end = quads.end();
143 for (; it != end; ++it)
144 subtargets.append(SubtargetGeometry(node, *it));
145 }
146
147 static inline Node* parentShadowHostOrOwner(const Node* node)
148 {
149 if (Node* ancestor = node->parentOrShadowHostNode())
150 return ancestor;
151 return 0;
152 }
153
154 // Compiles a list of subtargets of all the relevant target nodes. 119 // Compiles a list of subtargets of all the relevant target nodes.
155 void compileSubtargetList(const Vector<RefPtr<Node> >& intersectedNodes, Subtarg etGeometryList& subtargets, NodeFilter nodeFilter, AppendSubtargetsForNode appen dSubtargetsForNode) 120 void compileSubtargetList(const Vector<RefPtr<Node> >& intersectedNodes, Subtarg etGeometryList& subtargets, NodeFilter nodeFilter, AppendSubtargetsForNode appen dSubtargetsForNode)
156 { 121 {
157 // Find candidates responding to tap gesture events in O(n) time. 122 // Find candidates responding to tap gesture events in O(n) time.
158 HashMap<RawPtr<Node>, RawPtr<Node> > responderMap; 123 HashMap<RawPtr<Node>, RawPtr<Node> > responderMap;
159 HashSet<RawPtr<Node> > ancestorsToRespondersSet; 124 HashSet<RawPtr<Node> > ancestorsToRespondersSet;
160 Vector<RawPtr<Node> > candidates; 125 Vector<RawPtr<Node> > candidates;
161 HashSet<RawPtr<Node> > editableAncestors; 126 HashSet<RawPtr<Node> > editableAncestors;
162 127
163 // A node matching the NodeFilter is called a responder. Candidate nodes mus t either be a 128 // A node matching the NodeFilter is called a responder. Candidate nodes mus t either be a
164 // responder or have an ancestor that is a responder. 129 // responder or have an ancestor that is a responder.
165 // This iteration tests all ancestors at most once by caching earlier result s. 130 // This iteration tests all ancestors at most once by caching earlier result s.
166 for (unsigned i = 0; i < intersectedNodes.size(); ++i) { 131 for (unsigned i = 0; i < intersectedNodes.size(); ++i) {
167 Node* node = intersectedNodes[i].get(); 132 Node* node = intersectedNodes[i].get();
168 Vector<RawPtr<Node> > visitedNodes; 133 Vector<RawPtr<Node> > visitedNodes;
169 Node* respondingNode = 0; 134 Node* respondingNode = 0;
170 for (Node* visitedNode = node; visitedNode; visitedNode = visitedNode->p arentOrShadowHostNode()) { 135 for (Node* visitedNode = node; visitedNode; visitedNode = visitedNode->p arentOrShadowHostNode()) {
171 // Check if we already have a result for a common ancestor from anot her candidate. 136 // Check if we already have a result for a common ancestor from anot her candidate.
172 respondingNode = responderMap.get(visitedNode); 137 respondingNode = responderMap.get(visitedNode);
173 if (respondingNode) 138 if (respondingNode)
174 break; 139 break;
175 visitedNodes.append(visitedNode); 140 visitedNodes.append(visitedNode);
176 // Check if the node filter applies, which would mean we have found a responding node. 141 // Check if the node filter applies, which would mean we have found a responding node.
177 if (nodeFilter(visitedNode)) { 142 if (nodeFilter(visitedNode)) {
178 respondingNode = visitedNode; 143 respondingNode = visitedNode;
179 // Continue the iteration to collect the ancestors of the respon der, which we will need later. 144 // Continue the iteration to collect the ancestors of the respon der, which we will need later.
180 for (visitedNode = parentShadowHostOrOwner(visitedNode); visited Node; visitedNode = parentShadowHostOrOwner(visitedNode)) { 145 for (visitedNode = visitedNode->parentOrShadowHostNode(); visite dNode; visitedNode = visitedNode->parentOrShadowHostNode()) {
181 HashSet<RawPtr<Node> >::AddResult addResult = ancestorsToRes pondersSet.add(visitedNode); 146 HashSet<RawPtr<Node> >::AddResult addResult = ancestorsToRes pondersSet.add(visitedNode);
182 if (!addResult.isNewEntry) 147 if (!addResult.isNewEntry)
183 break; 148 break;
184 } 149 }
185 break; 150 break;
186 } 151 }
187 } 152 }
188 // Insert the detected responder for all the visited nodes. 153 // Insert the detected responder for all the visited nodes.
189 for (unsigned j = 0; j < visitedNodes.size(); j++) 154 for (unsigned j = 0; j < visitedNodes.size(); j++)
190 responderMap.add(visitedNodes[j], respondingNode); 155 responderMap.add(visitedNodes[j], respondingNode);
(...skipping 28 matching lines...) Expand all
219 editableAncestors.add(replacement); 184 editableAncestors.add(replacement);
220 parent = parent->parentOrShadowHostNode(); 185 parent = parent->parentOrShadowHostNode();
221 } 186 }
222 candidate = replacement; 187 candidate = replacement;
223 } 188 }
224 if (candidate) 189 if (candidate)
225 appendSubtargetsForNode(candidate, subtargets); 190 appendSubtargetsForNode(candidate, subtargets);
226 } 191 }
227 } 192 }
228 193
229 // Compiles a list of zoomable subtargets.
230 void compileZoomableSubtargets(const Vector<RefPtr<Node> >& intersectedNodes, Su btargetGeometryList& subtargets)
231 {
232 for (unsigned i = 0; i < intersectedNodes.size(); ++i) {
233 Node* candidate = intersectedNodes[i].get();
234 if (nodeIsZoomTarget(candidate))
235 appendZoomableSubtargets(candidate, subtargets);
236 }
237 }
238
239 // This returns quotient of the target area and its intersection with the touch area.
240 // This will prioritize largest intersection and smallest area, while balancing the two against each other.
241 float zoomableIntersectionQuotient(const IntPoint& touchHotspot, const IntRect& touchArea, const SubtargetGeometry& subtarget)
242 {
243 IntRect rect = subtarget.boundingBox();
244
245 // Convert from frame coordinates to window coordinates.
246 rect = subtarget.node()->document().view()->contentsToWindow(rect);
247
248 // Check the rectangle is meaningful zoom target. It should at least contain the hotspot.
249 if (!rect.contains(touchHotspot))
250 return std::numeric_limits<float>::infinity();
251 IntRect intersection = rect;
252 intersection.intersect(touchArea);
253
254 // Return the quotient of the intersection.
255 return rect.size().area() / (float)intersection.size().area();
256 }
257
258 // Uses a hybrid of distance to adjust and intersect ratio, normalizing each sco re between 0 and 1 194 // Uses a hybrid of distance to adjust and intersect ratio, normalizing each sco re between 0 and 1
259 // and combining them. The distance to adjust works best for disambiguating clic ks on targets such 195 // and combining them. The distance to adjust works best for disambiguating clic ks on targets such
260 // as links, where the width may be significantly larger than the touch width. U sing area of overlap 196 // as links, where the width may be significantly larger than the touch width. U sing area of overlap
261 // in such cases can lead to a bias towards shorter links. Conversely, percentag e of overlap can 197 // in such cases can lead to a bias towards shorter links. Conversely, percentag e of overlap can
262 // provide strong confidence in tapping on a small target, where the overlap is often quite high, 198 // provide strong confidence in tapping on a small target, where the overlap is often quite high,
263 // and works well for tightly packed controls. 199 // and works well for tightly packed controls.
264 float hybridDistanceFunction(const IntPoint& touchHotspot, const IntRect& touchR ect, const SubtargetGeometry& subtarget) 200 float hybridDistanceFunction(const IntPoint& touchHotspot, const IntRect& touchR ect, const SubtargetGeometry& subtarget)
265 { 201 {
266 IntRect rect = subtarget.boundingBox(); 202 IntRect rect = subtarget.boundingBox();
267 203
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } // namespace TouchAdjustment 330 } // namespace TouchAdjustment
395 331
396 bool findBestClickableCandidate(Node*& targetNode, IntPoint& targetPoint, const IntPoint& touchHotspot, const IntRect& touchArea, const Vector<RefPtr<Node> >& n odes) 332 bool findBestClickableCandidate(Node*& targetNode, IntPoint& targetPoint, const IntPoint& touchHotspot, const IntRect& touchArea, const Vector<RefPtr<Node> >& n odes)
397 { 333 {
398 IntRect targetArea; 334 IntRect targetArea;
399 TouchAdjustment::SubtargetGeometryList subtargets; 335 TouchAdjustment::SubtargetGeometryList subtargets;
400 TouchAdjustment::compileSubtargetList(nodes, subtargets, TouchAdjustment::no deRespondsToTapGesture, TouchAdjustment::appendBasicSubtargetsForNode); 336 TouchAdjustment::compileSubtargetList(nodes, subtargets, TouchAdjustment::no deRespondsToTapGesture, TouchAdjustment::appendBasicSubtargetsForNode);
401 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDi stanceFunction); 337 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::hybridDi stanceFunction);
402 } 338 }
403 339
404 bool findBestZoomableArea(Node*& targetNode, IntRect& targetArea, const IntPoint & touchHotspot, const IntRect& touchArea, const Vector<RefPtr<Node> >& nodes)
405 {
406 IntPoint targetPoint;
407 TouchAdjustment::SubtargetGeometryList subtargets;
408 TouchAdjustment::compileZoomableSubtargets(nodes, subtargets);
409 return TouchAdjustment::findNodeWithLowestDistanceMetric(targetNode, targetP oint, targetArea, touchHotspot, touchArea, subtargets, TouchAdjustment::zoomable IntersectionQuotient);
410 }
411
412 } // namespace blink 340 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/page/TouchAdjustment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698