diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 17:28:34 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-04 17:28:34 +0000 |
commit | c8d245577a6395dacdff2b3d76fb0371b002d4e9 (patch) | |
tree | 50f42fa33d0df79649a42ca389458cde35adcff9 /ui/aura_shell | |
parent | 8353bb406801e97daf5b27d91b3606a95a4ed1cd (diff) | |
download | chromium_src-c8d245577a6395dacdff2b3d76fb0371b002d4e9.zip chromium_src-c8d245577a6395dacdff2b3d76fb0371b002d4e9.tar.gz chromium_src-c8d245577a6395dacdff2b3d76fb0371b002d4e9.tar.bz2 |
Implements maximize and fullscreen for default window manager.
BUG=none
TEST=none
R=ben@chromium.org
Review URL: http://codereview.chromium.org/8477002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108677 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell')
-rw-r--r-- | ui/aura_shell/aura_shell.gyp | 3 | ||||
-rw-r--r-- | ui/aura_shell/property_util.cc | 5 | ||||
-rw-r--r-- | ui/aura_shell/property_util.h | 10 | ||||
-rw-r--r-- | ui/aura_shell/shell.cc | 13 | ||||
-rw-r--r-- | ui/aura_shell/toplevel_layout_manager.cc | 85 | ||||
-rw-r--r-- | ui/aura_shell/toplevel_layout_manager.h | 59 | ||||
-rw-r--r-- | ui/aura_shell/toplevel_layout_manager_unittest.cc | 80 |
7 files changed, 244 insertions, 11 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index e46f28d..bea8aff 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -70,6 +70,8 @@ 'status_area_view.h', 'toplevel_frame_view.cc', 'toplevel_frame_view.h', + 'toplevel_layout_manager.cc', + 'toplevel_layout_manager.h', 'workspace/workspace.cc', 'workspace/workspace.h', 'workspace/workspace_controller.cc', @@ -107,6 +109,7 @@ 'launcher/launcher_model_unittest.cc', 'launcher/view_model_unittest.cc', 'launcher/view_model_utils_unittest.cc', + 'toplevel_layout_manager_unittest.cc', 'workspace/workspace_manager_unittest.cc', 'run_all_unittests.cc', 'test_suite.cc', diff --git a/ui/aura_shell/property_util.cc b/ui/aura_shell/property_util.cc index 1247807..b5cf34c 100644 --- a/ui/aura_shell/property_util.cc +++ b/ui/aura_shell/property_util.cc @@ -16,6 +16,11 @@ void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { window->SetProperty(aura::kRestoreBoundsKey, new gfx::Rect(bounds)); } +void SetRestoreBoundsIfNotSet(aura::Window* window) { + if (!GetRestoreBounds(window)) + SetRestoreBounds(window, window->bounds()); +} + const gfx::Rect* GetRestoreBounds(aura::Window* window) { return reinterpret_cast<gfx::Rect*>( window->GetProperty(aura::kRestoreBoundsKey)); diff --git a/ui/aura_shell/property_util.h b/ui/aura_shell/property_util.h index 35a09c9..bfd9345 100644 --- a/ui/aura_shell/property_util.h +++ b/ui/aura_shell/property_util.h @@ -16,9 +16,13 @@ class Rect; namespace aura_shell { -// Sets the restore bounds property on |window|. Deletes -// existing bounds value if exists. -void SetRestoreBounds(aura::Window* window, const gfx::Rect&); +// Sets the restore bounds property on |window|. Deletes existing bounds value +// if exists. +void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds); + +// Same as SetRestoreBounds(), but does nothing if the restore bounds have +// already been set. The bounds used are the bounds of the window. +void SetRestoreBoundsIfNotSet(aura::Window* window); // Returns the restore bounds property on |window|. NULL if the // restore bounds property does not exist for |window|. |window| diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 659bfc8..705e0ac 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -19,6 +19,7 @@ #include "ui/aura_shell/shell_delegate.h" #include "ui/aura_shell/shell_factory.h" #include "ui/aura_shell/shell_window_ids.h" +#include "ui/aura_shell/toplevel_layout_manager.h" #include "ui/aura_shell/workspace/workspace_controller.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" @@ -29,9 +30,6 @@ namespace aura_shell { namespace { -// The right/left margin of work area in the screen. -const int kWorkAreaHorizontalMargin = 15; - using views::Widget; // Creates each of the special window containers that holds windows of various @@ -120,14 +118,13 @@ void Shell::Init() { desktop_layout->set_launcher_widget(launcher_->widget()); desktop_layout->set_status_area_widget(internal::CreateStatusArea()); - desktop_window->screen()->set_work_area_insets( - gfx::Insets( - 0, kWorkAreaHorizontalMargin, - launcher_->widget()->GetWindowScreenBounds().height(), - kWorkAreaHorizontalMargin)); + desktop_window->screen()->set_work_area_insets(gfx::Insets( + 0, 0, launcher_->widget()->GetWindowScreenBounds().height(), 0)); if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) EnableWorkspaceManager(); + else + toplevel_container->SetLayoutManager(new internal::ToplevelLayoutManager()); // Force a layout. desktop_layout->OnWindowResized(); diff --git a/ui/aura_shell/toplevel_layout_manager.cc b/ui/aura_shell/toplevel_layout_manager.cc new file mode 100644 index 0000000..ade2fe0 --- /dev/null +++ b/ui/aura_shell/toplevel_layout_manager.cc @@ -0,0 +1,85 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura_shell/toplevel_layout_manager.h" + +#include "ui/aura/aura_constants.h" +#include "ui/aura/window.h" +#include "ui/aura_shell/property_util.h" +#include "ui/aura_shell/workspace/workspace.h" +#include "ui/aura_shell/workspace/workspace_manager.h" +#include "ui/base/ui_base_types.h" +#include "ui/gfx/screen.h" + +namespace aura_shell { +namespace internal { + +ToplevelLayoutManager::ToplevelLayoutManager() { +} + +ToplevelLayoutManager::~ToplevelLayoutManager() { + for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) + (*i)->RemoveObserver(this); +} + +void ToplevelLayoutManager::OnWindowResized() { +} + +void ToplevelLayoutManager::OnWindowAdded(aura::Window* child) { + windows_.insert(child); + child->AddObserver(this); + if (child->GetProperty(aura::kShowStateKey)) + WindowStateChanged(child); +} + +void ToplevelLayoutManager::OnWillRemoveWindow(aura::Window* child) { + windows_.erase(child); + child->RemoveObserver(this); +} + +void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, + bool visibile) { +} + +void ToplevelLayoutManager::SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) { + SetChildBoundsDirect(child, requested_bounds); +} + +void ToplevelLayoutManager::OnPropertyChanged(aura::Window* window, + const char* name, + void* old) { + if (name == aura::kShowStateKey) + WindowStateChanged(window); +} + +void ToplevelLayoutManager::WindowStateChanged(aura::Window* window) { + switch (window->GetIntProperty(aura::kShowStateKey)) { + case ui::SHOW_STATE_NORMAL: { + const gfx::Rect* restore = GetRestoreBounds(window); + window->SetProperty(aura::kRestoreBoundsKey, NULL); + if (restore) + window->SetBounds(*restore); + delete restore; + break; + } + + case ui::SHOW_STATE_MAXIMIZED: + SetRestoreBoundsIfNotSet(window); + window->SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(window)); + break; + + case ui::SHOW_STATE_FULLSCREEN: + SetRestoreBoundsIfNotSet(window); + window->SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(window)); + // TODO: need to hide the launcher. + break; + + default: + break; + } +} + +} // namespace internal +} // namespace aura_shell diff --git a/ui/aura_shell/toplevel_layout_manager.h b/ui/aura_shell/toplevel_layout_manager.h new file mode 100644 index 0000000..8921b63 --- /dev/null +++ b/ui/aura_shell/toplevel_layout_manager.h @@ -0,0 +1,59 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ +#define UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ +#pragma once + +#include <set> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/layout_manager.h" +#include "ui/aura/window_observer.h" +#include "ui/aura_shell/aura_shell_export.h" + +namespace aura_shell { +namespace internal { + +// ToplevelLayoutManager is the LayoutManager installed on the +// ToplevelWindowContainer. It is used if the WorkspaceManager is not +// enabled. ToplevelLayoutManager listens for changes to kShowStateKey and +// resizes the window appropriately. +class AURA_SHELL_EXPORT ToplevelLayoutManager : public aura::LayoutManager, + public aura::WindowObserver { + public: + ToplevelLayoutManager(); + virtual ~ToplevelLayoutManager(); + + // LayoutManager overrides: + virtual void OnWindowResized() OVERRIDE; + virtual void OnWindowAdded(aura::Window* child) OVERRIDE; + virtual void OnWillRemoveWindow(aura::Window* child) OVERRIDE; + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visibile) OVERRIDE; + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE; + + // WindowObserver overrides: + virtual void OnPropertyChanged(aura::Window* window, + const char* name, + void* old) OVERRIDE; + + private: + typedef std::set<aura::Window*> Windows; + + // If necessary adjusts the bounds of window based on it's show state. + void WindowStateChanged(aura::Window* window); + + // Set of windows we're listening to. + Windows windows_; + + DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManager); +}; + +} // namepsace aura_shell +} // namepsace internal + +#endif // UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/toplevel_layout_manager_unittest.cc b/ui/aura_shell/toplevel_layout_manager_unittest.cc new file mode 100644 index 0000000..8dd9b5a --- /dev/null +++ b/ui/aura_shell/toplevel_layout_manager_unittest.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura_shell/toplevel_layout_manager.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/aura_constants.h" +#include "ui/aura/desktop.h" +#include "ui/aura/screen_aura.h" +#include "ui/aura/test/aura_test_base.h" +#include "ui/base/ui_base_types.h" +#include "ui/aura/window.h" + +namespace aura_shell { + +namespace { + +class ToplevelLayoutManagerTest : public aura::test::AuraTestBase { + public: + ToplevelLayoutManagerTest() : layout_manager_(NULL) {} + virtual ~ToplevelLayoutManagerTest() {} + + virtual void SetUp() OVERRIDE { + aura::test::AuraTestBase::SetUp(); + aura::Desktop::GetInstance()->screen()->set_work_area_insets( + gfx::Insets(1, 2, 3, 4)); + aura::Desktop::GetInstance()->SetHostSize(gfx::Size(500, 400)); + container_.reset(new aura::Window(NULL)); + container_->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + container_->SetBounds(gfx::Rect(0, 0, 500, 500)); + layout_manager_ = new internal::ToplevelLayoutManager(); + container_->SetLayoutManager(layout_manager_); + } + + aura::Window* CreateTestWindow(const gfx::Rect& bounds) { + aura::Window* window = new aura::Window(NULL); + window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + window->SetBounds(bounds); + window->Show(); + window->SetParent(container_.get()); + return window; + } + + private: + // Owned by |container_|. + internal::ToplevelLayoutManager* layout_manager_; + + scoped_ptr<aura::Window> container_; + + private: + DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManagerTest); +}; + +} // namespace + +// Tests normal->maximize->normal. +TEST_F(ToplevelLayoutManagerTest, Maximize) { + gfx::Rect bounds(100, 100, 200, 200); + scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); + window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); + EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()), + window->bounds()); + window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); + EXPECT_EQ(bounds, window->bounds()); +} + +// Tests normal->fullscreen->normal. +TEST_F(ToplevelLayoutManagerTest, Fullscreen) { + gfx::Rect bounds(100, 100, 200, 200); + scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); + window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); + EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()), + window->bounds()); + window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); + EXPECT_EQ(bounds, window->bounds()); +} + +} // namespace aura_shell |