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

Side by Side Diff: Source/core/page/TouchDisambiguation.cpp

Issue 330933002: Revert of Removing "using" declarations that import names in the C++ Standard library. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months 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
OLDNEW
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 27 matching lines...) Expand all
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/Element.h" 39 #include "core/dom/Element.h"
40 #include "core/dom/NodeTraversal.h" 40 #include "core/dom/NodeTraversal.h"
41 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/html/HTMLHtmlElement.h" 43 #include "core/html/HTMLHtmlElement.h"
44 #include "core/page/EventHandler.h" 44 #include "core/page/EventHandler.h"
45 #include "core/rendering/HitTestResult.h" 45 #include "core/rendering/HitTestResult.h"
46 #include "core/rendering/RenderBlock.h" 46 #include "core/rendering/RenderBlock.h"
47 47
48 using namespace std;
49
48 namespace WebCore { 50 namespace WebCore {
49 51
50 static IntRect boundingBoxForEventNodes(Node* eventNode) 52 static IntRect boundingBoxForEventNodes(Node* eventNode)
51 { 53 {
52 if (!eventNode->document().view()) 54 if (!eventNode->document().view())
53 return IntRect(); 55 return IntRect();
54 56
55 IntRect result; 57 IntRect result;
56 Node* node = eventNode; 58 Node* node = eventNode;
57 while (node) { 59 while (node) {
(...skipping 10 matching lines...) Expand all
68 70
69 static float scoreTouchTarget(IntPoint touchPoint, int padding, IntRect bounding Box) 71 static float scoreTouchTarget(IntPoint touchPoint, int padding, IntRect bounding Box)
70 { 72 {
71 if (boundingBox.isEmpty()) 73 if (boundingBox.isEmpty())
72 return 0; 74 return 0;
73 75
74 float reciprocalPadding = 1.f / padding; 76 float reciprocalPadding = 1.f / padding;
75 float score = 1; 77 float score = 1;
76 78
77 IntSize distance = boundingBox.differenceToPoint(touchPoint); 79 IntSize distance = boundingBox.differenceToPoint(touchPoint);
78 score *= std::max((padding - std::abs(distance.width())) * reciprocalPadding , 0.f); 80 score *= max((padding - abs(distance.width())) * reciprocalPadding, 0.f);
79 score *= std::max((padding - std::abs(distance.height())) * reciprocalPaddin g, 0.f); 81 score *= max((padding - abs(distance.height())) * reciprocalPadding, 0.f);
80 82
81 return score; 83 return score;
82 } 84 }
83 85
84 struct TouchTargetData { 86 struct TouchTargetData {
85 IntRect windowBoundingBox; 87 IntRect windowBoundingBox;
86 float score; 88 float score;
87 }; 89 };
88 90
89 void findGoodTouchTargets(const IntRect& touchBox, LocalFrame* mainFrame, Vector <IntRect>& goodTargets, WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNo des) 91 void findGoodTouchTargets(const IntRect& touchBox, LocalFrame* mainFrame, Vector <IntRect>& goodTargets, WillBeHeapVector<RawPtrWillBeMember<Node> >& highlightNo des)
90 { 92 {
91 goodTargets.clear(); 93 goodTargets.clear();
92 94
93 int touchPointPadding = ceil(std::max(touchBox.width(), touchBox.height()) * 0.5); 95 int touchPointPadding = ceil(max(touchBox.width(), touchBox.height()) * 0.5) ;
94 96
95 IntPoint touchPoint = touchBox.center(); 97 IntPoint touchPoint = touchBox.center();
96 IntPoint contentsPoint = mainFrame->view()->windowToContents(touchPoint); 98 IntPoint contentsPoint = mainFrame->view()->windowToContents(touchPoint);
97 99
98 HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(conten tsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::Con fusingAndOftenMisusedDisallowShadowContent, IntSize(touchPointPadding, touchPoin tPadding)); 100 HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(conten tsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::Con fusingAndOftenMisusedDisallowShadowContent, IntSize(touchPointPadding, touchPoin tPadding));
99 const WillBeHeapListHashSet<RefPtrWillBeMember<Node> >& hitResults = result. rectBasedTestResult(); 101 const WillBeHeapListHashSet<RefPtrWillBeMember<Node> >& hitResults = result. rectBasedTestResult();
100 102
101 // Blacklist nodes that are container of disambiguated nodes. 103 // Blacklist nodes that are container of disambiguated nodes.
102 // It is not uncommon to have a clickable <div> that contains other clickabl e objects. 104 // It is not uncommon to have a clickable <div> that contains other clickabl e objects.
103 // This heuristic avoids excessive disambiguation in that case. 105 // This heuristic avoids excessive disambiguation in that case.
(...skipping 19 matching lines...) Expand all
123 for (WillBeHeapListHashSet<RefPtrWillBeMember<Node> >::const_iterator it = h itResults.begin(); it != hitResults.end(); ++it) { 125 for (WillBeHeapListHashSet<RefPtrWillBeMember<Node> >::const_iterator it = h itResults.begin(); it != hitResults.end(); ++it) {
124 for (Node* node = it->get(); node; node = node->parentNode()) { 126 for (Node* node = it->get(); node; node = node->parentNode()) {
125 if (blackList.contains(node)) 127 if (blackList.contains(node))
126 continue; 128 continue;
127 if (node->isDocumentNode() || isHTMLHtmlElement(*node) || isHTMLBody Element(*node)) 129 if (node->isDocumentNode() || isHTMLHtmlElement(*node) || isHTMLBody Element(*node))
128 break; 130 break;
129 if (node->willRespondToMouseClickEvents()) { 131 if (node->willRespondToMouseClickEvents()) {
130 TouchTargetData& targetData = touchTargets.add(node, TouchTarget Data()).storedValue->value; 132 TouchTargetData& targetData = touchTargets.add(node, TouchTarget Data()).storedValue->value;
131 targetData.windowBoundingBox = boundingBoxForEventNodes(node); 133 targetData.windowBoundingBox = boundingBoxForEventNodes(node);
132 targetData.score = scoreTouchTarget(touchPoint, touchPointPaddin g, targetData.windowBoundingBox); 134 targetData.score = scoreTouchTarget(touchPoint, touchPointPaddin g, targetData.windowBoundingBox);
133 bestScore = std::max(bestScore, targetData.score); 135 bestScore = max(bestScore, targetData.score);
134 break; 136 break;
135 } 137 }
136 } 138 }
137 } 139 }
138 140
139 for (WillBeHeapHashMap<RawPtrWillBeMember<Node>, TouchTargetData>::iterator it = touchTargets.begin(); it != touchTargets.end(); ++it) { 141 for (WillBeHeapHashMap<RawPtrWillBeMember<Node>, TouchTargetData>::iterator it = touchTargets.begin(); it != touchTargets.end(); ++it) {
140 // Currently the scoring function uses the overlap area with the fat poi nt as the score. 142 // 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. 143 // 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 (it->value.score < bestScore * 0.5) 144 if (it->value.score < bestScore * 0.5)
143 continue; 145 continue;
144 goodTargets.append(it->value.windowBoundingBox); 146 goodTargets.append(it->value.windowBoundingBox);
145 highlightNodes.append(it->key); 147 highlightNodes.append(it->key);
146 } 148 }
147 } 149 }
148 150
149 } // namespace WebCore 151 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/ScopedPageLoadDeferrer.cpp ('k') | Source/core/svg/animation/SMILTimeContainer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698