| 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/shelf/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // counts the number of animation steps. | 69 // counts the number of animation steps. |
| 70 class ShelfAnimationWaiter : views::WidgetObserver { | 70 class ShelfAnimationWaiter : views::WidgetObserver { |
| 71 public: | 71 public: |
| 72 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds) | 72 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds) |
| 73 : target_bounds_(target_bounds), | 73 : target_bounds_(target_bounds), |
| 74 animation_steps_(0), | 74 animation_steps_(0), |
| 75 done_waiting_(false) { | 75 done_waiting_(false) { |
| 76 GetShelfWidget()->AddObserver(this); | 76 GetShelfWidget()->AddObserver(this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual ~ShelfAnimationWaiter() { | 79 ~ShelfAnimationWaiter() override { GetShelfWidget()->RemoveObserver(this); } |
| 80 GetShelfWidget()->RemoveObserver(this); | |
| 81 } | |
| 82 | 80 |
| 83 // Wait till the shelf finishes animating to its expected bounds. | 81 // Wait till the shelf finishes animating to its expected bounds. |
| 84 void WaitTillDoneAnimating() { | 82 void WaitTillDoneAnimating() { |
| 85 if (IsDoneAnimating()) | 83 if (IsDoneAnimating()) |
| 86 done_waiting_ = true; | 84 done_waiting_ = true; |
| 87 else | 85 else |
| 88 base::MessageLoop::current()->Run(); | 86 base::MessageLoop::current()->Run(); |
| 89 } | 87 } |
| 90 | 88 |
| 91 // Returns true if the animation has completed and it was valid. | 89 // Returns true if the animation has completed and it was valid. |
| 92 bool WasValidAnimation() const { | 90 bool WasValidAnimation() const { |
| 93 return done_waiting_ && animation_steps_ > 0; | 91 return done_waiting_ && animation_steps_ > 0; |
| 94 } | 92 } |
| 95 | 93 |
| 96 private: | 94 private: |
| 97 // Returns true if shelf has finished animating to the target size. | 95 // Returns true if shelf has finished animating to the target size. |
| 98 bool IsDoneAnimating() const { | 96 bool IsDoneAnimating() const { |
| 99 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); | 97 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); |
| 100 gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); | 98 gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
| 101 int size = layout_manager->PrimaryAxisValue(current_bounds.height(), | 99 int size = layout_manager->PrimaryAxisValue(current_bounds.height(), |
| 102 current_bounds.width()); | 100 current_bounds.width()); |
| 103 int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(), | 101 int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(), |
| 104 target_bounds_.width()); | 102 target_bounds_.width()); |
| 105 return (size == desired_size); | 103 return (size == desired_size); |
| 106 } | 104 } |
| 107 | 105 |
| 108 // views::WidgetObserver override. | 106 // views::WidgetObserver override. |
| 109 virtual void OnWidgetBoundsChanged(views::Widget* widget, | 107 void OnWidgetBoundsChanged(views::Widget* widget, |
| 110 const gfx::Rect& new_bounds) override { | 108 const gfx::Rect& new_bounds) override { |
| 111 if (done_waiting_) | 109 if (done_waiting_) |
| 112 return; | 110 return; |
| 113 | 111 |
| 114 ++animation_steps_; | 112 ++animation_steps_; |
| 115 if (IsDoneAnimating()) { | 113 if (IsDoneAnimating()) { |
| 116 done_waiting_ = true; | 114 done_waiting_ = true; |
| 117 base::MessageLoop::current()->Quit(); | 115 base::MessageLoop::current()->Quit(); |
| 118 } | 116 } |
| 119 } | 117 } |
| 120 | 118 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 227 |
| 230 DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback); | 228 DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback); |
| 231 }; | 229 }; |
| 232 | 230 |
| 233 class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver { | 231 class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver { |
| 234 public: | 232 public: |
| 235 ShelfLayoutObserverTest() | 233 ShelfLayoutObserverTest() |
| 236 : changed_auto_hide_state_(false) { | 234 : changed_auto_hide_state_(false) { |
| 237 } | 235 } |
| 238 | 236 |
| 239 virtual ~ShelfLayoutObserverTest() {} | 237 ~ShelfLayoutObserverTest() override {} |
| 240 | 238 |
| 241 bool changed_auto_hide_state() const { return changed_auto_hide_state_; } | 239 bool changed_auto_hide_state() const { return changed_auto_hide_state_; } |
| 242 | 240 |
| 243 private: | 241 private: |
| 244 virtual void OnAutoHideStateChanged( | 242 void OnAutoHideStateChanged(ShelfAutoHideState new_state) override { |
| 245 ShelfAutoHideState new_state) override { | |
| 246 changed_auto_hide_state_ = true; | 243 changed_auto_hide_state_ = true; |
| 247 } | 244 } |
| 248 | 245 |
| 249 bool changed_auto_hide_state_; | 246 bool changed_auto_hide_state_; |
| 250 | 247 |
| 251 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest); | 248 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest); |
| 252 }; | 249 }; |
| 253 | 250 |
| 254 // Trivial item implementation that tracks its views for testing. | 251 // Trivial item implementation that tracks its views for testing. |
| 255 class TestItem : public SystemTrayItem { | 252 class TestItem : public SystemTrayItem { |
| 256 public: | 253 public: |
| 257 TestItem() | 254 TestItem() |
| 258 : SystemTrayItem(GetSystemTray()), | 255 : SystemTrayItem(GetSystemTray()), |
| 259 tray_view_(NULL), | 256 tray_view_(NULL), |
| 260 default_view_(NULL), | 257 default_view_(NULL), |
| 261 detailed_view_(NULL), | 258 detailed_view_(NULL), |
| 262 notification_view_(NULL) {} | 259 notification_view_(NULL) {} |
| 263 | 260 |
| 264 virtual views::View* CreateTrayView(user::LoginStatus status) override { | 261 views::View* CreateTrayView(user::LoginStatus status) override { |
| 265 tray_view_ = new views::View; | 262 tray_view_ = new views::View; |
| 266 // Add a label so it has non-zero width. | 263 // Add a label so it has non-zero width. |
| 267 tray_view_->SetLayoutManager(new views::FillLayout); | 264 tray_view_->SetLayoutManager(new views::FillLayout); |
| 268 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray"))); | 265 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray"))); |
| 269 return tray_view_; | 266 return tray_view_; |
| 270 } | 267 } |
| 271 | 268 |
| 272 virtual views::View* CreateDefaultView(user::LoginStatus status) override { | 269 views::View* CreateDefaultView(user::LoginStatus status) override { |
| 273 default_view_ = new views::View; | 270 default_view_ = new views::View; |
| 274 default_view_->SetLayoutManager(new views::FillLayout); | 271 default_view_->SetLayoutManager(new views::FillLayout); |
| 275 default_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Default"))); | 272 default_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Default"))); |
| 276 return default_view_; | 273 return default_view_; |
| 277 } | 274 } |
| 278 | 275 |
| 279 virtual views::View* CreateDetailedView(user::LoginStatus status) override { | 276 views::View* CreateDetailedView(user::LoginStatus status) override { |
| 280 detailed_view_ = new views::View; | 277 detailed_view_ = new views::View; |
| 281 detailed_view_->SetLayoutManager(new views::FillLayout); | 278 detailed_view_->SetLayoutManager(new views::FillLayout); |
| 282 detailed_view_->AddChildView( | 279 detailed_view_->AddChildView( |
| 283 new views::Label(base::UTF8ToUTF16("Detailed"))); | 280 new views::Label(base::UTF8ToUTF16("Detailed"))); |
| 284 return detailed_view_; | 281 return detailed_view_; |
| 285 } | 282 } |
| 286 | 283 |
| 287 virtual views::View* CreateNotificationView( | 284 views::View* CreateNotificationView(user::LoginStatus status) override { |
| 288 user::LoginStatus status) override { | |
| 289 notification_view_ = new views::View; | 285 notification_view_ = new views::View; |
| 290 return notification_view_; | 286 return notification_view_; |
| 291 } | 287 } |
| 292 | 288 |
| 293 virtual void DestroyTrayView() override { | 289 void DestroyTrayView() override { tray_view_ = NULL; } |
| 294 tray_view_ = NULL; | |
| 295 } | |
| 296 | 290 |
| 297 virtual void DestroyDefaultView() override { | 291 void DestroyDefaultView() override { default_view_ = NULL; } |
| 298 default_view_ = NULL; | |
| 299 } | |
| 300 | 292 |
| 301 virtual void DestroyDetailedView() override { | 293 void DestroyDetailedView() override { detailed_view_ = NULL; } |
| 302 detailed_view_ = NULL; | |
| 303 } | |
| 304 | 294 |
| 305 virtual void DestroyNotificationView() override { | 295 void DestroyNotificationView() override { notification_view_ = NULL; } |
| 306 notification_view_ = NULL; | |
| 307 } | |
| 308 | 296 |
| 309 virtual void UpdateAfterLoginStatusChange( | 297 void UpdateAfterLoginStatusChange(user::LoginStatus status) override {} |
| 310 user::LoginStatus status) override {} | |
| 311 | 298 |
| 312 views::View* tray_view() const { return tray_view_; } | 299 views::View* tray_view() const { return tray_view_; } |
| 313 views::View* default_view() const { return default_view_; } | 300 views::View* default_view() const { return default_view_; } |
| 314 views::View* detailed_view() const { return detailed_view_; } | 301 views::View* detailed_view() const { return detailed_view_; } |
| 315 views::View* notification_view() const { return notification_view_; } | 302 views::View* notification_view() const { return notification_view_; } |
| 316 | 303 |
| 317 private: | 304 private: |
| 318 views::View* tray_view_; | 305 views::View* tray_view_; |
| 319 views::View* default_view_; | 306 views::View* default_view_; |
| 320 views::View* detailed_view_; | 307 views::View* detailed_view_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Create a simple widget attached to the current context (will | 345 // Create a simple widget attached to the current context (will |
| 359 // delete on TearDown). | 346 // delete on TearDown). |
| 360 views::Widget* CreateTestWidget() { | 347 views::Widget* CreateTestWidget() { |
| 361 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 348 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 362 params.bounds = gfx::Rect(0, 0, 200, 200); | 349 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 363 params.context = CurrentContext(); | 350 params.context = CurrentContext(); |
| 364 return CreateTestWidgetWithParams(params); | 351 return CreateTestWidgetWithParams(params); |
| 365 } | 352 } |
| 366 | 353 |
| 367 // Overridden from AshTestBase: | 354 // Overridden from AshTestBase: |
| 368 virtual void SetUp() override { | 355 void SetUp() override { |
| 369 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 356 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 370 ash::switches::kAshEnableTrayDragging); | 357 ash::switches::kAshEnableTrayDragging); |
| 371 test::AshTestBase::SetUp(); | 358 test::AshTestBase::SetUp(); |
| 372 } | 359 } |
| 373 | 360 |
| 374 void RunGestureDragTests(gfx::Vector2d); | 361 void RunGestureDragTests(gfx::Vector2d); |
| 375 | 362 |
| 376 private: | 363 private: |
| 377 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest); | 364 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest); |
| 378 }; | 365 }; |
| (...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 2010 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 2024 gfx::Rect hide_target_bounds = status_window->GetTargetBounds(); | 2011 gfx::Rect hide_target_bounds = status_window->GetTargetBounds(); |
| 2025 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y()); | 2012 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y()); |
| 2026 | 2013 |
| 2027 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 2014 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 2028 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds(); | 2015 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds(); |
| 2029 EXPECT_EQ(initial_bounds, reshow_target_bounds); | 2016 EXPECT_EQ(initial_bounds, reshow_target_bounds); |
| 2030 } | 2017 } |
| 2031 | 2018 |
| 2032 } // namespace ash | 2019 } // namespace ash |
| OLD | NEW |