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

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

Issue 2194353002: mash: Migrate ScopedTargetRootWindow to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reflow comment Created 4 years, 4 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/aura/wm_window_aura.h" 10 #include "ash/aura/wm_window_aura.h"
11 #include "ash/common/ash_constants.h" 11 #include "ash/common/ash_constants.h"
12 #include "ash/common/ash_switches.h" 12 #include "ash/common/ash_switches.h"
13 #include "ash/common/scoped_root_window_for_new_windows.h"
13 #include "ash/common/shelf/app_list_button.h" 14 #include "ash/common/shelf/app_list_button.h"
14 #include "ash/common/shelf/overflow_bubble.h" 15 #include "ash/common/shelf/overflow_bubble.h"
15 #include "ash/common/shelf/overflow_bubble_view.h" 16 #include "ash/common/shelf/overflow_bubble_view.h"
16 #include "ash/common/shelf/overflow_button.h" 17 #include "ash/common/shelf/overflow_button.h"
17 #include "ash/common/shelf/shelf_button.h" 18 #include "ash/common/shelf/shelf_button.h"
18 #include "ash/common/shelf/shelf_constants.h" 19 #include "ash/common/shelf/shelf_constants.h"
19 #include "ash/common/shelf/shelf_delegate.h" 20 #include "ash/common/shelf/shelf_delegate.h"
20 #include "ash/common/shelf/shelf_menu_model.h" 21 #include "ash/common/shelf/shelf_menu_model.h"
21 #include "ash/common/shelf/shelf_model.h" 22 #include "ash/common/shelf/shelf_model.h"
22 #include "ash/common/shelf/wm_shelf.h" 23 #include "ash/common/shelf/wm_shelf.h"
23 #include "ash/common/shell_delegate.h" 24 #include "ash/common/shell_delegate.h"
24 #include "ash/common/wm/root_window_finder.h" 25 #include "ash/common/wm/root_window_finder.h"
26 #include "ash/common/wm_lookup.h"
25 #include "ash/common/wm_shell.h" 27 #include "ash/common/wm_shell.h"
26 #include "ash/drag_drop/drag_image_view.h" 28 #include "ash/drag_drop/drag_image_view.h"
27 #include "ash/scoped_target_root_window.h"
28 #include "ash/shelf/shelf.h" 29 #include "ash/shelf/shelf.h"
29 #include "ash/shelf/shelf_icon_observer.h" 30 #include "ash/shelf/shelf_icon_observer.h"
30 #include "ash/shelf/shelf_widget.h" 31 #include "ash/shelf/shelf_widget.h"
31 #include "base/auto_reset.h" 32 #include "base/auto_reset.h"
32 #include "base/metrics/histogram.h" 33 #include "base/metrics/histogram.h"
33 #include "grit/ash_strings.h" 34 #include "grit/ash_strings.h"
34 #include "ui/accessibility/ax_view_state.h" 35 #include "ui/accessibility/ax_view_state.h"
35 #include "ui/aura/client/screen_position_client.h"
36 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
37 #include "ui/aura/window_event_dispatcher.h"
38 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/models/simple_menu_model.h" 38 #include "ui/base/models/simple_menu_model.h"
40 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/compositor/layer.h" 40 #include "ui/compositor/layer.h"
42 #include "ui/compositor/layer_animator.h" 41 #include "ui/compositor/layer_animator.h"
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 42 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
44 #include "ui/events/event_utils.h" 43 #include "ui/events/event_utils.h"
45 #include "ui/gfx/canvas.h" 44 #include "ui/gfx/canvas.h"
46 #include "ui/gfx/geometry/point.h" 45 #include "ui/gfx/geometry/point.h"
47 #include "ui/views/animation/bounds_animator.h" 46 #include "ui/views/animation/bounds_animator.h"
(...skipping 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 1693
1695 // None of the checks in ShouldEventActivateButton() affects overflow button. 1694 // None of the checks in ShouldEventActivateButton() affects overflow button.
1696 // So, it is safe to be checked after handling overflow button. 1695 // So, it is safe to be checked after handling overflow button.
1697 if (!ShouldEventActivateButton(sender, event)) 1696 if (!ShouldEventActivateButton(sender, event))
1698 return; 1697 return;
1699 1698
1700 // Record the index for the last pressed shelf item. 1699 // Record the index for the last pressed shelf item.
1701 last_pressed_index_ = view_model_->GetIndexOfView(sender); 1700 last_pressed_index_ = view_model_->GetIndexOfView(sender);
1702 DCHECK_LT(-1, last_pressed_index_); 1701 DCHECK_LT(-1, last_pressed_index_);
1703 1702
1704 scoped_target_root_window_.reset(new ScopedTargetRootWindow( 1703 // Place new windows on the same display as the button.
1705 sender->GetWidget()->GetNativeView()->GetRootWindow())); 1704 WmWindow* root_window =
msw 2016/08/02 01:04:50 optional nit: use a GetRootWindow pattern consiste
James Cook 2016/08/02 16:16:04 Done.
1705 WmLookup::Get()->GetWindowForWidget(sender->GetWidget())->GetRootWindow();
1706 scoped_root_window_for_new_windows_.reset(
1707 new ScopedRootWindowForNewWindows(root_window));
1706 // Slow down activation animations if shift key is pressed. 1708 // Slow down activation animations if shift key is pressed.
1707 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; 1709 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
1708 if (event.IsShiftDown()) { 1710 if (event.IsShiftDown()) {
1709 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 1711 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
1710 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 1712 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
1711 } 1713 }
1712 1714
1713 // Collect usage statistics before we decide what to do with the click. 1715 // Collect usage statistics before we decide what to do with the click.
1714 switch (model_->items()[last_pressed_index_].type) { 1716 switch (model_->items()[last_pressed_index_].type) {
1715 case TYPE_APP_SHORTCUT: 1717 case TYPE_APP_SHORTCUT:
(...skipping 26 matching lines...) Expand all
1742 performed_action); 1744 performed_action);
1743 1745
1744 // For the app list menu no TRIGGERED ink drop effect is needed and it 1746 // For the app list menu no TRIGGERED ink drop effect is needed and it
1745 // handles its own ACTIVATED/DEACTIVATED states. 1747 // handles its own ACTIVATED/DEACTIVATED states.
1746 if (performed_action == ShelfItemDelegate::kNewWindowCreated || 1748 if (performed_action == ShelfItemDelegate::kNewWindowCreated ||
1747 (performed_action != ShelfItemDelegate::kAppListMenuShown && 1749 (performed_action != ShelfItemDelegate::kAppListMenuShown &&
1748 !ShowListMenuForView(model_->items()[last_pressed_index_], sender, event, 1750 !ShowListMenuForView(model_->items()[last_pressed_index_], sender, event,
1749 ink_drop))) { 1751 ink_drop))) {
1750 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED); 1752 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED);
1751 } 1753 }
1752 // Allow the menu to clear |scoped_target_root_window_| during OnMenuClosed. 1754 // Allow the menu to clear |scoped_root_window_for_new_windows_| during
1755 // OnMenuClosed.
1753 if (!IsShowingMenu()) 1756 if (!IsShowingMenu())
1754 scoped_target_root_window_.reset(); 1757 scoped_root_window_for_new_windows_.reset();
1755 } 1758 }
1756 1759
1757 bool ShelfView::ShowListMenuForView(const ShelfItem& item, 1760 bool ShelfView::ShowListMenuForView(const ShelfItem& item,
1758 views::View* source, 1761 views::View* source,
1759 const ui::Event& event, 1762 const ui::Event& event,
1760 views::InkDrop* ink_drop) { 1763 views::InkDrop* ink_drop) {
1761 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id); 1764 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id);
1762 std::unique_ptr<ui::MenuModel> list_menu_model( 1765 std::unique_ptr<ui::MenuModel> list_menu_model(
1763 item_delegate->CreateApplicationMenu(event.flags())); 1766 item_delegate->CreateApplicationMenu(event.flags()));
1764 1767
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 menu_model_.get(), 1809 menu_model_.get(),
1807 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); 1810 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop)));
1808 1811
1809 closing_event_time_ = base::TimeTicks(); 1812 closing_event_time_ = base::TimeTicks();
1810 int run_types = views::MenuRunner::ASYNC; 1813 int run_types = views::MenuRunner::ASYNC;
1811 if (context_menu) 1814 if (context_menu)
1812 run_types |= views::MenuRunner::CONTEXT_MENU; 1815 run_types |= views::MenuRunner::CONTEXT_MENU;
1813 launcher_menu_runner_.reset( 1816 launcher_menu_runner_.reset(
1814 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); 1817 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types));
1815 1818
1816 aura::Window* window = source->GetWidget()->GetNativeWindow(); 1819 // Place new windows on the same display as the button that spawned the menu.
1817 scoped_target_root_window_.reset( 1820 WmWindow* window = WmLookup::Get()->GetWindowForWidget(source->GetWidget());
1818 new ScopedTargetRootWindow(window->GetRootWindow())); 1821 scoped_root_window_for_new_windows_.reset(
1822 new ScopedRootWindowForNewWindows(window->GetRootWindow()));
1819 1823
1820 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; 1824 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT;
1821 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); 1825 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size());
1822 1826
1823 if (!context_menu) { 1827 if (!context_menu) {
1824 // Application lists use a bubble. 1828 // Application lists use a bubble.
1825 // It is possible to invoke the menu while it is sliding into view. To cover 1829 // It is possible to invoke the menu while it is sliding into view. To cover
1826 // that case, the screen coordinates are offsetted by the animation delta. 1830 // that case, the screen coordinates are offsetted by the animation delta.
1827 anchor = source->GetBoundsInScreen() + 1831 anchor = source->GetBoundsInScreen() + (window->GetTargetBounds().origin() -
1828 (window->GetTargetBounds().origin() - window->bounds().origin()); 1832 window->GetBounds().origin());
1829 1833
1830 // Adjust the anchor location for shelf items with asymmetrical borders. 1834 // Adjust the anchor location for shelf items with asymmetrical borders.
1831 if (source->border()) 1835 if (source->border())
1832 anchor.Inset(source->border()->GetInsets()); 1836 anchor.Inset(source->border()->GetInsets());
1833 1837
1834 // Determine the menu alignment dependent on the shelf. 1838 // Determine the menu alignment dependent on the shelf.
1835 menu_alignment = shelf_->SelectValueForShelfAlignment( 1839 menu_alignment = shelf_->SelectValueForShelfAlignment(
1836 views::MENU_ANCHOR_BUBBLE_ABOVE, views::MENU_ANCHOR_BUBBLE_RIGHT, 1840 views::MENU_ANCHOR_BUBBLE_ABOVE, views::MENU_ANCHOR_BUBBLE_RIGHT,
1837 views::MENU_ANCHOR_BUBBLE_LEFT); 1841 views::MENU_ANCHOR_BUBBLE_LEFT);
1838 } 1842 }
(...skipping 13 matching lines...) Expand all
1852 owner_overflow_bubble_->HideBubbleAndRefreshButton(); 1856 owner_overflow_bubble_->HideBubbleAndRefreshButton();
1853 1857
1854 closing_event_time_ = launcher_menu_runner_->closing_event_time(); 1858 closing_event_time_ = launcher_menu_runner_->closing_event_time();
1855 1859
1856 if (ink_drop) 1860 if (ink_drop)
1857 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); 1861 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED);
1858 1862
1859 launcher_menu_runner_.reset(); 1863 launcher_menu_runner_.reset();
1860 menu_model_adapter_.reset(); 1864 menu_model_adapter_.reset();
1861 menu_model_.reset(); 1865 menu_model_.reset();
1862 scoped_target_root_window_.reset(); 1866 scoped_root_window_for_new_windows_.reset();
1863 1867
1864 // Auto-hide or alignment might have changed, but only for this shelf. 1868 // Auto-hide or alignment might have changed, but only for this shelf.
1865 wm_shelf_->UpdateVisibilityState(); 1869 wm_shelf_->UpdateVisibilityState();
1866 } 1870 }
1867 1871
1868 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { 1872 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
1869 FOR_EACH_OBSERVER(ShelfIconObserver, observers_, 1873 FOR_EACH_OBSERVER(ShelfIconObserver, observers_,
1870 OnShelfIconPositionsChanged()); 1874 OnShelfIconPositionsChanged());
1871 PreferredSizeChanged(); 1875 PreferredSizeChanged();
1872 } 1876 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 1912
1909 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1913 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1910 const gfx::Rect bounds = GetBoundsInScreen(); 1914 const gfx::Rect bounds = GetBoundsInScreen();
1911 int distance = shelf_->SelectValueForShelfAlignment( 1915 int distance = shelf_->SelectValueForShelfAlignment(
1912 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1916 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1913 bounds.x() - coordinate.x()); 1917 bounds.x() - coordinate.x());
1914 return distance > 0 ? distance : 0; 1918 return distance > 0 ? distance : 0;
1915 } 1919 }
1916 1920
1917 } // namespace ash 1921 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698