| OLD | NEW |
| 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 std::string StateBitfieldToString(uint32_t state) { |
| 31 std::string str; |
| 32 for (uint32_t i = AX_STATE_NONE + 1; i <= AX_STATE_LAST; ++i) { |
| 33 if (IsFlagSet(state, i)) |
| 34 str += " " + base::ToUpperASCII(ToString(static_cast<AXState>(i))); |
| 35 } |
| 36 return str; |
| 37 } |
| 38 |
| 26 std::string IntVectorToString(const std::vector<int>& items) { | 39 std::string IntVectorToString(const std::vector<int>& items) { |
| 27 std::string str; | 40 std::string str; |
| 28 for (size_t i = 0; i < items.size(); ++i) { | 41 for (size_t i = 0; i < items.size(); ++i) { |
| 29 if (i > 0) | 42 if (i > 0) |
| 30 str += ","; | 43 str += ","; |
| 31 str += IntToString(items[i]); | 44 str += IntToString(items[i]); |
| 32 } | 45 } |
| 33 return str; | 46 return str; |
| 34 } | 47 } |
| 35 | 48 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 423 } |
| 411 } | 424 } |
| 412 | 425 |
| 413 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value)); | 426 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value)); |
| 414 } | 427 } |
| 415 | 428 |
| 416 void AXNodeData::SetValue(const base::string16& value) { | 429 void AXNodeData::SetValue(const base::string16& value) { |
| 417 SetValue(base::UTF16ToUTF8(value)); | 430 SetValue(base::UTF16ToUTF8(value)); |
| 418 } | 431 } |
| 419 | 432 |
| 420 // static | 433 void AXNodeData::Init() { |
| 421 bool AXNodeData::IsFlagSet(uint32_t state, ui::AXState state_flag) { | 434 DCHECK_EQ(state, 0xFFFFFFFF); |
| 422 return 0 != (state & (1 << state_flag)); | 435 state = AX_STATE_NONE; |
| 423 } | 436 } |
| 424 | 437 |
| 425 void AXNodeData::AddStateFlag(ui::AXState state_flag) { | 438 bool AXNodeData::HasState(AXState state_flag) const { |
| 439 return IsFlagSet(state, state_flag); |
| 440 } |
| 441 |
| 442 void AXNodeData::AddState(AXState state_flag) { |
| 443 DCHECK_NE(state_flag, AX_STATE_NONE); |
| 426 state |= (1 << state_flag); | 444 state |= (1 << state_flag); |
| 427 } | 445 } |
| 428 | 446 |
| 429 bool AXNodeData::HasStateFlag(ui::AXState state_flag) const { | |
| 430 return IsFlagSet(state, state_flag); | |
| 431 } | |
| 432 | |
| 433 std::string AXNodeData::ToString() const { | 447 std::string AXNodeData::ToString() const { |
| 434 std::string result; | 448 std::string result; |
| 435 | 449 |
| 436 result += "id=" + IntToString(id); | 450 result += "id=" + IntToString(id); |
| 437 result += " " + ui::ToString(role); | 451 result += " " + ui::ToString(role); |
| 438 | 452 |
| 439 if (state & (1 << AX_STATE_BUSY)) | 453 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 | 454 |
| 480 result += " (" + IntToString(location.x()) + ", " + | 455 result += " (" + IntToString(location.x()) + ", " + |
| 481 IntToString(location.y()) + ")-(" + | 456 IntToString(location.y()) + ")-(" + |
| 482 IntToString(location.width()) + ", " + | 457 IntToString(location.width()) + ", " + |
| 483 IntToString(location.height()) + ")"; | 458 IntToString(location.height()) + ")"; |
| 484 | 459 |
| 485 if (offset_container_id != -1) | 460 if (offset_container_id != -1) |
| 486 result += " offset_container_id=" + IntToString(offset_container_id); | 461 result += " offset_container_id=" + IntToString(offset_container_id); |
| 487 | 462 |
| 488 if (transform && !transform->IsIdentity()) | 463 if (transform && !transform->IsIdentity()) |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 916 } |
| 942 } | 917 } |
| 943 | 918 |
| 944 if (!child_ids.empty()) | 919 if (!child_ids.empty()) |
| 945 result += " child_ids=" + IntVectorToString(child_ids); | 920 result += " child_ids=" + IntVectorToString(child_ids); |
| 946 | 921 |
| 947 return result; | 922 return result; |
| 948 } | 923 } |
| 949 | 924 |
| 950 } // namespace ui | 925 } // namespace ui |
| OLD | NEW |