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

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

Powered by Google App Engine
This is Rietveld 408576698