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

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

Issue 2870683002: ash: Remove ShelfModel id conversion functions. (Closed)
Patch Set: Address comments. Created 3 years, 7 months 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
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 void ShelfView::DestroyDragIconProxy() { 523 void ShelfView::DestroyDragIconProxy() {
524 drag_image_.reset(); 524 drag_image_.reset();
525 drag_image_offset_ = gfx::Vector2d(0, 0); 525 drag_image_offset_ = gfx::Vector2d(0, 0);
526 } 526 }
527 527
528 bool ShelfView::StartDrag(const std::string& app_id, 528 bool ShelfView::StartDrag(const std::string& app_id,
529 const gfx::Point& location_in_screen_coordinates) { 529 const gfx::Point& location_in_screen_coordinates) {
530 // Bail if an operation is already going on - or the cursor is not inside. 530 // Bail if an operation is already going on - or the cursor is not inside.
531 // This could happen if mouse / touch operations overlap. 531 // This could happen if mouse / touch operations overlap.
532 if (!drag_and_drop_shelf_id_.IsNull() || 532 if (!drag_and_drop_shelf_id_.IsNull() || app_id.empty() ||
533 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 533 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
534 return false; 534 return false;
535 535
536 // If the AppsGridView (which was dispatching this event) was opened by our 536 // If the AppsGridView (which was dispatching this event) was opened by our
537 // button, ShelfView dragging operations are locked and we have to unlock. 537 // button, ShelfView dragging operations are locked and we have to unlock.
538 CancelDrag(-1); 538 CancelDrag(-1);
539 drag_and_drop_item_pinned_ = false; 539 drag_and_drop_item_pinned_ = false;
540 drag_and_drop_app_id_ = app_id; 540 drag_and_drop_shelf_id_ = ShelfID(app_id);
541 drag_and_drop_shelf_id_ = model_->GetShelfIDForAppID(drag_and_drop_app_id_); 541 // Check if the application is pinned - if not, we have to pin it so
542 // Check if the application is known and pinned - if not, we have to pin it so
543 // that we can re-arrange the shelf order accordingly. Note that items have 542 // that we can re-arrange the shelf order accordingly. Note that items have
544 // to be pinned to give them the same (order) possibilities as a shortcut. 543 // to be pinned to give them the same (order) possibilities as a shortcut.
545 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble() 544 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble()
546 // returns true. At this time, we don't need to pin the item. 545 // returns true. At this time, we don't need to pin the item.
547 if (!IsShowingOverflowBubble() && 546 if (!IsShowingOverflowBubble() && !model_->IsAppPinned(app_id)) {
548 (drag_and_drop_shelf_id_.IsNull() || !model_->IsAppPinned(app_id))) {
549 model_->PinAppWithID(app_id); 547 model_->PinAppWithID(app_id);
550 drag_and_drop_shelf_id_ = model_->GetShelfIDForAppID(drag_and_drop_app_id_);
551 if (drag_and_drop_shelf_id_.IsNull())
552 return false;
553 drag_and_drop_item_pinned_ = true; 548 drag_and_drop_item_pinned_ = true;
554 } 549 }
555 views::View* drag_and_drop_view = 550 views::View* drag_and_drop_view =
556 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); 551 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
557 DCHECK(drag_and_drop_view); 552 DCHECK(drag_and_drop_view);
558 553
559 // Since there is already an icon presented by the caller, we hide this item 554 // Since there is already an icon presented by the caller, we hide this item
560 // for now. That has to be done by reducing the size since the visibility will 555 // for now. That has to be done by reducing the size since the visibility will
561 // change once a regrouping animation is performed. 556 // change once a regrouping animation is performed.
562 pre_drag_and_drop_size_ = drag_and_drop_view->size(); 557 pre_drag_and_drop_size_ = drag_and_drop_view->size();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 void ShelfView::EndDrag(bool cancel) { 593 void ShelfView::EndDrag(bool cancel) {
599 if (drag_and_drop_shelf_id_.IsNull()) 594 if (drag_and_drop_shelf_id_.IsNull())
600 return; 595 return;
601 596
602 views::View* drag_and_drop_view = 597 views::View* drag_and_drop_view =
603 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); 598 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
604 PointerReleasedOnButton(drag_and_drop_view, DRAG_AND_DROP, cancel); 599 PointerReleasedOnButton(drag_and_drop_view, DRAG_AND_DROP, cancel);
605 600
606 // Either destroy the temporarily created item - or - make the item visible. 601 // Either destroy the temporarily created item - or - make the item visible.
607 if (drag_and_drop_item_pinned_ && cancel) { 602 if (drag_and_drop_item_pinned_ && cancel) {
608 model_->UnpinAppWithID(drag_and_drop_app_id_); 603 model_->UnpinAppWithID(drag_and_drop_shelf_id_.app_id);
609 } else if (drag_and_drop_view) { 604 } else if (drag_and_drop_view) {
610 if (cancel) { 605 if (cancel) {
611 // When a hosted drag gets canceled, the item can remain in the same slot 606 // When a hosted drag gets canceled, the item can remain in the same slot
612 // and it might have moved within the bounds. In that case the item need 607 // and it might have moved within the bounds. In that case the item need
613 // to animate back to its correct location. 608 // to animate back to its correct location.
614 AnimateToIdealBounds(); 609 AnimateToIdealBounds();
615 } else { 610 } else {
616 drag_and_drop_view->SetSize(pre_drag_and_drop_size_); 611 drag_and_drop_view->SetSize(pre_drag_and_drop_size_);
617 } 612 }
618 } 613 }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 main_shelf_->EndDrag(cancel); 1033 main_shelf_->EndDrag(cancel);
1039 } else { 1034 } else {
1040 DCHECK(overflow_bubble_->IsShowing()); 1035 DCHECK(overflow_bubble_->IsShowing());
1041 overflow_bubble_->shelf_view()->EndDrag(cancel); 1036 overflow_bubble_->shelf_view()->EndDrag(cancel);
1042 } 1037 }
1043 } 1038 }
1044 1039
1045 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { 1040 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
1046 int current_index = view_model_->GetIndexOfView(drag_view_); 1041 int current_index = view_model_->GetIndexOfView(drag_view_);
1047 DCHECK_NE(-1, current_index); 1042 DCHECK_NE(-1, current_index);
1048 std::string dragged_app_id = 1043 std::string dragged_app_id = model_->items()[current_index].id.app_id;
1049 model_->GetAppIDForShelfID(model_->items()[current_index].id);
1050 1044
1051 gfx::Point screen_location = 1045 gfx::Point screen_location =
1052 WmWindow::Get(GetWidget()->GetNativeWindow()) 1046 WmWindow::Get(GetWidget()->GetNativeWindow())
1053 ->GetRootWindow() 1047 ->GetRootWindow()
1054 ->ConvertPointToScreen(event.root_location()); 1048 ->ConvertPointToScreen(event.root_location());
1055 1049
1056 // To avoid ugly forwards and backwards flipping we use different constants 1050 // To avoid ugly forwards and backwards flipping we use different constants
1057 // for ripping off / re-inserting the items. 1051 // for ripping off / re-inserting the items.
1058 if (dragged_off_shelf_) { 1052 if (dragged_off_shelf_) {
1059 // If the shelf/overflow bubble bounds contains |screen_location| we insert 1053 // If the shelf/overflow bubble bounds contains |screen_location| we insert
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 EndDragOnOtherShelf(false /* cancel */); 1187 EndDragOnOtherShelf(false /* cancel */);
1194 drag_view_->layer()->SetOpacity(1.0f); 1188 drag_view_->layer()->SetOpacity(1.0f);
1195 } else if (RemovableByRipOff(current_index) != REMOVABLE) { 1189 } else if (RemovableByRipOff(current_index) != REMOVABLE) {
1196 // Make sure we do not try to remove un-removable items like items which 1190 // Make sure we do not try to remove un-removable items like items which
1197 // were not pinned or have to be always there. 1191 // were not pinned or have to be always there.
1198 cancel = true; 1192 cancel = true;
1199 snap_back = true; 1193 snap_back = true;
1200 } else { 1194 } else {
1201 // Make sure the item stays invisible upon removal. 1195 // Make sure the item stays invisible upon removal.
1202 drag_view_->SetVisible(false); 1196 drag_view_->SetVisible(false);
1203 std::string app_id = 1197 model_->UnpinAppWithID(model_->items()[current_index].id.app_id);
1204 model_->GetAppIDForShelfID(model_->items()[current_index].id);
1205 model_->UnpinAppWithID(app_id);
1206 } 1198 }
1207 } 1199 }
1208 if (cancel || snap_back) { 1200 if (cancel || snap_back) {
1209 if (dragged_to_another_shelf_) { 1201 if (dragged_to_another_shelf_) {
1210 dragged_to_another_shelf_ = false; 1202 dragged_to_another_shelf_ = false;
1211 // Other shelf handles revert of dragged item. 1203 // Other shelf handles revert of dragged item.
1212 EndDragOnOtherShelf(false /* true */); 1204 EndDragOnOtherShelf(false /* true */);
1213 drag_view_->layer()->SetOpacity(1.0f); 1205 drag_view_->layer()->SetOpacity(1.0f);
1214 } else if (!cancelling_drag_model_changed_) { 1206 } else if (!cancelling_drag_model_changed_) {
1215 // Only do something if the change did not come through a model change. 1207 // Only do something if the change did not come through a model change.
(...skipping 21 matching lines...) Expand all
1237 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) const { 1229 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) const {
1238 DCHECK(index >= 0 && index < model_->item_count()); 1230 DCHECK(index >= 0 && index < model_->item_count());
1239 ShelfItemType type = model_->items()[index].type; 1231 ShelfItemType type = model_->items()[index].type;
1240 if (type == TYPE_APP_LIST || type == TYPE_DIALOG) 1232 if (type == TYPE_APP_LIST || type == TYPE_DIALOG)
1241 return NOT_REMOVABLE; 1233 return NOT_REMOVABLE;
1242 1234
1243 if (model_->items()[index].pinned_by_policy) 1235 if (model_->items()[index].pinned_by_policy)
1244 return NOT_REMOVABLE; 1236 return NOT_REMOVABLE;
1245 1237
1246 // Note: Only pinned app shortcuts can be removed! 1238 // Note: Only pinned app shortcuts can be removed!
1247 std::string app_id = model_->GetAppIDForShelfID(model_->items()[index].id); 1239 const std::string& app_id = model_->items()[index].id.app_id;
1248 return (type == TYPE_PINNED_APP && model_->IsAppPinned(app_id)) ? REMOVABLE 1240 return (type == TYPE_PINNED_APP && model_->IsAppPinned(app_id)) ? REMOVABLE
1249 : DRAGGABLE; 1241 : DRAGGABLE;
1250 } 1242 }
1251 1243
1252 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const { 1244 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const {
1253 switch (typea) { 1245 switch (typea) {
1254 case TYPE_PINNED_APP: 1246 case TYPE_PINNED_APP:
1255 case TYPE_BROWSER_SHORTCUT: 1247 case TYPE_BROWSER_SHORTCUT:
1256 return (typeb == TYPE_PINNED_APP || typeb == TYPE_BROWSER_SHORTCUT); 1248 return (typeb == TYPE_PINNED_APP || typeb == TYPE_BROWSER_SHORTCUT);
1257 case TYPE_APP_PANEL: 1249 case TYPE_APP_PANEL:
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 if (pointer == TOUCH && 1792 if (pointer == TOUCH &&
1801 (base::TimeTicks::Now() - touch_press_time_) < 1793 (base::TimeTicks::Now() - touch_press_time_) <
1802 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { 1794 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) {
1803 return false; 1795 return false;
1804 } 1796 }
1805 1797
1806 return true; 1798 return true;
1807 } 1799 }
1808 1800
1809 } // namespace ash 1801 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698