Commit 709f5211 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

shelf: When dragged item is ripped off, hide it on shelf on all displays

The present CL fixes a bug where if you rip an item off the shelf on one
display, it shows at the right or bottom of the shelf on other displays.

Test: manual
Change-Id: I75813306ec0a11f3ac4ec39ed08ad736e5788fa0
Fixed: 1014721
Bug: 1014721
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161900
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762017}
parent d0cbcbc8
......@@ -232,6 +232,16 @@ void ShelfModel::OnItemStatusChanged(const ShelfID& id) {
observer.ShelfItemStatusChanged(id);
}
void ShelfModel::OnItemRippedOff() {
for (auto& observer : observers_)
observer.ShelfItemRippedOff();
}
void ShelfModel::OnItemReturnedFromRipOff(int index) {
for (auto& observer : observers_)
observer.ShelfItemReturnedFromRipOff(index);
}
void ShelfModel::RemoveNotificationRecord(const std::string& notification_id) {
auto notification_id_it = notification_id_to_app_id_.find(notification_id);
......
......@@ -120,6 +120,14 @@ class ASH_PUBLIC_EXPORT ShelfModel {
// has changed.
void OnItemStatusChanged(const ShelfID& id);
// Notifies observers that an item has been dragged off the shelf (it is still
// being dragged).
void OnItemRippedOff();
// Notifies observers that an item that was dragged off the shelf has been
// dragged back onto the shelf (it is still being dragged).
void OnItemReturnedFromRipOff(int index);
// Adds a record of the notification with this app id and notifies observers.
void AddNotificationRecord(const std::string& app_id,
const std::string& notification_id);
......
......@@ -41,6 +41,13 @@ class ASH_PUBLIC_EXPORT ShelfModelObserver {
// event.
virtual void ShelfItemStatusChanged(const ShelfID& id) {}
// Invoked after an item is dragged off the shelf (it is still being dragged).
virtual void ShelfItemRippedOff() {}
// Invoked after an item that has been dragged off the shelf is dragged back
// onto the shelf (it is still being dragged).
virtual void ShelfItemReturnedFromRipOff(int index) {}
protected:
virtual ~ShelfModelObserver() {}
};
......
......@@ -1301,6 +1301,8 @@ void ShelfView::ContinueDrag(const ui::LocatedEvent& event) {
DCHECK(drag_view_);
DCHECK_NE(-1, view_model_->GetIndexOfView(drag_view_));
const bool dragged_off_shelf_before = dragged_off_shelf_;
// Handle rip off functionality if this is not a drag and drop host operation
// and not the app list item.
if (drag_and_drop_shelf_id_.IsNull() &&
......@@ -1312,6 +1314,8 @@ void ShelfView::ContinueDrag(const ui::LocatedEvent& event) {
drag_scroll_dir_ = 0;
scrolling_timer_.Stop();
speed_up_drag_scrolling_.Stop();
if (!dragged_off_shelf_before)
model_->OnItemRippedOff();
return;
}
}
......@@ -1326,6 +1330,8 @@ void ShelfView::ContinueDrag(const ui::LocatedEvent& event) {
drag_point.y() - drag_origin_.y()));
drag_and_drop_host_->UpdateDragIconProxy(drag_point_in_screen -
drag_origin_.OffsetFromOrigin());
if (dragged_off_shelf_before)
model_->OnItemReturnedFromRipOff(view_model_->GetIndexOfView(drag_view_));
}
void ShelfView::MoveDragViewTo(int primary_axis_coordinate) {
......@@ -1920,6 +1926,27 @@ void ShelfView::ShelfItemStatusChanged(const ShelfID& id) {
button->SchedulePaint();
}
void ShelfView::ShelfItemRippedOff() {
// On the display where the drag started, there is nothing to do.
if (dragging())
return;
// When a dragged item has been ripped off the shelf, it is moved to the end.
// Now we need to hide it.
view_model_->view_at(model_->item_count() - 1)->layer()->SetOpacity(0.f);
}
void ShelfView::ShelfItemReturnedFromRipOff(int index) {
// On the display where the drag started, there is nothing to do.
if (dragging())
return;
// Show the item and prevent it from animating into place from the position
// where it was sitting with zero opacity.
views::View* view = view_model_->view_at(index);
view->SetBoundsRect(bounds_animator_->GetTargetBounds(view));
bounds_animator_->StopAnimatingView(view);
view->layer()->SetOpacity(1.f);
}
void ShelfView::OnShelfAlignmentChanged(aura::Window* root_window,
ShelfAlignment old_alignment) {
LayoutToIdealBounds();
......
......@@ -416,6 +416,8 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
ShelfItemDelegate* old_delegate,
ShelfItemDelegate* delegate) override;
void ShelfItemStatusChanged(const ShelfID& id) override;
void ShelfItemRippedOff() override;
void ShelfItemReturnedFromRipOff(int index) override;
// Overridden from ShellObserver:
void OnShelfAlignmentChanged(aura::Window* root_window,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment