Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1764)

Side by Side Diff: ash/shelf/shelf_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698