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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // For instance: | 66 // For instance: |
67 // - Primary display is left of secondary display. | 67 // - Primary display is left of secondary display. |
68 // - Shelf is left aligned | 68 // - Shelf is left aligned |
69 // - This ShelfLayoutManager manages the shelf for the secondary display. | 69 // - This ShelfLayoutManager manages the shelf for the secondary display. |
70 // |kMaxAutoHideShowShelfRegionSize| refers to the maximum size of the region | 70 // |kMaxAutoHideShowShelfRegionSize| refers to the maximum size of the region |
71 // from the right edge of the primary display which can trigger showing the | 71 // from the right edge of the primary display which can trigger showing the |
72 // auto hidden shelf. The region is used to make it easier to trigger showing | 72 // auto hidden shelf. The region is used to make it easier to trigger showing |
73 // the auto hidden shelf when the shelf is on the boundary between displays. | 73 // the auto hidden shelf when the shelf is on the boundary between displays. |
74 const int kMaxAutoHideShowShelfRegionSize = 10; | 74 const int kMaxAutoHideShowShelfRegionSize = 10; |
75 | 75 |
76 // Const inset from the edget of the shelf to the edget of the status area. | |
77 const int kStatusAreaInset = 3; | |
78 | |
79 ui::Layer* GetLayer(views::Widget* widget) { | 76 ui::Layer* GetLayer(views::Widget* widget) { |
80 return widget->GetNativeView()->layer(); | 77 return widget->GetNativeView()->layer(); |
81 } | 78 } |
82 | 79 |
83 bool IsDraggingTrayEnabled() { | 80 bool IsDraggingTrayEnabled() { |
84 static bool dragging_tray_allowed = CommandLine::ForCurrentProcess()-> | 81 static bool dragging_tray_allowed = CommandLine::ForCurrentProcess()-> |
85 HasSwitch(ash::switches::kAshEnableTrayDragging); | 82 HasSwitch(ash::switches::kAshEnableTrayDragging); |
86 return dragging_tray_allowed; | 83 return dragging_tray_allowed; |
87 } | 84 } |
88 | 85 |
89 } // namespace | 86 } // namespace |
90 | 87 |
91 // static | 88 // static |
92 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | 89 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; |
93 | 90 |
94 // static | 91 // static |
95 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | 92 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; |
96 | 93 |
97 // static | 94 // static |
98 const int ShelfLayoutManager::kAutoHideSize = 3; | 95 const int ShelfLayoutManager::kAutoHideSize = 3; |
99 | 96 |
100 // static | 97 // static |
101 const int ShelfLayoutManager::kShelfSize = 47; | 98 const int ShelfLayoutManager::kShelfSize = 47; |
102 | 99 |
| 100 // static |
| 101 const int ShelfLayoutManager::kShelfItemInset = 3; |
| 102 |
103 int ShelfLayoutManager::GetPreferredShelfSize() { | 103 int ShelfLayoutManager::GetPreferredShelfSize() { |
104 return ash::switches::UseAlternateShelfLayout() ? | 104 return ash::switches::UseAlternateShelfLayout() ? |
105 ShelfLayoutManager::kShelfSize : kLauncherPreferredSize; | 105 ShelfLayoutManager::kShelfSize : kLauncherPreferredSize; |
106 } | 106 } |
107 | 107 |
108 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 108 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
109 | 109 |
110 // Notifies ShelfLayoutManager any time the mouse moves. | 110 // Notifies ShelfLayoutManager any time the mouse moves. |
111 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 111 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
112 public: | 112 public: |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 gfx::Rect(available_bounds.x(), available_bounds.y(), | 762 gfx::Rect(available_bounds.x(), available_bounds.y(), |
763 shelf_width, available_bounds.height()), | 763 shelf_width, available_bounds.height()), |
764 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 764 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
765 shelf_width, available_bounds.height()), | 765 shelf_width, available_bounds.height()), |
766 gfx::Rect(available_bounds.x(), available_bounds.y(), | 766 gfx::Rect(available_bounds.x(), available_bounds.y(), |
767 available_bounds.width(), shelf_height)); | 767 available_bounds.width(), shelf_height)); |
768 | 768 |
769 int status_inset = std::max(0, GetPreferredShelfSize() - | 769 int status_inset = std::max(0, GetPreferredShelfSize() - |
770 PrimaryAxisValue(status_size.height(), status_size.width())); | 770 PrimaryAxisValue(status_size.height(), status_size.width())); |
771 | 771 |
772 if (ash::switches::UseAlternateShelfLayout()) | 772 if (ash::switches::UseAlternateShelfLayout()) { |
773 status_inset = kStatusAreaInset; | 773 status_inset = 0; |
| 774 if (IsHorizontalAlignment()) |
| 775 status_size.set_height(kShelfSize); |
| 776 else |
| 777 status_size.set_width(kShelfSize); |
| 778 } |
774 | 779 |
775 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( | 780 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
776 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 781 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
777 status_inset, status_size.width(), status_size.height()), | 782 status_inset, status_size.width(), status_size.height()), |
778 gfx::Rect(shelf_width - (status_size.width() + status_inset), | 783 gfx::Rect(shelf_width - (status_size.width() + status_inset), |
779 shelf_height - status_size.height(), status_size.width(), | 784 shelf_height - status_size.height(), status_size.width(), |
780 status_size.height()), | 785 status_size.height()), |
781 gfx::Rect(status_inset, shelf_height - status_size.height(), | 786 gfx::Rect(status_inset, shelf_height - status_size.height(), |
782 status_size.width(), status_size.height()), | 787 status_size.width(), status_size.height()), |
783 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 788 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // Move and size the launcher with the gesture. | 880 // Move and size the launcher with the gesture. |
876 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 881 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
877 shelf_height = std::max(shelf_height, kAutoHideSize); | 882 shelf_height = std::max(shelf_height, kAutoHideSize); |
878 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 883 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
879 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 884 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
880 target_bounds->shelf_bounds_in_root.set_y( | 885 target_bounds->shelf_bounds_in_root.set_y( |
881 available_bounds.bottom() - shelf_height); | 886 available_bounds.bottom() - shelf_height); |
882 } | 887 } |
883 | 888 |
884 if (ash::switches::UseAlternateShelfLayout()) { | 889 if (ash::switches::UseAlternateShelfLayout()) { |
885 target_bounds->status_bounds_in_shelf.set_y(kStatusAreaInset); | 890 target_bounds->status_bounds_in_shelf.set_y(0); |
886 } else { | 891 } else { |
887 // The statusbar should be in the center of the shelf. | 892 // The statusbar should be in the center of the shelf. |
888 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | 893 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; |
889 status_y.set_y(0); | 894 status_y.set_y(0); |
890 status_y.ClampToCenteredSize( | 895 status_y.ClampToCenteredSize( |
891 target_bounds->status_bounds_in_shelf.size()); | 896 target_bounds->status_bounds_in_shelf.size()); |
892 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | 897 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); |
893 } | 898 } |
894 } else { | 899 } else { |
895 // Move and size the launcher with the gesture. | 900 // Move and size the launcher with the gesture. |
896 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 901 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
897 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 902 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
898 if (right_aligned) | 903 if (right_aligned) |
899 shelf_width -= translate; | 904 shelf_width -= translate; |
900 else | 905 else |
901 shelf_width += translate; | 906 shelf_width += translate; |
902 shelf_width = std::max(shelf_width, kAutoHideSize); | 907 shelf_width = std::max(shelf_width, kAutoHideSize); |
903 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 908 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
904 if (right_aligned) { | 909 if (right_aligned) { |
905 target_bounds->shelf_bounds_in_root.set_x( | 910 target_bounds->shelf_bounds_in_root.set_x( |
906 available_bounds.right() - shelf_width); | 911 available_bounds.right() - shelf_width); |
907 } | 912 } |
908 | 913 |
909 if (ash::switches::UseAlternateShelfLayout()) { | 914 if (ash::switches::UseAlternateShelfLayout()) { |
910 if (right_aligned) { | 915 if (right_aligned) |
911 target_bounds->status_bounds_in_shelf.set_x(kStatusAreaInset); | 916 target_bounds->status_bounds_in_shelf.set_x(0); |
912 } else { | 917 else |
913 target_bounds->status_bounds_in_shelf.set_x( | 918 target_bounds->status_bounds_in_shelf.set_x( |
914 available_bounds.right() - shelf_width + kStatusAreaInset); | 919 target_bounds->shelf_bounds_in_root.width() - |
915 } | 920 kShelfSize); |
916 } else { | 921 } else { |
917 // The statusbar should be in the center of the shelf. | 922 // The statusbar should be in the center of the shelf. |
918 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; | 923 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; |
919 status_x.set_x(0); | 924 status_x.set_x(0); |
920 status_x.ClampToCenteredSize( | 925 status_x.ClampToCenteredSize( |
921 target_bounds->status_bounds_in_shelf.size()); | 926 target_bounds->status_bounds_in_shelf.size()); |
922 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); | 927 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); |
923 } | 928 } |
924 } | 929 } |
925 } | 930 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 return gfx::Insets(0, distance, 0, 0); | 1154 return gfx::Insets(0, distance, 0, 0); |
1150 case SHELF_ALIGNMENT_TOP: | 1155 case SHELF_ALIGNMENT_TOP: |
1151 return gfx::Insets(0, 0, distance, 0); | 1156 return gfx::Insets(0, 0, distance, 0); |
1152 } | 1157 } |
1153 NOTREACHED(); | 1158 NOTREACHED(); |
1154 return gfx::Insets(); | 1159 return gfx::Insets(); |
1155 } | 1160 } |
1156 | 1161 |
1157 } // namespace internal | 1162 } // namespace internal |
1158 } // namespace ash | 1163 } // namespace ash |
OLD | NEW |