| OLD | NEW |
| 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 #include "ui/accessibility/ax_action_data.h" | 5 #include "ui/accessibility/ax_action_data.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <set> | 8 #include <set> |
| 8 | 9 |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 | 14 |
| 14 using base::IntToString; | 15 using base::IntToString; |
| 15 | 16 |
| 16 namespace ui { | 17 namespace ui { |
| 17 | 18 |
| 18 AXActionData::AXActionData() | 19 AXActionData::AXActionData() |
| 19 : action(AX_ACTION_NONE), | 20 : action(AX_ACTION_NONE), |
| 20 target_node_id(-1), | 21 target_node_id(-1), |
| 21 flags(0), | 22 flags(0), |
| 22 anchor_node_id(-1), | 23 anchor_node_id(-1), |
| 23 anchor_offset(-1), | 24 anchor_offset(-1), |
| 24 focus_node_id(-1), | 25 focus_node_id(-1), |
| 25 focus_offset(-1) { | 26 focus_offset(-1) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 AXActionData::AXActionData(const AXActionData& other) = default; | 29 AXActionData::AXActionData(const AXActionData& other) = default; |
| 29 | 30 |
| 30 AXActionData::~AXActionData() { | 31 AXActionData::~AXActionData() { |
| 31 } | 32 } |
| 32 | 33 |
| 34 void AXActionData::AddBoolAttribute(AXActionBoolAttribute attribute, |
| 35 bool value) { |
| 36 bool_attributes.push_back(std::make_pair(attribute, value)); |
| 37 } |
| 38 |
| 39 bool AXActionData::GetBoolAttribute(AXActionBoolAttribute attr) const { |
| 40 auto iter = |
| 41 std::find_if(bool_attributes.begin(), bool_attributes.end(), |
| 42 [attr](const std::pair<AXActionBoolAttribute, bool>& item) { |
| 43 return item.first == attr; |
| 44 }); |
| 45 return iter != bool_attributes.end() && iter->second; |
| 46 } |
| 47 |
| 33 // Note that this includes an initial space character if nonempty, but | 48 // Note that this includes an initial space character if nonempty, but |
| 34 // that works fine because this is normally printed by AXAction::ToString. | 49 // that works fine because this is normally printed by AXAction::ToString. |
| 35 std::string AXActionData::ToString() const { | 50 std::string AXActionData::ToString() const { |
| 36 std::string result = ui::ToString(action); | 51 std::string result = ui::ToString(action); |
| 37 | 52 |
| 38 if (target_node_id != -1) | 53 if (target_node_id != -1) |
| 39 result += " target_node_id=" + IntToString(target_node_id); | 54 result += " target_node_id=" + IntToString(target_node_id); |
| 40 | 55 |
| 41 if (flags & (1 << ui::AX_ACTION_FLAGS_REQUEST_IMAGES)) | 56 if (flags & (1 << ui::AX_ACTION_FLAGS_REQUEST_IMAGES)) |
| 42 result += " flag_request_images"; | 57 result += " flag_request_images"; |
| 43 | 58 |
| 44 if (flags & (1 << ui::AX_ACTION_FLAGS_REQUEST_INLINE_TEXT_BOXES)) | 59 if (flags & (1 << ui::AX_ACTION_FLAGS_REQUEST_INLINE_TEXT_BOXES)) |
| 45 result += " flag_request_inline_text_boxes"; | 60 result += " flag_request_inline_text_boxes"; |
| 46 | 61 |
| 47 if (anchor_node_id != -1) { | 62 if (anchor_node_id != -1) { |
| 48 result += " anchor_node_id=" + IntToString(anchor_node_id); | 63 result += " anchor_node_id=" + IntToString(anchor_node_id); |
| 49 result += " anchor_offset=" + IntToString(anchor_offset); | 64 result += " anchor_offset=" + IntToString(anchor_offset); |
| 50 } | 65 } |
| 51 if (focus_node_id != -1) { | 66 if (focus_node_id != -1) { |
| 52 result += " focus_node_id=" + IntToString(focus_node_id); | 67 result += " focus_node_id=" + IntToString(focus_node_id); |
| 53 result += " focus_offset=" + IntToString(focus_offset); | 68 result += " focus_offset=" + IntToString(focus_offset); |
| 54 } | 69 } |
| 55 | 70 |
| 56 return result; | 71 return result; |
| 57 } | 72 } |
| 58 | 73 |
| 59 } // namespace ui | 74 } // namespace ui |
| OLD | NEW |