blob: 4a6649d8fbcd0d4a7c28993cca36de16eb50dba5 [file] [log] [blame]
dmazzoni329fd012015-10-22 20:05:351// 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
14using base::DoubleToString;
15using base::IntToString;
16
17namespace ui {
18
19AXTreeData::AXTreeData()
20 : tree_id(-1),
21 parent_tree_id(-1),
dmazzonif27bf892016-03-10 15:51:5522 focused_tree_id(-1),
dmazzoni329fd012015-10-22 20:05:3523 loaded(false),
24 loading_progress(0.0),
dmazzoni965ba002016-02-19 01:43:2225 focus_id(-1),
dmazzoni329fd012015-10-22 20:05:3526 sel_anchor_object_id(-1),
27 sel_anchor_offset(-1),
dmazzoni25a949f2016-08-01 17:20:4428 sel_anchor_affinity(AX_TEXT_AFFINITY_UPSTREAM),
dmazzoni329fd012015-10-22 20:05:3529 sel_focus_object_id(-1),
dmazzoni25a949f2016-08-01 17:20:4430 sel_focus_offset(-1),
31 sel_focus_affinity(AX_TEXT_AFFINITY_DOWNSTREAM) {
dmazzoni329fd012015-10-22 20:05:3532}
33
vmpstr0ae825e72016-02-25 20:31:3134AXTreeData::AXTreeData(const AXTreeData& other) = default;
35
dmazzoni329fd012015-10-22 20:05:3536AXTreeData::~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.
41std::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);
dmazzonif27bf892016-03-10 15:51:5548 if (focused_tree_id != -1)
49 result += " focused_tree_id=" + IntToString(focused_tree_id);
dmazzoni329fd012015-10-22 20:05:3550
dmazzoni329fd012015-10-22 20:05:3551 if (!doctype.empty())
52 result += " doctype=" + doctype;
dmazzoni329fd012015-10-22 20:05:3553 if (loaded)
54 result += " loaded=true";
55 if (loading_progress != 0.0)
56 result += " loading_progress=" + DoubleToString(loading_progress);
nektar0eebf0c2016-03-16 22:08:4857 if (!mimetype.empty())
58 result += " mimetype=" + mimetype;
59 if (!url.empty())
60 result += " url=" + url;
61 if (!title.empty())
62 result += " title=" + title;
dmazzoni329fd012015-10-22 20:05:3563
dmazzoni965ba002016-02-19 01:43:2264 if (focus_id != -1)
65 result += " focus_id=" + IntToString(focus_id);
66
dmazzoni329fd012015-10-22 20:05:3567 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 Wilson8d535232017-09-07 16:24:2670 result += " sel_anchor_affinity=";
71 result += ui::ToString(sel_anchor_affinity);
dmazzoni329fd012015-10-22 20:05:3572 }
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 Wilson8d535232017-09-07 16:24:2676 result += " sel_focus_affinity=";
77 result += ui::ToString(sel_focus_affinity);
dmazzoni329fd012015-10-22 20:05:3578 }
79
80 return result;
81}
82
83bool operator==(const AXTreeData& lhs, const AXTreeData& rhs) {
84 return (lhs.tree_id == rhs.tree_id &&
85 lhs.parent_tree_id == rhs.parent_tree_id &&
dmazzonif27bf892016-03-10 15:51:5586 lhs.focused_tree_id == rhs.focused_tree_id &&
nektar0eebf0c2016-03-16 22:08:4887 lhs.doctype == rhs.doctype && lhs.loaded == rhs.loaded &&
dmazzoni329fd012015-10-22 20:05:3588 lhs.loading_progress == rhs.loading_progress &&
nektar0eebf0c2016-03-16 22:08:4889 lhs.mimetype == rhs.mimetype && lhs.title == rhs.title &&
90 lhs.url == rhs.url && lhs.focus_id == rhs.focus_id &&
dmazzoni329fd012015-10-22 20:05:3591 lhs.sel_anchor_object_id == rhs.sel_anchor_object_id &&
92 lhs.sel_anchor_offset == rhs.sel_anchor_offset &&
dmazzoni25a949f2016-08-01 17:20:4493 lhs.sel_anchor_affinity == rhs.sel_anchor_affinity &&
dmazzoni329fd012015-10-22 20:05:3594 lhs.sel_focus_object_id == rhs.sel_focus_object_id &&
dmazzoni25a949f2016-08-01 17:20:4495 lhs.sel_focus_offset == rhs.sel_focus_offset &&
96 lhs.sel_focus_affinity == rhs.sel_focus_affinity);
dmazzoni329fd012015-10-22 20:05:3597}
98
99bool operator!=(const AXTreeData& lhs, const AXTreeData& rhs) {
100 return !(lhs == rhs);
101}
102
103} // namespace ui