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

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

Issue 25716004: Revert 226547 "Refactor LauncherItemController and LauncherItemD..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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_].id); 988 model_->items()[start_drag_index_].type);
989 if (item_delegate && !item_delegate->IsDraggable()) { 989 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) {
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].id); 1006 model_->items()[current_index].type);
1007 if (item_delegate && !item_delegate->IsDraggable()) { 1007 if (!item_delegate->IsDraggable(model_->items()[current_index])) {
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].id); 1534 model_->items()[index].type);
1535 if (view_model_->view_size() <= 1 || 1535 if (view_model_->view_size() <= 1 ||
1536 (item_delegate && !item_delegate->IsDraggable())) 1536 !item_delegate->IsDraggable(model_->items()[index]))
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].id); 1606 model_->items()[view_index].type);
1607 return item_delegate ? item_delegate->GetTitle() : base::string16(); 1607 return item_delegate->GetTitle(model_->items()[view_index]);
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].id); 1666 model_->items()[view_index].type);
1667 if (item_delegate) 1667 item_delegate->ItemSelected(model_->items()[view_index], event);
1668 item_delegate->ItemSelected(event);
1669 1668
1670 ShowListMenuForView(model_->items()[view_index], sender, event); 1669 ShowListMenuForView(model_->items()[view_index], sender, event);
1671 } 1670 }
1672 } 1671 }
1673 1672
1674 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1673 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1675 views::View* source, 1674 views::View* source,
1676 const ui::Event& event) { 1675 const ui::Event& event) {
1677 scoped_ptr<ash::LauncherMenuModel> menu_model; 1676 scoped_ptr<ash::LauncherMenuModel> menu_model;
1678 LauncherItemDelegate* item_delegate = 1677 LauncherItemDelegate* item_delegate =
1679 item_manager_->GetLauncherItemDelegate(item.id); 1678 item_manager_->GetLauncherItemDelegate(item.type);
1680 if (item_delegate) 1679 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags()));
1681 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags()));
1682 1680
1683 // Make sure we have a menu and it has at least two items in addition to the 1681 // 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. 1682 // application title and the 3 spacing separators.
1685 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1683 if (!menu_model.get() || menu_model->GetItemCount() <= 5)
1686 return false; 1684 return false;
1687 1685
1688 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1686 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1689 new LauncherMenuModelAdapter(menu_model.get())), 1687 new LauncherMenuModelAdapter(menu_model.get())),
1690 source, 1688 source,
1691 gfx::Point(), 1689 gfx::Point(),
(...skipping 12 matching lines...) Expand all
1704 model_->items()[view_index].type == TYPE_APP_LIST) { 1702 model_->items()[view_index].type == TYPE_APP_LIST) {
1705 view_index = -1; 1703 view_index = -1;
1706 } 1704 }
1707 1705
1708 if (view_index == -1) { 1706 if (view_index == -1) {
1709 Shell::GetInstance()->ShowContextMenu(point, source_type); 1707 Shell::GetInstance()->ShowContextMenu(point, source_type);
1710 return; 1708 return;
1711 } 1709 }
1712 scoped_ptr<ui::MenuModel> menu_model; 1710 scoped_ptr<ui::MenuModel> menu_model;
1713 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1711 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
1714 model_->items()[view_index].id); 1712 model_->items()[view_index].type);
1715 if (item_delegate) { 1713 menu_model.reset(item_delegate->CreateContextMenu(
1716 menu_model.reset(item_delegate->CreateContextMenu( 1714 model_->items()[view_index],
1717 source->GetWidget()->GetNativeView()->GetRootWindow())); 1715 source->GetWidget()->GetNativeView()->GetRootWindow()));
1718 }
1719 if (!menu_model) 1716 if (!menu_model)
1720 return; 1717 return;
1721 1718
1722 base::AutoReset<LauncherID> reseter( 1719 base::AutoReset<LauncherID> reseter(
1723 &context_menu_id_, 1720 &context_menu_id_,
1724 view_index == -1 ? 0 : model_->items()[view_index].id); 1721 view_index == -1 ? 0 : model_->items()[view_index].id);
1725 1722
1726 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1723 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1727 new views::MenuModelAdapter(menu_model.get())), 1724 new views::MenuModelAdapter(menu_model.get())),
1728 source, 1725 source,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 } 1860 }
1864 1861
1865 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1862 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1866 if (view == GetAppListButtonView() && 1863 if (view == GetAppListButtonView() &&
1867 Shell::GetInstance()->GetAppListWindow()) 1864 Shell::GetInstance()->GetAppListWindow())
1868 return false; 1865 return false;
1869 const LauncherItem* item = LauncherItemForView(view); 1866 const LauncherItem* item = LauncherItemForView(view);
1870 if (!item) 1867 if (!item)
1871 return true; 1868 return true;
1872 LauncherItemDelegate* item_delegate = 1869 LauncherItemDelegate* item_delegate =
1873 item_manager_->GetLauncherItemDelegate(item->id); 1870 item_manager_->GetLauncherItemDelegate(item->type);
1874 return item_delegate ? item_delegate->ShouldShowTooltip() : false; 1871 return item_delegate->ShouldShowTooltip(*item);
1875 } 1872 }
1876 1873
1877 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1874 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1878 ShelfWidget* shelf = RootWindowController::ForLauncher( 1875 ShelfWidget* shelf = RootWindowController::ForLauncher(
1879 GetWidget()->GetNativeView())->shelf(); 1876 GetWidget()->GetNativeView())->shelf();
1880 ash::ShelfAlignment align = shelf->GetAlignment(); 1877 ash::ShelfAlignment align = shelf->GetAlignment();
1881 const gfx::Rect bounds = GetBoundsInScreen(); 1878 const gfx::Rect bounds = GetBoundsInScreen();
1882 int distance = 0; 1879 int distance = 0;
1883 switch (align) { 1880 switch (align) {
1884 case ash::SHELF_ALIGNMENT_BOTTOM: 1881 case ash::SHELF_ALIGNMENT_BOTTOM:
1885 distance = bounds.y() - coordinate.y(); 1882 distance = bounds.y() - coordinate.y();
1886 break; 1883 break;
1887 case ash::SHELF_ALIGNMENT_LEFT: 1884 case ash::SHELF_ALIGNMENT_LEFT:
1888 distance = coordinate.x() - bounds.right(); 1885 distance = coordinate.x() - bounds.right();
1889 break; 1886 break;
1890 case ash::SHELF_ALIGNMENT_RIGHT: 1887 case ash::SHELF_ALIGNMENT_RIGHT:
1891 distance = bounds.x() - coordinate.x(); 1888 distance = bounds.x() - coordinate.x();
1892 break; 1889 break;
1893 case ash::SHELF_ALIGNMENT_TOP: 1890 case ash::SHELF_ALIGNMENT_TOP:
1894 distance = coordinate.y() - bounds.bottom(); 1891 distance = coordinate.y() - bounds.bottom();
1895 break; 1892 break;
1896 } 1893 }
1897 return distance > 0 ? distance : 0; 1894 return distance > 0 ? distance : 0;
1898 } 1895 }
1899 1896
1900 } // namespace internal 1897 } // namespace internal
1901 } // namespace ash 1898 } // namespace ash
OLDNEW
« no previous file with comments | « trunk/src/ash/launcher/launcher_unittest.cc ('k') | trunk/src/ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698