| 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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // Ignore if this is a repost event on the last pressed shelf item. | 645 // Ignore if this is a repost event on the last pressed shelf item. |
| 646 int index = view_model_->GetIndexOfView(view); | 646 int index = view_model_->GetIndexOfView(view); |
| 647 if (index == -1) | 647 if (index == -1) |
| 648 return false; | 648 return false; |
| 649 return !IsRepostEvent(event) || last_pressed_index_ != index; | 649 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 650 } | 650 } |
| 651 | 651 |
| 652 void ShelfView::PointerPressedOnButton(views::View* view, | 652 void ShelfView::PointerPressedOnButton(views::View* view, |
| 653 Pointer pointer, | 653 Pointer pointer, |
| 654 const ui::LocatedEvent& event) { | 654 const ui::LocatedEvent& event) { |
| 655 if (IsShowingMenu()) |
| 656 launcher_menu_runner_->Cancel(); |
| 655 if (drag_view_) | 657 if (drag_view_) |
| 656 return; | 658 return; |
| 657 | 659 |
| 658 int index = view_model_->GetIndexOfView(view); | 660 int index = view_model_->GetIndexOfView(view); |
| 659 if (index == -1 || view_model_->view_size() <= 1) | 661 if (index == -1 || view_model_->view_size() <= 1) |
| 660 return; // View is being deleted, ignore request. | 662 return; // View is being deleted, ignore request. |
| 661 | 663 |
| 662 if (view == GetAppListButton()) | 664 if (view == GetAppListButton()) |
| 663 return; // View is not draggable, ignore request. | 665 return; // View is not draggable, ignore request. |
| 664 | 666 |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 break; | 1676 break; |
| 1675 case SHELF_ALIGNMENT_RIGHT: | 1677 case SHELF_ALIGNMENT_RIGHT: |
| 1676 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, | 1678 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, |
| 1677 point.y()); | 1679 point.y()); |
| 1678 break; | 1680 break; |
| 1679 } | 1681 } |
| 1680 } | 1682 } |
| 1681 last_pressed_index_ = -1; | 1683 last_pressed_index_ = -1; |
| 1682 | 1684 |
| 1683 const ShelfItem* item = ShelfItemForView(source); | 1685 const ShelfItem* item = ShelfItemForView(source); |
| 1684 if (!item) { | 1686 if (!item || item->type == TYPE_APP_LIST) { |
| 1685 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); | 1687 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
| 1686 return; | 1688 return; |
| 1687 } | 1689 } |
| 1688 | 1690 |
| 1689 std::unique_ptr<ui::MenuModel> context_menu_model( | 1691 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1690 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); | 1692 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); |
| 1691 if (!context_menu_model) | 1693 if (!context_menu_model) |
| 1692 return; | 1694 return; |
| 1693 | 1695 |
| 1694 context_menu_id_ = item ? item->id : ShelfID(); | 1696 context_menu_id_ = item ? item->id : ShelfID(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1705 menu_model_ = std::move(menu_model); | 1707 menu_model_ = std::move(menu_model); |
| 1706 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1708 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1707 menu_model_.get(), | 1709 menu_model_.get(), |
| 1708 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1710 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1709 | 1711 |
| 1710 closing_event_time_ = base::TimeTicks(); | 1712 closing_event_time_ = base::TimeTicks(); |
| 1711 int run_types = 0; | 1713 int run_types = 0; |
| 1712 if (context_menu) | 1714 if (context_menu) |
| 1713 run_types |= | 1715 run_types |= |
| 1714 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1716 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1717 |
| 1718 // Shelf items can only be dragged if the shelf is not in auto-hide. |
| 1719 if (shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) |
| 1720 run_types |= views::MenuRunner::SEND_GESTURE_EVENTS_TO_OWNER; |
| 1721 |
| 1715 launcher_menu_runner_.reset( | 1722 launcher_menu_runner_.reset( |
| 1716 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1723 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1717 | 1724 |
| 1718 // Place new windows on the same display as the button that spawned the menu. | 1725 // Place new windows on the same display as the button that spawned the menu. |
| 1719 aura::Window* window = source->GetWidget()->GetNativeWindow(); | 1726 aura::Window* window = source->GetWidget()->GetNativeWindow(); |
| 1720 scoped_root_window_for_new_windows_.reset( | 1727 scoped_root_window_for_new_windows_.reset( |
| 1721 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1728 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1722 | 1729 |
| 1723 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1730 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1724 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1731 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 } | 1764 } |
| 1758 | 1765 |
| 1759 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1766 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1760 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1767 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| 1761 menu_alignment, source_type); | 1768 menu_alignment, source_type); |
| 1762 } | 1769 } |
| 1763 | 1770 |
| 1764 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1771 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1765 context_menu_id_ = ShelfID(); | 1772 context_menu_id_ = ShelfID(); |
| 1766 | 1773 |
| 1767 // Hide the hide overflow bubble after showing a context menu for its items. | |
| 1768 if (owner_overflow_bubble_) | |
| 1769 owner_overflow_bubble_->Hide(); | |
| 1770 | |
| 1771 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1774 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1772 | 1775 |
| 1773 if (ink_drop) | 1776 if (ink_drop) |
| 1774 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1777 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1775 | 1778 |
| 1776 launcher_menu_runner_.reset(); | 1779 launcher_menu_runner_.reset(); |
| 1777 menu_model_adapter_.reset(); | 1780 menu_model_adapter_.reset(); |
| 1778 menu_model_.reset(); | 1781 menu_model_.reset(); |
| 1779 scoped_root_window_for_new_windows_.reset(); | 1782 scoped_root_window_for_new_windows_.reset(); |
| 1780 | 1783 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 if (pointer == TOUCH && | 1850 if (pointer == TOUCH && |
| 1848 (base::TimeTicks::Now() - touch_press_time_) < | 1851 (base::TimeTicks::Now() - touch_press_time_) < |
| 1849 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1852 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1850 return false; | 1853 return false; |
| 1851 } | 1854 } |
| 1852 | 1855 |
| 1853 return true; | 1856 return true; |
| 1854 } | 1857 } |
| 1855 | 1858 |
| 1856 } // namespace ash | 1859 } // namespace ash |
| OLD | NEW |