Commit 9e84ea0a authored by minch's avatar minch Committed by Commit Bot

a11y: Activate magnifier while drag a window across displays.

The root window and root_location of the event are still based on the
original display while dragging a window across displays. This makes
the magnifier will not be activated in the display that the window has
been dragged to until the drag be released.

This cl updates the root window and root location during drag to make
sure the magnifier can be activated at corresponding display
immediately while drag a window across displays.


Bug: 1082392
Change-Id: Ie3feb7679c29e1e9c0b4f8811ae98bd0f170ade0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354997Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799883}
parent cff79c96
......@@ -429,12 +429,26 @@ void MagnificationController::OnWindowBoundsChanged(
void MagnificationController::OnMouseEvent(ui::MouseEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
aura::Window* current_root = target->GetRootWindow();
gfx::Rect root_bounds = current_root->bounds();
gfx::Point root_location = event->root_location();
if (event->type() == ui::ET_MOUSE_DRAGGED) {
auto* screen = display::Screen::GetScreen();
const gfx::Point cursor_screen_location = screen->GetCursorScreenPoint();
auto* window = screen->GetWindowAtScreenPoint(cursor_screen_location);
// Update the |current_root| to be the one that contains the cursor
// currently. This will make sure the magnifier be activated in the display
// that contains the cursor while drag a window across displays.
current_root =
window ? window->GetRootWindow() : Shell::GetPrimaryRootWindow();
root_location = cursor_screen_location;
wm::ConvertPointFromScreen(current_root, &root_location);
}
if (root_bounds.Contains(event->root_location())) {
if (current_root->bounds().Contains(root_location)) {
// This must be before |SwitchTargetRootWindow()|.
if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)
point_of_interest_in_root_ = event->root_location();
point_of_interest_in_root_ = root_location;
if (current_root != root_window_) {
DCHECK(current_root);
......@@ -445,7 +459,7 @@ void MagnificationController::OnMouseEvent(ui::MouseEvent* event) {
event->type() == ui::ET_MOUSE_DRAGGED;
if (IsMagnified() && dragged_or_moved &&
event->pointer_details().pointer_type != ui::EventPointerType::kPen) {
OnMouseMove(event->root_location());
OnMouseMove(root_location);
}
}
}
......
......@@ -1126,4 +1126,30 @@ TEST_F(MagnificationControllerTest, DragWindow) {
EXPECT_NE(initial_window_bounds, window->bounds());
}
// Tests that the magnifier gets updated while drag a window across displays.
TEST_F(MagnificationControllerTest, DragWindowAcrossDisplays) {
UpdateDisplay("0+0-500x500, 500+0-500x500");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
// Create a window and start dragging by grabbing its caption.
std::unique_ptr<aura::Window> window =
CreateTestWindow(gfx::Rect(100, 100, 300, 300));
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->set_current_screen_location(gfx::Point(105, 105));
event_generator->PressLeftButton();
ASSERT_TRUE(WindowState::Get(window.get())->is_dragged());
GetMagnificationController()->SetEnabled(true);
event_generator->MoveMouseToInHost(gfx::Point(250, 250));
EXPECT_FALSE(root_windows[0]->layer()->transform().IsIdentity());
EXPECT_TRUE(root_windows[1]->layer()->transform().IsIdentity());
// Move the cursor manually since EventGenerator uses a hack to move the
// cursor between displays.
root_windows[1]->MoveCursorTo(gfx::Point(950, 250));
event_generator->MoveMouseToInHost(gfx::Point(950, 250));
EXPECT_TRUE(root_windows[0]->layer()->transform().IsIdentity());
EXPECT_FALSE(root_windows[1]->layer()->transform().IsIdentity());
}
} // namespace ash
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