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

Side by Side Diff: ash/common/shelf/shelf_view.cc

Issue 2575613002: Remove ShelfItemDelegate::IsDraggable; check for app list button. (Closed)
Patch Set: Address comments. Created 4 years 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
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 "ash/common/shelf/shelf_view.h" 5 #include "ash/common/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/common/ash_constants.h" 10 #include "ash/common/ash_constants.h"
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 void ShelfView::PointerPressedOnButton(views::View* view, 791 void ShelfView::PointerPressedOnButton(views::View* view,
792 Pointer pointer, 792 Pointer pointer,
793 const ui::LocatedEvent& event) { 793 const ui::LocatedEvent& event) {
794 if (drag_view_) 794 if (drag_view_)
795 return; 795 return;
796 796
797 int index = view_model_->GetIndexOfView(view); 797 int index = view_model_->GetIndexOfView(view);
798 if (index == -1 || view_model_->view_size() <= 1) 798 if (index == -1 || view_model_->view_size() <= 1)
799 return; // View is being deleted, ignore request. 799 return; // View is being deleted, ignore request.
800 800
801 ShelfItemDelegate* item_delegate = 801 if (view == GetAppListButton())
802 model_->GetShelfItemDelegate(model_->items()[index].id);
803 if (!item_delegate->IsDraggable())
804 return; // View is not draggable, ignore request. 802 return; // View is not draggable, ignore request.
805 803
806 // Only when the repost event occurs on the same shelf item, we should ignore 804 // Only when the repost event occurs on the same shelf item, we should ignore
807 // the call in ShelfView::ButtonPressed(...). 805 // the call in ShelfView::ButtonPressed(...).
808 is_repost_event_on_same_item_ = 806 is_repost_event_on_same_item_ =
809 IsRepostEvent(event) && (last_pressed_index_ == index); 807 IsRepostEvent(event) && (last_pressed_index_ == index);
810 808
811 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 809 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
812 drag_view_ = static_cast<ShelfButton*>(view); 810 drag_view_ = static_cast<ShelfButton*>(view);
813 drag_origin_ = gfx::Point(event.x(), event.y()); 811 drag_origin_ = gfx::Point(event.x(), event.y());
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 DCHECK(!dragging()); 1095 DCHECK(!dragging());
1098 DCHECK(drag_view_); 1096 DCHECK(drag_view_);
1099 drag_pointer_ = pointer; 1097 drag_pointer_ = pointer;
1100 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); 1098 start_drag_index_ = view_model_->GetIndexOfView(drag_view_);
1101 1099
1102 if (start_drag_index_ == -1) { 1100 if (start_drag_index_ == -1) {
1103 CancelDrag(-1); 1101 CancelDrag(-1);
1104 return; 1102 return;
1105 } 1103 }
1106 1104
1107 // If the item is no longer draggable, bail out.
1108 ShelfItemDelegate* item_delegate =
1109 model_->GetShelfItemDelegate(model_->items()[start_drag_index_].id);
1110 if (!item_delegate->IsDraggable()) {
1111 CancelDrag(-1);
1112 return;
1113 }
1114
1115 // Move the view to the front so that it appears on top of other views. 1105 // Move the view to the front so that it appears on top of other views.
1116 ReorderChildView(drag_view_, -1); 1106 ReorderChildView(drag_view_, -1);
1117 bounds_animator_->StopAnimatingView(drag_view_); 1107 bounds_animator_->StopAnimatingView(drag_view_);
1118 1108
1119 drag_view_->OnDragStarted(&event); 1109 drag_view_->OnDragStarted(&event);
1120 } 1110 }
1121 1111
1122 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) { 1112 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) {
1113 DCHECK(dragging());
1114 DCHECK(drag_view_);
1123 // Due to a syncing operation the application might have been removed. 1115 // Due to a syncing operation the application might have been removed.
1124 // Bail if it is gone. 1116 // Bail if it is gone.
1125 int current_index = view_model_->GetIndexOfView(drag_view_); 1117 int current_index = view_model_->GetIndexOfView(drag_view_);
1126 DCHECK_NE(-1, current_index); 1118 DCHECK_NE(-1, current_index);
1127 1119
1128 ShelfItemDelegate* item_delegate =
1129 model_->GetShelfItemDelegate(model_->items()[current_index].id);
1130 if (!item_delegate->IsDraggable()) {
1131 CancelDrag(-1);
1132 return;
1133 }
1134
1135 // If this is not a drag and drop host operation and not the app list item, 1120 // If this is not a drag and drop host operation and not the app list item,
1136 // check if the item got ripped off the shelf - if it did we are done. 1121 // check if the item got ripped off the shelf - if it did we are done.
1137 if (!drag_and_drop_shelf_id_ && 1122 if (!drag_and_drop_shelf_id_ &&
1138 RemovableByRipOff(current_index) != NOT_REMOVABLE) { 1123 RemovableByRipOff(current_index) != NOT_REMOVABLE) {
1139 if (HandleRipOffDrag(event)) 1124 if (HandleRipOffDrag(event))
1140 return; 1125 return;
1141 // The rip off handler could have changed the location of the item. 1126 // The rip off handler could have changed the location of the item.
1142 current_index = view_model_->GetIndexOfView(drag_view_); 1127 current_index = view_model_->GetIndexOfView(drag_view_);
1143 } 1128 }
1144 1129
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 } 1162 }
1178 1163
1179 int target_index = views::ViewModelUtils::DetermineMoveIndex( 1164 int target_index = views::ViewModelUtils::DetermineMoveIndex(
1180 *view_model_, drag_view_, 1165 *view_model_, drag_view_,
1181 wm_shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL 1166 wm_shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL
1182 : views::ViewModelUtils::VERTICAL, 1167 : views::ViewModelUtils::VERTICAL,
1183 x, y); 1168 x, y);
1184 target_index = 1169 target_index =
1185 std::min(indices.second, std::max(target_index, indices.first)); 1170 std::min(indices.second, std::max(target_index, indices.first));
1186 1171
1187 int first_draggable_item = 0; 1172 // The app list button is always first, and it is the only non-draggable item.
1188 while (first_draggable_item < static_cast<int>(model_->items().size()) && 1173 int first_draggable_item = model_->GetItemIndexForType(TYPE_APP_LIST) + 1;
1189 !model_->GetShelfItemDelegate(model_->items()[first_draggable_item].id) 1174 DCHECK_EQ(1, first_draggable_item);
1190 ->IsDraggable()) {
1191 first_draggable_item++;
1192 }
1193
1194 target_index = std::max(target_index, first_draggable_item); 1175 target_index = std::max(target_index, first_draggable_item);
1176 DCHECK_LT(target_index, model_->item_count());
1195 1177
1196 if (target_index == current_index) 1178 if (target_index == current_index)
1197 return; 1179 return;
1198 1180
1199 // Change the model, the ShelfItemMoved() callback will handle the 1181 // Change the model, the ShelfItemMoved() callback will handle the
1200 // |view_model_| update. 1182 // |view_model_| update.
1201 model_->Move(current_index, target_index); 1183 model_->Move(current_index, target_index);
1202 bounds_animator_->StopAnimatingView(drag_view_); 1184 bounds_animator_->StopAnimatingView(drag_view_);
1203 } 1185 }
1204 1186
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 1881
1900 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1882 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1901 const gfx::Rect bounds = GetBoundsInScreen(); 1883 const gfx::Rect bounds = GetBoundsInScreen();
1902 int distance = wm_shelf_->SelectValueForShelfAlignment( 1884 int distance = wm_shelf_->SelectValueForShelfAlignment(
1903 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1885 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1904 bounds.x() - coordinate.x()); 1886 bounds.x() - coordinate.x());
1905 return distance > 0 ? distance : 0; 1887 return distance > 0 ? distance : 0;
1906 } 1888 }
1907 1889
1908 } // namespace ash 1890 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_item_delegate.h ('k') | ash/common/shelf/shelf_window_watcher_item_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698