Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: ash/shelf/shelf_layout_manager.cc

Issue 1998933002: Update shelf spacing in Chrome OS according to the MD specs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // auto hidden shelf. The region is used to make it easier to trigger showing 81 // auto hidden shelf. The region is used to make it easier to trigger showing
82 // the auto hidden shelf when the shelf is on the boundary between displays. 82 // the auto hidden shelf when the shelf is on the boundary between displays.
83 const int kMaxAutoHideShowShelfRegionSize = 10; 83 const int kMaxAutoHideShowShelfRegionSize = 10;
84 84
85 ui::Layer* GetLayer(views::Widget* widget) { 85 ui::Layer* GetLayer(views::Widget* widget) {
86 return widget->GetNativeView()->layer(); 86 return widget->GetNativeView()->layer();
87 } 87 }
88 88
89 } // namespace 89 } // namespace
90 90
91 // static
92 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2;
93
94 // static
95 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5;
96
97 // static
98 const int ShelfLayoutManager::kAutoHideSize = 3;
99
100 // static
101 const int ShelfLayoutManager::kShelfItemInset = 3;
102
103 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- 91 // ShelfLayoutManager::AutoHideEventFilter -------------------------------------
104 92
105 // Notifies ShelfLayoutManager any time the mouse moves. Not used on mash. 93 // Notifies ShelfLayoutManager any time the mouse moves. Not used on mash.
106 // TODO(jamescook): Delete this once the mash implementation handles drags on 94 // TODO(jamescook): Delete this once the mash implementation handles drags on
107 // and off the shelf. 95 // and off the shelf.
108 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { 96 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler {
109 public: 97 public:
110 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); 98 explicit AutoHideEventFilter(ShelfLayoutManager* shelf);
111 ~AutoHideEventFilter() override; 99 ~AutoHideEventFilter() override;
112 100
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 bool ShelfLayoutManager::IsVisible() const { 261 bool ShelfLayoutManager::IsVisible() const {
274 // status_area_widget() may be NULL during the shutdown. 262 // status_area_widget() may be NULL during the shutdown.
275 return shelf_widget_->status_area_widget() && 263 return shelf_widget_->status_area_widget() &&
276 shelf_widget_->status_area_widget()->IsVisible() && 264 shelf_widget_->status_area_widget()->IsVisible() &&
277 (state_.visibility_state == SHELF_VISIBLE || 265 (state_.visibility_state == SHELF_VISIBLE ||
278 (state_.visibility_state == SHELF_AUTO_HIDE && 266 (state_.visibility_state == SHELF_AUTO_HIDE &&
279 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); 267 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN));
280 } 268 }
281 269
282 gfx::Rect ShelfLayoutManager::GetIdealBounds() { 270 gfx::Rect ShelfLayoutManager::GetIdealBounds() {
271 int shelf_size = GetShelfConstant(SHELF_SIZE);
tdanderson 2016/06/10 22:54:43 nit: const
yiyix 2016/06/13 18:43:54 Done.
283 gfx::Rect rect( 272 gfx::Rect rect(
284 ScreenUtil::GetDisplayBoundsInParent(shelf_widget_->GetNativeView())); 273 ScreenUtil::GetDisplayBoundsInParent(shelf_widget_->GetNativeView()));
285 return SelectValueForShelfAlignment( 274 return SelectValueForShelfAlignment(
286 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), 275 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size),
287 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), 276 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()),
288 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, 277 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size,
289 rect.height())); 278 rect.height()));
290 } 279 }
291 280
292 gfx::Size ShelfLayoutManager::GetPreferredSize() { 281 gfx::Size ShelfLayoutManager::GetPreferredSize() {
293 TargetBounds target_bounds; 282 TargetBounds target_bounds;
294 CalculateTargetBounds(state_, &target_bounds); 283 CalculateTargetBounds(state_, &target_bounds);
295 return target_bounds.shelf_bounds_in_root.size(); 284 return target_bounds.shelf_bounds_in_root.size();
296 } 285 }
297 286
298 void ShelfLayoutManager::LayoutShelf() { 287 void ShelfLayoutManager::LayoutShelf() {
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 shelf_widget_->status_area_widget()->Show(); 772 shelf_widget_->status_area_widget()->Show();
784 } 773 }
785 774
786 void ShelfLayoutManager::StopAnimating() { 775 void ShelfLayoutManager::StopAnimating() {
787 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating(); 776 GetLayer(shelf_widget_)->GetAnimator()->StopAnimating();
788 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating(); 777 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()->StopAnimating();
789 } 778 }
790 779
791 void ShelfLayoutManager::CalculateTargetBounds(const State& state, 780 void ShelfLayoutManager::CalculateTargetBounds(const State& state,
792 TargetBounds* target_bounds) { 781 TargetBounds* target_bounds) {
793 int shelf_size = kShelfSize; 782 int shelf_size = GetShelfConstant(SHELF_SIZE);
794 if (state.visibility_state == SHELF_AUTO_HIDE && 783 if (state.visibility_state == SHELF_AUTO_HIDE &&
795 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 784 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
796 // Auto-hidden shelf always starts with the default size. If a gesture-drag 785 // Auto-hidden shelf always starts with the default size. If a gesture-drag
797 // is in progress, then the call to UpdateTargetBoundsForGesture() below 786 // is in progress, then the call to UpdateTargetBoundsForGesture() below
798 // takes care of setting the height properly. 787 // takes care of setting the height properly.
799 shelf_size = kAutoHideSize; 788 shelf_size = kShelfAutoHideSize;
800 } else if (state.visibility_state == SHELF_HIDDEN || 789 } else if (state.visibility_state == SHELF_HIDDEN ||
801 (!keyboard_bounds_.IsEmpty() && 790 (!keyboard_bounds_.IsEmpty() &&
802 !keyboard::IsKeyboardOverscrollEnabled())) { 791 !keyboard::IsKeyboardOverscrollEnabled())) {
803 shelf_size = 0; 792 shelf_size = 0;
804 } 793 }
805 794
806 gfx::Rect available_bounds = 795 gfx::Rect available_bounds =
807 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); 796 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_);
808 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); 797 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size);
809 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); 798 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height());
810 int bottom_shelf_vertical_offset = available_bounds.bottom(); 799 int bottom_shelf_vertical_offset = available_bounds.bottom();
811 if (keyboard_bounds_.IsEmpty()) 800 if (keyboard_bounds_.IsEmpty())
812 bottom_shelf_vertical_offset -= shelf_height; 801 bottom_shelf_vertical_offset -= shelf_height;
813 else 802 else
814 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); 803 bottom_shelf_vertical_offset -= keyboard_bounds_.height();
815 804
816 gfx::Point shelf_origin = SelectValueForShelfAlignment( 805 gfx::Point shelf_origin = SelectValueForShelfAlignment(
817 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), 806 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset),
818 gfx::Point(available_bounds.x(), available_bounds.y()), 807 gfx::Point(available_bounds.x(), available_bounds.y()),
819 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); 808 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y()));
820 target_bounds->shelf_bounds_in_root = 809 target_bounds->shelf_bounds_in_root =
821 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); 810 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height);
822 811
823 gfx::Size status_size( 812 gfx::Size status_size(
824 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); 813 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size());
825 if (IsHorizontalAlignment()) 814 if (IsHorizontalAlignment())
826 status_size.set_height(kShelfSize); 815 status_size.set_height(GetShelfConstant(SHELF_SIZE));
827 else 816 else
828 status_size.set_width(kShelfSize); 817 status_size.set_width(GetShelfConstant(SHELF_SIZE));
829 818
830 gfx::Point status_origin = SelectValueForShelfAlignment( 819 gfx::Point status_origin = SelectValueForShelfAlignment(
831 gfx::Point(0, 0), 820 gfx::Point(0, 0),
832 gfx::Point(shelf_width - status_size.width(), 821 gfx::Point(shelf_width - status_size.width(),
833 shelf_height - status_size.height()), 822 shelf_height - status_size.height()),
834 gfx::Point(0, shelf_height - status_size.height())); 823 gfx::Point(0, shelf_height - status_size.height()));
835 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) 824 if (IsHorizontalAlignment() && !base::i18n::IsRTL())
836 status_origin.set_x(shelf_width - status_size.width()); 825 status_origin.set_x(shelf_width - status_size.width());
837 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); 826 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size);
838 827
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); 891 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_);
903 int resistance_free_region = 0; 892 int resistance_free_region = 0;
904 893
905 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && 894 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
906 visibility_state() == SHELF_AUTO_HIDE && 895 visibility_state() == SHELF_AUTO_HIDE &&
907 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { 896 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) {
908 // If the shelf was hidden when the drag started (and the state hasn't 897 // If the shelf was hidden when the drag started (and the state hasn't
909 // changed since then, e.g. because the tray-menu was shown because of the 898 // changed since then, e.g. because the tray-menu was shown because of the
910 // drag), then allow the drag some resistance-free region at first to make 899 // drag), then allow the drag some resistance-free region at first to make
911 // sure the shelf sticks with the finger until the shelf is visible. 900 // sure the shelf sticks with the finger until the shelf is visible.
912 resistance_free_region = kShelfSize - kAutoHideSize; 901 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize;
913 } 902 }
914 903
915 bool resist = SelectValueForShelfAlignment( 904 bool resist = SelectValueForShelfAlignment(
916 gesture_drag_amount_ < -resistance_free_region, 905 gesture_drag_amount_ < -resistance_free_region,
917 gesture_drag_amount_ > resistance_free_region, 906 gesture_drag_amount_ > resistance_free_region,
918 gesture_drag_amount_ < -resistance_free_region); 907 gesture_drag_amount_ < -resistance_free_region);
919 908
920 float translate = 0.f; 909 float translate = 0.f;
921 if (resist) { 910 if (resist) {
922 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; 911 float diff = fabsf(gesture_drag_amount_) - resistance_free_region;
923 diff = std::min(diff, sqrtf(diff)); 912 diff = std::min(diff, sqrtf(diff));
924 if (gesture_drag_amount_ < 0) 913 if (gesture_drag_amount_ < 0)
925 translate = -resistance_free_region - diff; 914 translate = -resistance_free_region - diff;
926 else 915 else
927 translate = resistance_free_region + diff; 916 translate = resistance_free_region + diff;
928 } else { 917 } else {
929 translate = gesture_drag_amount_; 918 translate = gesture_drag_amount_;
930 } 919 }
931 920
932 if (horizontal) { 921 if (horizontal) {
933 // Move and size the shelf with the gesture. 922 // Move and size the shelf with the gesture.
934 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; 923 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
935 shelf_height = std::max(shelf_height, kAutoHideSize); 924 shelf_height = std::max(shelf_height, kShelfAutoHideSize);
936 target_bounds->shelf_bounds_in_root.set_height(shelf_height); 925 target_bounds->shelf_bounds_in_root.set_height(shelf_height);
937 if (IsHorizontalAlignment()) { 926 if (IsHorizontalAlignment()) {
938 target_bounds->shelf_bounds_in_root.set_y( 927 target_bounds->shelf_bounds_in_root.set_y(
939 available_bounds.bottom() - shelf_height); 928 available_bounds.bottom() - shelf_height);
940 } 929 }
941 930
942 target_bounds->status_bounds_in_shelf.set_y(0); 931 target_bounds->status_bounds_in_shelf.set_y(0);
943 } else { 932 } else {
944 // Move and size the shelf with the gesture. 933 // Move and size the shelf with the gesture.
945 int shelf_width = target_bounds->shelf_bounds_in_root.width(); 934 int shelf_width = target_bounds->shelf_bounds_in_root.width();
946 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; 935 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT;
947 if (right_aligned) 936 if (right_aligned)
948 shelf_width -= translate; 937 shelf_width -= translate;
949 else 938 else
950 shelf_width += translate; 939 shelf_width += translate;
951 shelf_width = std::max(shelf_width, kAutoHideSize); 940 shelf_width = std::max(shelf_width, kShelfAutoHideSize);
952 target_bounds->shelf_bounds_in_root.set_width(shelf_width); 941 target_bounds->shelf_bounds_in_root.set_width(shelf_width);
953 if (right_aligned) { 942 if (right_aligned) {
954 target_bounds->shelf_bounds_in_root.set_x( 943 target_bounds->shelf_bounds_in_root.set_x(
955 available_bounds.right() - shelf_width); 944 available_bounds.right() - shelf_width);
956 } 945 }
957 946
958 if (right_aligned) 947 if (right_aligned) {
959 target_bounds->status_bounds_in_shelf.set_x(0); 948 target_bounds->status_bounds_in_shelf.set_x(0);
960 else 949 } else {
961 target_bounds->status_bounds_in_shelf.set_x( 950 target_bounds->status_bounds_in_shelf.set_x(
962 target_bounds->shelf_bounds_in_root.width() - 951 target_bounds->shelf_bounds_in_root.width() -
963 kShelfSize); 952 GetShelfConstant(SHELF_SIZE));
953 }
tdanderson 2016/06/10 22:54:43 thanks for adding the {} here!
yiyix 2016/06/13 18:43:54 :) from the previous reviews, I learnt that we nee
964 } 954 }
965 } 955 }
966 956
967 void ShelfLayoutManager::UpdateShelfBackground( 957 void ShelfLayoutManager::UpdateShelfBackground(
968 BackgroundAnimatorChangeType type) { 958 BackgroundAnimatorChangeType type) {
969 const ShelfBackgroundType background_type(GetShelfBackgroundType()); 959 const ShelfBackgroundType background_type(GetShelfBackgroundType());
970 shelf_widget_->SetPaintsBackground(background_type, type); 960 shelf_widget_->SetPaintsBackground(background_type, type);
971 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 961 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
972 OnBackgroundUpdated(background_type, type)); 962 OnBackgroundUpdated(background_type, type));
973 } 963 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 shelf_widget_->GetNativeWindow()->Contains(window)) || 1127 shelf_widget_->GetNativeWindow()->Contains(window)) ||
1138 (shelf_widget_->status_area_widget() && 1128 (shelf_widget_->status_area_widget() &&
1139 shelf_widget_->status_area_widget()->GetNativeWindow()->Contains( 1129 shelf_widget_->status_area_widget()->GetNativeWindow()->Contains(
1140 window)); 1130 window));
1141 } 1131 }
1142 1132
1143 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { 1133 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const {
1144 if (state.visibility_state == SHELF_VISIBLE) 1134 if (state.visibility_state == SHELF_VISIBLE)
1145 return size; 1135 return size;
1146 if (state.visibility_state == SHELF_AUTO_HIDE) 1136 if (state.visibility_state == SHELF_AUTO_HIDE)
1147 return kAutoHideSize; 1137 return kShelfAutoHideSize;
1148 return 0; 1138 return 0;
1149 } 1139 }
1150 1140
1151 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { 1141 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
1152 bool keyboard_is_about_to_hide = false; 1142 bool keyboard_is_about_to_hide = false;
1153 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) 1143 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty())
1154 keyboard_is_about_to_hide = true; 1144 keyboard_is_about_to_hide = true;
1155 1145
1156 keyboard_bounds_ = new_bounds; 1146 keyboard_bounds_ = new_bounds;
1157 OnWindowResized(); 1147 OnWindowResized();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 UpdateBoundsAndOpacity(target_bounds, true, NULL); 1196 UpdateBoundsAndOpacity(target_bounds, true, NULL);
1207 UpdateVisibilityState(); 1197 UpdateVisibilityState();
1208 } 1198 }
1209 1199
1210 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { 1200 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() {
1211 UpdateVisibilityState(); 1201 UpdateVisibilityState();
1212 LayoutShelf(); 1202 LayoutShelf();
1213 } 1203 }
1214 1204
1215 } // namespace ash 1205 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698