Chromium Code Reviews| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 bool ShelfLayoutManager::IsVisible() const { | 185 bool ShelfLayoutManager::IsVisible() const { |
| 186 // status_area_widget() may be nullptr during the shutdown. | 186 // status_area_widget() may be nullptr during the shutdown. |
| 187 return shelf_widget_->status_area_widget() && | 187 return shelf_widget_->status_area_widget() && |
| 188 shelf_widget_->status_area_widget()->IsVisible() && | 188 shelf_widget_->status_area_widget()->IsVisible() && |
| 189 (state_.visibility_state == SHELF_VISIBLE || | 189 (state_.visibility_state == SHELF_VISIBLE || |
| 190 (state_.visibility_state == SHELF_AUTO_HIDE && | 190 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 191 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 191 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 194 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 195 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 195 const int shelf_size = kShelfSize; |
|
James Cook
2017/04/18 15:31:52
nit: inline uses of kShelfSize
Evan Stade
2017/04/18 16:41:09
Done.
| |
| 196 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 196 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
| 197 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); | 197 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); |
| 198 return SelectValueForShelfAlignment( | 198 return SelectValueForShelfAlignment( |
| 199 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), | 199 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), |
| 200 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), | 200 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), |
| 201 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, | 201 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, |
| 202 rect.height())); | 202 rect.height())); |
| 203 } | 203 } |
| 204 | 204 |
| 205 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 205 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 shelf_widget_->status_area_widget()->Show(); | 653 shelf_widget_->status_area_widget()->Show(); |
| 654 } | 654 } |
| 655 | 655 |
| 656 void ShelfLayoutManager::StopAnimating() { | 656 void ShelfLayoutManager::StopAnimating() { |
| 657 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating(); | 657 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating(); |
| 658 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating(); | 658 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 659 } | 659 } |
| 660 | 660 |
| 661 void ShelfLayoutManager::CalculateTargetBounds(const State& state, | 661 void ShelfLayoutManager::CalculateTargetBounds(const State& state, |
| 662 TargetBounds* target_bounds) { | 662 TargetBounds* target_bounds) { |
| 663 int shelf_size = GetShelfConstant(SHELF_SIZE); | 663 int shelf_size = kShelfSize; |
| 664 if (state.visibility_state == SHELF_AUTO_HIDE && | 664 if (state.visibility_state == SHELF_AUTO_HIDE && |
| 665 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 665 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 666 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 666 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
| 667 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 667 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
| 668 // takes care of setting the height properly. | 668 // takes care of setting the height properly. |
| 669 shelf_size = kShelfAutoHideSize; | 669 shelf_size = kShelfAutoHideSize; |
| 670 } else if (state.visibility_state == SHELF_HIDDEN || | 670 } else if (state.visibility_state == SHELF_HIDDEN || |
| 671 (!keyboard_bounds_.IsEmpty() && | 671 (!keyboard_bounds_.IsEmpty() && |
| 672 !keyboard::IsKeyboardOverscrollEnabled())) { | 672 !keyboard::IsKeyboardOverscrollEnabled())) { |
| 673 shelf_size = 0; | 673 shelf_size = 0; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 687 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 687 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
| 688 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), | 688 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), |
| 689 gfx::Point(available_bounds.x(), available_bounds.y()), | 689 gfx::Point(available_bounds.x(), available_bounds.y()), |
| 690 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); | 690 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); |
| 691 target_bounds->shelf_bounds_in_root = | 691 target_bounds->shelf_bounds_in_root = |
| 692 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); | 692 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); |
| 693 | 693 |
| 694 gfx::Size status_size( | 694 gfx::Size status_size( |
| 695 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); | 695 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 696 if (wm_shelf_->IsHorizontalAlignment()) | 696 if (wm_shelf_->IsHorizontalAlignment()) |
| 697 status_size.set_height(GetShelfConstant(SHELF_SIZE)); | 697 status_size.set_height(kShelfSize); |
| 698 else | 698 else |
| 699 status_size.set_width(GetShelfConstant(SHELF_SIZE)); | 699 status_size.set_width(kShelfSize); |
| 700 | 700 |
| 701 gfx::Point status_origin = SelectValueForShelfAlignment( | 701 gfx::Point status_origin = SelectValueForShelfAlignment( |
| 702 gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(), | 702 gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(), |
| 703 shelf_height - status_size.height()), | 703 shelf_height - status_size.height()), |
| 704 gfx::Point(0, shelf_height - status_size.height())); | 704 gfx::Point(0, shelf_height - status_size.height())); |
| 705 if (wm_shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL()) | 705 if (wm_shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL()) |
| 706 status_origin.set_x(shelf_width - status_size.width()); | 706 status_origin.set_x(shelf_width - status_size.width()); |
| 707 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); | 707 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); |
| 708 | 708 |
| 709 target_bounds->work_area_insets = SelectValueForShelfAlignment( | 709 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(window); | 763 gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(window); |
| 764 int resistance_free_region = 0; | 764 int resistance_free_region = 0; |
| 765 | 765 |
| 766 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 766 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 767 visibility_state() == SHELF_AUTO_HIDE && | 767 visibility_state() == SHELF_AUTO_HIDE && |
| 768 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 768 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 769 // If the shelf was hidden when the drag started (and the state hasn't | 769 // If the shelf was hidden when the drag started (and the state hasn't |
| 770 // changed since then, e.g. because the tray-menu was shown because of the | 770 // changed since then, e.g. because the tray-menu was shown because of the |
| 771 // drag), then allow the drag some resistance-free region at first to make | 771 // drag), then allow the drag some resistance-free region at first to make |
| 772 // sure the shelf sticks with the finger until the shelf is visible. | 772 // sure the shelf sticks with the finger until the shelf is visible. |
| 773 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize; | 773 resistance_free_region = kShelfSize - kShelfAutoHideSize; |
| 774 } | 774 } |
| 775 | 775 |
| 776 bool resist = SelectValueForShelfAlignment( | 776 bool resist = SelectValueForShelfAlignment( |
| 777 gesture_drag_amount_<-resistance_free_region, gesture_drag_amount_> | 777 gesture_drag_amount_<-resistance_free_region, gesture_drag_amount_> |
| 778 resistance_free_region, | 778 resistance_free_region, |
| 779 gesture_drag_amount_ < -resistance_free_region); | 779 gesture_drag_amount_ < -resistance_free_region); |
| 780 | 780 |
| 781 float translate = 0.f; | 781 float translate = 0.f; |
| 782 if (resist) { | 782 if (resist) { |
| 783 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 783 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| 784 diff = std::min(diff, sqrtf(diff)); | 784 diff = std::min(diff, sqrtf(diff)); |
| 785 if (gesture_drag_amount_ < 0) | 785 if (gesture_drag_amount_ < 0) |
| 786 translate = -resistance_free_region - diff; | 786 translate = -resistance_free_region - diff; |
| 787 else | 787 else |
| 788 translate = resistance_free_region + diff; | 788 translate = resistance_free_region + diff; |
| 789 } else { | 789 } else { |
| 790 translate = gesture_drag_amount_; | 790 translate = gesture_drag_amount_; |
| 791 } | 791 } |
| 792 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | |
| 793 if (horizontal) { | 792 if (horizontal) { |
| 794 // Move and size the shelf with the gesture. | 793 // Move and size the shelf with the gesture. |
| 795 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 794 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 796 shelf_height = std::max(shelf_height, shelf_insets); | 795 shelf_height = std::max(shelf_height, 0); |
| 797 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 796 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
| 798 if (wm_shelf_->IsHorizontalAlignment()) { | 797 if (wm_shelf_->IsHorizontalAlignment()) { |
| 799 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - | 798 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - |
| 800 shelf_height); | 799 shelf_height); |
| 801 } | 800 } |
| 802 | 801 |
| 803 target_bounds->status_bounds_in_shelf.set_y(0); | 802 target_bounds->status_bounds_in_shelf.set_y(0); |
| 804 } else { | 803 } else { |
| 805 // Move and size the shelf with the gesture. | 804 // Move and size the shelf with the gesture. |
| 806 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 805 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
| 807 bool right_aligned = wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 806 bool right_aligned = wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
| 808 if (right_aligned) | 807 if (right_aligned) |
| 809 shelf_width -= translate; | 808 shelf_width -= translate; |
| 810 else | 809 else |
| 811 shelf_width += translate; | 810 shelf_width += translate; |
| 812 shelf_width = std::max(shelf_width, shelf_insets); | 811 shelf_width = std::max(shelf_width, 0); |
| 813 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 812 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
| 814 if (right_aligned) { | 813 if (right_aligned) { |
| 815 target_bounds->shelf_bounds_in_root.set_x(available_bounds.right() - | 814 target_bounds->shelf_bounds_in_root.set_x(available_bounds.right() - |
| 816 shelf_width); | 815 shelf_width); |
| 817 } | 816 } |
| 818 | 817 |
| 819 if (right_aligned) { | 818 if (right_aligned) { |
| 820 target_bounds->status_bounds_in_shelf.set_x(0); | 819 target_bounds->status_bounds_in_shelf.set_x(0); |
| 821 } else { | 820 } else { |
| 822 target_bounds->status_bounds_in_shelf.set_x( | 821 target_bounds->status_bounds_in_shelf.set_x( |
| 823 target_bounds->shelf_bounds_in_root.width() - | 822 target_bounds->shelf_bounds_in_root.width() - kShelfSize); |
| 824 GetShelfConstant(SHELF_SIZE)); | |
| 825 } | 823 } |
| 826 } | 824 } |
| 827 } | 825 } |
| 828 | 826 |
| 829 void ShelfLayoutManager::MaybeUpdateShelfBackground(AnimationChangeType type) { | 827 void ShelfLayoutManager::MaybeUpdateShelfBackground(AnimationChangeType type) { |
| 830 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); | 828 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); |
| 831 | 829 |
| 832 if (new_background_type == shelf_background_type_) | 830 if (new_background_type == shelf_background_type_) |
| 833 return; | 831 return; |
| 834 | 832 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 968 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
| 971 WmWindow* status_window = | 969 WmWindow* status_window = |
| 972 WmWindow::Get(shelf_widget_->status_area_widget()->GetNativeWindow()); | 970 WmWindow::Get(shelf_widget_->status_area_widget()->GetNativeWindow()); |
| 973 return (shelf_window && shelf_window->Contains(window)) || | 971 return (shelf_window && shelf_window->Contains(window)) || |
| 974 (status_window && status_window->Contains(window)); | 972 (status_window && status_window->Contains(window)); |
| 975 } | 973 } |
| 976 | 974 |
| 977 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { | 975 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { |
| 978 if (state.visibility_state == SHELF_VISIBLE) | 976 if (state.visibility_state == SHELF_VISIBLE) |
| 979 return size; | 977 return size; |
| 980 if (state.visibility_state == SHELF_AUTO_HIDE) | |
| 981 return GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | |
| 982 return 0; | 978 return 0; |
| 983 } | 979 } |
| 984 | 980 |
| 985 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { | 981 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { |
| 986 if (event == EVENT_LOCK_ANIMATION_STARTED) { | 982 if (event == EVENT_LOCK_ANIMATION_STARTED) { |
| 987 // Enter the screen locked state and update the visibility to avoid an odd | 983 // Enter the screen locked state and update the visibility to avoid an odd |
| 988 // animation when transitioning the orientation from L/R to bottom. | 984 // animation when transitioning the orientation from L/R to bottom. |
| 989 state_.pre_lock_screen_animation_active = true; | 985 state_.pre_lock_screen_animation_active = true; |
| 990 UpdateShelfVisibilityAfterLoginUIChange(); | 986 UpdateShelfVisibilityAfterLoginUIChange(); |
| 991 } else { | 987 } else { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1135 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1140 } | 1136 } |
| 1141 | 1137 |
| 1142 void ShelfLayoutManager::CancelGestureDrag() { | 1138 void ShelfLayoutManager::CancelGestureDrag() { |
| 1143 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1139 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1144 UpdateVisibilityState(); | 1140 UpdateVisibilityState(); |
| 1145 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1141 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1146 } | 1142 } |
| 1147 | 1143 |
| 1148 } // namespace ash | 1144 } // namespace ash |
| OLD | NEW |