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 "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 |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "ui/app_list/app_list_constants.h" | 13 #include "ui/app_list/app_list_constants.h" |
14 #include "ui/app_list/app_list_folder_item.h" | 14 #include "ui/app_list/app_list_folder_item.h" |
15 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
16 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
17 #include "ui/app_list/pagination_model.h" | 17 #include "ui/app_list/pagination_model.h" |
18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 18 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
19 #include "ui/app_list/views/app_list_folder_view.h" | 19 #include "ui/app_list/views/app_list_folder_view.h" |
20 #include "ui/app_list/views/app_list_item_view.h" | 20 #include "ui/app_list/views/app_list_item_view.h" |
21 #include "ui/app_list/views/apps_grid_view_delegate.h" | 21 #include "ui/app_list/views/apps_grid_view_delegate.h" |
22 #include "ui/app_list/views/page_switcher.h" | 22 #include "ui/app_list/views/page_switcher.h" |
23 #include "ui/app_list/views/pulsing_block_view.h" | 23 #include "ui/app_list/views/pulsing_block_view.h" |
24 #include "ui/app_list/views/top_icon_animation_view.h" | 24 #include "ui/app_list/views/top_icon_animation_view.h" |
25 #include "ui/aura/window.h" | |
26 #include "ui/aura/window_event_dispatcher.h" | |
25 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
26 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
27 #include "ui/gfx/animation/animation.h" | 29 #include "ui/gfx/animation/animation.h" |
28 #include "ui/views/border.h" | 30 #include "ui/views/border.h" |
29 #include "ui/views/controls/webview/webview.h" | 31 #include "ui/views/controls/webview/webview.h" |
30 #include "ui/views/view_model_utils.h" | 32 #include "ui/views/view_model_utils.h" |
31 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
32 | 34 |
33 #if defined(USE_AURA) | |
34 #include "ui/aura/window.h" | |
35 #include "ui/aura/window_event_dispatcher.h" | |
36 #if defined(OS_WIN) | |
37 #include "ui/views/win/hwnd_util.h" | |
38 #endif // defined(OS_WIN) | |
39 #endif // defined(USE_AURA) | |
40 | |
41 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
42 #include "base/command_line.h" | 36 #include "base/command_line.h" |
43 #include "base/files/file_path.h" | 37 #include "base/files/file_path.h" |
44 #include "base/win/shortcut.h" | 38 #include "base/win/shortcut.h" |
45 #include "ui/base/dragdrop/drag_utils.h" | 39 #include "ui/base/dragdrop/drag_utils.h" |
46 #include "ui/base/dragdrop/drop_target_win.h" | 40 #include "ui/base/dragdrop/drop_target_win.h" |
47 #include "ui/base/dragdrop/os_exchange_data.h" | 41 #include "ui/base/dragdrop/os_exchange_data.h" |
48 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 42 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
43 #include "ui/views/win/hwnd_util.h" | |
49 #endif | 44 #endif |
50 | 45 |
51 namespace app_list { | 46 namespace app_list { |
52 | 47 |
53 namespace { | 48 namespace { |
54 | 49 |
55 // Distance a drag needs to be from the app grid to be considered 'outside', at | 50 // Distance a drag needs to be from the app grid to be considered 'outside', at |
56 // which point we rearrange the apps to their pre-drag configuration, as a drop | 51 // which point we rearrange the apps to their pre-drag configuration, as a drop |
57 // then would be canceled. We have a buffer to make it easier to drag apps to | 52 // then would be canceled. We have a buffer to make it easier to drag apps to |
58 // other pages. | 53 // other pages. |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 } | 918 } |
924 } | 919 } |
925 | 920 |
926 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 921 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
927 // The drag_view_ might be pending for deletion, therefore view_model_ | 922 // The drag_view_ might be pending for deletion, therefore view_model_ |
928 // may have one more item than item_list_. | 923 // may have one more item than item_list_. |
929 DCHECK_LE(index, item_list_->item_count()); | 924 DCHECK_LE(index, item_list_->item_count()); |
930 AppListItemView* view = new AppListItemView(this, | 925 AppListItemView* view = new AppListItemView(this, |
931 item_list_->item_at(index)); | 926 item_list_->item_at(index)); |
932 view->SetIconSize(icon_size_); | 927 view->SetIconSize(icon_size_); |
933 #if defined(USE_AURA) | |
934 view->SetPaintToLayer(true); | 928 view->SetPaintToLayer(true); |
935 view->SetFillsBoundsOpaquely(false); | 929 view->SetFillsBoundsOpaquely(false); |
936 #endif | |
937 return view; | 930 return view; |
938 } | 931 } |
939 | 932 |
940 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( | 933 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( |
941 int model_index) const { | 934 int model_index) const { |
942 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); | 935 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); |
943 } | 936 } |
944 | 937 |
945 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { | 938 int AppsGridView::GetModelIndexFromIndex(const Index& index) const { |
946 return index.page * tiles_per_page() + index.slot; | 939 return index.page * tiles_per_page() + index.slot; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 // Determine page of |current| and |target|. -1 means in the left invisible | 1141 // Determine page of |current| and |target|. -1 means in the left invisible |
1149 // page, 0 is the center visible page and 1 means in the right invisible page. | 1142 // page, 0 is the center visible page and 1 means in the right invisible page. |
1150 const int current_page = current.x() < 0 ? -1 : | 1143 const int current_page = current.x() < 0 ? -1 : |
1151 current.x() >= width() ? 1 : 0; | 1144 current.x() >= width() ? 1 : 0; |
1152 const int target_page = target.x() < 0 ? -1 : | 1145 const int target_page = target.x() < 0 ? -1 : |
1153 target.x() >= width() ? 1 : 0; | 1146 target.x() >= width() ? 1 : 0; |
1154 | 1147 |
1155 const int dir = current_page < target_page || | 1148 const int dir = current_page < target_page || |
1156 (current_page == target_page && current.y() < target.y()) ? 1 : -1; | 1149 (current_page == target_page && current.y() < target.y()) ? 1 : -1; |
1157 | 1150 |
1158 #if defined(USE_AURA) | |
1159 scoped_ptr<ui::Layer> layer; | 1151 scoped_ptr<ui::Layer> layer; |
1160 if (animate_current) { | 1152 if (animate_current) { |
1161 layer = view->RecreateLayer(); | 1153 layer = view->RecreateLayer(); |
1162 layer->SuppressPaint(); | 1154 layer->SuppressPaint(); |
1163 | 1155 |
1164 view->SetFillsBoundsOpaquely(false); | 1156 view->SetFillsBoundsOpaquely(false); |
1165 view->layer()->SetOpacity(0.f); | 1157 view->layer()->SetOpacity(0.f); |
1166 } | 1158 } |
1167 | 1159 |
1168 gfx::Rect current_out(current); | 1160 gfx::Rect current_out(current); |
1169 current_out.Offset(dir * kPreferredTileWidth, 0); | 1161 current_out.Offset(dir * kPreferredTileWidth, 0); |
1170 #endif | |
1171 | 1162 |
1172 gfx::Rect target_in(target); | 1163 gfx::Rect target_in(target); |
1173 if (animate_target) | 1164 if (animate_target) |
1174 target_in.Offset(-dir * kPreferredTileWidth, 0); | 1165 target_in.Offset(-dir * kPreferredTileWidth, 0); |
1175 view->SetBoundsRect(target_in); | 1166 view->SetBoundsRect(target_in); |
1176 bounds_animator_.AnimateViewTo(view, target); | 1167 bounds_animator_.AnimateViewTo(view, target); |
1177 | 1168 |
1178 #if defined(USE_AURA) | |
1179 bounds_animator_.SetAnimationDelegate( | 1169 bounds_animator_.SetAnimationDelegate( |
1180 view, | 1170 view, |
1181 new RowMoveAnimationDelegate(view, layer.release(), current_out), | 1171 new RowMoveAnimationDelegate(view, layer.release(), current_out), |
1182 true); | 1172 true); |
1183 #endif | |
1184 } | 1173 } |
1185 | 1174 |
1186 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, | 1175 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, |
1187 gfx::Point* drag_point) { | 1176 gfx::Point* drag_point) { |
1188 #if defined(USE_AURA) && !defined(OS_WIN) | 1177 #if !defined(OS_WIN) |
tapted
2014/04/23 23:38:09
This one.. I'll actually need to refactor drag and
| |
1189 // Use root location of |event| instead of location in |drag_view_|'s | 1178 // Use root location of |event| instead of location in |drag_view_|'s |
1190 // coordinates because |drag_view_| has a scale transform and location | 1179 // coordinates because |drag_view_| has a scale transform and location |
1191 // could have integer round error and causes jitter. | 1180 // could have integer round error and causes jitter. |
1192 *drag_point = event.root_location(); | 1181 *drag_point = event.root_location(); |
1193 | 1182 |
1194 // GetWidget() could be NULL for tests. | 1183 // GetWidget() could be NULL for tests. |
1195 if (GetWidget()) { | 1184 if (GetWidget()) { |
1196 aura::Window::ConvertPointToTarget( | 1185 aura::Window::ConvertPointToTarget( |
1197 GetWidget()->GetNativeWindow()->GetRootWindow(), | 1186 GetWidget()->GetNativeWindow()->GetRootWindow(), |
1198 GetWidget()->GetNativeWindow(), | 1187 GetWidget()->GetNativeWindow(), |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 Layout(); | 1867 Layout(); |
1879 } | 1868 } |
1880 | 1869 |
1881 void AppsGridView::OnAppListModelStatusChanged() { | 1870 void AppsGridView::OnAppListModelStatusChanged() { |
1882 UpdatePulsingBlockViews(); | 1871 UpdatePulsingBlockViews(); |
1883 Layout(); | 1872 Layout(); |
1884 SchedulePaint(); | 1873 SchedulePaint(); |
1885 } | 1874 } |
1886 | 1875 |
1887 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { | 1876 void AppsGridView::SetViewHidden(views::View* view, bool hide, bool immediate) { |
1888 #if defined(USE_AURA) | |
1889 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1877 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
1890 animator.SetPreemptionStrategy( | 1878 animator.SetPreemptionStrategy( |
1891 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : | 1879 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : |
1892 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); | 1880 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); |
1893 view->layer()->SetOpacity(hide ? 0 : 1); | 1881 view->layer()->SetOpacity(hide ? 0 : 1); |
1894 #endif | |
1895 } | 1882 } |
1896 | 1883 |
1897 void AppsGridView::OnImplicitAnimationsCompleted() { | 1884 void AppsGridView::OnImplicitAnimationsCompleted() { |
1898 if (layer()->opacity() == 0.0f) | 1885 if (layer()->opacity() == 0.0f) |
1899 SetVisible(false); | 1886 SetVisible(false); |
1900 } | 1887 } |
1901 | 1888 |
1902 bool AppsGridView::EnableFolderDragDropUI() { | 1889 bool AppsGridView::EnableFolderDragDropUI() { |
1903 // Enable drag and drop folder UI only if it is at the app list root level | 1890 // Enable drag and drop folder UI only if it is at the app list root level |
1904 // and the switch is on and the target folder can still accept new items. | 1891 // and the switch is on and the target folder can still accept new items. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2085 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2072 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2086 bool is_target_folder) { | 2073 bool is_target_folder) { |
2087 AppListItemView* target_view = | 2074 AppListItemView* target_view = |
2088 static_cast<AppListItemView*>( | 2075 static_cast<AppListItemView*>( |
2089 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2076 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2090 if (target_view) | 2077 if (target_view) |
2091 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2078 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2092 } | 2079 } |
2093 | 2080 |
2094 } // namespace app_list | 2081 } // namespace app_list |
OLD | NEW |