Commit 96979774 authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

arc-a11y: Use correct scale factor for ARC R

Starting ARC R, ARC natively supports display density. As a result, when
the client is ARC P, the bounds are always scaled by the default device
scale factor, and when the client is ARC R and later, the bounds are
always scaled by the screen scale of the display, which matches the
browser behavior.

This CL addresses the above change in accessibility layer.

AX-Relnotes: n/a. (a part of preparation for ARC R)
Bug: b:17251157
Test: manual. Open PlayStore and change scale factor by ctrl+shift+(+/-) with P and R.
Change-Id: Iae39adaed7b3fc7a00962edc9da617b89dea7202
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540266
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829057}
parent 2b5b4772
...@@ -35,9 +35,9 @@ void AccessibilityInfoDataWrapper::PopulateBounds( ...@@ -35,9 +35,9 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
tree_source_->is_input_method_window() || root->GetId() != GetId()) { tree_source_->is_input_method_window() || root->GetId() != GetId()) {
// By default, populate the bounds relative to the tree root. // By default, populate the bounds relative to the tree root.
const gfx::Rect& root_bounds = root->GetBounds(); const gfx::Rect& root_bounds = root->GetBounds();
info_data_bounds.Offset(-1 * root_bounds.x(), -1 * root_bounds.y()); info_data_bounds.Offset(-1 * root_bounds.x(), -1 * root_bounds.y());
out_bounds = ToChromeScale(info_data_bounds);
out_bounds = ScaleAndroidPxToChromePx(info_data_bounds, window);
out_data->relative_bounds.offset_container_id = root->GetId(); out_data->relative_bounds.offset_container_id = root->GetId();
} else { } else {
// For the root node of application tree, populate the bounds to be // For the root node of application tree, populate the bounds to be
...@@ -46,17 +46,21 @@ void AccessibilityInfoDataWrapper::PopulateBounds( ...@@ -46,17 +46,21 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
DCHECK(widget); DCHECK(widget);
DCHECK(widget->widget_delegate()); DCHECK(widget->widget_delegate());
DCHECK(widget->widget_delegate()->GetContentsView()); DCHECK(widget->widget_delegate()->GetContentsView());
const gfx::Rect& root_bounds = gfx::PointF root_origin = gfx::PointF(widget->widget_delegate()
widget->widget_delegate()->GetContentsView()->GetBoundsInScreen(); ->GetContentsView()
->GetBoundsInScreen()
.origin());
out_bounds = ToChromeBounds(info_data_bounds, widget); // Adjust the origin because a maximized window has an offset in Android.
out_bounds.Offset(-1 * root_bounds.x(), -1 * root_bounds.y()); root_origin.Offset(0, -1 * GetChromeWindowHeightOffsetInDip(window));
}
// |out_bounds| is in Chrome DPI here. As ARC is considered the same as web // Scale to Chrome pixels.
// in Chrome automation, scale the bounds by device scale factor. root_origin.Scale(
out_bounds.Scale( window->GetToplevelWindow()->layer()->device_scale_factor());
window->GetToplevelWindow()->layer()->device_scale_factor());
out_bounds = ScaleAndroidPxToChromePx(info_data_bounds, window);
out_bounds.Offset(-1 * root_origin.x(), -1 * root_origin.y());
}
} else { } else {
// We cannot compute global bounds, so use the raw bounds. // We cannot compute global bounds, so use the raw bounds.
out_bounds.SetRect(info_data_bounds.x(), info_data_bounds.y(), out_bounds.SetRect(info_data_bounds.x(), info_data_bounds.y(),
......
...@@ -93,9 +93,14 @@ void DispatchFocusChange(arc::mojom::AccessibilityNodeInfoData* node_data, ...@@ -93,9 +93,14 @@ void DispatchFocusChange(arc::mojom::AccessibilityNodeInfoData* node_data,
if (!active_window) if (!active_window)
return; return;
gfx::Rect bounds_in_screen = gfx::ToEnclosingRect(arc::ToChromeBounds( // Convert bounds from Android pixels to Chrome DIP, and adjust coordinate to
// Chrome's screen coordinate.
gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect(
node_data->bounds_in_screen, node_data->bounds_in_screen,
views::Widget::GetWidgetForNativeView(active_window))); 1.0f / exo::WMHelper::GetInstance()->GetDeviceScaleFactorForWindow(
active_window));
bounds_in_screen.Offset(0,
arc::GetChromeWindowHeightOffsetInDip(active_window));
bool is_editable = arc::GetBooleanProperty( bool is_editable = arc::GetBooleanProperty(
node_data, arc::mojom::AccessibilityBooleanProperty::EDITABLE); node_data, arc::mojom::AccessibilityBooleanProperty::EDITABLE);
...@@ -677,8 +682,8 @@ ArcAccessibilityHelperBridge::OnGetTextLocationDataResultInternal( ...@@ -677,8 +682,8 @@ ArcAccessibilityHelperBridge::OnGetTextLocationDataResultInternal(
if (!active_window) if (!active_window)
return base::nullopt; return base::nullopt;
gfx::RectF rect_f = arc::ToChromeScale(*result_rect); const gfx::RectF& rect_f =
rect_f.Scale(DeviceScaleFactorFromWindow(active_window)); ScaleAndroidPxToChromePx(result_rect.value(), active_window);
return gfx::ToEnclosingRect(rect_f); return gfx::ToEnclosingRect(rect_f);
} }
......
...@@ -14,28 +14,32 @@ ...@@ -14,28 +14,32 @@
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace arc { namespace arc {
gfx::RectF ToChromeScale(const gfx::Rect& bounds) { gfx::RectF ScaleAndroidPxToChromePx(const gfx::Rect& android_bounds,
aura::Window* window) {
DCHECK(exo::WMHelper::HasInstance()); DCHECK(exo::WMHelper::HasInstance());
gfx::RectF bounds_f(bounds); DCHECK(window);
bounds_f.Scale(1.0f /
exo::WMHelper::GetInstance()->GetDefaultDeviceScaleFactor());
return bounds_f;
}
gfx::RectF ToChromeBounds(const gfx::Rect& bounds, views::Widget* widget) { const float chrome_dsf =
DCHECK(widget); window->GetToplevelWindow()->layer()->device_scale_factor();
gfx::RectF chrome_bounds = ToChromeScale(bounds); const float android_dsf =
exo::WMHelper::GetInstance()->GetDeviceScaleFactorForWindow(window);
if (chrome_dsf == android_dsf)
return gfx::RectF(android_bounds);
gfx::RectF chrome_bounds(android_bounds);
chrome_bounds.Scale(chrome_dsf / android_dsf);
return chrome_bounds;
}
int GetChromeWindowHeightOffsetInDip(aura::Window* window) {
// On Android side, content is rendered without considering height of // 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 // caption bar when it's maximized, e.g. Content is rendered at y:0 instead of
// height of caption bar. Add back height of caption bar here. // y:32 where 32 is height of caption bar.
if (widget->IsMaximized()) { views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
chrome_bounds.Offset( if (!widget->IsMaximized())
0, return 0;
widget->non_client_view()->frame_view()->GetBoundsForClientView().y());
}
return chrome_bounds; return widget->non_client_view()->frame_view()->GetBoundsForClientView().y();
} }
} // namespace arc } // namespace arc
......
...@@ -11,18 +11,19 @@ namespace gfx { ...@@ -11,18 +11,19 @@ namespace gfx {
class RectF; class RectF;
} }
namespace views { namespace aura {
class Widget; class Window;
} }
namespace arc { namespace arc {
// Given ARC pixels, returns DIPs in Chrome OS main display. // Given a rect in Android pixels, returns a scaled rectangle in Chrome pixels.
// This function only scales the bounds. // This only scales the given bounds.
gfx::RectF ToChromeScale(const gfx::Rect& rect); gfx::RectF ScaleAndroidPxToChromePx(const gfx::Rect& android_bounds,
aura::Window* window);
// Given ARC pixels in screen coordinate, returns DIPs in Chrome OS main // Returns an difference of y coordinate in DIP between Android internal bounds
// display. This function adjusts differences between ARC and Chrome. // and what Chrome actually renders in the screen.
gfx::RectF ToChromeBounds(const gfx::Rect& rect, views::Widget* widget); int GetChromeWindowHeightOffsetInDip(aura::Window* window);
} // namespace arc } // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_GEOMETRY_UTIL_H_ #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