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

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

Issue 14533006: Drag and drop between app list and launcher - First patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 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_dnd_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
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 dnd_host_(NULL),
114 dnd_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 ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)) { 117 ALLOW_THIS_IN_INITIALIZER_LIST(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
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 dnd host is provided, see if the drag operation needs to be forwarded.
208 DispatchDragEventToDnDHost(event);
203 ExtractDragLocation(event, &last_drag_point_); 209 ExtractDragLocation(event, &last_drag_point_);
204 210
205 const Index last_drop_target = drop_target_; 211 const Index last_drop_target = drop_target_;
206 CalculateDropTarget(last_drag_point_, false); 212 CalculateDropTarget(last_drag_point_, false);
207 MaybeStartPageFlipTimer(last_drag_point_); 213 MaybeStartPageFlipTimer(last_drag_point_);
208 214
209 gfx::Point page_switcher_point(last_drag_point_); 215 gfx::Point page_switcher_point(last_drag_point_);
210 views::View::ConvertPointToTarget(this, page_switcher_view_, 216 views::View::ConvertPointToTarget(this, page_switcher_view_,
211 &page_switcher_point); 217 &page_switcher_point);
212 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); 218 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point);
213 219
214 if (last_drop_target != drop_target_) 220 if (last_drop_target != drop_target_)
215 AnimateToIdealBounds(); 221 AnimateToIdealBounds();
216 drag_view_->SetPosition( 222 drag_view_->SetPosition(
217 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); 223 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_));
218 } 224 }
219 225
220 void AppsGridView::EndDrag(bool cancel) { 226 void AppsGridView::EndDrag(bool cancel) {
221 if (!cancel && dragging() && drag_view_) { 227 if (dnd_host_dispatched_drag_) {
228 dnd_host_dispatched_drag_ = false;
229 dnd_host_->EndDrag(cancel);
230 } else if (!cancel && dragging() && drag_view_) {
222 CalculateDropTarget(last_drag_point_, true); 231 CalculateDropTarget(last_drag_point_, true);
223 if (IsValidIndex(drop_target_)) 232 if (IsValidIndex(drop_target_))
224 MoveItemInModel(drag_view_, drop_target_); 233 MoveItemInModel(drag_view_, drop_target_);
225 } 234 }
226 235
227 drag_pointer_ = NONE; 236 drag_pointer_ = NONE;
228 drop_target_ = Index(); 237 drop_target_ = Index();
229 if (drag_view_) { 238 if (drag_view_) {
230 drag_view_ = NULL; 239 drag_view_ = NULL;
231 AnimateToIdealBounds(); 240 AnimateToIdealBounds();
232 } 241 }
233 242
234 page_flip_timer_.Stop(); 243 page_flip_timer_.Stop();
235 page_flip_target_ = -1; 244 page_flip_target_ = -1;
236 } 245 }
237 246
238 bool AppsGridView::IsDraggedView(const views::View* view) const { 247 bool AppsGridView::IsDraggedView(const views::View* view) const {
239 return drag_view_ == view; 248 return drag_view_ == view;
240 } 249 }
241 250
251 void AppsGridView::SetAppListDnDHost(ApplicationDnDHost* dnd_host) {
252 dnd_host_ = dnd_host;
253 }
254
242 void AppsGridView::Prerender(int page_index) { 255 void AppsGridView::Prerender(int page_index) {
243 Layout(); 256 Layout();
244 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); 257 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page());
245 int end = std::min(view_model_.view_size(), 258 int end = std::min(view_model_.view_size(),
246 (page_index + 1 + kPrerenderPages) * tiles_per_page()); 259 (page_index + 1 + kPrerenderPages) * tiles_per_page());
247 for (int i = start; i < end; i++) { 260 for (int i = start; i < end; i++) {
248 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); 261 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i));
249 v->Prerender(); 262 v->Prerender();
250 } 263 }
251 } 264 }
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 665 }
653 666
654 // Limits to the last possible slot on last page. 667 // Limits to the last possible slot on last page.
655 if (drop_target_.page == pagination_model_->total_pages() - 1) { 668 if (drop_target_.page == pagination_model_->total_pages() - 1) {
656 drop_target_.slot = std::min( 669 drop_target_.slot = std::min(
657 (view_model_.view_size() - 1) % tiles_per_page(), 670 (view_model_.view_size() - 1) % tiles_per_page(),
658 drop_target_.slot); 671 drop_target_.slot);
659 } 672 }
660 } 673 }
661 674
675 void AppsGridView::DispatchDragEventToDnDHost(const ui::LocatedEvent& event) {
676 if (!drag_view_ || !dnd_host_)
677 return;
678 if (bounds().Contains(last_drag_point_)) {
679 // The event was issued inside the app menu and we should get all events.
680 if (dnd_host_dispatched_drag_) {
681 // The DnD host was previously called and needs to be informed that the
682 // session returns to the owner.
683 dnd_host_dispatched_drag_ = false;
684 dnd_host_->EndDrag(true);
685 }
686 } else {
687 // The event happened outside our app menu and we might need to dispatch.
688 if (dnd_host_dispatched_drag_) {
689 // Dispatch since we have already started.
690 if (!dnd_host_->Drag(event.root_location())) {
691 // The host is not active any longer and we cancel the operation.
692 dnd_host_dispatched_drag_ = false;
693 dnd_host_->EndDrag(true);
694 }
695 } else {
696 if (dnd_host_->StartDrag(drag_view_->model()->app_id(),
697 event.root_location())) {
698 // From now on we forward the drag events.
699 dnd_host_dispatched_drag_ = true;
700 // Any flip operations are stopped.
701 page_flip_timer_.Stop();
702 page_flip_target_ = -1;
703 }
704 }
705 }
706 }
707
662 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { 708 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) {
663 int new_page_flip_target = -1; 709 int new_page_flip_target = -1;
664 710
665 if (page_switcher_view_->bounds().Contains(drag_point)) { 711 if (page_switcher_view_->bounds().Contains(drag_point)) {
666 gfx::Point page_switcher_point(drag_point); 712 gfx::Point page_switcher_point(drag_point);
667 views::View::ConvertPointToTarget(this, page_switcher_view_, 713 views::View::ConvertPointToTarget(this, page_switcher_view_,
668 &page_switcher_point); 714 &page_switcher_point);
669 new_page_flip_target = 715 new_page_flip_target =
670 page_switcher_view_->GetPageForPoint(page_switcher_point); 716 page_switcher_view_->GetPageForPoint(page_switcher_point);
671 } 717 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 Layout(); 845 Layout();
800 } 846 }
801 847
802 void AppsGridView::OnAppListModelStatusChanged() { 848 void AppsGridView::OnAppListModelStatusChanged() {
803 UpdatePulsingBlockViews(); 849 UpdatePulsingBlockViews();
804 Layout(); 850 Layout();
805 SchedulePaint(); 851 SchedulePaint();
806 } 852 }
807 853
808 } // namespace app_list 854 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698