| 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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // Ignore if this is a repost event on the last pressed shelf item. | 659 // Ignore if this is a repost event on the last pressed shelf item. |
| 660 int index = view_model_->GetIndexOfView(view); | 660 int index = view_model_->GetIndexOfView(view); |
| 661 if (index == -1) | 661 if (index == -1) |
| 662 return false; | 662 return false; |
| 663 return !IsRepostEvent(event) || last_pressed_index_ != index; | 663 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 664 } | 664 } |
| 665 | 665 |
| 666 void ShelfView::PointerPressedOnButton(views::View* view, | 666 void ShelfView::PointerPressedOnButton(views::View* view, |
| 667 Pointer pointer, | 667 Pointer pointer, |
| 668 const ui::LocatedEvent& event) { | 668 const ui::LocatedEvent& event) { |
| 669 if (IsShowingMenu()) |
| 670 launcher_menu_runner_->Cancel(); |
| 669 if (drag_view_) | 671 if (drag_view_) |
| 670 return; | 672 return; |
| 671 | 673 |
| 672 int index = view_model_->GetIndexOfView(view); | 674 int index = view_model_->GetIndexOfView(view); |
| 673 if (index == -1 || view_model_->view_size() <= 1) | 675 if (index == -1 || view_model_->view_size() <= 1) |
| 674 return; // View is being deleted, ignore request. | 676 return; // View is being deleted, ignore request. |
| 675 | 677 |
| 676 if (view == GetAppListButton()) | 678 if (view == GetAppListButton()) |
| 677 return; // View is not draggable, ignore request. | 679 return; // View is not draggable, ignore request. |
| 678 | 680 |
| (...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 break; | 1738 break; |
| 1737 case SHELF_ALIGNMENT_RIGHT: | 1739 case SHELF_ALIGNMENT_RIGHT: |
| 1738 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, | 1740 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, |
| 1739 point.y()); | 1741 point.y()); |
| 1740 break; | 1742 break; |
| 1741 } | 1743 } |
| 1742 } | 1744 } |
| 1743 last_pressed_index_ = -1; | 1745 last_pressed_index_ = -1; |
| 1744 | 1746 |
| 1745 const ShelfItem* item = ShelfItemForView(source); | 1747 const ShelfItem* item = ShelfItemForView(source); |
| 1746 if (!item) { | 1748 if (!item || item->type == TYPE_APP_LIST) { |
| 1747 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); | 1749 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); |
| 1748 return; | 1750 return; |
| 1749 } | 1751 } |
| 1750 | 1752 |
| 1751 std::unique_ptr<ui::MenuModel> context_menu_model( | 1753 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1752 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); | 1754 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item)); |
| 1753 if (!context_menu_model) | 1755 if (!context_menu_model) |
| 1754 return; | 1756 return; |
| 1755 | 1757 |
| 1756 context_menu_id_ = item ? item->id : ShelfID(); | 1758 context_menu_id_ = item ? item->id : ShelfID(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1767 menu_model_ = std::move(menu_model); | 1769 menu_model_ = std::move(menu_model); |
| 1768 menu_model_adapter_.reset(new views::MenuModelAdapter( | 1770 menu_model_adapter_.reset(new views::MenuModelAdapter( |
| 1769 menu_model_.get(), | 1771 menu_model_.get(), |
| 1770 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); | 1772 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); |
| 1771 | 1773 |
| 1772 closing_event_time_ = base::TimeTicks(); | 1774 closing_event_time_ = base::TimeTicks(); |
| 1773 int run_types = 0; | 1775 int run_types = 0; |
| 1774 if (context_menu) | 1776 if (context_menu) |
| 1775 run_types |= | 1777 run_types |= |
| 1776 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; | 1778 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::FIXED_ANCHOR; |
| 1779 |
| 1780 // Shelf items can only be dragged if the shelf is not in auto-hide. |
| 1781 if (shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) |
| 1782 run_types |= views::MenuRunner::SEND_GESTURE_EVENTS_TO_OWNER; |
| 1783 |
| 1777 launcher_menu_runner_.reset( | 1784 launcher_menu_runner_.reset( |
| 1778 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); | 1785 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); |
| 1779 | 1786 |
| 1780 // Place new windows on the same display as the button that spawned the menu. | 1787 // Place new windows on the same display as the button that spawned the menu. |
| 1781 aura::Window* window = source->GetWidget()->GetNativeWindow(); | 1788 aura::Window* window = source->GetWidget()->GetNativeWindow(); |
| 1782 scoped_root_window_for_new_windows_.reset( | 1789 scoped_root_window_for_new_windows_.reset( |
| 1783 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 1790 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 1784 | 1791 |
| 1785 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; | 1792 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| 1786 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); | 1793 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 } | 1826 } |
| 1820 | 1827 |
| 1821 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. | 1828 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| 1822 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, | 1829 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| 1823 menu_alignment, source_type); | 1830 menu_alignment, source_type); |
| 1824 } | 1831 } |
| 1825 | 1832 |
| 1826 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { | 1833 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { |
| 1827 context_menu_id_ = ShelfID(); | 1834 context_menu_id_ = ShelfID(); |
| 1828 | 1835 |
| 1829 // Hide the hide overflow bubble after showing a context menu for its items. | |
| 1830 if (owner_overflow_bubble_) | |
| 1831 owner_overflow_bubble_->Hide(); | |
| 1832 | |
| 1833 closing_event_time_ = launcher_menu_runner_->closing_event_time(); | 1836 closing_event_time_ = launcher_menu_runner_->closing_event_time(); |
| 1834 | 1837 |
| 1835 if (ink_drop) | 1838 if (ink_drop) |
| 1836 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); | 1839 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); |
| 1837 | 1840 |
| 1838 launcher_menu_runner_.reset(); | 1841 launcher_menu_runner_.reset(); |
| 1839 menu_model_adapter_.reset(); | 1842 menu_model_adapter_.reset(); |
| 1840 menu_model_.reset(); | 1843 menu_model_.reset(); |
| 1841 scoped_root_window_for_new_windows_.reset(); | 1844 scoped_root_window_for_new_windows_.reset(); |
| 1842 | 1845 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 if (pointer == TOUCH && | 1915 if (pointer == TOUCH && |
| 1913 (base::TimeTicks::Now() - touch_press_time_) < | 1916 (base::TimeTicks::Now() - touch_press_time_) < |
| 1914 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { | 1917 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { |
| 1915 return false; | 1918 return false; |
| 1916 } | 1919 } |
| 1917 | 1920 |
| 1918 return true; | 1921 return true; |
| 1919 } | 1922 } |
| 1920 | 1923 |
| 1921 } // namespace ash | 1924 } // namespace ash |
| OLD | NEW |