| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 int available_size = wm_shelf_->PrimaryAxisValue(width(), height()); | 779 int available_size = wm_shelf_->PrimaryAxisValue(width(), height()); |
| 780 DCHECK(model_->item_count() == view_model_->view_size()); | 780 DCHECK(model_->item_count() == view_model_->view_size()); |
| 781 if (!available_size) | 781 if (!available_size) |
| 782 return; | 782 return; |
| 783 | 783 |
| 784 int first_panel_index = model_->FirstPanelIndex(); | 784 int first_panel_index = model_->FirstPanelIndex(); |
| 785 int last_button_index = first_panel_index - 1; | 785 int last_button_index = first_panel_index - 1; |
| 786 | 786 |
| 787 int x = 0; | 787 int x = 0; |
| 788 int y = 0; | 788 int y = 0; |
| 789 int button_size = GetShelfConstant(SHELF_BUTTON_SIZE); | |
| 790 int button_spacing = GetShelfConstant(SHELF_BUTTON_SPACING); | |
| 791 | 789 |
| 792 int w = wm_shelf_->PrimaryAxisValue(button_size, width()); | 790 int w = wm_shelf_->PrimaryAxisValue(kShelfButtonSize, width()); |
| 793 int h = wm_shelf_->PrimaryAxisValue(height(), button_size); | 791 int h = wm_shelf_->PrimaryAxisValue(height(), kShelfButtonSize); |
| 794 for (int i = 0; i < view_model_->view_size(); ++i) { | 792 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 795 if (i < first_visible_index_) { | 793 if (i < first_visible_index_) { |
| 796 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 794 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
| 797 continue; | 795 continue; |
| 798 } | 796 } |
| 799 | 797 |
| 800 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 798 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 801 x = wm_shelf_->PrimaryAxisValue(x + w + button_spacing, x); | 799 x = wm_shelf_->PrimaryAxisValue(x + w + kShelfButtonSpacing, x); |
| 802 y = wm_shelf_->PrimaryAxisValue(y, y + h + button_spacing); | 800 y = wm_shelf_->PrimaryAxisValue(y, y + h + kShelfButtonSpacing); |
| 803 } | 801 } |
| 804 | 802 |
| 805 if (is_overflow_mode()) { | 803 if (is_overflow_mode()) { |
| 806 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); | 804 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); |
| 807 return; | 805 return; |
| 808 } | 806 } |
| 809 | 807 |
| 810 // Right aligned icons. | 808 // Right aligned icons. |
| 811 int end_position = available_size; | 809 int end_position = available_size; |
| 812 x = wm_shelf_->PrimaryAxisValue(end_position, 0); | 810 x = wm_shelf_->PrimaryAxisValue(end_position, 0); |
| 813 y = wm_shelf_->PrimaryAxisValue(0, end_position); | 811 y = wm_shelf_->PrimaryAxisValue(0, end_position); |
| 814 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { | 812 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { |
| 815 x = wm_shelf_->PrimaryAxisValue(x - w - button_spacing, x); | 813 x = wm_shelf_->PrimaryAxisValue(x - w - kShelfButtonSpacing, x); |
| 816 y = wm_shelf_->PrimaryAxisValue(y, y - h - button_spacing); | 814 y = wm_shelf_->PrimaryAxisValue(y, y - h - kShelfButtonSpacing); |
| 817 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 815 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 818 end_position = wm_shelf_->PrimaryAxisValue(x, y); | 816 end_position = wm_shelf_->PrimaryAxisValue(x, y); |
| 819 } | 817 } |
| 820 | 818 |
| 821 // Icons on the left / top are guaranteed up to kLeftIconProportion of | 819 // Icons on the left / top are guaranteed up to kLeftIconProportion of |
| 822 // the available space. | 820 // the available space. |
| 823 int last_icon_position = | 821 int last_icon_position = |
| 824 wm_shelf_->PrimaryAxisValue( | 822 wm_shelf_->PrimaryAxisValue( |
| 825 view_model_->ideal_bounds(last_button_index).right(), | 823 view_model_->ideal_bounds(last_button_index).right(), |
| 826 view_model_->ideal_bounds(last_button_index).bottom()) + | 824 view_model_->ideal_bounds(last_button_index).bottom()) + |
| 827 button_spacing; | 825 kShelfButtonSpacing; |
| 828 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; | 826 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; |
| 829 if (last_icon_position < reserved_icon_space) | 827 if (last_icon_position < reserved_icon_space) |
| 830 end_position = last_icon_position; | 828 end_position = last_icon_position; |
| 831 else | 829 else |
| 832 end_position = std::max(end_position, reserved_icon_space); | 830 end_position = std::max(end_position, reserved_icon_space); |
| 833 | 831 |
| 834 bounds->overflow_bounds.set_size( | 832 bounds->overflow_bounds.set_size( |
| 835 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()), | 833 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()), |
| 836 wm_shelf_->PrimaryAxisValue(height(), h))); | 834 wm_shelf_->PrimaryAxisValue(height(), h))); |
| 837 | 835 |
| 838 last_visible_index_ = | 836 last_visible_index_ = |
| 839 DetermineLastVisibleIndex(end_position - button_spacing); | 837 DetermineLastVisibleIndex(end_position - kShelfButtonSpacing); |
| 840 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; | 838 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; |
| 841 bool show_overflow = last_visible_index_ < last_button_index || | 839 bool show_overflow = last_visible_index_ < last_button_index || |
| 842 last_hidden_index_ >= first_panel_index; | 840 last_hidden_index_ >= first_panel_index; |
| 843 | 841 |
| 844 // Create Space for the overflow button | 842 // Create Space for the overflow button |
| 845 if (show_overflow) { | 843 if (show_overflow) { |
| 846 // The following code makes sure that platform apps icons (aligned to left / | 844 // The following code makes sure that platform apps icons (aligned to left / |
| 847 // top) are favored over panel apps icons (aligned to right / bottom). | 845 // top) are favored over panel apps icons (aligned to right / bottom). |
| 848 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) { | 846 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) { |
| 849 // This condition means that we will take one platform app and replace it | 847 // This condition means that we will take one platform app and replace it |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 view_model_->ideal_bounds(last_visible_index_).right(), | 883 view_model_->ideal_bounds(last_visible_index_).right(), |
| 886 view_model_->ideal_bounds(last_visible_index_).x()); | 884 view_model_->ideal_bounds(last_visible_index_).x()); |
| 887 y = wm_shelf_->PrimaryAxisValue( | 885 y = wm_shelf_->PrimaryAxisValue( |
| 888 view_model_->ideal_bounds(last_visible_index_).y(), | 886 view_model_->ideal_bounds(last_visible_index_).y(), |
| 889 view_model_->ideal_bounds(last_visible_index_).bottom()); | 887 view_model_->ideal_bounds(last_visible_index_).bottom()); |
| 890 } | 888 } |
| 891 | 889 |
| 892 if (last_visible_index_ >= 0) { | 890 if (last_visible_index_ >= 0) { |
| 893 // Add more space between last visible item and overflow button. | 891 // Add more space between last visible item and overflow button. |
| 894 // Without this, two buttons look too close compared with other items. | 892 // Without this, two buttons look too close compared with other items. |
| 895 x = wm_shelf_->PrimaryAxisValue(x + button_spacing, x); | 893 x = wm_shelf_->PrimaryAxisValue(x + kShelfButtonSpacing, x); |
| 896 y = wm_shelf_->PrimaryAxisValue(y, y + button_spacing); | 894 y = wm_shelf_->PrimaryAxisValue(y, y + kShelfButtonSpacing); |
| 897 } | 895 } |
| 898 | 896 |
| 899 // Set all hidden panel icon positions to be on the overflow button. | 897 // Set all hidden panel icon positions to be on the overflow button. |
| 900 for (int i = first_panel_index; i <= last_hidden_index_; ++i) | 898 for (int i = first_panel_index; i <= last_hidden_index_; ++i) |
| 901 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 899 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 902 | 900 |
| 903 bounds->overflow_bounds.set_x(x); | 901 bounds->overflow_bounds.set_x(x); |
| 904 bounds->overflow_bounds.set_y(y); | 902 bounds->overflow_bounds.set_y(y); |
| 905 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) | 903 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) |
| 906 UpdateOverflowRange(overflow_bubble_->shelf_view()); | 904 UpdateOverflowRange(overflow_bubble_->shelf_view()); |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 | 1774 |
| 1777 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1775 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1778 const gfx::Rect bounds = GetBoundsInScreen(); | 1776 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1779 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1777 int distance = wm_shelf_->SelectValueForShelfAlignment( |
| 1780 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1778 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1781 bounds.x() - coordinate.x()); | 1779 bounds.x() - coordinate.x()); |
| 1782 return distance > 0 ? distance : 0; | 1780 return distance > 0 ? distance : 0; |
| 1783 } | 1781 } |
| 1784 | 1782 |
| 1785 } // namespace ash | 1783 } // namespace ash |
| OLD | NEW |