OLD | NEW |
---|---|
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 if (!is_visible_) { | |
mfomitchev
2016/09/30 18:41:19
This will always be true
thanhph
2016/09/30 19:03:52
reverted
| |
46 views::WindowManagerConnection::Get() | |
mfomitchev
2016/09/30 18:41:19
Shouldn't do this here, the idea was to not regist
thanhph
2016/09/30 19:03:52
reverted
| |
47 ->pointer_watcher_event_router() | |
48 ->AddPointerWatcher(this, false); | |
49 is_visible_ = true; | |
mfomitchev
2016/09/30 18:41:19
Why?
thanhph
2016/09/30 19:03:52
reverted
| |
50 } | |
51 } | |
41 | 52 |
42 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {} | 53 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() { |
54 if (is_visible_) { | |
55 views::WindowManagerConnection::Get() | |
56 ->pointer_watcher_event_router() | |
57 ->RemovePointerWatcher(this); | |
58 | |
59 is_visible_ = false; | |
mfomitchev
2016/09/30 18:41:19
We don't need to update is_visible_ when destroyin
thanhph
2016/09/30 19:03:52
reverted
| |
60 } | |
61 } | |
43 | 62 |
44 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { | 63 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { |
45 return view_delegate_factory_->GetDelegate(); | 64 return view_delegate_factory_->GetDelegate(); |
46 } | 65 } |
47 | 66 |
48 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, | 67 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, |
49 int64_t display_id, | 68 int64_t display_id, |
50 int current_apps_page) { | 69 int current_apps_page) { |
51 view_ = view; | 70 view_ = view; |
52 | 71 |
53 // Note: This would place the app list into the USER_WINDOWS container, unlike | 72 // Note: This would place the app list into the USER_WINDOWS container, unlike |
54 // in classic ash, where it has it's own container. | 73 // 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 | 74 // 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. | 75 // init at (0, 0) and then reset its anchor point. |
57 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like | 76 // 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 | 77 // 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 | 78 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by |
60 // passing the display_id or the scale factor directly | 79 // passing the display_id or the scale factor directly |
61 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, | 80 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, |
62 gfx::Point(), views::BubbleBorder::FLOAT, | 81 gfx::Point(), views::BubbleBorder::FLOAT, |
63 true /* border_accepts_events */); | 82 true /* border_accepts_events */); |
64 | 83 |
65 view->SetAnchorPoint( | 84 view->SetAnchorPoint( |
66 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); | 85 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); |
67 | 86 |
68 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. | 87 // 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. | 88 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. |
72 // TODO(mfomitchev): Setup DnD. | 89 // TODO(mfomitchev): Setup DnD. |
73 // TODO(mfomitchev): UpdateAutoHideState for shelf | 90 // TODO(mfomitchev): UpdateAutoHideState for shelf |
74 } | 91 } |
75 | 92 |
76 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { | 93 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { |
77 is_visible_ = true; | 94 if (!is_visible_) { |
mfomitchev
2016/09/30 18:41:19
I don't think OnShown can ever be called when is_v
thanhph
2016/09/30 19:03:52
reverted
| |
95 views::WindowManagerConnection::Get() | |
96 ->pointer_watcher_event_router() | |
97 ->AddPointerWatcher(this, false); | |
98 is_visible_ = true; | |
99 } | |
78 } | 100 } |
79 | 101 |
80 void AppListPresenterDelegateMus::OnDismissed() { | 102 void AppListPresenterDelegateMus::OnDismissed() { |
81 DCHECK(is_visible_); | 103 if (is_visible_) { |
mfomitchev
2016/09/30 18:41:19
Why did you replace DCHECK with if? OnDismissed sh
thanhph
2016/09/30 19:03:52
Good to know this. Thanks!
| |
82 is_visible_ = false; | 104 views::WindowManagerConnection::Get() |
105 ->pointer_watcher_event_router() | |
106 ->RemovePointerWatcher(this); | |
107 is_visible_ = false; | |
108 } | |
83 } | 109 } |
84 | 110 |
85 void AppListPresenterDelegateMus::UpdateBounds() { | 111 void AppListPresenterDelegateMus::UpdateBounds() { |
86 if (!view_ || !is_visible_) | 112 if (!view_ || !is_visible_) |
87 return; | 113 return; |
114 view_->UpdateBounds(); | |
115 } | |
88 | 116 |
89 view_->UpdateBounds(); | 117 void AppListPresenterDelegateMus::OnPointerEventObserved( |
mfomitchev
2016/09/30 18:41:19
Nit: Move this method to after GetVisibilityAnimat
thanhph
2016/09/30 19:03:52
done!
| |
118 const ui::PointerEvent& event, | |
119 const gfx::Point& location_in_screen, | |
120 views::Widget* target) { | |
121 DCHECK(is_visible_); | |
122 | |
123 // Dismiss app list on a mouse click or touch outside of the app list window. | |
124 if (event.type() == ui::ET_TOUCH_PRESSED || | |
125 event.type() == ui::ET_POINTER_DOWN) { | |
126 if (!target || target != view_->GetWidget()) | |
127 presenter_->Dismiss(); | |
128 } | |
90 } | 129 } |
91 | 130 |
92 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( | 131 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( |
93 aura::Window* root_window) { | 132 aura::Window* root_window) { |
94 // TODO(mfomitchev): Classic ash does different animation here depending on | 133 // TODO(mfomitchev): Classic ash does different animation here depending on |
95 // shelf alignment. We should probably do that too. | 134 // shelf alignment. We should probably do that too. |
96 return gfx::Vector2d(0, kAnimationOffset); | 135 return gfx::Vector2d(0, kAnimationOffset); |
97 } | 136 } |
OLD | NEW |