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

Side by Side Diff: ui/accessibility/ax_position.h

Issue 2930273002: Use ContainsValue() instead of std::find() in ui/accessibility, ui/gl and ui/ozone (Closed)
Patch Set: Rebase patch Created 3 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
« no previous file with comments | « no previous file | ui/accessibility/ax_tree_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_ 5 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_
6 #define UI_ACCESSIBILITY_AX_POSITION_H_ 6 #define UI_ACCESSIBILITY_AX_POSITION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm>
11 #include <memory> 10 #include <memory>
12 #include <stack> 11 #include <stack>
13 #include <string> 12 #include <string>
14 #include <utility> 13 #include <utility>
15 #include <vector> 14 #include <vector>
16 15
16 #include "base/stl_util.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "ui/accessibility/ax_enums.h" 20 #include "ui/accessibility/ax_enums.h"
21 21
22 namespace ui { 22 namespace ui {
23 23
24 // Defines the type of position in the accessibility tree. 24 // Defines the type of position in the accessibility tree.
25 // A tree position is used when referring to a specific child of a node in the 25 // A tree position is used when referring to a specific child of a node in the
26 // accessibility tree. 26 // accessibility tree.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 AXPositionInstance text_position = AsLeafTextPosition(); 231 AXPositionInstance text_position = AsLeafTextPosition();
232 switch (text_position->kind_) { 232 switch (text_position->kind_) {
233 case AXPositionKind::NULL_POSITION: 233 case AXPositionKind::NULL_POSITION:
234 return false; 234 return false;
235 case AXPositionKind::TREE_POSITION: 235 case AXPositionKind::TREE_POSITION:
236 NOTREACHED(); 236 NOTREACHED();
237 return false; 237 return false;
238 case AXPositionKind::TEXT_POSITION: { 238 case AXPositionKind::TEXT_POSITION: {
239 const std::vector<int32_t> word_starts = 239 const std::vector<int32_t> word_starts =
240 text_position->GetWordStartOffsets(); 240 text_position->GetWordStartOffsets();
241 auto iterator = 241 return base::ContainsValue(
242 std::find(word_starts.begin(), word_starts.end(), 242 word_starts, static_cast<int32_t>(text_position->text_offset_));
243 static_cast<int32_t>(text_position->text_offset_));
244 return iterator != word_starts.end();
245 } 243 }
246 } 244 }
247 return false; 245 return false;
248 } 246 }
249 247
250 bool AtEndOfWord() const { 248 bool AtEndOfWord() const {
251 AXPositionInstance text_position = AsLeafTextPosition(); 249 AXPositionInstance text_position = AsLeafTextPosition();
252 switch (text_position->kind_) { 250 switch (text_position->kind_) {
253 case AXPositionKind::NULL_POSITION: 251 case AXPositionKind::NULL_POSITION:
254 return false; 252 return false;
255 case AXPositionKind::TREE_POSITION: 253 case AXPositionKind::TREE_POSITION:
256 NOTREACHED(); 254 NOTREACHED();
257 return false; 255 return false;
258 case AXPositionKind::TEXT_POSITION: { 256 case AXPositionKind::TEXT_POSITION: {
259 const std::vector<int32_t> word_ends = 257 const std::vector<int32_t> word_ends =
260 text_position->GetWordEndOffsets(); 258 text_position->GetWordEndOffsets();
261 auto iterator = 259 return base::ContainsValue(
262 std::find(word_ends.begin(), word_ends.end(), 260 word_ends, static_cast<int32_t>(text_position->text_offset_));
263 static_cast<int32_t>(text_position->text_offset_));
264 return iterator != word_ends.end();
265 } 261 }
266 } 262 }
267 return false; 263 return false;
268 } 264 }
269 265
270 bool AtStartOfLine() const { 266 bool AtStartOfLine() const {
271 AXPositionInstance text_position = AsLeafTextPosition(); 267 AXPositionInstance text_position = AsLeafTextPosition();
272 switch (text_position->kind_) { 268 switch (text_position->kind_) {
273 case AXPositionKind::NULL_POSITION: 269 case AXPositionKind::NULL_POSITION:
274 return false; 270 return false;
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 1189
1194 template <class AXPositionType, class AXNodeType> 1190 template <class AXPositionType, class AXNodeType>
1195 bool operator>=(const AXPosition<AXPositionType, AXNodeType>& first, 1191 bool operator>=(const AXPosition<AXPositionType, AXNodeType>& first,
1196 const AXPosition<AXPositionType, AXNodeType>& second) { 1192 const AXPosition<AXPositionType, AXNodeType>& second) {
1197 return first == second || first > second; 1193 return first == second || first > second;
1198 } 1194 }
1199 1195
1200 } // namespace ui 1196 } // namespace ui
1201 1197
1202 #endif // UI_ACCESSIBILITY_AX_POSITION_H_ 1198 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW
« no previous file with comments | « no previous file | ui/accessibility/ax_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698