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