| 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/common/shelf/shelf_view.h" | 5 #include "ash/common/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/common/ash_constants.h" | 10 #include "ash/common/ash_constants.h" |
| 11 #include "ash/common/drag_drop/drag_image_view.h" | 11 #include "ash/common/drag_drop/drag_image_view.h" |
| 12 #include "ash/common/scoped_root_window_for_new_windows.h" | 12 #include "ash/common/scoped_root_window_for_new_windows.h" |
| 13 #include "ash/common/shelf/app_list_button.h" | 13 #include "ash/common/shelf/app_list_button.h" |
| 14 #include "ash/common/shelf/overflow_bubble.h" | 14 #include "ash/common/shelf/overflow_bubble.h" |
| 15 #include "ash/common/shelf/overflow_bubble_view.h" | 15 #include "ash/common/shelf/overflow_bubble_view.h" |
| 16 #include "ash/common/shelf/overflow_button.h" | 16 #include "ash/common/shelf/overflow_button.h" |
| 17 #include "ash/common/shelf/shelf_application_menu_model.h" |
| 17 #include "ash/common/shelf/shelf_button.h" | 18 #include "ash/common/shelf/shelf_button.h" |
| 18 #include "ash/common/shelf/shelf_constants.h" | 19 #include "ash/common/shelf/shelf_constants.h" |
| 19 #include "ash/common/shelf/shelf_delegate.h" | 20 #include "ash/common/shelf/shelf_delegate.h" |
| 20 #include "ash/common/shelf/shelf_model.h" | 21 #include "ash/common/shelf/shelf_model.h" |
| 21 #include "ash/common/shelf/shelf_widget.h" | 22 #include "ash/common/shelf/shelf_widget.h" |
| 22 #include "ash/common/shelf/wm_shelf.h" | 23 #include "ash/common/shelf/wm_shelf.h" |
| 23 #include "ash/common/shell_delegate.h" | 24 #include "ash/common/shell_delegate.h" |
| 24 #include "ash/common/wm/root_window_finder.h" | 25 #include "ash/common/wm/root_window_finder.h" |
| 25 #include "ash/common/wm_lookup.h" | 26 #include "ash/common/wm_lookup.h" |
| 26 #include "ash/common/wm_shell.h" | 27 #include "ash/common/wm_shell.h" |
| 27 #include "ash/common/wm_window.h" | 28 #include "ash/common/wm_window.h" |
| 28 #include "base/auto_reset.h" | 29 #include "base/auto_reset.h" |
| 30 #include "base/memory/ptr_util.h" |
| 29 #include "base/metrics/histogram_macros.h" | 31 #include "base/metrics/histogram_macros.h" |
| 30 #include "grit/ash_strings.h" | 32 #include "grit/ash_strings.h" |
| 31 #include "ui/accessibility/ax_node_data.h" | 33 #include "ui/accessibility/ax_node_data.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/models/simple_menu_model.h" | 35 #include "ui/base/models/simple_menu_model.h" |
| 34 #include "ui/compositor/layer.h" | 36 #include "ui/compositor/layer.h" |
| 35 #include "ui/compositor/layer_animator.h" | 37 #include "ui/compositor/layer_animator.h" |
| 36 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 38 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 37 #include "ui/events/event_utils.h" | 39 #include "ui/events/event_utils.h" |
| 38 #include "ui/gfx/canvas.h" | 40 #include "ui/gfx/canvas.h" |
| (...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 } | 1608 } |
| 1607 | 1609 |
| 1608 void ShelfView::OnSetShelfItemDelegate(ShelfID id, | 1610 void ShelfView::OnSetShelfItemDelegate(ShelfID id, |
| 1609 ShelfItemDelegate* item_delegate) {} | 1611 ShelfItemDelegate* item_delegate) {} |
| 1610 | 1612 |
| 1611 bool ShelfView::ShowListMenuForView(const ShelfItem& item, | 1613 bool ShelfView::ShowListMenuForView(const ShelfItem& item, |
| 1612 views::View* source, | 1614 views::View* source, |
| 1613 const ui::Event& event, | 1615 const ui::Event& event, |
| 1614 views::InkDrop* ink_drop) { | 1616 views::InkDrop* ink_drop) { |
| 1615 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id); | 1617 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id); |
| 1616 std::unique_ptr<ui::MenuModel> list_menu_model( | 1618 ShelfAppMenuItemList menu_items = |
| 1617 item_delegate->CreateApplicationMenu(event.flags())); | 1619 item_delegate->GetAppMenuItems(event.flags()); |
| 1618 | 1620 |
| 1619 // Make sure we have a menu and it has at least two items in addition to the | 1621 // The application list menu should only show for two or more items; return |
| 1620 // application title and the 3 spacing separators. | 1622 // false here to ensure that other behavior is triggered (eg. activating or |
| 1621 if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5) | 1623 // minimizing a single associated window, or launching a pinned shelf item). |
| 1624 if (menu_items.size() < 2) |
| 1622 return false; | 1625 return false; |
| 1623 | 1626 |
| 1624 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); | 1627 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); |
| 1625 context_menu_id_ = item.id; | 1628 context_menu_id_ = item.id; |
| 1626 ShowMenu(std::move(list_menu_model), source, gfx::Point(), false, | 1629 ShowMenu(base::MakeUnique<ShelfApplicationMenuModel>(item.title, |
| 1627 ui::GetMenuSourceTypeForEvent(event), ink_drop); | 1630 std::move(menu_items)), |
| 1631 source, gfx::Point(), false, ui::GetMenuSourceTypeForEvent(event), |
| 1632 ink_drop); |
| 1628 return true; | 1633 return true; |
| 1629 } | 1634 } |
| 1630 | 1635 |
| 1631 void ShelfView::ShowContextMenuForView(views::View* source, | 1636 void ShelfView::ShowContextMenuForView(views::View* source, |
| 1632 const gfx::Point& point, | 1637 const gfx::Point& point, |
| 1633 ui::MenuSourceType source_type) { | 1638 ui::MenuSourceType source_type) { |
| 1634 last_pressed_index_ = -1; | 1639 last_pressed_index_ = -1; |
| 1635 | 1640 |
| 1636 const ShelfItem* item = ShelfItemForView(source); | 1641 const ShelfItem* item = ShelfItemForView(source); |
| 1637 if (!item) { | 1642 if (!item) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 | 1774 |
| 1770 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1775 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1771 const gfx::Rect bounds = GetBoundsInScreen(); | 1776 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1772 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1777 int distance = wm_shelf_->SelectValueForShelfAlignment( |
| 1773 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1778 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1774 bounds.x() - coordinate.x()); | 1779 bounds.x() - coordinate.x()); |
| 1775 return distance > 0 ? distance : 0; | 1780 return distance > 0 ? distance : 0; |
| 1776 } | 1781 } |
| 1777 | 1782 |
| 1778 } // namespace ash | 1783 } // namespace ash |
| OLD | NEW |