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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 view_model_->ideal_bounds(last_button_index).bottom()) | 786 view_model_->ideal_bounds(last_button_index).bottom()) |
787 + button_size + inset; | 787 + button_size + inset; |
788 if (!ash::switches::UseAlternateShelfLayout()) | 788 if (!ash::switches::UseAlternateShelfLayout()) |
789 last_icon_position += button_size; | 789 last_icon_position += button_size; |
790 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; | 790 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; |
791 if (last_icon_position < reserved_icon_space) | 791 if (last_icon_position < reserved_icon_space) |
792 end_position = last_icon_position; | 792 end_position = last_icon_position; |
793 else | 793 else |
794 end_position = std::max(end_position, reserved_icon_space); | 794 end_position = std::max(end_position, reserved_icon_space); |
795 | 795 |
796 if (bounds) { | 796 if (bounds) { |
sky
2013/10/14 13:24:43
I don't like the NULL checks here. This is error p
simonhong_
2013/10/14 21:17:32
This was changed by another CL because some caller
| |
797 bounds->overflow_bounds.set_size(gfx::Size( | 797 bounds->overflow_bounds.set_size(gfx::Size( |
798 shelf->PrimaryAxisValue(w, width()), | 798 shelf->PrimaryAxisValue(w, width()), |
799 shelf->PrimaryAxisValue(height(), h))); | 799 shelf->PrimaryAxisValue(height(), h))); |
800 } | 800 } |
801 if (ash::switches::UseAlternateShelfLayout()) | 801 if (ash::switches::UseAlternateShelfLayout()) |
802 last_visible_index_ = DetermineLastVisibleIndex( | 802 last_visible_index_ = DetermineLastVisibleIndex( |
803 end_position - button_size); | 803 end_position - button_size); |
804 else | 804 else |
805 last_visible_index_ = DetermineLastVisibleIndex( | 805 last_visible_index_ = DetermineLastVisibleIndex( |
806 end_position - inset - 2 * button_size); | 806 end_position - inset - 2 * button_size); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 drag_pointer_ = pointer; | 982 drag_pointer_ = pointer; |
983 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); | 983 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
984 | 984 |
985 if (start_drag_index_== -1) { | 985 if (start_drag_index_== -1) { |
986 CancelDrag(-1); | 986 CancelDrag(-1); |
987 return; | 987 return; |
988 } | 988 } |
989 | 989 |
990 // If the item is no longer draggable, bail out. | 990 // If the item is no longer draggable, bail out. |
991 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 991 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
992 model_->items()[start_drag_index_].type); | 992 model_->items()[start_drag_index_].id); |
993 if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) { | 993 if (!item_delegate->IsDraggable()) { |
994 CancelDrag(-1); | 994 CancelDrag(-1); |
995 return; | 995 return; |
996 } | 996 } |
997 | 997 |
998 // Move the view to the front so that it appears on top of other views. | 998 // Move the view to the front so that it appears on top of other views. |
999 ReorderChildView(drag_view_, -1); | 999 ReorderChildView(drag_view_, -1); |
1000 bounds_animator_->StopAnimatingView(drag_view_); | 1000 bounds_animator_->StopAnimatingView(drag_view_); |
1001 } | 1001 } |
1002 | 1002 |
1003 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { | 1003 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
1004 // Due to a syncing operation the application might have been removed. | 1004 // Due to a syncing operation the application might have been removed. |
1005 // Bail if it is gone. | 1005 // Bail if it is gone. |
1006 int current_index = view_model_->GetIndexOfView(drag_view_); | 1006 int current_index = view_model_->GetIndexOfView(drag_view_); |
1007 DCHECK_NE(-1, current_index); | 1007 DCHECK_NE(-1, current_index); |
1008 | 1008 |
1009 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1009 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1010 model_->items()[current_index].type); | 1010 model_->items()[current_index].id); |
1011 if (!item_delegate->IsDraggable(model_->items()[current_index])) { | 1011 if (!item_delegate->IsDraggable()) { |
1012 CancelDrag(-1); | 1012 CancelDrag(-1); |
1013 return; | 1013 return; |
1014 } | 1014 } |
1015 | 1015 |
1016 // If this is not a drag and drop host operation and not the app list item, | 1016 // If this is not a drag and drop host operation and not the app list item, |
1017 // check if the item got ripped off the shelf - if it did we are done. | 1017 // check if the item got ripped off the shelf - if it did we are done. |
1018 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && | 1018 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && |
1019 RemovableByRipOff(current_index) != NOT_REMOVABLE) { | 1019 RemovableByRipOff(current_index) != NOT_REMOVABLE) { |
1020 if (HandleRipOffDrag(event)) | 1020 if (HandleRipOffDrag(event)) |
1021 return; | 1021 return; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1346 // the list. | 1346 // the list. |
1347 if (at_end) | 1347 if (at_end) |
1348 return view_model_->view_size(); | 1348 return view_model_->view_size(); |
1349 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; | 1349 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; |
1350 } | 1350 } |
1351 | 1351 |
1352 gfx::Size LauncherView::GetPreferredSize() { | 1352 gfx::Size LauncherView::GetPreferredSize() { |
1353 CalculateIdealBounds(NULL); | 1353 CalculateIdealBounds(NULL); |
1354 | 1354 |
1355 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1355 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
1356 const int preferred_size = shelf->GetPreferredShelfSize(); | 1356 const int preferred_size = shelf->GetPreferredShelfSize(); |
sky
2013/10/14 13:24:43
Why does the Launcher need to care about the shelf
simonhong_
2013/10/14 21:17:32
IMO, different launcher icon size is used depends
| |
1357 | 1357 |
1358 const int app_list_index = view_model_->view_size() - 1; | 1358 const int app_list_index = view_model_->view_size() - 1; |
1359 const int last_button_index = is_overflow_mode() ? | 1359 const int last_button_index = is_overflow_mode() ? |
1360 last_visible_index_ : app_list_index; | 1360 last_visible_index_ : app_list_index; |
1361 const gfx::Rect last_button_bounds = | 1361 const gfx::Rect last_button_bounds = |
1362 last_button_index >= first_visible_index_ ? | 1362 last_button_index >= first_visible_index_ ? |
1363 view_model_->view_at(last_button_index)->bounds() : | 1363 view_model_->view_at(last_button_index)->bounds() : |
1364 gfx::Rect(gfx::Size(preferred_size, preferred_size)); | 1364 gfx::Rect(gfx::Size(preferred_size, preferred_size)); |
1365 | 1365 |
1366 if (shelf->IsHorizontalAlignment()) { | 1366 if (shelf->IsHorizontalAlignment()) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1534 Pointer pointer, | 1534 Pointer pointer, |
1535 const ui::LocatedEvent& event) { | 1535 const ui::LocatedEvent& event) { |
1536 if (drag_view_) | 1536 if (drag_view_) |
1537 return; | 1537 return; |
1538 | 1538 |
1539 int index = view_model_->GetIndexOfView(view); | 1539 int index = view_model_->GetIndexOfView(view); |
1540 if (index == -1) | 1540 if (index == -1) |
1541 return; | 1541 return; |
1542 | 1542 |
1543 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1543 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1544 model_->items()[index].type); | 1544 model_->items()[index].id); |
1545 if (view_model_->view_size() <= 1 || | 1545 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) |
1546 !item_delegate->IsDraggable(model_->items()[index])) | |
1547 return; // View is being deleted or not draggable, ignore request. | 1546 return; // View is being deleted or not draggable, ignore request. |
1548 | 1547 |
1549 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1548 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
1550 | 1549 |
1551 drag_view_ = view; | 1550 drag_view_ = view; |
1552 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); | 1551 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); |
1553 } | 1552 } |
1554 | 1553 |
1555 void LauncherView::PointerDraggedOnButton(views::View* view, | 1554 void LauncherView::PointerDraggedOnButton(views::View* view, |
1556 Pointer pointer, | 1555 Pointer pointer, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 tooltip_->StopTimer(); | 1605 tooltip_->StopTimer(); |
1607 } | 1606 } |
1608 | 1607 |
1609 base::string16 LauncherView::GetAccessibleName(const views::View* view) { | 1608 base::string16 LauncherView::GetAccessibleName(const views::View* view) { |
1610 int view_index = view_model_->GetIndexOfView(view); | 1609 int view_index = view_model_->GetIndexOfView(view); |
1611 // May be -1 while in the process of animating closed. | 1610 // May be -1 while in the process of animating closed. |
1612 if (view_index == -1) | 1611 if (view_index == -1) |
1613 return base::string16(); | 1612 return base::string16(); |
1614 | 1613 |
1615 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1614 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1616 model_->items()[view_index].type); | 1615 model_->items()[view_index].id); |
1617 return item_delegate->GetTitle(model_->items()[view_index]); | 1616 return item_delegate->GetTitle(); |
1618 } | 1617 } |
1619 | 1618 |
1620 void LauncherView::ButtonPressed(views::Button* sender, | 1619 void LauncherView::ButtonPressed(views::Button* sender, |
1621 const ui::Event& event) { | 1620 const ui::Event& event) { |
1622 // Do not handle mouse release during drag. | 1621 // Do not handle mouse release during drag. |
1623 if (dragging()) | 1622 if (dragging()) |
1624 return; | 1623 return; |
1625 | 1624 |
1626 if (sender == overflow_button_) { | 1625 if (sender == overflow_button_) { |
1627 ToggleOverflowBubble(); | 1626 ToggleOverflowBubble(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1666 case TYPE_APP_PANEL: | 1665 case TYPE_APP_PANEL: |
1667 break; | 1666 break; |
1668 | 1667 |
1669 case TYPE_UNDEFINED: | 1668 case TYPE_UNDEFINED: |
1670 NOTREACHED() << "LauncherItemType must be set."; | 1669 NOTREACHED() << "LauncherItemType must be set."; |
1671 break; | 1670 break; |
1672 } | 1671 } |
1673 | 1672 |
1674 LauncherItemDelegate* item_delegate = | 1673 LauncherItemDelegate* item_delegate = |
1675 item_manager_->GetLauncherItemDelegate( | 1674 item_manager_->GetLauncherItemDelegate( |
1676 model_->items()[view_index].type); | 1675 model_->items()[view_index].id); |
1677 item_delegate->ItemSelected(model_->items()[view_index], event); | 1676 item_delegate->ItemSelected(event); |
1678 | 1677 |
1679 ShowListMenuForView(model_->items()[view_index], sender, event); | 1678 ShowListMenuForView(model_->items()[view_index], sender, event); |
1680 } | 1679 } |
1681 } | 1680 } |
1682 | 1681 |
1683 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1682 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
1684 views::View* source, | 1683 views::View* source, |
1685 const ui::Event& event) { | 1684 const ui::Event& event) { |
1686 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1685 scoped_ptr<ash::LauncherMenuModel> menu_model; |
1687 LauncherItemDelegate* item_delegate = | 1686 LauncherItemDelegate* item_delegate = |
1688 item_manager_->GetLauncherItemDelegate(item.type); | 1687 item_manager_->GetLauncherItemDelegate(item.id); |
1689 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); | 1688 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); |
1690 | 1689 |
1691 // Make sure we have a menu and it has at least two items in addition to the | 1690 // Make sure we have a menu and it has at least two items in addition to the |
1692 // application title and the 3 spacing separators. | 1691 // application title and the 3 spacing separators. |
1693 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1692 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
1694 return false; | 1693 return false; |
1695 | 1694 |
1696 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1695 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1697 new LauncherMenuModelAdapter(menu_model.get())), | 1696 new LauncherMenuModelAdapter(menu_model.get())), |
1698 source, | 1697 source, |
1699 gfx::Point(), | 1698 gfx::Point(), |
(...skipping 12 matching lines...) Expand all Loading... | |
1712 model_->items()[view_index].type == TYPE_APP_LIST) { | 1711 model_->items()[view_index].type == TYPE_APP_LIST) { |
1713 view_index = -1; | 1712 view_index = -1; |
1714 } | 1713 } |
1715 | 1714 |
1716 if (view_index == -1) { | 1715 if (view_index == -1) { |
1717 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1716 Shell::GetInstance()->ShowContextMenu(point, source_type); |
1718 return; | 1717 return; |
1719 } | 1718 } |
1720 scoped_ptr<ui::MenuModel> menu_model; | 1719 scoped_ptr<ui::MenuModel> menu_model; |
1721 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( | 1720 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( |
1722 model_->items()[view_index].type); | 1721 model_->items()[view_index].id); |
1723 menu_model.reset(item_delegate->CreateContextMenu( | 1722 menu_model.reset(item_delegate->CreateContextMenu( |
1724 model_->items()[view_index], | |
1725 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1723 source->GetWidget()->GetNativeView()->GetRootWindow())); |
1726 if (!menu_model) | 1724 if (!menu_model) |
1727 return; | 1725 return; |
1728 | 1726 |
1729 base::AutoReset<LauncherID> reseter( | 1727 base::AutoReset<LauncherID> reseter( |
1730 &context_menu_id_, | 1728 &context_menu_id_, |
1731 view_index == -1 ? 0 : model_->items()[view_index].id); | 1729 view_index == -1 ? 0 : model_->items()[view_index].id); |
1732 | 1730 |
1733 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1731 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
1734 new views::MenuModelAdapter(menu_model.get())), | 1732 new views::MenuModelAdapter(menu_model.get())), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1875 } | 1873 } |
1876 | 1874 |
1877 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1875 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
1878 if (view == GetAppListButtonView() && | 1876 if (view == GetAppListButtonView() && |
1879 Shell::GetInstance()->GetAppListWindow()) | 1877 Shell::GetInstance()->GetAppListWindow()) |
1880 return false; | 1878 return false; |
1881 const LauncherItem* item = LauncherItemForView(view); | 1879 const LauncherItem* item = LauncherItemForView(view); |
1882 if (!item) | 1880 if (!item) |
1883 return true; | 1881 return true; |
1884 LauncherItemDelegate* item_delegate = | 1882 LauncherItemDelegate* item_delegate = |
1885 item_manager_->GetLauncherItemDelegate(item->type); | 1883 item_manager_->GetLauncherItemDelegate(item->id); |
1886 return item_delegate->ShouldShowTooltip(*item); | 1884 return item_delegate->ShouldShowTooltip(); |
1887 } | 1885 } |
1888 | 1886 |
1889 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1887 int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
1890 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1888 ShelfWidget* shelf = RootWindowController::ForLauncher( |
1891 GetWidget()->GetNativeView())->shelf(); | 1889 GetWidget()->GetNativeView())->shelf(); |
1892 ash::ShelfAlignment align = shelf->GetAlignment(); | 1890 ash::ShelfAlignment align = shelf->GetAlignment(); |
1893 const gfx::Rect bounds = GetBoundsInScreen(); | 1891 const gfx::Rect bounds = GetBoundsInScreen(); |
1894 int distance = 0; | 1892 int distance = 0; |
1895 switch (align) { | 1893 switch (align) { |
1896 case ash::SHELF_ALIGNMENT_BOTTOM: | 1894 case ash::SHELF_ALIGNMENT_BOTTOM: |
1897 distance = bounds.y() - coordinate.y(); | 1895 distance = bounds.y() - coordinate.y(); |
1898 break; | 1896 break; |
1899 case ash::SHELF_ALIGNMENT_LEFT: | 1897 case ash::SHELF_ALIGNMENT_LEFT: |
1900 distance = coordinate.x() - bounds.right(); | 1898 distance = coordinate.x() - bounds.right(); |
1901 break; | 1899 break; |
1902 case ash::SHELF_ALIGNMENT_RIGHT: | 1900 case ash::SHELF_ALIGNMENT_RIGHT: |
1903 distance = bounds.x() - coordinate.x(); | 1901 distance = bounds.x() - coordinate.x(); |
1904 break; | 1902 break; |
1905 case ash::SHELF_ALIGNMENT_TOP: | 1903 case ash::SHELF_ALIGNMENT_TOP: |
1906 distance = coordinate.y() - bounds.bottom(); | 1904 distance = coordinate.y() - bounds.bottom(); |
1907 break; | 1905 break; |
1908 } | 1906 } |
1909 return distance > 0 ? distance : 0; | 1907 return distance > 0 ? distance : 0; |
1910 } | 1908 } |
1911 | 1909 |
1912 } // namespace internal | 1910 } // namespace internal |
1913 } // namespace ash | 1911 } // namespace ash |
OLD | NEW |