| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); | 143 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 | 147 |
| 148 class SystemModalContainerLayoutManagerTest : public AshTestBase { | 148 class SystemModalContainerLayoutManagerTest : public AshTestBase { |
| 149 public: | 149 public: |
| 150 virtual void SetUp() OVERRIDE { | 150 virtual void SetUp() OVERRIDE { |
| 151 // Allow a virtual keyboard (and initialize it per default). | 151 // Allow a virtual keyboard (and initialize it per default). |
| 152 CommandLine::ForCurrentProcess()->AppendSwitch( | 152 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 153 keyboard::switches::kEnableVirtualKeyboard); | 153 keyboard::switches::kEnableVirtualKeyboard); |
| 154 AshTestBase::SetUp(); | 154 AshTestBase::SetUp(); |
| 155 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( | 155 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
| 156 keyboard::KeyboardController::GetInstance()); | 156 keyboard::KeyboardController::GetInstance()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual void TearDown() OVERRIDE { | 159 virtual void TearDown() OVERRIDE { |
| 160 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( | 160 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
| 161 keyboard::KeyboardController::GetInstance()); | 161 keyboard::KeyboardController::GetInstance()); |
| 162 AshTestBase::TearDown(); | 162 AshTestBase::TearDown(); |
| 163 } | 163 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Show or hide the keyboard. | 179 // Show or hide the keyboard. |
| 180 void ShowKeyboard(bool show) { | 180 void ShowKeyboard(bool show) { |
| 181 keyboard::KeyboardController* keyboard = | 181 keyboard::KeyboardController* keyboard = |
| 182 keyboard::KeyboardController::GetInstance(); | 182 keyboard::KeyboardController::GetInstance(); |
| 183 ASSERT_TRUE(keyboard); | 183 ASSERT_TRUE(keyboard); |
| 184 if (show == keyboard->keyboard_visible()) | 184 if (show == keyboard->keyboard_visible()) |
| 185 return; | 185 return; |
| 186 | 186 |
| 187 // The animation has to run in order to get the notification. Run the | 187 if (show) { |
| 188 // animation and wait until its finished. | 188 keyboard->ShowKeyboard(true); |
| 189 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 189 if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) { |
| 190 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 190 gfx::Rect window_bounds = keyboard->GetContainerWindow()->bounds(); |
| 191 if (show) | 191 keyboard->proxy()->GetKeyboardWindow()->SetBounds(gfx::Rect( |
| 192 keyboard->ShowAndLockKeyboard(); | 192 window_bounds.x(), |
| 193 else | 193 window_bounds.bottom() - 100, |
| 194 window_bounds.width(), |
| 195 100)); |
| 196 } |
| 197 } else { |
| 194 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); | 198 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 195 | 199 } |
| 196 WaitForWindowAnimationToBeFinished(keyboard->GetContainerWindow()); | |
| 197 | 200 |
| 198 DCHECK_EQ(show, keyboard->keyboard_visible()); | 201 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 199 } | 202 } |
| 200 | 203 |
| 201 void WaitForWindowAnimationToBeFinished(aura::Window* window) { | |
| 202 DCHECK(window); | |
| 203 ui::Layer* layer = window->layer(); | |
| 204 ui::LayerAnimatorTestController controller(layer->GetAnimator()); | |
| 205 gfx::AnimationContainerElement* element = layer->GetAnimator(); | |
| 206 while (controller.animator()->is_animating()) { | |
| 207 controller.StartThreadedAnimationsIfNeeded(); | |
| 208 base::TimeTicks step_time = controller.animator()->last_step_time(); | |
| 209 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); | |
| 210 } | |
| 211 } | |
| 212 }; | 204 }; |
| 213 | 205 |
| 214 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 206 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
| 215 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 207 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 216 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); | 208 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
| 217 TransientWindowObserver destruction_observer; | 209 TransientWindowObserver destruction_observer; |
| 218 transient->AddObserver(&destruction_observer); | 210 transient->AddObserver(&destruction_observer); |
| 219 | 211 |
| 220 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); | 212 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); |
| 221 EXPECT_EQ(parent->parent(), transient->parent()); | 213 EXPECT_EQ(parent->parent(), transient->parent()); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 572 |
| 581 // After the keyboard is gone, the window will remain where it was. | 573 // After the keyboard is gone, the window will remain where it was. |
| 582 ShowKeyboard(false); | 574 ShowKeyboard(false); |
| 583 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); | 575 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); |
| 584 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 576 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
| 585 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 577 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
| 586 } | 578 } |
| 587 | 579 |
| 588 } // namespace test | 580 } // namespace test |
| 589 } // namespace ash | 581 } // namespace ash |
| OLD | NEW |