Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ui / accessibility / platform / ax_platform_node_base.cc
blob2c1bf90507da7516cb6934759f9cced686be641c
1 // Copyright 2014 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.
5 #include "ui/accessibility/platform/ax_platform_node_base.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_node_data.h"
9 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
11 namespace ui {
13 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) {
14 delegate_ = delegate;
17 const AXNodeData& AXPlatformNodeBase::GetData() const {
18 CHECK(delegate_);
19 return delegate_->GetData();
22 gfx::Rect AXPlatformNodeBase::GetBoundsInScreen() const {
23 CHECK(delegate_);
24 gfx::Rect bounds = GetData().location;
25 bounds.Offset(delegate_->GetGlobalCoordinateOffset());
26 return bounds;
29 gfx::NativeViewAccessible AXPlatformNodeBase::GetParent() {
30 CHECK(delegate_);
31 return delegate_->GetParent();
34 int AXPlatformNodeBase::GetChildCount() {
35 CHECK(delegate_);
36 return delegate_->GetChildCount();
39 gfx::NativeViewAccessible AXPlatformNodeBase::ChildAtIndex(int index) {
40 CHECK(delegate_);
41 return delegate_->ChildAtIndex(index);
44 // AXPlatformNode overrides.
46 void AXPlatformNodeBase::Destroy() {
47 delegate_ = nullptr;
48 delete this;
51 gfx::NativeViewAccessible AXPlatformNodeBase::GetNativeViewAccessible() {
52 return nullptr;
55 AXPlatformNodeDelegate* AXPlatformNodeBase::GetDelegate() const {
56 return delegate_;
59 // Helpers.
61 AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() {
62 CHECK(delegate_);
63 gfx::NativeViewAccessible parent_accessible = GetParent();
64 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible);
65 if (!parent)
66 return nullptr;
68 int previous_index = GetIndexInParent() - 1;
69 if (previous_index >= 0 &&
70 previous_index < parent->GetChildCount()) {
71 return FromNativeViewAccessible(parent->ChildAtIndex(previous_index));
73 return nullptr;
76 AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() {
77 CHECK(delegate_);
78 gfx::NativeViewAccessible parent_accessible = GetParent();
79 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible);
80 if (!parent)
81 return nullptr;
83 int next_index = GetIndexInParent() + 1;
84 if (next_index >= 0 && next_index < parent->GetChildCount())
85 return FromNativeViewAccessible(parent->ChildAtIndex(next_index));
86 return nullptr;
89 bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) {
90 CHECK(delegate_);
91 if (!node)
92 return false;
93 if (node == this)
94 return true;
95 AXPlatformNodeBase* parent = FromNativeViewAccessible(node->GetParent());
96 return IsDescendant(parent);
99 bool AXPlatformNodeBase::HasBoolAttribute(
100 ui::AXBoolAttribute attribute) const {
101 CHECK(delegate_);
102 return GetData().HasBoolAttribute(attribute);
105 bool AXPlatformNodeBase::GetBoolAttribute(
106 ui::AXBoolAttribute attribute) const {
107 CHECK(delegate_);
108 return GetData().GetBoolAttribute(attribute);
111 bool AXPlatformNodeBase::GetBoolAttribute(
112 ui::AXBoolAttribute attribute, bool* value) const {
113 CHECK(delegate_);
114 return GetData().GetBoolAttribute(attribute, value);
117 bool AXPlatformNodeBase::HasFloatAttribute(
118 ui::AXFloatAttribute attribute) const {
119 CHECK(delegate_);
120 return GetData().HasFloatAttribute(attribute);
123 float AXPlatformNodeBase::GetFloatAttribute(
124 ui::AXFloatAttribute attribute) const {
125 CHECK(delegate_);
126 return GetData().GetFloatAttribute(attribute);
129 bool AXPlatformNodeBase::GetFloatAttribute(
130 ui::AXFloatAttribute attribute, float* value) const {
131 CHECK(delegate_);
132 return GetData().GetFloatAttribute(attribute, value);
135 bool AXPlatformNodeBase::HasIntAttribute(
136 ui::AXIntAttribute attribute) const {
137 CHECK(delegate_);
138 return GetData().HasIntAttribute(attribute);
141 int AXPlatformNodeBase::GetIntAttribute(
142 ui::AXIntAttribute attribute) const {
143 CHECK(delegate_);
144 return GetData().GetIntAttribute(attribute);
147 bool AXPlatformNodeBase::GetIntAttribute(
148 ui::AXIntAttribute attribute, int* value) const {
149 CHECK(delegate_);
150 return GetData().GetIntAttribute(attribute, value);
153 bool AXPlatformNodeBase::HasStringAttribute(
154 ui::AXStringAttribute attribute) const {
155 CHECK(delegate_);
156 return GetData().HasStringAttribute(attribute);
159 const std::string& AXPlatformNodeBase::GetStringAttribute(
160 ui::AXStringAttribute attribute) const {
161 CHECK(delegate_);
162 return GetData().GetStringAttribute(attribute);
165 bool AXPlatformNodeBase::GetStringAttribute(
166 ui::AXStringAttribute attribute, std::string* value) const {
167 CHECK(delegate_);
168 return GetData().GetStringAttribute(attribute, value);
171 base::string16 AXPlatformNodeBase::GetString16Attribute(
172 ui::AXStringAttribute attribute) const {
173 CHECK(delegate_);
174 return GetData().GetString16Attribute(attribute);
177 bool AXPlatformNodeBase::GetString16Attribute(
178 ui::AXStringAttribute attribute,
179 base::string16* value) const {
180 CHECK(delegate_);
181 return GetData().GetString16Attribute(attribute, value);
184 AXPlatformNodeBase::AXPlatformNodeBase() {
187 AXPlatformNodeBase::~AXPlatformNodeBase() {
190 // static
191 AXPlatformNodeBase* AXPlatformNodeBase::FromNativeViewAccessible(
192 gfx::NativeViewAccessible accessible) {
193 return static_cast<AXPlatformNodeBase*>(
194 AXPlatformNode::FromNativeViewAccessible(accessible));
197 } // namespace ui