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> |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // direction of the drag does not matter. | 381 // direction of the drag does not matter. |
382 const float kDragHideThreshold = 0.4f; | 382 const float kDragHideThreshold = 0.4f; |
383 gfx::Rect bounds = GetIdealBounds(); | 383 gfx::Rect bounds = GetIdealBounds(); |
384 float drag_ratio = fabs(gesture_drag_amount_) / | 384 float drag_ratio = fabs(gesture_drag_amount_) / |
385 (horizontal ? bounds.height() : bounds.width()); | 385 (horizontal ? bounds.height() : bounds.width()); |
386 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { | 386 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
387 should_change = drag_ratio > kDragHideThreshold; | 387 should_change = drag_ratio > kDragHideThreshold; |
388 } else { | 388 } else { |
389 bool correct_direction = false; | 389 bool correct_direction = false; |
390 switch (GetAlignment()) { | 390 switch (GetAlignment()) { |
391 case SHELF_ALIGNMENT_BOTTOM: | 391 case wm::SHELF_ALIGNMENT_BOTTOM: |
392 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 392 case wm::SHELF_ALIGNMENT_BOTTOM_LOCKED: |
393 case SHELF_ALIGNMENT_RIGHT: | 393 case wm::SHELF_ALIGNMENT_RIGHT: |
394 correct_direction = gesture_drag_amount_ < 0; | 394 correct_direction = gesture_drag_amount_ < 0; |
395 break; | 395 break; |
396 case SHELF_ALIGNMENT_LEFT: | 396 case wm::SHELF_ALIGNMENT_LEFT: |
397 correct_direction = gesture_drag_amount_ > 0; | 397 correct_direction = gesture_drag_amount_ > 0; |
398 break; | 398 break; |
399 } | 399 } |
400 should_change = correct_direction && drag_ratio > kDragHideThreshold; | 400 should_change = correct_direction && drag_ratio > kDragHideThreshold; |
401 } | 401 } |
402 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { | 402 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { |
403 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { | 403 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
404 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : | 404 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : |
405 fabs(gesture.details().velocity_x()) > 0; | 405 fabs(gesture.details().velocity_x()) > 0; |
406 } else { | 406 } else { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 839 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
840 if (IsHorizontalAlignment()) { | 840 if (IsHorizontalAlignment()) { |
841 target_bounds->shelf_bounds_in_root.set_y( | 841 target_bounds->shelf_bounds_in_root.set_y( |
842 available_bounds.bottom() - shelf_height); | 842 available_bounds.bottom() - shelf_height); |
843 } | 843 } |
844 | 844 |
845 target_bounds->status_bounds_in_shelf.set_y(0); | 845 target_bounds->status_bounds_in_shelf.set_y(0); |
846 } else { | 846 } else { |
847 // Move and size the shelf with the gesture. | 847 // Move and size the shelf with the gesture. |
848 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 848 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
849 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 849 bool right_aligned = GetAlignment() == wm::SHELF_ALIGNMENT_RIGHT; |
850 if (right_aligned) | 850 if (right_aligned) |
851 shelf_width -= translate; | 851 shelf_width -= translate; |
852 else | 852 else |
853 shelf_width += translate; | 853 shelf_width += translate; |
854 shelf_width = std::max(shelf_width, kAutoHideSize); | 854 shelf_width = std::max(shelf_width, kAutoHideSize); |
855 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 855 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
856 if (right_aligned) { | 856 if (right_aligned) { |
857 target_bounds->shelf_bounds_in_root.set_x( | 857 target_bounds->shelf_bounds_in_root.set_x( |
858 available_bounds.right() - shelf_width); | 858 available_bounds.right() - shelf_width); |
859 } | 859 } |
860 | 860 |
861 if (right_aligned) | 861 if (right_aligned) |
862 target_bounds->status_bounds_in_shelf.set_x(0); | 862 target_bounds->status_bounds_in_shelf.set_x(0); |
863 else | 863 else |
864 target_bounds->status_bounds_in_shelf.set_x( | 864 target_bounds->status_bounds_in_shelf.set_x( |
865 target_bounds->shelf_bounds_in_root.width() - | 865 target_bounds->shelf_bounds_in_root.width() - |
866 kShelfSize); | 866 kShelfSize); |
867 } | 867 } |
868 } | 868 } |
869 | 869 |
870 void ShelfLayoutManager::UpdateShelfBackground( | 870 void ShelfLayoutManager::UpdateShelfBackground( |
871 BackgroundAnimatorChangeType type) { | 871 BackgroundAnimatorChangeType type) { |
872 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 872 const wm::ShelfBackgroundType background_type(GetShelfBackgroundType()); |
873 shelf_->SetPaintsBackground(background_type, type); | 873 shelf_->SetPaintsBackground(background_type, type); |
874 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 874 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
875 OnBackgroundUpdated(background_type, type)); | 875 OnBackgroundUpdated(background_type, type)); |
876 } | 876 } |
877 | 877 |
878 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { | 878 wm::ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { |
879 if (state_.visibility_state != SHELF_AUTO_HIDE && | 879 if (state_.visibility_state != SHELF_AUTO_HIDE && |
880 state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { | 880 state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { |
881 return SHELF_BACKGROUND_MAXIMIZED; | 881 return wm::SHELF_BACKGROUND_MAXIMIZED; |
882 } | 882 } |
883 | 883 |
884 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 884 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
885 (!state_.is_screen_locked && !state_.is_adding_user_screen && | 885 (!state_.is_screen_locked && !state_.is_adding_user_screen && |
886 window_overlaps_shelf_) || | 886 window_overlaps_shelf_) || |
887 (state_.visibility_state == SHELF_AUTO_HIDE)) { | 887 (state_.visibility_state == SHELF_AUTO_HIDE)) { |
888 return SHELF_BACKGROUND_OVERLAP; | 888 return wm::SHELF_BACKGROUND_OVERLAP; |
889 } | 889 } |
890 | 890 |
891 return SHELF_BACKGROUND_DEFAULT; | 891 return wm::SHELF_BACKGROUND_DEFAULT; |
892 } | 892 } |
893 | 893 |
894 void ShelfLayoutManager::UpdateAutoHideStateNow() { | 894 void ShelfLayoutManager::UpdateAutoHideStateNow() { |
895 SetState(state_.visibility_state); | 895 SetState(state_.visibility_state); |
896 | 896 |
897 // If the state did not change, the auto hide timer may still be running. | 897 // If the state did not change, the auto hide timer may still be running. |
898 StopAutoHideTimer(); | 898 StopAutoHideTimer(); |
899 } | 899 } |
900 | 900 |
901 void ShelfLayoutManager::StopAutoHideTimer() { | 901 void ShelfLayoutManager::StopAutoHideTimer() { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 shelf_->GetNativeWindow()->GetRootWindow()); | 983 shelf_->GetNativeWindow()->GetRootWindow()); |
984 if (!cursor_client->IsMouseEventsEnabled()) | 984 if (!cursor_client->IsMouseEventsEnabled()) |
985 return SHELF_AUTO_HIDE_HIDDEN; | 985 return SHELF_AUTO_HIDE_HIDDEN; |
986 | 986 |
987 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); | 987 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
988 if (shelf_->status_area_widget() && | 988 if (shelf_->status_area_widget() && |
989 shelf_->status_area_widget()->IsMessageBubbleShown() && | 989 shelf_->status_area_widget()->IsMessageBubbleShown() && |
990 IsVisible()) { | 990 IsVisible()) { |
991 // Increase the the hit test area to prevent the shelf from disappearing | 991 // Increase the the hit test area to prevent the shelf from disappearing |
992 // when the mouse is over the bubble gap. | 992 // when the mouse is over the bubble gap. |
993 ShelfAlignment alignment = GetAlignment(); | 993 wm::ShelfAlignment alignment = GetAlignment(); |
994 shelf_region.Inset( | 994 shelf_region.Inset( |
995 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, | 995 alignment == wm::SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight |
| 996 : 0, |
996 IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, | 997 IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, |
997 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, | 998 alignment == wm::SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight |
| 999 : 0, |
998 0); | 1000 0); |
999 } | 1001 } |
1000 | 1002 |
1001 gfx::Point cursor_position_in_screen = | 1003 gfx::Point cursor_position_in_screen = |
1002 gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 1004 gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
1003 if (shelf_region.Contains(cursor_position_in_screen)) | 1005 if (shelf_region.Contains(cursor_position_in_screen)) |
1004 return SHELF_AUTO_HIDE_SHOWN; | 1006 return SHELF_AUTO_HIDE_SHOWN; |
1005 | 1007 |
1006 // When the shelf is auto hidden and the shelf is on the boundary between two | 1008 // When the shelf is auto hidden and the shelf is on the boundary between two |
1007 // displays, it is hard to trigger showing the shelf. For instance, if a | 1009 // displays, it is hard to trigger showing the shelf. For instance, if a |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1101 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1100 UpdateVisibilityState(); | 1102 UpdateVisibilityState(); |
1101 } | 1103 } |
1102 | 1104 |
1103 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1105 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
1104 UpdateVisibilityState(); | 1106 UpdateVisibilityState(); |
1105 LayoutShelf(); | 1107 LayoutShelf(); |
1106 } | 1108 } |
1107 | 1109 |
1108 } // namespace ash | 1110 } // namespace ash |
OLD | NEW |