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