| 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" | 
|   11 #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" |   12 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 
|   13 #include "ui/app_list/views/app_list_item_view.h" |   13 #include "ui/app_list/views/app_list_item_view.h" | 
|   14 #include "ui/app_list/views/page_switcher.h" |   14 #include "ui/app_list/views/page_switcher.h" | 
|   15 #include "ui/app_list/views/pulsing_block_view.h" |   15 #include "ui/app_list/views/pulsing_block_view.h" | 
|   16 #include "ui/base/animation/animation.h" |   16 #include "ui/base/animation/animation.h" | 
|   17 #include "ui/base/events/event.h" |   17 #include "ui/base/events/event.h" | 
 |   18 #include "ui/compositor/scoped_layer_animation_settings.h" | 
|   18 #include "ui/views/border.h" |   19 #include "ui/views/border.h" | 
|   19 #include "ui/views/view_model_utils.h" |   20 #include "ui/views/view_model_utils.h" | 
|   20 #include "ui/views/widget/widget.h" |   21 #include "ui/views/widget/widget.h" | 
|   21  |   22  | 
|   22 #if defined(USE_AURA) |   23 #if defined(USE_AURA) | 
|   23 #include "ui/aura/root_window.h" |   24 #include "ui/aura/root_window.h" | 
|   24 #endif |   25 #endif | 
|   25  |   26  | 
|   26 namespace { |   27 namespace { | 
|   27  |   28  | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  194   if (drag_view_ || pulsing_blocks_model_.view_size()) |  195   if (drag_view_ || pulsing_blocks_model_.view_size()) | 
|  195     return; |  196     return; | 
|  196  |  197  | 
|  197   drag_view_ = view; |  198   drag_view_ = view; | 
|  198  |  199  | 
|  199   // 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 | 
|  200   // 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. | 
|  201   // 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) | 
|  202   // when a |drag_and_drop_host_| gets implemented. |  203   // when a |drag_and_drop_host_| gets implemented. | 
|  203   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 | 
 |  206     // drop host follows this layer. | 
 |  207     gfx::Vector2d delta = event.root_location() - | 
 |  208                           drag_view_->GetBoundsInScreen().CenterPoint(); | 
 |  209     delta.set_y(delta.y() + drag_view_->title()->size().height() / 2); | 
|  204     // 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 | 
|  205     // the OS dependent code to "lift off the dragged item". |  211     // the OS dependent code to "lift off the dragged item". | 
|  206     // Note that we cannot use SetVisible since it would remove the mouse input. |  | 
|  207     drag_view_->SetSize(gfx::Size()); |  | 
|  208     drag_and_drop_host_->CreateDragIconProxy(event.root_location(), |  212     drag_and_drop_host_->CreateDragIconProxy(event.root_location(), | 
|  209                                              view->model()->icon(), |  213                                              view->model()->icon(), | 
|  210                                              drag_view_, |  214                                              drag_view_, | 
 |  215                                              delta, | 
|  211                                              kDragAndDropProxyScale); |  216                                              kDragAndDropProxyScale); | 
 |  217     HideView(drag_view_, true); | 
|  212   } |  218   } | 
|  213   drag_start_ = event.location(); |  219   drag_start_ = event.location(); | 
|  214 } |  220 } | 
|  215  |  221  | 
|  216 void AppsGridView::UpdateDrag(AppListItemView* view, |  222 void AppsGridView::UpdateDrag(AppListItemView* view, | 
|  217                               Pointer pointer, |  223                               Pointer pointer, | 
|  218                               const ui::LocatedEvent& event) { |  224                               const ui::LocatedEvent& event) { | 
|  219   if (!dragging() && drag_view_ && |  225   if (!dragging() && drag_view_ && | 
|  220       ExceededDragThreshold(event.location() - drag_start_)) { |  226       ExceededDragThreshold(event.location() - drag_start_)) { | 
|  221     drag_pointer_ = pointer; |  227     drag_pointer_ = pointer; | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  237   MaybeStartPageFlipTimer(last_drag_point_); |  243   MaybeStartPageFlipTimer(last_drag_point_); | 
|  238  |  244  | 
|  239   gfx::Point page_switcher_point(last_drag_point_); |  245   gfx::Point page_switcher_point(last_drag_point_); | 
|  240   views::View::ConvertPointToTarget(this, page_switcher_view_, |  246   views::View::ConvertPointToTarget(this, page_switcher_view_, | 
|  241                                     &page_switcher_point); |  247                                     &page_switcher_point); | 
|  242   page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); |  248   page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); | 
|  243  |  249  | 
|  244   if (last_drop_target != drop_target_) |  250   if (last_drop_target != drop_target_) | 
|  245     AnimateToIdealBounds(); |  251     AnimateToIdealBounds(); | 
|  246  |  252  | 
|  247   if (drag_and_drop_host_) { |  253   if (drag_and_drop_host_) | 
|  248     drag_and_drop_host_->UpdateDragIconProxy(event.root_location()); |  254     drag_and_drop_host_->UpdateDragIconProxy(event.root_location()); | 
|  249     return; |  | 
|  250   } |  | 
|  251  |  255  | 
|  252   drag_view_->SetPosition( |  256   drag_view_->SetPosition( | 
|  253       gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); |  257       gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); | 
|  254 } |  258 } | 
|  255  |  259  | 
|  256 void AppsGridView::EndDrag(bool cancel) { |  260 void AppsGridView::EndDrag(bool cancel) { | 
|  257   if (forward_events_to_drag_and_drop_host_) { |  261   if (forward_events_to_drag_and_drop_host_) { | 
|  258     forward_events_to_drag_and_drop_host_ = false; |  262     forward_events_to_drag_and_drop_host_ = false; | 
|  259     drag_and_drop_host_->EndDrag(cancel); |  263     drag_and_drop_host_->EndDrag(cancel); | 
|  260   } else if (!cancel && dragging() && drag_view_) { |  264   } else if (!cancel && dragging() && drag_view_) { | 
|  261     CalculateDropTarget(last_drag_point_, true); |  265     CalculateDropTarget(last_drag_point_, true); | 
|  262     if (IsValidIndex(drop_target_)) |  266     if (IsValidIndex(drop_target_)) | 
|  263       MoveItemInModel(drag_view_, drop_target_); |  267       MoveItemInModel(drag_view_, drop_target_); | 
|  264   } |  268   } | 
|  265  |  269  | 
|  266   // In case we had a drag and drop proxy icon, we delete it and make the real |  | 
|  267   // item visible again. |  | 
|  268   if (drag_and_drop_host_) { |  270   if (drag_and_drop_host_) { | 
 |  271     // If we had a drag and drop proxy icon, we delete it and make the real | 
 |  272     // item visible again. | 
|  269     drag_and_drop_host_->DestroyDragIconProxy(); |  273     drag_and_drop_host_->DestroyDragIconProxy(); | 
|  270     // To avoid an incorrect animation on re-group, |drag_view_| gets positioned |  274     HideView(drag_view_, false); | 
|  271     // at its last known drag location. |  | 
|  272     drag_view_->SetPosition( |  | 
|  273         gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); |  | 
|  274   } |  275   } | 
|  275  |  276  | 
|  276   drag_pointer_ = NONE; |  277   drag_pointer_ = NONE; | 
|  277   drop_target_ = Index(); |  278   drop_target_ = Index(); | 
|  278   if (drag_view_) { |  279   if (drag_view_) { | 
|  279     drag_view_ = NULL; |  280     drag_view_ = NULL; | 
|  280     AnimateToIdealBounds(); |  281     AnimateToIdealBounds(); | 
|  281   } |  282   } | 
|  282  |  283  | 
|  283   page_flip_timer_.Stop(); |  284   page_flip_timer_.Stop(); | 
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  912   if (pagination_model_->is_valid_page(transition.target_page)) |  913   if (pagination_model_->is_valid_page(transition.target_page)) | 
|  913     Layout(); |  914     Layout(); | 
|  914 } |  915 } | 
|  915  |  916  | 
|  916 void AppsGridView::OnAppListModelStatusChanged() { |  917 void AppsGridView::OnAppListModelStatusChanged() { | 
|  917   UpdatePulsingBlockViews(); |  918   UpdatePulsingBlockViews(); | 
|  918   Layout(); |  919   Layout(); | 
|  919   SchedulePaint(); |  920   SchedulePaint(); | 
|  920 } |  921 } | 
|  921  |  922  | 
 |  923 void AppsGridView::HideView(views::View* view, bool hide) { | 
 |  924 #if defined(USE_AURA) | 
 |  925   ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 
 |  926   animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 
 |  927   view->layer()->SetOpacity(hide ? 0 : 1); | 
 |  928 #endif | 
 |  929 } | 
 |  930  | 
|  922 }  // namespace app_list |  931 }  // namespace app_list | 
| OLD | NEW |