| 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 "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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // change once a regrouping animation is performed. | 587 // change once a regrouping animation is performed. |
| 588 pre_drag_and_drop_size_ = drag_and_drop_view->size(); | 588 pre_drag_and_drop_size_ = drag_and_drop_view->size(); |
| 589 drag_and_drop_view->SetSize(gfx::Size()); | 589 drag_and_drop_view->SetSize(gfx::Size()); |
| 590 | 590 |
| 591 // First we have to center the mouse cursor over the item. | 591 // First we have to center the mouse cursor over the item. |
| 592 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); | 592 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); |
| 593 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt); | 593 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt); |
| 594 gfx::Point point_in_root = | 594 gfx::Point point_in_root = |
| 595 wm::GetRootWindowAt(location_in_screen_coordinates) | 595 wm::GetRootWindowAt(location_in_screen_coordinates) |
| 596 ->ConvertPointFromScreen(location_in_screen_coordinates); | 596 ->ConvertPointFromScreen(location_in_screen_coordinates); |
| 597 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, | 597 ui::MouseEvent event( |
| 598 ui::EventTimeForNow(), 0, 0); | 598 ui::ET_MOUSE_PRESSED, pt, point_in_root, ui::EventTimeForNow(), 0, 0, |
| 599 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 600 ui::PointerEvent::kMousePointerId)); |
| 599 PointerPressedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); | 601 PointerPressedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); |
| 600 | 602 |
| 601 // Drag the item where it really belongs. | 603 // Drag the item where it really belongs. |
| 602 Drag(location_in_screen_coordinates); | 604 Drag(location_in_screen_coordinates); |
| 603 return true; | 605 return true; |
| 604 } | 606 } |
| 605 | 607 |
| 606 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { | 608 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { |
| 607 if (!drag_and_drop_shelf_id_ || | 609 if (!drag_and_drop_shelf_id_ || |
| 608 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) | 610 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) |
| 609 return false; | 611 return false; |
| 610 | 612 |
| 611 gfx::Point pt = location_in_screen_coordinates; | 613 gfx::Point pt = location_in_screen_coordinates; |
| 612 views::View* drag_and_drop_view = | 614 views::View* drag_and_drop_view = |
| 613 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); | 615 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); |
| 614 ConvertPointFromScreen(drag_and_drop_view, &pt); | 616 ConvertPointFromScreen(drag_and_drop_view, &pt); |
| 615 gfx::Point point_in_root = | 617 gfx::Point point_in_root = |
| 616 wm::GetRootWindowAt(location_in_screen_coordinates) | 618 wm::GetRootWindowAt(location_in_screen_coordinates) |
| 617 ->ConvertPointFromScreen(location_in_screen_coordinates); | 619 ->ConvertPointFromScreen(location_in_screen_coordinates); |
| 618 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, | 620 ui::MouseEvent event( |
| 619 ui::EventTimeForNow(), 0, 0); | 621 ui::ET_MOUSE_DRAGGED, pt, point_in_root, ui::EventTimeForNow(), 0, 0, |
| 622 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 623 ui::PointerEvent::kMousePointerId)); |
| 620 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); | 624 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); |
| 621 return true; | 625 return true; |
| 622 } | 626 } |
| 623 | 627 |
| 624 void ShelfView::EndDrag(bool cancel) { | 628 void ShelfView::EndDrag(bool cancel) { |
| 625 if (!drag_and_drop_shelf_id_) | 629 if (!drag_and_drop_shelf_id_) |
| 626 return; | 630 return; |
| 627 | 631 |
| 628 views::View* drag_and_drop_view = | 632 views::View* drag_and_drop_view = |
| 629 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); | 633 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_)); |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 | 1771 |
| 1768 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1772 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1769 const gfx::Rect bounds = GetBoundsInScreen(); | 1773 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1770 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1774 int distance = wm_shelf_->SelectValueForShelfAlignment( |
| 1771 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1775 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1772 bounds.x() - coordinate.x()); | 1776 bounds.x() - coordinate.x()); |
| 1773 return distance > 0 ? distance : 0; | 1777 return distance > 0 ? distance : 0; |
| 1774 } | 1778 } |
| 1775 | 1779 |
| 1776 } // namespace ash | 1780 } // namespace ash |
| OLD | NEW |