Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: ui/views/accessibility/native_view_accessibility.cc

Issue 2715543003: Views a11y: Implement AXPlatformNode::FromNativeViewAccessible on all platforms. (Closed)
Patch Set: Make GetForView protected. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/accessibility/native_view_accessibility.cc
diff --git a/ui/views/accessibility/native_view_accessibility.cc b/ui/views/accessibility/native_view_accessibility.cc
index 409ac5a80e802e46f6db09e2a8bbbb0cbce44b65..ef951d464bd4195ea5dbaed54abe82d324220d11 100644
--- a/ui/views/accessibility/native_view_accessibility.cc
+++ b/ui/views/accessibility/native_view_accessibility.cc
@@ -4,7 +4,11 @@
#include "ui/views/accessibility/native_view_accessibility.h"
+#include <memory>
+
+#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/native/native_view_host.h"
@@ -13,12 +17,11 @@
namespace views {
-#if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
// static
-NativeViewAccessibility* NativeViewAccessibility::Create(View* view) {
- return new NativeViewAccessibility(view);
+std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::CreateForView(
+ View* view) {
+ return base::WrapUnique(Create(view));
}
-#endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
NativeViewAccessibility::NativeViewAccessibility(View* view)
: view_(view),
@@ -38,10 +41,6 @@ gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() {
return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr;
}
-void NativeViewAccessibility::Destroy() {
- delete this;
-}
-
void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) {
if (ax_node_)
ax_node_->NotifyAccessibilityEvent(event_type);
@@ -127,10 +126,7 @@ gfx::NativeViewAccessible NativeViewAccessibility::GetParent() {
if (view_->parent())
return view_->parent()->GetNativeViewAccessible();
- if (parent_widget_)
- return parent_widget_->GetRootView()->GetNativeViewAccessible();
-
- return nullptr;
+ return GetNativeViewAccessibleForWidget();
}
gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() {
@@ -241,6 +237,39 @@ void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
parent_widget_->AddObserver(this);
}
+gfx::NativeViewAccessible
+NativeViewAccessibility::GetNativeViewAccessibleForWidget() {
+ if (parent_widget_)
+ return parent_widget_->GetRootView()->GetNativeViewAccessible();
+ return nullptr;
+}
+
+// static
+NativeViewAccessibility* NativeViewAccessibility::GetForView(View* view) {
+#if defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
+ // Retrieving the gfx::NativeViewAccessible also ensures that a
+ // NativeViewAccessibility exists for the given View.
+ gfx::NativeViewAccessible native_object = view->GetNativeViewAccessible();
+ ui::AXPlatformNode* node =
+ ui::AXPlatformNode::FromNativeViewAccessible(native_object);
+ DCHECK(node);
+ return static_cast<NativeViewAccessibility*>(node->GetDelegate());
+#else
+ // Platforms (currently ChromeOS) without a native implementation also have no
+ // gfx::NativeViewAccessible, so make sure a NativeViewAccessibility exists
+ // and return the instance belonging to |view|.
+ view->GetNativeViewAccessible();
+ return view->native_view_accessibility_.get();
+#endif
+}
+
+#if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
+// static
+NativeViewAccessibility* NativeViewAccessibility::Create(View* view) {
+ return new NativeViewAccessibility(view);
+}
+#endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
+
void NativeViewAccessibility::PopulateChildWidgetVector(
std::vector<Widget*>* result_child_widgets) {
// Only attach child widgets to the root view.

Powered by Google App Engine
This is Rietveld 408576698