| 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/common/shelf/shelf_layout_manager.h" | 5 #include "ash/common/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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return SHELF_HIDDEN; | 195 return SHELF_HIDDEN; |
| 196 } | 196 } |
| 197 return SHELF_VISIBLE; | 197 return SHELF_VISIBLE; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void ShelfLayoutManager::UpdateVisibilityState() { | 200 void ShelfLayoutManager::UpdateVisibilityState() { |
| 201 // Bail out early before the shelf is initialized or after it is destroyed. | 201 // Bail out early before the shelf is initialized or after it is destroyed. |
| 202 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | 202 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 203 if (in_shutdown_ || !wm_shelf_->IsShelfInitialized() || !shelf_window) | 203 if (in_shutdown_ || !wm_shelf_->IsShelfInitialized() || !shelf_window) |
| 204 return; | 204 return; |
| 205 bool was_invisible_auto_hide_shelf = invisible_auto_hide_shelf_; | |
| 206 // Always reset to be safe. | |
| 207 invisible_auto_hide_shelf_ = false; | |
| 208 if (state_.is_screen_locked || state_.is_adding_user_screen) { | 205 if (state_.is_screen_locked || state_.is_adding_user_screen) { |
| 209 SetState(SHELF_VISIBLE); | 206 SetState(SHELF_VISIBLE); |
| 210 } else if (WmShell::Get()->IsPinned()) { | 207 } else if (WmShell::Get()->IsPinned()) { |
| 211 SetState(SHELF_HIDDEN); | 208 SetState(SHELF_HIDDEN); |
| 212 } else { | 209 } else { |
| 213 // TODO(zelidrag): Verify shelf drag animation still shows on the device | 210 // TODO(zelidrag): Verify shelf drag animation still shows on the device |
| 214 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. | 211 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
| 215 wm::WorkspaceWindowState window_state( | 212 wm::WorkspaceWindowState window_state( |
| 216 shelf_window->GetRootWindowController()->GetWorkspaceWindowState()); | 213 shelf_window->GetRootWindowController()->GetWorkspaceWindowState()); |
| 217 switch (window_state) { | 214 switch (window_state) { |
| 218 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { | 215 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { |
| 219 switch (GetShelfModeForFullscreen()) { | 216 if (IsShelfHiddenForFullscreen()) { |
| 220 case wm::WindowState::SHELF_HIDDEN: | 217 SetState(SHELF_HIDDEN); |
| 221 SetState(SHELF_HIDDEN); | 218 } else { |
| 222 break; | 219 // The shelf is sometimes not hidden when in immersive fullscreen. |
| 223 case wm::WindowState::SHELF_AUTO_HIDE_INVISIBLE: | 220 // Force the shelf to be auto hidden in this case. |
| 224 invisible_auto_hide_shelf_ = true; | 221 SetState(SHELF_AUTO_HIDE); |
| 225 case wm::WindowState::SHELF_AUTO_HIDE_VISIBLE: | |
| 226 if (was_invisible_auto_hide_shelf != invisible_auto_hide_shelf_ && | |
| 227 state_.visibility_state == SHELF_AUTO_HIDE) { | |
| 228 // A hack to swtich the visibility state correctly | |
| 229 // between auto hide visible to auto hide invisible. | |
| 230 // TODO(oshima): Remove this once MD ash is launched. | |
| 231 SetState(SHELF_HIDDEN); | |
| 232 } | |
| 233 SetState(SHELF_AUTO_HIDE); | |
| 234 break; | |
| 235 } | 222 } |
| 236 break; | 223 break; |
| 237 } | 224 } |
| 238 | |
| 239 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: | 225 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: |
| 240 SetState(CalculateShelfVisibility()); | 226 SetState(CalculateShelfVisibility()); |
| 241 break; | 227 break; |
| 242 | 228 |
| 243 case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: | 229 case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: |
| 244 case wm::WORKSPACE_WINDOW_STATE_DEFAULT: | 230 case wm::WORKSPACE_WINDOW_STATE_DEFAULT: |
| 245 SetState(CalculateShelfVisibility()); | 231 SetState(CalculateShelfVisibility()); |
| 246 SetWindowOverlapsShelf( | 232 SetWindowOverlapsShelf( |
| 247 window_state == wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); | 233 window_state == wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); |
| 248 break; | 234 break; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 if (resist) { | 752 if (resist) { |
| 767 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 753 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| 768 diff = std::min(diff, sqrtf(diff)); | 754 diff = std::min(diff, sqrtf(diff)); |
| 769 if (gesture_drag_amount_ < 0) | 755 if (gesture_drag_amount_ < 0) |
| 770 translate = -resistance_free_region - diff; | 756 translate = -resistance_free_region - diff; |
| 771 else | 757 else |
| 772 translate = resistance_free_region + diff; | 758 translate = resistance_free_region + diff; |
| 773 } else { | 759 } else { |
| 774 translate = gesture_drag_amount_; | 760 translate = gesture_drag_amount_; |
| 775 } | 761 } |
| 776 int shelf_insets = GetShelfInsetsForAutoHide(); | 762 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
| 777 if (horizontal) { | 763 if (horizontal) { |
| 778 // Move and size the shelf with the gesture. | 764 // Move and size the shelf with the gesture. |
| 779 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 765 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 780 shelf_height = std::max(shelf_height, shelf_insets); | 766 shelf_height = std::max(shelf_height, shelf_insets); |
| 781 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 767 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
| 782 if (IsHorizontalAlignment()) { | 768 if (IsHorizontalAlignment()) { |
| 783 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - | 769 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - |
| 784 shelf_height); | 770 shelf_height); |
| 785 } | 771 } |
| 786 | 772 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 WmWindow* status_window = | 943 WmWindow* status_window = |
| 958 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); | 944 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); |
| 959 return (shelf_window && shelf_window->Contains(window)) || | 945 return (shelf_window && shelf_window->Contains(window)) || |
| 960 (status_window && status_window->Contains(window)); | 946 (status_window && status_window->Contains(window)); |
| 961 } | 947 } |
| 962 | 948 |
| 963 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { | 949 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { |
| 964 if (state.visibility_state == SHELF_VISIBLE) | 950 if (state.visibility_state == SHELF_VISIBLE) |
| 965 return size; | 951 return size; |
| 966 if (state.visibility_state == SHELF_AUTO_HIDE) | 952 if (state.visibility_state == SHELF_AUTO_HIDE) |
| 967 return GetShelfInsetsForAutoHide(); | 953 return GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
| 968 return 0; | 954 return 0; |
| 969 } | 955 } |
| 970 | 956 |
| 971 void ShelfLayoutManager::OnDockBoundsChanging( | 957 void ShelfLayoutManager::OnDockBoundsChanging( |
| 972 const gfx::Rect& dock_bounds, | 958 const gfx::Rect& dock_bounds, |
| 973 DockedWindowLayoutManagerObserver::Reason reason) { | 959 DockedWindowLayoutManagerObserver::Reason reason) { |
| 974 // Skip shelf layout in case docked notification originates from this class. | 960 // Skip shelf layout in case docked notification originates from this class. |
| 975 if (reason == DISPLAY_INSETS_CHANGED) | 961 if (reason == DISPLAY_INSETS_CHANGED) |
| 976 return; | 962 return; |
| 977 if (dock_bounds_ != dock_bounds) { | 963 if (dock_bounds_ != dock_bounds) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 } | 1000 } |
| 1015 | 1001 |
| 1016 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1002 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
| 1017 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1003 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| 1018 state.visibility_state == SHELF_VISIBLE) { | 1004 state.visibility_state == SHELF_VISIBLE) { |
| 1019 return 1.0f; | 1005 return 1.0f; |
| 1020 } | 1006 } |
| 1021 // In Chrome OS Material Design, when shelf is hidden during auto hide state, | 1007 // In Chrome OS Material Design, when shelf is hidden during auto hide state, |
| 1022 // target bounds are also hidden. So the window can extend to the edge of | 1008 // target bounds are also hidden. So the window can extend to the edge of |
| 1023 // screen. | 1009 // screen. |
| 1024 if (ash::MaterialDesignController::IsImmersiveModeMaterial() || | 1010 if (ash::MaterialDesignController::IsImmersiveModeMaterial()) { |
| 1025 invisible_auto_hide_shelf_) { | |
| 1026 return (state.visibility_state == SHELF_AUTO_HIDE && | 1011 return (state.visibility_state == SHELF_AUTO_HIDE && |
| 1027 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) | 1012 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) |
| 1028 ? 1.0f | 1013 ? 1.0f |
| 1029 : 0.0f; | 1014 : 0.0f; |
| 1030 } | 1015 } |
| 1031 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 1016 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
| 1032 } | 1017 } |
| 1033 | 1018 |
| 1034 ash::wm::WindowState::FullscreenShelfMode | |
| 1035 ShelfLayoutManager::GetShelfModeForFullscreen() const { | |
| 1036 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( | |
| 1037 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); | |
| 1038 return fullscreen_window->GetWindowState()->shelf_mode_in_fullscreen(); | |
| 1039 } | |
| 1040 | |
| 1041 bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const { | 1019 bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const { |
| 1042 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( | 1020 const WmWindow* fullscreen_window = wm::GetWindowForFullscreenMode( |
| 1043 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); | 1021 WmLookup::Get()->GetWindowForWidget(shelf_widget_)); |
| 1044 return fullscreen_window && | 1022 return fullscreen_window && |
| 1045 fullscreen_window->GetWindowState()->shelf_mode_in_fullscreen() == | 1023 fullscreen_window->GetWindowState()->hide_shelf_when_fullscreen(); |
| 1046 ash::wm::WindowState::SHELF_HIDDEN; | |
| 1047 } | 1024 } |
| 1048 | 1025 |
| 1049 //////////////////////////////////////////////////////////////////////////////// | 1026 //////////////////////////////////////////////////////////////////////////////// |
| 1050 // ShelfLayoutManager, Gesture functions: | 1027 // ShelfLayoutManager, Gesture functions: |
| 1051 | 1028 |
| 1052 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { | 1029 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 1053 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; | 1030 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
| 1054 gesture_drag_amount_ = 0.f; | 1031 gesture_drag_amount_ = 0.f; |
| 1055 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE | 1032 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE |
| 1056 ? auto_hide_state() | 1033 ? auto_hide_state() |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 UpdateVisibilityState(); | 1110 UpdateVisibilityState(); |
| 1134 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1111 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1135 } | 1112 } |
| 1136 | 1113 |
| 1137 void ShelfLayoutManager::CancelGestureDrag() { | 1114 void ShelfLayoutManager::CancelGestureDrag() { |
| 1138 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1115 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1139 UpdateVisibilityState(); | 1116 UpdateVisibilityState(); |
| 1140 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1117 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1141 } | 1118 } |
| 1142 | 1119 |
| 1143 int ShelfLayoutManager::GetShelfInsetsForAutoHide() const { | |
| 1144 if (invisible_auto_hide_shelf_) | |
| 1145 return 0; | |
| 1146 return GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | |
| 1147 } | |
| 1148 | |
| 1149 } // namespace ash | 1120 } // namespace ash |
| OLD | NEW |