Commit 19ccbee7 authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

Fix text location bounds computation in ARC a11y

http://crrev/c/1978202 fixed the scaling computation, but
ArcAccessibilityHelperBridge::OnGetTextLocationDataResult left
unchanged.
This method is used in Select-to-Speak to get text location, so we also
need to fix it.

This CL also refactors bounds computation and adds a new file geometry_util.

Bug: b:129680977
Test: manual. (ChromeVox, HighlightInputFocus and S2S with various scale)
Change-Id: I091d5a91e083d160b4c20af0529744b9b0613eec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980265
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729166}
parent 6d763d76
...@@ -474,6 +474,8 @@ source_set("chromeos") { ...@@ -474,6 +474,8 @@ source_set("chromeos") {
"arc/accessibility/arc_accessibility_util.h", "arc/accessibility/arc_accessibility_util.h",
"arc/accessibility/ax_tree_source_arc.cc", "arc/accessibility/ax_tree_source_arc.cc",
"arc/accessibility/ax_tree_source_arc.h", "arc/accessibility/ax_tree_source_arc.h",
"arc/accessibility/geometry_util.cc",
"arc/accessibility/geometry_util.h",
"arc/app_shortcuts/arc_app_shortcut_item.cc", "arc/app_shortcuts/arc_app_shortcut_item.cc",
"arc/app_shortcuts/arc_app_shortcut_item.h", "arc/app_shortcuts/arc_app_shortcut_item.h",
"arc/app_shortcuts/arc_app_shortcuts_menu_builder.cc", "arc/app_shortcuts/arc_app_shortcuts_menu_builder.cc",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "chrome/browser/chromeos/arc/accessibility/geometry_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
#include "chrome/common/extensions/api/accessibility_private.h" #include "chrome/common/extensions/api/accessibility_private.h"
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -69,23 +71,9 @@ void DispatchFocusChange(arc::mojom::AccessibilityNodeInfoData* node_data, ...@@ -69,23 +71,9 @@ void DispatchFocusChange(arc::mojom::AccessibilityNodeInfoData* node_data,
if (!active_window) if (!active_window)
return; return;
gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect( gfx::Rect bounds_in_screen = gfx::ToEnclosingRect(arc::ToChromeBounds(
node_data->bounds_in_screen, node_data->bounds_in_screen, wm_helper,
1.0f / wm_helper->GetDefaultDeviceScaleFactor()); views::Widget::GetWidgetForNativeView(active_window)));
views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window);
DCHECK(widget);
// On Android side, content is rendered without considering height of
// caption bar, e.g. Content is rendered at y:0 instead of y:32 where 32 is
// height of caption bar. Add back height of caption bar here.
if (widget->IsMaximized()) {
bounds_in_screen.Offset(
0, static_cast<int>(static_cast<float>(widget->non_client_view()
->frame_view()
->GetBoundsForClientView()
.y())));
}
accessibility_manager->OnViewFocusedInArc(bounds_in_screen); accessibility_manager->OnViewFocusedInArc(bounds_in_screen);
} }
...@@ -708,7 +696,27 @@ void ArcAccessibilityHelperBridge::OnGetTextLocationDataResult( ...@@ -708,7 +696,27 @@ void ArcAccessibilityHelperBridge::OnGetTextLocationDataResult(
if (!tree_source) if (!tree_source)
return; return;
tree_source->NotifyGetTextLocationDataResult(data, result_rect); tree_source->NotifyGetTextLocationDataResult(
data, OnGetTextLocationDataResultInternal(result_rect));
}
base::Optional<gfx::Rect>
ArcAccessibilityHelperBridge::OnGetTextLocationDataResultInternal(
const base::Optional<gfx::Rect>& result_rect) const {
if (!result_rect)
return base::nullopt;
exo::WMHelper* wm_helper = exo::WMHelper::GetInstance();
if (!wm_helper)
return base::nullopt;
aura::Window* active_window = wm_helper->GetActiveWindow();
if (!active_window)
return base::nullopt;
gfx::RectF rect_f = arc::ToChromeScale(*result_rect, wm_helper);
arc::ScaleDeviceFactor(rect_f, active_window->GetToplevelWindow());
return gfx::ToEnclosingRect(rect_f);
} }
void ArcAccessibilityHelperBridge::OnAccessibilityStatusChanged( void ArcAccessibilityHelperBridge::OnAccessibilityStatusChanged(
......
...@@ -136,6 +136,9 @@ class ArcAccessibilityHelperBridge ...@@ -136,6 +136,9 @@ class ArcAccessibilityHelperBridge
const ui::AXActionData& data, const ui::AXActionData& data,
const base::Optional<gfx::Rect>& result_rect) const; const base::Optional<gfx::Rect>& result_rect) const;
base::Optional<gfx::Rect> OnGetTextLocationDataResultInternal(
const base::Optional<gfx::Rect>& result_rect) const;
void OnAccessibilityStatusChanged( void OnAccessibilityStatusChanged(
const chromeos::AccessibilityStatusEventDetails& event_details); const chromeos::AccessibilityStatusEventDetails& event_details);
arc::mojom::AccessibilityFilterType GetFilterTypeForProfile(Profile* profile); arc::mojom::AccessibilityFilterType GetFilterTypeForProfile(Profile* profile);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/arc/accessibility/accessibility_node_info_data_wrapper.h" #include "chrome/browser/chromeos/arc/accessibility/accessibility_node_info_data_wrapper.h"
#include "chrome/browser/chromeos/arc/accessibility/accessibility_window_info_data_wrapper.h" #include "chrome/browser/chromeos/arc/accessibility/accessibility_window_info_data_wrapper.h"
#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_util.h" #include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_util.h"
#include "chrome/browser/chromeos/arc/accessibility/geometry_util.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "extensions/browser/api/automation_internal/automation_event_router.h" #include "extensions/browser/api/automation_internal/automation_event_router.h"
...@@ -19,6 +20,8 @@ ...@@ -19,6 +20,8 @@
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/platform/ax_android_constants.h" #include "ui/accessibility/platform/ax_android_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -235,39 +238,26 @@ const gfx::Rect AXTreeSourceArc::GetBounds( ...@@ -235,39 +238,26 @@ const gfx::Rect AXTreeSourceArc::GetBounds(
if (!wm_helper) if (!wm_helper)
return info_data_bounds; return info_data_bounds;
// TODO(katie): offset_container_id should work and we shouldn't have to
// go into this code path for each node.
aura::Window* toplevel_window = active_window->GetToplevelWindow();
views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window); views::Widget* widget = views::Widget::GetWidgetForNativeView(active_window);
DCHECK(widget); DCHECK(widget);
gfx::RectF info_data_bounds_f =
arc::ToChromeBounds(info_data_bounds, wm_helper, widget);
// TODO(katie): offset_container_id should work and we shouldn't have to
// go into this code path for each node.
DCHECK(widget->widget_delegate()); DCHECK(widget->widget_delegate());
DCHECK(widget->widget_delegate()->GetContentsView()); DCHECK(widget->widget_delegate()->GetContentsView());
const gfx::Rect bounds = const gfx::Rect root_bounds =
widget->widget_delegate()->GetContentsView()->GetBoundsInScreen(); widget->widget_delegate()->GetContentsView()->GetBoundsInScreen();
float scale = wm_helper->GetDefaultDeviceScaleFactor();
// Bounds of root node is relative to its container, i.e. contents view // Bounds of root node is relative to its container, i.e. contents view
// (ShellSurfaceBase). // (ShellSurfaceBase).
info_data_bounds.Offset( info_data_bounds_f.Offset(-1 * root_bounds.x(), -1 * root_bounds.y());
static_cast<int>(-1.0f * scale * static_cast<float>(bounds.x())),
static_cast<int>(-1.0f * scale * static_cast<float>(bounds.y()))); arc::ScaleDeviceFactor(info_data_bounds_f,
active_window->GetToplevelWindow());
// On Android side, content is rendered without considering height of return gfx::ToEnclosingRect(info_data_bounds_f);
// caption bar, e.g. content is rendered at y:0 instead of y:32 where 32 is
// height of caption bar. Add back height of caption bar here.
if (widget->IsMaximized()) {
info_data_bounds.Offset(
0, static_cast<int>(scale *
static_cast<float>(widget->non_client_view()
->frame_view()
->GetBoundsForClientView()
.y())));
}
return gfx::ScaleToEnclosingRect(
info_data_bounds,
toplevel_window->layer()->device_scale_factor() / scale);
} }
void AXTreeSourceArc::InvalidateTree() { void AXTreeSourceArc::InvalidateTree() {
......
// Copyright 2020 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.
#ifndef CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
#include "components/exo/wm_helper.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/views/widget/widget.h"
namespace arc {
gfx::RectF ToChromeScale(const gfx::Rect& bounds, exo::WMHelper* wm_helper) {
DCHECK(wm_helper);
gfx::RectF bounds_f(bounds);
bounds_f.Scale(1.0f / wm_helper->GetDefaultDeviceScaleFactor());
return bounds_f;
}
gfx::RectF ToChromeBounds(const gfx::Rect& bounds,
exo::WMHelper* wm_helper,
views::Widget* widget) {
DCHECK(wm_helper);
DCHECK(widget);
gfx::RectF chrome_bounds = ToChromeScale(bounds, wm_helper);
// On Android side, content is rendered without considering height of
// caption bar, e.g. Content is rendered at y:0 instead of y:32 where 32 is
// height of caption bar. Add back height of caption bar here.
if (widget->IsMaximized()) {
chrome_bounds.Offset(
0,
widget->non_client_view()->frame_view()->GetBoundsForClientView().y());
}
return chrome_bounds;
}
void ScaleDeviceFactor(gfx::RectF& bounds, aura::Window* toplevel_window) {
DCHECK(toplevel_window);
bounds.Scale(toplevel_window->layer()->device_scale_factor());
}
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
// Copyright 2020 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.
#ifndef CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
// TODO(hirokisato) support multiple display.
namespace aura {
class Window;
}
namespace exo {
class WMHelper;
}
namespace gfx {
class RectF;
}
namespace views {
class Widget;
}
namespace arc {
// Given ARC pixels, returns DIPs in Chrome OS main display.
// This function only scales the bounds.
gfx::RectF ToChromeScale(const gfx::Rect& rect, exo::WMHelper* wm_helper);
// Given ARC pixels in screen coordinate, returns DIPs in Chrome OS main
// display. This function adjusts differences between ARC and Chrome.
gfx::RectF ToChromeBounds(const gfx::Rect& rect,
exo::WMHelper* wm_helper,
views::Widget* widget);
// Given DIPs in Chrome OS main display, scales it into pixels.
void ScaleDeviceFactor(gfx::RectF& rect, aura::Window* toplevel_window);
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment