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 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 drag_pointer_ = pointer; | 979 drag_pointer_ = pointer; |
980 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); | 980 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
981 | 981 |
982 if (start_drag_index_== -1) { | 982 if (start_drag_index_== -1) { |
983 CancelDrag(-1); | 983 CancelDrag(-1); |
984 return; | 984 return; |
985 } | 985 } |
986 | 986 |
987 // If the item is no longer draggable, bail out. | 987 // If the item is no longer draggable, bail out. |
988 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 988 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
989 model_->items()[start_drag_index_].type); | 989 model_->items()[start_drag_index_].id); |
990 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) { | 990 if (item_delegate && !item_delegate->IsDraggable()) { |
991 CancelDrag(-1); | 991 CancelDrag(-1); |
992 return; | 992 return; |
993 } | 993 } |
994 | 994 |
995 // Move the view to the front so that it appears on top of other views. | 995 // Move the view to the front so that it appears on top of other views. |
996 ReorderChildView(drag_view_, -1); | 996 ReorderChildView(drag_view_, -1); |
997 bounds_animator_->StopAnimatingView(drag_view_); | 997 bounds_animator_->StopAnimatingView(drag_view_); |
998 } | 998 } |
999 | 999 |
1000 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { | 1000 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
1001 // Due to a syncing operation the application might have been removed. | 1001 // Due to a syncing operation the application might have been removed. |
1002 // Bail if it is gone. | 1002 // Bail if it is gone. |
1003 int current_index = view_model_->GetIndexOfView(drag_view_); | 1003 int current_index = view_model_->GetIndexOfView(drag_view_); |
1004 DCHECK_NE(-1, current_index); | 1004 DCHECK_NE(-1, current_index); |
1005 | 1005 |
1006 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1006 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1007 model_->items()[current_index].type); | 1007 model_->items()[current_index].id); |
1008 if (!item_delegate->IsDraggable(model_->items()[current_index])) { | 1008 if (item_delegate && !item_delegate->IsDraggable()) { |
1009 CancelDrag(-1); | 1009 CancelDrag(-1); |
1010 return; | 1010 return; |
1011 } | 1011 } |
1012 | 1012 |
1013 // If this is not a drag and drop host operation and not the app list item, | 1013 // If this is not a drag and drop host operation and not the app list item, |
1014 // check if the item got ripped off the shelf - if it did we are done. | 1014 // check if the item got ripped off the shelf - if it did we are done. |
1015 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && | 1015 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && |
1016 RemovableByRipOff(current_index) != NOT_REMOVABLE) { | 1016 RemovableByRipOff(current_index) != NOT_REMOVABLE) { |
1017 if (HandleRipOffDrag(event)) | 1017 if (HandleRipOffDrag(event)) |
1018 return; | 1018 return; |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1526 Pointer pointer, | 1526 Pointer pointer, |
1527 const ui::LocatedEvent& event) { | 1527 const ui::LocatedEvent& event) { |
1528 if (drag_view_) | 1528 if (drag_view_) |
1529 return; | 1529 return; |
1530 | 1530 |
1531 int index = view_model_->GetIndexOfView(view); | 1531 int index = view_model_->GetIndexOfView(view); |
1532 if (index == -1) | 1532 if (index == -1) |
1533 return; | 1533 return; |
1534 | 1534 |
1535 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1535 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1536 model_->items()[index].type); | 1536 model_->items()[index].id); |
1537 if (view_model_->view_size() <= 1 || | 1537 if (view_model_->view_size() <= 1 || |
1538 !item_delegate->IsDraggable(model_->items()[index])) | 1538 (item_delegate && !item_delegate->IsDraggable())) |
1539 return; // View is being deleted or not draggable, ignore request. | 1539 return; // View is being deleted or not draggable, ignore request. |
1540 | 1540 |
1541 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1541 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
1542 | 1542 |
1543 drag_view_ = view; | 1543 drag_view_ = view; |
1544 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); | 1544 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); |
1545 } | 1545 } |
1546 | 1546 |
1547 void LauncherView::PointerDraggedOnButton(views::View* view, | 1547 void LauncherView::PointerDraggedOnButton(views::View* view, |
1548 Pointer pointer, | 1548 Pointer pointer, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1598 tooltip_->StopTimer(); | 1598 tooltip_->StopTimer(); |
1599 } | 1599 } |
1600 | 1600 |
1601 base::string16 LauncherView::GetAccessibleName(const views::View* view) { | 1601 base::string16 LauncherView::GetAccessibleName(const views::View* view) { |
1602 int view_index = view_model_->GetIndexOfView(view); | 1602 int view_index = view_model_->GetIndexOfView(view); |
1603 // May be -1 while in the process of animating closed. | 1603 // May be -1 while in the process of animating closed. |
1604 if (view_index == -1) | 1604 if (view_index == -1) |
1605 return base::string16(); | 1605 return base::string16(); |
1606 | 1606 |
1607 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1607 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1608 model_->items()[view_index].type); | 1608 model_->items()[view_index].id); |
1609 return item_delegate->GetTitle(model_->items()[view_index]); | 1609 return item_delegate ? item_delegate->GetTitle() : base::string16(); |
1610 } | 1610 } |
1611 | 1611 |
1612 void LauncherView::ButtonPressed(views::Button* sender, | 1612 void LauncherView::ButtonPressed(views::Button* sender, |
1613 const ui::Event& event) { | 1613 const ui::Event& event) { |
1614 // Do not handle mouse release during drag. | 1614 // Do not handle mouse release during drag. |
1615 if (dragging()) | 1615 if (dragging()) |
1616 return; | 1616 return; |
1617 | 1617 |
1618 if (sender == overflow_button_) { | 1618 if (sender == overflow_button_) { |
1619 ToggleOverflowBubble(); | 1619 ToggleOverflowBubble(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1658 case TYPE_APP_PANEL: | 1658 case TYPE_APP_PANEL: |
1659 break; | 1659 break; |
1660 | 1660 |
1661 case TYPE_UNDEFINED: | 1661 case TYPE_UNDEFINED: |
1662 NOTREACHED() << "LauncherItemType must be set."; | 1662 NOTREACHED() << "LauncherItemType must be set."; |
1663 break; | 1663 break; |
1664 } | 1664 } |
1665 | 1665 |
1666 LauncherItemDelegate* item_delegate = | 1666 LauncherItemDelegate* item_delegate = |
1667 item_manager_->GetLauncherItemDelegate( | 1667 item_manager_->GetLauncherItemDelegate( |
1668 model_->items()[view_index].type); | 1668 model_->items()[view_index].id); |
1669 item_delegate->ItemSelected(model_->items()[view_index], event); | 1669 if (item_delegate) |
1670 item_delegate->ItemSelected(event); | |
1670 | 1671 |
1671 ShowListMenuForView(model_->items()[view_index], sender, event); | 1672 ShowListMenuForView(model_->items()[view_index], sender, event); |
1672 } | 1673 } |
1673 } | 1674 } |
1674 | 1675 |
1675 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1676 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
1676 views::View* source, | 1677 views::View* source, |
1677 const ui::Event& event) { | 1678 const ui::Event& event) { |
1678 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1679 scoped_ptr<ash::LauncherMenuModel> menu_model; |
1679 LauncherItemDelegate* item_delegate = | 1680 LauncherItemDelegate* item_delegate = |
1680 item_manager_->GetLauncherItemDelegate(item.type); | 1681 item_manager_->GetLauncherItemDelegate(item.id); |
1681 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); | 1682 if (item_delegate) |
1683 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); | |
1682 | 1684 |
1683 // Make sure we have a menu and it has at least two items in addition to the | 1685 // Make sure we have a menu and it has at least two items in addition to the |
1684 // application title and the 3 spacing separators. | 1686 // application title and the 3 spacing separators. |
1685 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1687 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
1686 return false; | 1688 return false; |
1687 | 1689 |
1688 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1690 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1689 new LauncherMenuModelAdapter(menu_model.get())), | 1691 new LauncherMenuModelAdapter(menu_model.get())), |
1690 source, | 1692 source, |
1691 gfx::Point(), | 1693 gfx::Point(), |
(...skipping 12 matching lines...) Expand all Loading... | |
1704 model_->items()[view_index].type == TYPE_APP_LIST) { | 1706 model_->items()[view_index].type == TYPE_APP_LIST) { |
1705 view_index = -1; | 1707 view_index = -1; |
1706 } | 1708 } |
1707 | 1709 |
1708 if (view_index == -1) { | 1710 if (view_index == -1) { |
1709 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1711 Shell::GetInstance()->ShowContextMenu(point, source_type); |
1710 return; | 1712 return; |
1711 } | 1713 } |
1712 scoped_ptr<ui::MenuModel> menu_model; | 1714 scoped_ptr<ui::MenuModel> menu_model; |
1713 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1715 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1714 model_->items()[view_index].type); | 1716 model_->items()[view_index].id); |
1715 menu_model.reset(item_delegate->CreateContextMenu( | 1717 if (item_delegate) { |
1716 model_->items()[view_index], | 1718 menu_model.reset(item_delegate->CreateContextMenu( |
1717 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1719 source->GetWidget()->GetNativeView()->GetRootWindow())); |
1720 } | |
1718 if (!menu_model) | 1721 if (!menu_model) |
1719 return; | 1722 return; |
1720 | 1723 |
1721 base::AutoReset<LauncherID> reseter( | 1724 base::AutoReset<LauncherID> reseter( |
1722 &context_menu_id_, | 1725 &context_menu_id_, |
1723 view_index == -1 ? 0 : model_->items()[view_index].id); | 1726 view_index == -1 ? 0 : model_->items()[view_index].id); |
1724 | 1727 |
1725 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1728 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1726 new views::MenuModelAdapter(menu_model.get())), | 1729 new views::MenuModelAdapter(menu_model.get())), |
1727 source, | 1730 source, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 } | 1870 } |
1868 | 1871 |
1869 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1872 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
1870 if (view == GetAppListButtonView() && | 1873 if (view == GetAppListButtonView() && |
1871 Shell::GetInstance()->GetAppListWindow()) | 1874 Shell::GetInstance()->GetAppListWindow()) |
1872 return false; | 1875 return false; |
1873 const LauncherItem* item = LauncherItemForView(view); | 1876 const LauncherItem* item = LauncherItemForView(view); |
1874 if (!item) | 1877 if (!item) |
1875 return true; | 1878 return true; |
1876 LauncherItemDelegate* item_delegate = | 1879 LauncherItemDelegate* item_delegate = |
1877 item_manager_->GetLauncherItemDelegate(item->type); | 1880 item_manager_->GetLauncherItemDelegate(item->id); |
Mr4D (OOO till 08-26)
2013/10/09 16:14:08
Is it possible to have an item with an assigned id
simonhong_
2013/10/09 22:14:10
In production code, all item have its item delegat
Mr4D (OOO till 08-26)
2013/10/10 04:20:15
I just looked and there are many checks for this.
| |
1878 return item_delegate->ShouldShowTooltip(*item); | 1881 return item_delegate ? item_delegate->ShouldShowTooltip() : false; |
1879 } | 1882 } |
1880 | 1883 |
1881 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1884 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
1882 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1885 ShelfWidget* shelf = RootWindowController::ForLauncher( |
1883 GetWidget()->GetNativeView())->shelf(); | 1886 GetWidget()->GetNativeView())->shelf(); |
1884 ash::ShelfAlignment align = shelf->GetAlignment(); | 1887 ash::ShelfAlignment align = shelf->GetAlignment(); |
1885 const gfx::Rect bounds = GetBoundsInScreen(); | 1888 const gfx::Rect bounds = GetBoundsInScreen(); |
1886 int distance = 0; | 1889 int distance = 0; |
1887 switch (align) { | 1890 switch (align) { |
1888 case ash::SHELF_ALIGNMENT_BOTTOM: | 1891 case ash::SHELF_ALIGNMENT_BOTTOM: |
1889 distance = bounds.y() - coordinate.y(); | 1892 distance = bounds.y() - coordinate.y(); |
1890 break; | 1893 break; |
1891 case ash::SHELF_ALIGNMENT_LEFT: | 1894 case ash::SHELF_ALIGNMENT_LEFT: |
1892 distance = coordinate.x() - bounds.right(); | 1895 distance = coordinate.x() - bounds.right(); |
1893 break; | 1896 break; |
1894 case ash::SHELF_ALIGNMENT_RIGHT: | 1897 case ash::SHELF_ALIGNMENT_RIGHT: |
1895 distance = bounds.x() - coordinate.x(); | 1898 distance = bounds.x() - coordinate.x(); |
1896 break; | 1899 break; |
1897 case ash::SHELF_ALIGNMENT_TOP: | 1900 case ash::SHELF_ALIGNMENT_TOP: |
1898 distance = coordinate.y() - bounds.bottom(); | 1901 distance = coordinate.y() - bounds.bottom(); |
1899 break; | 1902 break; |
1900 } | 1903 } |
1901 return distance > 0 ? distance : 0; | 1904 return distance > 0 ? distance : 0; |
1902 } | 1905 } |
1903 | 1906 |
1904 } // namespace internal | 1907 } // namespace internal |
1905 } // namespace ash | 1908 } // namespace ash |
OLD | NEW |