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

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

Issue 23606016: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for unittest.. 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
« no previous file with comments | « ash/launcher/launcher_unittest.cc ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 && !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 && !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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 Pointer pointer, 1524 Pointer pointer,
1525 const ui::LocatedEvent& event) { 1525 const ui::LocatedEvent& event) {
1526 if (drag_view_) 1526 if (drag_view_)
1527 return; 1527 return;
1528 1528
1529 int index = view_model_->GetIndexOfView(view); 1529 int index = view_model_->GetIndexOfView(view);
1530 if (index == -1) 1530 if (index == -1)
1531 return; 1531 return;
1532 1532
1533 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1533 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1534 model_->items()[index].type); 1534 model_->items()[index].id);
1535 if (view_model_->view_size() <= 1 || 1535 if (view_model_->view_size() <= 1 ||
1536 !item_delegate->IsDraggable(model_->items()[index])) 1536 (item_delegate && !item_delegate->IsDraggable()))
1537 return; // View is being deleted or not draggable, ignore request. 1537 return; // View is being deleted or not draggable, ignore request.
1538 1538
1539 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); 1539 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
1540 1540
1541 drag_view_ = view; 1541 drag_view_ = view;
1542 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); 1542 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y());
1543 } 1543 }
1544 1544
1545 void LauncherView::PointerDraggedOnButton(views::View* view, 1545 void LauncherView::PointerDraggedOnButton(views::View* view,
1546 Pointer pointer, 1546 Pointer pointer,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 tooltip_->StopTimer(); 1596 tooltip_->StopTimer();
1597 } 1597 }
1598 1598
1599 base::string16 LauncherView::GetAccessibleName(const views::View* view) { 1599 base::string16 LauncherView::GetAccessibleName(const views::View* view) {
1600 int view_index = view_model_->GetIndexOfView(view); 1600 int view_index = view_model_->GetIndexOfView(view);
1601 // May be -1 while in the process of animating closed. 1601 // May be -1 while in the process of animating closed.
1602 if (view_index == -1) 1602 if (view_index == -1)
1603 return base::string16(); 1603 return base::string16();
1604 1604
1605 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1605 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1606 model_->items()[view_index].type); 1606 model_->items()[view_index].id);
1607 return item_delegate->GetTitle(model_->items()[view_index]); 1607 return item_delegate ? item_delegate->GetTitle() : base::string16();
1608 } 1608 }
1609 1609
1610 void LauncherView::ButtonPressed(views::Button* sender, 1610 void LauncherView::ButtonPressed(views::Button* sender,
1611 const ui::Event& event) { 1611 const ui::Event& event) {
1612 // Do not handle mouse release during drag. 1612 // Do not handle mouse release during drag.
1613 if (dragging()) 1613 if (dragging())
1614 return; 1614 return;
1615 1615
1616 if (sender == overflow_button_) { 1616 if (sender == overflow_button_) {
1617 ToggleOverflowBubble(); 1617 ToggleOverflowBubble();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 case TYPE_APP_PANEL: 1656 case TYPE_APP_PANEL:
1657 break; 1657 break;
1658 1658
1659 case TYPE_UNDEFINED: 1659 case TYPE_UNDEFINED:
1660 NOTREACHED() << "LauncherItemType must be set."; 1660 NOTREACHED() << "LauncherItemType must be set.";
1661 break; 1661 break;
1662 } 1662 }
1663 1663
1664 LauncherItemDelegate* item_delegate = 1664 LauncherItemDelegate* item_delegate =
1665 item_manager_->GetLauncherItemDelegate( 1665 item_manager_->GetLauncherItemDelegate(
1666 model_->items()[view_index].type); 1666 model_->items()[view_index].id);
1667 item_delegate->ItemSelected(model_->items()[view_index], event); 1667 if (item_delegate)
1668 item_delegate->ItemSelected(event);
1668 1669
1669 ShowListMenuForView(model_->items()[view_index], sender, event); 1670 ShowListMenuForView(model_->items()[view_index], sender, event);
1670 } 1671 }
1671 } 1672 }
1672 1673
1673 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1674 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1674 views::View* source, 1675 views::View* source,
1675 const ui::Event& event) { 1676 const ui::Event& event) {
1676 scoped_ptr<ash::LauncherMenuModel> menu_model; 1677 scoped_ptr<ash::LauncherMenuModel> menu_model;
1677 LauncherItemDelegate* item_delegate = 1678 LauncherItemDelegate* item_delegate =
1678 item_manager_->GetLauncherItemDelegate(item.type); 1679 item_manager_->GetLauncherItemDelegate(item.id);
1679 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); 1680 if (item_delegate)
1681 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags()));
1680 1682
1681 // Make sure we have a menu and it has at least two items in addition to the 1683 // Make sure we have a menu and it has at least two items in addition to the
1682 // application title and the 3 spacing separators. 1684 // application title and the 3 spacing separators.
1683 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1685 if (!menu_model.get() || menu_model->GetItemCount() <= 5)
1684 return false; 1686 return false;
1685 1687
1686 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1688 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1687 new LauncherMenuModelAdapter(menu_model.get())), 1689 new LauncherMenuModelAdapter(menu_model.get())),
1688 source, 1690 source,
1689 gfx::Point(), 1691 gfx::Point(),
(...skipping 12 matching lines...) Expand all
1702 model_->items()[view_index].type == TYPE_APP_LIST) { 1704 model_->items()[view_index].type == TYPE_APP_LIST) {
1703 view_index = -1; 1705 view_index = -1;
1704 } 1706 }
1705 1707
1706 if (view_index == -1) { 1708 if (view_index == -1) {
1707 Shell::GetInstance()->ShowContextMenu(point, source_type); 1709 Shell::GetInstance()->ShowContextMenu(point, source_type);
1708 return; 1710 return;
1709 } 1711 }
1710 scoped_ptr<ui::MenuModel> menu_model; 1712 scoped_ptr<ui::MenuModel> menu_model;
1711 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1713 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1712 model_->items()[view_index].type); 1714 model_->items()[view_index].id);
1713 menu_model.reset(item_delegate->CreateContextMenu( 1715 if (item_delegate) {
1714 model_->items()[view_index], 1716 menu_model.reset(item_delegate->CreateContextMenu(
1715 source->GetWidget()->GetNativeView()->GetRootWindow())); 1717 source->GetWidget()->GetNativeView()->GetRootWindow()));
1718 }
1716 if (!menu_model) 1719 if (!menu_model)
1717 return; 1720 return;
1718 1721
1719 base::AutoReset<LauncherID> reseter( 1722 base::AutoReset<LauncherID> reseter(
1720 &context_menu_id_, 1723 &context_menu_id_,
1721 view_index == -1 ? 0 : model_->items()[view_index].id); 1724 view_index == -1 ? 0 : model_->items()[view_index].id);
1722 1725
1723 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1726 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1724 new views::MenuModelAdapter(menu_model.get())), 1727 new views::MenuModelAdapter(menu_model.get())),
1725 source, 1728 source,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 } 1863 }
1861 1864
1862 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1865 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1863 if (view == GetAppListButtonView() && 1866 if (view == GetAppListButtonView() &&
1864 Shell::GetInstance()->GetAppListWindow()) 1867 Shell::GetInstance()->GetAppListWindow())
1865 return false; 1868 return false;
1866 const LauncherItem* item = LauncherItemForView(view); 1869 const LauncherItem* item = LauncherItemForView(view);
1867 if (!item) 1870 if (!item)
1868 return true; 1871 return true;
1869 LauncherItemDelegate* item_delegate = 1872 LauncherItemDelegate* item_delegate =
1870 item_manager_->GetLauncherItemDelegate(item->type); 1873 item_manager_->GetLauncherItemDelegate(item->id);
1871 return item_delegate->ShouldShowTooltip(*item); 1874 return item_delegate ? item_delegate->ShouldShowTooltip() : false;
1872 } 1875 }
1873 1876
1874 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1877 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1875 ShelfWidget* shelf = RootWindowController::ForLauncher( 1878 ShelfWidget* shelf = RootWindowController::ForLauncher(
1876 GetWidget()->GetNativeView())->shelf(); 1879 GetWidget()->GetNativeView())->shelf();
1877 ash::ShelfAlignment align = shelf->GetAlignment(); 1880 ash::ShelfAlignment align = shelf->GetAlignment();
1878 const gfx::Rect bounds = GetBoundsInScreen(); 1881 const gfx::Rect bounds = GetBoundsInScreen();
1879 int distance = 0; 1882 int distance = 0;
1880 switch (align) { 1883 switch (align) {
1881 case ash::SHELF_ALIGNMENT_BOTTOM: 1884 case ash::SHELF_ALIGNMENT_BOTTOM:
1882 distance = bounds.y() - coordinate.y(); 1885 distance = bounds.y() - coordinate.y();
1883 break; 1886 break;
1884 case ash::SHELF_ALIGNMENT_LEFT: 1887 case ash::SHELF_ALIGNMENT_LEFT:
1885 distance = coordinate.x() - bounds.right(); 1888 distance = coordinate.x() - bounds.right();
1886 break; 1889 break;
1887 case ash::SHELF_ALIGNMENT_RIGHT: 1890 case ash::SHELF_ALIGNMENT_RIGHT:
1888 distance = bounds.x() - coordinate.x(); 1891 distance = bounds.x() - coordinate.x();
1889 break; 1892 break;
1890 case ash::SHELF_ALIGNMENT_TOP: 1893 case ash::SHELF_ALIGNMENT_TOP:
1891 distance = coordinate.y() - bounds.bottom(); 1894 distance = coordinate.y() - bounds.bottom();
1892 break; 1895 break;
1893 } 1896 }
1894 return distance > 0 ? distance : 0; 1897 return distance > 0 ? distance : 0;
1895 } 1898 }
1896 1899
1897 } // namespace internal 1900 } // namespace internal
1898 } // namespace ash 1901 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_unittest.cc ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698