Commit 5b5759d0 authored by Tess Eisenberger's avatar Tess Eisenberger Committed by Commit Bot

[fuchsia][a11y] Apply device pixel scaling to hit tests

Hit test coordinates from the a11y-manager are relative to the
registered view's coordinate space. When pixel scaling is on, this
coordinate space is scaled to be a device-independent space. However,
Chromium's semantic trees are scaled to the device resolution. This
patch adds scaling of the received coordinates to compensate for this
difference.

Note that with this patch, Fuchsia highlights are still quite broken.
There is likely some degree of scaling issue there, but the more
major problem is fuchsia:62891.

Fixed: fuchsia:59633
Change-Id: I1e4217592a48fe284a60b5edb294c21b855744a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508322
Commit-Queue: Tess Eisenberger <teisenbe@google.com>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarSharon Yang <yangsharon@chromium.org>
Auto-Submit: Tess Eisenberger <teisenbe@google.com>
Cr-Commit-Position: refs/heads/master@{#826637}
parent ca288e0c
......@@ -11,6 +11,7 @@
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "content/public/browser/render_widget_host_view.h"
#include "fuchsia/engine/browser/ax_tree_converter.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/gfx/geometry/rect_conversions.h"
......@@ -171,8 +172,9 @@ void AccessibilityBridge::HitTest(fuchsia::math::PointF local_point,
ui::AXActionData action_data;
action_data.action = ax::mojom::Action::kHitTest;
gfx::Point point;
point.set_x(local_point.x);
point.set_y(local_point.y);
float device_scale_factor = GetDeviceScaleFactor();
point.set_x(local_point.x * device_scale_factor);
point.set_y(local_point.y * device_scale_factor);
action_data.target_point = point;
action_data.hit_test_event_to_fire = ax::mojom::Event::kHitTestResult;
pending_hit_test_callbacks_[action_data.request_id] = std::move(callback);
......@@ -244,3 +246,10 @@ void AccessibilityBridge::InterruptPendingActions() {
}
pending_hit_test_callbacks_.clear();
}
float AccessibilityBridge::GetDeviceScaleFactor() {
if (device_scale_factor_override_for_test_) {
return *device_scale_factor_override_for_test_;
}
return web_contents_->GetRenderWidgetHostView()->GetDeviceScaleFactor();
}
......@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/optional.h"
#include "content/public/browser/ax_event_notification_details.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -56,6 +57,10 @@ class WEB_ENGINE_EXPORT AccessibilityBridge
event_received_callback_for_test_ = std::move(callback);
}
void set_device_scale_factor_for_test(float device_scale_factor) {
device_scale_factor_override_for_test_ = device_scale_factor;
}
private:
FRIEND_TEST_ALL_PREFIXES(AccessibilityBridgeTest, OnSemanticsModeChanged);
FRIEND_TEST_ALL_PREFIXES(AccessibilityBridgeTest,
......@@ -71,6 +76,10 @@ class WEB_ENGINE_EXPORT AccessibilityBridge
// destruction time or when semantic updates have been disabled.
void InterruptPendingActions();
// Accessor for the device scale factor that allows for overriding the value
// in tests.
float GetDeviceScaleFactor();
// content::WebContentsObserver implementation.
void AccessibilityEventReceived(
const content::AXEventNotificationDetails& details) override;
......@@ -117,6 +126,9 @@ class WEB_ENGINE_EXPORT AccessibilityBridge
int32_t root_id_ = 0;
base::OnceClosure event_received_callback_for_test_;
// If set, the scale factor for this device for use in tests.
base::Optional<float> device_scale_factor_override_for_test_;
};
#endif // FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_
......@@ -231,6 +231,16 @@ IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, HitTest) {
fuchsia::math::PointF target_point = GetCenterOfBox(target_node->location());
float scale_factor = 20.f;
// Make the bridge use scaling in hit test calculations.
AccessibilityBridge* bridge = frame_impl_->accessibility_bridge_for_test();
bridge->set_device_scale_factor_for_test(scale_factor);
// Downscale the target point, since the hit test calculation will scale it
// back up.
target_point.x /= scale_factor;
target_point.y /= scale_factor;
uint32_t hit_node_id =
semantics_manager_.HitTestAtPointSync(std::move(target_point));
fuchsia::accessibility::semantics::Node* hit_node =
......@@ -243,8 +253,8 @@ IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, HitTest) {
target_point.x = -1;
target_point.y = -1;
EXPECT_EQ(0u, semantics_manager_.HitTestAtPointSync(std::move(target_point)));
target_point.x = 1;
target_point.y = 1;
target_point.x = 1. / scale_factor;
target_point.y = 1. / scale_factor;
EXPECT_EQ(0u, semantics_manager_.HitTestAtPointSync(std::move(target_point)));
}
......
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