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 <cstring> | 9 #include <cstring> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // auto hidden shelf. The region is used to make it easier to trigger showing | 79 // auto hidden shelf. The region is used to make it easier to trigger showing |
| 80 // the auto hidden shelf when the shelf is on the boundary between displays. | 80 // the auto hidden shelf when the shelf is on the boundary between displays. |
| 81 const int kMaxAutoHideShowShelfRegionSize = 10; | 81 const int kMaxAutoHideShowShelfRegionSize = 10; |
| 82 | 82 |
| 83 ui::Layer* GetLayer(views::Widget* widget) { | 83 ui::Layer* GetLayer(views::Widget* widget) { |
| 84 return widget->GetNativeView()->layer(); | 84 return widget->GetNativeView()->layer(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 // static | |
| 90 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | |
| 91 | |
| 92 // static | |
| 93 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | |
| 94 | |
| 95 // static | |
| 96 const int ShelfLayoutManager::kAutoHideSize = 3; | |
| 97 | |
| 98 // static | |
| 99 const int ShelfLayoutManager::kShelfItemInset = 3; | |
| 100 | |
| 101 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 89 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| 102 | 90 |
| 103 // Notifies ShelfLayoutManager any time the mouse moves. | 91 // Notifies ShelfLayoutManager any time the mouse moves. |
| 104 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 92 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| 105 public: | 93 public: |
| 106 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); | 94 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| 107 ~AutoHideEventFilter() override; | 95 ~AutoHideEventFilter() override; |
| 108 | 96 |
| 109 // Returns true if the last mouse event was a mouse drag. | 97 // Returns true if the last mouse event was a mouse drag. |
| 110 bool in_mouse_drag() const { return in_mouse_drag_; } | 98 bool in_mouse_drag() const { return in_mouse_drag_; } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 return shelf_->status_area_widget() && | 264 return shelf_->status_area_widget() && |
| 277 shelf_->status_area_widget()->IsVisible() && | 265 shelf_->status_area_widget()->IsVisible() && |
| 278 (state_.visibility_state == SHELF_VISIBLE || | 266 (state_.visibility_state == SHELF_VISIBLE || |
| 279 (state_.visibility_state == SHELF_AUTO_HIDE && | 267 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 280 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 268 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 281 } | 269 } |
| 282 | 270 |
| 283 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 271 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 284 gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView())); | 272 gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView())); |
| 285 return SelectValueForShelfAlignment( | 273 return SelectValueForShelfAlignment( |
| 286 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), | 274 gfx::Rect(rect.x(), rect.bottom() - GetShelfLayoutConstant(SHELF_SIZE), |
|
tdanderson
2016/06/03 19:25:23
nit: use const int shelf_size = GetShelfLayoutCons
yiyix
2016/06/10 19:26:04
Done.
| |
| 287 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), | 275 rect.width(), GetShelfLayoutConstant(SHELF_SIZE)), |
| 288 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, | 276 gfx::Rect(rect.x(), rect.y(), GetShelfLayoutConstant(SHELF_SIZE), |
| 289 rect.height())); | 277 rect.height()), |
| 278 gfx::Rect(rect.right() - GetShelfLayoutConstant(SHELF_SIZE), rect.y(), | |
| 279 GetShelfLayoutConstant(SHELF_SIZE), rect.height())); | |
| 290 } | 280 } |
| 291 | 281 |
| 292 void ShelfLayoutManager::LayoutShelf() { | 282 void ShelfLayoutManager::LayoutShelf() { |
| 293 TargetBounds target_bounds; | 283 TargetBounds target_bounds; |
| 294 CalculateTargetBounds(state_, &target_bounds); | 284 CalculateTargetBounds(state_, &target_bounds); |
| 295 UpdateBoundsAndOpacity(target_bounds, false, NULL); | 285 UpdateBoundsAndOpacity(target_bounds, false, NULL); |
| 296 | 286 |
| 297 // Update insets in ShelfWindowTargeter when shelf bounds change. | 287 // Update insets in ShelfWindowTargeter when shelf bounds change. |
| 298 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 288 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 299 WillChangeVisibilityState(visibility_state())); | 289 WillChangeVisibilityState(visibility_state())); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 shelf_->status_area_widget()->Show(); | 720 shelf_->status_area_widget()->Show(); |
| 731 } | 721 } |
| 732 | 722 |
| 733 void ShelfLayoutManager::StopAnimating() { | 723 void ShelfLayoutManager::StopAnimating() { |
| 734 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 724 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 735 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 725 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 736 } | 726 } |
| 737 | 727 |
| 738 void ShelfLayoutManager::CalculateTargetBounds(const State& state, | 728 void ShelfLayoutManager::CalculateTargetBounds(const State& state, |
| 739 TargetBounds* target_bounds) { | 729 TargetBounds* target_bounds) { |
| 740 int shelf_size = kShelfSize; | 730 int shelf_size = GetShelfLayoutConstant(SHELF_SIZE); |
| 741 if (state.visibility_state == SHELF_AUTO_HIDE && | 731 if (state.visibility_state == SHELF_AUTO_HIDE && |
| 742 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 732 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 743 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 733 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
| 744 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 734 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
| 745 // takes care of setting the height properly. | 735 // takes care of setting the height properly. |
| 746 shelf_size = kAutoHideSize; | 736 shelf_size = kAutoHideSize; |
| 747 } else if (state.visibility_state == SHELF_HIDDEN || | 737 } else if (state.visibility_state == SHELF_HIDDEN || |
| 748 (!keyboard_bounds_.IsEmpty() && | 738 (!keyboard_bounds_.IsEmpty() && |
| 749 !keyboard::IsKeyboardOverscrollEnabled())) { | 739 !keyboard::IsKeyboardOverscrollEnabled())) { |
| 750 shelf_size = 0; | 740 shelf_size = 0; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 763 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 753 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
| 764 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), | 754 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), |
| 765 gfx::Point(available_bounds.x(), available_bounds.y()), | 755 gfx::Point(available_bounds.x(), available_bounds.y()), |
| 766 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); | 756 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); |
| 767 target_bounds->shelf_bounds_in_root = | 757 target_bounds->shelf_bounds_in_root = |
| 768 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); | 758 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); |
| 769 | 759 |
| 770 gfx::Size status_size( | 760 gfx::Size status_size( |
| 771 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 761 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 772 if (IsHorizontalAlignment()) | 762 if (IsHorizontalAlignment()) |
| 773 status_size.set_height(kShelfSize); | 763 status_size.set_height(GetShelfLayoutConstant(SHELF_SIZE)); |
| 774 else | 764 else |
| 775 status_size.set_width(kShelfSize); | 765 status_size.set_width(GetShelfLayoutConstant(SHELF_SIZE)); |
| 776 | 766 |
| 777 gfx::Point status_origin = SelectValueForShelfAlignment( | 767 gfx::Point status_origin = SelectValueForShelfAlignment( |
| 778 gfx::Point(0, 0), | 768 gfx::Point(0, 0), |
| 779 gfx::Point(shelf_width - status_size.width(), | 769 gfx::Point(shelf_width - status_size.width(), |
| 780 shelf_height - status_size.height()), | 770 shelf_height - status_size.height()), |
| 781 gfx::Point(0, shelf_height - status_size.height())); | 771 gfx::Point(0, shelf_height - status_size.height())); |
| 782 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) | 772 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) |
| 783 status_origin.set_x(shelf_width - status_size.width()); | 773 status_origin.set_x(shelf_width - status_size.width()); |
| 784 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); | 774 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); |
| 785 | 775 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); | 839 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); |
| 850 int resistance_free_region = 0; | 840 int resistance_free_region = 0; |
| 851 | 841 |
| 852 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 842 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 853 visibility_state() == SHELF_AUTO_HIDE && | 843 visibility_state() == SHELF_AUTO_HIDE && |
| 854 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 844 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 855 // If the shelf was hidden when the drag started (and the state hasn't | 845 // If the shelf was hidden when the drag started (and the state hasn't |
| 856 // changed since then, e.g. because the tray-menu was shown because of the | 846 // changed since then, e.g. because the tray-menu was shown because of the |
| 857 // drag), then allow the drag some resistance-free region at first to make | 847 // drag), then allow the drag some resistance-free region at first to make |
| 858 // sure the shelf sticks with the finger until the shelf is visible. | 848 // sure the shelf sticks with the finger until the shelf is visible. |
| 859 resistance_free_region = kShelfSize - kAutoHideSize; | 849 resistance_free_region = GetShelfLayoutConstant(SHELF_SIZE) - kAutoHideSize; |
| 860 } | 850 } |
| 861 | 851 |
| 862 bool resist = SelectValueForShelfAlignment( | 852 bool resist = SelectValueForShelfAlignment( |
| 863 gesture_drag_amount_ < -resistance_free_region, | 853 gesture_drag_amount_ < -resistance_free_region, |
| 864 gesture_drag_amount_ > resistance_free_region, | 854 gesture_drag_amount_ > resistance_free_region, |
| 865 gesture_drag_amount_ < -resistance_free_region); | 855 gesture_drag_amount_ < -resistance_free_region); |
| 866 | 856 |
| 867 float translate = 0.f; | 857 float translate = 0.f; |
| 868 if (resist) { | 858 if (resist) { |
| 869 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 859 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 900 if (right_aligned) { | 890 if (right_aligned) { |
| 901 target_bounds->shelf_bounds_in_root.set_x( | 891 target_bounds->shelf_bounds_in_root.set_x( |
| 902 available_bounds.right() - shelf_width); | 892 available_bounds.right() - shelf_width); |
| 903 } | 893 } |
| 904 | 894 |
| 905 if (right_aligned) | 895 if (right_aligned) |
| 906 target_bounds->status_bounds_in_shelf.set_x(0); | 896 target_bounds->status_bounds_in_shelf.set_x(0); |
| 907 else | 897 else |
| 908 target_bounds->status_bounds_in_shelf.set_x( | 898 target_bounds->status_bounds_in_shelf.set_x( |
| 909 target_bounds->shelf_bounds_in_root.width() - | 899 target_bounds->shelf_bounds_in_root.width() - |
| 910 kShelfSize); | 900 GetShelfLayoutConstant(SHELF_SIZE)); |
|
tdanderson
2016/06/03 19:25:23
I know you didn't add this if/else, but since the
yiyix
2016/06/10 19:26:04
Done.
| |
| 911 } | 901 } |
| 912 } | 902 } |
| 913 | 903 |
| 914 void ShelfLayoutManager::UpdateShelfBackground( | 904 void ShelfLayoutManager::UpdateShelfBackground( |
| 915 BackgroundAnimatorChangeType type) { | 905 BackgroundAnimatorChangeType type) { |
| 916 const wm::ShelfBackgroundType background_type(GetShelfBackgroundType()); | 906 const wm::ShelfBackgroundType background_type(GetShelfBackgroundType()); |
| 917 shelf_->SetPaintsBackground(background_type, type); | 907 shelf_->SetPaintsBackground(background_type, type); |
| 918 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 908 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 919 OnBackgroundUpdated(background_type, type)); | 909 OnBackgroundUpdated(background_type, type)); |
| 920 } | 910 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1135 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
| 1146 UpdateVisibilityState(); | 1136 UpdateVisibilityState(); |
| 1147 } | 1137 } |
| 1148 | 1138 |
| 1149 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1139 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1150 UpdateVisibilityState(); | 1140 UpdateVisibilityState(); |
| 1151 LayoutShelf(); | 1141 LayoutShelf(); |
| 1152 } | 1142 } |
| 1153 | 1143 |
| 1154 } // namespace ash | 1144 } // namespace ash |
| OLD | NEW |