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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 return SHELF_VISIBLE; | 232 return SHELF_VISIBLE; |
233 } | 233 } |
234 | 234 |
235 void ShelfLayoutManager::UpdateVisibilityState() { | 235 void ShelfLayoutManager::UpdateVisibilityState() { |
236 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | 236 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
237 WmRootWindowController* controller = shelf_window->GetRootWindowController(); | 237 WmRootWindowController* controller = shelf_window->GetRootWindowController(); |
238 // Bail out early before the shelf is initialized or after it is destroyed. | 238 // Bail out early before the shelf is initialized or after it is destroyed. |
239 if (!controller || !shelf_widget_->shelf() || in_shutdown_) | 239 if (!controller || !shelf_widget_->shelf() || in_shutdown_) |
240 return; | 240 return; |
241 bool was_invisible_auto_hide_shelf = invisible_auto_hide_shelf_; | 241 |
242 // Always reset to be safe. | |
243 invisible_auto_hide_shelf_ = false; | |
244 if (state_.is_screen_locked || state_.is_adding_user_screen) { | 242 if (state_.is_screen_locked || state_.is_adding_user_screen) { |
245 SetState(SHELF_VISIBLE); | 243 SetState(SHELF_VISIBLE); |
246 } else if (WmShell::Get()->IsPinned()) { | 244 } else if (WmShell::Get()->IsPinned()) { |
247 SetState(SHELF_HIDDEN); | 245 SetState(SHELF_HIDDEN); |
248 } else { | 246 } else { |
249 // TODO(zelidrag): Verify shelf drag animation still shows on the device | 247 // TODO(zelidrag): Verify shelf drag animation still shows on the device |
250 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. | 248 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
251 wm::WorkspaceWindowState window_state( | 249 wm::WorkspaceWindowState window_state( |
252 controller->GetWorkspaceWindowState()); | 250 controller->GetWorkspaceWindowState()); |
253 switch (window_state) { | 251 switch (window_state) { |
254 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { | 252 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { |
255 switch (GetShelfModeForFullscreen()) { | 253 if (IsShelfHiddenForFullscreen()) { |
256 case wm::WindowState::SHELF_HIDDEN: | 254 SetState(SHELF_HIDDEN); |
257 SetState(SHELF_HIDDEN); | 255 } else { |
258 break; | 256 // The shelf is sometimes not hidden when in immersive fullscreen. |
259 case wm::WindowState::SHELF_AUTO_HIDE_INVISIBLE: | 257 // Force the shelf to be auto hidden in this case. |
260 invisible_auto_hide_shelf_ = true; | 258 SetState(SHELF_AUTO_HIDE); |
261 case wm::WindowState::SHELF_AUTO_HIDE_VISIBLE: | |
262 if (was_invisible_auto_hide_shelf != invisible_auto_hide_shelf_ && | |
263 state_.visibility_state == SHELF_AUTO_HIDE) { | |
264 // A hack to swtich the visibility state correctly | |
265 // between auto hide visible to auto hide invisible. | |
266 // TODO(oshima): Remove this once MD ash is launched. | |
267 SetState(SHELF_HIDDEN); | |
268 } | |
269 SetState(SHELF_AUTO_HIDE); | |
270 break; | |
271 } | 259 } |
272 break; | 260 break; |
273 } | 261 } |
274 | 262 |
275 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: | 263 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: |
276 SetState(CalculateShelfVisibility()); | 264 SetState(CalculateShelfVisibility()); |
277 break; | 265 break; |
278 | 266 |
279 case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: | 267 case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: |
280 case wm::WORKSPACE_WINDOW_STATE_DEFAULT: | 268 case wm::WORKSPACE_WINDOW_STATE_DEFAULT: |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 if (resist) { | 788 if (resist) { |
801 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 789 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
802 diff = std::min(diff, sqrtf(diff)); | 790 diff = std::min(diff, sqrtf(diff)); |
803 if (gesture_drag_amount_ < 0) | 791 if (gesture_drag_amount_ < 0) |
804 translate = -resistance_free_region - diff; | 792 translate = -resistance_free_region - diff; |
805 else | 793 else |
806 translate = resistance_free_region + diff; | 794 translate = resistance_free_region + diff; |
807 } else { | 795 } else { |
808 translate = gesture_drag_amount_; | 796 translate = gesture_drag_amount_; |
809 } | 797 } |
810 int shelf_insets = GetShelfInsetsForAutoHide(); | 798 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
811 if (horizontal) { | 799 if (horizontal) { |
812 // Move and size the shelf with the gesture. | 800 // Move and size the shelf with the gesture. |
813 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 801 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
814 shelf_height = std::max(shelf_height, shelf_insets); | 802 shelf_height = std::max(shelf_height, shelf_insets); |
815 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 803 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
816 if (IsHorizontalAlignment()) { | 804 if (IsHorizontalAlignment()) { |
817 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - | 805 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - |
818 shelf_height); | 806 shelf_height); |
819 } | 807 } |
820 | 808 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 WmWindow* status_window = | 981 WmWindow* status_window = |
994 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); | 982 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); |
995 return (shelf_window && shelf_window->Contains(window)) || | 983 return (shelf_window && shelf_window->Contains(window)) || |
996 (status_window && status_window->Contains(window)); | 984 (status_window && status_window->Contains(window)); |
997 } | 985 } |
998 | 986 |
999 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { | 987 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { |
1000 if (state.visibility_state == SHELF_VISIBLE) | 988 if (state.visibility_state == SHELF_VISIBLE) |
1001 return size; | 989 return size; |
1002 if (state.visibility_state == SHELF_AUTO_HIDE) | 990 if (state.visibility_state == SHELF_AUTO_HIDE) |
1003 return GetShelfInsetsForAutoHide(); | 991 return GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
1004 return 0; | 992 return 0; |
1005 } | 993 } |
1006 | 994 |
1007 void ShelfLayoutManager::OnDockBoundsChanging( | 995 void ShelfLayoutManager::OnDockBoundsChanging( |
1008 const gfx::Rect& dock_bounds, | 996 const gfx::Rect& dock_bounds, |
1009 DockedWindowLayoutManagerObserver::Reason reason) { | 997 DockedWindowLayoutManagerObserver::Reason reason) { |
1010 // Skip shelf layout in case docked notification originates from this class. | 998 // Skip shelf layout in case docked notification originates from this class. |
1011 if (reason == DISPLAY_INSETS_CHANGED) | 999 if (reason == DISPLAY_INSETS_CHANGED) |
1012 return; | 1000 return; |
1013 if (dock_bounds_ != dock_bounds) { | 1001 if (dock_bounds_ != dock_bounds) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 } | 1038 } |
1051 | 1039 |
1052 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1040 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
1053 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1041 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
1054 state.visibility_state == SHELF_VISIBLE) { | 1042 state.visibility_state == SHELF_VISIBLE) { |
1055 return 1.0f; | 1043 return 1.0f; |
1056 } | 1044 } |
1057 // In Chrome OS Material Design, when shelf is hidden during auto hide state, | 1045 // In Chrome OS Material Design, when shelf is hidden during auto hide state, |
1058 // target bounds are also hidden. So the window can extend to the edge of | 1046 // target bounds are also hidden. So the window can extend to the edge of |
1059 // screen. | 1047 // screen. |
1060 if (ash::MaterialDesignController::IsShelfMaterial() || | 1048 if (ash::MaterialDesignController::IsShelfMaterial()) { |
1061 invisible_auto_hide_shelf_) { | |
1062 return (state.visibility_state == SHELF_AUTO_HIDE && | 1049 return (state.visibility_state == SHELF_AUTO_HIDE && |
1063 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) | 1050 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) |
1064 ? 1.0f | 1051 ? 1.0f |
1065 : 0.0f; | 1052 : 0.0f; |
1066 } | 1053 } |
1067 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 1054 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
1068 } | 1055 } |
1069 | 1056 |
1070 ash::wm::WindowState::FullscreenShelfMode | |
1071 ShelfLayoutManager::GetShelfModeForFullscreen() const { | |
1072 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( | |
1073 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); | |
1074 return fullscreen_window->GetWindowState()->shelf_mode_in_fullscreen(); | |
1075 } | |
1076 | |
1077 bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const { | 1057 bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const { |
1078 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( | 1058 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( |
1079 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); | 1059 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); |
1080 return fullscreen_window && | 1060 return fullscreen_window && |
1081 fullscreen_window->GetWindowState()->shelf_mode_in_fullscreen() == | 1061 fullscreen_window->GetWindowState()->hide_shelf_when_fullscreen(); |
1082 ash::wm::WindowState::SHELF_HIDDEN; | |
1083 } | 1062 } |
1084 | 1063 |
1085 //////////////////////////////////////////////////////////////////////////////// | 1064 //////////////////////////////////////////////////////////////////////////////// |
1086 // ShelfLayoutManager, Gesture functions: | 1065 // ShelfLayoutManager, Gesture functions: |
1087 | 1066 |
1088 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { | 1067 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
1089 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; | 1068 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
1090 gesture_drag_amount_ = 0.f; | 1069 gesture_drag_amount_ = 0.f; |
1091 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE | 1070 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE |
1092 ? auto_hide_state() | 1071 ? auto_hide_state() |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 UpdateVisibilityState(); | 1149 UpdateVisibilityState(); |
1171 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1150 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1172 } | 1151 } |
1173 | 1152 |
1174 void ShelfLayoutManager::CancelGestureDrag() { | 1153 void ShelfLayoutManager::CancelGestureDrag() { |
1175 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1154 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
1176 UpdateVisibilityState(); | 1155 UpdateVisibilityState(); |
1177 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1156 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1178 } | 1157 } |
1179 | 1158 |
1180 int ShelfLayoutManager::GetShelfInsetsForAutoHide() const { | |
1181 if (invisible_auto_hide_shelf_) | |
1182 return 0; | |
1183 return GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | |
1184 } | |
1185 | |
1186 } // namespace ash | 1159 } // namespace ash |
OLD | NEW |