dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/accessibility/ax_action_data.h" |
| 6 | |
| 7 | #include <set> |
| 8 | |
| 9 | #include "base/strings/string_number_conversions.h" |
| 10 | #include "base/strings/string_util.h" |
| 11 | #include "base/strings/stringprintf.h" |
| 12 | #include "base/strings/utf_string_conversions.h" |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 13 | #include "ui/accessibility/ax_enum_util.h" |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 14 | |
| 15 | using base::IntToString; |
| 16 | |
| 17 | namespace ui { |
| 18 | |
Brett Wilson | 0feae3a | 2017-12-06 03:16:56 | [diff] [blame] | 19 | AXActionData::AXActionData() = default; |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 20 | AXActionData::AXActionData(const AXActionData& other) = default; |
Brett Wilson | 0feae3a | 2017-12-06 03:16:56 | [diff] [blame] | 21 | AXActionData::~AXActionData() = default; |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 22 | |
Dominic Mazzoni | 909f8e7 | 2018-01-24 20:37:04 | [diff] [blame] | 23 | namespace { |
| 24 | |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 25 | bool IsFlagSet(uint32_t bitfield, ax::mojom::ActionFlags flag) { |
Dominic Mazzoni | 909f8e7 | 2018-01-24 20:37:04 | [diff] [blame] | 26 | return 0 != (bitfield & (1 << static_cast<uint32_t>(flag))); |
| 27 | } |
| 28 | |
| 29 | } // namespace |
| 30 | |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 31 | // Note that this includes an initial space character if nonempty, but |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 32 | // that works fine because this is normally printed by |
| 33 | // ax::mojom::Action::ToString. |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 34 | std::string AXActionData::ToString() const { |
| 35 | std::string result = ui::ToString(action); |
| 36 | |
| 37 | if (target_node_id != -1) |
| 38 | result += " target_node_id=" + IntToString(target_node_id); |
| 39 | |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 40 | if (IsFlagSet(flags, ax::mojom::ActionFlags::kRequestImages)) |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 41 | result += " flag_request_images"; |
| 42 | |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 43 | if (IsFlagSet(flags, ax::mojom::ActionFlags::kRequestInlineTextBoxes)) |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 44 | result += " flag_request_inline_text_boxes"; |
| 45 | |
dmazzoni | e6f29fc | 2016-10-19 16:34:29 | [diff] [blame] | 46 | if (anchor_node_id != -1) { |
| 47 | result += " anchor_node_id=" + IntToString(anchor_node_id); |
| 48 | result += " anchor_offset=" + IntToString(anchor_offset); |
| 49 | } |
| 50 | if (focus_node_id != -1) { |
| 51 | result += " focus_node_id=" + IntToString(focus_node_id); |
| 52 | result += " focus_offset=" + IntToString(focus_offset); |
| 53 | } |
| 54 | |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | } // namespace ui |