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"
13 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate
* delegate
) {
17 const AXNodeData
& AXPlatformNodeBase::GetData() const {
19 return delegate_
->GetData();
22 gfx::Rect
AXPlatformNodeBase::GetBoundsInScreen() const {
24 gfx::Rect bounds
= GetData().location
;
25 bounds
.Offset(delegate_
->GetGlobalCoordinateOffset());
29 gfx::NativeViewAccessible
AXPlatformNodeBase::GetParent() {
31 return delegate_
->GetParent();
34 int AXPlatformNodeBase::GetChildCount() {
36 return delegate_
->GetChildCount();
39 gfx::NativeViewAccessible
AXPlatformNodeBase::ChildAtIndex(int index
) {
41 return delegate_
->ChildAtIndex(index
);
44 // AXPlatformNode overrides.
46 void AXPlatformNodeBase::Destroy() {
51 gfx::NativeViewAccessible
AXPlatformNodeBase::GetNativeViewAccessible() {
55 AXPlatformNodeDelegate
* AXPlatformNodeBase::GetDelegate() const {
61 AXPlatformNodeBase
* AXPlatformNodeBase::GetPreviousSibling() {
63 gfx::NativeViewAccessible parent_accessible
= GetParent();
64 AXPlatformNodeBase
* parent
= FromNativeViewAccessible(parent_accessible
);
68 int previous_index
= GetIndexInParent() - 1;
69 if (previous_index
>= 0 &&
70 previous_index
< parent
->GetChildCount()) {
71 return FromNativeViewAccessible(parent
->ChildAtIndex(previous_index
));
76 AXPlatformNodeBase
* AXPlatformNodeBase::GetNextSibling() {
78 gfx::NativeViewAccessible parent_accessible
= GetParent();
79 AXPlatformNodeBase
* parent
= FromNativeViewAccessible(parent_accessible
);
83 int next_index
= GetIndexInParent() + 1;
84 if (next_index
>= 0 && next_index
< parent
->GetChildCount())
85 return FromNativeViewAccessible(parent
->ChildAtIndex(next_index
));
89 bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase
* node
) {
95 AXPlatformNodeBase
* parent
= FromNativeViewAccessible(node
->GetParent());
96 return IsDescendant(parent
);
99 bool AXPlatformNodeBase::HasBoolAttribute(
100 ui::AXBoolAttribute attribute
) const {
102 return GetData().HasBoolAttribute(attribute
);
105 bool AXPlatformNodeBase::GetBoolAttribute(
106 ui::AXBoolAttribute attribute
) const {
108 return GetData().GetBoolAttribute(attribute
);
111 bool AXPlatformNodeBase::GetBoolAttribute(
112 ui::AXBoolAttribute attribute
, bool* value
) const {
114 return GetData().GetBoolAttribute(attribute
, value
);
117 bool AXPlatformNodeBase::HasFloatAttribute(
118 ui::AXFloatAttribute attribute
) const {
120 return GetData().HasFloatAttribute(attribute
);
123 float AXPlatformNodeBase::GetFloatAttribute(
124 ui::AXFloatAttribute attribute
) const {
126 return GetData().GetFloatAttribute(attribute
);
129 bool AXPlatformNodeBase::GetFloatAttribute(
130 ui::AXFloatAttribute attribute
, float* value
) const {
132 return GetData().GetFloatAttribute(attribute
, value
);
135 bool AXPlatformNodeBase::HasIntAttribute(
136 ui::AXIntAttribute attribute
) const {
138 return GetData().HasIntAttribute(attribute
);
141 int AXPlatformNodeBase::GetIntAttribute(
142 ui::AXIntAttribute attribute
) const {
144 return GetData().GetIntAttribute(attribute
);
147 bool AXPlatformNodeBase::GetIntAttribute(
148 ui::AXIntAttribute attribute
, int* value
) const {
150 return GetData().GetIntAttribute(attribute
, value
);
153 bool AXPlatformNodeBase::HasStringAttribute(
154 ui::AXStringAttribute attribute
) const {
156 return GetData().HasStringAttribute(attribute
);
159 const std::string
& AXPlatformNodeBase::GetStringAttribute(
160 ui::AXStringAttribute attribute
) const {
162 return GetData().GetStringAttribute(attribute
);
165 bool AXPlatformNodeBase::GetStringAttribute(
166 ui::AXStringAttribute attribute
, std::string
* value
) const {
168 return GetData().GetStringAttribute(attribute
, value
);
171 base::string16
AXPlatformNodeBase::GetString16Attribute(
172 ui::AXStringAttribute attribute
) const {
174 return GetData().GetString16Attribute(attribute
);
177 bool AXPlatformNodeBase::GetString16Attribute(
178 ui::AXStringAttribute attribute
,
179 base::string16
* value
) const {
181 return GetData().GetString16Attribute(attribute
, value
);
184 AXPlatformNodeBase::AXPlatformNodeBase() {
187 AXPlatformNodeBase::~AXPlatformNodeBase() {
191 AXPlatformNodeBase
* AXPlatformNodeBase::FromNativeViewAccessible(
192 gfx::NativeViewAccessible accessible
) {
193 return static_cast<AXPlatformNodeBase
*>(
194 AXPlatformNode::FromNativeViewAccessible(accessible
));