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

Side by Side Diff: ash/launcher/launcher_view.cc

Issue 25823002: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and DCHECK(LauncherItemDelegate*) for LauncherID Created 7 years, 2 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 unified diff | Download patch
OLDNEW
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 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 drag_pointer_ = pointer; 978 drag_pointer_ = pointer;
979 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); 979 start_drag_index_ = view_model_->GetIndexOfView(drag_view_);
980 980
981 if (start_drag_index_== -1) { 981 if (start_drag_index_== -1) {
982 CancelDrag(-1); 982 CancelDrag(-1);
983 return; 983 return;
984 } 984 }
985 985
986 // If the item is no longer draggable, bail out. 986 // If the item is no longer draggable, bail out.
987 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 987 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
988 model_->items()[start_drag_index_].type); 988 model_->items()[start_drag_index_].id);
989 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) { 989 if (!item_delegate->IsDraggable()) {
990 CancelDrag(-1); 990 CancelDrag(-1);
991 return; 991 return;
992 } 992 }
993 993
994 // Move the view to the front so that it appears on top of other views. 994 // Move the view to the front so that it appears on top of other views.
995 ReorderChildView(drag_view_, -1); 995 ReorderChildView(drag_view_, -1);
996 bounds_animator_->StopAnimatingView(drag_view_); 996 bounds_animator_->StopAnimatingView(drag_view_);
997 } 997 }
998 998
999 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { 999 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) {
1000 // Due to a syncing operation the application might have been removed. 1000 // Due to a syncing operation the application might have been removed.
1001 // Bail if it is gone. 1001 // Bail if it is gone.
1002 int current_index = view_model_->GetIndexOfView(drag_view_); 1002 int current_index = view_model_->GetIndexOfView(drag_view_);
1003 DCHECK_NE(-1, current_index); 1003 DCHECK_NE(-1, current_index);
1004 1004
1005 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1005 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1006 model_->items()[current_index].type); 1006 model_->items()[current_index].id);
1007 if (!item_delegate->IsDraggable(model_->items()[current_index])) { 1007 if (!item_delegate->IsDraggable()) {
1008 CancelDrag(-1); 1008 CancelDrag(-1);
1009 return; 1009 return;
1010 } 1010 }
1011 1011
1012 // If this is not a drag and drop host operation and not the app list item, 1012 // If this is not a drag and drop host operation and not the app list item,
1013 // check if the item got ripped off the shelf - if it did we are done. 1013 // check if the item got ripped off the shelf - if it did we are done.
1014 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && 1014 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() &&
1015 RemovableByRipOff(current_index) != NOT_REMOVABLE) { 1015 RemovableByRipOff(current_index) != NOT_REMOVABLE) {
1016 if (HandleRipOffDrag(event)) 1016 if (HandleRipOffDrag(event))
1017 return; 1017 return;
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 Pointer pointer, 1532 Pointer pointer,
1533 const ui::LocatedEvent& event) { 1533 const ui::LocatedEvent& event) {
1534 if (drag_view_) 1534 if (drag_view_)
1535 return; 1535 return;
1536 1536
1537 int index = view_model_->GetIndexOfView(view); 1537 int index = view_model_->GetIndexOfView(view);
1538 if (index == -1) 1538 if (index == -1)
1539 return; 1539 return;
1540 1540
1541 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1541 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1542 model_->items()[index].type); 1542 model_->items()[index].id);
1543 if (view_model_->view_size() <= 1 || 1543 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable())
1544 !item_delegate->IsDraggable(model_->items()[index]))
1545 return; // View is being deleted or not draggable, ignore request. 1544 return; // View is being deleted or not draggable, ignore request.
1546 1545
1547 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); 1546 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
1548 1547
1549 drag_view_ = view; 1548 drag_view_ = view;
1550 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); 1549 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y());
1551 } 1550 }
1552 1551
1553 void LauncherView::PointerDraggedOnButton(views::View* view, 1552 void LauncherView::PointerDraggedOnButton(views::View* view,
1554 Pointer pointer, 1553 Pointer pointer,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 tooltip_->StopTimer(); 1603 tooltip_->StopTimer();
1605 } 1604 }
1606 1605
1607 base::string16 LauncherView::GetAccessibleName(const views::View* view) { 1606 base::string16 LauncherView::GetAccessibleName(const views::View* view) {
1608 int view_index = view_model_->GetIndexOfView(view); 1607 int view_index = view_model_->GetIndexOfView(view);
1609 // May be -1 while in the process of animating closed. 1608 // May be -1 while in the process of animating closed.
1610 if (view_index == -1) 1609 if (view_index == -1)
1611 return base::string16(); 1610 return base::string16();
1612 1611
1613 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1612 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1614 model_->items()[view_index].type); 1613 model_->items()[view_index].id);
1615 return item_delegate->GetTitle(model_->items()[view_index]); 1614 return item_delegate->GetTitle();
1616 } 1615 }
1617 1616
1618 void LauncherView::ButtonPressed(views::Button* sender, 1617 void LauncherView::ButtonPressed(views::Button* sender,
1619 const ui::Event& event) { 1618 const ui::Event& event) {
1620 // Do not handle mouse release during drag. 1619 // Do not handle mouse release during drag.
1621 if (dragging()) 1620 if (dragging())
1622 return; 1621 return;
1623 1622
1624 if (sender == overflow_button_) { 1623 if (sender == overflow_button_) {
1625 ToggleOverflowBubble(); 1624 ToggleOverflowBubble();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 case TYPE_APP_PANEL: 1663 case TYPE_APP_PANEL:
1665 break; 1664 break;
1666 1665
1667 case TYPE_UNDEFINED: 1666 case TYPE_UNDEFINED:
1668 NOTREACHED() << "LauncherItemType must be set."; 1667 NOTREACHED() << "LauncherItemType must be set.";
1669 break; 1668 break;
1670 } 1669 }
1671 1670
1672 LauncherItemDelegate* item_delegate = 1671 LauncherItemDelegate* item_delegate =
1673 item_manager_->GetLauncherItemDelegate( 1672 item_manager_->GetLauncherItemDelegate(
1674 model_->items()[view_index].type); 1673 model_->items()[view_index].id);
1675 item_delegate->ItemSelected(model_->items()[view_index], event); 1674 item_delegate->ItemSelected(event);
1676 1675
1677 ShowListMenuForView(model_->items()[view_index], sender, event); 1676 ShowListMenuForView(model_->items()[view_index], sender, event);
1678 } 1677 }
1679 } 1678 }
1680 1679
1681 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1680 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1682 views::View* source, 1681 views::View* source,
1683 const ui::Event& event) { 1682 const ui::Event& event) {
1684 scoped_ptr<ash::LauncherMenuModel> menu_model; 1683 scoped_ptr<ash::LauncherMenuModel> menu_model;
1685 LauncherItemDelegate* item_delegate = 1684 LauncherItemDelegate* item_delegate =
1686 item_manager_->GetLauncherItemDelegate(item.type); 1685 item_manager_->GetLauncherItemDelegate(item.id);
1687 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); 1686 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags()));
1688 1687
1689 // Make sure we have a menu and it has at least two items in addition to the 1688 // Make sure we have a menu and it has at least two items in addition to the
1690 // application title and the 3 spacing separators. 1689 // application title and the 3 spacing separators.
1691 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1690 if (!menu_model.get() || menu_model->GetItemCount() <= 5)
1692 return false; 1691 return false;
1693 1692
1694 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1693 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1695 new LauncherMenuModelAdapter(menu_model.get())), 1694 new LauncherMenuModelAdapter(menu_model.get())),
1696 source, 1695 source,
1697 gfx::Point(), 1696 gfx::Point(),
(...skipping 12 matching lines...) Expand all
1710 model_->items()[view_index].type == TYPE_APP_LIST) { 1709 model_->items()[view_index].type == TYPE_APP_LIST) {
1711 view_index = -1; 1710 view_index = -1;
1712 } 1711 }
1713 1712
1714 if (view_index == -1) { 1713 if (view_index == -1) {
1715 Shell::GetInstance()->ShowContextMenu(point, source_type); 1714 Shell::GetInstance()->ShowContextMenu(point, source_type);
1716 return; 1715 return;
1717 } 1716 }
1718 scoped_ptr<ui::MenuModel> menu_model; 1717 scoped_ptr<ui::MenuModel> menu_model;
1719 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1718 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1720 model_->items()[view_index].type); 1719 model_->items()[view_index].id);
1721 menu_model.reset(item_delegate->CreateContextMenu( 1720 menu_model.reset(item_delegate->CreateContextMenu(
1722 model_->items()[view_index],
1723 source->GetWidget()->GetNativeView()->GetRootWindow())); 1721 source->GetWidget()->GetNativeView()->GetRootWindow()));
1724 if (!menu_model) 1722 if (!menu_model)
1725 return; 1723 return;
1726 1724
1727 base::AutoReset<LauncherID> reseter( 1725 base::AutoReset<LauncherID> reseter(
1728 &context_menu_id_, 1726 &context_menu_id_,
1729 view_index == -1 ? 0 : model_->items()[view_index].id); 1727 view_index == -1 ? 0 : model_->items()[view_index].id);
1730 1728
1731 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1729 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1732 new views::MenuModelAdapter(menu_model.get())), 1730 new views::MenuModelAdapter(menu_model.get())),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 } 1871 }
1874 1872
1875 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1873 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1876 if (view == GetAppListButtonView() && 1874 if (view == GetAppListButtonView() &&
1877 Shell::GetInstance()->GetAppListWindow()) 1875 Shell::GetInstance()->GetAppListWindow())
1878 return false; 1876 return false;
1879 const LauncherItem* item = LauncherItemForView(view); 1877 const LauncherItem* item = LauncherItemForView(view);
1880 if (!item) 1878 if (!item)
1881 return true; 1879 return true;
1882 LauncherItemDelegate* item_delegate = 1880 LauncherItemDelegate* item_delegate =
1883 item_manager_->GetLauncherItemDelegate(item->type); 1881 item_manager_->GetLauncherItemDelegate(item->id);
1884 return item_delegate->ShouldShowTooltip(*item); 1882 return item_delegate->ShouldShowTooltip();
1885 } 1883 }
1886 1884
1887 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1885 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1888 ShelfWidget* shelf = RootWindowController::ForLauncher( 1886 ShelfWidget* shelf = RootWindowController::ForLauncher(
1889 GetWidget()->GetNativeView())->shelf(); 1887 GetWidget()->GetNativeView())->shelf();
1890 ash::ShelfAlignment align = shelf->GetAlignment(); 1888 ash::ShelfAlignment align = shelf->GetAlignment();
1891 const gfx::Rect bounds = GetBoundsInScreen(); 1889 const gfx::Rect bounds = GetBoundsInScreen();
1892 int distance = 0; 1890 int distance = 0;
1893 switch (align) { 1891 switch (align) {
1894 case ash::SHELF_ALIGNMENT_BOTTOM: 1892 case ash::SHELF_ALIGNMENT_BOTTOM:
1895 distance = bounds.y() - coordinate.y(); 1893 distance = bounds.y() - coordinate.y();
1896 break; 1894 break;
1897 case ash::SHELF_ALIGNMENT_LEFT: 1895 case ash::SHELF_ALIGNMENT_LEFT:
1898 distance = coordinate.x() - bounds.right(); 1896 distance = coordinate.x() - bounds.right();
1899 break; 1897 break;
1900 case ash::SHELF_ALIGNMENT_RIGHT: 1898 case ash::SHELF_ALIGNMENT_RIGHT:
1901 distance = bounds.x() - coordinate.x(); 1899 distance = bounds.x() - coordinate.x();
1902 break; 1900 break;
1903 case ash::SHELF_ALIGNMENT_TOP: 1901 case ash::SHELF_ALIGNMENT_TOP:
1904 distance = coordinate.y() - bounds.bottom(); 1902 distance = coordinate.y() - bounds.bottom();
1905 break; 1903 break;
1906 } 1904 }
1907 return distance > 0 ? distance : 0; 1905 return distance > 0 ? distance : 0;
1908 } 1906 }
1909 1907
1910 } // namespace internal 1908 } // namespace internal
1911 } // namespace ash 1909 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698