| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // static | 89 // static |
| 90 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; | 90 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; |
| 91 | 91 |
| 92 // static | 92 // static |
| 93 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; | 93 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 const int ShelfLayoutManager::kAutoHideSize = 3; | 96 const int ShelfLayoutManager::kAutoHideSize = 3; |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 const int ShelfLayoutManager::kShelfSize = 47; | |
| 100 | |
| 101 // static | |
| 102 const int ShelfLayoutManager::kShelfItemInset = 3; | 99 const int ShelfLayoutManager::kShelfItemInset = 3; |
| 103 | 100 |
| 104 int ShelfLayoutManager::GetPreferredShelfSize() { | |
| 105 return ash::switches::UseAlternateShelfLayout() ? | |
| 106 ShelfLayoutManager::kShelfSize : kShelfPreferredSize; | |
| 107 } | |
| 108 | |
| 109 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- | 101 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| 110 | 102 |
| 111 // Notifies ShelfLayoutManager any time the mouse moves. | 103 // Notifies ShelfLayoutManager any time the mouse moves. |
| 112 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { | 104 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| 113 public: | 105 public: |
| 114 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); | 106 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| 115 virtual ~AutoHideEventFilter(); | 107 virtual ~AutoHideEventFilter(); |
| 116 | 108 |
| 117 // Returns true if the last mouse event was a mouse drag. | 109 // Returns true if the last mouse event was a mouse drag. |
| 118 bool in_mouse_drag() const { return in_mouse_drag_; } | 110 bool in_mouse_drag() const { return in_mouse_drag_; } |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 void ShelfLayoutManager::StopAnimating() { | 721 void ShelfLayoutManager::StopAnimating() { |
| 730 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 722 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 731 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 723 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 732 } | 724 } |
| 733 | 725 |
| 734 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 726 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
| 735 *width = *height = 0; | 727 *width = *height = 0; |
| 736 gfx::Size status_size( | 728 gfx::Size status_size( |
| 737 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 729 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 738 if (IsHorizontalAlignment()) | 730 if (IsHorizontalAlignment()) |
| 739 *height = GetPreferredShelfSize(); | 731 *height = kShelfSize; |
| 740 else | 732 else |
| 741 *width = GetPreferredShelfSize(); | 733 *width = kShelfSize; |
| 742 } | 734 } |
| 743 | 735 |
| 744 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 736 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
| 745 gfx::Rect* bounds) const { | 737 gfx::Rect* bounds) const { |
| 746 bounds->Inset(SelectValueForShelfAlignment( | 738 bounds->Inset(SelectValueForShelfAlignment( |
| 747 gfx::Insets(0, 0, inset, 0), | 739 gfx::Insets(0, 0, inset, 0), |
| 748 gfx::Insets(0, inset, 0, 0), | 740 gfx::Insets(0, inset, 0, 0), |
| 749 gfx::Insets(0, 0, 0, inset), | 741 gfx::Insets(0, 0, 0, inset), |
| 750 gfx::Insets(inset, 0, 0, 0))); | 742 gfx::Insets(inset, 0, 0, 0))); |
| 751 } | 743 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( | 775 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
| 784 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, | 776 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
| 785 available_bounds.width(), shelf_height), | 777 available_bounds.width(), shelf_height), |
| 786 gfx::Rect(available_bounds.x(), available_bounds.y(), | 778 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 787 shelf_width, available_bounds.height()), | 779 shelf_width, available_bounds.height()), |
| 788 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 780 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
| 789 shelf_width, available_bounds.height()), | 781 shelf_width, available_bounds.height()), |
| 790 gfx::Rect(available_bounds.x(), available_bounds.y(), | 782 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 791 available_bounds.width(), shelf_height)); | 783 available_bounds.width(), shelf_height)); |
| 792 | 784 |
| 793 int status_inset = std::max(0, GetPreferredShelfSize() - | 785 int status_inset = 0; |
| 794 PrimaryAxisValue(status_size.height(), status_size.width())); | 786 if (IsHorizontalAlignment()) |
| 795 | 787 status_size.set_height(kShelfSize); |
| 796 if (ash::switches::UseAlternateShelfLayout()) { | 788 else |
| 797 status_inset = 0; | 789 status_size.set_width(kShelfSize); |
| 798 if (IsHorizontalAlignment()) | |
| 799 status_size.set_height(kShelfSize); | |
| 800 else | |
| 801 status_size.set_width(kShelfSize); | |
| 802 } | |
| 803 | 790 |
| 804 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( | 791 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
| 805 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 792 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 806 status_inset, status_size.width(), status_size.height()), | 793 status_inset, status_size.width(), status_size.height()), |
| 807 gfx::Rect(shelf_width - (status_size.width() + status_inset), | 794 gfx::Rect(shelf_width - (status_size.width() + status_inset), |
| 808 shelf_height - status_size.height(), status_size.width(), | 795 shelf_height - status_size.height(), status_size.width(), |
| 809 status_size.height()), | 796 status_size.height()), |
| 810 gfx::Rect(status_inset, shelf_height - status_size.height(), | 797 gfx::Rect(status_inset, shelf_height - status_size.height(), |
| 811 status_size.width(), status_size.height()), | 798 status_size.width(), status_size.height()), |
| 812 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), | 799 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 const gfx::Rect& available_bounds(root_window_->bounds()); | 859 const gfx::Rect& available_bounds(root_window_->bounds()); |
| 873 int resistance_free_region = 0; | 860 int resistance_free_region = 0; |
| 874 | 861 |
| 875 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 862 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 876 visibility_state() == SHELF_AUTO_HIDE && | 863 visibility_state() == SHELF_AUTO_HIDE && |
| 877 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 864 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 878 // If the shelf was hidden when the drag started (and the state hasn't | 865 // If the shelf was hidden when the drag started (and the state hasn't |
| 879 // changed since then, e.g. because the tray-menu was shown because of the | 866 // changed since then, e.g. because the tray-menu was shown because of the |
| 880 // drag), then allow the drag some resistance-free region at first to make | 867 // drag), then allow the drag some resistance-free region at first to make |
| 881 // sure the shelf sticks with the finger until the shelf is visible. | 868 // sure the shelf sticks with the finger until the shelf is visible. |
| 882 resistance_free_region = GetPreferredShelfSize() - kAutoHideSize; | 869 resistance_free_region = kShelfSize - kAutoHideSize; |
| 883 } | 870 } |
| 884 | 871 |
| 885 bool resist = SelectValueForShelfAlignment( | 872 bool resist = SelectValueForShelfAlignment( |
| 886 gesture_drag_amount_ < -resistance_free_region, | 873 gesture_drag_amount_ < -resistance_free_region, |
| 887 gesture_drag_amount_ > resistance_free_region, | 874 gesture_drag_amount_ > resistance_free_region, |
| 888 gesture_drag_amount_ < -resistance_free_region, | 875 gesture_drag_amount_ < -resistance_free_region, |
| 889 gesture_drag_amount_ > resistance_free_region); | 876 gesture_drag_amount_ > resistance_free_region); |
| 890 | 877 |
| 891 float translate = 0.f; | 878 float translate = 0.f; |
| 892 if (resist) { | 879 if (resist) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 903 if (horizontal) { | 890 if (horizontal) { |
| 904 // Move and size the shelf with the gesture. | 891 // Move and size the shelf with the gesture. |
| 905 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 892 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 906 shelf_height = std::max(shelf_height, kAutoHideSize); | 893 shelf_height = std::max(shelf_height, kAutoHideSize); |
| 907 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 894 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
| 908 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 895 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 909 target_bounds->shelf_bounds_in_root.set_y( | 896 target_bounds->shelf_bounds_in_root.set_y( |
| 910 available_bounds.bottom() - shelf_height); | 897 available_bounds.bottom() - shelf_height); |
| 911 } | 898 } |
| 912 | 899 |
| 913 if (ash::switches::UseAlternateShelfLayout()) { | 900 target_bounds->status_bounds_in_shelf.set_y(0); |
| 914 target_bounds->status_bounds_in_shelf.set_y(0); | |
| 915 } else { | |
| 916 // The statusbar should be in the center of the shelf. | |
| 917 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | |
| 918 status_y.set_y(0); | |
| 919 status_y.ClampToCenteredSize( | |
| 920 target_bounds->status_bounds_in_shelf.size()); | |
| 921 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | |
| 922 } | |
| 923 } else { | 901 } else { |
| 924 // Move and size the shelf with the gesture. | 902 // Move and size the shelf with the gesture. |
| 925 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 903 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
| 926 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 904 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; |
| 927 if (right_aligned) | 905 if (right_aligned) |
| 928 shelf_width -= translate; | 906 shelf_width -= translate; |
| 929 else | 907 else |
| 930 shelf_width += translate; | 908 shelf_width += translate; |
| 931 shelf_width = std::max(shelf_width, kAutoHideSize); | 909 shelf_width = std::max(shelf_width, kAutoHideSize); |
| 932 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 910 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
| 933 if (right_aligned) { | 911 if (right_aligned) { |
| 934 target_bounds->shelf_bounds_in_root.set_x( | 912 target_bounds->shelf_bounds_in_root.set_x( |
| 935 available_bounds.right() - shelf_width); | 913 available_bounds.right() - shelf_width); |
| 936 } | 914 } |
| 937 | 915 |
| 938 if (ash::switches::UseAlternateShelfLayout()) { | 916 if (right_aligned) |
| 939 if (right_aligned) | 917 target_bounds->status_bounds_in_shelf.set_x(0); |
| 940 target_bounds->status_bounds_in_shelf.set_x(0); | 918 else |
| 941 else | 919 target_bounds->status_bounds_in_shelf.set_x( |
| 942 target_bounds->status_bounds_in_shelf.set_x( | 920 target_bounds->shelf_bounds_in_root.width() - |
| 943 target_bounds->shelf_bounds_in_root.width() - | 921 kShelfSize); |
| 944 kShelfSize); | |
| 945 } else { | |
| 946 // The statusbar should be in the center of the shelf. | |
| 947 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; | |
| 948 status_x.set_x(0); | |
| 949 status_x.ClampToCenteredSize( | |
| 950 target_bounds->status_bounds_in_shelf.size()); | |
| 951 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); | |
| 952 } | |
| 953 } | 922 } |
| 954 } | 923 } |
| 955 | 924 |
| 956 void ShelfLayoutManager::UpdateShelfBackground( | 925 void ShelfLayoutManager::UpdateShelfBackground( |
| 957 BackgroundAnimatorChangeType type) { | 926 BackgroundAnimatorChangeType type) { |
| 958 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 927 const ShelfBackgroundType background_type(GetShelfBackgroundType()); |
| 959 shelf_->SetPaintsBackground(background_type, type); | 928 shelf_->SetPaintsBackground(background_type, type); |
| 960 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 929 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 961 OnBackgroundUpdated(background_type, type)); | 930 OnBackgroundUpdated(background_type, type)); |
| 962 } | 931 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 SHELF_HIDDEN); | 1125 SHELF_HIDDEN); |
| 1157 TargetBounds target_bounds; | 1126 TargetBounds target_bounds; |
| 1158 CalculateTargetBounds(state_, &target_bounds); | 1127 CalculateTargetBounds(state_, &target_bounds); |
| 1159 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1128 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
| 1160 UpdateVisibilityState(); | 1129 UpdateVisibilityState(); |
| 1161 } | 1130 } |
| 1162 } | 1131 } |
| 1163 | 1132 |
| 1164 } // namespace internal | 1133 } // namespace internal |
| 1165 } // namespace ash | 1134 } // namespace ash |
| OLD | NEW |