| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura_shell/default_container_layout_manager.h" | 5 #include "ui/aura_shell/default_container_layout_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 new aura_shell::internal::WorkspaceController(container_.get())); | 40 new aura_shell::internal::WorkspaceController(container_.get())); |
| 41 layout_manager_ = new DefaultContainerLayoutManager( | 41 layout_manager_ = new DefaultContainerLayoutManager( |
| 42 workspace_controller_->workspace_manager()); | 42 workspace_controller_->workspace_manager()); |
| 43 container_->SetLayoutManager(layout_manager_); | 43 container_->SetLayoutManager(layout_manager_); |
| 44 | 44 |
| 45 root_window->SetHostSize(gfx::Size(500, 400)); | 45 root_window->SetHostSize(gfx::Size(500, 400)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, | 48 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, |
| 49 aura::Window* parent, | 49 aura::Window* parent, |
| 50 aura::WindowType type) { | 50 aura::client::WindowType type) { |
| 51 aura::Window* window = new aura::Window(NULL); | 51 aura::Window* window = new aura::Window(NULL); |
| 52 window->SetType(type); | 52 window->SetType(type); |
| 53 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 53 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 54 window->SetBounds(bounds); | 54 window->SetBounds(bounds); |
| 55 window->Show(); | 55 window->Show(); |
| 56 window->SetParent(parent); | 56 window->SetParent(parent); |
| 57 return window; | 57 return window; |
| 58 } | 58 } |
| 59 | 59 |
| 60 aura::Window* CreateTestWindow(const gfx::Rect& bounds, | 60 aura::Window* CreateTestWindow(const gfx::Rect& bounds, |
| 61 aura::Window* parent) { | 61 aura::Window* parent) { |
| 62 return CreateTestWindowWithType(bounds, | 62 return CreateTestWindowWithType(bounds, |
| 63 parent, | 63 parent, |
| 64 aura::WINDOW_TYPE_NORMAL); | 64 aura::client::WINDOW_TYPE_NORMAL); |
| 65 } | 65 } |
| 66 | 66 |
| 67 aura::Window* container() { return container_.get(); } | 67 aura::Window* container() { return container_.get(); } |
| 68 | 68 |
| 69 DefaultContainerLayoutManager* default_container_layout_manager() { | 69 DefaultContainerLayoutManager* default_container_layout_manager() { |
| 70 return layout_manager_; | 70 return layout_manager_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 aura_shell::internal::WorkspaceManager* workspace_manager() { | 74 aura_shell::internal::WorkspaceManager* workspace_manager() { |
| 75 return workspace_controller_->workspace_manager(); | 75 return workspace_controller_->workspace_manager(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 scoped_ptr<aura::Window> container_; | 79 scoped_ptr<aura::Window> container_; |
| 80 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; | 80 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; |
| 81 // LayoutManager is owned by |container|. | 81 // LayoutManager is owned by |container|. |
| 82 aura_shell::internal::DefaultContainerLayoutManager* layout_manager_; | 82 aura_shell::internal::DefaultContainerLayoutManager* layout_manager_; |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); | 85 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // Utility functions to set and get show state on |window|. | 88 // Utility functions to set and get show state on |window|. |
| 89 void Maximize(aura::Window* window) { | 89 void Maximize(aura::Window* window) { |
| 90 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 90 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void Fullscreen(aura::Window* window) { | 93 void Fullscreen(aura::Window* window) { |
| 94 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 94 window->SetIntProperty(aura::client::kShowStateKey, |
| 95 ui::SHOW_STATE_FULLSCREEN); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void Restore(aura::Window* window) { | 98 void Restore(aura::Window* window) { |
| 98 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | 99 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 99 } | 100 } |
| 100 | 101 |
| 101 ui::WindowShowState GetShowState(aura::Window* window) { | 102 ui::WindowShowState GetShowState(aura::Window* window) { |
| 102 return static_cast<ui::WindowShowState>( | 103 return static_cast<ui::WindowShowState>( |
| 103 window->GetIntProperty(aura::kShowStateKey)); | 104 window->GetIntProperty(aura::client::kShowStateKey)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 } // namespace | 107 } // namespace |
| 107 | 108 |
| 108 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { | 109 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { |
| 109 // Layout Manager moves the window to (0,0) to fit to draggable area. | 110 // Layout Manager moves the window to (0,0) to fit to draggable area. |
| 110 scoped_ptr<aura::Window> child( | 111 scoped_ptr<aura::Window> child( |
| 111 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); | 112 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); |
| 112 // Window is centered in workspace. | 113 // Window is centered in workspace. |
| 113 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); | 114 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 140 child->SetBounds(gfx::Rect(1000, 500, 50, 50)); | 141 child->SetBounds(gfx::Rect(1000, 500, 50, 50)); |
| 141 EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString()); | 142 EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString()); |
| 142 default_container_layout_manager()->EndMove(child.get(), NULL); | 143 default_container_layout_manager()->EndMove(child.get(), NULL); |
| 143 EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString()); | 144 EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 TEST_F(DefaultContainerLayoutManagerTest, Popup) { | 147 TEST_F(DefaultContainerLayoutManagerTest, Popup) { |
| 147 scoped_ptr<aura::Window> popup( | 148 scoped_ptr<aura::Window> popup( |
| 148 CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100), | 149 CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100), |
| 149 container(), | 150 container(), |
| 150 aura::WINDOW_TYPE_POPUP)); | 151 aura::client::WINDOW_TYPE_POPUP)); |
| 151 // A popup window can be placed outside of draggable area. | 152 // A popup window can be placed outside of draggable area. |
| 152 EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString()); | 153 EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString()); |
| 153 | 154 |
| 154 // A popup window can be moved to outside of draggable area. | 155 // A popup window can be moved to outside of draggable area. |
| 155 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); | 156 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); |
| 156 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); | 157 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); |
| 157 | 158 |
| 158 // A popup window can be resized to the size bigger than draggable area. | 159 // A popup window can be resized to the size bigger than draggable area. |
| 159 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); | 160 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); |
| 160 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); | 161 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 // Make sure a window with a transient parent isn't resized by the layout | 164 // Make sure a window with a transient parent isn't resized by the layout |
| 164 // manager. | 165 // manager. |
| 165 TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { | 166 TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { |
| 166 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 167 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 167 window->SetType(aura::WINDOW_TYPE_NORMAL); | 168 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 168 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 169 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 169 aura::RootWindow::GetInstance()->AddTransientChild(window.get()); | 170 aura::RootWindow::GetInstance()->AddTransientChild(window.get()); |
| 170 window->SetBounds(gfx::Rect(0, 0, 200, 200)); | 171 window->SetBounds(gfx::Rect(0, 0, 200, 200)); |
| 171 window->Show(); | 172 window->Show(); |
| 172 window->SetParent(container()); | 173 window->SetParent(container()); |
| 173 | 174 |
| 174 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); | 175 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); |
| 175 } | 176 } |
| 176 | 177 |
| 177 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { | 178 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { |
| 178 scoped_ptr<aura::Window> w( | 179 scoped_ptr<aura::Window> w( |
| 179 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | 180 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); |
| 180 gfx::Rect fullscreen_bounds = | 181 gfx::Rect fullscreen_bounds = |
| 181 workspace_manager()->FindBy(w.get())->bounds(); | 182 workspace_manager()->FindBy(w.get())->bounds(); |
| 182 gfx::Rect original_bounds = w->GetTargetBounds(); | 183 gfx::Rect original_bounds = w->GetTargetBounds(); |
| 183 | 184 |
| 184 // Restoreing the restored window. | 185 // Restoreing the restored window. |
| 185 Restore(w.get()); | 186 Restore(w.get()); |
| 186 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | 187 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); |
| 187 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | 188 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); |
| 188 | 189 |
| 189 // Fullscreen | 190 // Fullscreen |
| 190 Fullscreen(w.get()); | 191 Fullscreen(w.get()); |
| 191 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | 192 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); |
| 192 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | 193 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); |
| 193 w->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | 194 w->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 194 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | 195 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); |
| 195 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | 196 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); |
| 196 | 197 |
| 197 Fullscreen(w.get()); | 198 Fullscreen(w.get()); |
| 198 // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect. | 199 // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect. |
| 199 Fullscreen(w.get()); | 200 Fullscreen(w.get()); |
| 200 EXPECT_EQ(fullscreen_bounds, w->bounds()); | 201 EXPECT_EQ(fullscreen_bounds, w->bounds()); |
| 201 Restore(w.get()); | 202 Restore(w.get()); |
| 202 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | 203 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); |
| 203 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | 204 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 332 |
| 332 Restore(w1.get()); | 333 Restore(w1.get()); |
| 333 // The following test does not pass due to crbug.com/102413. | 334 // The following test does not pass due to crbug.com/102413. |
| 334 // TODO(oshima): Re-enable this once the bug is fixed. | 335 // TODO(oshima): Re-enable this once the bug is fixed. |
| 335 // EXPECT_EQ(window_bounds.size().ToString(), | 336 // EXPECT_EQ(window_bounds.size().ToString(), |
| 336 // w1->GetTargetBounds().size().ToString()); | 337 // w1->GetTargetBounds().size().ToString()); |
| 337 } | 338 } |
| 338 | 339 |
| 339 } // namespace test | 340 } // namespace test |
| 340 } // namespace aura_shell | 341 } // namespace aura_shell |
| OLD | NEW |