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/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 drag_pointer_ = pointer; | 973 drag_pointer_ = pointer; |
974 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); | 974 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
975 | 975 |
976 if (start_drag_index_== -1) { | 976 if (start_drag_index_== -1) { |
977 CancelDrag(-1); | 977 CancelDrag(-1); |
978 return; | 978 return; |
979 } | 979 } |
980 | 980 |
981 // If the item is no longer draggable, bail out. | 981 // If the item is no longer draggable, bail out. |
982 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 982 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
983 model_->items()[start_drag_index_].type); | 983 model_->items()[start_drag_index_].id); |
984 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) { | 984 if (!item_delegate->IsDraggable()) { |
985 CancelDrag(-1); | 985 CancelDrag(-1); |
986 return; | 986 return; |
987 } | 987 } |
988 | 988 |
989 // Move the view to the front so that it appears on top of other views. | 989 // Move the view to the front so that it appears on top of other views. |
990 ReorderChildView(drag_view_, -1); | 990 ReorderChildView(drag_view_, -1); |
991 bounds_animator_->StopAnimatingView(drag_view_); | 991 bounds_animator_->StopAnimatingView(drag_view_); |
992 } | 992 } |
993 | 993 |
994 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { | 994 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
995 // Due to a syncing operation the application might have been removed. | 995 // Due to a syncing operation the application might have been removed. |
996 // Bail if it is gone. | 996 // Bail if it is gone. |
997 int current_index = view_model_->GetIndexOfView(drag_view_); | 997 int current_index = view_model_->GetIndexOfView(drag_view_); |
998 DCHECK_NE(-1, current_index); | 998 DCHECK_NE(-1, current_index); |
999 | 999 |
1000 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1000 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1001 model_->items()[current_index].type); | 1001 model_->items()[current_index].id); |
1002 if (!item_delegate->IsDraggable(model_->items()[current_index])) { | 1002 if (!item_delegate->IsDraggable()) { |
1003 CancelDrag(-1); | 1003 CancelDrag(-1); |
1004 return; | 1004 return; |
1005 } | 1005 } |
1006 | 1006 |
1007 // If this is not a drag and drop host operation and not the app list item, | 1007 // If this is not a drag and drop host operation and not the app list item, |
1008 // check if the item got ripped off the shelf - if it did we are done. | 1008 // check if the item got ripped off the shelf - if it did we are done. |
1009 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && | 1009 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && |
1010 RemovableByRipOff(current_index) != NOT_REMOVABLE) { | 1010 RemovableByRipOff(current_index) != NOT_REMOVABLE) { |
1011 if (HandleRipOffDrag(event)) | 1011 if (HandleRipOffDrag(event)) |
1012 return; | 1012 return; |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 Pointer pointer, | 1516 Pointer pointer, |
1517 const ui::LocatedEvent& event) { | 1517 const ui::LocatedEvent& event) { |
1518 if (drag_view_) | 1518 if (drag_view_) |
1519 return; | 1519 return; |
1520 | 1520 |
1521 int index = view_model_->GetIndexOfView(view); | 1521 int index = view_model_->GetIndexOfView(view); |
1522 if (index == -1) | 1522 if (index == -1) |
1523 return; | 1523 return; |
1524 | 1524 |
1525 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1525 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1526 model_->items()[index].type); | 1526 model_->items()[index].id); |
1527 if (view_model_->view_size() <= 1 || | 1527 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) |
1528 !item_delegate->IsDraggable(model_->items()[index])) | |
1529 return; // View is being deleted or not draggable, ignore request. | 1528 return; // View is being deleted or not draggable, ignore request. |
1530 | 1529 |
1531 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1530 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
1532 | 1531 |
1533 drag_view_ = view; | 1532 drag_view_ = view; |
1534 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); | 1533 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); |
1535 } | 1534 } |
1536 | 1535 |
1537 void LauncherView::PointerDraggedOnButton(views::View* view, | 1536 void LauncherView::PointerDraggedOnButton(views::View* view, |
1538 Pointer pointer, | 1537 Pointer pointer, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 tooltip_->StopTimer(); | 1587 tooltip_->StopTimer(); |
1589 } | 1588 } |
1590 | 1589 |
1591 base::string16 LauncherView::GetAccessibleName(const views::View* view) { | 1590 base::string16 LauncherView::GetAccessibleName(const views::View* view) { |
1592 int view_index = view_model_->GetIndexOfView(view); | 1591 int view_index = view_model_->GetIndexOfView(view); |
1593 // May be -1 while in the process of animating closed. | 1592 // May be -1 while in the process of animating closed. |
1594 if (view_index == -1) | 1593 if (view_index == -1) |
1595 return base::string16(); | 1594 return base::string16(); |
1596 | 1595 |
1597 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1596 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1598 model_->items()[view_index].type); | 1597 model_->items()[view_index].id); |
1599 return item_delegate->GetTitle(model_->items()[view_index]); | 1598 return item_delegate->GetTitle(); |
1600 } | 1599 } |
1601 | 1600 |
1602 void LauncherView::ButtonPressed(views::Button* sender, | 1601 void LauncherView::ButtonPressed(views::Button* sender, |
1603 const ui::Event& event) { | 1602 const ui::Event& event) { |
1604 // Do not handle mouse release during drag. | 1603 // Do not handle mouse release during drag. |
1605 if (dragging()) | 1604 if (dragging()) |
1606 return; | 1605 return; |
1607 | 1606 |
1608 if (sender == overflow_button_) { | 1607 if (sender == overflow_button_) { |
1609 ToggleOverflowBubble(); | 1608 ToggleOverflowBubble(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 case TYPE_APP_PANEL: | 1647 case TYPE_APP_PANEL: |
1649 break; | 1648 break; |
1650 | 1649 |
1651 case TYPE_UNDEFINED: | 1650 case TYPE_UNDEFINED: |
1652 NOTREACHED() << "LauncherItemType must be set."; | 1651 NOTREACHED() << "LauncherItemType must be set."; |
1653 break; | 1652 break; |
1654 } | 1653 } |
1655 | 1654 |
1656 LauncherItemDelegate* item_delegate = | 1655 LauncherItemDelegate* item_delegate = |
1657 item_manager_->GetLauncherItemDelegate( | 1656 item_manager_->GetLauncherItemDelegate( |
1658 model_->items()[view_index].type); | 1657 model_->items()[view_index].id); |
1659 item_delegate->ItemSelected(model_->items()[view_index], event); | 1658 item_delegate->ItemSelected(event); |
1660 | 1659 |
1661 ShowListMenuForView(model_->items()[view_index], sender, event); | 1660 ShowListMenuForView(model_->items()[view_index], sender, event); |
1662 } | 1661 } |
1663 } | 1662 } |
1664 | 1663 |
1665 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1664 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
1666 views::View* source, | 1665 views::View* source, |
1667 const ui::Event& event) { | 1666 const ui::Event& event) { |
1668 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1667 scoped_ptr<ash::LauncherMenuModel> menu_model; |
1669 LauncherItemDelegate* item_delegate = | 1668 LauncherItemDelegate* item_delegate = |
1670 item_manager_->GetLauncherItemDelegate(item.type); | 1669 item_manager_->GetLauncherItemDelegate(item.id); |
1671 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); | 1670 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); |
1672 | 1671 |
1673 // Make sure we have a menu and it has at least two items in addition to the | 1672 // Make sure we have a menu and it has at least two items in addition to the |
1674 // application title and the 3 spacing separators. | 1673 // application title and the 3 spacing separators. |
1675 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1674 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
1676 return false; | 1675 return false; |
1677 | 1676 |
1678 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1677 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1679 new LauncherMenuModelAdapter(menu_model.get())), | 1678 new LauncherMenuModelAdapter(menu_model.get())), |
1680 source, | 1679 source, |
1681 gfx::Point(), | 1680 gfx::Point(), |
(...skipping 12 matching lines...) Expand all Loading... |
1694 model_->items()[view_index].type == TYPE_APP_LIST) { | 1693 model_->items()[view_index].type == TYPE_APP_LIST) { |
1695 view_index = -1; | 1694 view_index = -1; |
1696 } | 1695 } |
1697 | 1696 |
1698 if (view_index == -1) { | 1697 if (view_index == -1) { |
1699 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1698 Shell::GetInstance()->ShowContextMenu(point, source_type); |
1700 return; | 1699 return; |
1701 } | 1700 } |
1702 scoped_ptr<ui::MenuModel> menu_model; | 1701 scoped_ptr<ui::MenuModel> menu_model; |
1703 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1702 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1704 model_->items()[view_index].type); | 1703 model_->items()[view_index].id); |
1705 menu_model.reset(item_delegate->CreateContextMenu( | 1704 menu_model.reset(item_delegate->CreateContextMenu( |
1706 model_->items()[view_index], | |
1707 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1705 source->GetWidget()->GetNativeView()->GetRootWindow())); |
1708 if (!menu_model) | 1706 if (!menu_model) |
1709 return; | 1707 return; |
1710 | 1708 |
1711 base::AutoReset<LauncherID> reseter( | 1709 base::AutoReset<LauncherID> reseter( |
1712 &context_menu_id_, | 1710 &context_menu_id_, |
1713 view_index == -1 ? 0 : model_->items()[view_index].id); | 1711 view_index == -1 ? 0 : model_->items()[view_index].id); |
1714 | 1712 |
1715 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1713 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1716 new views::MenuModelAdapter(menu_model.get())), | 1714 new views::MenuModelAdapter(menu_model.get())), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 } | 1850 } |
1853 | 1851 |
1854 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1852 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
1855 if (view == GetAppListButtonView() && | 1853 if (view == GetAppListButtonView() && |
1856 Shell::GetInstance()->GetAppListWindow()) | 1854 Shell::GetInstance()->GetAppListWindow()) |
1857 return false; | 1855 return false; |
1858 const LauncherItem* item = LauncherItemForView(view); | 1856 const LauncherItem* item = LauncherItemForView(view); |
1859 if (!item) | 1857 if (!item) |
1860 return true; | 1858 return true; |
1861 LauncherItemDelegate* item_delegate = | 1859 LauncherItemDelegate* item_delegate = |
1862 item_manager_->GetLauncherItemDelegate(item->type); | 1860 item_manager_->GetLauncherItemDelegate(item->id); |
1863 return item_delegate->ShouldShowTooltip(*item); | 1861 return item_delegate->ShouldShowTooltip(); |
1864 } | 1862 } |
1865 | 1863 |
1866 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1864 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
1867 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1865 ShelfWidget* shelf = RootWindowController::ForLauncher( |
1868 GetWidget()->GetNativeView())->shelf(); | 1866 GetWidget()->GetNativeView())->shelf(); |
1869 ash::ShelfAlignment align = shelf->GetAlignment(); | 1867 ash::ShelfAlignment align = shelf->GetAlignment(); |
1870 const gfx::Rect bounds = GetBoundsInScreen(); | 1868 const gfx::Rect bounds = GetBoundsInScreen(); |
1871 int distance = 0; | 1869 int distance = 0; |
1872 switch (align) { | 1870 switch (align) { |
1873 case ash::SHELF_ALIGNMENT_BOTTOM: | 1871 case ash::SHELF_ALIGNMENT_BOTTOM: |
1874 distance = bounds.y() - coordinate.y(); | 1872 distance = bounds.y() - coordinate.y(); |
1875 break; | 1873 break; |
1876 case ash::SHELF_ALIGNMENT_LEFT: | 1874 case ash::SHELF_ALIGNMENT_LEFT: |
1877 distance = coordinate.x() - bounds.right(); | 1875 distance = coordinate.x() - bounds.right(); |
1878 break; | 1876 break; |
1879 case ash::SHELF_ALIGNMENT_RIGHT: | 1877 case ash::SHELF_ALIGNMENT_RIGHT: |
1880 distance = bounds.x() - coordinate.x(); | 1878 distance = bounds.x() - coordinate.x(); |
1881 break; | 1879 break; |
1882 case ash::SHELF_ALIGNMENT_TOP: | 1880 case ash::SHELF_ALIGNMENT_TOP: |
1883 distance = coordinate.y() - bounds.bottom(); | 1881 distance = coordinate.y() - bounds.bottom(); |
1884 break; | 1882 break; |
1885 } | 1883 } |
1886 return distance > 0 ? distance : 0; | 1884 return distance > 0 ? distance : 0; |
1887 } | 1885 } |
1888 | 1886 |
1889 } // namespace internal | 1887 } // namespace internal |
1890 } // namespace ash | 1888 } // namespace ash |
OLD | NEW |