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

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

Issue 2746813002: Hide AXPlatformNode on ChromeOS. (Closed)
Patch Set: has_native_accessibility 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
deleted file mode 100644
index 891d2cc3f50ec9d488fa4ba76ce4f66b52583846..0000000000000000000000000000000000000000
--- a/ui/views/accessibility/native_view_accessibility.cc
+++ /dev/null
@@ -1,281 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/views/accessibility/native_view_accessibility.h"
-
-#include "base/memory/ptr_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "ui/events/event_utils.h"
-#include "ui/gfx/native_widget_types.h"
-#include "ui/views/controls/native/native_view_host.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-#if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
-// static
-std::unique_ptr<NativeViewAccessibility> NativeViewAccessibility::Create(
- View* view) {
- // Use WrapUnique over MakeUnique to invoke the protected constructor.
- return base::WrapUnique<NativeViewAccessibility>(
- new NativeViewAccessibility(view));
-}
-#endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL)
-
-NativeViewAccessibility::NativeViewAccessibility(View* view)
- : view_(view),
- parent_widget_(nullptr),
- ax_node_(nullptr) {
- ax_node_ = ui::AXPlatformNode::Create(this);
-}
-
-NativeViewAccessibility::~NativeViewAccessibility() {
- if (ax_node_)
- ax_node_->Destroy();
- if (parent_widget_)
- parent_widget_->RemoveObserver(this);
-}
-
-gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() {
- return ax_node_ ? ax_node_->GetNativeViewAccessible() : nullptr;
-}
-
-void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) {
- if (ax_node_)
- ax_node_->NotifyAccessibilityEvent(event_type);
-}
-
-bool NativeViewAccessibility::SetFocused(bool focused) {
- if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE))
- return false;
-
- if (focused)
- view_->RequestFocus();
- else if (view_->HasFocus())
- view_->GetFocusManager()->ClearFocus();
- return true;
-}
-
-// ui::AXPlatformNodeDelegate
-
-const ui::AXNodeData& NativeViewAccessibility::GetData() {
- data_ = ui::AXNodeData();
- data_.state = 0;
-
- // Views may misbehave if their widget is closed; return an unknown role
- // rather than possibly crashing.
- if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) {
- data_.role = ui::AX_ROLE_UNKNOWN;
- data_.state = 1 << ui::AX_STATE_DISABLED;
- return data_;
- }
-
- view_->GetAccessibleNodeData(&data_);
- data_.location = gfx::RectF(view_->GetBoundsInScreen());
- base::string16 description;
- view_->GetTooltipText(gfx::Point(), &description);
- data_.AddStringAttribute(ui::AX_ATTR_DESCRIPTION,
- base::UTF16ToUTF8(description));
-
- if (view_->IsAccessibilityFocusable())
- data_.state |= (1 << ui::AX_STATE_FOCUSABLE);
-
- if (!view_->enabled())
- data_.state |= (1 << ui::AX_STATE_DISABLED);
-
- if (!view_->IsDrawn())
- data_.state |= (1 << ui::AX_STATE_INVISIBLE);
-
- return data_;
-}
-
-int NativeViewAccessibility::GetChildCount() {
- int child_count = view_->child_count();
-
- std::vector<Widget*> child_widgets;
- PopulateChildWidgetVector(&child_widgets);
- child_count += child_widgets.size();
-
- return child_count;
-}
-
-gfx::NativeViewAccessible NativeViewAccessibility::ChildAtIndex(int index) {
- // If this is a root view, our widget might have child widgets. Include
- std::vector<Widget*> child_widgets;
- PopulateChildWidgetVector(&child_widgets);
- int child_widget_count = static_cast<int>(child_widgets.size());
-
- if (index < view_->child_count()) {
- return view_->child_at(index)->GetNativeViewAccessible();
- } else if (index < view_->child_count() + child_widget_count) {
- Widget* child_widget = child_widgets[index - view_->child_count()];
- return child_widget->GetRootView()->GetNativeViewAccessible();
- }
-
- return nullptr;
-}
-
-gfx::NativeWindow NativeViewAccessibility::GetTopLevelWidget() {
- if (view_->GetWidget())
- return view_->GetWidget()->GetTopLevelWidget()->GetNativeWindow();
- return nullptr;
-}
-
-gfx::NativeViewAccessible NativeViewAccessibility::GetParent() {
- if (view_->parent())
- return view_->parent()->GetNativeViewAccessible();
-
- if (parent_widget_)
- return parent_widget_->GetRootView()->GetNativeViewAccessible();
-
- return nullptr;
-}
-
-gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() {
- return gfx::Vector2d(0, 0); // location is already in screen coordinates.
-}
-
-gfx::NativeViewAccessible NativeViewAccessibility::HitTestSync(int x, int y) {
- if (!view_ || !view_->GetWidget())
- return nullptr;
-
- // Search child widgets first, since they're on top in the z-order.
- std::vector<Widget*> child_widgets;
- PopulateChildWidgetVector(&child_widgets);
- for (Widget* child_widget : child_widgets) {
- View* child_root_view = child_widget->GetRootView();
- gfx::Point point(x, y);
- View::ConvertPointFromScreen(child_root_view, &point);
- if (child_root_view->HitTestPoint(point))
- return child_root_view->GetNativeViewAccessible();
- }
-
- gfx::Point point(x, y);
- View::ConvertPointFromScreen(view_, &point);
- if (!view_->HitTestPoint(point))
- return nullptr;
-
- // Check if the point is within any of the immediate children of this
- // view. We don't have to search further because AXPlatformNode will
- // do a recursive hit test if we return anything other than |this| or NULL.
- for (int i = view_->child_count() - 1; i >= 0; --i) {
- View* child_view = view_->child_at(i);
- if (!child_view->visible())
- continue;
-
- gfx::Point point_in_child_coords(point);
- view_->ConvertPointToTarget(view_, child_view, &point_in_child_coords);
- if (child_view->HitTestPoint(point_in_child_coords))
- return child_view->GetNativeViewAccessible();
- }
-
- // If it's not inside any of our children, it's inside this view.
- return GetNativeObject();
-}
-
-gfx::NativeViewAccessible NativeViewAccessibility::GetFocus() {
- FocusManager* focus_manager = view_->GetFocusManager();
- View* focused_view =
- focus_manager ? focus_manager->GetFocusedView() : nullptr;
- return focused_view ? focused_view->GetNativeViewAccessible() : nullptr;
-}
-
-gfx::AcceleratedWidget
-NativeViewAccessibility::GetTargetForNativeAccessibilityEvent() {
- return gfx::kNullAcceleratedWidget;
-}
-
-bool NativeViewAccessibility::AccessibilityPerformAction(
- const ui::AXActionData& data) {
- switch (data.action) {
- // Handle accessible actions that apply to all Views here.
- case ui::AX_ACTION_DO_DEFAULT:
- DoDefaultAction();
- return true;
- case ui::AX_ACTION_FOCUS:
- return SetFocused(true);
- case ui::AX_ACTION_BLUR:
- return SetFocused(false);
-
- case ui::AX_ACTION_NONE:
- NOTREACHED();
- break;
-
- // All other actions can potentially be dealt with by the View itself.
- default:
- return view_->HandleAccessibleAction(data);
- break;
- }
- return false;
-}
-
-void NativeViewAccessibility::DoDefaultAction() {
- gfx::Point center = view_->GetLocalBounds().CenterPoint();
- view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED,
- center,
- center,
- ui::EventTimeForNow(),
- ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON));
- view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED,
- center,
- center,
- ui::EventTimeForNow(),
- ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON));
-}
-
-void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) {
- if (parent_widget_ == widget) {
- parent_widget_->RemoveObserver(this);
- parent_widget_ = nullptr;
- }
-}
-
-void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
- if (parent_widget_)
- parent_widget_->RemoveObserver(this);
- parent_widget_ = parent_widget;
- parent_widget_->AddObserver(this);
-}
-
-void NativeViewAccessibility::PopulateChildWidgetVector(
- std::vector<Widget*>* result_child_widgets) {
- // Only attach child widgets to the root view.
- Widget* widget = view_->GetWidget();
- // Note that during window close, a Widget may exist in a state where it has
- // no NativeView, but hasn't yet torn down its view hierarchy.
- if (!widget || !widget->GetNativeView() || widget->GetRootView() != view_)
- return;
-
- std::set<Widget*> child_widgets;
- Widget::GetAllOwnedWidgets(widget->GetNativeView(), &child_widgets);
- for (auto iter = child_widgets.begin(); iter != child_widgets.end(); ++iter) {
- Widget* child_widget = *iter;
- DCHECK_NE(widget, child_widget);
-
- if (!child_widget->IsVisible())
- continue;
-
- if (widget->GetNativeWindowProperty(kWidgetNativeViewHostKey))
- continue;
-
- gfx::NativeViewAccessible child_widget_accessible =
- child_widget->GetRootView()->GetNativeViewAccessible();
- ui::AXPlatformNode* child_widget_platform_node =
- ui::AXPlatformNode::FromNativeViewAccessible(child_widget_accessible);
- if (child_widget_platform_node) {
- NativeViewAccessibility* child_widget_view_accessibility =
- static_cast<NativeViewAccessibility*>(
- child_widget_platform_node->GetDelegate());
- if (child_widget_view_accessibility->parent_widget() != widget)
- child_widget_view_accessibility->SetParentWidget(widget);
- }
-
- result_child_widgets->push_back(child_widget);
- }
-}
-
-} // namespace views
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.h ('k') | ui/views/accessibility/native_view_accessibility_auralinux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698