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 | 8 |
9 #include "ui/app_list/app_list_item_model.h" | |
9 #include "ui/app_list/apps_grid_view_delegate.h" | 10 #include "ui/app_list/apps_grid_view_delegate.h" |
10 #include "ui/app_list/pagination_model.h" | 11 #include "ui/app_list/pagination_model.h" |
12 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | |
11 #include "ui/app_list/views/app_list_item_view.h" | 13 #include "ui/app_list/views/app_list_item_view.h" |
12 #include "ui/app_list/views/page_switcher.h" | 14 #include "ui/app_list/views/page_switcher.h" |
13 #include "ui/app_list/views/pulsing_block_view.h" | 15 #include "ui/app_list/views/pulsing_block_view.h" |
14 #include "ui/base/animation/animation.h" | 16 #include "ui/base/animation/animation.h" |
15 #include "ui/base/events/event.h" | 17 #include "ui/base/events/event.h" |
16 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
17 #include "ui/views/view_model_utils.h" | 19 #include "ui/views/view_model_utils.h" |
18 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
19 | 21 |
20 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 PaginationModel* pagination_model) | 103 PaginationModel* pagination_model) |
102 : model_(NULL), | 104 : model_(NULL), |
103 delegate_(delegate), | 105 delegate_(delegate), |
104 pagination_model_(pagination_model), | 106 pagination_model_(pagination_model), |
105 page_switcher_view_(new PageSwitcher(pagination_model)), | 107 page_switcher_view_(new PageSwitcher(pagination_model)), |
106 cols_(0), | 108 cols_(0), |
107 rows_per_page_(0), | 109 rows_per_page_(0), |
108 selected_view_(NULL), | 110 selected_view_(NULL), |
109 drag_view_(NULL), | 111 drag_view_(NULL), |
110 drag_pointer_(NONE), | 112 drag_pointer_(NONE), |
113 drag_and_drop_host_(NULL), | |
114 drag_and_drop_host_dispatched_drag_(false), | |
111 page_flip_target_(-1), | 115 page_flip_target_(-1), |
112 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 116 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
113 bounds_animator_(this) { | 117 bounds_animator_(this) { |
114 pagination_model_->AddObserver(this); | 118 pagination_model_->AddObserver(this); |
115 AddChildView(page_switcher_view_); | 119 AddChildView(page_switcher_view_); |
116 } | 120 } |
117 | 121 |
118 AppsGridView::~AppsGridView() { | 122 AppsGridView::~AppsGridView() { |
119 if (model_) { | 123 if (model_) { |
120 model_->RemoveObserver(this); | 124 model_->RemoveObserver(this); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 | 174 |
171 void AppsGridView::EnsureViewVisible(const views::View* view) { | 175 void AppsGridView::EnsureViewVisible(const views::View* view) { |
172 if (pagination_model_->has_transition()) | 176 if (pagination_model_->has_transition()) |
173 return; | 177 return; |
174 | 178 |
175 Index index = GetIndexOfView(view); | 179 Index index = GetIndexOfView(view); |
176 if (IsValidIndex(index)) | 180 if (IsValidIndex(index)) |
177 pagination_model_->SelectPage(index.page, false); | 181 pagination_model_->SelectPage(index.page, false); |
178 } | 182 } |
179 | 183 |
180 void AppsGridView::InitiateDrag(views::View* view, | 184 void AppsGridView::InitiateDrag(AppListItemView* view, |
181 Pointer pointer, | 185 Pointer pointer, |
182 const ui::LocatedEvent& event) { | 186 const ui::LocatedEvent& event) { |
183 if (drag_view_ || pulsing_blocks_model_.view_size()) | 187 if (drag_view_ || pulsing_blocks_model_.view_size()) |
184 return; | 188 return; |
185 | 189 |
186 drag_view_ = view; | 190 drag_view_ = view; |
187 drag_start_ = event.location(); | 191 drag_start_ = event.location(); |
188 } | 192 } |
189 | 193 |
190 void AppsGridView::UpdateDrag(views::View* view, | 194 void AppsGridView::UpdateDrag(AppListItemView* view, |
191 Pointer pointer, | 195 Pointer pointer, |
192 const ui::LocatedEvent& event) { | 196 const ui::LocatedEvent& event) { |
193 if (!dragging() && drag_view_ && | 197 if (!dragging() && drag_view_ && |
194 ExceededDragThreshold(event.location() - drag_start_)) { | 198 ExceededDragThreshold(event.location() - drag_start_)) { |
195 drag_pointer_ = pointer; | 199 drag_pointer_ = pointer; |
196 // Move the view to the front so that it appears on top of other views. | 200 // Move the view to the front so that it appears on top of other views. |
197 ReorderChildView(drag_view_, -1); | 201 ReorderChildView(drag_view_, -1); |
198 bounds_animator_.StopAnimatingView(drag_view_); | 202 bounds_animator_.StopAnimatingView(drag_view_); |
199 } | 203 } |
200 if (drag_pointer_ != pointer) | 204 if (drag_pointer_ != pointer) |
201 return; | 205 return; |
202 | 206 |
207 // If a drag and drop host is provided, see if the drag operation needs to be | |
208 // forwarded. | |
209 DispatchDragEventToDragAndDropHost(event); | |
203 ExtractDragLocation(event, &last_drag_point_); | 210 ExtractDragLocation(event, &last_drag_point_); |
204 | 211 |
205 const Index last_drop_target = drop_target_; | 212 const Index last_drop_target = drop_target_; |
206 CalculateDropTarget(last_drag_point_, false); | 213 CalculateDropTarget(last_drag_point_, false); |
207 MaybeStartPageFlipTimer(last_drag_point_); | 214 MaybeStartPageFlipTimer(last_drag_point_); |
208 | 215 |
209 gfx::Point page_switcher_point(last_drag_point_); | 216 gfx::Point page_switcher_point(last_drag_point_); |
210 views::View::ConvertPointToTarget(this, page_switcher_view_, | 217 views::View::ConvertPointToTarget(this, page_switcher_view_, |
211 &page_switcher_point); | 218 &page_switcher_point); |
212 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); | 219 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); |
213 | 220 |
214 if (last_drop_target != drop_target_) | 221 if (last_drop_target != drop_target_) |
215 AnimateToIdealBounds(); | 222 AnimateToIdealBounds(); |
216 drag_view_->SetPosition( | 223 drag_view_->SetPosition( |
217 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); | 224 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); |
218 } | 225 } |
219 | 226 |
220 void AppsGridView::EndDrag(bool cancel) { | 227 void AppsGridView::EndDrag(bool cancel) { |
221 if (!cancel && dragging() && drag_view_) { | 228 if (drag_and_drop_host_dispatched_drag_) { |
229 drag_and_drop_host_dispatched_drag_ = false; | |
230 drag_and_drop_host_->EndDrag(cancel); | |
231 } else if (!cancel && dragging() && drag_view_) { | |
222 CalculateDropTarget(last_drag_point_, true); | 232 CalculateDropTarget(last_drag_point_, true); |
223 if (IsValidIndex(drop_target_)) | 233 if (IsValidIndex(drop_target_)) |
224 MoveItemInModel(drag_view_, drop_target_); | 234 MoveItemInModel(drag_view_, drop_target_); |
225 } | 235 } |
226 | 236 |
227 drag_pointer_ = NONE; | 237 drag_pointer_ = NONE; |
228 drop_target_ = Index(); | 238 drop_target_ = Index(); |
229 if (drag_view_) { | 239 if (drag_view_) { |
230 drag_view_ = NULL; | 240 drag_view_ = NULL; |
231 AnimateToIdealBounds(); | 241 AnimateToIdealBounds(); |
232 } | 242 } |
233 | 243 |
234 page_flip_timer_.Stop(); | 244 page_flip_timer_.Stop(); |
235 page_flip_target_ = -1; | 245 page_flip_target_ = -1; |
236 } | 246 } |
237 | 247 |
238 bool AppsGridView::IsDraggedView(const views::View* view) const { | 248 bool AppsGridView::IsDraggedView(const views::View* view) const { |
239 return drag_view_ == view; | 249 return drag_view_ == view; |
240 } | 250 } |
241 | 251 |
252 void AppsGridView::SetDragAndDropHostOfCurrentAppList( | |
253 ApplicationDragAndDropHost* drag_and_drop_host) { | |
254 drag_and_drop_host_ = drag_and_drop_host; | |
255 } | |
256 | |
242 void AppsGridView::Prerender(int page_index) { | 257 void AppsGridView::Prerender(int page_index) { |
243 Layout(); | 258 Layout(); |
244 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); | 259 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); |
245 int end = std::min(view_model_.view_size(), | 260 int end = std::min(view_model_.view_size(), |
246 (page_index + 1 + kPrerenderPages) * tiles_per_page()); | 261 (page_index + 1 + kPrerenderPages) * tiles_per_page()); |
247 for (int i = start; i < end; i++) { | 262 for (int i = start; i < end; i++) { |
248 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); | 263 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); |
249 v->Prerender(); | 264 v->Prerender(); |
250 } | 265 } |
251 } | 266 } |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 } | 667 } |
653 | 668 |
654 // Limits to the last possible slot on last page. | 669 // Limits to the last possible slot on last page. |
655 if (drop_target_.page == pagination_model_->total_pages() - 1) { | 670 if (drop_target_.page == pagination_model_->total_pages() - 1) { |
656 drop_target_.slot = std::min( | 671 drop_target_.slot = std::min( |
657 (view_model_.view_size() - 1) % tiles_per_page(), | 672 (view_model_.view_size() - 1) % tiles_per_page(), |
658 drop_target_.slot); | 673 drop_target_.slot); |
659 } | 674 } |
660 } | 675 } |
661 | 676 |
677 void AppsGridView::DispatchDragEventToDragAndDropHost( | |
678 const ui::LocatedEvent& event) { | |
679 if (!drag_view_ || !drag_and_drop_host_) | |
680 return; | |
681 if (bounds().Contains(last_drag_point_)) { | |
682 // The event was issued inside the app menu and we should get all events. | |
683 if (drag_and_drop_host_dispatched_drag_) { | |
684 // The DnD host was previously called and needs to be informed that the | |
685 // session returns to the owner. | |
686 drag_and_drop_host_dispatched_drag_ = false; | |
687 drag_and_drop_host_->EndDrag(true); | |
688 } | |
689 } else { | |
690 // The event happened outside our app menu and we might need to dispatch. | |
691 if (drag_and_drop_host_dispatched_drag_) { | |
692 // Dispatch since we have already started. | |
693 if (!drag_and_drop_host_->Drag(event.root_location())) { | |
694 // The host is not active any longer and we cancel the operation. | |
695 drag_and_drop_host_dispatched_drag_ = false; | |
696 drag_and_drop_host_->EndDrag(true); | |
697 } | |
698 } else { | |
699 if (drag_and_drop_host_->StartDrag(drag_view_->model()->app_id(), | |
700 event.root_location())) { | |
James Cook
2013/04/30 18:03:00
nit: indentation
Mr4D (OOO till 08-26)
2013/04/30 18:22:48
Done.
| |
701 // From now on we forward the drag events. | |
702 drag_and_drop_host_dispatched_drag_ = true; | |
703 // Any flip operations are stopped. | |
704 page_flip_timer_.Stop(); | |
705 page_flip_target_ = -1; | |
706 } | |
707 } | |
708 } | |
709 } | |
710 | |
662 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { | 711 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { |
663 int new_page_flip_target = -1; | 712 int new_page_flip_target = -1; |
664 | 713 |
665 if (page_switcher_view_->bounds().Contains(drag_point)) { | 714 if (page_switcher_view_->bounds().Contains(drag_point)) { |
666 gfx::Point page_switcher_point(drag_point); | 715 gfx::Point page_switcher_point(drag_point); |
667 views::View::ConvertPointToTarget(this, page_switcher_view_, | 716 views::View::ConvertPointToTarget(this, page_switcher_view_, |
668 &page_switcher_point); | 717 &page_switcher_point); |
669 new_page_flip_target = | 718 new_page_flip_target = |
670 page_switcher_view_->GetPageForPoint(page_switcher_point); | 719 page_switcher_view_->GetPageForPoint(page_switcher_point); |
671 } | 720 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 Layout(); | 848 Layout(); |
800 } | 849 } |
801 | 850 |
802 void AppsGridView::OnAppListModelStatusChanged() { | 851 void AppsGridView::OnAppListModelStatusChanged() { |
803 UpdatePulsingBlockViews(); | 852 UpdatePulsingBlockViews(); |
804 Layout(); | 853 Layout(); |
805 SchedulePaint(); | 854 SchedulePaint(); |
806 } | 855 } |
807 | 856 |
808 } // namespace app_list | 857 } // namespace app_list |
OLD | NEW |