| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // static | 88 // static |
| 89 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | 89 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | 92 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 const int ShelfLayoutManager::kAutoHideSize = 3; | 95 const int ShelfLayoutManager::kAutoHideSize = 3; |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 const int ShelfLayoutManager::kShelfSize = 47; | |
| 99 | |
| 100 // static | |
| 101 const int ShelfLayoutManager::kShelfItemInset = 3; | 98 const int ShelfLayoutManager::kShelfItemInset = 3; |
| 102 | 99 |
| 103 int ShelfLayoutManager::GetPreferredShelfSize() { | |
| 104 return ash::switches::UseAlternateShelfLayout() ? | |
| 105 ShelfLayoutManager::kShelfSize : kShelfPreferredSize; | |
| 106 } | |
| 107 | |
| 108 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 100 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| 109 | 101 |
| 110 // Notifies ShelfLayoutManager any time the mouse moves. | 102 // Notifies ShelfLayoutManager any time the mouse moves. |
| 111 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 103 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| 112 public: | 104 public: |
| 113 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); | 105 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| 114 virtual ~AutoHideEventFilter(); | 106 virtual ~AutoHideEventFilter(); |
| 115 | 107 |
| 116 // Returns true if the last mouse event was a mouse drag. | 108 // Returns true if the last mouse event was a mouse drag. |
| 117 bool in_mouse_drag() const { return in_mouse_drag_; } | 109 bool in_mouse_drag() const { return in_mouse_drag_; } |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 void ShelfLayoutManager::StopAnimating() { | 691 void ShelfLayoutManager::StopAnimating() { |
| 700 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 692 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 701 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 693 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 702 } | 694 } |
| 703 | 695 |
| 704 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 696 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
| 705 *width = *height = 0; | 697 *width = *height = 0; |
| 706 gfx::Size status_size( | 698 gfx::Size status_size( |
| 707 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 699 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 708 if (IsHorizontalAlignment()) | 700 if (IsHorizontalAlignment()) |
| 709 *height = GetPreferredShelfSize(); | 701 *height = kShelfSize; |
| 710 else | 702 else |
| 711 *width = GetPreferredShelfSize(); | 703 *width = kShelfSize; |
| 712 } | 704 } |
| 713 | 705 |
| 714 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 706 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
| 715 gfx::Rect* bounds) const { | 707 gfx::Rect* bounds) const { |
| 716 bounds->Inset(SelectValueForShelfAlignment( | 708 bounds->Inset(SelectValueForShelfAlignment( |
| 717 gfx::Insets(0, 0, inset, 0), | 709 gfx::Insets(0, 0, inset, 0), |
| 718 gfx::Insets(0, inset, 0, 0), | 710 gfx::Insets(0, inset, 0, 0), |
| 719 gfx::Insets(0, 0, 0, inset), | 711 gfx::Insets(0, 0, 0, inset), |
| 720 gfx::Insets(inset, 0, 0, 0))); | 712 gfx::Insets(inset, 0, 0, 0))); |
| 721 } | 713 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( | 745 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
| 754 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, | 746 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
| 755 available_bounds.width(), shelf_height), | 747 available_bounds.width(), shelf_height), |
| 756 gfx::Rect(available_bounds.x(), available_bounds.y(), | 748 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 757 shelf_width, available_bounds.height()), | 749 shelf_width, available_bounds.height()), |
| 758 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 750 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
| 759 shelf_width, available_bounds.height()), | 751 shelf_width, available_bounds.height()), |
| 760 gfx::Rect(available_bounds.x(), available_bounds.y(), | 752 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 761 available_bounds.width(), shelf_height)); | 753 available_bounds.width(), shelf_height)); |
| 762 | 754 |
| 763 int status_inset = std::max(0, GetPreferredShelfSize() - | 755 int status_inset = 0; |
| 764 PrimaryAxisValue(status_size.height(), status_size.width())); | 756 if (IsHorizontalAlignment()) |
| 765 | 757 status_size.set_height(kShelfSize); |
| 766 if (ash::switches::UseAlternateShelfLayout()) { | 758 else |
| 767 status_inset = 0; | 759 status_size.set_width(kShelfSize); |
| 768 if (IsHorizontalAlignment()) | |
| 769 status_size.set_height(kShelfSize); | |
| 770 else | |
| 771 status_size.set_width(kShelfSize); | |
| 772 } | |
| 773 | 760 |
| 774 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( | 761 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
| 775 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 762 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 776 status_inset, status_size.width(), status_size.height()), | 763 status_inset, status_size.width(), status_size.height()), |
| 777 gfx::Rect(shelf_width - (status_size.width() + status_inset), | 764 gfx::Rect(shelf_width - (status_size.width() + status_inset), |
| 778 shelf_height - status_size.height(), status_size.width(), | 765 shelf_height - status_size.height(), status_size.width(), |
| 779 status_size.height()), | 766 status_size.height()), |
| 780 gfx::Rect(status_inset, shelf_height - status_size.height(), | 767 gfx::Rect(status_inset, shelf_height - status_size.height(), |
| 781 status_size.width(), status_size.height()), | 768 status_size.width(), status_size.height()), |
| 782 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 769 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 const gfx::Rect& available_bounds(root_window_->bounds()); | 829 const gfx::Rect& available_bounds(root_window_->bounds()); |
| 843 int resistance_free_region = 0; | 830 int resistance_free_region = 0; |
| 844 | 831 |
| 845 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 832 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 846 visibility_state() == SHELF_AUTO_HIDE && | 833 visibility_state() == SHELF_AUTO_HIDE && |
| 847 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 834 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 848 // If the shelf was hidden when the drag started (and the state hasn't | 835 // If the shelf was hidden when the drag started (and the state hasn't |
| 849 // changed since then, e.g. because the tray-menu was shown because of the | 836 // changed since then, e.g. because the tray-menu was shown because of the |
| 850 // drag), then allow the drag some resistance-free region at first to make | 837 // drag), then allow the drag some resistance-free region at first to make |
| 851 // sure the shelf sticks with the finger until the shelf is visible. | 838 // sure the shelf sticks with the finger until the shelf is visible. |
| 852 resistance_free_region = GetPreferredShelfSize() - kAutoHideSize; | 839 resistance_free_region = kShelfSize - kAutoHideSize; |
| 853 } | 840 } |
| 854 | 841 |
| 855 bool resist = SelectValueForShelfAlignment( | 842 bool resist = SelectValueForShelfAlignment( |
| 856 gesture_drag_amount_ < -resistance_free_region, | 843 gesture_drag_amount_ < -resistance_free_region, |
| 857 gesture_drag_amount_ > resistance_free_region, | 844 gesture_drag_amount_ > resistance_free_region, |
| 858 gesture_drag_amount_ < -resistance_free_region, | 845 gesture_drag_amount_ < -resistance_free_region, |
| 859 gesture_drag_amount_ > resistance_free_region); | 846 gesture_drag_amount_ > resistance_free_region); |
| 860 | 847 |
| 861 float translate = 0.f; | 848 float translate = 0.f; |
| 862 if (resist) { | 849 if (resist) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 873 if (horizontal) { | 860 if (horizontal) { |
| 874 // Move and size the shelf with the gesture. | 861 // Move and size the shelf with the gesture. |
| 875 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 862 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 876 shelf_height = std::max(shelf_height, kAutoHideSize); | 863 shelf_height = std::max(shelf_height, kAutoHideSize); |
| 877 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 864 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
| 878 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 865 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 879 target_bounds->shelf_bounds_in_root.set_y( | 866 target_bounds->shelf_bounds_in_root.set_y( |
| 880 available_bounds.bottom() - shelf_height); | 867 available_bounds.bottom() - shelf_height); |
| 881 } | 868 } |
| 882 | 869 |
| 883 if (ash::switches::UseAlternateShelfLayout()) { | 870 target_bounds->status_bounds_in_shelf.set_y(0); |
| 884 target_bounds->status_bounds_in_shelf.set_y(0); | |
| 885 } else { | |
| 886 // The statusbar should be in the center of the shelf. | |
| 887 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | |
| 888 status_y.set_y(0); | |
| 889 status_y.ClampToCenteredSize( | |
| 890 target_bounds->status_bounds_in_shelf.size()); | |
| 891 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | |
| 892 } | |
| 893 } else { | 871 } else { |
| 894 // Move and size the shelf with the gesture. | 872 // Move and size the shelf with the gesture. |
| 895 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 873 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
| 896 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 874 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
| 897 if (right_aligned) | 875 if (right_aligned) |
| 898 shelf_width -= translate; | 876 shelf_width -= translate; |
| 899 else | 877 else |
| 900 shelf_width += translate; | 878 shelf_width += translate; |
| 901 shelf_width = std::max(shelf_width, kAutoHideSize); | 879 shelf_width = std::max(shelf_width, kAutoHideSize); |
| 902 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 880 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
| 903 if (right_aligned) { | 881 if (right_aligned) { |
| 904 target_bounds->shelf_bounds_in_root.set_x( | 882 target_bounds->shelf_bounds_in_root.set_x( |
| 905 available_bounds.right() - shelf_width); | 883 available_bounds.right() - shelf_width); |
| 906 } | 884 } |
| 907 | 885 |
| 908 if (ash::switches::UseAlternateShelfLayout()) { | 886 if (right_aligned) |
| 909 if (right_aligned) | 887 target_bounds->status_bounds_in_shelf.set_x(0); |
| 910 target_bounds->status_bounds_in_shelf.set_x(0); | 888 else |
| 911 else | 889 target_bounds->status_bounds_in_shelf.set_x( |
| 912 target_bounds->status_bounds_in_shelf.set_x( | 890 target_bounds->shelf_bounds_in_root.width() - |
| 913 target_bounds->shelf_bounds_in_root.width() - | 891 kShelfSize); |
| 914 kShelfSize); | |
| 915 } else { | |
| 916 // The statusbar should be in the center of the shelf. | |
| 917 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; | |
| 918 status_x.set_x(0); | |
| 919 status_x.ClampToCenteredSize( | |
| 920 target_bounds->status_bounds_in_shelf.size()); | |
| 921 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); | |
| 922 } | |
| 923 } | 892 } |
| 924 } | 893 } |
| 925 | 894 |
| 926 void ShelfLayoutManager::UpdateShelfBackground( | 895 void ShelfLayoutManager::UpdateShelfBackground( |
| 927 BackgroundAnimatorChangeType type) { | 896 BackgroundAnimatorChangeType type) { |
| 928 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 897 const ShelfBackgroundType background_type(GetShelfBackgroundType()); |
| 929 shelf_->SetPaintsBackground(background_type, type); | 898 shelf_->SetPaintsBackground(background_type, type); |
| 930 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 899 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 931 OnBackgroundUpdated(background_type, type)); | 900 OnBackgroundUpdated(background_type, type)); |
| 932 } | 901 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 return gfx::Insets(0, distance, 0, 0); | 1126 return gfx::Insets(0, distance, 0, 0); |
| 1158 case SHELF_ALIGNMENT_TOP: | 1127 case SHELF_ALIGNMENT_TOP: |
| 1159 return gfx::Insets(0, 0, distance, 0); | 1128 return gfx::Insets(0, 0, distance, 0); |
| 1160 } | 1129 } |
| 1161 NOTREACHED(); | 1130 NOTREACHED(); |
| 1162 return gfx::Insets(); | 1131 return gfx::Insets(); |
| 1163 } | 1132 } |
| 1164 | 1133 |
| 1165 } // namespace internal | 1134 } // namespace internal |
| 1166 } // namespace ash | 1135 } // namespace ash |
| OLD | NEW |