| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return SHELF_VISIBLE; | 307 return SHELF_VISIBLE; |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ShelfLayoutManager::UpdateVisibilityState() { | 310 void ShelfLayoutManager::UpdateVisibilityState() { |
| 311 // Bail out early when there is no |workspace_controller_|, which happens | 311 // Bail out early when there is no |workspace_controller_|, which happens |
| 312 // during shutdown after PrepareForShutdown. | 312 // during shutdown after PrepareForShutdown. |
| 313 if (!workspace_controller_) | 313 if (!workspace_controller_) |
| 314 return; | 314 return; |
| 315 | 315 |
| 316 if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() || | 316 if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() || |
| 317 force_shelf_always_visibile_) { | 317 IsShelfForcedToBeVisible()) { |
| 318 SetState(SHELF_VISIBLE); | 318 SetState(SHELF_VISIBLE); |
| 319 } else { | 319 } else { |
| 320 // TODO(zelidrag): Verify shelf drag animation still shows on the device | 320 // TODO(zelidrag): Verify shelf drag animation still shows on the device |
| 321 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. | 321 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
| 322 WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); | 322 WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); |
| 323 switch (window_state) { | 323 switch (window_state) { |
| 324 case WORKSPACE_WINDOW_STATE_FULL_SCREEN: { | 324 case WORKSPACE_WINDOW_STATE_FULL_SCREEN: { |
| 325 const aura::Window* fullscreen_window = GetRootWindowController( | 325 const aura::Window* fullscreen_window = GetRootWindowController( |
| 326 root_window_)->GetWindowForFullscreenMode(); | 326 root_window_)->GetWindowForFullscreenMode(); |
| 327 if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> | 327 if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 382 } |
| 383 | 383 |
| 384 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { | 384 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { |
| 385 observers_.RemoveObserver(observer); | 385 observers_.RemoveObserver(observer); |
| 386 } | 386 } |
| 387 | 387 |
| 388 //////////////////////////////////////////////////////////////////////////////// | 388 //////////////////////////////////////////////////////////////////////////////// |
| 389 // ShelfLayoutManager, Gesture functions: | 389 // ShelfLayoutManager, Gesture functions: |
| 390 | 390 |
| 391 void ShelfLayoutManager::OnGestureEdgeSwipe(const ui::GestureEvent& gesture) { | 391 void ShelfLayoutManager::OnGestureEdgeSwipe(const ui::GestureEvent& gesture) { |
| 392 if (force_shelf_always_visibile_) | 392 if (IsShelfForcedToBeVisible()) |
| 393 return; | 393 return; |
| 394 | 394 |
| 395 if (visibility_state() == SHELF_AUTO_HIDE) { | 395 if (visibility_state() == SHELF_AUTO_HIDE) { |
| 396 gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN; | 396 gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN; |
| 397 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 397 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
| 398 UpdateVisibilityState(); | 398 UpdateVisibilityState(); |
| 399 gesture_drag_status_ = GESTURE_DRAG_NONE; | 399 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 | 402 |
| 403 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { | 403 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 404 if (force_shelf_always_visibile_) | 404 if (IsShelfForcedToBeVisible()) |
| 405 return; | 405 return; |
| 406 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; | 406 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
| 407 gesture_drag_amount_ = 0.f; | 407 gesture_drag_amount_ = 0.f; |
| 408 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? | 408 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? |
| 409 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; | 409 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; |
| 410 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 410 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); |
| 411 } | 411 } |
| 412 | 412 |
| 413 ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( | 413 ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( |
| 414 const ui::GestureEvent& gesture) { | 414 const ui::GestureEvent& gesture) { |
| 415 if (force_shelf_always_visibile_) | 415 if (IsShelfForcedToBeVisible()) |
| 416 return DRAG_SHELF; | 416 return DRAG_SHELF; |
| 417 bool horizontal = IsHorizontalAlignment(); | 417 bool horizontal = IsHorizontalAlignment(); |
| 418 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : | 418 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : |
| 419 gesture.details().scroll_x(); | 419 gesture.details().scroll_x(); |
| 420 LayoutShelf(); | 420 LayoutShelf(); |
| 421 | 421 |
| 422 // Start reveling the status menu when: | 422 // Start reveling the status menu when: |
| 423 // - dragging up on an already visible shelf | 423 // - dragging up on an already visible shelf |
| 424 // - dragging up on a hidden shelf, but it is currently completely visible. | 424 // - dragging up on a hidden shelf, but it is currently completely visible. |
| 425 if (horizontal && gesture.details().scroll_y() < 0) { | 425 if (horizontal && gesture.details().scroll_y() < 0) { |
| 426 int min_height = 0; | 426 int min_height = 0; |
| 427 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && shelf_) | 427 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && shelf_) |
| 428 min_height = shelf_->GetContentsView()->GetPreferredSize().height(); | 428 min_height = shelf_->GetContentsView()->GetPreferredSize().height(); |
| 429 | 429 |
| 430 if (min_height < shelf_->GetWindowBoundsInScreen().height() && | 430 if (min_height < shelf_->GetWindowBoundsInScreen().height() && |
| 431 gesture.root_location().x() >= | 431 gesture.root_location().x() >= |
| 432 shelf_->status_area_widget()->GetWindowBoundsInScreen().x() && | 432 shelf_->status_area_widget()->GetWindowBoundsInScreen().x() && |
| 433 IsDraggingTrayEnabled()) | 433 IsDraggingTrayEnabled()) |
| 434 return DRAG_TRAY; | 434 return DRAG_TRAY; |
| 435 } | 435 } |
| 436 | 436 |
| 437 return DRAG_SHELF; | 437 return DRAG_SHELF; |
| 438 } | 438 } |
| 439 | 439 |
| 440 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 440 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
| 441 if (force_shelf_always_visibile_) | 441 if (IsShelfForcedToBeVisible()) |
| 442 return; | 442 return; |
| 443 bool horizontal = IsHorizontalAlignment(); | 443 bool horizontal = IsHorizontalAlignment(); |
| 444 bool should_change = false; | 444 bool should_change = false; |
| 445 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { | 445 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { |
| 446 // The visibility of the shelf changes only if the shelf was dragged X% | 446 // The visibility of the shelf changes only if the shelf was dragged X% |
| 447 // along the correct axis. If the shelf was already visible, then the | 447 // along the correct axis. If the shelf was already visible, then the |
| 448 // direction of the drag does not matter. | 448 // direction of the drag does not matter. |
| 449 const float kDragHideThreshold = 0.4f; | 449 const float kDragHideThreshold = 0.4f; |
| 450 gfx::Rect bounds = GetIdealBounds(); | 450 gfx::Rect bounds = GetIdealBounds(); |
| 451 float drag_ratio = fabs(gesture_drag_amount_) / | 451 float drag_ratio = fabs(gesture_drag_amount_) / |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 else | 1001 else |
| 1002 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); | 1002 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); |
| 1003 | 1003 |
| 1004 // TODO: Figure out if we need any special handling when the keyboard is | 1004 // TODO: Figure out if we need any special handling when the keyboard is |
| 1005 // visible. | 1005 // visible. |
| 1006 return show_shelf_region_in_screen; | 1006 return show_shelf_region_in_screen; |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 1009 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| 1010 ShelfVisibilityState visibility_state) const { | 1010 ShelfVisibilityState visibility_state) const { |
| 1011 if (force_shelf_always_visibile_) | 1011 if (IsShelfForcedToBeVisible()) |
| 1012 return SHELF_AUTO_HIDE_SHOWN; | 1012 return SHELF_AUTO_HIDE_SHOWN; |
| 1013 | 1013 |
| 1014 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) | 1014 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) |
| 1015 return SHELF_AUTO_HIDE_HIDDEN; | 1015 return SHELF_AUTO_HIDE_HIDDEN; |
| 1016 | 1016 |
| 1017 Shell* shell = Shell::GetInstance(); | 1017 Shell* shell = Shell::GetInstance(); |
| 1018 if (shell->GetAppListTargetVisibility()) | 1018 if (shell->GetAppListTargetVisibility()) |
| 1019 return SHELF_AUTO_HIDE_SHOWN; | 1019 return SHELF_AUTO_HIDE_SHOWN; |
| 1020 | 1020 |
| 1021 if (shelf_->status_area_widget() && | 1021 if (shelf_->status_area_widget() && |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 1116 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
| 1117 if (state.visibility_state == SHELF_VISIBLE) | 1117 if (state.visibility_state == SHELF_VISIBLE) |
| 1118 return size; | 1118 return size; |
| 1119 if (state.visibility_state == SHELF_AUTO_HIDE) | 1119 if (state.visibility_state == SHELF_AUTO_HIDE) |
| 1120 return kAutoHideSize; | 1120 return kAutoHideSize; |
| 1121 return 0; | 1121 return 0; |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 bool ShelfLayoutManager::IsShelfForcedToBeVisible() const { |
| 1125 // Bail out early when there is no |workspace_controller_|, which happens |
| 1126 // during shutdown after PrepareForShutdown. |
| 1127 if (!workspace_controller_) |
| 1128 return force_shelf_always_visibile_; |
| 1129 |
| 1130 return force_shelf_always_visibile_ && |
| 1131 workspace_controller_->GetWindowState() != |
| 1132 WORKSPACE_WINDOW_STATE_FULL_SCREEN; |
| 1133 } |
| 1134 |
| 1124 gfx::Rect ShelfLayoutManager::GetAvailableBounds() const { | 1135 gfx::Rect ShelfLayoutManager::GetAvailableBounds() const { |
| 1125 gfx::Rect bounds(root_window_->bounds()); | 1136 gfx::Rect bounds(root_window_->bounds()); |
| 1126 bounds.set_height(bounds.height() - keyboard_bounds_.height()); | 1137 bounds.set_height(bounds.height() - keyboard_bounds_.height()); |
| 1127 return bounds; | 1138 return bounds; |
| 1128 } | 1139 } |
| 1129 | 1140 |
| 1130 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 1141 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 1131 bool keyboard_is_about_to_hide = false; | 1142 bool keyboard_is_about_to_hide = false; |
| 1132 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 1143 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
| 1133 keyboard_is_about_to_hide = true; | 1144 keyboard_is_about_to_hide = true; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 | 1189 |
| 1179 void ShelfLayoutManager::SessionStateChanged( | 1190 void ShelfLayoutManager::SessionStateChanged( |
| 1180 SessionStateDelegate::SessionState state) { | 1191 SessionStateDelegate::SessionState state) { |
| 1181 TargetBounds target_bounds; | 1192 TargetBounds target_bounds; |
| 1182 CalculateTargetBounds(state_, &target_bounds); | 1193 CalculateTargetBounds(state_, &target_bounds); |
| 1183 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1194 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
| 1184 UpdateVisibilityState(); | 1195 UpdateVisibilityState(); |
| 1185 } | 1196 } |
| 1186 | 1197 |
| 1187 } // namespace ash | 1198 } // namespace ash |
| OLD | NEW |