| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // auto hidden shelf. The region is used to make it easier to trigger showing | 80 // auto hidden shelf. The region is used to make it easier to trigger showing |
| 81 // the auto hidden shelf when the shelf is on the boundary between displays. | 81 // the auto hidden shelf when the shelf is on the boundary between displays. |
| 82 const int kMaxAutoHideShowShelfRegionSize = 10; | 82 const int kMaxAutoHideShowShelfRegionSize = 10; |
| 83 | 83 |
| 84 ui::Layer* GetLayer(views::Widget* widget) { | 84 ui::Layer* GetLayer(views::Widget* widget) { |
| 85 return widget->GetNativeView()->layer(); | 85 return widget->GetNativeView()->layer(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 // static | |
| 91 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | |
| 92 | |
| 93 // static | |
| 94 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | |
| 95 | |
| 96 // static | |
| 97 const int ShelfLayoutManager::kAutoHideSize = 3; | |
| 98 | |
| 99 // static | |
| 100 const int ShelfLayoutManager::kShelfItemInset = 3; | |
| 101 | |
| 102 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 90 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| 103 | 91 |
| 104 // Notifies ShelfLayoutManager any time the mouse moves. Not used on mash. | 92 // Notifies ShelfLayoutManager any time the mouse moves. Not used on mash. |
| 105 // TODO(jamescook): Delete this once the mash implementation handles drags on | 93 // TODO(jamescook): Delete this once the mash implementation handles drags on |
| 106 // and off the shelf. | 94 // and off the shelf. |
| 107 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 95 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| 108 public: | 96 public: |
| 109 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); | 97 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| 110 ~AutoHideEventFilter() override; | 98 ~AutoHideEventFilter() override; |
| 111 | 99 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 bool ShelfLayoutManager::IsVisible() const { | 260 bool ShelfLayoutManager::IsVisible() const { |
| 273 // status_area_widget() may be NULL during the shutdown. | 261 // status_area_widget() may be NULL during the shutdown. |
| 274 return shelf_widget_->status_area_widget() && | 262 return shelf_widget_->status_area_widget() && |
| 275 shelf_widget_->status_area_widget()->IsVisible() && | 263 shelf_widget_->status_area_widget()->IsVisible() && |
| 276 (state_.visibility_state == SHELF_VISIBLE || | 264 (state_.visibility_state == SHELF_VISIBLE || |
| 277 (state_.visibility_state == SHELF_AUTO_HIDE && | 265 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 278 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 266 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 279 } | 267 } |
| 280 | 268 |
| 281 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 269 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 270 const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| 282 gfx::Rect rect( | 271 gfx::Rect rect( |
| 283 ScreenUtil::GetDisplayBoundsInParent(shelf_widget_->GetNativeView())); | 272 ScreenUtil::GetDisplayBoundsInParent(shelf_widget_->GetNativeView())); |
| 284 return SelectValueForShelfAlignment( | 273 return SelectValueForShelfAlignment( |
| 285 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), | 274 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), |
| 286 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), | 275 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), |
| 287 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, | 276 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, |
| 288 rect.height())); | 277 rect.height())); |
| 289 } | 278 } |
| 290 | 279 |
| 291 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 280 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| 292 TargetBounds target_bounds; | 281 TargetBounds target_bounds; |
| 293 CalculateTargetBounds(state_, &target_bounds); | 282 CalculateTargetBounds(state_, &target_bounds); |
| 294 return target_bounds.shelf_bounds_in_root.size(); | 283 return target_bounds.shelf_bounds_in_root.size(); |
| 295 } | 284 } |
| 296 | 285 |
| 297 void ShelfLayoutManager::LayoutShelf() { | 286 void ShelfLayoutManager::LayoutShelf() { |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 shelf_widget_->status_area_widget()->Show(); | 760 shelf_widget_->status_area_widget()->Show(); |
| 772 } | 761 } |
| 773 | 762 |
| 774 void ShelfLayoutManager::StopAnimating() { | 763 void ShelfLayoutManager::StopAnimating() { |
| 775 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating(); | 764 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating(); |
| 776 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating(); | 765 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 777 } | 766 } |
| 778 | 767 |
| 779 void ShelfLayoutManager::CalculateTargetBounds(const State& state, | 768 void ShelfLayoutManager::CalculateTargetBounds(const State& state, |
| 780 TargetBounds* target_bounds) { | 769 TargetBounds* target_bounds) { |
| 781 int shelf_size = kShelfSize; | 770 int shelf_size = GetShelfConstant(SHELF_SIZE); |
| 782 if (state.visibility_state == SHELF_AUTO_HIDE && | 771 if (state.visibility_state == SHELF_AUTO_HIDE && |
| 783 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 772 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 784 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 773 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
| 785 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 774 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
| 786 // takes care of setting the height properly. | 775 // takes care of setting the height properly. |
| 787 shelf_size = kAutoHideSize; | 776 shelf_size = kShelfAutoHideSize; |
| 788 } else if (state.visibility_state == SHELF_HIDDEN || | 777 } else if (state.visibility_state == SHELF_HIDDEN || |
| 789 (!keyboard_bounds_.IsEmpty() && | 778 (!keyboard_bounds_.IsEmpty() && |
| 790 !keyboard::IsKeyboardOverscrollEnabled())) { | 779 !keyboard::IsKeyboardOverscrollEnabled())) { |
| 791 shelf_size = 0; | 780 shelf_size = 0; |
| 792 } | 781 } |
| 793 | 782 |
| 794 gfx::Rect available_bounds = | 783 gfx::Rect available_bounds = |
| 795 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); | 784 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); |
| 796 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); | 785 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); |
| 797 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); | 786 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); |
| 798 int bottom_shelf_vertical_offset = available_bounds.bottom(); | 787 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
| 799 if (keyboard_bounds_.IsEmpty()) | 788 if (keyboard_bounds_.IsEmpty()) |
| 800 bottom_shelf_vertical_offset -= shelf_height; | 789 bottom_shelf_vertical_offset -= shelf_height; |
| 801 else | 790 else |
| 802 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); | 791 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); |
| 803 | 792 |
| 804 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 793 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
| 805 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), | 794 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), |
| 806 gfx::Point(available_bounds.x(), available_bounds.y()), | 795 gfx::Point(available_bounds.x(), available_bounds.y()), |
| 807 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); | 796 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); |
| 808 target_bounds->shelf_bounds_in_root = | 797 target_bounds->shelf_bounds_in_root = |
| 809 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); | 798 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); |
| 810 | 799 |
| 811 gfx::Size status_size( | 800 gfx::Size status_size( |
| 812 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); | 801 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 813 if (IsHorizontalAlignment()) | 802 if (IsHorizontalAlignment()) |
| 814 status_size.set_height(kShelfSize); | 803 status_size.set_height(GetShelfConstant(SHELF_SIZE)); |
| 815 else | 804 else |
| 816 status_size.set_width(kShelfSize); | 805 status_size.set_width(GetShelfConstant(SHELF_SIZE)); |
| 817 | 806 |
| 818 gfx::Point status_origin = SelectValueForShelfAlignment( | 807 gfx::Point status_origin = SelectValueForShelfAlignment( |
| 819 gfx::Point(0, 0), | 808 gfx::Point(0, 0), |
| 820 gfx::Point(shelf_width - status_size.width(), | 809 gfx::Point(shelf_width - status_size.width(), |
| 821 shelf_height - status_size.height()), | 810 shelf_height - status_size.height()), |
| 822 gfx::Point(0, shelf_height - status_size.height())); | 811 gfx::Point(0, shelf_height - status_size.height())); |
| 823 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) | 812 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) |
| 824 status_origin.set_x(shelf_width - status_size.width()); | 813 status_origin.set_x(shelf_width - status_size.width()); |
| 825 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); | 814 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); |
| 826 | 815 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); | 879 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); |
| 891 int resistance_free_region = 0; | 880 int resistance_free_region = 0; |
| 892 | 881 |
| 893 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 882 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 894 visibility_state() == SHELF_AUTO_HIDE && | 883 visibility_state() == SHELF_AUTO_HIDE && |
| 895 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 884 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 896 // If the shelf was hidden when the drag started (and the state hasn't | 885 // If the shelf was hidden when the drag started (and the state hasn't |
| 897 // changed since then, e.g. because the tray-menu was shown because of the | 886 // changed since then, e.g. because the tray-menu was shown because of the |
| 898 // drag), then allow the drag some resistance-free region at first to make | 887 // drag), then allow the drag some resistance-free region at first to make |
| 899 // sure the shelf sticks with the finger until the shelf is visible. | 888 // sure the shelf sticks with the finger until the shelf is visible. |
| 900 resistance_free_region = kShelfSize - kAutoHideSize; | 889 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize; |
| 901 } | 890 } |
| 902 | 891 |
| 903 bool resist = SelectValueForShelfAlignment( | 892 bool resist = SelectValueForShelfAlignment( |
| 904 gesture_drag_amount_ < -resistance_free_region, | 893 gesture_drag_amount_ < -resistance_free_region, |
| 905 gesture_drag_amount_ > resistance_free_region, | 894 gesture_drag_amount_ > resistance_free_region, |
| 906 gesture_drag_amount_ < -resistance_free_region); | 895 gesture_drag_amount_ < -resistance_free_region); |
| 907 | 896 |
| 908 float translate = 0.f; | 897 float translate = 0.f; |
| 909 if (resist) { | 898 if (resist) { |
| 910 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 899 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| 911 diff = std::min(diff, sqrtf(diff)); | 900 diff = std::min(diff, sqrtf(diff)); |
| 912 if (gesture_drag_amount_ < 0) | 901 if (gesture_drag_amount_ < 0) |
| 913 translate = -resistance_free_region - diff; | 902 translate = -resistance_free_region - diff; |
| 914 else | 903 else |
| 915 translate = resistance_free_region + diff; | 904 translate = resistance_free_region + diff; |
| 916 } else { | 905 } else { |
| 917 translate = gesture_drag_amount_; | 906 translate = gesture_drag_amount_; |
| 918 } | 907 } |
| 919 | 908 |
| 920 if (horizontal) { | 909 if (horizontal) { |
| 921 // Move and size the shelf with the gesture. | 910 // Move and size the shelf with the gesture. |
| 922 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 911 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 923 shelf_height = std::max(shelf_height, kAutoHideSize); | 912 shelf_height = std::max(shelf_height, kShelfAutoHideSize); |
| 924 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 913 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
| 925 if (IsHorizontalAlignment()) { | 914 if (IsHorizontalAlignment()) { |
| 926 target_bounds->shelf_bounds_in_root.set_y( | 915 target_bounds->shelf_bounds_in_root.set_y( |
| 927 available_bounds.bottom() - shelf_height); | 916 available_bounds.bottom() - shelf_height); |
| 928 } | 917 } |
| 929 | 918 |
| 930 target_bounds->status_bounds_in_shelf.set_y(0); | 919 target_bounds->status_bounds_in_shelf.set_y(0); |
| 931 } else { | 920 } else { |
| 932 // Move and size the shelf with the gesture. | 921 // Move and size the shelf with the gesture. |
| 933 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 922 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
| 934 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 923 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
| 935 if (right_aligned) | 924 if (right_aligned) |
| 936 shelf_width -= translate; | 925 shelf_width -= translate; |
| 937 else | 926 else |
| 938 shelf_width += translate; | 927 shelf_width += translate; |
| 939 shelf_width = std::max(shelf_width, kAutoHideSize); | 928 shelf_width = std::max(shelf_width, kShelfAutoHideSize); |
| 940 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 929 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
| 941 if (right_aligned) { | 930 if (right_aligned) { |
| 942 target_bounds->shelf_bounds_in_root.set_x( | 931 target_bounds->shelf_bounds_in_root.set_x( |
| 943 available_bounds.right() - shelf_width); | 932 available_bounds.right() - shelf_width); |
| 944 } | 933 } |
| 945 | 934 |
| 946 if (right_aligned) | 935 if (right_aligned) { |
| 947 target_bounds->status_bounds_in_shelf.set_x(0); | 936 target_bounds->status_bounds_in_shelf.set_x(0); |
| 948 else | 937 } else { |
| 949 target_bounds->status_bounds_in_shelf.set_x( | 938 target_bounds->status_bounds_in_shelf.set_x( |
| 950 target_bounds->shelf_bounds_in_root.width() - | 939 target_bounds->shelf_bounds_in_root.width() - |
| 951 kShelfSize); | 940 GetShelfConstant(SHELF_SIZE)); |
| 941 } |
| 952 } | 942 } |
| 953 } | 943 } |
| 954 | 944 |
| 955 void ShelfLayoutManager::UpdateShelfBackground( | 945 void ShelfLayoutManager::UpdateShelfBackground( |
| 956 BackgroundAnimatorChangeType type) { | 946 BackgroundAnimatorChangeType type) { |
| 957 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 947 const ShelfBackgroundType background_type(GetShelfBackgroundType()); |
| 958 shelf_widget_->SetPaintsBackground(background_type, type); | 948 shelf_widget_->SetPaintsBackground(background_type, type); |
| 959 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 949 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 960 OnBackgroundUpdated(background_type, type)); | 950 OnBackgroundUpdated(background_type, type)); |
| 961 } | 951 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 shelf_widget_->GetNativeWindow()->Contains(window)) || | 1113 shelf_widget_->GetNativeWindow()->Contains(window)) || |
| 1124 (shelf_widget_->status_area_widget() && | 1114 (shelf_widget_->status_area_widget() && |
| 1125 shelf_widget_->status_area_widget()->GetNativeWindow()->Contains( | 1115 shelf_widget_->status_area_widget()->GetNativeWindow()->Contains( |
| 1126 window)); | 1116 window)); |
| 1127 } | 1117 } |
| 1128 | 1118 |
| 1129 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 1119 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
| 1130 if (state.visibility_state == SHELF_VISIBLE) | 1120 if (state.visibility_state == SHELF_VISIBLE) |
| 1131 return size; | 1121 return size; |
| 1132 if (state.visibility_state == SHELF_AUTO_HIDE) | 1122 if (state.visibility_state == SHELF_AUTO_HIDE) |
| 1133 return kAutoHideSize; | 1123 return kShelfAutoHideSize; |
| 1134 return 0; | 1124 return 0; |
| 1135 } | 1125 } |
| 1136 | 1126 |
| 1137 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 1127 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 1138 bool keyboard_is_about_to_hide = false; | 1128 bool keyboard_is_about_to_hide = false; |
| 1139 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 1129 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
| 1140 keyboard_is_about_to_hide = true; | 1130 keyboard_is_about_to_hide = true; |
| 1141 | 1131 |
| 1142 keyboard_bounds_ = new_bounds; | 1132 keyboard_bounds_ = new_bounds; |
| 1143 OnWindowResized(); | 1133 OnWindowResized(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1182 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
| 1193 UpdateVisibilityState(); | 1183 UpdateVisibilityState(); |
| 1194 } | 1184 } |
| 1195 | 1185 |
| 1196 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1186 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1197 UpdateVisibilityState(); | 1187 UpdateVisibilityState(); |
| 1198 LayoutShelf(); | 1188 LayoutShelf(); |
| 1199 } | 1189 } |
| 1200 | 1190 |
| 1201 } // namespace ash | 1191 } // namespace ash |
| OLD | NEW |