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

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

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

Powered by Google App Engine
This is Rietveld 408576698