summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:20:22 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 06:20:22 +0000
commit5b0ca087e16d3c8810763fd3630d8c59d7574ba1 (patch)
treef5700cbe0040fe38cbf3a48fbdf72931910f06b1
parent98a5bb04453b7dedddd2feb60344c3a42d9cf5b4 (diff)
downloadchromium_src-5b0ca087e16d3c8810763fd3630d8c59d7574ba1.zip
chromium_src-5b0ca087e16d3c8810763fd3630d8c59d7574ba1.tar.gz
chromium_src-5b0ca087e16d3c8810763fd3630d8c59d7574ba1.tar.bz2
Replace Shell::GetRootWindow with Window::GetRootWindow
where this makes sense. I didn't change the class that is potentially global and not root specific. This also removes ToplevelLayoutManager that is not longer in use. BUG=115510 TEST=none Review URL: https://chromiumcodereview.appspot.com/9665016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126590 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/app_list/app_list.cc4
-rw-r--r--ash/ash.gyp3
-rw-r--r--ash/focus_cycler.cc2
-rw-r--r--ash/shell.cc10
-rw-r--r--ash/wm/base_layout_manager.cc7
-rw-r--r--ash/wm/base_layout_manager.h5
-rw-r--r--ash/wm/base_layout_manager_unittest.cc3
-rw-r--r--ash/wm/root_window_event_filter.cc12
-rw-r--r--ash/wm/root_window_event_filter.h8
-rw-r--r--ash/wm/shelf_layout_manager.cc3
-rw-r--r--ash/wm/shelf_layout_manager.h6
-rw-r--r--ash/wm/toplevel_layout_manager.cc100
-rw-r--r--ash/wm/toplevel_layout_manager.h64
-rw-r--r--ash/wm/toplevel_layout_manager_unittest.cc229
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc4
-rw-r--r--ash/wm/workspace/workspace_layout_manager.h4
-rw-r--r--ash/wm/workspace_controller.cc9
17 files changed, 50 insertions, 423 deletions
diff --git a/ash/app_list/app_list.cc b/ash/app_list/app_list.cc
index da9384a..0f0c612 100644
--- a/ash/app_list/app_list.cc
+++ b/ash/app_list/app_list.cc
@@ -74,7 +74,7 @@ void AppList::SetWidget(views::Widget* widget) {
widget_ = widget;
widget_->AddObserver(this);
Shell::GetInstance()->AddRootWindowEventFilter(this);
- Shell::GetRootWindow()->AddRootWindowObserver(this);
+ widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this);
widget_->SetOpacity(0);
ScheduleAnimation();
@@ -93,7 +93,7 @@ void AppList::ResetWidget() {
widget_->RemoveObserver(this);
GetLayer(widget_)->GetAnimator()->RemoveObserver(this);
Shell::GetInstance()->RemoveRootWindowEventFilter(this);
- Shell::GetRootWindow()->RemoveRootWindowObserver(this);
+ widget_->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this);
widget_ = NULL;
}
diff --git a/ash/ash.gyp b/ash/ash.gyp
index fe83dec..797e864 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -193,8 +193,6 @@
'wm/stacking_controller.h',
'wm/status_area_layout_manager.cc',
'wm/status_area_layout_manager.h',
- 'wm/toplevel_layout_manager.cc',
- 'wm/toplevel_layout_manager.h',
'wm/toplevel_window_event_filter.cc',
'wm/toplevel_window_event_filter.h',
'wm/video_detector.cc',
@@ -311,7 +309,6 @@
'wm/shadow_controller_unittest.cc',
'wm/shelf_layout_manager_unittest.cc',
'wm/system_modal_container_layout_manager_unittest.cc',
- 'wm/toplevel_layout_manager_unittest.cc',
'wm/toplevel_window_event_filter_unittest.cc',
'wm/video_detector_unittest.cc',
'wm/visibility_controller_unittest.cc',
diff --git a/ash/focus_cycler.cc b/ash/focus_cycler.cc
index 29dea55..9c4dab1 100644
--- a/ash/focus_cycler.cc
+++ b/ash/focus_cycler.cc
@@ -66,7 +66,7 @@ void FocusCycler::RotateFocus(Direction direction) {
Shell::GetInstance()->delegate()->GetCycleWindowList(
ShellDelegate::SOURCE_LAUNCHER);
if (!windows.empty()) {
- aura::client::GetActivationClient(Shell::GetRootWindow())->
+ aura::client::GetActivationClient(windows[0]->GetRootWindow())->
ActivateWindow(windows[0]);
break;
}
diff --git a/ash/shell.cc b/ash/shell.cc
index acdce03..bc3e476 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -42,7 +42,6 @@
#include "ash/wm/stacking_controller.h"
#include "ash/wm/status_area_layout_manager.h"
#include "ash/wm/system_modal_container_layout_manager.h"
-#include "ash/wm/toplevel_layout_manager.h"
#include "ash/wm/toplevel_window_event_filter.h"
#include "ash/wm/video_detector.h"
#include "ash/wm/visibility_controller.h"
@@ -97,7 +96,7 @@ aura::Window* CreateContainer(int window_id,
// Creates each of the special window containers that holds windows of various
// types in the shell UI.
-void CreateSpecialContainers(aura::Window* root_window) {
+void CreateSpecialContainers(aura::RootWindow* root_window) {
// These containers are just used by PowerButtonController to animate groups
// of containers simultaneously without messing up the current transformations
// on those containers. These are direct children of the root window; all of
@@ -172,7 +171,8 @@ void CreateSpecialContainers(aura::Window* root_window) {
internal::kShellWindowId_LockScreenContainer,
"LockScreenContainer",
lock_screen_containers);
- lock_container->SetLayoutManager(new internal::BaseLayoutManager);
+ lock_container->SetLayoutManager(
+ new internal::BaseLayoutManager(root_window));
lock_container->set_stops_event_propagation(true);
aura::Window* lock_modal_container = CreateContainer(
@@ -412,7 +412,8 @@ aura::RootWindow* Shell::GetRootWindow() {
}
void Shell::Init() {
- root_filter_ = new internal::RootWindowEventFilter;
+ aura::RootWindow* root_window = GetRootWindow();
+ root_filter_ = new internal::RootWindowEventFilter(root_window);
#if !defined(OS_MACOSX)
nested_dispatcher_controller_.reset(new NestedDispatcherController);
accelerator_controller_.reset(new AcceleratorController);
@@ -438,7 +439,6 @@ void Shell::Init() {
input_method_filter_.reset(new internal::InputMethodEventFilter);
AddRootWindowEventFilter(input_method_filter_.get());
- aura::RootWindow* root_window = GetRootWindow();
root_window->SetCursor(aura::kCursorPointer);
if (initially_hide_cursor_)
root_window->ShowCursor(false);
diff --git a/ash/wm/base_layout_manager.cc b/ash/wm/base_layout_manager.cc
index 6a5e5e4..86d09b1 100644
--- a/ash/wm/base_layout_manager.cc
+++ b/ash/wm/base_layout_manager.cc
@@ -19,15 +19,16 @@ namespace internal {
/////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, public:
-BaseLayoutManager::BaseLayoutManager() {
+BaseLayoutManager::BaseLayoutManager(aura::RootWindow* root_window)
+ : root_window_(root_window) {
Shell::GetInstance()->AddShellObserver(this);
- Shell::GetRootWindow()->AddRootWindowObserver(this);
+ root_window_->AddRootWindowObserver(this);
}
BaseLayoutManager::~BaseLayoutManager() {
for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i)
(*i)->RemoveObserver(this);
- Shell::GetRootWindow()->RemoveRootWindowObserver(this);
+ root_window_->RemoveRootWindowObserver(this);
Shell::GetInstance()->RemoveShellObserver(this);
}
diff --git a/ash/wm/base_layout_manager.h b/ash/wm/base_layout_manager.h
index df858c8..f752495 100644
--- a/ash/wm/base_layout_manager.h
+++ b/ash/wm/base_layout_manager.h
@@ -17,6 +17,7 @@
#include "ui/aura/window_observer.h"
namespace aura {
+class RootWindow;
class Window;
}
@@ -35,7 +36,7 @@ class ASH_EXPORT BaseLayoutManager : public aura::LayoutManager,
public:
typedef std::set<aura::Window*> WindowSet;
- BaseLayoutManager();
+ explicit BaseLayoutManager(aura::RootWindow* root_window);
virtual ~BaseLayoutManager();
const WindowSet& windows() const { return windows_; }
@@ -71,6 +72,8 @@ class ASH_EXPORT BaseLayoutManager : public aura::LayoutManager,
// Set of windows we're listening to.
WindowSet windows_;
+ aura::RootWindow* root_window_;
+
DISALLOW_COPY_AND_ASSIGN(BaseLayoutManager);
};
diff --git a/ash/wm/base_layout_manager_unittest.cc b/ash/wm/base_layout_manager_unittest.cc
index f8045a4..f63e38c 100644
--- a/ash/wm/base_layout_manager_unittest.cc
+++ b/ash/wm/base_layout_manager_unittest.cc
@@ -32,7 +32,8 @@ class BaseLayoutManagerTest : public test::AshTestBase {
Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
aura::Window* default_container = Shell::GetInstance()->GetContainer(
internal::kShellWindowId_DefaultContainer);
- default_container->SetLayoutManager(new internal::BaseLayoutManager);
+ default_container->SetLayoutManager(new internal::BaseLayoutManager(
+ Shell::GetRootWindow()));
}
aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
diff --git a/ash/wm/root_window_event_filter.cc b/ash/wm/root_window_event_filter.cc
index 5fd9024..c924446 100644
--- a/ash/wm/root_window_event_filter.cc
+++ b/ash/wm/root_window_event_filter.cc
@@ -4,7 +4,6 @@
#include "ash/wm/root_window_event_filter.h"
-#include "ash/shell.h"
#include "ash/wm/activation_controller.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/window_util.h"
@@ -30,8 +29,9 @@ aura::Window* FindFocusableWindowFor(aura::Window* window) {
////////////////////////////////////////////////////////////////////////////////
// RootWindowEventFilter, public:
-RootWindowEventFilter::RootWindowEventFilter()
- : cursor_lock_count_(0),
+RootWindowEventFilter::RootWindowEventFilter(aura::RootWindow* root_window)
+ : root_window_(root_window),
+ cursor_lock_count_(0),
did_cursor_change_(false),
cursor_to_set_on_unlock_(0),
update_cursor_visibility_(true) {
@@ -78,7 +78,7 @@ void RootWindowEventFilter::UnlockCursor() {
if (cursor_lock_count_ == 0) {
if (did_cursor_change_) {
did_cursor_change_ = false;
- Shell::GetRootWindow()->SetCursor(cursor_to_set_on_unlock_);
+ root_window_->SetCursor(cursor_to_set_on_unlock_);
}
did_cursor_change_ = false;
cursor_to_set_on_unlock_ = 0;
@@ -165,7 +165,7 @@ void RootWindowEventFilter::UpdateCursor(aura::Window* target,
cursor = CursorForWindowComponent(window_component);
}
if (cursor_lock_count_ == 0) {
- Shell::GetRootWindow()->SetCursor(cursor);
+ root_window_->SetCursor(cursor);
} else {
cursor_to_set_on_unlock_ = cursor;
did_cursor_change_ = true;
@@ -176,7 +176,7 @@ void RootWindowEventFilter::SetCursorVisible(aura::Window* target,
aura::LocatedEvent* event,
bool show) {
if (!(event->flags() & ui::EF_IS_SYNTHESIZED))
- Shell::GetRootWindow()->ShowCursor(show);
+ root_window_->ShowCursor(show);
}
bool RootWindowEventFilter::FilterKeyEvent(aura::Window* target,
diff --git a/ash/wm/root_window_event_filter.h b/ash/wm/root_window_event_filter.h
index 1782534..49319d4 100644
--- a/ash/wm/root_window_event_filter.h
+++ b/ash/wm/root_window_event_filter.h
@@ -12,6 +12,10 @@
#include "ui/aura/event_filter.h"
#include "ash/ash_export.h"
+namespace aura {
+class RootWindow;
+}
+
namespace ash {
namespace internal {
@@ -25,7 +29,7 @@ namespace internal {
// event.
class ASH_EXPORT RootWindowEventFilter : public aura::EventFilter {
public:
- RootWindowEventFilter();
+ RootWindowEventFilter(aura::RootWindow* root_window);
virtual ~RootWindowEventFilter();
// Returns the cursor for the specified component.
@@ -75,6 +79,8 @@ class ASH_EXPORT RootWindowEventFilter : public aura::EventFilter {
ui::TouchStatus FilterTouchEvent(aura::Window* target,
aura::TouchEvent* event);
+ aura::RootWindow* root_window_;
+
// Additional event filters that pre-handles events.
ObserverList<aura::EventFilter, true> filters_;
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc
index fff8c19..9691a5f 100644
--- a/ash/wm/shelf_layout_manager.cc
+++ b/ash/wm/shelf_layout_manager.cc
@@ -42,6 +42,7 @@ ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher,
gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds();
gfx::Rect status_bounds = status->GetWindowScreenBounds();
max_height_ = std::max(launcher_bounds.height(), status_bounds.height());
+ root_window_ = launcher->GetNativeView()->GetRootWindow();
}
ShelfLayoutManager::~ShelfLayoutManager() {
@@ -133,7 +134,7 @@ void ShelfLayoutManager::StopAnimating() {
void ShelfLayoutManager::CalculateTargetBounds(bool visible,
TargetBounds* target_bounds) {
- const gfx::Rect& available_bounds(Shell::GetRootWindow()->bounds());
+ const gfx::Rect& available_bounds(root_window_->bounds());
int y = available_bounds.bottom() - (visible ? max_height_ : 0);
gfx::Rect status_bounds(status_->GetWindowScreenBounds());
// The status widget should extend to the bottom and right edges.
diff --git a/ash/wm/shelf_layout_manager.h b/ash/wm/shelf_layout_manager.h
index 5c4b6dd..b0a9b3c 100644
--- a/ash/wm/shelf_layout_manager.h
+++ b/ash/wm/shelf_layout_manager.h
@@ -14,6 +14,10 @@
#include "ui/gfx/insets.h"
#include "ui/gfx/rect.h"
+namespace aura {
+class RootWindow;
+}
+
namespace views {
class Widget;
}
@@ -97,6 +101,8 @@ class ASH_EXPORT ShelfLayoutManager : public aura::LayoutManager,
views::Widget* launcher_;
views::Widget* status_;
+ aura::RootWindow* root_window_;
+
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager);
};
diff --git a/ash/wm/toplevel_layout_manager.cc b/ash/wm/toplevel_layout_manager.cc
deleted file mode 100644
index 720576f..0000000
--- a/ash/wm/toplevel_layout_manager.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright (c) 2012 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 "ash/wm/toplevel_layout_manager.h"
-
-#include "ash/wm/shelf_layout_manager.h"
-#include "ash/wm/window_animations.h"
-#include "ash/wm/window_util.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/window.h"
-#include "ui/gfx/screen.h"
-
-namespace {
-
-// Minimum number of pixels at the window top to keep visible on screen.
-const int kMinimumWindowTopVisible = 12;
-
-// Returns a bounds rectangle with at least a few pixels of the window's
-// title bar visible.
-gfx::Rect BoundsWithTitleBarVisible(const gfx::Rect& window_bounds,
- const gfx::Rect& work_area) {
- gfx::Rect bounds(window_bounds);
- // Ensure title bar is vertically on screen.
- if (bounds.y() < work_area.y())
- bounds.set_y(work_area.y());
- else if (bounds.y() + kMinimumWindowTopVisible > work_area.bottom())
- bounds.set_y(work_area.bottom() - kMinimumWindowTopVisible);
- return bounds;
-}
-
-} // namespace
-
-namespace ash {
-namespace internal {
-
-/////////////////////////////////////////////////////////////////////////////
-// ToplevelLayoutManager, public:
-
-ToplevelLayoutManager::ToplevelLayoutManager()
- : shelf_(NULL) {
-}
-
-ToplevelLayoutManager::~ToplevelLayoutManager() {
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// ToplevelLayoutManager, LayoutManager overrides:
-
-void ToplevelLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
- BaseLayoutManager::OnWindowAddedToLayout(child);
- UpdateShelfVisibility();
-}
-
-void ToplevelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
- DCHECK(child->type() == aura::client::WINDOW_TYPE_NORMAL ||
- child->type() == aura::client::WINDOW_TYPE_POPUP);
- BaseLayoutManager::OnWillRemoveWindowFromLayout(child);
- UpdateShelfVisibility();
-}
-
-void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
- bool visible) {
- BaseLayoutManager::OnChildWindowVisibilityChanged(child, visible);
- UpdateShelfVisibility();
-}
-
-void ToplevelLayoutManager::SetChildBounds(aura::Window* child,
- const gfx::Rect& requested_bounds) {
- gfx::Rect child_bounds(requested_bounds);
- // Ensure normal windows have the title bar at least partly visible.
- if (!wm::IsWindowMaximized(child) && !wm::IsWindowFullscreen(child)) {
- child_bounds = BoundsWithTitleBarVisible(
- child_bounds, gfx::Screen::GetMonitorWorkAreaNearestWindow(child));
- }
- BaseLayoutManager::SetChildBounds(child, child_bounds);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// ToplevelLayoutManager, WindowObserver overrides:
-
-void ToplevelLayoutManager::OnWindowPropertyChanged(aura::Window* window,
- const void* key,
- intptr_t old) {
- BaseLayoutManager::OnWindowPropertyChanged(window, key, old);
- if (key == aura::client::kShowStateKey)
- UpdateShelfVisibility();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// ToplevelLayoutManager, private:
-
-void ToplevelLayoutManager::UpdateShelfVisibility() {
- if (!shelf_)
- return;
- shelf_->SetVisible(!wm::HasFullscreenWindow(windows()));
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/wm/toplevel_layout_manager.h b/ash/wm/toplevel_layout_manager.h
deleted file mode 100644
index faf6d5f..0000000
--- a/ash/wm/toplevel_layout_manager.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2012 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 ASH_WM_TOPLEVEL_LAYOUT_MANAGER_H_
-#define ASH_WM_TOPLEVEL_LAYOUT_MANAGER_H_
-#pragma once
-
-#include "ash/ash_export.h"
-#include "ash/wm/base_layout_manager.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-
-namespace ash {
-namespace internal {
-
-class ShelfLayoutManager;
-
-// ToplevelLayoutManager is the LayoutManager installed on a container that
-// hosts what the shell considers to be top-level windows.
-//
-// ToplevelLayoutManager is used if the WorkspaceManager is not enabled and
-// compact window mode is not enabled. It is intended to implement the simplest
-// possible window management code. If you have a more complex window mode
-// please implement a new LayoutManager for it.
-//
-// TODO(jamescook): If we're happy with managed window mode, this class and
-// its tests can be deleted.
-class ASH_EXPORT ToplevelLayoutManager : public BaseLayoutManager {
- public:
- ToplevelLayoutManager();
- virtual ~ToplevelLayoutManager();
-
- void set_shelf(ShelfLayoutManager* shelf) { shelf_ = shelf; }
-
- // LayoutManager overrides:
- virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
- virtual void OnWillRemoveWindowFromLayout(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 OnWindowPropertyChanged(aura::Window* window,
- const void* key,
- intptr_t old) OVERRIDE;
-
- private:
- // Updates the visibility of the shelf based on if there are any full screen
- // windows.
- void UpdateShelfVisibility();
-
- // Owned by the Shell container window LauncherContainer. May be NULL if
- // we're not using a shelf.
- ShelfLayoutManager* shelf_;
-
- DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManager);
-};
-
-} // namespace ash
-} // namespace internal
-
-#endif // ASH_WM_TOPLEVEL_LAYOUT_MANAGER_H_
diff --git a/ash/wm/toplevel_layout_manager_unittest.cc b/ash/wm/toplevel_layout_manager_unittest.cc
deleted file mode 100644
index dff916a..0000000
--- a/ash/wm/toplevel_layout_manager_unittest.cc
+++ /dev/null
@@ -1,229 +0,0 @@
-// Copyright (c) 2012 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 "ash/wm/toplevel_layout_manager.h"
-
-#include "ash/screen_ash.h"
-#include "ash/shell.h"
-#include "ash/shell_window_ids.h"
-#include "ash/test/ash_test_base.h"
-#include "ash/wm/shelf_layout_manager.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/test/test_windows.h"
-#include "ui/base/ui_base_types.h"
-#include "ui/aura/window.h"
-#include "ui/views/widget/widget.h"
-
-namespace ash {
-
-namespace {
-
-class ToplevelLayoutManagerTest : public test::AshTestBase {
- public:
- ToplevelLayoutManagerTest() : layout_manager_(NULL) {}
- virtual ~ToplevelLayoutManagerTest() {}
-
- internal::ToplevelLayoutManager* layout_manager() {
- return layout_manager_;
- }
-
- virtual void SetUp() OVERRIDE {
- test::AshTestBase::SetUp();
- Shell::GetInstance()->SetScreenWorkAreaInsets(
- gfx::Insets(1, 2, 3, 4));
- Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
- aura::Window* default_container = Shell::GetInstance()->GetContainer(
- internal::kShellWindowId_DefaultContainer);
- layout_manager_ = new internal::ToplevelLayoutManager();
- default_container->SetLayoutManager(layout_manager_);
- }
-
- aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
- return aura::test::CreateTestWindowWithBounds(bounds, NULL);
- }
-
- // Returns widget owned by its parent, so doesn't need scoped_ptr<>.
- views::Widget* CreateTestWidget() {
- views::Widget* widget = new views::Widget;
- views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
- params.bounds = gfx::Rect(11, 22, 33, 44);
- widget->Init(params);
- widget->Show();
- return widget;
- }
-
- private:
- // Owned by the default container.
- internal::ToplevelLayoutManager* layout_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManagerTest);
-};
-
-// Tests normal->maximize->normal.
-TEST_F(ToplevelLayoutManagerTest, Maximize) {
- gfx::Rect bounds(100, 100, 200, 200);
- scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
- // Maximized window fills the work area, not the whole monitor.
- EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
- window->bounds());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- EXPECT_EQ(bounds, window->bounds());
-}
-
-// Tests maximized window size during root window resize.
-TEST_F(ToplevelLayoutManagerTest, MaximizeRootWindowResize) {
- gfx::Rect bounds(100, 100, 200, 200);
- scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
- EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
- window->bounds());
- // Enlarge the root window. We should still match the work area size.
- Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
- EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
- 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->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
- // Fullscreen window fills the whole monitor.
- EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
- window->bounds());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- EXPECT_EQ(bounds, window->bounds());
-}
-
-// Tests maximized window resizing on work area insets change.
-TEST_F(ToplevelLayoutManagerTest,
- ResizeMaximizedWindowOnWorkAreaInsetsChange) {
- gfx::Rect bounds(100, 100, 200, 200);
- scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
- Shell::GetInstance()->SetScreenWorkAreaInsets(gfx::Insets(0, 0, 30, 0));
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
- // Maximized window fills the work area.
- EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
- window->bounds());
-
- // Change work area insets.
- Shell::GetInstance()->SetScreenWorkAreaInsets(gfx::Insets(0, 0, 60, 0));
- // Maximized window fills the changed work area.
- EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
- window->bounds());
-}
-
-// Tests fullscreen window size during root window resize.
-TEST_F(ToplevelLayoutManagerTest, FullscreenRootWindowResize) {
- gfx::Rect bounds(100, 100, 200, 200);
- scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
- // Fullscreen window fills the whole monitor.
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
- EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
- window->bounds());
- // Enlarge the root window. We should still match the monitor size.
- Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
- EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
- window->bounds());
-}
-
-// Fails on Mac only. Need to be implemented. http://crbug.com/111279.
-#if defined(OS_MACOSX)
-#define MAYBE_RootWindowResizeShrinksWindows \
- FAILS_RootWindowResizeShrinksWindows
-#else
-#define MAYBE_RootWindowResizeShrinksWindows RootWindowResizeShrinksWindows
-#endif
-// Tests that when the screen gets smaller the windows aren't bigger than
-// the screen.
-TEST_F(ToplevelLayoutManagerTest, MAYBE_RootWindowResizeShrinksWindows) {
- scoped_ptr<aura::Window> window(
- CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
- gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
- // Invariant: Window is smaller than work area.
- EXPECT_LE(window->bounds().width(), work_area.width());
- EXPECT_LE(window->bounds().height(), work_area.height());
-
- // Make the root window narrower than our window.
- Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 400));
- work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
- EXPECT_LE(window->bounds().width(), work_area.width());
- EXPECT_LE(window->bounds().height(), work_area.height());
-
- // Make the root window shorter than our window.
- Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 200));
- work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
- EXPECT_LE(window->bounds().width(), work_area.width());
- EXPECT_LE(window->bounds().height(), work_area.height());
-
- // Enlarging the root window does not change the window bounds.
- gfx::Rect old_bounds = window->bounds();
- Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
- EXPECT_EQ(old_bounds.width(), window->bounds().width());
- EXPECT_EQ(old_bounds.height(), window->bounds().height());
-}
-
-// Test that window stays on screen despite attempts to move it off.
-TEST_F(ToplevelLayoutManagerTest, WindowStaysOnScreen) {
- scoped_ptr<aura::Window> window(
- CreateTestWindow(gfx::Rect(10, 20, 300, 200)));
- gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
- // Invariant: The top edge of the window is inside the work area and at least
- // one pixel is visible horizontally.
- // and horizontal dimensions.
- EXPECT_GE(window->bounds().y(), 0);
- EXPECT_LT(window->bounds().y(), work_area.bottom());
- EXPECT_GE(window->bounds().right(), 0);
- EXPECT_LT(window->bounds().x(), work_area.right());
-
- // Try to move window above the top of screen.
- window->SetBounds(gfx::Rect(10, -1, 300, 200));
- EXPECT_GE(window->bounds().y(), 0);
-
- // Try to move window below the bottom.
- window->SetBounds(gfx::Rect(10, work_area.bottom(), 300, 200));
- EXPECT_LT(window->bounds().y(), work_area.bottom());
-
- // Put the screen near the right edge, then shrink the host window.
- window->SetBounds(gfx::Rect(work_area.right() - 15, 20, 300, 200));
- Shell::GetRootWindow()->SetHostSize(gfx::Size(350, 250));
- EXPECT_GE(window->bounds().y(), 0);
- EXPECT_LT(window->bounds().y(), work_area.bottom());
- EXPECT_GE(window->bounds().right(), 0);
- EXPECT_LT(window->bounds().x(), work_area.right());
-}
-
-// Tests shelf visibility during window maximize and fullscreen.
-TEST_F(ToplevelLayoutManagerTest, ShelfVisibility) {
- gfx::Rect bounds(100, 100, 200, 200);
- scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
- views::Widget* launcher = CreateTestWidget();
- views::Widget* status = CreateTestWidget();
- scoped_ptr<internal::ShelfLayoutManager> shelf_layout_manager(
- new internal::ShelfLayoutManager(launcher, status));
- layout_manager()->set_shelf(shelf_layout_manager.get());
- EXPECT_TRUE(shelf_layout_manager.get()->visible());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
- EXPECT_TRUE(shelf_layout_manager.get()->visible());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- EXPECT_TRUE(shelf_layout_manager.get()->visible());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
- EXPECT_FALSE(shelf_layout_manager.get()->visible());
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- EXPECT_TRUE(shelf_layout_manager.get()->visible());
- // Window depends on layout manager for cleanup.
- window.reset();
- // shelf_layout_manager is observing these animations so clean them up first.
- launcher->GetNativeView()->layer()->GetAnimator()->StopAnimating();
- status->GetNativeView()->layer()->GetAnimator()->StopAnimating();
- shelf_layout_manager.reset();
-}
-
-} // namespace
-
-} // namespace ash
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index b984493..00f6dac 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -26,8 +26,10 @@ namespace internal {
// WorkspaceLayoutManager, public:
WorkspaceLayoutManager::WorkspaceLayoutManager(
+ aura::RootWindow* root_window,
WorkspaceManager* workspace_manager)
- : workspace_manager_(workspace_manager) {
+ : BaseLayoutManager(root_window),
+ workspace_manager_(workspace_manager) {
}
WorkspaceLayoutManager::~WorkspaceLayoutManager() {
diff --git a/ash/wm/workspace/workspace_layout_manager.h b/ash/wm/workspace/workspace_layout_manager.h
index 8ea5135..cf644d1 100644
--- a/ash/wm/workspace/workspace_layout_manager.h
+++ b/ash/wm/workspace/workspace_layout_manager.h
@@ -14,6 +14,7 @@
namespace aura {
class MouseEvent;
+class RootWindow;
class Window;
}
@@ -29,7 +30,8 @@ class WorkspaceManager;
// LayoutManager for top level windows when WorkspaceManager is enabled.
class ASH_EXPORT WorkspaceLayoutManager : public BaseLayoutManager {
public:
- explicit WorkspaceLayoutManager(WorkspaceManager* workspace_manager);
+ WorkspaceLayoutManager(aura::RootWindow* root_window,
+ WorkspaceManager* workspace_manager);
virtual ~WorkspaceLayoutManager();
// Returns the workspace manager for this container.
diff --git a/ash/wm/workspace_controller.cc b/ash/wm/workspace_controller.cc
index f12eafc..61875f2 100644
--- a/ash/wm/workspace_controller.cc
+++ b/ash/wm/workspace_controller.cc
@@ -4,7 +4,6 @@
#include "ash/wm/workspace_controller.h"
-#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/workspace_event_filter.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
@@ -32,17 +31,19 @@ WorkspaceController::WorkspaceController(aura::Window* viewport)
workspace_manager_(new WorkspaceManager(viewport)),
layout_manager_(NULL),
event_filter_(NULL) {
+ aura::RootWindow* root_window = viewport->GetRootWindow();
event_filter_ = new WorkspaceEventFilter(viewport);
viewport->SetEventFilter(event_filter_);
- layout_manager_ = new WorkspaceLayoutManager(workspace_manager_.get());
+ layout_manager_ = new WorkspaceLayoutManager(
+ root_window, workspace_manager_.get());
viewport->SetLayoutManager(layout_manager_);
- Shell::GetRootWindow()->AddObserver(this);
+ root_window->AddObserver(this);
workspace_manager_->set_grid_size(kGridSize);
event_filter_->set_grid_size(kGridSize);
}
WorkspaceController::~WorkspaceController() {
- Shell::GetRootWindow()->RemoveObserver(this);
+ viewport_->GetRootWindow()->RemoveObserver(this);
// WorkspaceLayoutManager may attempt to access state from us. Destroy it now.
if (viewport_->layout_manager() == layout_manager_)
viewport_->SetLayoutManager(NULL);