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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // static | 87 // static |
88 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | 88 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; |
89 | 89 |
90 // static | 90 // static |
91 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | 91 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; |
92 | 92 |
93 // static | 93 // static |
94 const int ShelfLayoutManager::kAutoHideSize = 3; | 94 const int ShelfLayoutManager::kAutoHideSize = 3; |
95 | 95 |
96 // static | 96 // static |
97 const int ShelfLayoutManager::kShelfSize = 47; | |
98 | |
99 // static | |
100 const int ShelfLayoutManager::kShelfItemInset = 3; | 97 const int ShelfLayoutManager::kShelfItemInset = 3; |
101 | 98 |
102 int ShelfLayoutManager::GetPreferredShelfSize() { | |
103 return ash::switches::UseAlternateShelfLayout() ? | |
104 ShelfLayoutManager::kShelfSize : kShelfPreferredSize; | |
105 } | |
106 | |
107 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 99 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
108 | 100 |
109 // Notifies ShelfLayoutManager any time the mouse moves. | 101 // Notifies ShelfLayoutManager any time the mouse moves. |
110 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 102 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
111 public: | 103 public: |
112 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); | 104 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
113 virtual ~AutoHideEventFilter(); | 105 virtual ~AutoHideEventFilter(); |
114 | 106 |
115 // Returns true if the last mouse event was a mouse drag. | 107 // Returns true if the last mouse event was a mouse drag. |
116 bool in_mouse_drag() const { return in_mouse_drag_; } | 108 bool in_mouse_drag() const { return in_mouse_drag_; } |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 void ShelfLayoutManager::StopAnimating() { | 743 void ShelfLayoutManager::StopAnimating() { |
752 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 744 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
753 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 745 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
754 } | 746 } |
755 | 747 |
756 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 748 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
757 *width = *height = 0; | 749 *width = *height = 0; |
758 gfx::Size status_size( | 750 gfx::Size status_size( |
759 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 751 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
760 if (IsHorizontalAlignment()) | 752 if (IsHorizontalAlignment()) |
761 *height = GetPreferredShelfSize(); | 753 *height = kShelfSize; |
762 else | 754 else |
763 *width = GetPreferredShelfSize(); | 755 *width = kShelfSize; |
764 } | 756 } |
765 | 757 |
766 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 758 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
767 gfx::Rect* bounds) const { | 759 gfx::Rect* bounds) const { |
768 bounds->Inset(SelectValueForShelfAlignment( | 760 bounds->Inset(SelectValueForShelfAlignment( |
769 gfx::Insets(0, 0, inset, 0), | 761 gfx::Insets(0, 0, inset, 0), |
770 gfx::Insets(0, inset, 0, 0), | 762 gfx::Insets(0, inset, 0, 0), |
771 gfx::Insets(0, 0, 0, inset), | 763 gfx::Insets(0, 0, 0, inset), |
772 gfx::Insets(inset, 0, 0, 0))); | 764 gfx::Insets(inset, 0, 0, 0))); |
773 } | 765 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( | 797 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
806 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, | 798 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
807 available_bounds.width(), shelf_height), | 799 available_bounds.width(), shelf_height), |
808 gfx::Rect(available_bounds.x(), available_bounds.y(), | 800 gfx::Rect(available_bounds.x(), available_bounds.y(), |
809 shelf_width, available_bounds.height()), | 801 shelf_width, available_bounds.height()), |
810 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 802 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
811 shelf_width, available_bounds.height()), | 803 shelf_width, available_bounds.height()), |
812 gfx::Rect(available_bounds.x(), available_bounds.y(), | 804 gfx::Rect(available_bounds.x(), available_bounds.y(), |
813 available_bounds.width(), shelf_height)); | 805 available_bounds.width(), shelf_height)); |
814 | 806 |
815 int status_inset = std::max(0, GetPreferredShelfSize() - | 807 if (IsHorizontalAlignment()) |
816 PrimaryAxisValue(status_size.height(), status_size.width())); | 808 status_size.set_height(kShelfSize); |
817 | 809 else |
818 if (ash::switches::UseAlternateShelfLayout()) { | 810 status_size.set_width(kShelfSize); |
819 status_inset = 0; | |
820 if (IsHorizontalAlignment()) | |
821 status_size.set_height(kShelfSize); | |
822 else | |
823 status_size.set_width(kShelfSize); | |
824 } | |
825 | 811 |
826 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( | 812 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
827 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 813 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
828 status_inset, status_size.width(), status_size.height()), | 814 0, status_size.width(), status_size.height()), |
829 gfx::Rect(shelf_width - (status_size.width() + status_inset), | 815 gfx::Rect(shelf_width - status_size.width(), |
830 shelf_height - status_size.height(), status_size.width(), | 816 shelf_height - status_size.height(), status_size.width(), |
831 status_size.height()), | 817 status_size.height()), |
832 gfx::Rect(status_inset, shelf_height - status_size.height(), | 818 gfx::Rect(0, shelf_height - status_size.height(), |
833 status_size.width(), status_size.height()), | 819 status_size.width(), status_size.height()), |
834 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 820 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
835 shelf_height - (status_size.height() + status_inset), | 821 shelf_height - status_size.height(), |
836 status_size.width(), status_size.height())); | 822 status_size.width(), status_size.height())); |
837 | 823 |
838 target_bounds->work_area_insets = SelectValueForShelfAlignment( | 824 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
839 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), | 825 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
840 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), | 826 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
841 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), | 827 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
842 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); | 828 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
843 | 829 |
844 // TODO(varkha): The functionality of managing insets for display areas | 830 // TODO(varkha): The functionality of managing insets for display areas |
845 // should probably be pushed to a separate component. This would simplify or | 831 // should probably be pushed to a separate component. This would simplify or |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 const gfx::Rect& available_bounds(root_window_->bounds()); | 880 const gfx::Rect& available_bounds(root_window_->bounds()); |
895 int resistance_free_region = 0; | 881 int resistance_free_region = 0; |
896 | 882 |
897 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 883 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
898 visibility_state() == SHELF_AUTO_HIDE && | 884 visibility_state() == SHELF_AUTO_HIDE && |
899 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 885 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
900 // If the shelf was hidden when the drag started (and the state hasn't | 886 // If the shelf was hidden when the drag started (and the state hasn't |
901 // changed since then, e.g. because the tray-menu was shown because of the | 887 // changed since then, e.g. because the tray-menu was shown because of the |
902 // drag), then allow the drag some resistance-free region at first to make | 888 // drag), then allow the drag some resistance-free region at first to make |
903 // sure the shelf sticks with the finger until the shelf is visible. | 889 // sure the shelf sticks with the finger until the shelf is visible. |
904 resistance_free_region = GetPreferredShelfSize() - kAutoHideSize; | 890 resistance_free_region = kShelfSize - kAutoHideSize; |
905 } | 891 } |
906 | 892 |
907 bool resist = SelectValueForShelfAlignment( | 893 bool resist = SelectValueForShelfAlignment( |
908 gesture_drag_amount_ < -resistance_free_region, | 894 gesture_drag_amount_ < -resistance_free_region, |
909 gesture_drag_amount_ > resistance_free_region, | 895 gesture_drag_amount_ > resistance_free_region, |
910 gesture_drag_amount_ < -resistance_free_region, | 896 gesture_drag_amount_ < -resistance_free_region, |
911 gesture_drag_amount_ > resistance_free_region); | 897 gesture_drag_amount_ > resistance_free_region); |
912 | 898 |
913 float translate = 0.f; | 899 float translate = 0.f; |
914 if (resist) { | 900 if (resist) { |
(...skipping 10 matching lines...) Expand all Loading... |
925 if (horizontal) { | 911 if (horizontal) { |
926 // Move and size the shelf with the gesture. | 912 // Move and size the shelf with the gesture. |
927 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 913 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
928 shelf_height = std::max(shelf_height, kAutoHideSize); | 914 shelf_height = std::max(shelf_height, kAutoHideSize); |
929 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 915 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
930 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 916 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
931 target_bounds->shelf_bounds_in_root.set_y( | 917 target_bounds->shelf_bounds_in_root.set_y( |
932 available_bounds.bottom() - shelf_height); | 918 available_bounds.bottom() - shelf_height); |
933 } | 919 } |
934 | 920 |
935 if (ash::switches::UseAlternateShelfLayout()) { | 921 target_bounds->status_bounds_in_shelf.set_y(0); |
936 target_bounds->status_bounds_in_shelf.set_y(0); | |
937 } else { | |
938 // The statusbar should be in the center of the shelf. | |
939 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | |
940 status_y.set_y(0); | |
941 status_y.ClampToCenteredSize( | |
942 target_bounds->status_bounds_in_shelf.size()); | |
943 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | |
944 } | |
945 } else { | 922 } else { |
946 // Move and size the shelf with the gesture. | 923 // Move and size the shelf with the gesture. |
947 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 924 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
948 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 925 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
949 if (right_aligned) | 926 if (right_aligned) |
950 shelf_width -= translate; | 927 shelf_width -= translate; |
951 else | 928 else |
952 shelf_width += translate; | 929 shelf_width += translate; |
953 shelf_width = std::max(shelf_width, kAutoHideSize); | 930 shelf_width = std::max(shelf_width, kAutoHideSize); |
954 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 931 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
955 if (right_aligned) { | 932 if (right_aligned) { |
956 target_bounds->shelf_bounds_in_root.set_x( | 933 target_bounds->shelf_bounds_in_root.set_x( |
957 available_bounds.right() - shelf_width); | 934 available_bounds.right() - shelf_width); |
958 } | 935 } |
959 | 936 |
960 if (ash::switches::UseAlternateShelfLayout()) { | 937 if (right_aligned) |
961 if (right_aligned) | 938 target_bounds->status_bounds_in_shelf.set_x(0); |
962 target_bounds->status_bounds_in_shelf.set_x(0); | 939 else |
963 else | 940 target_bounds->status_bounds_in_shelf.set_x( |
964 target_bounds->status_bounds_in_shelf.set_x( | 941 target_bounds->shelf_bounds_in_root.width() - |
965 target_bounds->shelf_bounds_in_root.width() - | 942 kShelfSize); |
966 kShelfSize); | |
967 } else { | |
968 // The statusbar should be in the center of the shelf. | |
969 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; | |
970 status_x.set_x(0); | |
971 status_x.ClampToCenteredSize( | |
972 target_bounds->status_bounds_in_shelf.size()); | |
973 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); | |
974 } | |
975 } | 943 } |
976 } | 944 } |
977 | 945 |
978 void ShelfLayoutManager::UpdateShelfBackground( | 946 void ShelfLayoutManager::UpdateShelfBackground( |
979 BackgroundAnimatorChangeType type) { | 947 BackgroundAnimatorChangeType type) { |
980 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 948 const ShelfBackgroundType background_type(GetShelfBackgroundType()); |
981 shelf_->SetPaintsBackground(background_type, type); | 949 shelf_->SetPaintsBackground(background_type, type); |
982 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 950 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
983 OnBackgroundUpdated(background_type, type)); | 951 OnBackgroundUpdated(background_type, type)); |
984 } | 952 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 base::AutoReset<ShelfVisibilityState> state(&state_.visibility_state, | 1162 base::AutoReset<ShelfVisibilityState> state(&state_.visibility_state, |
1195 SHELF_HIDDEN); | 1163 SHELF_HIDDEN); |
1196 TargetBounds target_bounds; | 1164 TargetBounds target_bounds; |
1197 CalculateTargetBounds(state_, &target_bounds); | 1165 CalculateTargetBounds(state_, &target_bounds); |
1198 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1166 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1199 UpdateVisibilityState(); | 1167 UpdateVisibilityState(); |
1200 } | 1168 } |
1201 } | 1169 } |
1202 | 1170 |
1203 } // namespace ash | 1171 } // namespace ash |
OLD | NEW |