Commit 14011246 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: send a11y alert when window moved to another display

changes:
- make moving window between displays shortcuts "window needed", which
  means a11y alert "Alert Command unavailable. Press control-N to open
  a new window" is alerted when there is no window available.
- send a11y alert when there is actual window movement by shortcuts

Bug: 783058
Test: tested on device, working as expected; added test coverage.
Change-Id: I97a1fc2b771a10e1480a0a3dcf5107ae171e4f36
Reviewed-on: https://chromium-review.googlesource.com/767861
Commit-Queue: Qiang(Joe) Xu <warx@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516394}
parent 27dcbb8a
...@@ -257,22 +257,21 @@ void HandleMediaPrevTrack() { ...@@ -257,22 +257,21 @@ void HandleMediaPrevTrack() {
Shell::Get()->media_controller()->HandleMediaPrevTrack(); Shell::Get()->media_controller()->HandleMediaPrevTrack();
} }
void HandleMoveWindowBetweenDisplays(const ui::Accelerator& accelerator) { void HandleMoveWindowBetweenDisplays(AcceleratorAction action) {
ui::KeyboardCode key_code = accelerator.key_code();
DisplayMoveWindowDirection direction; DisplayMoveWindowDirection direction;
if (key_code == ui::VKEY_LEFT) { if (action == MOVE_WINDOW_TO_ABOVE_DISPLAY) {
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Left_Display"));
direction = DisplayMoveWindowDirection::kLeft;
} else if (key_code == ui::VKEY_UP) {
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Above_Display")); base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Above_Display"));
direction = DisplayMoveWindowDirection::kAbove; direction = DisplayMoveWindowDirection::kAbove;
} else if (key_code == ui::VKEY_RIGHT) { } else if (action == MOVE_WINDOW_TO_BELOW_DISPLAY) {
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Right_Display"));
direction = DisplayMoveWindowDirection::kRight;
} else {
DCHECK(key_code == ui::VKEY_DOWN);
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Below_Display")); base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Below_Display"));
direction = DisplayMoveWindowDirection::kBelow; direction = DisplayMoveWindowDirection::kBelow;
} else if (action == MOVE_WINDOW_TO_LEFT_DISPLAY) {
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Left_Display"));
direction = DisplayMoveWindowDirection::kLeft;
} else {
DCHECK(action == MOVE_WINDOW_TO_RIGHT_DISPLAY);
base::RecordAction(UserMetricsAction("Accel_Move_Window_To_Right_Display"));
direction = DisplayMoveWindowDirection::kRight;
} }
HandleMoveWindowToDisplay(direction); HandleMoveWindowToDisplay(direction);
} }
...@@ -1324,7 +1323,7 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1324,7 +1323,7 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case MOVE_WINDOW_TO_BELOW_DISPLAY: case MOVE_WINDOW_TO_BELOW_DISPLAY:
case MOVE_WINDOW_TO_LEFT_DISPLAY: case MOVE_WINDOW_TO_LEFT_DISPLAY:
case MOVE_WINDOW_TO_RIGHT_DISPLAY: case MOVE_WINDOW_TO_RIGHT_DISPLAY:
HandleMoveWindowBetweenDisplays(accelerator); HandleMoveWindowBetweenDisplays(action);
break; break;
case NEW_INCOGNITO_WINDOW: case NEW_INCOGNITO_WINDOW:
HandleNewIncognitoWindow(); HandleNewIncognitoWindow();
......
...@@ -489,14 +489,18 @@ const size_t kActionsAllowedInPinnedModeLength = ...@@ -489,14 +489,18 @@ const size_t kActionsAllowedInPinnedModeLength =
const AcceleratorAction kActionsNeedingWindow[] = { const AcceleratorAction kActionsNeedingWindow[] = {
CYCLE_BACKWARD_MRU, CYCLE_BACKWARD_MRU,
CYCLE_FORWARD_MRU, CYCLE_FORWARD_MRU,
MOVE_WINDOW_TO_ABOVE_DISPLAY,
MOVE_WINDOW_TO_BELOW_DISPLAY,
MOVE_WINDOW_TO_LEFT_DISPLAY,
MOVE_WINDOW_TO_RIGHT_DISPLAY,
ROTATE_WINDOW,
TOGGLE_FULLSCREEN,
TOGGLE_MAXIMIZED,
TOGGLE_OVERVIEW, TOGGLE_OVERVIEW,
WINDOW_CYCLE_SNAP_LEFT, WINDOW_CYCLE_SNAP_LEFT,
WINDOW_CYCLE_SNAP_RIGHT, WINDOW_CYCLE_SNAP_RIGHT,
WINDOW_MINIMIZE, WINDOW_MINIMIZE,
TOGGLE_FULLSCREEN,
TOGGLE_MAXIMIZED,
WINDOW_POSITION_CENTER, WINDOW_POSITION_CENTER,
ROTATE_WINDOW,
}; };
const size_t kActionsNeedingWindowLength = arraysize(kActionsNeedingWindow); const size_t kActionsNeedingWindowLength = arraysize(kActionsNeedingWindow);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <stdint.h> #include <stdint.h>
#include <array> #include <array>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/shell.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/display/display.h" #include "ui/display/display.h"
...@@ -142,7 +144,23 @@ void HandleMoveWindowToDisplay(DisplayMoveWindowDirection direction) { ...@@ -142,7 +144,23 @@ void HandleMoveWindowToDisplay(DisplayMoveWindowDirection direction) {
display::Display origin_display = display::Display origin_display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window); display::Screen::GetScreen()->GetDisplayNearestWindow(window);
int64_t dest_display_id = GetNextDisplay(origin_display, direction); int64_t dest_display_id = GetNextDisplay(origin_display, direction);
if (dest_display_id == display::kInvalidDisplayId)
return;
wm::MoveWindowToDisplay(window, dest_display_id); wm::MoveWindowToDisplay(window, dest_display_id);
// Send a11y alert.
mojom::AccessibilityAlert alert = mojom::AccessibilityAlert::NONE;
if (direction == DisplayMoveWindowDirection::kAbove) {
alert = mojom::AccessibilityAlert::WINDOW_MOVED_TO_ABOVE_DISPLAY;
} else if (direction == DisplayMoveWindowDirection::kBelow) {
alert = mojom::AccessibilityAlert::WINDOW_MOVED_TO_BELOW_DISPLAY;
} else if (direction == DisplayMoveWindowDirection::kLeft) {
alert = mojom::AccessibilityAlert::WINDOW_MOVED_TO_LEFT_DISPLAY;
} else {
DCHECK(direction == DisplayMoveWindowDirection::kRight);
alert = mojom::AccessibilityAlert::WINDOW_MOVED_TO_RIGHT_DISPLAY;
}
Shell::Get()->accessibility_controller()->TriggerAccessibilityAlert(alert);
} }
} // namespace ash } // namespace ash
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/display/display_move_window_util.h" #include "ash/display/display_move_window_util.h"
#include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/test_accessibility_controller_client.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
...@@ -213,4 +215,37 @@ TEST_F(DisplayMoveWindowUtilTest, SelectClosestCandidate) { ...@@ -213,4 +215,37 @@ TEST_F(DisplayMoveWindowUtilTest, SelectClosestCandidate) {
EXPECT_EQ(list[5], screen->GetDisplayNearestWindow(window).id()); EXPECT_EQ(list[5], screen->GetDisplayNearestWindow(window).id());
} }
// Tests that a11y alert is sent on handling move window to display.
TEST_F(DisplayMoveWindowUtilTest, A11yAlert) {
display::Screen* screen = display::Screen::GetScreen();
int64_t primary_id = screen->GetPrimaryDisplay().id();
display::DisplayIdList list =
display::test::CreateDisplayIdList2(primary_id, primary_id + 1);
// Layout: [p][1]
display::DisplayLayoutBuilder builder(primary_id);
builder.AddDisplayPlacement(list[1], primary_id,
display::DisplayPlacement::RIGHT, 0);
display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
list, builder.Build());
UpdateDisplay("400x300,400x300");
EXPECT_EQ(2U, display_manager()->GetNumDisplays());
EXPECT_EQ(gfx::Rect(0, 0, 400, 300),
display_manager()->GetDisplayAt(0).bounds());
EXPECT_EQ(gfx::Rect(400, 0, 400, 300),
display_manager()->GetDisplayAt(1).bounds());
AccessibilityController* controller =
Shell::Get()->accessibility_controller();
TestAccessibilityControllerClient client;
controller->SetClient(client.CreateInterfacePtrAndBind());
aura::Window* window =
CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 200, 100));
wm::ActivateWindow(window);
HandleMoveWindowToDisplay(DisplayMoveWindowDirection::kRight);
controller->FlushMojoForTest();
EXPECT_EQ(mojom::AccessibilityAlert::WINDOW_MOVED_TO_RIGHT_DISPLAY,
client.last_a11y_alert());
}
} // namespace ash } // namespace ash
...@@ -4,27 +4,34 @@ ...@@ -4,27 +4,34 @@
module ash.mojom; module ash.mojom;
// Alert sent to the accessibility api.
enum AccessibilityAlert { enum AccessibilityAlert {
// Default value, indicates no accessibility alert. // Default value, indicates no accessibility alert.
NONE, NONE,
// Caps Lock is On. // When caps lock is turned on.
CAPS_ON, CAPS_ON,
// Caps Lock is Off. // When caps lock is turned off.
CAPS_OFF, CAPS_OFF,
// Screen turned on by tablet power button. // When screen is turned on by tablet power button.
SCREEN_ON, SCREEN_ON,
// Screen turned off by tablet power button. // When screen is turned off by tablet power button.
SCREEN_OFF, SCREEN_OFF,
// Alerted when no window avaiable and accelerators operated which requires at // When window moved to above/below/left/right display by accelerators.
// least one window. WINDOW_MOVED_TO_ABOVE_DISPLAY,
WINDOW_MOVED_TO_BELOW_DISPLAY,
WINDOW_MOVED_TO_LEFT_DISPLAY,
WINDOW_MOVED_TO_RIGHT_DISPLAY,
// When the user attempts a keyboard command that requires a window to work,
// and none is available.
WINDOW_NEEDED, WINDOW_NEEDED,
// Entered overview mode. // When the user enters window overview mode.
WINDOW_OVERVIEW_MODE_ENTERED WINDOW_OVERVIEW_MODE_ENTERED
}; };
......
...@@ -10245,12 +10245,6 @@ For more information, visit our <ph name="BEGIN_LINK">&lt;a target="_blank" href ...@@ -10245,12 +10245,6 @@ For more information, visit our <ph name="BEGIN_LINK">&lt;a target="_blank" href
<!-- Accessibility alerts --> <!-- Accessibility alerts -->
<if expr="chromeos"> <if expr="chromeos">
<message name="IDS_A11Y_ALERT_WINDOW_NEEDED" desc="Alert sent to the accessibility api when the user attempts a keyboard command that requires a window to work.">
Command unavailable. Press control-N to open a new window.
</message>
<message name="IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED" desc="The accessible text read when the user enters window overview mode in Ash.">
Entered window overview mode
</message>
<message name="IDS_A11Y_ALERT_CAPS_OFF" desc="Alert sent to the accessibility api when caps lock is turned off."> <message name="IDS_A11Y_ALERT_CAPS_OFF" desc="Alert sent to the accessibility api when caps lock is turned off.">
caps lock off caps lock off
</message> </message>
...@@ -10263,6 +10257,24 @@ For more information, visit our <ph name="BEGIN_LINK">&lt;a target="_blank" href ...@@ -10263,6 +10257,24 @@ For more information, visit our <ph name="BEGIN_LINK">&lt;a target="_blank" href
<message name="IDS_A11Y_ALERT_SCREEN_ON" desc="Alert sent to the accessibility api when screen is turned on."> <message name="IDS_A11Y_ALERT_SCREEN_ON" desc="Alert sent to the accessibility api when screen is turned on.">
screen on screen on
</message> </message>
<message name="IDS_A11Y_ALERT_WINDOW_MOVED_TO_ABOVE_DISPLAY" desc="Alert sent to the accessibility api when active window is moved to above display.">
Active window moved to above display
</message>
<message name="IDS_A11Y_ALERT_WINDOW_MOVED_TO_BELOW_DISPLAY" desc="Alert sent to the accessibility api when active window is moved to below display.">
Active window moved to below display
</message>
<message name="IDS_A11Y_ALERT_WINDOW_MOVED_TO_LEFT_DISPLAY" desc="Alert sent to the accessibility api when active window is moved to left display.">
Active window moved to left display
</message>
<message name="IDS_A11Y_ALERT_WINDOW_MOVED_TO_RIGHT_DISPLAY" desc="Alert sent to the accessibility api when active window is moved to right display.">
Active window moved to right display
</message>
<message name="IDS_A11Y_ALERT_WINDOW_NEEDED" desc="Alert sent to the accessibility api when the user attempts a keyboard command that requires a window to work.">
Command unavailable. Press control-N to open a new window.
</message>
<message name="IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED" desc="The accessible text read when the user enters window overview mode in Ash.">
Entered window overview mode
</message>
</if> </if>
<message name="IDS_DESKTOP_MEDIA_PICKER_SHARE" desc="Used for Share on buttons"> <message name="IDS_DESKTOP_MEDIA_PICKER_SHARE" desc="Used for Share on buttons">
......
...@@ -82,6 +82,18 @@ void AccessibilityControllerClient::TriggerAccessibilityAlert( ...@@ -82,6 +82,18 @@ void AccessibilityControllerClient::TriggerAccessibilityAlert(
case ash::mojom::AccessibilityAlert::SCREEN_OFF: case ash::mojom::AccessibilityAlert::SCREEN_OFF:
msg = IDS_A11Y_ALERT_SCREEN_OFF; msg = IDS_A11Y_ALERT_SCREEN_OFF;
break; break;
case ash::mojom::AccessibilityAlert::WINDOW_MOVED_TO_ABOVE_DISPLAY:
msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_ABOVE_DISPLAY;
break;
case ash::mojom::AccessibilityAlert::WINDOW_MOVED_TO_BELOW_DISPLAY:
msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_BELOW_DISPLAY;
break;
case ash::mojom::AccessibilityAlert::WINDOW_MOVED_TO_LEFT_DISPLAY:
msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_LEFT_DISPLAY;
break;
case ash::mojom::AccessibilityAlert::WINDOW_MOVED_TO_RIGHT_DISPLAY:
msg = IDS_A11Y_ALERT_WINDOW_MOVED_TO_RIGHT_DISPLAY;
break;
case ash::mojom::AccessibilityAlert::WINDOW_NEEDED: case ash::mojom::AccessibilityAlert::WINDOW_NEEDED:
msg = IDS_A11Y_ALERT_WINDOW_NEEDED; msg = IDS_A11Y_ALERT_WINDOW_NEEDED;
break; break;
......
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