dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 1 | // Copyright 2015 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_tree_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" |
| 13 | |
| 14 | using base::DoubleToString; |
| 15 | using base::IntToString; |
| 16 | |
| 17 | namespace ui { |
| 18 | |
| 19 | AXTreeData::AXTreeData() |
| 20 | : tree_id(-1), |
| 21 | parent_tree_id(-1), |
dmazzoni | f27bf89 | 2016-03-10 15:51:55 | [diff] [blame] | 22 | focused_tree_id(-1), |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 23 | loaded(false), |
| 24 | loading_progress(0.0), |
dmazzoni | 965ba00 | 2016-02-19 01:43:22 | [diff] [blame] | 25 | focus_id(-1), |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 26 | sel_anchor_object_id(-1), |
| 27 | sel_anchor_offset(-1), |
dmazzoni | 25a949f | 2016-08-01 17:20:44 | [diff] [blame] | 28 | sel_anchor_affinity(AX_TEXT_AFFINITY_UPSTREAM), |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 29 | sel_focus_object_id(-1), |
dmazzoni | 25a949f | 2016-08-01 17:20:44 | [diff] [blame] | 30 | sel_focus_offset(-1), |
| 31 | sel_focus_affinity(AX_TEXT_AFFINITY_DOWNSTREAM) { |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 32 | } |
| 33 | |
vmpstr | 0ae825e7 | 2016-02-25 20:31:31 | [diff] [blame] | 34 | AXTreeData::AXTreeData(const AXTreeData& other) = default; |
| 35 | |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 36 | AXTreeData::~AXTreeData() { |
| 37 | } |
| 38 | |
| 39 | // Note that this includes an initial space character if nonempty, but |
| 40 | // that works fine because this is normally printed by AXTree::ToString. |
| 41 | std::string AXTreeData::ToString() const { |
| 42 | std::string result; |
| 43 | |
| 44 | if (tree_id != -1) |
| 45 | result += " tree_id=" + IntToString(tree_id); |
| 46 | if (parent_tree_id != -1) |
| 47 | result += " parent_tree_id=" + IntToString(parent_tree_id); |
dmazzoni | f27bf89 | 2016-03-10 15:51:55 | [diff] [blame] | 48 | if (focused_tree_id != -1) |
| 49 | result += " focused_tree_id=" + IntToString(focused_tree_id); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 50 | |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 51 | if (!doctype.empty()) |
| 52 | result += " doctype=" + doctype; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 53 | if (loaded) |
| 54 | result += " loaded=true"; |
| 55 | if (loading_progress != 0.0) |
| 56 | result += " loading_progress=" + DoubleToString(loading_progress); |
nektar | 0eebf0c | 2016-03-16 22:08:48 | [diff] [blame] | 57 | if (!mimetype.empty()) |
| 58 | result += " mimetype=" + mimetype; |
| 59 | if (!url.empty()) |
| 60 | result += " url=" + url; |
| 61 | if (!title.empty()) |
| 62 | result += " title=" + title; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 63 | |
dmazzoni | 965ba00 | 2016-02-19 01:43:22 | [diff] [blame] | 64 | if (focus_id != -1) |
| 65 | result += " focus_id=" + IntToString(focus_id); |
| 66 | |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 67 | if (sel_anchor_object_id != -1) { |
| 68 | result += " sel_anchor_object_id=" + IntToString(sel_anchor_object_id); |
| 69 | result += " sel_anchor_offset=" + IntToString(sel_anchor_offset); |
Brett Wilson | 8d53523 | 2017-09-07 16:24:26 | [diff] [blame] | 70 | result += " sel_anchor_affinity="; |
| 71 | result += ui::ToString(sel_anchor_affinity); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 72 | } |
| 73 | if (sel_focus_object_id != -1) { |
| 74 | result += " sel_focus_object_id=" + IntToString(sel_focus_object_id); |
| 75 | result += " sel_focus_offset=" + IntToString(sel_focus_offset); |
Brett Wilson | 8d53523 | 2017-09-07 16:24:26 | [diff] [blame] | 76 | result += " sel_focus_affinity="; |
| 77 | result += ui::ToString(sel_focus_affinity); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | bool operator==(const AXTreeData& lhs, const AXTreeData& rhs) { |
| 84 | return (lhs.tree_id == rhs.tree_id && |
| 85 | lhs.parent_tree_id == rhs.parent_tree_id && |
dmazzoni | f27bf89 | 2016-03-10 15:51:55 | [diff] [blame] | 86 | lhs.focused_tree_id == rhs.focused_tree_id && |
nektar | 0eebf0c | 2016-03-16 22:08:48 | [diff] [blame] | 87 | lhs.doctype == rhs.doctype && lhs.loaded == rhs.loaded && |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 88 | lhs.loading_progress == rhs.loading_progress && |
nektar | 0eebf0c | 2016-03-16 22:08:48 | [diff] [blame] | 89 | lhs.mimetype == rhs.mimetype && lhs.title == rhs.title && |
| 90 | lhs.url == rhs.url && lhs.focus_id == rhs.focus_id && |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 91 | lhs.sel_anchor_object_id == rhs.sel_anchor_object_id && |
| 92 | lhs.sel_anchor_offset == rhs.sel_anchor_offset && |
dmazzoni | 25a949f | 2016-08-01 17:20:44 | [diff] [blame] | 93 | lhs.sel_anchor_affinity == rhs.sel_anchor_affinity && |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 94 | lhs.sel_focus_object_id == rhs.sel_focus_object_id && |
dmazzoni | 25a949f | 2016-08-01 17:20:44 | [diff] [blame] | 95 | lhs.sel_focus_offset == rhs.sel_focus_offset && |
| 96 | lhs.sel_focus_affinity == rhs.sel_focus_affinity); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool operator!=(const AXTreeData& lhs, const AXTreeData& rhs) { |
| 100 | return !(lhs == rhs); |
| 101 | } |
| 102 | |
| 103 | } // namespace ui |