| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/accessibility/native_view_accessibility.h" | 5 #include "ui/views/accessibility/native_view_accessibility.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/accessibility/platform/ax_platform_node.h" |
| 9 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| 10 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
| 11 #include "ui/views/controls/native/native_view_host.h" | 12 #include "ui/views/controls/native/native_view_host.h" |
| 12 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 18 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
| 18 // static | 19 // static |
| 19 std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create( | 20 std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create( |
| 20 View* view) { | 21 View* view) { |
| 21 // Use WrapUnique over MakeUnique to invoke the protected constructor. | 22 // Use WrapUnique over MakeUnique to invoke the protected constructor. |
| 22 return base::WrapUnique<NativeViewAccessibility>( | 23 return base::WrapUnique(new NativeViewAccessibility(view)); |
| 23 new NativeViewAccessibility(view)); | |
| 24 } | 24 } |
| 25 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 25 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
| 26 | 26 |
| 27 NativeViewAccessibility::NativeViewAccessibility(View* view) | 27 NativeViewAccessibility::NativeViewAccessibility(View* view) |
| 28 : view_(view), | 28 : view_(view), |
| 29 parent_widget_(nullptr), | 29 parent_widget_(nullptr), |
| 30 ax_node_(nullptr) { | 30 ax_node_(nullptr) { |
| 31 ax_node_ = ui::AXPlatformNode::Create(this); | 31 ax_node_ = ui::AXPlatformNode::Create(this); |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { | 237 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { |
| 238 if (parent_widget_) | 238 if (parent_widget_) |
| 239 parent_widget_->RemoveObserver(this); | 239 parent_widget_->RemoveObserver(this); |
| 240 parent_widget_ = parent_widget; | 240 parent_widget_ = parent_widget; |
| 241 parent_widget_->AddObserver(this); | 241 parent_widget_->AddObserver(this); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // static |
| 245 NativeViewAccessibility* NativeViewAccessibility::GetForView(View* view) { |
| 246 #if defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
| 247 // Retrieving the gfx::NativeViewAccessible also ensures that a |
| 248 // NativeViewAccessibility exists for the given View. |
| 249 gfx::NativeViewAccessible native_object = view->GetNativeViewAccessible(); |
| 250 ui::AXPlatformNode* node = |
| 251 ui::AXPlatformNode::FromNativeViewAccessible(native_object); |
| 252 DCHECK(node); |
| 253 return static_cast<NativeViewAccessibility*>(node->GetDelegate()); |
| 254 #else |
| 255 // Platforms (currently ChromeOS) without a native implementation also have no |
| 256 // gfx::NativeViewAccessible, so make sure a NativeViewAccessibility exists |
| 257 // and return the instance belonging to |view|. |
| 258 view->GetNativeViewAccessible(); |
| 259 return view->native_view_accessibility_.get(); |
| 260 #endif |
| 261 } |
| 262 |
| 244 void NativeViewAccessibility::PopulateChildWidgetVector( | 263 void NativeViewAccessibility::PopulateChildWidgetVector( |
| 245 std::vector<Widget*>* result_child_widgets) { | 264 std::vector<Widget*>* result_child_widgets) { |
| 246 // Only attach child widgets to the root view. | 265 // Only attach child widgets to the root view. |
| 247 Widget* widget = view_->GetWidget(); | 266 Widget* widget = view_->GetWidget(); |
| 248 if (!widget || widget->GetRootView() != view_) | 267 if (!widget || widget->GetRootView() != view_) |
| 249 return; | 268 return; |
| 250 | 269 |
| 251 std::set<Widget*> child_widgets; | 270 std::set<Widget*> child_widgets; |
| 252 Widget::GetAllOwnedWidgets(widget->GetNativeView(), &child_widgets); | 271 Widget::GetAllOwnedWidgets(widget->GetNativeView(), &child_widgets); |
| 253 for (auto iter = child_widgets.begin(); iter != child_widgets.end(); ++iter) { | 272 for (auto iter = child_widgets.begin(); iter != child_widgets.end(); ++iter) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 270 child_widget_platform_node->GetDelegate()); | 289 child_widget_platform_node->GetDelegate()); |
| 271 if (child_widget_view_accessibility->parent_widget() != widget) | 290 if (child_widget_view_accessibility->parent_widget() != widget) |
| 272 child_widget_view_accessibility->SetParentWidget(widget); | 291 child_widget_view_accessibility->SetParentWidget(widget); |
| 273 } | 292 } |
| 274 | 293 |
| 275 result_child_widgets->push_back(child_widget); | 294 result_child_widgets->push_back(child_widget); |
| 276 } | 295 } |
| 277 } | 296 } |
| 278 | 297 |
| 279 } // namespace views | 298 } // namespace views |
| OLD | NEW |