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

Unified Diff: ash/shelf/shelf_view.cc

Issue 2820693004: shelf: Allow dragging items from main shelf to overflow shelf. (Closed)
Patch Set: Fixed patch set 1 errors. Created 3 years, 8 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/shelf/shelf_view.cc
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc
index 434c5bfc76f6b15fee7922e1cf3c0695322809db..f9e99510304a13af647d61baf4a801accec33990 100644
--- a/ash/shelf/shelf_view.cc
+++ b/ash/shelf/shelf_view.cc
@@ -263,10 +263,10 @@ ShelfView::ShelfView(ShelfModel* model,
drag_and_drop_shelf_id_(0),
drag_replaced_view_(nullptr),
dragged_off_shelf_(false),
+ dragged_to_another_shelf_(false),
snap_back_from_rip_off_view_(nullptr),
overflow_mode_(false),
main_shelf_(nullptr),
- dragged_off_from_overflow_to_shelf_(false),
is_repost_event_on_same_item_(false),
last_pressed_index_(-1),
weak_factory_(this) {
@@ -754,8 +754,7 @@ void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() {
bool visible = i >= first_visible_index_ && i <= last_visible_index_;
// To track the dragging of |drag_view_| continuously, its visibility
// should be always true regardless of its position.
- if (dragged_off_from_overflow_to_shelf_ &&
- view_model_->view_at(i) == drag_view_)
+ if (dragged_to_another_shelf_ && view_model_->view_at(i) == drag_view_)
view_model_->view_at(i)->SetVisible(true);
else
view_model_->view_at(i)->SetVisible(visible);
@@ -1077,17 +1076,23 @@ bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
// If the shelf/overflow bubble bounds contains |screen_location| we insert
// the item back into the shelf.
if (GetBoundsForDragInsertInScreen().Contains(screen_location)) {
- if (dragged_off_from_overflow_to_shelf_) {
+ if (dragged_to_another_shelf_) {
// During the dragging an item from Shelf to Overflow, it can enter here
- // directly because both are located very closly.
- main_shelf_->EndDrag(true);
+ // directly because both are located very closely.
+ if (is_overflow_mode()) {
+ main_shelf_->EndDrag(true);
+ } else {
+ DCHECK(overflow_bubble_ && overflow_bubble_->IsShowing());
msw 2017/04/18 00:11:04 nit: just DCHECK(overflow_bubble_->IsShowing()); t
sammiequon 2017/04/18 18:57:45 Done.
+ overflow_bubble_->shelf_view()->EndDrag(true);
+ }
+
// Stops the animation of |drag_view_| and sets its bounds explicitly
- // becase ContinueDrag() stops its animation. Without this, unexpected
+ // because ContinueDrag() stops its animation. Without this, unexpected
// bounds will be set.
bounds_animator_->StopAnimatingView(drag_view_);
int drag_view_index = view_model_->GetIndexOfView(drag_view_);
drag_view_->SetBoundsRect(view_model_->ideal_bounds(drag_view_index));
- dragged_off_from_overflow_to_shelf_ = false;
+ dragged_to_another_shelf_ = false;
}
// Destroy our proxy view item.
DestroyDragIconProxy();
@@ -1103,18 +1108,44 @@ bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
} else if (is_overflow_mode() &&
main_shelf_->GetBoundsForDragInsertInScreen().Contains(
screen_location)) {
- if (!dragged_off_from_overflow_to_shelf_) {
- dragged_off_from_overflow_to_shelf_ = true;
+ // The item was dragged from the overflow shelf to the main shelf.
+ if (!dragged_to_another_shelf_) {
+ dragged_to_another_shelf_ = true;
drag_image_->SetOpacity(1.0f);
main_shelf_->StartDrag(dragged_app_id, screen_location);
} else {
main_shelf_->Drag(screen_location);
}
- } else if (dragged_off_from_overflow_to_shelf_) {
+ } else if (!is_overflow_mode() && overflow_bubble_ &&
+ overflow_bubble_->IsShowing() &&
+ overflow_bubble_->shelf_view()
+ ->GetBoundsForDragInsertInScreen()
+ .Contains(screen_location)) {
+ // The item was dragged from the main shelf to the overflow shelf.
+ if (!dragged_to_another_shelf_) {
+ dragged_to_another_shelf_ = true;
+ drag_image_->SetOpacity(1.0f);
+ overflow_bubble_->shelf_view()->StartDrag(dragged_app_id,
+ screen_location);
+ } else {
+ overflow_bubble_->shelf_view()->Drag(screen_location);
+ }
+ } else if (dragged_to_another_shelf_) {
// Makes the |drag_image_| partially disappear again.
- dragged_off_from_overflow_to_shelf_ = false;
+ dragged_to_another_shelf_ = false;
drag_image_->SetOpacity(kDraggedImageOpacity);
- main_shelf_->EndDrag(true);
+
+ if (is_overflow_mode()) {
+ main_shelf_->EndDrag(true);
+ } else {
+ DCHECK(overflow_bubble_ && overflow_bubble_->IsShowing());
+ overflow_bubble_->shelf_view()->EndDrag(true);
+ // After entering the overflow shelf the last item becomes visible
+ // again. Hide the last item when we exit the overflow shelf, otherwise
+ // a copy of the item we are dragging will appear on the overflow shelf.
+ overflow_bubble_->shelf_view()->last_visible_index_--;
+ }
+
bounds_animator_->StopAnimatingView(drag_view_);
int drag_view_index = view_model_->GetIndexOfView(drag_view_);
drag_view_->SetBoundsRect(view_model_->ideal_bounds(drag_view_index));
@@ -1140,6 +1171,12 @@ bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
if (current_index != model_->FirstPanelIndex() - 1) {
model_->Move(current_index, model_->FirstPanelIndex() - 1);
StartFadeInLastVisibleItem();
+
+ // If the overflow bubble is showing, the current item will swap to the
+ // back of the overflow shelf as well, so we tell the overflow shelf to
+ // not show their last item, which would be the current item.
+ if (overflow_bubble_ && overflow_bubble_->IsShowing())
+ overflow_bubble_->shelf_view()->last_visible_index_--;
} else if (is_overflow_mode()) {
// Overflow bubble should be shrunk when an item is ripped off.
PreferredSizeChanged();
@@ -1174,9 +1211,14 @@ void ShelfView::FinalizeRipOffDrag(bool cancel) {
bool snap_back = false;
// Items which cannot be dragged off will be handled as a cancel.
if (!cancel) {
- if (dragged_off_from_overflow_to_shelf_) {
- dragged_off_from_overflow_to_shelf_ = false;
- main_shelf_->EndDrag(false);
+ if (dragged_to_another_shelf_) {
+ dragged_to_another_shelf_ = false;
+ if (is_overflow_mode()) {
+ main_shelf_->EndDrag(false);
+ } else {
+ DCHECK(overflow_bubble_ && overflow_bubble_->IsShowing());
+ overflow_bubble_->shelf_view()->EndDrag(false);
+ }
drag_view_->layer()->SetOpacity(1.0f);
} else if (RemovableByRipOff(current_index) != REMOVABLE) {
// Make sure we do not try to remove un-removable items like items which
@@ -1192,10 +1234,15 @@ void ShelfView::FinalizeRipOffDrag(bool cancel) {
}
}
if (cancel || snap_back) {
- if (dragged_off_from_overflow_to_shelf_) {
- dragged_off_from_overflow_to_shelf_ = false;
- // Main shelf handles revert of dragged item.
- main_shelf_->EndDrag(true);
+ if (dragged_to_another_shelf_) {
+ dragged_to_another_shelf_ = false;
+ // Other shelf handles revert of dragged item.
+ if (is_overflow_mode()) {
+ main_shelf_->EndDrag(true);
+ } else {
+ DCHECK(overflow_bubble_ && overflow_bubble_->IsShowing());
+ overflow_bubble_->shelf_view()->EndDrag(true);
+ }
drag_view_->layer()->SetOpacity(1.0f);
} else if (!cancelling_drag_model_changed_) {
// Only do something if the change did not come through a model change.
@@ -1409,10 +1456,9 @@ gfx::Size ShelfView::GetPreferredSize() const {
// When an item is dragged off from the overflow bubble, it is moved to last
// position and and changed to invisible. Overflow bubble size should be
// shrunk to fit only for visible items.
- // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible
- // items in the shelf.
- if (is_overflow_mode() && dragged_off_shelf_ &&
- !dragged_off_from_overflow_to_shelf_ &&
+ // If |dragged_to_another_shelf_| is set, there will be no
+ // invisible items in the shelf.
+ if (is_overflow_mode() && dragged_off_shelf_ && !dragged_to_another_shelf_ &&
RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
last_button_index--;
« 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