Chromium Code Reviews| 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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 last_visible_index_ > 0 && last_visible_index_ < last_button_index) | 815 last_visible_index_ > 0 && last_visible_index_ < last_button_index) |
| 816 --last_visible_index_; | 816 --last_visible_index_; |
| 817 for (int i = 0; i < view_model_->view_size(); ++i) { | 817 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 818 bool visible = i <= last_visible_index_ || i > last_hidden_index_; | 818 bool visible = i <= last_visible_index_ || i > last_hidden_index_; |
| 819 // Always show the app list. | 819 // Always show the app list. |
| 820 if (!ash::switches::UseAlternateShelfLayout()) | 820 if (!ash::switches::UseAlternateShelfLayout()) |
| 821 visible |= (i == last_button_index); | 821 visible |= (i == last_button_index); |
| 822 // To receive drag event continously from |drag_view_| during the dragging | 822 // To receive drag event continously from |drag_view_| during the dragging |
| 823 // off from the shelf, don't make |drag_view_| invisible. It will be | 823 // off from the shelf, don't make |drag_view_| invisible. It will be |
| 824 // eventually invisible and removed from the |view_model_| by | 824 // eventually invisible and removed from the |view_model_| by |
| 825 // FinalizeRipOffDrag(). | 825 // FinalizeRipOffDrag(). |
|
Mr4D (OOO till 08-26)
2013/10/09 00:38:22
Actually that is a problem: There are two views
a.
| |
| 826 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) | 826 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) |
| 827 continue; | 827 continue; |
| 828 view_model_->view_at(i)->SetVisible(visible); | 828 view_model_->view_at(i)->SetVisible(visible); |
| 829 } | 829 } |
| 830 | 830 |
| 831 overflow_button_->SetVisible(show_overflow); | 831 overflow_button_->SetVisible(show_overflow); |
| 832 if (show_overflow) { | 832 if (show_overflow) { |
| 833 DCHECK_NE(0, view_model_->view_size()); | 833 DCHECK_NE(0, view_model_->view_size()); |
| 834 if (last_visible_index_ == -1) { | 834 if (last_visible_index_ == -1) { |
| 835 x = shelf->SelectValueForShelfAlignment(inset, 0, 0, inset); | 835 x = shelf->SelectValueForShelfAlignment(inset, 0, 0, inset); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 drag_pointer_ = pointer; | 986 drag_pointer_ = pointer; |
| 987 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); | 987 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
| 988 | 988 |
| 989 if (start_drag_index_== -1) { | 989 if (start_drag_index_== -1) { |
| 990 CancelDrag(-1); | 990 CancelDrag(-1); |
| 991 return; | 991 return; |
| 992 } | 992 } |
| 993 | 993 |
| 994 // If the item is no longer draggable, bail out. | 994 // If the item is no longer draggable, bail out. |
| 995 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 995 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
| 996 model_->items()[start_drag_index_].type); | 996 model_->items()[start_drag_index_].id); |
| 997 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) { | 997 if (item_delegate && !item_delegate->IsDraggable()) { |
| 998 CancelDrag(-1); | 998 CancelDrag(-1); |
| 999 return; | 999 return; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 // Move the view to the front so that it appears on top of other views. | 1002 // Move the view to the front so that it appears on top of other views. |
| 1003 ReorderChildView(drag_view_, -1); | 1003 ReorderChildView(drag_view_, -1); |
| 1004 bounds_animator_->StopAnimatingView(drag_view_); | 1004 bounds_animator_->StopAnimatingView(drag_view_); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { | 1007 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
| 1008 // Due to a syncing operation the application might have been removed. | 1008 // Due to a syncing operation the application might have been removed. |
| 1009 // Bail if it is gone. | 1009 // Bail if it is gone. |
| 1010 int current_index = view_model_->GetIndexOfView(drag_view_); | 1010 int current_index = view_model_->GetIndexOfView(drag_view_); |
| 1011 DCHECK_NE(-1, current_index); | 1011 DCHECK_NE(-1, current_index); |
| 1012 | 1012 |
| 1013 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1013 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
| 1014 model_->items()[current_index].type); | 1014 model_->items()[current_index].id); |
| 1015 if (!item_delegate->IsDraggable(model_->items()[current_index])) { | 1015 if (item_delegate && !item_delegate->IsDraggable()) { |
| 1016 CancelDrag(-1); | 1016 CancelDrag(-1); |
| 1017 return; | 1017 return; |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 // If this is not a drag and drop host operation and not the app list item, | 1020 // If this is not a drag and drop host operation and not the app list item, |
| 1021 // check if the item got ripped off the shelf - if it did we are done. | 1021 // check if the item got ripped off the shelf - if it did we are done. |
| 1022 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && | 1022 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && |
| 1023 RemovableByRipOff(current_index) != NOT_REMOVABLE) { | 1023 RemovableByRipOff(current_index) != NOT_REMOVABLE) { |
| 1024 if (HandleRipOffDrag(event)) | 1024 if (HandleRipOffDrag(event)) |
| 1025 return; | 1025 return; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1539 Pointer pointer, | 1539 Pointer pointer, |
| 1540 const ui::LocatedEvent& event) { | 1540 const ui::LocatedEvent& event) { |
| 1541 if (drag_view_) | 1541 if (drag_view_) |
| 1542 return; | 1542 return; |
| 1543 | 1543 |
| 1544 int index = view_model_->GetIndexOfView(view); | 1544 int index = view_model_->GetIndexOfView(view); |
| 1545 if (index == -1) | 1545 if (index == -1) |
| 1546 return; | 1546 return; |
| 1547 | 1547 |
| 1548 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1548 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
| 1549 model_->items()[index].type); | 1549 model_->items()[index].id); |
| 1550 if (view_model_->view_size() <= 1 || | 1550 if (view_model_->view_size() <= 1 || |
| 1551 !item_delegate->IsDraggable(model_->items()[index])) | 1551 (item_delegate && !item_delegate->IsDraggable())) |
| 1552 return; // View is being deleted or not draggable, ignore request. | 1552 return; // View is being deleted or not draggable, ignore request. |
| 1553 | 1553 |
| 1554 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1554 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
| 1555 | 1555 |
| 1556 drag_view_ = view; | 1556 drag_view_ = view; |
| 1557 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); | 1557 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 void LauncherView::PointerDraggedOnButton(views::View* view, | 1560 void LauncherView::PointerDraggedOnButton(views::View* view, |
| 1561 Pointer pointer, | 1561 Pointer pointer, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 tooltip_->StopTimer(); | 1611 tooltip_->StopTimer(); |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 base::string16 LauncherView::GetAccessibleName(const views::View* view) { | 1614 base::string16 LauncherView::GetAccessibleName(const views::View* view) { |
| 1615 int view_index = view_model_->GetIndexOfView(view); | 1615 int view_index = view_model_->GetIndexOfView(view); |
| 1616 // May be -1 while in the process of animating closed. | 1616 // May be -1 while in the process of animating closed. |
| 1617 if (view_index == -1) | 1617 if (view_index == -1) |
| 1618 return base::string16(); | 1618 return base::string16(); |
| 1619 | 1619 |
| 1620 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1620 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
| 1621 model_->items()[view_index].type); | 1621 model_->items()[view_index].id); |
| 1622 return item_delegate->GetTitle(model_->items()[view_index]); | 1622 return item_delegate ? item_delegate->GetTitle() : base::string16(); |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 void LauncherView::ButtonPressed(views::Button* sender, | 1625 void LauncherView::ButtonPressed(views::Button* sender, |
| 1626 const ui::Event& event) { | 1626 const ui::Event& event) { |
| 1627 // Do not handle mouse release during drag. | 1627 // Do not handle mouse release during drag. |
| 1628 if (dragging()) | 1628 if (dragging()) |
| 1629 return; | 1629 return; |
| 1630 | 1630 |
| 1631 if (sender == overflow_button_) { | 1631 if (sender == overflow_button_) { |
| 1632 ToggleOverflowBubble(); | 1632 ToggleOverflowBubble(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1671 case TYPE_APP_PANEL: | 1671 case TYPE_APP_PANEL: |
| 1672 break; | 1672 break; |
| 1673 | 1673 |
| 1674 case TYPE_UNDEFINED: | 1674 case TYPE_UNDEFINED: |
| 1675 NOTREACHED() << "LauncherItemType must be set."; | 1675 NOTREACHED() << "LauncherItemType must be set."; |
| 1676 break; | 1676 break; |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 LauncherItemDelegate* item_delegate = | 1679 LauncherItemDelegate* item_delegate = |
| 1680 item_manager_->GetLauncherItemDelegate( | 1680 item_manager_->GetLauncherItemDelegate( |
| 1681 model_->items()[view_index].type); | 1681 model_->items()[view_index].id); |
| 1682 item_delegate->ItemSelected(model_->items()[view_index], event); | 1682 if (item_delegate) |
| 1683 item_delegate->ItemSelected(event); | |
| 1683 | 1684 |
| 1684 ShowListMenuForView(model_->items()[view_index], sender, event); | 1685 ShowListMenuForView(model_->items()[view_index], sender, event); |
| 1685 } | 1686 } |
| 1686 } | 1687 } |
| 1687 | 1688 |
| 1688 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1689 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
| 1689 views::View* source, | 1690 views::View* source, |
| 1690 const ui::Event& event) { | 1691 const ui::Event& event) { |
| 1691 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1692 scoped_ptr<ash::LauncherMenuModel> menu_model; |
| 1692 LauncherItemDelegate* item_delegate = | 1693 LauncherItemDelegate* item_delegate = |
| 1693 item_manager_->GetLauncherItemDelegate(item.type); | 1694 item_manager_->GetLauncherItemDelegate(item.id); |
| 1694 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); | 1695 if (item_delegate) |
| 1696 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); | |
| 1695 | 1697 |
| 1696 // Make sure we have a menu and it has at least two items in addition to the | 1698 // Make sure we have a menu and it has at least two items in addition to the |
| 1697 // application title and the 3 spacing separators. | 1699 // application title and the 3 spacing separators. |
| 1698 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1700 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
| 1699 return false; | 1701 return false; |
| 1700 | 1702 |
| 1701 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1703 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1702 new LauncherMenuModelAdapter(menu_model.get())), | 1704 new LauncherMenuModelAdapter(menu_model.get())), |
| 1703 source, | 1705 source, |
| 1704 gfx::Point(), | 1706 gfx::Point(), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1717 model_->items()[view_index].type == TYPE_APP_LIST) { | 1719 model_->items()[view_index].type == TYPE_APP_LIST) { |
| 1718 view_index = -1; | 1720 view_index = -1; |
| 1719 } | 1721 } |
| 1720 | 1722 |
| 1721 if (view_index == -1) { | 1723 if (view_index == -1) { |
| 1722 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1724 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1723 return; | 1725 return; |
| 1724 } | 1726 } |
| 1725 scoped_ptr<ui::MenuModel> menu_model; | 1727 scoped_ptr<ui::MenuModel> menu_model; |
| 1726 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1728 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
| 1727 model_->items()[view_index].type); | 1729 model_->items()[view_index].id); |
| 1728 menu_model.reset(item_delegate->CreateContextMenu( | 1730 if (item_delegate) { |
| 1729 model_->items()[view_index], | 1731 menu_model.reset(item_delegate->CreateContextMenu( |
| 1730 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1732 source->GetWidget()->GetNativeView()->GetRootWindow())); |
| 1733 } | |
| 1731 if (!menu_model) | 1734 if (!menu_model) |
| 1732 return; | 1735 return; |
| 1733 | 1736 |
| 1734 base::AutoReset<LauncherID> reseter( | 1737 base::AutoReset<LauncherID> reseter( |
| 1735 &context_menu_id_, | 1738 &context_menu_id_, |
| 1736 view_index == -1 ? 0 : model_->items()[view_index].id); | 1739 view_index == -1 ? 0 : model_->items()[view_index].id); |
| 1737 | 1740 |
| 1738 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1741 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1739 new views::MenuModelAdapter(menu_model.get())), | 1742 new views::MenuModelAdapter(menu_model.get())), |
| 1740 source, | 1743 source, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1809 NULL, | 1812 NULL, |
| 1810 anchor_point, | 1813 anchor_point, |
| 1811 menu_alignment, | 1814 menu_alignment, |
| 1812 source_type, | 1815 source_type, |
| 1813 context_menu ? views::MenuRunner::CONTEXT_MENU : 0) == | 1816 context_menu ? views::MenuRunner::CONTEXT_MENU : 0) == |
| 1814 views::MenuRunner::MENU_DELETED) { | 1817 views::MenuRunner::MENU_DELETED) { |
| 1815 if (!got_deleted) { | 1818 if (!got_deleted) { |
| 1816 got_deleted_ = NULL; | 1819 got_deleted_ = NULL; |
| 1817 shelf->ForceUndimming(false); | 1820 shelf->ForceUndimming(false); |
| 1818 } | 1821 } |
| 1819 LOG(ERROR) << __FUNCTION__; | 1822 LOG(ERROR) << __FUNCTION__; |
|
Mr4D (OOO till 08-26)
2013/10/09 00:38:22
I guess this can be removed?
| |
| 1820 return; | 1823 return; |
| 1821 } | 1824 } |
| 1822 LOG(ERROR) << __FUNCTION__ << " " << IsShowingMenu(); | 1825 LOG(ERROR) << __FUNCTION__ << " " << IsShowingMenu(); |
|
Mr4D (OOO till 08-26)
2013/10/09 00:38:22
And this?
| |
| 1823 got_deleted_ = NULL; | 1826 got_deleted_ = NULL; |
| 1824 shelf->ForceUndimming(false); | 1827 shelf->ForceUndimming(false); |
| 1825 | 1828 |
| 1826 // If it is a context menu and we are showing overflow bubble | 1829 // If it is a context menu and we are showing overflow bubble |
| 1827 // we want to hide overflow bubble. | 1830 // we want to hide overflow bubble. |
| 1828 //if (owner_overflow_bubble_) | 1831 //if (owner_overflow_bubble_) |
| 1829 // owner_overflow_bubble_->HideBubbleAndRefreshButton(); | 1832 // owner_overflow_bubble_->HideBubbleAndRefreshButton(); |
|
Mr4D (OOO till 08-26)
2013/10/09 00:38:22
I think this can go?
| |
| 1830 | 1833 |
| 1831 // Unpinning an item will reset the |launcher_menu_runner_| before coming | 1834 // Unpinning an item will reset the |launcher_menu_runner_| before coming |
| 1832 // here. | 1835 // here. |
| 1833 if (launcher_menu_runner_) | 1836 if (launcher_menu_runner_) |
| 1834 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1837 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1835 Shell::GetInstance()->UpdateShelfVisibility(); | 1838 Shell::GetInstance()->UpdateShelfVisibility(); |
| 1836 } | 1839 } |
| 1837 | 1840 |
| 1838 void LauncherView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { | 1841 void LauncherView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { |
| 1839 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1842 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1882 } | 1885 } |
| 1883 | 1886 |
| 1884 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1887 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
| 1885 if (view == GetAppListButtonView() && | 1888 if (view == GetAppListButtonView() && |
| 1886 Shell::GetInstance()->GetAppListWindow()) | 1889 Shell::GetInstance()->GetAppListWindow()) |
| 1887 return false; | 1890 return false; |
| 1888 const LauncherItem* item = LauncherItemForView(view); | 1891 const LauncherItem* item = LauncherItemForView(view); |
| 1889 if (!item) | 1892 if (!item) |
| 1890 return true; | 1893 return true; |
| 1891 LauncherItemDelegate* item_delegate = | 1894 LauncherItemDelegate* item_delegate = |
| 1892 item_manager_->GetLauncherItemDelegate(item->type); | 1895 item_manager_->GetLauncherItemDelegate(item->id); |
| 1893 return item_delegate->ShouldShowTooltip(*item); | 1896 return item_delegate ? item_delegate->ShouldShowTooltip() : false; |
| 1894 } | 1897 } |
| 1895 | 1898 |
| 1896 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1899 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1897 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1900 ShelfWidget* shelf = RootWindowController::ForLauncher( |
| 1898 GetWidget()->GetNativeView())->shelf(); | 1901 GetWidget()->GetNativeView())->shelf(); |
| 1899 ash::ShelfAlignment align = shelf->GetAlignment(); | 1902 ash::ShelfAlignment align = shelf->GetAlignment(); |
| 1900 const gfx::Rect bounds = GetBoundsInScreen(); | 1903 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1901 int distance = 0; | 1904 int distance = 0; |
| 1902 switch (align) { | 1905 switch (align) { |
| 1903 case ash::SHELF_ALIGNMENT_BOTTOM: | 1906 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 1904 distance = bounds.y() - coordinate.y(); | 1907 distance = bounds.y() - coordinate.y(); |
| 1905 break; | 1908 break; |
| 1906 case ash::SHELF_ALIGNMENT_LEFT: | 1909 case ash::SHELF_ALIGNMENT_LEFT: |
| 1907 distance = coordinate.x() - bounds.right(); | 1910 distance = coordinate.x() - bounds.right(); |
| 1908 break; | 1911 break; |
| 1909 case ash::SHELF_ALIGNMENT_RIGHT: | 1912 case ash::SHELF_ALIGNMENT_RIGHT: |
| 1910 distance = bounds.x() - coordinate.x(); | 1913 distance = bounds.x() - coordinate.x(); |
| 1911 break; | 1914 break; |
| 1912 case ash::SHELF_ALIGNMENT_TOP: | 1915 case ash::SHELF_ALIGNMENT_TOP: |
| 1913 distance = coordinate.y() - bounds.bottom(); | 1916 distance = coordinate.y() - bounds.bottom(); |
| 1914 break; | 1917 break; |
| 1915 } | 1918 } |
| 1916 return distance > 0 ? distance : 0; | 1919 return distance > 0 ? distance : 0; |
| 1917 } | 1920 } |
| 1918 | 1921 |
| 1919 } // namespace internal | 1922 } // namespace internal |
| 1920 } // namespace ash | 1923 } // namespace ash |
| OLD | NEW |