Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ax_tree_id.cc
Go to the documentation of this file.
1// Copyright 2018 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 "ax_tree_id.h"
6
7#include <algorithm>
8#include <iostream>
9
10#include "ax_enums.h"
11#include "base/logging.h"
12#include "base/no_destructor.h"
13
14namespace ui {
15
16AXTreeID::AXTreeID() : AXTreeID(ax::mojom::AXTreeIDType::kUnknown) {}
17
18AXTreeID::AXTreeID(const AXTreeID& other) = default;
19
23}
24
25AXTreeID::AXTreeID(const std::string& string) {
26 if (string.empty()) {
28 } else {
30 std::optional<base::SimpleToken> token = base::ValueToSimpleToken(string);
32 token_ = *token;
33 }
34}
35
36// static
37AXTreeID AXTreeID::FromString(const std::string& string) {
38 return AXTreeID(string);
39}
40
41// static
43 return AXTreeID(token.ToString());
44}
45
46// static
50
51AXTreeID& AXTreeID::operator=(const AXTreeID& other) = default;
52
53std::string AXTreeID::ToString() const {
54 switch (type_) {
56 return "";
58 return base::SimpleTokenToValue(*token_);
59 }
60
62 return std::string();
63}
64
65void swap(AXTreeID& first, AXTreeID& second) {
66 std::swap(first.type_, second.type_);
67 std::swap(first.token_, second.token_);
68}
69
70bool AXTreeID::operator==(const AXTreeID& rhs) const {
71 return type_ == rhs.type_ && token_ == rhs.token_;
72}
73
74bool AXTreeID::operator!=(const AXTreeID& rhs) const {
75 return !(*this == rhs);
76}
77
78bool AXTreeID::operator<(const AXTreeID& rhs) const {
79 return std::tie(type_, token_) < std::tie(rhs.type_, rhs.token_);
80}
81
82bool AXTreeID::operator<=(const AXTreeID& rhs) const {
83 return std::tie(type_, token_) <= std::tie(rhs.type_, rhs.token_);
84}
85
86bool AXTreeID::operator>(const AXTreeID& rhs) const {
87 return !(*this <= rhs);
88}
89
90bool AXTreeID::operator>=(const AXTreeID& rhs) const {
91 return !(*this < rhs);
92}
93
94size_t AXTreeIDHash::operator()(const ui::AXTreeID& tree_id) const {
96 return base::SimpleTokenHash(tree_id.token().value());
97}
98
99std::ostream& operator<<(std::ostream& stream, const AXTreeID& value) {
100 return stream << value.ToString();
101}
102
104 static const base::NoDestructor<AXTreeID> ax_tree_id_unknown(
106 return *ax_tree_id_unknown;
107}
108
109} // namespace ui
static SimpleToken Create()
static AXTreeID FromString(const std::string &string)
Definition ax_tree_id.cc:37
bool operator>(const AXTreeID &rhs) const
Definition ax_tree_id.cc:86
static AXTreeID CreateNewAXTreeID()
Definition ax_tree_id.cc:47
AXTreeID & operator=(const AXTreeID &other)
bool operator==(const AXTreeID &rhs) const
Definition ax_tree_id.cc:70
bool operator>=(const AXTreeID &rhs) const
Definition ax_tree_id.cc:90
std::string ToString() const
Definition ax_tree_id.cc:53
const std::optional< base::SimpleToken > & token() const
Definition ax_tree_id.h:43
bool operator!=(const AXTreeID &rhs) const
Definition ax_tree_id.cc:74
bool operator<(const AXTreeID &rhs) const
Definition ax_tree_id.cc:78
static AXTreeID FromToken(const base::SimpleToken &token)
Definition ax_tree_id.cc:42
bool operator<=(const AXTreeID &rhs) const
Definition ax_tree_id.cc:82
ax::mojom::AXTreeIDType type() const
Definition ax_tree_id.h:42
EMSCRIPTEN_KEEPALIVE void empty()
uint8_t value
size_t SimpleTokenHash(const SimpleToken &SimpleToken)
std::optional< base::SimpleToken > ValueToSimpleToken(std::string str)
std::string SimpleTokenToValue(const SimpleToken &token)
const AXTreeID & AXTreeIDUnknown()
void swap(AXPosition< AXPositionType, AXNodeType > &first, AXPosition< AXPositionType, AXNodeType > &second)
std::ostream & operator<<(std::ostream &os, AXEventGenerator::Event event)
size_t operator()(const ui::AXTreeID &tree_id) const
Definition ax_tree_id.cc:94
#define BASE_DCHECK(condition)
Definition logging.h:63
#define BASE_UNREACHABLE()
Definition logging.h:69