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

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

Issue 2715543003: Views a11y: Implement AXPlatformNode::FromNativeViewAccessible on all platforms. (Closed)
Patch Set: Rebase 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 f2efa2ef34db7a82b4e348aafbe5c14becf4a8b6..1b71c884973ac234a269f1efba9905f6ab31cb2c 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"
@@ -14,15 +15,11 @@
namespace views {
-#if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
// static
-std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create(
+std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::CreateForView(
View* view) {
- // Use WrapUnique over MakeUnique to invoke the protected constructor.
- return base::WrapUnique<NativeViewAccessibility>(
- new NativeViewAccessibility(view));
+ return base::WrapUnique(Create(view));
}
-#endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
NativeViewAccessibility::NativeViewAccessibility(View* view)
: view_(view),
@@ -241,6 +238,32 @@ 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();
tapted 2017/03/06 01:43:09 The CL description needs to be clear why this is n
Patti Lor 2017/03/13 03:03:25 Updated the description with why we need a fallbac
+#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