Chromium Code Reviews| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 delegate_(delegate), | 237 delegate_(delegate), |
| 238 pagination_model_(pagination_model), | 238 pagination_model_(pagination_model), |
| 239 page_switcher_view_(new PageSwitcher(pagination_model)), | 239 page_switcher_view_(new PageSwitcher(pagination_model)), |
| 240 cols_(0), | 240 cols_(0), |
| 241 rows_per_page_(0), | 241 rows_per_page_(0), |
| 242 selected_view_(NULL), | 242 selected_view_(NULL), |
| 243 drag_view_(NULL), | 243 drag_view_(NULL), |
| 244 drag_pointer_(NONE), | 244 drag_pointer_(NONE), |
| 245 drag_and_drop_host_(NULL), | 245 drag_and_drop_host_(NULL), |
| 246 forward_events_to_drag_and_drop_host_(false), | 246 forward_events_to_drag_and_drop_host_(false), |
| 247 drag_start_page_(-1), | |
| 247 page_flip_target_(-1), | 248 page_flip_target_(-1), |
| 248 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 249 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
| 249 bounds_animator_(this) { | 250 bounds_animator_(this) { |
| 250 last_created_grid_view_for_test = this; | 251 last_created_grid_view_for_test = this; |
| 251 pagination_model_->AddObserver(this); | 252 pagination_model_->AddObserver(this); |
| 252 AddChildView(page_switcher_view_); | 253 AddChildView(page_switcher_view_); |
| 253 } | 254 } |
| 254 | 255 |
| 255 AppsGridView::~AppsGridView() { | 256 AppsGridView::~AppsGridView() { |
| 256 if (model_) { | 257 if (model_) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 | 317 |
| 317 void AppsGridView::InitiateDrag(AppListItemView* view, | 318 void AppsGridView::InitiateDrag(AppListItemView* view, |
| 318 Pointer pointer, | 319 Pointer pointer, |
| 319 const ui::LocatedEvent& event) { | 320 const ui::LocatedEvent& event) { |
| 320 DCHECK(view); | 321 DCHECK(view); |
| 321 if (drag_view_ || pulsing_blocks_model_.view_size()) | 322 if (drag_view_ || pulsing_blocks_model_.view_size()) |
| 322 return; | 323 return; |
| 323 | 324 |
| 324 drag_view_ = view; | 325 drag_view_ = view; |
| 325 drag_view_offset_ = event.location(); | 326 drag_view_offset_ = event.location(); |
| 327 drag_start_page_ = pagination_model_->selected_page(); | |
| 326 ExtractDragLocation(event, &drag_start_grid_view_); | 328 ExtractDragLocation(event, &drag_start_grid_view_); |
| 327 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); | 329 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); |
| 328 } | 330 } |
| 329 | 331 |
| 330 void AppsGridView::OnGotShortcutPath(const base::FilePath& path) { | 332 void AppsGridView::OnGotShortcutPath(const base::FilePath& path) { |
| 331 #if defined(OS_WIN) && !defined(USE_AURA) | 333 #if defined(OS_WIN) && !defined(USE_AURA) |
| 332 // Drag may have ended before we get the shortcut path. | 334 // Drag may have ended before we get the shortcut path. |
| 333 if (!synchronous_drag_) | 335 if (!synchronous_drag_) |
| 334 return; | 336 return; |
| 335 // Setting the shortcut path here means the next time we hit UpdateDrag() | 337 // Setting the shortcut path here means the next time we hit UpdateDrag() |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 StartDragAndDropHostDrag(point); | 402 StartDragAndDropHostDrag(point); |
| 401 } | 403 } |
| 402 | 404 |
| 403 if (drag_pointer_ != pointer) | 405 if (drag_pointer_ != pointer) |
| 404 return; | 406 return; |
| 405 | 407 |
| 406 last_drag_point_ = point; | 408 last_drag_point_ = point; |
| 407 const Index last_drop_target = drop_target_; | 409 const Index last_drop_target = drop_target_; |
| 408 CalculateDropTarget(last_drag_point_, false); | 410 CalculateDropTarget(last_drag_point_, false); |
| 409 | 411 |
| 410 MaybeStartPageFlipTimer(last_drag_point_); | 412 MaybeStartPageFlipTimer(last_drag_point_); |
|
xiyuan
2013/07/19 01:06:33
I wonder if we should also update MaybeStartPageFl
koz (OOO until 15th September)
2013/07/19 04:03:57
Good idea! Done.
| |
| 411 | 413 |
| 412 gfx::Point page_switcher_point(last_drag_point_); | 414 gfx::Point page_switcher_point(last_drag_point_); |
| 413 views::View::ConvertPointToTarget(this, page_switcher_view_, | 415 views::View::ConvertPointToTarget(this, page_switcher_view_, |
| 414 &page_switcher_point); | 416 &page_switcher_point); |
| 415 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); | 417 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); |
| 416 | 418 |
| 417 if (last_drop_target != drop_target_) | 419 if (last_drop_target != drop_target_) |
| 418 AnimateToIdealBounds(); | 420 AnimateToIdealBounds(); |
| 419 | 421 |
| 420 drag_view_->SetPosition(drag_view_start_ + drag_vector); | 422 drag_view_->SetPosition(drag_view_start_ + drag_vector); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 441 HideView(drag_view_, false); | 443 HideView(drag_view_, false); |
| 442 } | 444 } |
| 443 | 445 |
| 444 // The drag can be ended after the synchronous drag is created but before it | 446 // The drag can be ended after the synchronous drag is created but before it |
| 445 // is Run(). | 447 // is Run(). |
| 446 CleanUpSynchronousDrag(); | 448 CleanUpSynchronousDrag(); |
| 447 | 449 |
| 448 drag_pointer_ = NONE; | 450 drag_pointer_ = NONE; |
| 449 drop_target_ = Index(); | 451 drop_target_ = Index(); |
| 450 drag_view_ = NULL; | 452 drag_view_ = NULL; |
| 453 drag_start_grid_view_ = gfx::Point(); | |
| 454 drag_start_page_ = -1; | |
| 455 drag_view_offset_ = gfx::Point(); | |
| 451 AnimateToIdealBounds(); | 456 AnimateToIdealBounds(); |
| 452 | 457 |
| 453 StopPageFlipTimer(); | 458 StopPageFlipTimer(); |
| 454 } | 459 } |
| 455 | 460 |
| 456 void AppsGridView::StopPageFlipTimer() { | 461 void AppsGridView::StopPageFlipTimer() { |
| 457 page_flip_timer_.Stop(); | 462 page_flip_timer_.Stop(); |
| 458 page_flip_target_ = -1; | 463 page_flip_target_ = -1; |
| 459 } | 464 } |
| 460 | 465 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 // For non-aura, root location is not clearly defined but |drag_view_| does | 896 // For non-aura, root location is not clearly defined but |drag_view_| does |
| 892 // not have the scale transform. So no round error would be introduced and | 897 // not have the scale transform. So no round error would be introduced and |
| 893 // it's okay to use View::ConvertPointToTarget. | 898 // it's okay to use View::ConvertPointToTarget. |
| 894 *drag_point = event.location(); | 899 *drag_point = event.location(); |
| 895 views::View::ConvertPointToTarget(drag_view_, this, drag_point); | 900 views::View::ConvertPointToTarget(drag_view_, this, drag_point); |
| 896 #endif | 901 #endif |
| 897 } | 902 } |
| 898 | 903 |
| 899 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, | 904 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, |
| 900 bool use_page_button_hovering) { | 905 bool use_page_button_hovering) { |
| 901 const int current_page = pagination_model_->selected_page(); | 906 int current_page = pagination_model_->selected_page(); |
| 907 gfx::Point point(drag_point); | |
| 908 if (!HitTestPoint(drag_point)) { | |
| 909 point = drag_start_grid_view_; | |
| 910 current_page = drag_start_page_; | |
|
xiyuan
2013/07/19 00:59:59
Should we jus return here? Otherwise, this would c
koz (OOO until 15th September)
2013/07/19 04:03:57
That's the intent of this change - to have the dra
xiyuan
2013/07/19 04:36:46
Okay. How about add a threshold for resetting to o
koz (OOO until 15th September)
2013/07/19 08:00:32
Yeah, that sounds good. Including turning the page
| |
| 911 } | |
| 902 | 912 |
| 903 if (use_page_button_hovering && | 913 if (use_page_button_hovering && |
| 904 page_switcher_view_->bounds().Contains(drag_point)) { | 914 page_switcher_view_->bounds().Contains(point)) { |
| 905 gfx::Point page_switcher_point(drag_point); | 915 gfx::Point page_switcher_point(point); |
| 906 views::View::ConvertPointToTarget(this, page_switcher_view_, | 916 views::View::ConvertPointToTarget(this, page_switcher_view_, |
| 907 &page_switcher_point); | 917 &page_switcher_point); |
| 908 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 918 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
| 909 if (pagination_model_->is_valid_page(page)) { | 919 if (pagination_model_->is_valid_page(page)) { |
| 910 drop_target_.page = page; | 920 drop_target_.page = page; |
| 911 drop_target_.slot = tiles_per_page() - 1; | 921 drop_target_.slot = tiles_per_page() - 1; |
| 912 } | 922 } |
| 913 } else { | 923 } else { |
| 914 const int drop_row = drag_point.y() / kPreferredTileHeight; | 924 const int drop_row = point.y() / kPreferredTileHeight; |
| 915 const int drop_col = std::min(cols_ - 1, | 925 const int drop_col = std::min(cols_ - 1, |
| 916 drag_point.x() / kPreferredTileWidth); | 926 point.x() / kPreferredTileWidth); |
| 917 | 927 |
| 918 drop_target_.page = current_page; | 928 drop_target_.page = current_page; |
| 919 drop_target_.slot = std::max(0, std::min( | 929 drop_target_.slot = std::max(0, std::min( |
| 920 tiles_per_page() - 1, | 930 tiles_per_page() - 1, |
| 921 drop_row * cols_ + drop_col)); | 931 drop_row * cols_ + drop_col)); |
| 922 } | 932 } |
| 923 | 933 |
| 924 // Limits to the last possible slot on last page. | 934 // Limits to the last possible slot on last page. |
| 925 if (drop_target_.page == pagination_model_->total_pages() - 1) { | 935 if (drop_target_.page == pagination_model_->total_pages() - 1) { |
| 926 drop_target_.slot = std::min( | 936 drop_target_.slot = std::min( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 | 1161 |
| 1152 void AppsGridView::HideView(views::View* view, bool hide) { | 1162 void AppsGridView::HideView(views::View* view, bool hide) { |
| 1153 #if defined(USE_AURA) | 1163 #if defined(USE_AURA) |
| 1154 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1164 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
| 1155 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 1165 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
| 1156 view->layer()->SetOpacity(hide ? 0 : 1); | 1166 view->layer()->SetOpacity(hide ? 0 : 1); |
| 1157 #endif | 1167 #endif |
| 1158 } | 1168 } |
| 1159 | 1169 |
| 1160 } // namespace app_list | 1170 } // namespace app_list |
| OLD | NEW |