Skip to content

Commit

Permalink
cros: move first-non-transient transient-parent if transient
Browse files Browse the repository at this point in the history
changes:
Transient child window could get activated. In this case, shortcut to
move active window between displays will move its first-non-transient
transient-parent window.

move browser window that has permission prompt shown and activated.

Bug: 778438
Test: added test coverage. Also tested on device operating shortcuts to
Change-Id: I5d24c2c8ecfc17c30b97fe16db025307c5b23810
Reviewed-on: https://chromium-review.googlesource.com/848696
Commit-Queue: Qiang(Joe) Xu <warx@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527498}
  • Loading branch information
Qiang Xu authored and Commit Bot committed Jan 6, 2018
1 parent 41c0d05 commit 606fcb4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ash/display/display_move_window_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
#include "ui/wm/core/window_util.h"

namespace ash {

Expand Down Expand Up @@ -142,12 +143,20 @@ void HandleMoveActiveWindowToDisplay(DisplayMoveWindowDirection direction) {
if (!window)
return;

// When |window_list| is not empty, |window| can only be the first one of the
// fresh built list if it is in the list.
MruWindowTracker::WindowList window_list =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList();
if (window_list.empty() || window_list.front() != window)
return;
// If |window| is transient window, move its first non-transient
// transient-parent window instead. Otherwise, it should be the first one in
// window cycle list.
if (::wm::GetTransientParent(window)) {
while (::wm::GetTransientParent(window))
window = ::wm::GetTransientParent(window);
if (window == window->GetRootWindow())
return;
} else {
MruWindowTracker::WindowList window_list =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList();
if (window_list.empty() || window_list.front() != window)
return;
}

display::Display origin_display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window);
Expand Down
40 changes: 40 additions & 0 deletions ash/display/display_move_window_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"

namespace ash {
Expand Down Expand Up @@ -440,4 +441,43 @@ TEST_F(DisplayMoveWindowUtilTest, WindowWithTransientChild) {
EXPECT_EQ(gfx::Rect(430, 50, 40, 50), child->GetBoundsInScreen());
}

// Test that when operating move window between displays on activated transient
// child window, its first non-transient transient-parent window should be the
// target instead.
TEST_F(DisplayMoveWindowUtilTest, ActiveTransientChildWindow) {
UpdateDisplay("400x300,400x300");
std::unique_ptr<views::Widget> window = CreateTestWidget();
window->SetBounds(gfx::Rect(10, 20, 200, 100));

// Create a |child| transient widget of |window|. When |child| is shown, it is
// activated.
std::unique_ptr<views::Widget> child(new views::Widget);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.delegate = nullptr;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(20, 30, 40, 50);
params.parent = window->GetNativeWindow();
child->Init(params);
child->Show();
display::Screen* screen = display::Screen::GetScreen();
EXPECT_EQ(display_manager()->GetDisplayAt(0).id(),
screen->GetDisplayNearestWindow(window->GetNativeWindow()).id());
EXPECT_EQ(display_manager()->GetDisplayAt(0).id(),
screen->GetDisplayNearestWindow(child->GetNativeWindow()).id());
// Ensure |child| window is activated.
EXPECT_FALSE(wm::IsActiveWindow(window->GetNativeWindow()));
EXPECT_TRUE(wm::IsActiveWindow(child->GetNativeWindow()));

// Operate moving window to right display. Check display and bounds.
HandleMoveActiveWindowToDisplay(DisplayMoveWindowDirection::kRight);
EXPECT_EQ(display_manager()->GetDisplayAt(1).id(),
screen->GetDisplayNearestWindow(window->GetNativeWindow()).id());
EXPECT_EQ(display_manager()->GetDisplayAt(1).id(),
screen->GetDisplayNearestWindow(child->GetNativeWindow()).id());
EXPECT_EQ(gfx::Rect(410, 20, 200, 100),
window->GetNativeWindow()->GetBoundsInScreen());
EXPECT_EQ(gfx::Rect(420, 30, 40, 50),
child->GetNativeWindow()->GetBoundsInScreen());
}

} // namespace ash

0 comments on commit 606fcb4

Please sign in to comment.