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 #include "ui/app_list/presenter/app_list_presenter.h" |
mfomitchev
2016/09/29 21:21:22
insert blank line
See https://google.github.io/sty
thanhph
2016/09/29 23:08:00
done! Let me know if it's incorrect.
| |
7 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" | 7 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" |
8 #include "ui/app_list/views/app_list_view.h" | 8 #include "ui/app_list/views/app_list_view.h" |
9 #include "ui/display/display.h" | 9 #include "ui/display/display.h" |
10 #include "ui/display/screen.h" | 10 #include "ui/display/screen.h" |
11 #include "ui/views/mus/pointer_watcher_event_router.h" | |
12 #include "ui/views/mus/window_manager_connection.h" | |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 // Gets the point at the center of the display. The calculation should exclude | 16 // 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 | 17 // 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 | 18 // |minimum_height|, its bottom will be extended to that height (so that the |
17 // app list never starts above the top of the screen). | 19 // app list never starts above the top of the screen). |
18 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { | 20 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { |
19 // TODO(mfomitchev): account for virtual keyboard. | 21 // TODO(mfomitchev): account for virtual keyboard. |
20 std::vector<display::Display> displays = | 22 std::vector<display::Display> displays = |
21 display::Screen::GetScreen()->GetAllDisplays(); | 23 display::Screen::GetScreen()->GetAllDisplays(); |
22 auto it = std::find_if(displays.begin(), displays.end(), | 24 auto it = std::find_if(displays.begin(), displays.end(), |
23 [display_id](const display::Display& display) { | 25 [display_id](const display::Display& display) { |
24 return display.id() == display_id; | 26 return display.id() == display_id; |
25 }); | 27 }); |
26 DCHECK(it != displays.end()); | 28 DCHECK(it != displays.end()); |
27 gfx::Rect bounds = it->bounds(); | 29 gfx::Rect bounds = it->bounds(); |
28 | 30 |
29 // Apply the |minimum_height|. | 31 // Apply the |minimum_height|. |
30 if (bounds.height() < minimum_height) | 32 if (bounds.height() < minimum_height) |
31 bounds.set_height(minimum_height); | 33 bounds.set_height(minimum_height); |
32 | 34 |
33 return bounds.CenterPoint(); | 35 return bounds.CenterPoint(); |
34 } | 36 } |
35 | 37 |
36 } // namespace | 38 } // namespace |
37 | 39 |
38 AppListPresenterDelegateMus::AppListPresenterDelegateMus( | 40 AppListPresenterDelegateMus::AppListPresenterDelegateMus( |
41 app_list::AppListPresenter* presenter, | |
39 app_list::AppListViewDelegateFactory* view_delegate_factory) | 42 app_list::AppListViewDelegateFactory* view_delegate_factory) |
40 : view_delegate_factory_(view_delegate_factory) {} | 43 : presenter_(presenter), view_delegate_factory_(view_delegate_factory) {} |
41 | 44 |
42 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {} | 45 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() { |
46 views::WindowManagerConnection::Get() | |
mfomitchev
2016/09/29 21:21:22
If Init() is never called, I think this will trip
thanhph
2016/09/29 23:08:00
Good catch! I haven't been able to start the app l
| |
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) { |
51 view_ = view; | 58 view_ = view; |
52 | 59 |
53 // Note: This would place the app list into the USER_WINDOWS container, unlike | 60 // Note: This would place the app list into the USER_WINDOWS container, unlike |
54 // in classic ash, where it has it's own container. | 61 // 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 | 62 // 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. | 63 // init at (0, 0) and then reset its anchor point. |
57 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like | 64 // 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 | 65 // 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 | 66 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by |
60 // passing the display_id or the scale factor directly | 67 // passing the display_id or the scale factor directly |
61 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, | 68 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, |
62 gfx::Point(), views::BubbleBorder::FLOAT, | 69 gfx::Point(), views::BubbleBorder::FLOAT, |
63 true /* border_accepts_events */); | 70 true /* border_accepts_events */); |
64 | 71 |
65 view->SetAnchorPoint( | 72 view->SetAnchorPoint( |
66 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); | 73 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); |
67 | 74 |
75 views::WindowManagerConnection::Get() | |
76 ->pointer_watcher_event_router() | |
77 ->AddPointerWatcher(this, true); | |
mfomitchev
2016/09/29 21:21:21
I don't think we want moves? So we need to pass fa
thanhph
2016/09/29 23:08:00
I agree. I don't know why this value got reverted
| |
78 | |
68 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. | 79 // 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. | 80 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. |
72 // TODO(mfomitchev): Setup DnD. | 81 // TODO(mfomitchev): Setup DnD. |
73 // TODO(mfomitchev): UpdateAutoHideState for shelf | 82 // TODO(mfomitchev): UpdateAutoHideState for shelf |
74 } | 83 } |
75 | 84 |
76 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { | 85 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { |
77 is_visible_ = true; | 86 is_visible_ = true; |
78 } | 87 } |
79 | 88 |
80 void AppListPresenterDelegateMus::OnDismissed() { | 89 void AppListPresenterDelegateMus::OnDismissed() { |
81 DCHECK(is_visible_); | |
82 is_visible_ = false; | |
83 } | 90 } |
84 | 91 |
85 void AppListPresenterDelegateMus::UpdateBounds() { | 92 void AppListPresenterDelegateMus::UpdateBounds() { |
86 if (!view_ || !is_visible_) | 93 if (!view_ || !is_visible_) |
87 return; | 94 return; |
88 | 95 |
89 view_->UpdateBounds(); | 96 view_->UpdateBounds(); |
90 } | 97 } |
91 | 98 |
99 void AppListPresenterDelegateMus::OnPointerEventObserved( | |
100 const ui::PointerEvent& event, | |
101 const gfx::Point& location_in_screen, | |
102 views::Widget* target) { | |
103 // Dismiss app list on a mouse click or touch outside of the app list window. | |
104 if (event.type() == ui::ET_TOUCH_PRESSED || | |
105 event.type() == ui::ET_POINTER_DOWN) { | |
106 if (!target or target != view_->GetWidget()) { | |
mfomitchev
2016/09/29 21:21:21
|| instead of "or"
Also no {} brackets for 1-line
thanhph
2016/09/29 23:08:00
good catch. Thanks!
| |
107 presenter_->Dismiss(); | |
108 } | |
109 } | |
110 } | |
111 | |
92 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( | 112 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( |
93 aura::Window* root_window) { | 113 aura::Window* root_window) { |
94 // TODO(mfomitchev): Classic ash does different animation here depending on | 114 // TODO(mfomitchev): Classic ash does different animation here depending on |
95 // shelf alignment. We should probably do that too. | 115 // shelf alignment. We should probably do that too. |
96 return gfx::Vector2d(0, kAnimationOffset); | 116 return gfx::Vector2d(0, kAnimationOffset); |
97 } | 117 } |
OLD | NEW |