| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 case AX_ATTR_WORD_STARTS: | 163 case AX_ATTR_WORD_STARTS: |
| 151 case AX_ATTR_WORD_ENDS: | 164 case AX_ATTR_WORD_ENDS: |
| 152 return false; | 165 return false; |
| 153 } | 166 } |
| 154 | 167 |
| 155 NOTREACHED(); | 168 NOTREACHED(); |
| 156 return false; | 169 return false; |
| 157 } | 170 } |
| 158 | 171 |
| 159 AXNodeData::AXNodeData() | 172 AXNodeData::AXNodeData() |
| 160 : id(-1), | 173 : id(-1), role(AX_ROLE_UNKNOWN), state(0), offset_container_id(-1) {} |
| 161 role(AX_ROLE_UNKNOWN), | |
| 162 // Turn on all flags to more easily catch bugs where no flags are set. | |
| 163 // This will be cleared back to a 0-state before use. | |
| 164 state(0xFFFFFFFF), | |
| 165 offset_container_id(-1) { | |
| 166 } | |
| 167 | 174 |
| 168 AXNodeData::~AXNodeData() { | 175 AXNodeData::~AXNodeData() { |
| 169 } | 176 } |
| 170 | 177 |
| 171 AXNodeData::AXNodeData(const AXNodeData& other) { | 178 AXNodeData::AXNodeData(const AXNodeData& other) { |
| 172 id = other.id; | 179 id = other.id; |
| 173 role = other.role; | 180 role = other.role; |
| 174 state = other.state; | 181 state = other.state; |
| 175 string_attributes = other.string_attributes; | 182 string_attributes = other.string_attributes; |
| 176 int_attributes = other.int_attributes; | 183 int_attributes = other.int_attributes; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 417 } |
| 411 } | 418 } |
| 412 | 419 |
| 413 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value)); | 420 string_attributes.push_back(std::make_pair(AX_ATTR_VALUE, value)); |
| 414 } | 421 } |
| 415 | 422 |
| 416 void AXNodeData::SetValue(const base::string16& value) { | 423 void AXNodeData::SetValue(const base::string16& value) { |
| 417 SetValue(base::UTF16ToUTF8(value)); | 424 SetValue(base::UTF16ToUTF8(value)); |
| 418 } | 425 } |
| 419 | 426 |
| 420 // static | 427 bool AXNodeData::HasState(AXState state_flag) const { |
| 421 bool AXNodeData::IsFlagSet(uint32_t state, ui::AXState state_flag) { | 428 return IsFlagSet(state, state_flag); |
| 422 return 0 != (state & (1 << state_flag)); | |
| 423 } | 429 } |
| 424 | 430 |
| 425 void AXNodeData::AddStateFlag(ui::AXState state_flag) { | 431 void AXNodeData::AddState(AXState state_flag) { |
| 432 DCHECK_NE(state_flag, AX_STATE_NONE); |
| 426 state |= (1 << state_flag); | 433 state |= (1 << state_flag); |
| 427 } | 434 } |
| 428 | 435 |
| 429 bool AXNodeData::HasStateFlag(ui::AXState state_flag) const { | |
| 430 return IsFlagSet(state, state_flag); | |
| 431 } | |
| 432 | |
| 433 std::string AXNodeData::ToString() const { | 436 std::string AXNodeData::ToString() const { |
| 434 std::string result; | 437 std::string result; |
| 435 | 438 |
| 436 result += "id=" + IntToString(id); | 439 result += "id=" + IntToString(id); |
| 437 result += " " + ui::ToString(role); | 440 result += " " + ui::ToString(role); |
| 438 | 441 |
| 439 if (state & (1 << AX_STATE_BUSY)) | 442 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 | 443 |
| 480 result += " (" + IntToString(location.x()) + ", " + | 444 result += " (" + IntToString(location.x()) + ", " + |
| 481 IntToString(location.y()) + ")-(" + | 445 IntToString(location.y()) + ")-(" + |
| 482 IntToString(location.width()) + ", " + | 446 IntToString(location.width()) + ", " + |
| 483 IntToString(location.height()) + ")"; | 447 IntToString(location.height()) + ")"; |
| 484 | 448 |
| 485 if (offset_container_id != -1) | 449 if (offset_container_id != -1) |
| 486 result += " offset_container_id=" + IntToString(offset_container_id); | 450 result += " offset_container_id=" + IntToString(offset_container_id); |
| 487 | 451 |
| 488 if (transform && !transform->IsIdentity()) | 452 if (transform && !transform->IsIdentity()) |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 905 } |
| 942 } | 906 } |
| 943 | 907 |
| 944 if (!child_ids.empty()) | 908 if (!child_ids.empty()) |
| 945 result += " child_ids=" + IntVectorToString(child_ids); | 909 result += " child_ids=" + IntVectorToString(child_ids); |
| 946 | 910 |
| 947 return result; | 911 return result; |
| 948 } | 912 } |
| 949 | 913 |
| 950 } // namespace ui | 914 } // namespace ui |
| OLD | NEW |