diff options
author | afakhry <afakhry@chromium.org> | 2014-10-27 13:55:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-27 20:55:37 +0000 |
commit | 63a5975ca272b44c8209055f38605e6598b6142d (patch) | |
tree | 53faf08de8875c94e73a79b04462efe5ac3310d6 | |
parent | 3642e122b21885ef467761b7ee37815c0d98b740 (diff) | |
download | chromium_src-63a5975ca272b44c8209055f38605e6598b6142d.zip chromium_src-63a5975ca272b44c8209055f38605e6598b6142d.tar.gz chromium_src-63a5975ca272b44c8209055f38605e6598b6142d.tar.bz2 |
Athena AppActivities should open maximized unless they specify otherwise.
Selecting an app window from the overview mode maximizes the window only if it's maximizable.
A change proposal to fix the below 2 bugs: - crbug.com/424710 - crbug.com/424708
R=oshima@chromium.org
BUG=424710,424708
TEST=Manual & athena_unittests @ OnSelectWindow
Review URL: https://codereview.chromium.org/668513003
Cr-Commit-Position: refs/heads/master@{#301438}
-rw-r--r-- | athena/activity/activity_widget_delegate.cc | 12 | ||||
-rw-r--r-- | athena/activity/activity_widget_delegate.h | 3 | ||||
-rw-r--r-- | athena/wm/window_manager_impl.cc | 34 | ||||
-rw-r--r-- | athena/wm/window_manager_unittest.cc | 67 |
4 files changed, 110 insertions, 6 deletions
diff --git a/athena/activity/activity_widget_delegate.cc b/athena/activity/activity_widget_delegate.cc index 3c638e8..b387b50 100644 --- a/athena/activity/activity_widget_delegate.cc +++ b/athena/activity/activity_widget_delegate.cc @@ -18,6 +18,18 @@ ActivityWidgetDelegate::ActivityWidgetDelegate(ActivityViewModel* view_model) ActivityWidgetDelegate::~ActivityWidgetDelegate() { } +bool ActivityWidgetDelegate::CanResize() const { + return true; +} + +bool ActivityWidgetDelegate::CanMaximize() const { + return true; +} + +bool ActivityWidgetDelegate::CanMinimize() const { + return true; +} + base::string16 ActivityWidgetDelegate::GetWindowTitle() const { return view_model_->GetTitle(); } diff --git a/athena/activity/activity_widget_delegate.h b/athena/activity/activity_widget_delegate.h index 7dbedef..93829b6 100644 --- a/athena/activity/activity_widget_delegate.h +++ b/athena/activity/activity_widget_delegate.h @@ -19,6 +19,9 @@ class ActivityWidgetDelegate : public views::WidgetDelegate { ~ActivityWidgetDelegate() override; // views::WidgetDelegate: + bool CanResize() const override; + bool CanMaximize() const override; + bool CanMinimize() const override; base::string16 GetWindowTitle() const override; void DeleteDelegate() override; views::Widget* GetWidget() override; diff --git a/athena/wm/window_manager_impl.cc b/athena/wm/window_manager_impl.cc index c8c1cac..1392133 100644 --- a/athena/wm/window_manager_impl.cc +++ b/athena/wm/window_manager_impl.cc @@ -16,8 +16,10 @@ #include "athena/wm/window_overview_mode.h" #include "base/bind.h" #include "base/logging.h" +#include "ui/aura/client/aura_constants.h" #include "ui/aura/layout_manager.h" #include "ui/aura/window.h" +#include "ui/aura/window_delegate.h" #include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/display.h" @@ -40,6 +42,16 @@ void SetWindowState(aura::Window* window, window->SetTransform(transform); } +// Tests whether the given window can be maximized +bool CanWindowMaximize(const aura::Window* const window) { + const aura::WindowDelegate* delegate = window->delegate(); + const bool no_max_size = + !delegate || delegate->GetMaximumSize().IsEmpty(); + return no_max_size && + window->GetProperty(aura::client::kCanMaximizeKey) && + window->GetProperty(aura::client::kCanResizeKey); +} + } // namespace class AthenaContainerLayoutManager : public aura::LayoutManager { @@ -88,12 +100,12 @@ void AthenaContainerLayoutManager::OnWindowResized() { if (is_splitview) { if (window == instance->split_view_controller_->left_window()) window->SetBounds(gfx::Rect(split_size)); - else if (window == instance->split_view_controller_->right_window()) + else if (window == instance->split_view_controller_->right_window()) { window->SetBounds( gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); - else - window->SetBounds(gfx::Rect(work_area)); - } else { + } else if (CanWindowMaximize(window)) + window->SetBounds(gfx::Rect(work_area)); + } else if (CanWindowMaximize(window)) { window->SetBounds(gfx::Rect(work_area)); } } @@ -119,6 +131,14 @@ void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( aura::Window* child, bool visible) { + if (visible && CanWindowMaximize(child)) { + // Make sure we're resizing a window that actually exists in the window list + // to avoid resizing the divider in the split mode. + if(instance->window_list_provider_->IsWindowInList(child)) { + child->SetBounds( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area()); + } + } } void AthenaContainerLayoutManager::SetChildBounds( @@ -291,7 +311,11 @@ void WindowManagerImpl::OnSelectWindow(aura::Window* window) { // resized. const gfx::Size work_area = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); - if (window->GetTargetBounds().size() != work_area) { + + // Resize to the screen bounds only if the window is maximize-able, and + // is not already maximized + if (window->GetTargetBounds().size() != work_area && + CanWindowMaximize(window)) { const gfx::Rect& window_bounds = window->bounds(); const gfx::Rect desired_bounds(work_area); gfx::Transform transform; diff --git a/athena/wm/window_manager_unittest.cc b/athena/wm/window_manager_unittest.cc index 636686a..b46b70e 100644 --- a/athena/wm/window_manager_unittest.cc +++ b/athena/wm/window_manager_unittest.cc @@ -11,6 +11,7 @@ #include "athena/wm/split_view_controller.h" #include "athena/wm/test/window_manager_impl_test_api.h" #include "athena/wm/window_manager_impl.h" +#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/window_tree_client.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window.h" @@ -33,6 +34,7 @@ class WindowManagerTest : public test::AthenaTestBase { test::CreateNormalWindow(delegate, nullptr)); window->Show(); wm::ActivateWindow(window.get()); + window->SetProperty(aura::client::kCanMaximizeKey, true); return window.Pass(); } @@ -101,6 +103,59 @@ TEST_F(WindowManagerTest, OverviewToSplitViewMode) { EXPECT_FALSE(w1->IsVisible()); } +TEST_F(WindowManagerTest, OnSelectWindow) { + test::WindowManagerImplTestApi wm_api; + aura::test::TestWindowDelegate delegate1; + aura::test::TestWindowDelegate delegate2; + aura::test::TestWindowDelegate delegate3; + + // (w1): A window that sets a maximum size + delegate1.set_maximum_size(gfx::Size(300, 200)); + scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate1)); + w1->SetBounds(gfx::Rect(0, 0, 300, 200)); + + // (w2): A window that doesn't set a max size and is maximizable + scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate2)); + w2->SetBounds(gfx::Rect(0, 0, 300, 200)); + w2->SetProperty(aura::client::kCanMaximizeKey, true); + + // (w3): A window that doesn't set a max size but is NOT maximizable + scoped_ptr<aura::Window> w3(CreateAndActivateWindow(&delegate3)); + w3->SetBounds(gfx::Rect(0, 0, 300, 200)); + w3->SetProperty(aura::client::kCanMaximizeKey, false); + + const gfx::Size old_bounds1 = w1->GetTargetBounds().size(); + const gfx::Size old_bounds2 = w2->GetTargetBounds().size(); + const gfx::Size old_bounds3 = w3->GetTargetBounds().size(); + const gfx::Size work_area = + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); + + // Select w1, which has a max size, in the overview mode and make sure it's + // not maximized. + WindowManager::Get()->EnterOverview(); + WindowOverviewModeDelegate* overview_delegate = wm_api.wm(); + overview_delegate->OnSelectWindow(w1.get()); + const gfx::Size new_bounds1 = w1->GetTargetBounds().size(); + EXPECT_EQ(new_bounds1.ToString(), old_bounds1.ToString()); + EXPECT_NE(work_area.ToString(), new_bounds1.ToString()); + + // Select w2, which has no max size & can be maximized, in the overview + // mode and make sure it's actually maximized. + WindowManager::Get()->EnterOverview(); + overview_delegate->OnSelectWindow(w2.get()); + const gfx::Size new_bounds2 = w2->GetTargetBounds().size(); + EXPECT_NE(new_bounds2.ToString(), old_bounds2.ToString()); + EXPECT_EQ(work_area.ToString(), new_bounds2.ToString()); + + // Select w3, which has no max size & cannot be maximized, in the overview + // mode and make sure it's not maximized. + WindowManager::Get()->EnterOverview(); + overview_delegate->OnSelectWindow(w3.get()); + const gfx::Size new_bounds3 = w3->GetTargetBounds().size(); + EXPECT_EQ(new_bounds3.ToString(), old_bounds3.ToString()); + EXPECT_NE(work_area.ToString(), new_bounds3.ToString()); +} + TEST_F(WindowManagerTest, NewWindowFromOverview) { aura::test::TestWindowDelegate delegate; scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); @@ -352,8 +407,18 @@ TEST_F(WindowManagerTest, SplitModeActivationByShortcut) { wm_api.wm()->ToggleSplitView(); EXPECT_FALSE(wm_api.GetSplitViewController()->IsSplitViewModeActive()); - EXPECT_EQ(width, w1->bounds().width()); + // w2 is the top window, it should be resized to max width and must be visible + // w1 should be hidden. EXPECT_EQ(width, w2->bounds().width()); + EXPECT_TRUE(w2->IsVisible()); + EXPECT_FALSE(w1->IsVisible()); + + // Expect w1 to be visible and maximized when activated. + // TODO(oshima): To change to wm::ActivateWindow once the correct window state + // is implemented. + w1->Show(); + EXPECT_EQ(width, w1->bounds().width()); + EXPECT_TRUE(w1->IsVisible()); } TEST_F(WindowManagerTest, OverviewModeFromSplitMode) { |