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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "ash/accelerators/accelerator_commands.h" | 13 #include "ash/accelerators/accelerator_commands.h" |
14 #include "ash/ash_switches.h" | 14 #include "ash/ash_switches.h" |
15 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
16 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
17 #include "ash/session/session_state_delegate.h" | 17 #include "ash/session/session_state_delegate.h" |
18 #include "ash/shelf/shelf.h" | 18 #include "ash/shelf/shelf.h" |
19 #include "ash/shelf/shelf_bezel_event_filter.h" | 19 #include "ash/shelf/shelf_bezel_event_filter.h" |
20 #include "ash/shelf/shelf_constants.h" | 20 #include "ash/shelf/shelf_constants.h" |
21 #include "ash/shelf/shelf_layout_manager_observer.h" | 21 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 22 #include "ash/shelf/shelf_util.h" |
22 #include "ash/shelf/shelf_widget.h" | 23 #include "ash/shelf/shelf_widget.h" |
23 #include "ash/shell.h" | 24 #include "ash/shell.h" |
24 #include "ash/shell_window_ids.h" | 25 #include "ash/shell_window_ids.h" |
25 #include "ash/system/status_area_widget.h" | 26 #include "ash/system/status_area_widget.h" |
26 #include "ash/wm/gestures/shelf_gesture_handler.h" | 27 #include "ash/wm/gestures/shelf_gesture_handler.h" |
27 #include "ash/wm/lock_state_controller.h" | 28 #include "ash/wm/lock_state_controller.h" |
28 #include "ash/wm/mru_window_tracker.h" | 29 #include "ash/wm/mru_window_tracker.h" |
29 #include "ash/wm/window_animations.h" | 30 #include "ash/wm/window_animations.h" |
30 #include "ash/wm/window_state.h" | 31 #include "ash/wm/window_state.h" |
31 #include "ash/wm/window_util.h" | 32 #include "ash/wm/window_util.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 const float kDragHideThreshold = 0.4f; | 380 const float kDragHideThreshold = 0.4f; |
380 gfx::Rect bounds = GetIdealBounds(); | 381 gfx::Rect bounds = GetIdealBounds(); |
381 float drag_ratio = fabs(gesture_drag_amount_) / | 382 float drag_ratio = fabs(gesture_drag_amount_) / |
382 (horizontal ? bounds.height() : bounds.width()); | 383 (horizontal ? bounds.height() : bounds.width()); |
383 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { | 384 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
384 should_change = drag_ratio > kDragHideThreshold; | 385 should_change = drag_ratio > kDragHideThreshold; |
385 } else { | 386 } else { |
386 bool correct_direction = false; | 387 bool correct_direction = false; |
387 switch (GetAlignment()) { | 388 switch (GetAlignment()) { |
388 case SHELF_ALIGNMENT_BOTTOM: | 389 case SHELF_ALIGNMENT_BOTTOM: |
| 390 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
389 case SHELF_ALIGNMENT_RIGHT: | 391 case SHELF_ALIGNMENT_RIGHT: |
390 correct_direction = gesture_drag_amount_ < 0; | 392 correct_direction = gesture_drag_amount_ < 0; |
391 break; | 393 break; |
392 case SHELF_ALIGNMENT_LEFT: | 394 case SHELF_ALIGNMENT_LEFT: |
393 correct_direction = gesture_drag_amount_ > 0; | 395 correct_direction = gesture_drag_amount_ > 0; |
394 break; | 396 break; |
395 } | 397 } |
396 should_change = correct_direction && drag_ratio > kDragHideThreshold; | 398 should_change = correct_direction && drag_ratio > kDragHideThreshold; |
397 } | 399 } |
398 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { | 400 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 485 } |
484 | 486 |
485 void ShelfLayoutManager::OnWindowActivated( | 487 void ShelfLayoutManager::OnWindowActivated( |
486 aura::client::ActivationChangeObserver::ActivationReason reason, | 488 aura::client::ActivationChangeObserver::ActivationReason reason, |
487 aura::Window* gained_active, | 489 aura::Window* gained_active, |
488 aura::Window* lost_active) { | 490 aura::Window* lost_active) { |
489 UpdateAutoHideStateNow(); | 491 UpdateAutoHideStateNow(); |
490 } | 492 } |
491 | 493 |
492 bool ShelfLayoutManager::IsHorizontalAlignment() const { | 494 bool ShelfLayoutManager::IsHorizontalAlignment() const { |
493 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM; | 495 return ash::IsHorizontalAlignment(GetAlignment()); |
494 } | |
495 | |
496 bool ShelfLayoutManager::IsAlignmentLocked() const { | |
497 if (state_.is_screen_locked) | |
498 return true; | |
499 // The session state becomes active at the start of transitioning to a user | |
500 // session, however the session is considered blocked until the full UI is | |
501 // ready. Exit early to allow for proper layout. | |
502 SessionStateDelegate* session_state_delegate = | |
503 Shell::GetInstance()->session_state_delegate(); | |
504 if (session_state_delegate->GetSessionState() == | |
505 SessionStateDelegate::SESSION_STATE_ACTIVE) { | |
506 return false; | |
507 } | |
508 if (session_state_delegate->IsUserSessionBlocked() || | |
509 state_.is_adding_user_screen) { | |
510 return true; | |
511 } | |
512 return false; | |
513 } | 496 } |
514 | 497 |
515 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { | 498 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { |
516 chromevox_panel_height_ = height; | 499 chromevox_panel_height_ = height; |
517 LayoutShelf(); | 500 LayoutShelf(); |
518 } | 501 } |
519 | 502 |
520 //////////////////////////////////////////////////////////////////////////////// | 503 //////////////////////////////////////////////////////////////////////////////// |
521 // ShelfLayoutManager, private: | 504 // ShelfLayoutManager, private: |
522 | 505 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 translate = resistance_free_region + diff; | 827 translate = resistance_free_region + diff; |
845 } else { | 828 } else { |
846 translate = gesture_drag_amount_; | 829 translate = gesture_drag_amount_; |
847 } | 830 } |
848 | 831 |
849 if (horizontal) { | 832 if (horizontal) { |
850 // Move and size the shelf with the gesture. | 833 // Move and size the shelf with the gesture. |
851 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 834 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
852 shelf_height = std::max(shelf_height, kAutoHideSize); | 835 shelf_height = std::max(shelf_height, kAutoHideSize); |
853 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 836 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
854 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 837 if (IsHorizontalAlignment()) { |
855 target_bounds->shelf_bounds_in_root.set_y( | 838 target_bounds->shelf_bounds_in_root.set_y( |
856 available_bounds.bottom() - shelf_height); | 839 available_bounds.bottom() - shelf_height); |
857 } | 840 } |
858 | 841 |
859 target_bounds->status_bounds_in_shelf.set_y(0); | 842 target_bounds->status_bounds_in_shelf.set_y(0); |
860 } else { | 843 } else { |
861 // Move and size the shelf with the gesture. | 844 // Move and size the shelf with the gesture. |
862 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 845 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
863 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 846 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
864 if (right_aligned) | 847 if (right_aligned) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 | 983 |
1001 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); | 984 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
1002 if (shelf_->status_area_widget() && | 985 if (shelf_->status_area_widget() && |
1003 shelf_->status_area_widget()->IsMessageBubbleShown() && | 986 shelf_->status_area_widget()->IsMessageBubbleShown() && |
1004 IsVisible()) { | 987 IsVisible()) { |
1005 // Increase the the hit test area to prevent the shelf from disappearing | 988 // Increase the the hit test area to prevent the shelf from disappearing |
1006 // when the mouse is over the bubble gap. | 989 // when the mouse is over the bubble gap. |
1007 ShelfAlignment alignment = GetAlignment(); | 990 ShelfAlignment alignment = GetAlignment(); |
1008 shelf_region.Inset( | 991 shelf_region.Inset( |
1009 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, | 992 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, |
1010 alignment == SHELF_ALIGNMENT_BOTTOM ? -kNotificationBubbleGapHeight : 0, | 993 IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, |
1011 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, | 994 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, |
1012 0); | 995 0); |
1013 } | 996 } |
1014 | 997 |
1015 gfx::Point cursor_position_in_screen = | 998 gfx::Point cursor_position_in_screen = |
1016 gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 999 gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
1017 if (shelf_region.Contains(cursor_position_in_screen)) | 1000 if (shelf_region.Contains(cursor_position_in_screen)) |
1018 return SHELF_AUTO_HIDE_SHOWN; | 1001 return SHELF_AUTO_HIDE_SHOWN; |
1019 | 1002 |
1020 // When the shelf is auto hidden and the shelf is on the boundary between two | 1003 // When the shelf is auto hidden and the shelf is on the boundary between two |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 } | 1093 } |
1111 TargetBounds target_bounds; | 1094 TargetBounds target_bounds; |
1112 CalculateTargetBounds(state_, &target_bounds); | 1095 CalculateTargetBounds(state_, &target_bounds); |
1113 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1096 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1114 UpdateVisibilityState(); | 1097 UpdateVisibilityState(); |
1115 } | 1098 } |
1116 | 1099 |
1117 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1100 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
1118 UpdateVisibilityState(); | 1101 UpdateVisibilityState(); |
1119 LayoutShelf(); | 1102 LayoutShelf(); |
1120 // The shelf alignment may have changed when it was unlocked. | |
1121 Shell::GetInstance()->OnShelfAlignmentChanged( | |
1122 shelf_->GetNativeWindow()->GetRootWindow()); | |
1123 } | 1103 } |
1124 | 1104 |
1125 } // namespace ash | 1105 } // namespace ash |
OLD | NEW |