Skip to content

Commit

Permalink
[cros touch] Proper handling of non-maximized/fullscreen windows in l…
Browse files Browse the repository at this point in the history
…ock screen container

Switch cros login host window back to ui::SHOW_STATE_FULLSCREEN since new layout manager handles that correctly even with virtual keyboard.
This way login window state will be consistent with screen lock state which is full screen.

BUG=384849

Review URL: https://codereview.chromium.org/330763005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278691 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nkostylev@chromium.org committed Jun 20, 2014
1 parent 2a62f77 commit c18663d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 18 deletions.
131 changes: 115 additions & 16 deletions ash/wm/lock_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"

namespace ash {
namespace test {
Expand All @@ -26,6 +27,36 @@ namespace {

const int kVirtualKeyboardHeight = 100;

// A login implementation of WidgetDelegate.
class LoginTestWidgetDelegate : public views::WidgetDelegate {
public:
explicit LoginTestWidgetDelegate(views::Widget* widget) : widget_(widget) {
}
virtual ~LoginTestWidgetDelegate() {}

// Overridden from WidgetDelegate:
virtual void DeleteDelegate() OVERRIDE {
delete this;
}
virtual views::Widget* GetWidget() OVERRIDE {
return widget_;
}
virtual const views::Widget* GetWidget() const OVERRIDE {
return widget_;
}
virtual bool CanActivate() const OVERRIDE {
return true;
}
virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE {
return true;
}

private:
views::Widget* widget_;

DISALLOW_COPY_AND_ASSIGN(LoginTestWidgetDelegate);
};

} // namespace

class LockLayoutManagerTest : public AshTestBase {
Expand All @@ -45,13 +76,18 @@ class LockLayoutManagerTest : public AshTestBase {
AshTestBase::TearDown();
}

aura::Window* CreateTestLoginWindowWithBounds(const gfx::Rect& bounds) {
aura::Window* CreateTestLoginWindow(views::Widget::InitParams params,
bool use_delegate) {
aura::Window* parent = Shell::GetPrimaryRootWindowController()->
GetContainer(ash::kShellWindowId_LockScreenContainer);
views::Widget* widget =
views::Widget::CreateWindowWithParentAndBounds(NULL, parent, bounds);
params.parent = parent;
views::Widget* widget = new views::Widget;
if (use_delegate)
params.delegate = new LoginTestWidgetDelegate(widget);
widget->Init(params);
widget->Show();
return widget->GetNativeView();
aura::Window* window = widget->GetNativeView();
return window;
}

// Show or hide the keyboard.
Expand All @@ -78,30 +114,87 @@ class LockLayoutManagerTest : public AshTestBase {
}
};

TEST_F(LockLayoutManagerTest, WindowBoundsAreEqualToScreen) {
TEST_F(LockLayoutManagerTest, NorwmalWindowBoundsArePreserved) {
gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();

views::Widget::InitParams widget_params(
views::Widget::InitParams::TYPE_WINDOW);
const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300);
widget_params.bounds = bounds;
scoped_ptr<aura::Window> window(
CreateTestLoginWindowWithBounds(gfx::Rect(10, 10, 300, 300)));
EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
CreateTestLoginWindow(widget_params, false /* use_delegate */));
EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString());

gfx::Rect work_area =
ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get());
window->SetBounds(work_area);

// Usually work_area takes Shelf into account but that doesn't affect
// LockScreen container windows.
EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString());
EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString());
EXPECT_NE(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());

window->SetBounds(gfx::Rect(100, 100, 200, 200));
EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200);
window->SetBounds(bounds2);
EXPECT_EQ(bounds2.ToString(), window->GetBoundsInScreen().ToString());
}

TEST_F(LockLayoutManagerTest, MaximizedFullscreenWindowBoundsAreEqualToScreen) {
gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();

views::Widget::InitParams widget_params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
widget_params.show_state = ui::SHOW_STATE_MAXIMIZED;
const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300);
widget_params.bounds = bounds;
// Maximized TYPE_WINDOW_FRAMELESS windows needs a delegate defined otherwise
// it won't get initial SetBounds event.
scoped_ptr<aura::Window> maximized_window(
CreateTestLoginWindow(widget_params, true /* use_delegate */));

widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
widget_params.delegate = NULL;
scoped_ptr<aura::Window> fullscreen_window(
CreateTestLoginWindow(widget_params, false /* use_delegate */));

EXPECT_EQ(screen_bounds.ToString(),
maximized_window->GetBoundsInScreen().ToString());
EXPECT_EQ(screen_bounds.ToString(),
fullscreen_window->GetBoundsInScreen().ToString());

gfx::Rect work_area =
ScreenUtil::GetDisplayWorkAreaBoundsInParent(maximized_window.get());
maximized_window->SetBounds(work_area);

EXPECT_NE(work_area.ToString(),
maximized_window->GetBoundsInScreen().ToString());
EXPECT_EQ(screen_bounds.ToString(),
maximized_window->GetBoundsInScreen().ToString());

work_area =
ScreenUtil::GetDisplayWorkAreaBoundsInParent(fullscreen_window.get());
fullscreen_window->SetBounds(work_area);
EXPECT_NE(work_area.ToString(),
fullscreen_window->GetBoundsInScreen().ToString());
EXPECT_EQ(screen_bounds.ToString(),
fullscreen_window->GetBoundsInScreen().ToString());

const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200);
maximized_window->SetBounds(bounds2);
fullscreen_window->SetBounds(bounds2);
EXPECT_EQ(screen_bounds.ToString(),
maximized_window->GetBoundsInScreen().ToString());
EXPECT_EQ(screen_bounds.ToString(),
fullscreen_window->GetBoundsInScreen().ToString());
}

TEST_F(LockLayoutManagerTest, KeyboardBounds) {
gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();

scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect()));
views::Widget::InitParams widget_params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
scoped_ptr<aura::Window> window(
CreateTestLoginWindow(widget_params, false /* use_delegate */));

EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());

// When virtual keyboard overscroll is enabled keyboard bounds should not
Expand Down Expand Up @@ -134,10 +227,16 @@ TEST_F(LockLayoutManagerTest, MultipleMonitors) {
return;

UpdateDisplay("300x400,400x500");
gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();

gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect()));
views::Widget::InitParams widget_params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
scoped_ptr<aura::Window> window(
CreateTestLoginWindow(widget_params, false /* use_delegate */));
window->SetProperty(aura::client::kCanMaximizeKey, true);

EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());

EXPECT_EQ(root_windows[0], window->GetRootWindow());
Expand Down
11 changes: 10 additions & 1 deletion ash/wm/lock_window_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ void LockWindowState::OnWMEvent(wm::WindowState* window_state,
case wm::WM_EVENT_SHOW_INACTIVE:
return;
case wm::WM_EVENT_SET_BOUNDS:
UpdateBounds(window_state);
if (window_state->IsMaximized() || window_state->IsFullscreen()) {
UpdateBounds(window_state);
} else {
const ash::wm::SetBoundsEvent* bounds_event =
static_cast<const ash::wm::SetBoundsEvent*>(event);
window_state->SetBoundsConstrained(bounds_event->requested_bounds());
}
break;
case wm::WM_EVENT_ADDED_TO_WORKSPACE:
if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
Expand Down Expand Up @@ -154,6 +160,9 @@ wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType(
}

void LockWindowState::UpdateBounds(wm::WindowState* window_state) {
if (!window_state->IsMaximized() && !window_state->IsFullscreen())
return;

keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
gfx::Rect keyboard_bounds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ void LoginDisplayHostImpl::InitLoginWindowAndView() {
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.bounds = background_bounds();
params.show_state = ui::SHOW_STATE_MAXIMIZED;
params.show_state = ui::SHOW_STATE_FULLSCREEN;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.parent =
ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
Expand Down

0 comments on commit c18663d

Please sign in to comment.