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/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 Loading... | |
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 if (drag_view_ || pulsing_blocks_model_.view_size()) | 195 if (drag_view_ || pulsing_blocks_model_.view_size() || !view) |
xiyuan
2013/06/03 18:03:34
nit: DCHECK(view) to catch the error as well since
Mr4D (OOO till 08-26)
2013/06/03 18:35:16
Done.
| |
196 return; | 196 return; |
197 | 197 |
198 drag_view_ = view; | 198 drag_view_ = view; |
199 | 199 |
200 // When a drag and drop host is given, the item can be dragged out of the app | 200 // 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. | 201 // 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) | 202 // Note: This code has very likely to be changed for Windows (non metro mode) |
203 // when a |drag_and_drop_host_| gets implemented. | 203 // when a |drag_and_drop_host_| gets implemented. |
204 if (drag_and_drop_host_) { | 204 if (drag_and_drop_host_) { |
205 // Determine the mouse offset to the center of the icon so that the drag and | 205 // Determine the mouse offset to the center of the icon so that the drag and |
206 // drop host follows this layer. | 206 // drop host follows this layer. |
207 gfx::Vector2d delta = event.root_location() - | 207 gfx::Vector2d delta = event.root_location() - |
208 drag_view_->GetBoundsInScreen().CenterPoint(); | 208 drag_view_->GetBoundsInScreen().CenterPoint(); |
209 delta.set_y(delta.y() + drag_view_->title()->size().height() / 2); | 209 delta.set_y(delta.y() + drag_view_->title()->size().height() / 2); |
210 // We have to hide the original item since the drag and drop host will do | 210 // We have to hide the original item since the drag and drop host will do |
211 // the OS dependent code to "lift off the dragged item". | 211 // the OS dependent code to "lift off the dragged item". |
212 drag_and_drop_host_->CreateDragIconProxy(event.root_location(), | 212 drag_and_drop_host_->CreateDragIconProxy(event.root_location(), |
213 view->model()->icon(), | 213 view->model()->icon(), |
214 drag_view_, | 214 drag_view_, |
215 delta, | 215 delta, |
216 kDragAndDropProxyScale); | 216 kDragAndDropProxyScale); |
217 HideView(drag_view_, true); | 217 HideView(drag_view_, true); |
218 } | 218 } |
219 drag_start_ = event.location(); | 219 drag_start_ = event.location(); |
220 } | 220 } |
221 | 221 |
222 void AppsGridView::UpdateDrag(AppListItemView* view, | 222 void AppsGridView::UpdateDrag(AppListItemView* view, |
223 Pointer pointer, | 223 Pointer pointer, |
224 const ui::LocatedEvent& event) { | 224 const ui::LocatedEvent& event) { |
225 if (!dragging() && drag_view_ && | 225 // EndDrag was called before if |drag_view_| is NULL. |
226 ExceededDragThreshold(event.location() - drag_start_)) { | 226 if (!drag_view_) |
227 return; | |
228 | |
229 if (!dragging() && ExceededDragThreshold(event.location() - drag_start_)) { | |
227 drag_pointer_ = pointer; | 230 drag_pointer_ = pointer; |
228 // Move the view to the front so that it appears on top of other views. | 231 // Move the view to the front so that it appears on top of other views. |
229 ReorderChildView(drag_view_, -1); | 232 ReorderChildView(drag_view_, -1); |
230 bounds_animator_.StopAnimatingView(drag_view_); | 233 bounds_animator_.StopAnimatingView(drag_view_); |
231 } | 234 } |
232 if (drag_pointer_ != pointer) | 235 if (drag_pointer_ != pointer) |
233 return; | 236 return; |
234 | 237 |
235 ExtractDragLocation(event, &last_drag_point_); | 238 ExtractDragLocation(event, &last_drag_point_); |
236 const Index last_drop_target = drop_target_; | 239 const Index last_drop_target = drop_target_; |
(...skipping 14 matching lines...) Expand all Loading... | |
251 AnimateToIdealBounds(); | 254 AnimateToIdealBounds(); |
252 | 255 |
253 if (drag_and_drop_host_) | 256 if (drag_and_drop_host_) |
254 drag_and_drop_host_->UpdateDragIconProxy(event.root_location()); | 257 drag_and_drop_host_->UpdateDragIconProxy(event.root_location()); |
255 | 258 |
256 drag_view_->SetPosition( | 259 drag_view_->SetPosition( |
257 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); | 260 gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); |
258 } | 261 } |
259 | 262 |
260 void AppsGridView::EndDrag(bool cancel) { | 263 void AppsGridView::EndDrag(bool cancel) { |
264 // EndDrag was called before if |drag_view_| is NULL. | |
265 if (!drag_view_) | |
266 return; | |
267 | |
261 if (forward_events_to_drag_and_drop_host_) { | 268 if (forward_events_to_drag_and_drop_host_) { |
262 forward_events_to_drag_and_drop_host_ = false; | 269 forward_events_to_drag_and_drop_host_ = false; |
263 drag_and_drop_host_->EndDrag(cancel); | 270 drag_and_drop_host_->EndDrag(cancel); |
264 } else if (!cancel && dragging() && drag_view_) { | 271 } else if (!cancel && dragging()) { |
265 CalculateDropTarget(last_drag_point_, true); | 272 CalculateDropTarget(last_drag_point_, true); |
266 if (IsValidIndex(drop_target_)) | 273 if (IsValidIndex(drop_target_)) |
267 MoveItemInModel(drag_view_, drop_target_); | 274 MoveItemInModel(drag_view_, drop_target_); |
268 } | 275 } |
269 | 276 |
270 if (drag_and_drop_host_) { | 277 if (drag_and_drop_host_) { |
271 // If we had a drag and drop proxy icon, we delete it and make the real | 278 // If we had a drag and drop proxy icon, we delete it and make the real |
272 // item visible again. | 279 // item visible again. |
273 drag_and_drop_host_->DestroyDragIconProxy(); | 280 drag_and_drop_host_->DestroyDragIconProxy(); |
274 HideView(drag_view_, false); | 281 HideView(drag_view_, false); |
275 } | 282 } |
276 | 283 |
277 drag_pointer_ = NONE; | 284 drag_pointer_ = NONE; |
278 drop_target_ = Index(); | 285 drop_target_ = Index(); |
279 if (drag_view_) { | 286 drag_view_ = NULL; |
280 drag_view_ = NULL; | 287 AnimateToIdealBounds(); |
281 AnimateToIdealBounds(); | |
282 } | |
283 | 288 |
284 page_flip_timer_.Stop(); | 289 page_flip_timer_.Stop(); |
285 page_flip_target_ = -1; | 290 page_flip_target_ = -1; |
286 } | 291 } |
287 | 292 |
288 bool AppsGridView::IsDraggedView(const views::View* view) const { | 293 bool AppsGridView::IsDraggedView(const views::View* view) const { |
289 return drag_view_ == view; | 294 return drag_view_ == view; |
290 } | 295 } |
291 | 296 |
292 void AppsGridView::SetDragAndDropHostOfCurrentAppList( | 297 void AppsGridView::SetDragAndDropHostOfCurrentAppList( |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 | 927 |
923 void AppsGridView::HideView(views::View* view, bool hide) { | 928 void AppsGridView::HideView(views::View* view, bool hide) { |
924 #if defined(USE_AURA) | 929 #if defined(USE_AURA) |
925 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 930 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
926 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 931 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
927 view->layer()->SetOpacity(hide ? 0 : 1); | 932 view->layer()->SetOpacity(hide ? 0 : 1); |
928 #endif | 933 #endif |
929 } | 934 } |
930 | 935 |
931 } // namespace app_list | 936 } // namespace app_list |
OLD | NEW |