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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 virtual void OnDragSourceCancel() OVERRIDE { | 176 virtual void OnDragSourceCancel() OVERRIDE { |
| 177 canceled_ = true; | 177 canceled_ = true; |
| 178 } | 178 } |
| 179 | 179 |
| 180 virtual void OnDragSourceDrop() OVERRIDE { | 180 virtual void OnDragSourceDrop() OVERRIDE { |
| 181 } | 181 } |
| 182 | 182 |
| 183 virtual void OnDragSourceMove() OVERRIDE { | 183 virtual void OnDragSourceMove() OVERRIDE { |
| 184 grid_view_->UpdateDrag(app_list::AppsGridView::MOUSE, | 184 grid_view_->UpdateDrag(app_list::AppsGridView::MOUSE, |
| 185 GetCursorInGridViewCoords()); | 185 GetCursorInGridViewCoords()); |
| 186 | |
| 187 // Don't turn pages if the cursor is dragged outside the view. | |
| 188 if (!IsCursorWithinGridView()) | |
| 189 grid_view_->StopPageFlipTimer(); | |
| 190 } | 186 } |
| 191 | 187 |
| 192 void SetupExchangeData(ui::OSExchangeData* data) { | 188 void SetupExchangeData(ui::OSExchangeData* data) { |
| 193 data->SetFilename(shortcut_path_); | 189 data->SetFilename(shortcut_path_); |
| 194 gfx::ImageSkia image(drag_view_->GetDragImage()); | 190 gfx::ImageSkia image(drag_view_->GetDragImage()); |
| 195 gfx::Size image_size(image.size()); | 191 gfx::Size image_size(image.size()); |
| 196 drag_utils::SetDragImageOnDataObject( | 192 drag_utils::SetDragImageOnDataObject( |
| 197 image, | 193 image, |
| 198 image.size(), | 194 image.size(), |
| 199 gfx::Vector2d(drag_view_offset_.x(), drag_view_offset_.y()), | 195 gfx::Vector2d(drag_view_offset_.x(), drag_view_offset_.y()), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 delegate_(delegate), | 233 delegate_(delegate), |
| 238 pagination_model_(pagination_model), | 234 pagination_model_(pagination_model), |
| 239 page_switcher_view_(new PageSwitcher(pagination_model)), | 235 page_switcher_view_(new PageSwitcher(pagination_model)), |
| 240 cols_(0), | 236 cols_(0), |
| 241 rows_per_page_(0), | 237 rows_per_page_(0), |
| 242 selected_view_(NULL), | 238 selected_view_(NULL), |
| 243 drag_view_(NULL), | 239 drag_view_(NULL), |
| 244 drag_pointer_(NONE), | 240 drag_pointer_(NONE), |
| 245 drag_and_drop_host_(NULL), | 241 drag_and_drop_host_(NULL), |
| 246 forward_events_to_drag_and_drop_host_(false), | 242 forward_events_to_drag_and_drop_host_(false), |
| 243 drag_start_page_(-1), | |
| 247 page_flip_target_(-1), | 244 page_flip_target_(-1), |
| 248 page_flip_delay_in_ms_(kPageFlipDelayInMs), | 245 page_flip_delay_in_ms_(kPageFlipDelayInMs), |
| 249 bounds_animator_(this) { | 246 bounds_animator_(this) { |
| 250 last_created_grid_view_for_test = this; | 247 last_created_grid_view_for_test = this; |
| 251 pagination_model_->AddObserver(this); | 248 pagination_model_->AddObserver(this); |
| 252 AddChildView(page_switcher_view_); | 249 AddChildView(page_switcher_view_); |
| 253 } | 250 } |
| 254 | 251 |
| 255 AppsGridView::~AppsGridView() { | 252 AppsGridView::~AppsGridView() { |
| 256 if (model_) { | 253 if (model_) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 | 313 |
| 317 void AppsGridView::InitiateDrag(AppListItemView* view, | 314 void AppsGridView::InitiateDrag(AppListItemView* view, |
| 318 Pointer pointer, | 315 Pointer pointer, |
| 319 const ui::LocatedEvent& event) { | 316 const ui::LocatedEvent& event) { |
| 320 DCHECK(view); | 317 DCHECK(view); |
| 321 if (drag_view_ || pulsing_blocks_model_.view_size()) | 318 if (drag_view_ || pulsing_blocks_model_.view_size()) |
| 322 return; | 319 return; |
| 323 | 320 |
| 324 drag_view_ = view; | 321 drag_view_ = view; |
| 325 drag_view_offset_ = event.location(); | 322 drag_view_offset_ = event.location(); |
| 323 drag_start_page_ = pagination_model_->selected_page(); | |
| 326 ExtractDragLocation(event, &drag_start_grid_view_); | 324 ExtractDragLocation(event, &drag_start_grid_view_); |
| 327 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); | 325 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); |
| 328 } | 326 } |
| 329 | 327 |
| 330 void AppsGridView::OnGotShortcutPath(const base::FilePath& path) { | 328 void AppsGridView::OnGotShortcutPath(const base::FilePath& path) { |
| 331 #if defined(OS_WIN) && !defined(USE_AURA) | 329 #if defined(OS_WIN) && !defined(USE_AURA) |
| 332 // Drag may have ended before we get the shortcut path. | 330 // Drag may have ended before we get the shortcut path. |
| 333 if (!synchronous_drag_) | 331 if (!synchronous_drag_) |
| 334 return; | 332 return; |
| 335 // Setting the shortcut path here means the next time we hit UpdateDrag() | 333 // Setting the shortcut path here means the next time we hit UpdateDrag() |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 HideView(drag_view_, false); | 439 HideView(drag_view_, false); |
| 442 } | 440 } |
| 443 | 441 |
| 444 // The drag can be ended after the synchronous drag is created but before it | 442 // The drag can be ended after the synchronous drag is created but before it |
| 445 // is Run(). | 443 // is Run(). |
| 446 CleanUpSynchronousDrag(); | 444 CleanUpSynchronousDrag(); |
| 447 | 445 |
| 448 drag_pointer_ = NONE; | 446 drag_pointer_ = NONE; |
| 449 drop_target_ = Index(); | 447 drop_target_ = Index(); |
| 450 drag_view_ = NULL; | 448 drag_view_ = NULL; |
| 449 drag_start_grid_view_ = gfx::Point(); | |
| 450 drag_start_page_ = -1; | |
| 451 drag_view_offset_ = gfx::Point(); | |
| 451 AnimateToIdealBounds(); | 452 AnimateToIdealBounds(); |
| 452 | 453 |
| 453 StopPageFlipTimer(); | 454 StopPageFlipTimer(); |
| 454 } | 455 } |
| 455 | 456 |
| 456 void AppsGridView::StopPageFlipTimer() { | 457 void AppsGridView::StopPageFlipTimer() { |
| 457 page_flip_timer_.Stop(); | 458 page_flip_timer_.Stop(); |
| 458 page_flip_target_ = -1; | 459 page_flip_target_ = -1; |
| 459 } | 460 } |
| 460 | 461 |
| (...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 | 892 // 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 | 893 // not have the scale transform. So no round error would be introduced and |
| 893 // it's okay to use View::ConvertPointToTarget. | 894 // it's okay to use View::ConvertPointToTarget. |
| 894 *drag_point = event.location(); | 895 *drag_point = event.location(); |
| 895 views::View::ConvertPointToTarget(drag_view_, this, drag_point); | 896 views::View::ConvertPointToTarget(drag_view_, this, drag_point); |
| 896 #endif | 897 #endif |
| 897 } | 898 } |
| 898 | 899 |
| 899 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, | 900 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, |
| 900 bool use_page_button_hovering) { | 901 bool use_page_button_hovering) { |
| 901 const int current_page = pagination_model_->selected_page(); | 902 int current_page = pagination_model_->selected_page(); |
| 903 gfx::Point point(drag_point); | |
| 904 if (!HitTestPoint(drag_point)) { | |
| 905 point = drag_start_grid_view_; | |
| 906 current_page = drag_start_page_; | |
| 907 } | |
| 902 | 908 |
| 903 if (use_page_button_hovering && | 909 if (use_page_button_hovering && |
| 904 page_switcher_view_->bounds().Contains(drag_point)) { | 910 page_switcher_view_->bounds().Contains(point)) { |
| 905 gfx::Point page_switcher_point(drag_point); | 911 gfx::Point page_switcher_point(point); |
| 906 views::View::ConvertPointToTarget(this, page_switcher_view_, | 912 views::View::ConvertPointToTarget(this, page_switcher_view_, |
| 907 &page_switcher_point); | 913 &page_switcher_point); |
| 908 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); | 914 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); |
| 909 if (pagination_model_->is_valid_page(page)) { | 915 if (pagination_model_->is_valid_page(page)) { |
| 910 drop_target_.page = page; | 916 drop_target_.page = page; |
| 911 drop_target_.slot = tiles_per_page() - 1; | 917 drop_target_.slot = tiles_per_page() - 1; |
| 912 } | 918 } |
| 913 } else { | 919 } else { |
| 914 const int drop_row = drag_point.y() / kPreferredTileHeight; | 920 const int drop_row = point.y() / kPreferredTileHeight; |
| 915 const int drop_col = std::min(cols_ - 1, | 921 const int drop_col = std::min(cols_ - 1, |
| 916 drag_point.x() / kPreferredTileWidth); | 922 point.x() / kPreferredTileWidth); |
| 917 | 923 |
| 918 drop_target_.page = current_page; | 924 drop_target_.page = current_page; |
| 919 drop_target_.slot = std::max(0, std::min( | 925 drop_target_.slot = std::max(0, std::min( |
| 920 tiles_per_page() - 1, | 926 tiles_per_page() - 1, |
| 921 drop_row * cols_ + drop_col)); | 927 drop_row * cols_ + drop_col)); |
| 922 } | 928 } |
| 923 | 929 |
| 924 // Limits to the last possible slot on last page. | 930 // Limits to the last possible slot on last page. |
| 925 if (drop_target_.page == pagination_model_->total_pages() - 1) { | 931 if (drop_target_.page == pagination_model_->total_pages() - 1) { |
| 926 drop_target_.slot = std::min( | 932 drop_target_.slot = std::min( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 // From now on we forward the drag events. | 989 // From now on we forward the drag events. |
| 984 forward_events_to_drag_and_drop_host_ = true; | 990 forward_events_to_drag_and_drop_host_ = true; |
| 985 // Any flip operations are stopped. | 991 // Any flip operations are stopped. |
| 986 StopPageFlipTimer(); | 992 StopPageFlipTimer(); |
| 987 } | 993 } |
| 988 } | 994 } |
| 989 } | 995 } |
| 990 } | 996 } |
| 991 | 997 |
| 992 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { | 998 void AppsGridView::MaybeStartPageFlipTimer(const gfx::Point& drag_point) { |
| 999 if (!HitTestPoint(drag_point)) | |
| 1000 StopPageFlipTimer(); | |
| 993 int new_page_flip_target = -1; | 1001 int new_page_flip_target = -1; |
| 994 | 1002 |
| 995 if (page_switcher_view_->bounds().Contains(drag_point)) { | 1003 if (page_switcher_view_->bounds().Contains(drag_point)) { |
| 996 gfx::Point page_switcher_point(drag_point); | 1004 gfx::Point page_switcher_point(drag_point); |
| 997 views::View::ConvertPointToTarget(this, page_switcher_view_, | 1005 views::View::ConvertPointToTarget(this, page_switcher_view_, |
| 998 &page_switcher_point); | 1006 &page_switcher_point); |
| 999 new_page_flip_target = | 1007 new_page_flip_target = |
| 1000 page_switcher_view_->GetPageForPoint(page_switcher_point); | 1008 page_switcher_view_->GetPageForPoint(page_switcher_point); |
| 1001 } | 1009 } |
| 1002 | 1010 |
| 1003 // TODO(xiyuan): Fix this for RTL. | 1011 // TODO(xiyuan): Fix this for RTL. |
| 1004 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) | 1012 if (new_page_flip_target == -1 && drag_point.x() < kPageFlipZoneSize) |
| 1005 new_page_flip_target = pagination_model_->selected_page() - 1; | 1013 new_page_flip_target = pagination_model_->selected_page() - 1; |
| 1006 | 1014 |
| 1007 if (new_page_flip_target == -1 && | 1015 if (new_page_flip_target == -1 && |
| 1008 drag_point.x() > width() - kPageFlipZoneSize) { | 1016 drag_point.x() > width() - kPageFlipZoneSize) { |
| 1009 new_page_flip_target = pagination_model_->selected_page() + 1; | 1017 new_page_flip_target = pagination_model_->selected_page() + 1; |
| 1010 } | 1018 } |
| 1011 | 1019 |
| 1012 if (new_page_flip_target == page_flip_target_) | 1020 if (new_page_flip_target == page_flip_target_) |
| 1013 return; | 1021 return; |
| 1014 | 1022 |
| 1015 if (pagination_model_->is_valid_page(new_page_flip_target)) { | 1023 if (pagination_model_->is_valid_page(new_page_flip_target)) { |
| 1024 StopPageFlipTimer(); | |
| 1016 page_flip_target_ = new_page_flip_target; | 1025 page_flip_target_ = new_page_flip_target; |
| 1017 page_flip_timer_.Stop(); | |
| 1018 | 1026 |
| 1019 if (page_flip_target_ != pagination_model_->selected_page()) { | 1027 if (page_flip_target_ != pagination_model_->selected_page()) { |
| 1020 page_flip_timer_.Start(FROM_HERE, | 1028 page_flip_timer_.Start(FROM_HERE, |
| 1021 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_), | 1029 base::TimeDelta::FromMilliseconds(page_flip_delay_in_ms_), |
| 1022 this, &AppsGridView::OnPageFlipTimer); | 1030 this, &AppsGridView::OnPageFlipTimer); |
| 1023 } | 1031 } |
| 1024 } else { | 1032 } else { |
| 1025 page_flip_target_ = -1; | 1033 StopPageFlipTimer(); |
|
xiyuan
2013/07/19 04:36:46
nit: We probably could move this to be before the
koz (OOO until 15th September)
2013/07/19 08:00:32
Done.
| |
| 1026 page_flip_timer_.Stop(); | |
| 1027 } | 1034 } |
| 1028 } | 1035 } |
| 1029 | 1036 |
| 1030 void AppsGridView::OnPageFlipTimer() { | 1037 void AppsGridView::OnPageFlipTimer() { |
| 1031 DCHECK(pagination_model_->is_valid_page(page_flip_target_)); | 1038 DCHECK(pagination_model_->is_valid_page(page_flip_target_)); |
| 1032 pagination_model_->SelectPage(page_flip_target_, true); | 1039 pagination_model_->SelectPage(page_flip_target_, true); |
| 1033 } | 1040 } |
| 1034 | 1041 |
| 1035 void AppsGridView::MoveItemInModel(views::View* item_view, | 1042 void AppsGridView::MoveItemInModel(views::View* item_view, |
| 1036 const Index& target) { | 1043 const Index& target) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 | 1158 |
| 1152 void AppsGridView::HideView(views::View* view, bool hide) { | 1159 void AppsGridView::HideView(views::View* view, bool hide) { |
| 1153 #if defined(USE_AURA) | 1160 #if defined(USE_AURA) |
| 1154 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1161 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
| 1155 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 1162 animator.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
| 1156 view->layer()->SetOpacity(hide ? 0 : 1); | 1163 view->layer()->SetOpacity(hide ? 0 : 1); |
| 1157 #endif | 1164 #endif |
| 1158 } | 1165 } |
| 1159 | 1166 |
| 1160 } // namespace app_list | 1167 } // namespace app_list |
| OLD | NEW |