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 25 matching lines...) Expand all Loading... | |
| 36 #include "ui/base/models/simple_menu_model.h" | 36 #include "ui/base/models/simple_menu_model.h" |
| 37 #include "ui/compositor/layer.h" | 37 #include "ui/compositor/layer.h" |
| 38 #include "ui/compositor/layer_animator.h" | 38 #include "ui/compositor/layer_animator.h" |
| 39 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 39 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 40 #include "ui/events/event_utils.h" | 40 #include "ui/events/event_utils.h" |
| 41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/geometry/point.h" | 42 #include "ui/gfx/geometry/point.h" |
| 43 #include "ui/views/animation/bounds_animator.h" | 43 #include "ui/views/animation/bounds_animator.h" |
| 44 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 45 #include "ui/views/controls/button/image_button.h" | 45 #include "ui/views/controls/button/image_button.h" |
| 46 #include "ui/views/controls/menu/menu_controller.h" | |
| 46 #include "ui/views/controls/menu/menu_model_adapter.h" | 47 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 47 #include "ui/views/controls/menu/menu_runner.h" | 48 #include "ui/views/controls/menu/menu_runner.h" |
| 48 #include "ui/views/focus/focus_search.h" | 49 #include "ui/views/focus/focus_search.h" |
| 49 #include "ui/views/view_model.h" | 50 #include "ui/views/view_model.h" |
| 50 #include "ui/views/view_model_utils.h" | 51 #include "ui/views/view_model_utils.h" |
| 51 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
| 52 #include "ui/wm/core/coordinate_conversion.h" | 53 #include "ui/wm/core/coordinate_conversion.h" |
| 53 | 54 |
| 54 using gfx::Animation; | 55 using gfx::Animation; |
| 55 using views::View; | 56 using views::View; |
| (...skipping 579 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. | 636 // Ignore if this is a repost event on the last pressed shelf item. |
| 636 int index = view_model_->GetIndexOfView(view); | 637 int index = view_model_->GetIndexOfView(view); |
| 637 if (index == -1) | 638 if (index == -1) |
| 638 return false; | 639 return false; |
| 639 return !IsRepostEvent(event) || last_pressed_index_ != index; | 640 return !IsRepostEvent(event) || last_pressed_index_ != index; |
| 640 } | 641 } |
| 641 | 642 |
| 642 void ShelfView::PointerPressedOnButton(views::View* view, | 643 void ShelfView::PointerPressedOnButton(views::View* view, |
| 643 Pointer pointer, | 644 Pointer pointer, |
| 644 const ui::LocatedEvent& event) { | 645 const ui::LocatedEvent& event) { |
| 646 if (IsShowingMenu()) | |
| 647 launcher_menu_runner_->Cancel(); | |
| 645 if (drag_view_) | 648 if (drag_view_) |
| 646 return; | 649 return; |
| 647 | 650 |
| 648 int index = view_model_->GetIndexOfView(view); | 651 int index = view_model_->GetIndexOfView(view); |
| 649 if (index == -1 || view_model_->view_size() <= 1) | 652 if (index == -1 || view_model_->view_size() <= 1) |
| 650 return; // View is being deleted, ignore request. | 653 return; // View is being deleted, ignore request. |
| 651 | 654 |
| 652 if (view == GetAppListButton()) | 655 if (view == GetAppListButton()) |
| 653 return; // View is not draggable, ignore request. | 656 return; // View is not draggable, ignore request. |
| 654 | 657 |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 case SHELF_ALIGNMENT_LEFT: | 1652 case SHELF_ALIGNMENT_LEFT: |
| 1650 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); | 1653 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); |
| 1651 break; | 1654 break; |
| 1652 case SHELF_ALIGNMENT_RIGHT: | 1655 case SHELF_ALIGNMENT_RIGHT: |
| 1653 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); | 1656 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y()); |
| 1654 break; | 1657 break; |
| 1655 } | 1658 } |
| 1656 last_pressed_index_ = -1; | 1659 last_pressed_index_ = -1; |
| 1657 | 1660 |
| 1658 const ShelfItem* item = ShelfItemForView(source); | 1661 const ShelfItem* item = ShelfItemForView(source); |
| 1659 if (!item) { | 1662 int index = view_model_->GetIndexOfView(source); |
| 1663 if (index == 0 || !item) { | |
|
xiyuan
2017/05/15 19:20:52
Why we need to include |index| == 0? Can you docum
minch1
2017/05/15 22:16:34
This is for the launcher icon (the first item in t
xiyuan
2017/05/15 22:41:10
It is more accurate to check |item| type than the
minch1
2017/05/16 22:13:38
Done.
| |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1724 } | 1728 } |
| 1725 } else { | 1729 } else { |
| 1726 // Distinguish the touch events that triggered on the bottom or left / right | 1730 // Distinguish the touch events that triggered on the bottom or left / right |
| 1727 // shelf. Since they should have different |MenuAnchorPosition|. | 1731 // shelf. Since they should have different |MenuAnchorPosition|. |
| 1728 if (wm_shelf_->IsHorizontalAlignment()) | 1732 if (wm_shelf_->IsHorizontalAlignment()) |
| 1729 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER; | 1733 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER; |
| 1730 else | 1734 else |
| 1731 menu_alignment = views::MENU_ANCHOR_FIXED_SIDECENTER; | 1735 menu_alignment = views::MENU_ANCHOR_FIXED_SIDECENTER; |
| 1732 } | 1736 } |
| 1733 | 1737 |
| 1738 // No dragging if shelf is autohide. | |
| 1739 if (wm_shelf()->auto_hide_behavior() == SHELF_AUTO_HIDE_BEHAVIOR_NEVER) | |
| 1740 views::MenuController::SetDoCancel(false); | |
| 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 |