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

Side by Side Diff: ui/accessibility/ax_node_data.cc

Issue 2860883003: A11y: Add/refactor methods for manipulating bitfields on AXNodeData. (Closed)
Patch Set: Revert comment. Created 3 years, 7 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ui/accessibility/ax_node_data.h" 5 #include "ui/accessibility/ax_node_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
11 11
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "ui/accessibility/ax_text_utils.h" 16 #include "ui/accessibility/ax_text_utils.h"
17 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
18 18
19 using base::DoubleToString; 19 using base::DoubleToString;
20 using base::IntToString; 20 using base::IntToString;
21 21
22 namespace ui { 22 namespace ui {
23 23
24 namespace { 24 namespace {
25 25
26 bool IsFlagSet(uint32_t bitfield, uint32_t flag) {
27 return 0 != (bitfield & (1 << flag));
28 }
29
30 uint32_t ModifyFlag(uint32_t bitfield, uint32_t flag, bool set) {
31 return set ? (bitfield |= (1 << flag)) : (bitfield &= ~(1 << flag));
tapted 2017/05/05 05:53:36 The '=' on this line are not needed. i.e. '|=' ->
Patti Lor 2017/05/08 00:28:08 Deleted :)
32 }
33
34 std::string StateBitfieldToString(uint32_t state) {
35 std::string str;
36 for (uint32_t i = AX_STATE_NONE + 1; i <= AX_STATE_LAST; ++i) {
37 if (IsFlagSet(state, i))
38 str += " " + base::ToUpperASCII(ToString(static_cast<AXState>(i)));
39 }
40 return str;
41 }
42
26 std::string IntVectorToString(const std::vector<int>& items) { 43 std::string IntVectorToString(const std::vector<int>& items) {
27 std::string str; 44 std::string str;
28 for (size_t i = 0; i < items.size(); ++i) { 45 for (size_t i = 0; i < items.size(); ++i) {
29 if (i > 0) 46 if (i > 0)
30 str += ","; 47 str += ",";
31 str += IntToString(items[i]); 48 str += IntToString(items[i]);
32 } 49 }
33 return str; 50 return str;
34 } 51 }
35 52
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 427 }
411 } 428 }
412 429
413 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value)); 430 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value));
414 } 431 }
415 432
416 void AXNodeData::SetValue(const base::string16& value) { 433 void AXNodeData::SetValue(const base::string16& value) {
417 SetValue(base::UTF16ToUTF8(value)); 434 SetValue(base::UTF16ToUTF8(value));
418 } 435 }
419 436
420 // static 437 void AXNodeData::ClearBitfields() {
421 bool AXNodeData::IsFlagSet(uint32_t state, ui::AXState state_flag) { 438 DCHECK(state == 0xFFFFFFFF);
tapted 2017/05/05 05:53:36 DCHECK_EQ?
Patti Lor 2017/05/08 00:28:08 Done.
422 return 0 != (state & (1 << state_flag)); 439 state = AX_STATE_NONE;
423 } 440 }
424 441
425 void AXNodeData::AddStateFlag(ui::AXState state_flag) { 442 bool AXNodeData::HasState(AXState state_flag) const {
426 state |= (1 << state_flag);
427 }
428
429 bool AXNodeData::HasStateFlag(ui::AXState state_flag) const {
430 return IsFlagSet(state, state_flag); 443 return IsFlagSet(state, state_flag);
431 } 444 }
432 445
446 void AXNodeData::AddState(AXState state_flag) {
447 DCHECK(state_flag != AX_STATE_NONE);
tapted 2017/05/05 05:53:36 DCHECK_NE?
Patti Lor 2017/05/08 00:28:08 Done.
448 state = ModifyFlag(state, state_flag, true);
449 }
450
433 std::string AXNodeData::ToString() const { 451 std::string AXNodeData::ToString() const {
434 std::string result; 452 std::string result;
435 453
436 result += "id=" + IntToString(id); 454 result += "id=" + IntToString(id);
437 result += " " + ui::ToString(role); 455 result += " " + ui::ToString(role);
438 456
439 if (state & (1 << AX_STATE_BUSY)) 457 result += StateBitfieldToString(state);
440 result += " BUSY";
441 if (state & (1 << AX_STATE_COLLAPSED))
442 result += " COLLAPSED";
443 if (state & (1 << AX_STATE_EDITABLE))
444 result += " EDITABLE";
445 if (state & (1 << AX_STATE_EXPANDED))
446 result += " EXPANDED";
447 if (state & (1 << AX_STATE_FOCUSABLE))
448 result += " FOCUSABLE";
449 if (state & (1 << AX_STATE_HASPOPUP))
450 result += " HASPOPUP";
451 if (state & (1 << AX_STATE_HOVERED))
452 result += " HOVERED";
453 if (state & (1 << AX_STATE_INVISIBLE))
454 result += " INVISIBLE";
455 if (state & (1 << AX_STATE_LINKED))
456 result += " LINKED";
457 if (state & (1 << AX_STATE_MULTISELECTABLE))
458 result += " MULTISELECTABLE";
459 if (state & (1 << AX_STATE_OFFSCREEN))
460 result += " OFFSCREEN";
461 if (state & (1 << AX_STATE_PRESSED))
462 result += " PRESSED";
463 if (state & (1 << AX_STATE_PROTECTED))
464 result += " PROTECTED";
465 if (state & (1 << AX_STATE_READ_ONLY))
466 result += " READONLY";
467 if (state & (1 << AX_STATE_REQUIRED))
468 result += " REQUIRED";
469 if (state & (1 << AX_STATE_RICHLY_EDITABLE))
470 result += " RICHLY_EDITABLE";
471 if (state & (1 << AX_STATE_SELECTABLE))
472 result += " SELECTABLE";
473 if (state & (1 << AX_STATE_SELECTED))
474 result += " SELECTED";
475 if (state & (1 << AX_STATE_VERTICAL))
476 result += " VERTICAL";
477 if (state & (1 << AX_STATE_VISITED))
478 result += " VISITED";
479 458
480 result += " (" + IntToString(location.x()) + ", " + 459 result += " (" + IntToString(location.x()) + ", " +
481 IntToString(location.y()) + ")-(" + 460 IntToString(location.y()) + ")-(" +
482 IntToString(location.width()) + ", " + 461 IntToString(location.width()) + ", " +
483 IntToString(location.height()) + ")"; 462 IntToString(location.height()) + ")";
484 463
485 if (offset_container_id != -1) 464 if (offset_container_id != -1)
486 result += " offset_container_id=" + IntToString(offset_container_id); 465 result += " offset_container_id=" + IntToString(offset_container_id);
487 466
488 if (transform && !transform->IsIdentity()) 467 if (transform && !transform->IsIdentity())
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 920 }
942 } 921 }
943 922
944 if (!child_ids.empty()) 923 if (!child_ids.empty())
945 result += " child_ids=" + IntVectorToString(child_ids); 924 result += " child_ids=" + IntVectorToString(child_ids);
946 925
947 return result; 926 return result;
948 } 927 }
949 928
950 } // namespace ui 929 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698