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

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

Issue 2715543003: Views a11y: Implement AXPlatformNode::FromNativeViewAccessible on all platforms. (Closed)
Patch Set: Fix bad rebase. Created 3 years, 9 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 f2efa2ef34db7a82b4e348aafbe5c14becf4a8b6..8a6694df402206df6092a5ec5c3a60f055cea425 100644
--- a/ui/views/accessibility/native_view_accessibility.cc
+++ b/ui/views/accessibility/native_view_accessibility.cc
@@ -6,6 +6,7 @@
#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"
@@ -19,8 +20,7 @@ namespace views {
std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create(
View* view) {
// Use WrapUnique over MakeUnique to invoke the protected constructor.
- return base::WrapUnique<NativeViewAccessibility>(
- new NativeViewAccessibility(view));
+ return base::WrapUnique(new NativeViewAccessibility(view));
}
#endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
@@ -241,6 +241,25 @@ void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
parent_widget_->AddObserver(this);
}
+// 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
+}
+
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