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

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

Issue 16295012: Made the EndDrag logic clearer by using |drag_view_| as Drag state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 7 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/app_list_item_model.h"
10 #include "ui/app_list/apps_grid_view_delegate.h" 10 #include "ui/app_list/apps_grid_view_delegate.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return; 185 return;
186 186
187 Index index = GetIndexOfView(view); 187 Index index = GetIndexOfView(view);
188 if (IsValidIndex(index)) 188 if (IsValidIndex(index))
189 pagination_model_->SelectPage(index.page, false); 189 pagination_model_->SelectPage(index.page, false);
190 } 190 }
191 191
192 void AppsGridView::InitiateDrag(AppListItemView* view, 192 void AppsGridView::InitiateDrag(AppListItemView* view,
193 Pointer pointer, 193 Pointer pointer,
194 const ui::LocatedEvent& event) { 194 const ui::LocatedEvent& event) {
195 DCHECK(view);
195 if (drag_view_ || pulsing_blocks_model_.view_size()) 196 if (drag_view_ || pulsing_blocks_model_.view_size())
196 return; 197 return;
197 198
198 drag_view_ = view; 199 drag_view_ = view;
199 200
200 // When a drag and drop host is given, the item can be dragged out of the app 201 // When a drag and drop host is given, the item can be dragged out of the app
201 // list window. In that case a proxy widget needs to be used. 202 // list window. In that case a proxy widget needs to be used.
202 // Note: This code has very likely to be changed for Windows (non metro mode) 203 // Note: This code has very likely to be changed for Windows (non metro mode)
203 // when a |drag_and_drop_host_| gets implemented. 204 // when a |drag_and_drop_host_| gets implemented.
204 if (drag_and_drop_host_) { 205 if (drag_and_drop_host_) {
(...skipping 10 matching lines...) Expand all
215 delta, 216 delta,
216 kDragAndDropProxyScale); 217 kDragAndDropProxyScale);
217 HideView(drag_view_, true); 218 HideView(drag_view_, true);
218 } 219 }
219 drag_start_ = event.location(); 220 drag_start_ = event.location();
220 } 221 }
221 222
222 void AppsGridView::UpdateDrag(AppListItemView* view, 223 void AppsGridView::UpdateDrag(AppListItemView* view,
223 Pointer pointer, 224 Pointer pointer,
224 const ui::LocatedEvent& event) { 225 const ui::LocatedEvent& event) {
225 if (!dragging() && drag_view_ && 226 // EndDrag was called before if |drag_view_| is NULL.
226 ExceededDragThreshold(event.location() - drag_start_)) { 227 if (!drag_view_)
228 return;
229
230 if (!dragging() && ExceededDragThreshold(event.location() - drag_start_)) {
227 drag_pointer_ = pointer; 231 drag_pointer_ = pointer;
228 // Move the view to the front so that it appears on top of other views. 232 // Move the view to the front so that it appears on top of other views.
229 ReorderChildView(drag_view_, -1); 233 ReorderChildView(drag_view_, -1);
230 bounds_animator_.StopAnimatingView(drag_view_); 234 bounds_animator_.StopAnimatingView(drag_view_);
231 } 235 }
232 if (drag_pointer_ != pointer) 236 if (drag_pointer_ != pointer)
233 return; 237 return;
234 238
235 ExtractDragLocation(event, &last_drag_point_); 239 ExtractDragLocation(event, &last_drag_point_);
236 const Index last_drop_target = drop_target_; 240 const Index last_drop_target = drop_target_;
(...skipping 14 matching lines...) Expand all
251 AnimateToIdealBounds(); 255 AnimateToIdealBounds();
252 256
253 if (drag_and_drop_host_) 257 if (drag_and_drop_host_)
254 drag_and_drop_host_->UpdateDragIconProxy(event.root_location()); 258 drag_and_drop_host_->UpdateDragIconProxy(event.root_location());
255 259
256 drag_view_->SetPosition( 260 drag_view_->SetPosition(
257 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); 261 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_));
258 } 262 }
259 263
260 void AppsGridView::EndDrag(bool cancel) { 264 void AppsGridView::EndDrag(bool cancel) {
265 // EndDrag was called before if |drag_view_| is NULL.
266 if (!drag_view_)
267 return;
268
261 if (forward_events_to_drag_and_drop_host_) { 269 if (forward_events_to_drag_and_drop_host_) {
262 forward_events_to_drag_and_drop_host_ = false; 270 forward_events_to_drag_and_drop_host_ = false;
263 drag_and_drop_host_->EndDrag(cancel); 271 drag_and_drop_host_->EndDrag(cancel);
264 } else if (!cancel && dragging() && drag_view_) { 272 } else if (!cancel && dragging()) {
265 CalculateDropTarget(last_drag_point_, true); 273 CalculateDropTarget(last_drag_point_, true);
266 if (IsValidIndex(drop_target_)) 274 if (IsValidIndex(drop_target_))
267 MoveItemInModel(drag_view_, drop_target_); 275 MoveItemInModel(drag_view_, drop_target_);
268 } 276 }
269 277
270 if (drag_and_drop_host_) { 278 if (drag_and_drop_host_) {
271 // If we had a drag and drop proxy icon, we delete it and make the real 279 // If we had a drag and drop proxy icon, we delete it and make the real
272 // item visible again. 280 // item visible again.
273 drag_and_drop_host_->DestroyDragIconProxy(); 281 drag_and_drop_host_->DestroyDragIconProxy();
274 HideView(drag_view_, false); 282 HideView(drag_view_, false);
275 } 283 }
276 284
277 drag_pointer_ = NONE; 285 drag_pointer_ = NONE;
278 drop_target_ = Index(); 286 drop_target_ = Index();
279 if (drag_view_) { 287 drag_view_ = NULL;
280 drag_view_ = NULL; 288 AnimateToIdealBounds();
281 AnimateToIdealBounds();
282 }
283 289
284 page_flip_timer_.Stop(); 290 page_flip_timer_.Stop();
285 page_flip_target_ = -1; 291 page_flip_target_ = -1;
286 } 292 }
287 293
288 bool AppsGridView::IsDraggedView(const views::View* view) const { 294 bool AppsGridView::IsDraggedView(const views::View* view) const {
289 return drag_view_ == view; 295 return drag_view_ == view;
290 } 296 }
291 297
292 void AppsGridView::SetDragAndDropHostOfCurrentAppList( 298 void AppsGridView::SetDragAndDropHostOfCurrentAppList(
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 928
923 void AppsGridView::HideView(views::View* view, bool hide) { 929 void AppsGridView::HideView(views::View* view, bool hide) {
924 #if defined(USE_AURA) 930 #if defined(USE_AURA)
925 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); 931 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
926 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 932 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
927 view->layer()->SetOpacity(hide ? 0 : 1); 933 view->layer()->SetOpacity(hide ? 0 : 1);
928 #endif 934 #endif
929 } 935 }
930 936
931 } // namespace app_list 937 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698