Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: ui/app_list/views/apps_grid_view.cc

Issue 599933004: AppsGridView: Use specific types instead of views::View*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/app_list/views/apps_grid_view.h" 5 #include "ui/app_list/views/apps_grid_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 folder_delegate_->UpdateFolderViewBackground(false); 756 folder_delegate_->UpdateFolderViewBackground(false);
757 } 757 }
758 758
759 void AppsGridView::StopPageFlipTimer() { 759 void AppsGridView::StopPageFlipTimer() {
760 page_flip_timer_.Stop(); 760 page_flip_timer_.Stop();
761 page_flip_target_ = -1; 761 page_flip_target_ = -1;
762 } 762 }
763 763
764 AppListItemView* AppsGridView::GetItemViewAt(int index) const { 764 AppListItemView* AppsGridView::GetItemViewAt(int index) const {
765 DCHECK(index >= 0 && index < view_model_.view_size()); 765 DCHECK(index >= 0 && index < view_model_.view_size());
766 return static_cast<AppListItemView*>(view_model_.view_at(index)); 766 return static_cast<AppListItemView*>(view_model_.view_at(index));
tapted 2014/09/25 06:35:28 I wish we could go further by extending ViewModel
calamity 2014/09/26 01:47:26 Could go make ViewModel templated. #doublehides
Matt Giuca 2014/09/26 03:48:39 I think the template is a good idea. Follow-up pat
767 } 767 }
768 768
769 void AppsGridView::SetTopItemViewsVisible(bool visible) { 769 void AppsGridView::SetTopItemViewsVisible(bool visible) {
770 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems), 770 int top_item_count = std::min(static_cast<int>(kNumFolderTopItems),
771 view_model_.view_size()); 771 view_model_.view_size());
772 for (int i = 0; i < top_item_count; ++i) 772 for (int i = 0; i < top_item_count; ++i)
773 GetItemViewAt(i)->icon()->SetVisible(visible); 773 GetItemViewAt(i)->icon()->SetVisible(visible);
774 } 774 }
775 775
776 void AppsGridView::ScheduleShowHideAnimation(bool show) { 776 void AppsGridView::ScheduleShowHideAnimation(bool show) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 ApplicationDragAndDropHost* drag_and_drop_host) { 877 ApplicationDragAndDropHost* drag_and_drop_host) {
878 drag_and_drop_host_ = drag_and_drop_host; 878 drag_and_drop_host_ = drag_and_drop_host;
879 } 879 }
880 880
881 void AppsGridView::Prerender() { 881 void AppsGridView::Prerender() {
882 Layout(); 882 Layout();
883 int selected_page = std::max(0, pagination_model_.selected_page()); 883 int selected_page = std::max(0, pagination_model_.selected_page());
884 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page()); 884 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page());
885 int end = std::min(view_model_.view_size(), 885 int end = std::min(view_model_.view_size(),
886 (selected_page + 1 + kPrerenderPages) * tiles_per_page()); 886 (selected_page + 1 + kPrerenderPages) * tiles_per_page());
887 for (int i = start; i < end; i++) { 887 for (int i = start; i < end; i++)
888 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); 888 GetItemViewAt(i)->Prerender();
889 v->Prerender();
890 }
891 } 889 }
892 890
893 bool AppsGridView::IsAnimatingView(views::View* view) { 891 bool AppsGridView::IsAnimatingView(views::View* view) {
894 return bounds_animator_.IsAnimating(view); 892 return bounds_animator_.IsAnimating(view);
895 } 893 }
896 894
897 gfx::Size AppsGridView::GetPreferredSize() const { 895 gfx::Size AppsGridView::GetPreferredSize() const {
898 const gfx::Insets insets(GetInsets()); 896 const gfx::Insets insets(GetInsets());
899 int page_switcher_height = 0; 897 int page_switcher_height = 0;
900 if (page_switcher_view_) 898 if (page_switcher_view_)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1087 }
1090 1088
1091 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { 1089 int AppsGridView::GetModelIndexFromIndex(const Index& index) const {
1092 return index.page * tiles_per_page() + index.slot; 1090 return index.page * tiles_per_page() + index.slot;
1093 } 1091 }
1094 1092
1095 void AppsGridView::SetSelectedItemByIndex(const Index& index) { 1093 void AppsGridView::SetSelectedItemByIndex(const Index& index) {
1096 if (GetIndexOfView(selected_view_) == index) 1094 if (GetIndexOfView(selected_view_) == index)
1097 return; 1095 return;
1098 1096
1099 views::View* new_selection = GetViewAtIndex(index); 1097 AppListItemView* new_selection = GetViewAtIndex(index);
1100 if (!new_selection) 1098 if (!new_selection)
1101 return; // Keep current selection. 1099 return; // Keep current selection.
1102 1100
1103 if (selected_view_) 1101 if (selected_view_)
1104 selected_view_->SchedulePaint(); 1102 selected_view_->SchedulePaint();
1105 1103
1106 EnsureViewVisible(new_selection); 1104 EnsureViewVisible(new_selection);
1107 selected_view_ = new_selection; 1105 selected_view_ = new_selection;
1108 selected_view_->SchedulePaint(); 1106 selected_view_->SchedulePaint();
1109 selected_view_->NotifyAccessibilityEvent( 1107 selected_view_->NotifyAccessibilityEvent(
1110 ui::AX_EVENT_FOCUS, true); 1108 ui::AX_EVENT_FOCUS, true);
1111 } 1109 }
1112 1110
1113 bool AppsGridView::IsValidIndex(const Index& index) const { 1111 bool AppsGridView::IsValidIndex(const Index& index) const {
1114 return index.page >= 0 && index.page < pagination_model_.total_pages() && 1112 return index.page >= 0 && index.page < pagination_model_.total_pages() &&
1115 index.slot >= 0 && index.slot < tiles_per_page() && 1113 index.slot >= 0 && index.slot < tiles_per_page() &&
1116 GetModelIndexFromIndex(index) < view_model_.view_size(); 1114 GetModelIndexFromIndex(index) < view_model_.view_size();
1117 } 1115 }
1118 1116
1119 AppsGridView::Index AppsGridView::GetIndexOfView( 1117 AppsGridView::Index AppsGridView::GetIndexOfView(
1120 const views::View* view) const { 1118 const views::View* view) const {
1121 const int model_index = view_model_.GetIndexOfView(view); 1119 const int model_index = view_model_.GetIndexOfView(view);
1122 if (model_index == -1) 1120 if (model_index == -1)
1123 return Index(); 1121 return Index();
1124 1122
1125 return GetIndexFromModelIndex(model_index); 1123 return GetIndexFromModelIndex(model_index);
1126 } 1124 }
1127 1125
1128 views::View* AppsGridView::GetViewAtIndex(const Index& index) const { 1126 AppListItemView* AppsGridView::GetViewAtIndex(const Index& index) const {
1129 if (!IsValidIndex(index)) 1127 if (!IsValidIndex(index))
1130 return NULL; 1128 return NULL;
1131 1129
1132 const int model_index = GetModelIndexFromIndex(index); 1130 const int model_index = GetModelIndexFromIndex(index);
1133 return view_model_.view_at(model_index); 1131 return GetItemViewAt(model_index);
1134 } 1132 }
1135 1133
1136 AppsGridView::Index AppsGridView::GetLastViewIndex() const { 1134 AppsGridView::Index AppsGridView::GetLastViewIndex() const {
1137 DCHECK_LT(0, view_model_.view_size()); 1135 DCHECK_LT(0, view_model_.view_size());
1138 int view_index = view_model_.view_size() - 1; 1136 int view_index = view_model_.view_size() - 1;
1139 return Index(view_index / tiles_per_page(), view_index % tiles_per_page()); 1137 return Index(view_index / tiles_per_page(), view_index % tiles_per_page());
1140 } 1138 }
1141 1139
1142 void AppsGridView::MoveSelected(int page_delta, 1140 void AppsGridView::MoveSelected(int page_delta,
1143 int slot_x_delta, 1141 int slot_x_delta,
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1722
1725 item_list_->RemoveObserver(this); 1723 item_list_->RemoveObserver(this);
1726 item_list_->MoveItem(current_model_index, target_model_index); 1724 item_list_->MoveItem(current_model_index, target_model_index);
1727 view_model_.Move(current_model_index, target_model_index); 1725 view_model_.Move(current_model_index, target_model_index);
1728 item_list_->AddObserver(this); 1726 item_list_->AddObserver(this);
1729 1727
1730 if (pagination_model_.selected_page() != target.page) 1728 if (pagination_model_.selected_page() != target.page)
1731 pagination_model_.SelectPage(target.page, false); 1729 pagination_model_.SelectPage(target.page, false);
1732 } 1730 }
1733 1731
1734 void AppsGridView::MoveItemToFolder(views::View* item_view, 1732 void AppsGridView::MoveItemToFolder(AppListItemView* item_view,
1735 const Index& target) { 1733 const Index& target) {
1736 const std::string& source_item_id = 1734 const std::string& source_item_id = item_view->item()->id();
1737 static_cast<AppListItemView*>(item_view)->item()->id(); 1735 AppListItemView* target_view = GetViewAtSlotOnCurrentPage(target.slot);
1738 AppListItemView* target_view =
1739 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1740 const std::string& target_view_item_id = target_view->item()->id(); 1736 const std::string& target_view_item_id = target_view->item()->id();
1741 1737
1742 // Make change to data model. 1738 // Make change to data model.
1743 item_list_->RemoveObserver(this); 1739 item_list_->RemoveObserver(this);
1744 std::string folder_item_id = 1740 std::string folder_item_id =
1745 model_->MergeItems(target_view_item_id, source_item_id); 1741 model_->MergeItems(target_view_item_id, source_item_id);
1746 item_list_->AddObserver(this); 1742 item_list_->AddObserver(this);
1747 if (folder_item_id.empty()) { 1743 if (folder_item_id.empty()) {
1748 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id; 1744 LOG(ERROR) << "Unable to merge into item id: " << target_view_item_id;
1749 return; 1745 return;
(...skipping 20 matching lines...) Expand all
1770 int drag_view_index = view_model_.GetIndexOfView(drag_view_); 1766 int drag_view_index = view_model_.GetIndexOfView(drag_view_);
1771 view_model_.Remove(drag_view_index); 1767 view_model_.Remove(drag_view_index);
1772 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); 1768 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds());
1773 bounds_animator_.SetAnimationDelegate( 1769 bounds_animator_.SetAnimationDelegate(
1774 drag_view_, 1770 drag_view_,
1775 scoped_ptr<gfx::AnimationDelegate>( 1771 scoped_ptr<gfx::AnimationDelegate>(
1776 new ItemRemoveAnimationDelegate(drag_view_))); 1772 new ItemRemoveAnimationDelegate(drag_view_)));
1777 UpdatePaging(); 1773 UpdatePaging();
1778 } 1774 }
1779 1775
1780 void AppsGridView::ReparentItemForReorder(views::View* item_view, 1776 void AppsGridView::ReparentItemForReorder(AppListItemView* item_view,
1781 const Index& target) { 1777 const Index& target) {
1782 item_list_->RemoveObserver(this); 1778 item_list_->RemoveObserver(this);
1783 model_->RemoveObserver(this); 1779 model_->RemoveObserver(this);
1784 1780
1785 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item(); 1781 AppListItem* reparent_item = item_view->item();
1786 DCHECK(reparent_item->IsInFolder()); 1782 DCHECK(reparent_item->IsInFolder());
1787 const std::string source_folder_id = reparent_item->folder_id(); 1783 const std::string source_folder_id = reparent_item->folder_id();
1788 AppListFolderItem* source_folder = 1784 AppListFolderItem* source_folder =
1789 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); 1785 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1790 1786
1791 int target_model_index = GetModelIndexFromIndex(target); 1787 int target_model_index = GetModelIndexFromIndex(target);
1792 1788
1793 // Remove the source folder view if there is only 1 item in it, since the 1789 // Remove the source folder view if there is only 1 item in it, since the
1794 // source folder will be deleted after its only child item removed from it. 1790 // source folder will be deleted after its only child item removed from it.
1795 if (source_folder->ChildItemCount() == 1u) { 1791 if (source_folder->ChildItemCount() == 1u) {
(...skipping 16 matching lines...) Expand all
1812 model_->MoveItemToFolderAt(reparent_item, "", target_position); 1808 model_->MoveItemToFolderAt(reparent_item, "", target_position);
1813 view_model_.Move(current_model_index, target_model_index); 1809 view_model_.Move(current_model_index, target_model_index);
1814 1810
1815 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); 1811 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id);
1816 1812
1817 item_list_->AddObserver(this); 1813 item_list_->AddObserver(this);
1818 model_->AddObserver(this); 1814 model_->AddObserver(this);
1819 UpdatePaging(); 1815 UpdatePaging();
1820 } 1816 }
1821 1817
1822 void AppsGridView::ReparentItemToAnotherFolder(views::View* item_view, 1818 void AppsGridView::ReparentItemToAnotherFolder(AppListItemView* item_view,
1823 const Index& target) { 1819 const Index& target) {
1824 DCHECK(IsDraggingForReparentInRootLevelGridView()); 1820 DCHECK(IsDraggingForReparentInRootLevelGridView());
1825 1821
1826 AppListItemView* target_view = 1822 AppListItemView* target_view = GetViewAtSlotOnCurrentPage(target.slot);
1827 static_cast<AppListItemView*>(GetViewAtSlotOnCurrentPage(target.slot));
1828 if (!target_view) 1823 if (!target_view)
1829 return; 1824 return;
1830 1825
1831 // Make change to data model. 1826 // Make change to data model.
1832 item_list_->RemoveObserver(this); 1827 item_list_->RemoveObserver(this);
1833 1828
1834 AppListItem* reparent_item = static_cast<AppListItemView*>(item_view)->item(); 1829 AppListItem* reparent_item = item_view->item();
1835 DCHECK(reparent_item->IsInFolder()); 1830 DCHECK(reparent_item->IsInFolder());
1836 const std::string source_folder_id = reparent_item->folder_id(); 1831 const std::string source_folder_id = reparent_item->folder_id();
1837 AppListFolderItem* source_folder = 1832 AppListFolderItem* source_folder =
1838 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id)); 1833 static_cast<AppListFolderItem*>(item_list_->FindItem(source_folder_id));
1839 1834
1840 // Remove the source folder view if there is only 1 item in it, since the 1835 // Remove the source folder view if there is only 1 item in it, since the
1841 // source folder will be deleted after its only child item merged into the 1836 // source folder will be deleted after its only child item merged into the
1842 // target item. 1837 // target item.
1843 if (source_folder->ChildItemCount() == 1u) 1838 if (source_folder->ChildItemCount() == 1u)
1844 DeleteItemViewAtIndex( 1839 DeleteItemViewAtIndex(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 target_icon_rect, 1930 target_icon_rect,
1936 false); /* animate like closing folder */ 1931 false); /* animate like closing folder */
1937 AddChildView(icon_view); 1932 AddChildView(icon_view);
1938 icon_view->SetBoundsRect(drag_view_icon_to_grid); 1933 icon_view->SetBoundsRect(drag_view_icon_to_grid);
1939 icon_view->TransformView(); 1934 icon_view->TransformView();
1940 } 1935 }
1941 1936
1942 void AppsGridView::CancelContextMenusOnCurrentPage() { 1937 void AppsGridView::CancelContextMenusOnCurrentPage() {
1943 int start = pagination_model_.selected_page() * tiles_per_page(); 1938 int start = pagination_model_.selected_page() * tiles_per_page();
1944 int end = std::min(view_model_.view_size(), start + tiles_per_page()); 1939 int end = std::min(view_model_.view_size(), start + tiles_per_page());
1945 for (int i = start; i < end; ++i) { 1940 for (int i = start; i < end; ++i)
1946 AppListItemView* view = 1941 GetItemViewAt(i)->CancelContextMenu();
1947 static_cast<AppListItemView*>(view_model_.view_at(i));
1948 view->CancelContextMenu();
1949 }
1950 } 1942 }
1951 1943
1952 void AppsGridView::DeleteItemViewAtIndex(int index) { 1944 void AppsGridView::DeleteItemViewAtIndex(int index) {
1953 views::View* item_view = view_model_.view_at(index); 1945 views::View* item_view = view_model_.view_at(index);
1954 view_model_.Remove(index); 1946 view_model_.Remove(index);
1955 if (item_view == drag_view_) 1947 if (item_view == drag_view_)
1956 drag_view_ = NULL; 1948 drag_view_ = NULL;
1957 delete item_view; 1949 delete item_view;
1958 } 1950 }
1959 1951
1960 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const { 1952 bool AppsGridView::IsPointWithinDragBuffer(const gfx::Point& point) const {
1961 gfx::Rect rect(GetLocalBounds()); 1953 gfx::Rect rect(GetLocalBounds());
1962 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx); 1954 rect.Inset(-kDragBufferPx, -kDragBufferPx, -kDragBufferPx, -kDragBufferPx);
1963 return rect.Contains(point); 1955 return rect.Contains(point);
1964 } 1956 }
1965 1957
1966 void AppsGridView::ButtonPressed(views::Button* sender, 1958 void AppsGridView::ButtonPressed(views::Button* sender,
1967 const ui::Event& event) { 1959 const ui::Event& event) {
1968 if (dragging()) 1960 if (dragging())
1969 return; 1961 return;
1970 1962
1971 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName)) 1963 if (strcmp(sender->GetClassName(), AppListItemView::kViewClassName))
1972 return; 1964 return;
1965 AppListItemView* pressed_item_view = static_cast<AppListItemView*>(sender);
1973 1966
1974 if (delegate_) { 1967 if (delegate_) {
1975 // Always set the previous activated_folder_item_view_ to be visible. This 1968 // Always set the previous activated_folder_item_view_ to be visible. This
1976 // prevents a case where the item would remain hidden due the 1969 // prevents a case where the item would remain hidden due the
1977 // |activated_folder_item_view_| changing during the animation. We only 1970 // |activated_folder_item_view_| changing during the animation. We only
1978 // need to track |activated_folder_item_view_| in the root level grid view. 1971 // need to track |activated_folder_item_view_| in the root level grid view.
1979 if (!folder_delegate_) { 1972 if (!folder_delegate_) {
1980 if (activated_folder_item_view_) 1973 if (activated_folder_item_view_)
1981 activated_folder_item_view_->SetVisible(true); 1974 activated_folder_item_view_->SetVisible(true);
1982 AppListItemView* pressed_item_view =
1983 static_cast<AppListItemView*>(sender);
1984 if (IsFolderItem(pressed_item_view->item())) 1975 if (IsFolderItem(pressed_item_view->item()))
1985 activated_folder_item_view_ = pressed_item_view; 1976 activated_folder_item_view_ = pressed_item_view;
1986 else 1977 else
1987 activated_folder_item_view_ = NULL; 1978 activated_folder_item_view_ = NULL;
1988 } 1979 }
1989 delegate_->ActivateApp(static_cast<AppListItemView*>(sender)->item(), 1980 delegate_->ActivateApp(pressed_item_view->item(), event.flags());
1990 event.flags());
1991 } 1981 }
1992 } 1982 }
1993 1983
1994 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) { 1984 void AppsGridView::OnListItemAdded(size_t index, AppListItem* item) {
1995 EndDrag(true); 1985 EndDrag(true);
1996 1986
1997 views::View* view = CreateViewForItemAtIndex(index); 1987 views::View* view = CreateViewForItemAtIndex(index);
1998 view_model_.Add(view, index); 1988 view_model_.Add(view, index);
1999 AddChildView(view); 1989 AddChildView(view);
2000 1990
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 SetVisible(false); 2061 SetVisible(false);
2072 } 2062 }
2073 2063
2074 bool AppsGridView::EnableFolderDragDropUI() { 2064 bool AppsGridView::EnableFolderDragDropUI() {
2075 // Enable drag and drop folder UI only if it is at the app list root level 2065 // Enable drag and drop folder UI only if it is at the app list root level
2076 // and the switch is on. 2066 // and the switch is on.
2077 return model_->folders_enabled() && !folder_delegate_; 2067 return model_->folders_enabled() && !folder_delegate_;
2078 } 2068 }
2079 2069
2080 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const { 2070 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const {
2081 views::View* target_view = GetViewAtIndex(drop_target); 2071 AppListItemView* target_view = GetViewAtIndex(drop_target);
2082 if (!target_view) 2072 if (!target_view)
2083 return false; 2073 return false;
2084 2074
2085 AppListItem* target_item = 2075 AppListItem* target_item = target_view->item();
2086 static_cast<AppListItemView*>(target_view)->item();
2087 // Items can be dropped into non-folders (which have no children) or folders 2076 // Items can be dropped into non-folders (which have no children) or folders
2088 // that have fewer than the max allowed items. 2077 // that have fewer than the max allowed items.
2089 // OEM folder does not allow to drag/drop other items in it. 2078 // OEM folder does not allow to drag/drop other items in it.
2090 return target_item->ChildItemCount() < kMaxFolderItems && 2079 return target_item->ChildItemCount() < kMaxFolderItems &&
2091 !IsOEMFolderItem(target_item); 2080 !IsOEMFolderItem(target_item);
2092 } 2081 }
2093 2082
2094 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( 2083 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint(
2095 const gfx::Point& point) const { 2084 const gfx::Point& point) const {
2096 gfx::Rect bounds = GetContentsBounds(); 2085 gfx::Rect bounds = GetContentsBounds();
(...skipping 21 matching lines...) Expand all
2118 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { 2107 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const {
2119 gfx::Rect bounds(GetContentsBounds()); 2108 gfx::Rect bounds(GetContentsBounds());
2120 gfx::Size total_tile_size = GetTotalTileSize(); 2109 gfx::Size total_tile_size = GetTotalTileSize();
2121 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(), 2110 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(),
2122 bounds.y() + row * total_tile_size.height()), 2111 bounds.y() + row * total_tile_size.height()),
2123 total_tile_size); 2112 total_tile_size);
2124 tile_bounds.ClampToCenteredSize(GetTileViewSize()); 2113 tile_bounds.ClampToCenteredSize(GetTileViewSize());
2125 return tile_bounds; 2114 return tile_bounds;
2126 } 2115 }
2127 2116
2128 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { 2117 AppListItemView* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) {
calamity 2014/09/26 01:47:26 Ugh. This needs to get a better name that indicate
Matt Giuca 2014/09/26 03:48:39 Done. Note that I called it GetViewDisplayedAtSlo
2129 if (slot < 0) 2118 if (slot < 0)
2130 return NULL; 2119 return NULL;
2131 2120
2132 // Calculate the original bound of the tile at |index|. 2121 // Calculate the original bound of the tile at |index|.
2133 int row = slot / cols_; 2122 int row = slot / cols_;
2134 int col = slot % cols_; 2123 int col = slot % cols_;
2135 gfx::Rect tile_rect = GetExpectedTileBounds(row, col); 2124 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2136 2125
2137 for (int i = 0; i < view_model_.view_size(); ++i) { 2126 for (int i = 0; i < view_model_.view_size(); ++i) {
2138 views::View* view = view_model_.view_at(i); 2127 AppListItemView* view = GetItemViewAt(i);
2139 if (view->bounds() == tile_rect && view != drag_view_) 2128 if (view->bounds() == tile_rect && view != drag_view_)
2140 return view; 2129 return view;
2141 } 2130 }
2142 return NULL; 2131 return NULL;
2143 } 2132 }
2144 2133
2145 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2134 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2146 bool is_target_folder) { 2135 bool is_target_folder) {
2147 AppListItemView* target_view = 2136 AppListItemView* target_view = GetViewAtSlotOnCurrentPage(target_index.slot);
2148 static_cast<AppListItemView*>(
2149 GetViewAtSlotOnCurrentPage(target_index.slot));
2150 if (target_view) 2137 if (target_view)
2151 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2138 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2152 } 2139 }
2153 2140
2154 } // namespace app_list 2141 } // namespace app_list
OLDNEW
« ui/app_list/views/apps_grid_view.h ('K') | « ui/app_list/views/apps_grid_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698