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 | |
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 #include "ui/views/pointer_watcher.h" | |
mfomitchev
2016/09/29 18:38:25
We already include this in .h
thanhph
2016/09/29 19:43:04
Good catch. Thanks!
| |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Gets the point at the center of the display. The calculation should exclude | 15 // 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 | 16 // 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 | 17 // |minimum_height|, its bottom will be extended to that height (so that the |
17 // app list never starts above the top of the screen). | 18 // app list never starts above the top of the screen). |
18 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { | 19 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { |
19 // TODO(mfomitchev): account for virtual keyboard. | 20 // TODO(mfomitchev): account for virtual keyboard. |
20 std::vector<display::Display> displays = | 21 std::vector<display::Display> displays = |
21 display::Screen::GetScreen()->GetAllDisplays(); | 22 display::Screen::GetScreen()->GetAllDisplays(); |
22 auto it = std::find_if(displays.begin(), displays.end(), | 23 auto it = std::find_if(displays.begin(), displays.end(), |
23 [display_id](const display::Display& display) { | 24 [display_id](const display::Display& display) { |
24 return display.id() == display_id; | 25 return display.id() == display_id; |
25 }); | 26 }); |
26 DCHECK(it != displays.end()); | 27 DCHECK(it != displays.end()); |
27 gfx::Rect bounds = it->bounds(); | 28 gfx::Rect bounds = it->bounds(); |
28 | 29 |
29 // Apply the |minimum_height|. | 30 // Apply the |minimum_height|. |
30 if (bounds.height() < minimum_height) | 31 if (bounds.height() < minimum_height) |
31 bounds.set_height(minimum_height); | 32 bounds.set_height(minimum_height); |
32 | 33 |
33 return bounds.CenterPoint(); | 34 return bounds.CenterPoint(); |
34 } | 35 } |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 AppListPresenterDelegateMus::AppListPresenterDelegateMus( | 39 AppListPresenterDelegateMus::AppListPresenterDelegateMus( |
40 app_list::AppListPresenter* presenter, | |
39 app_list::AppListViewDelegateFactory* view_delegate_factory) | 41 app_list::AppListViewDelegateFactory* view_delegate_factory) |
40 : view_delegate_factory_(view_delegate_factory) {} | 42 : view_delegate_factory_(view_delegate_factory), presenter_(presenter) {} |
mfomitchev
2016/09/29 18:38:25
Nit: Would be better to have the argument order to
thanhph
2016/09/29 19:43:04
I agree. I still don't know why I get the below er
mfomitchev
2016/09/29 20:00:35
The declaration order (in .h) needs to match the i
thanhph
2016/09/29 20:42:51
done. thanks!
| |
41 | 43 |
42 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {} | 44 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() { |
45 // Remove mouse/touch monitor for this delegate | |
mfomitchev
2016/09/29 18:38:25
Nit: This comment isn't particularly helpful, I'd
thanhph
2016/09/29 19:43:04
Ok. Removed!
| |
46 views::WindowManagerConnection::Get() | |
47 ->pointer_watcher_event_router() | |
48 ->RemovePointerWatcher(this); | |
49 } | |
43 | 50 |
44 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { | 51 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { |
45 return view_delegate_factory_->GetDelegate(); | 52 return view_delegate_factory_->GetDelegate(); |
46 } | 53 } |
47 | 54 |
48 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, | 55 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, |
49 int64_t display_id, | 56 int64_t display_id, |
50 int current_apps_page) { | 57 int current_apps_page) { |
58 LOG(ERROR) << "\n\n!!!!!. Initializing AppListPresenterDelegateMus\n\n\n"; | |
mfomitchev
2016/09/29 18:38:25
remove
thanhph
2016/09/29 19:43:04
done!
| |
51 view_ = view; | 59 view_ = view; |
52 | 60 |
53 // Note: This would place the app list into the USER_WINDOWS container, unlike | 61 // Note: This would place the app list into the USER_WINDOWS container, unlike |
54 // in classic ash, where it has it's own container. | 62 // 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 | 63 // 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. | 64 // init at (0, 0) and then reset its anchor point. |
57 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like | 65 // 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 | 66 // 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 | 67 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by |
60 // passing the display_id or the scale factor directly | 68 // passing the display_id or the scale factor directly |
61 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, | 69 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, |
62 gfx::Point(), views::BubbleBorder::FLOAT, | 70 gfx::Point(), views::BubbleBorder::FLOAT, |
63 true /* border_accepts_events */); | 71 true /* border_accepts_events */); |
64 | 72 |
65 view->SetAnchorPoint( | 73 view->SetAnchorPoint( |
66 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); | 74 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); |
67 | 75 |
76 // add mouse-touch capture function to this delegate | |
mfomitchev
2016/09/29 18:38:26
Nit: This comment isn't particularly helpful, I'd
thanhph
2016/09/29 19:43:04
removed. thanks!
| |
77 views::WindowManagerConnection::Get() | |
78 ->pointer_watcher_event_router() | |
79 ->AddPointerWatcher(this, true); | |
80 | |
68 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. | 81 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. |
69 // TODO(mfomitchev): Setup dismissing on mouse/touch gesture anywhere outside | 82 // TODO(mfomitchev): Setup dismissing on mouse/touch gesture anywhere outside |
mfomitchev
2016/09/29 18:38:25
You can now remove this TODO :)
thanhph
2016/09/29 19:43:04
nice!
| |
70 // the bounds of the app list. | 83 // the bounds of the app list. |
71 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. | 84 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. |
72 // TODO(mfomitchev): Setup DnD. | 85 // TODO(mfomitchev): Setup DnD. |
73 // TODO(mfomitchev): UpdateAutoHideState for shelf | 86 // TODO(mfomitchev): UpdateAutoHideState for shelf |
74 } | 87 } |
75 | 88 |
76 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { | 89 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { |
77 is_visible_ = true; | 90 is_visible_ = true; |
78 } | 91 } |
79 | 92 |
80 void AppListPresenterDelegateMus::OnDismissed() { | 93 void AppListPresenterDelegateMus::OnDismissed() { |
81 DCHECK(is_visible_); | |
82 is_visible_ = false; | |
83 } | 94 } |
84 | 95 |
85 void AppListPresenterDelegateMus::UpdateBounds() { | 96 void AppListPresenterDelegateMus::UpdateBounds() { |
86 if (!view_ || !is_visible_) | 97 if (!view_ || !is_visible_) |
98 | |
mfomitchev
2016/09/29 18:38:26
remove blank line
thanhph
2016/09/29 20:42:51
ok
| |
87 return; | 99 return; |
88 | 100 |
89 view_->UpdateBounds(); | 101 view_->UpdateBounds(); |
90 } | 102 } |
91 | 103 |
104 void AppListPresenterDelegateMus::OnPointerEventObserved( | |
105 const ui::PointerEvent& event, | |
106 const gfx::Point& location_in_screen, | |
107 views::Widget* target) { | |
108 if (event.type() == ui::ET_TOUCH_PRESSED || | |
mfomitchev
2016/09/29 18:38:26
Nit: Add a comment in the beginning saying that th
thanhph
2016/09/29 19:43:04
done! thanks!
| |
109 event.type() == ui::ET_POINTER_DOWN) { | |
110 if (!target) { | |
111 presenter_->Dismiss(); | |
112 } else if (!target->GetWindowBoundsInScreen().ApproximatelyEqual( | |
mfomitchev
2016/09/29 18:38:25
Explain to me again why can't we just compare targ
thanhph
2016/09/29 19:43:04
It works indeed. I change the code to target != vi
| |
113 view_->GetWidget()->GetWindowBoundsInScreen(), 0)) { | |
114 // else close the app list widget if clicks elsewhere | |
115 presenter_->Dismiss(); | |
116 } | |
117 } | |
118 } | |
119 | |
92 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( | 120 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( |
93 aura::Window* root_window) { | 121 aura::Window* root_window) { |
94 // TODO(mfomitchev): Classic ash does different animation here depending on | 122 // TODO(mfomitchev): Classic ash does different animation here depending on |
95 // shelf alignment. We should probably do that too. | 123 // shelf alignment. We should probably do that too. |
96 return gfx::Vector2d(0, kAnimationOffset); | 124 return gfx::Vector2d(0, kAnimationOffset); |
97 } | 125 } |
OLD | NEW |