| 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/common/shelf/shelf_view.h" | 5 #include "ash/common/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/common/ash_constants.h" | 10 #include "ash/common/ash_constants.h" |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 x = wm_shelf_->PrimaryAxisValue(x + w + button_spacing, x); | 924 x = wm_shelf_->PrimaryAxisValue(x + w + button_spacing, x); |
| 925 y = wm_shelf_->PrimaryAxisValue(y, y + h + button_spacing); | 925 y = wm_shelf_->PrimaryAxisValue(y, y + h + button_spacing); |
| 926 } | 926 } |
| 927 | 927 |
| 928 if (is_overflow_mode()) { | 928 if (is_overflow_mode()) { |
| 929 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); | 929 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); |
| 930 return; | 930 return; |
| 931 } | 931 } |
| 932 | 932 |
| 933 // Right aligned icons. | 933 // Right aligned icons. |
| 934 int end_position = available_size - button_spacing; | 934 int end_position = available_size; |
| 935 x = wm_shelf_->PrimaryAxisValue(end_position, 0); | 935 x = wm_shelf_->PrimaryAxisValue(end_position, 0); |
| 936 y = wm_shelf_->PrimaryAxisValue(0, end_position); | 936 y = wm_shelf_->PrimaryAxisValue(0, end_position); |
| 937 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { | 937 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { |
| 938 x = wm_shelf_->PrimaryAxisValue(x - w - button_spacing, x); | 938 x = wm_shelf_->PrimaryAxisValue(x - w - button_spacing, x); |
| 939 y = wm_shelf_->PrimaryAxisValue(y, y - h - button_spacing); | 939 y = wm_shelf_->PrimaryAxisValue(y, y - h - button_spacing); |
| 940 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 940 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 941 end_position = wm_shelf_->PrimaryAxisValue(x, y); | 941 end_position = wm_shelf_->PrimaryAxisValue(x, y); |
| 942 } | 942 } |
| 943 | 943 |
| 944 // Icons on the left / top are guaranteed up to kLeftIconProportion of | 944 // Icons on the left / top are guaranteed up to kLeftIconProportion of |
| 945 // the available space. | 945 // the available space. |
| 946 int last_icon_position = | 946 int last_icon_position = |
| 947 wm_shelf_->PrimaryAxisValue( | 947 wm_shelf_->PrimaryAxisValue( |
| 948 view_model_->ideal_bounds(last_button_index).right(), | 948 view_model_->ideal_bounds(last_button_index).right(), |
| 949 view_model_->ideal_bounds(last_button_index).bottom()) + | 949 view_model_->ideal_bounds(last_button_index).bottom()) + |
| 950 button_size; | 950 button_spacing; |
| 951 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; | 951 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; |
| 952 if (last_icon_position < reserved_icon_space) | 952 if (last_icon_position < reserved_icon_space) |
| 953 end_position = last_icon_position; | 953 end_position = last_icon_position; |
| 954 else | 954 else |
| 955 end_position = std::max(end_position, reserved_icon_space); | 955 end_position = std::max(end_position, reserved_icon_space); |
| 956 | 956 |
| 957 bounds->overflow_bounds.set_size( | 957 bounds->overflow_bounds.set_size( |
| 958 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()), | 958 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()), |
| 959 wm_shelf_->PrimaryAxisValue(height(), h))); | 959 wm_shelf_->PrimaryAxisValue(height(), h))); |
| 960 | 960 |
| 961 last_visible_index_ = DetermineLastVisibleIndex(end_position - button_size); | 961 last_visible_index_ = |
| 962 DetermineLastVisibleIndex(end_position - button_spacing); |
| 962 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; | 963 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; |
| 963 bool show_overflow = last_visible_index_ < last_button_index || | 964 bool show_overflow = last_visible_index_ < last_button_index || |
| 964 last_hidden_index_ >= first_panel_index; | 965 last_hidden_index_ >= first_panel_index; |
| 965 | 966 |
| 966 // Create Space for the overflow button | 967 // Create Space for the overflow button |
| 967 if (show_overflow) { | 968 if (show_overflow) { |
| 968 // The following code makes sure that platform apps icons (aligned to left / | 969 // The following code makes sure that platform apps icons (aligned to left / |
| 969 // top) are favored over panel apps icons (aligned to right / bottom). | 970 // top) are favored over panel apps icons (aligned to right / bottom). |
| 970 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) { | 971 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) { |
| 971 // This condition means that we will take one platform app and replace it | 972 // This condition means that we will take one platform app and replace it |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 x = 0; | 1004 x = 0; |
| 1004 y = 0; | 1005 y = 0; |
| 1005 } else { | 1006 } else { |
| 1006 x = wm_shelf_->PrimaryAxisValue( | 1007 x = wm_shelf_->PrimaryAxisValue( |
| 1007 view_model_->ideal_bounds(last_visible_index_).right(), | 1008 view_model_->ideal_bounds(last_visible_index_).right(), |
| 1008 view_model_->ideal_bounds(last_visible_index_).x()); | 1009 view_model_->ideal_bounds(last_visible_index_).x()); |
| 1009 y = wm_shelf_->PrimaryAxisValue( | 1010 y = wm_shelf_->PrimaryAxisValue( |
| 1010 view_model_->ideal_bounds(last_visible_index_).y(), | 1011 view_model_->ideal_bounds(last_visible_index_).y(), |
| 1011 view_model_->ideal_bounds(last_visible_index_).bottom()); | 1012 view_model_->ideal_bounds(last_visible_index_).bottom()); |
| 1012 } | 1013 } |
| 1014 |
| 1015 if (last_visible_index_ >= 0) { |
| 1016 // Add more space between last visible item and overflow button. |
| 1017 // Without this, two buttons look too close compared with other items. |
| 1018 x = wm_shelf_->PrimaryAxisValue(x + button_spacing, x); |
| 1019 y = wm_shelf_->PrimaryAxisValue(y, y + button_spacing); |
| 1020 } |
| 1021 |
| 1013 // Set all hidden panel icon positions to be on the overflow button. | 1022 // Set all hidden panel icon positions to be on the overflow button. |
| 1014 for (int i = first_panel_index; i <= last_hidden_index_; ++i) | 1023 for (int i = first_panel_index; i <= last_hidden_index_; ++i) |
| 1015 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 1024 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 1016 | 1025 |
| 1017 // Add more space between last visible item and overflow button. | |
| 1018 // Without this, two buttons look too close compared with other items. | |
| 1019 x = wm_shelf_->PrimaryAxisValue(x + button_spacing, x); | |
| 1020 y = wm_shelf_->PrimaryAxisValue(y, y + button_spacing); | |
| 1021 | |
| 1022 bounds->overflow_bounds.set_x(x); | 1026 bounds->overflow_bounds.set_x(x); |
| 1023 bounds->overflow_bounds.set_y(y); | 1027 bounds->overflow_bounds.set_y(y); |
| 1024 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) | 1028 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) |
| 1025 UpdateOverflowRange(overflow_bubble_->shelf_view()); | 1029 UpdateOverflowRange(overflow_bubble_->shelf_view()); |
| 1026 } else { | 1030 } else { |
| 1027 if (overflow_bubble_) | 1031 if (overflow_bubble_) |
| 1028 overflow_bubble_->Hide(); | 1032 overflow_bubble_->Hide(); |
| 1029 } | 1033 } |
| 1030 } | 1034 } |
| 1031 | 1035 |
| 1032 int ShelfView::DetermineLastVisibleIndex(int max_value) const { | 1036 int ShelfView::DetermineLastVisibleIndex(int max_value) const { |
| 1033 int index = model_->FirstPanelIndex() - 1; | 1037 int index = model_->FirstPanelIndex() - 1; |
| 1034 while (index >= 0 && | 1038 while (index >= 0 && |
| 1035 wm_shelf_->PrimaryAxisValue( | 1039 wm_shelf_->PrimaryAxisValue( |
| 1036 view_model_->ideal_bounds(index).right(), | 1040 view_model_->ideal_bounds(index).right(), |
| 1037 view_model_->ideal_bounds(index).bottom()) > max_value) { | 1041 view_model_->ideal_bounds(index).bottom()) > max_value) { |
| 1038 index--; | 1042 index--; |
| 1039 } | 1043 } |
| 1040 return index; | 1044 return index; |
| 1041 } | 1045 } |
| 1042 | 1046 |
| 1043 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const { | 1047 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const { |
| 1044 int index = model_->FirstPanelIndex(); | 1048 int index = model_->FirstPanelIndex(); |
| 1045 while (index < view_model_->view_size() && | 1049 while (index < view_model_->view_size() && |
| 1046 wm_shelf_->PrimaryAxisValue( | 1050 wm_shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).x(), |
| 1047 view_model_->ideal_bounds(index).right(), | 1051 view_model_->ideal_bounds(index).y()) < |
| 1048 view_model_->ideal_bounds(index).bottom()) < min_value) { | 1052 min_value) { |
| 1049 ++index; | 1053 ++index; |
| 1050 } | 1054 } |
| 1051 return index; | 1055 return index; |
| 1052 } | 1056 } |
| 1053 | 1057 |
| 1054 void ShelfView::AnimateToIdealBounds() { | 1058 void ShelfView::AnimateToIdealBounds() { |
| 1055 IdealBounds ideal_bounds; | 1059 IdealBounds ideal_bounds; |
| 1056 CalculateIdealBounds(&ideal_bounds); | 1060 CalculateIdealBounds(&ideal_bounds); |
| 1057 for (int i = 0; i < view_model_->view_size(); ++i) { | 1061 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 1058 View* view = view_model_->view_at(i); | 1062 View* view = view_model_->view_at(i); |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 if (at_end) | 1553 if (at_end) |
| 1550 return view_model_->view_size(); | 1554 return view_model_->view_size(); |
| 1551 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; | 1555 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; |
| 1552 } | 1556 } |
| 1553 | 1557 |
| 1554 gfx::Size ShelfView::GetPreferredSize() const { | 1558 gfx::Size ShelfView::GetPreferredSize() const { |
| 1555 IdealBounds ideal_bounds; | 1559 IdealBounds ideal_bounds; |
| 1556 CalculateIdealBounds(&ideal_bounds); | 1560 CalculateIdealBounds(&ideal_bounds); |
| 1557 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 1561 const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| 1558 | 1562 |
| 1559 int last_button_index = | 1563 int last_button_index = last_visible_index_; |
| 1560 is_overflow_mode() ? last_visible_index_ : view_model_->view_size() - 1; | 1564 if (!is_overflow_mode()) { |
| 1565 if (last_hidden_index_ < view_model_->view_size() - 1) |
| 1566 last_button_index = view_model_->view_size() - 1; |
| 1567 else if (overflow_button_ && overflow_button_->visible()) |
| 1568 last_button_index++; |
| 1569 } |
| 1561 | 1570 |
| 1562 // When an item is dragged off from the overflow bubble, it is moved to last | 1571 // When an item is dragged off from the overflow bubble, it is moved to last |
| 1563 // position and and changed to invisible. Overflow bubble size should be | 1572 // position and and changed to invisible. Overflow bubble size should be |
| 1564 // shrunk to fit only for visible items. | 1573 // shrunk to fit only for visible items. |
| 1565 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible | 1574 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible |
| 1566 // items in the shelf. | 1575 // items in the shelf. |
| 1567 if (is_overflow_mode() && dragged_off_shelf_ && | 1576 if (is_overflow_mode() && dragged_off_shelf_ && |
| 1568 !dragged_off_from_overflow_to_shelf_ && | 1577 !dragged_off_from_overflow_to_shelf_ && |
| 1569 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) | 1578 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) |
| 1570 last_button_index--; | 1579 last_button_index--; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1914 | 1923 |
| 1915 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1924 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1916 const gfx::Rect bounds = GetBoundsInScreen(); | 1925 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1917 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1926 int distance = wm_shelf_->SelectValueForShelfAlignment( |
| 1918 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1927 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1919 bounds.x() - coordinate.x()); | 1928 bounds.x() - coordinate.x()); |
| 1920 return distance > 0 ? distance : 0; | 1929 return distance > 0 ? distance : 0; |
| 1921 } | 1930 } |
| 1922 | 1931 |
| 1923 } // namespace ash | 1932 } // namespace ash |
| OLD | NEW |