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

Side by Side Diff: chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.cc

Issue 2364173002: Add app_list_presenterr pointer in app_list_presenter_delegate_mus to use dismiss function (Closed)
Patch Set: revert delegate on OnShown and OnDismissed functions. conform function orders. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" 5 #include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h"
6 6
7 #include "ui/app_list/presenter/app_list_presenter.h"
7 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" 8 #include "ui/app_list/presenter/app_list_view_delegate_factory.h"
8 #include "ui/app_list/views/app_list_view.h" 9 #include "ui/app_list/views/app_list_view.h"
9 #include "ui/display/display.h" 10 #include "ui/display/display.h"
10 #include "ui/display/screen.h" 11 #include "ui/display/screen.h"
12 #include "ui/views/mus/pointer_watcher_event_router.h"
13 #include "ui/views/mus/window_manager_connection.h"
11 14
12 namespace { 15 namespace {
13 16
14 // Gets the point at the center of the display. The calculation should exclude 17 // Gets the point at the center of the display. The calculation should exclude
15 // the virtual keyboard area. If the height of the display area is less than 18 // the virtual keyboard area. If the height of the display area is less than
16 // |minimum_height|, its bottom will be extended to that height (so that the 19 // |minimum_height|, its bottom will be extended to that height (so that the
17 // app list never starts above the top of the screen). 20 // app list never starts above the top of the screen).
18 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { 21 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) {
19 // TODO(mfomitchev): account for virtual keyboard. 22 // TODO(mfomitchev): account for virtual keyboard.
20 std::vector<display::Display> displays = 23 std::vector<display::Display> displays =
21 display::Screen::GetScreen()->GetAllDisplays(); 24 display::Screen::GetScreen()->GetAllDisplays();
22 auto it = std::find_if(displays.begin(), displays.end(), 25 auto it = std::find_if(displays.begin(), displays.end(),
23 [display_id](const display::Display& display) { 26 [display_id](const display::Display& display) {
24 return display.id() == display_id; 27 return display.id() == display_id;
25 }); 28 });
26 DCHECK(it != displays.end()); 29 DCHECK(it != displays.end());
27 gfx::Rect bounds = it->bounds(); 30 gfx::Rect bounds = it->bounds();
28 31
29 // Apply the |minimum_height|. 32 // Apply the |minimum_height|.
30 if (bounds.height() < minimum_height) 33 if (bounds.height() < minimum_height)
31 bounds.set_height(minimum_height); 34 bounds.set_height(minimum_height);
32 35
33 return bounds.CenterPoint(); 36 return bounds.CenterPoint();
34 } 37 }
35 38
36 } // namespace 39 } // namespace
37 40
38 AppListPresenterDelegateMus::AppListPresenterDelegateMus( 41 AppListPresenterDelegateMus::AppListPresenterDelegateMus(
42 app_list::AppListPresenter* presenter,
39 app_list::AppListViewDelegateFactory* view_delegate_factory) 43 app_list::AppListViewDelegateFactory* view_delegate_factory)
40 : view_delegate_factory_(view_delegate_factory) {} 44 : presenter_(presenter), view_delegate_factory_(view_delegate_factory) {
45 views::WindowManagerConnection::Get()
46 ->pointer_watcher_event_router()
47 ->AddPointerWatcher(this, false);
48 }
41 49
42 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {} 50 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {
51 views::WindowManagerConnection::Get()
52 ->pointer_watcher_event_router()
53 ->RemovePointerWatcher(this);
54 }
43 55
44 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { 56 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() {
45 return view_delegate_factory_->GetDelegate(); 57 return view_delegate_factory_->GetDelegate();
46 } 58 }
47 59
48 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, 60 void AppListPresenterDelegateMus::Init(app_list::AppListView* view,
49 int64_t display_id, 61 int64_t display_id,
50 int current_apps_page) { 62 int current_apps_page) {
51 view_ = view; 63 view_ = view;
52 64
53 // Note: This would place the app list into the USER_WINDOWS container, unlike 65 // Note: This would place the app list into the USER_WINDOWS container, unlike
54 // in classic ash, where it has it's own container. 66 // in classic ash, where it has it's own container.
55 // Note: We can't center the app list until we have its dimensions, so we 67 // Note: We can't center the app list until we have its dimensions, so we
56 // init at (0, 0) and then reset its anchor point. 68 // init at (0, 0) and then reset its anchor point.
57 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like 69 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like
58 // the only thing this is used for is choosing the right scale factor in 70 // the only thing this is used for is choosing the right scale factor in
59 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by 71 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by
60 // passing the display_id or the scale factor directly 72 // passing the display_id or the scale factor directly
61 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, 73 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page,
62 gfx::Point(), views::BubbleBorder::FLOAT, 74 gfx::Point(), views::BubbleBorder::FLOAT,
63 true /* border_accepts_events */); 75 true /* border_accepts_events */);
64 76
65 view->SetAnchorPoint( 77 view->SetAnchorPoint(
66 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); 78 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view)));
67 79
68 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. 80 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change.
69 // TODO(mfomitchev): Setup dismissing on mouse/touch gesture anywhere outside
70 // the bounds of the app list.
71 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. 81 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end.
72 // TODO(mfomitchev): Setup DnD. 82 // TODO(mfomitchev): Setup DnD.
73 // TODO(mfomitchev): UpdateAutoHideState for shelf 83 // TODO(mfomitchev): UpdateAutoHideState for shelf
74 } 84 }
75 85
76 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { 86 void AppListPresenterDelegateMus::OnShown(int64_t display_id) {
77 is_visible_ = true; 87 is_visible_ = true;
78 } 88 }
79 89
80 void AppListPresenterDelegateMus::OnDismissed() { 90 void AppListPresenterDelegateMus::OnDismissed() {
81 DCHECK(is_visible_);
mfomitchev 2016/09/30 19:05:25 Keep the DCHECK
thanhph 2016/09/30 19:09:09 added back.
82 is_visible_ = false; 91 is_visible_ = false;
83 } 92 }
84 93
85 void AppListPresenterDelegateMus::UpdateBounds() { 94 void AppListPresenterDelegateMus::UpdateBounds() {
86 if (!view_ || !is_visible_) 95 if (!view_ || !is_visible_)
87 return; 96 return;
88 97
89 view_->UpdateBounds(); 98 view_->UpdateBounds();
90 } 99 }
91 100
92 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( 101 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset(
93 aura::Window* root_window) { 102 aura::Window* root_window) {
94 // TODO(mfomitchev): Classic ash does different animation here depending on 103 // TODO(mfomitchev): Classic ash does different animation here depending on
95 // shelf alignment. We should probably do that too. 104 // shelf alignment. We should probably do that too.
96 return gfx::Vector2d(0, kAnimationOffset); 105 return gfx::Vector2d(0, kAnimationOffset);
97 } 106 }
107
108 void AppListPresenterDelegateMus::OnPointerEventObserved(
109 const ui::PointerEvent& event,
110 const gfx::Point& location_in_screen,
111 views::Widget* target) {
112 // Dismiss app list on a mouse click or touch outside of the app list window.
113 if (event.type() == ui::ET_TOUCH_PRESSED ||
114 event.type() == ui::ET_POINTER_DOWN) {
115 if (!target || target != view_->GetWidget())
116 presenter_->Dismiss();
117 }
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698