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/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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 // Ignore if this is a repost event on the last pressed shelf item. | 635 // Ignore if this is a repost event on the last pressed shelf item. |
| 636 int index = view_model_->GetIndexOfView(view); | 636 int index = view_model_->GetIndexOfView(view); |
| 637 if (index == -1) | 637 if (index == -1) |
| 638 return false; | 638 return false; |
| 639 return !IsRepostEvent(event) || last_pressed_index_ != index; | 639 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 640 } | 640 } |
| 641 | 641 |
| 642 void ShelfView::PointerPressedOnButton(views::View* view, | 642 void ShelfView::PointerPressedOnButton(views::View* view, |
| 643 Pointer pointer, | 643 Pointer pointer, |
| 644 const ui::LocatedEvent& event) { | 644 const ui::LocatedEvent& event) { |
| 645 #if defined(OS_CHROMEOS) | |
|
xiyuan
2017/05/16 22:46:57
not needed
minch1
2017/05/17 16:55:37
Done.
| |
| 646 if (IsShowingMenu()) | |
| 647 launcher_menu_runner_->Cancel(); | |
| 648 #endif | |
| 645 if (drag_view_) | 649 if (drag_view_) |
| 646 return; | 650 return; |
| 647 | 651 |
| 648 int index = view_model_->GetIndexOfView(view); | 652 int index = view_model_->GetIndexOfView(view); |
| 649 if (index == -1 || view_model_->view_size() <= 1) | 653 if (index == -1 || view_model_->view_size() <= 1) |
| 650 return; // View is being deleted, ignore request. | 654 return; // View is being deleted, ignore request. |
| 651 | 655 |
| 652 if (view == GetAppListButton()) | 656 if (view == GetAppListButton()) |
| 653 return; // View is not draggable, ignore request. | 657 return; // View is not draggable, ignore request. |
| 654 | 658 |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 case SHELF_ALIGNMENT_LEFT: | 1653 case SHELF_ALIGNMENT_LEFT: |
| 1650 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); | 1654 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); |
| 1651 break; | 1655 break; |
| 1652 case SHELF_ALIGNMENT_RIGHT: | 1656 case SHELF_ALIGNMENT_RIGHT: |
| 1653 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); | 1657 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); |
| 1654 break; | 1658 break; |
| 1655 } | 1659 } |
| 1656 last_pressed_index_ = -1; | 1660 last_pressed_index_ = -1; |
| 1657 | 1661 |
| 1658 const ShelfItem* item = ShelfItemForView(source); | 1662 const ShelfItem* item = ShelfItemForView(source); |
| 1659 if (!item) { | 1663 if (!item || item->type == TYPE_APP_LIST) { |
| 1660 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); | 1664 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
| 1661 return; | 1665 return; |
| 1662 } | 1666 } |
| 1663 | 1667 |
| 1664 std::unique_ptr<ui::MenuModel> context_menu_model( | 1668 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1665 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); | 1669 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); |
| 1666 if (!context_menu_model) | 1670 if (!context_menu_model) |
| 1667 return; | 1671 return; |
| 1668 | 1672 |
| 1669 context_menu_id_ = item ? item->id : ShelfID(); | 1673 context_menu_id_ = item ? item->id : ShelfID(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1680 menu_model_ = std::move(menu_model); | 1684 menu_model_ = std::move(menu_model); |
| 1681 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1685 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1682 menu_model_.get(), | 1686 menu_model_.get(), |
| 1683 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1687 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1684 | 1688 |
| 1685 closing_event_time_ = base::TimeTicks(); | 1689 closing_event_time_ = base::TimeTicks(); |
| 1686 int run_types = 0; | 1690 int run_types = 0; |
| 1687 if (context_menu) | 1691 if (context_menu) |
| 1688 run_types |= | 1692 run_types |= |
| 1689 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1693 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1694 | |
| 1695 #if defined(OS_CHROMEOS) | |
|
xiyuan
2017/05/16 22:46:56
not needed
minch1
2017/05/17 16:55:37
Done.
| |
| 1696 // Shelf items can only be dragged if the shelf is not autohide. | |
| 1697 if (wm_shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) | |
| 1698 run_types |= views::MenuRunner::IS_DRAGGABLE; | |
| 1699 #endif | |
| 1700 | |
| 1690 launcher_menu_runner_.reset( | 1701 launcher_menu_runner_.reset( |
| 1691 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1702 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1692 | 1703 |
| 1693 // Place new windows on the same display as the button that spawned the menu. | 1704 // Place new windows on the same display as the button that spawned the menu. |
| 1694 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); | 1705 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); |
| 1695 scoped_root_window_for_new_windows_.reset( | 1706 scoped_root_window_for_new_windows_.reset( |
| 1696 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1707 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1697 | 1708 |
| 1698 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1709 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1699 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1710 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1732 } | 1743 } |
| 1733 | 1744 |
| 1734 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1745 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1735 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1746 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| 1736 menu_alignment, source_type); | 1747 menu_alignment, source_type); |
| 1737 } | 1748 } |
| 1738 | 1749 |
| 1739 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1750 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1740 context_menu_id_ = ShelfID(); | 1751 context_menu_id_ = ShelfID(); |
| 1741 | 1752 |
| 1753 #if !defined(OS_CHROMEOS) | |
|
xiyuan
2017/05/16 22:46:57
remove the whole block if we don't need it on chro
minch1
2017/05/17 16:55:37
Done.
| |
| 1742 // Hide the hide overflow bubble after showing a context menu for its items. | 1754 // Hide the hide overflow bubble after showing a context menu for its items. |
| 1743 if (owner_overflow_bubble_) | 1755 if (owner_overflow_bubble_) |
| 1744 owner_overflow_bubble_->Hide(); | 1756 owner_overflow_bubble_->Hide(); |
| 1757 #endif | |
| 1745 | 1758 |
| 1746 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1759 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1747 | 1760 |
| 1748 if (ink_drop) | 1761 if (ink_drop) |
| 1749 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1762 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1750 | 1763 |
| 1751 launcher_menu_runner_.reset(); | 1764 launcher_menu_runner_.reset(); |
| 1752 menu_model_adapter_.reset(); | 1765 menu_model_adapter_.reset(); |
| 1753 menu_model_.reset(); | 1766 menu_model_.reset(); |
| 1754 scoped_root_window_for_new_windows_.reset(); | 1767 scoped_root_window_for_new_windows_.reset(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 if (pointer == TOUCH && | 1835 if (pointer == TOUCH && |
| 1823 (base::TimeTicks::Now() - touch_press_time_) < | 1836 (base::TimeTicks::Now() - touch_press_time_) < |
| 1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1837 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1825 return false; | 1838 return false; |
| 1826 } | 1839 } |
| 1827 | 1840 |
| 1828 return true; | 1841 return true; |
| 1829 } | 1842 } |
| 1830 | 1843 |
| 1831 } // namespace ash | 1844 } // namespace ash |
| OLD | NEW |