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 (IsShowingMenu()) | |
| 646 launcher_menu_runner_->Cancel(); | |
| 645 if (drag_view_) | 647 if (drag_view_) |
| 646 return; | 648 return; |
| 647 | 649 |
| 648 int index = view_model_->GetIndexOfView(view); | 650 int index = view_model_->GetIndexOfView(view); |
| 649 if (index == -1 || view_model_->view_size() <= 1) | 651 if (index == -1 || view_model_->view_size() <= 1) |
| 650 return; // View is being deleted, ignore request. | 652 return; // View is being deleted, ignore request. |
| 651 | 653 |
| 652 if (view == GetAppListButton()) | 654 if (view == GetAppListButton()) |
| 653 return; // View is not draggable, ignore request. | 655 return; // View is not draggable, ignore request. |
| 654 | 656 |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 case SHELF_ALIGNMENT_LEFT: | 1651 case SHELF_ALIGNMENT_LEFT: |
| 1650 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); | 1652 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); |
| 1651 break; | 1653 break; |
| 1652 case SHELF_ALIGNMENT_RIGHT: | 1654 case SHELF_ALIGNMENT_RIGHT: |
| 1653 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); | 1655 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); |
| 1654 break; | 1656 break; |
| 1655 } | 1657 } |
| 1656 last_pressed_index_ = -1; | 1658 last_pressed_index_ = -1; |
| 1657 | 1659 |
| 1658 const ShelfItem* item = ShelfItemForView(source); | 1660 const ShelfItem* item = ShelfItemForView(source); |
| 1659 if (!item) { | 1661 if (!item || item->type == TYPE_APP_LIST) { |
| 1660 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); | 1662 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
| 1661 return; | 1663 return; |
| 1662 } | 1664 } |
| 1663 | 1665 |
| 1664 std::unique_ptr<ui::MenuModel> context_menu_model( | 1666 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1665 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); | 1667 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); |
| 1666 if (!context_menu_model) | 1668 if (!context_menu_model) |
| 1667 return; | 1669 return; |
| 1668 | 1670 |
| 1669 context_menu_id_ = item ? item->id : ShelfID(); | 1671 context_menu_id_ = item ? item->id : ShelfID(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1680 menu_model_ = std::move(menu_model); | 1682 menu_model_ = std::move(menu_model); |
| 1681 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1683 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1682 menu_model_.get(), | 1684 menu_model_.get(), |
| 1683 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1685 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1684 | 1686 |
| 1685 closing_event_time_ = base::TimeTicks(); | 1687 closing_event_time_ = base::TimeTicks(); |
| 1686 int run_types = 0; | 1688 int run_types = 0; |
| 1687 if (context_menu) | 1689 if (context_menu) |
| 1688 run_types |= | 1690 run_types |= |
| 1689 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1691 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1692 | |
| 1693 // Shelf items can only be dragged if the shelf is not autohide. | |
|
msw
2017/05/17 23:03:30
nit: s/autohide/in auto-hide/ (or 'is not auto-hid
minch1
2017/05/26 23:01:11
update the comment according to next comment.
| |
| 1694 if (wm_shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) | |
|
msw
2017/05/17 23:03:30
It's not clear to me how the comment above relates
minch1
2017/05/18 17:42:57
We cannot drag the shelf items when the shelf is a
msw
2017/05/18 20:42:20
Why won't the shelf itself correctly ignore drag t
minch1
2017/05/26 23:01:11
Done.
| |
| 1695 run_types |= views::MenuRunner::OWNER_NEEDS_DRAG; | |
| 1696 | |
| 1690 launcher_menu_runner_.reset( | 1697 launcher_menu_runner_.reset( |
| 1691 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1698 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1692 | 1699 |
| 1693 // Place new windows on the same display as the button that spawned the menu. | 1700 // Place new windows on the same display as the button that spawned the menu. |
| 1694 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); | 1701 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow()); |
| 1695 scoped_root_window_for_new_windows_.reset( | 1702 scoped_root_window_for_new_windows_.reset( |
| 1696 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1703 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1697 | 1704 |
| 1698 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1705 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1699 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1706 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1732 } | 1739 } |
| 1733 | 1740 |
| 1734 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1741 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1735 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1742 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| 1736 menu_alignment, source_type); | 1743 menu_alignment, source_type); |
| 1737 } | 1744 } |
| 1738 | 1745 |
| 1739 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1746 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1740 context_menu_id_ = ShelfID(); | 1747 context_menu_id_ = ShelfID(); |
| 1741 | 1748 |
| 1742 // Hide the hide overflow bubble after showing a context menu for its items. | |
| 1743 if (owner_overflow_bubble_) | |
| 1744 owner_overflow_bubble_->Hide(); | |
| 1745 | |
| 1746 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1749 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1747 | 1750 |
| 1748 if (ink_drop) | 1751 if (ink_drop) |
| 1749 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1752 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1750 | 1753 |
| 1751 launcher_menu_runner_.reset(); | 1754 launcher_menu_runner_.reset(); |
| 1752 menu_model_adapter_.reset(); | 1755 menu_model_adapter_.reset(); |
| 1753 menu_model_.reset(); | 1756 menu_model_.reset(); |
| 1754 scoped_root_window_for_new_windows_.reset(); | 1757 scoped_root_window_for_new_windows_.reset(); |
| 1755 | 1758 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 if (pointer == TOUCH && | 1825 if (pointer == TOUCH && |
| 1823 (base::TimeTicks::Now() - touch_press_time_) < | 1826 (base::TimeTicks::Now() - touch_press_time_) < |
| 1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1827 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1825 return false; | 1828 return false; |
| 1826 } | 1829 } |
| 1827 | 1830 |
| 1828 return true; | 1831 return true; |
| 1829 } | 1832 } |
| 1830 | 1833 |
| 1831 } // namespace ash | 1834 } // namespace ash |
| OLD | NEW |