Chromium Code Reviews| 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_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 | 11 |
| 12 #include "ui/views/mus/window_manager_connection.h" | |
| 13 #include "ui/views/pointer_watcher.h" | |
| 14 #include "ash/common/shelf/wm_shelf.h" | |
|
mfomitchev
2016/09/23 19:47:15
We shouldn't depend on any of the ash classes. Wit
thanhph
2016/09/29 18:12:08
Good point. I forget to remove these ash includes.
| |
| 15 #include "ash/common/wm_lookup.h" | |
| 16 #include "ash/common/wm_window.h" | |
| 17 #include "ash/common/shelf/app_list_button.h" | |
| 18 #include "ash/common/shelf/shelf_layout_manager.h" | |
| 19 #include "ash/common/shelf/shelf_types.h" | |
| 20 | |
| 12 namespace { | 21 namespace { |
| 13 | 22 |
| 14 // Gets the point at the center of the display. The calculation should exclude | 23 // 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 | 24 // 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 | 25 // |minimum_height|, its bottom will be extended to that height (so that the |
| 17 // app list never starts above the top of the screen). | 26 // app list never starts above the top of the screen). |
| 18 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { | 27 gfx::Point GetCenterOfDisplay(int64_t display_id, int minimum_height) { |
| 19 // TODO(mfomitchev): account for virtual keyboard. | 28 // TODO(mfomitchev): account for virtual keyboard. |
| 20 std::vector<display::Display> displays = | 29 std::vector<display::Display> displays = |
| 21 display::Screen::GetScreen()->GetAllDisplays(); | 30 display::Screen::GetScreen()->GetAllDisplays(); |
| 22 auto it = std::find_if(displays.begin(), displays.end(), | 31 auto it = std::find_if(displays.begin(), displays.end(), |
| 23 [display_id](const display::Display& display) { | 32 [display_id](const display::Display& display) { |
| 24 return display.id() == display_id; | 33 return display.id() == display_id; |
| 25 }); | 34 }); |
| 26 DCHECK(it != displays.end()); | 35 DCHECK(it != displays.end()); |
| 27 gfx::Rect bounds = it->bounds(); | 36 gfx::Rect bounds = it->bounds(); |
| 28 | 37 |
| 29 // Apply the |minimum_height|. | 38 // Apply the |minimum_height|. |
| 30 if (bounds.height() < minimum_height) | 39 if (bounds.height() < minimum_height) |
| 31 bounds.set_height(minimum_height); | 40 bounds.set_height(minimum_height); |
| 32 | 41 |
| 33 return bounds.CenterPoint(); | 42 return bounds.CenterPoint(); |
| 34 } | 43 } |
| 35 | 44 |
| 36 } // namespace | 45 } // namespace |
| 37 | 46 |
| 38 AppListPresenterDelegateMus::AppListPresenterDelegateMus( | 47 AppListPresenterDelegateMus::AppListPresenterDelegateMus( |
| 48 app_list::AppListPresenter* presenter, | |
| 39 app_list::AppListViewDelegateFactory* view_delegate_factory) | 49 app_list::AppListViewDelegateFactory* view_delegate_factory) |
| 40 : view_delegate_factory_(view_delegate_factory) {} | 50 : view_delegate_factory_(view_delegate_factory), |
| 51 presenter_(presenter){ | |
| 52 // ash::WmShell::Get()->AddShellObserver(this); | |
| 53 }; | |
| 41 | 54 |
| 42 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() {} | 55 AppListPresenterDelegateMus::~AppListPresenterDelegateMus() { |
| 56 // views::WindowManagerConnection::Get() | |
|
mfomitchev
2016/09/23 19:47:15
I think we do want this?
thanhph
2016/09/29 18:12:08
Yes..I'll add this back.
| |
| 57 // ->pointer_watcher_event_router() | |
| 58 // ->RemovePointerWatcher(this); | |
| 59 } | |
| 43 | 60 |
| 44 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { | 61 app_list::AppListViewDelegate* AppListPresenterDelegateMus::GetViewDelegate() { |
| 45 return view_delegate_factory_->GetDelegate(); | 62 return view_delegate_factory_->GetDelegate(); |
| 46 } | 63 } |
| 47 | 64 |
| 48 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, | 65 void AppListPresenterDelegateMus::Init(app_list::AppListView* view, |
| 49 int64_t display_id, | 66 int64_t display_id, |
| 50 int current_apps_page) { | 67 int current_apps_page) { |
| 68 LOG(ERROR) << "\n\n!!!!!. Initializing AppListPresenterDelegateMus\n\n\n"; | |
| 51 view_ = view; | 69 view_ = view; |
| 52 | 70 |
| 53 // Note: This would place the app list into the USER_WINDOWS container, unlike | 71 // Note: This would place the app list into the USER_WINDOWS container, unlike |
| 54 // in classic ash, where it has it's own container. | 72 // 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 | 73 // 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. | 74 // init at (0, 0) and then reset its anchor point. |
| 57 // TODO(mfomitchev): We are currently passing NULL for |parent|. It seems like | 75 // 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 | 76 // 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 | 77 // AppListMainView::PreloadIcons(), so we take care of that - perhaps by |
| 60 // passing the display_id or the scale factor directly | 78 // passing the display_id or the scale factor directly |
| 61 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, | 79 view->InitAsBubbleAtFixedLocation(nullptr /* parent */, current_apps_page, |
| 62 gfx::Point(), views::BubbleBorder::FLOAT, | 80 gfx::Point(), views::BubbleBorder::FLOAT, |
| 63 true /* border_accepts_events */); | 81 true /* border_accepts_events */); |
| 64 | 82 |
| 65 view->SetAnchorPoint( | 83 view->SetAnchorPoint( |
| 66 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); | 84 GetCenterOfDisplay(display_id, GetMinimumBoundsHeightForAppList(view))); |
| 67 | 85 |
| 86 views::WindowManagerConnection::Get() | |
| 87 ->pointer_watcher_event_router() | |
| 88 ->AddPointerWatcher(this, true); | |
|
mfomitchev
2016/09/23 19:47:15
Any reason we passing true for |wants_moves|? I th
thanhph
2016/09/29 18:12:08
That makes sense, will make the code faster by set
| |
| 89 | |
| 68 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. | 90 // TODO(mfomitchev): Setup updating bounds on keyboard bounds change. |
| 69 // TODO(mfomitchev): Setup dismissing on mouse/touch gesture anywhere outside | 91 // TODO(mfomitchev): Setup dismissing on mouse/touch gesture anywhere outside |
| 70 // the bounds of the app list. | 92 // the bounds of the app list. |
| 71 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. | 93 // TODO(mfomitchev): Setup dismissing on maximize (touch-view) mode start/end. |
| 72 // TODO(mfomitchev): Setup DnD. | 94 // TODO(mfomitchev): Setup DnD. |
| 73 // TODO(mfomitchev): UpdateAutoHideState for shelf | 95 // TODO(mfomitchev): UpdateAutoHideState for shelf |
| 74 } | 96 } |
| 75 | 97 |
| 76 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { | 98 void AppListPresenterDelegateMus::OnShown(int64_t display_id) { |
| 77 is_visible_ = true; | 99 is_visible_ = true; |
| 78 } | 100 } |
| 79 | 101 |
| 80 void AppListPresenterDelegateMus::OnDismissed() { | 102 void AppListPresenterDelegateMus::OnDismissed() { |
| 81 DCHECK(is_visible_); | 103 presenter_->Dismiss(); |
|
mfomitchev
2016/09/23 19:47:15
This will cause an infinite loop, since Dismiss()
thanhph
2016/09/29 18:12:08
my function is OnDismissed not OnDismiss so it'll
| |
| 82 is_visible_ = false; | |
| 83 } | 104 } |
| 84 | 105 |
| 85 void AppListPresenterDelegateMus::UpdateBounds() { | 106 void AppListPresenterDelegateMus::UpdateBounds() { |
| 86 if (!view_ || !is_visible_) | 107 if (!view_ || !is_visible_) |
| 108 | |
| 87 return; | 109 return; |
| 88 | 110 |
| 89 view_->UpdateBounds(); | 111 view_->UpdateBounds(); |
| 90 } | 112 } |
| 91 | 113 |
| 114 void AppListPresenterDelegateMus::OnPointerEventObserved( | |
| 115 const ui::PointerEvent& event, | |
| 116 const gfx::Point& location_in_screen, | |
| 117 views::Widget* target) { | |
| 118 LOG(ERROR) << "\n\n!!!!!. Closing ?\n\n\n"; | |
| 119 | |
| 120 if (event.type() == ui::ET_TOUCH_PRESSED || | |
| 121 event.type() == ui::ET_POINTER_DOWN) { | |
| 122 if (!target) { | |
| 123 // | |
| 124 LOG(ERROR) << "\n\n!!!!!. Closing OnPointerEventObserved\n\n\n"; | |
| 125 // view_->app_list_main_view_->close(); | |
| 126 // view_->CloseAppList(); | |
| 127 // target->Hide(); | |
| 128 this->OnDismissed(); | |
|
mfomitchev
2016/09/23 19:47:15
presenter_->Dismiss()
thanhph
2016/09/29 18:12:08
Thanks.. This is cleaner.
| |
| 129 // OnDismissed(); | |
| 130 // target->CloseNow(); | |
| 131 // target->GetTopLevelWidget()->CloseNow(); | |
| 132 } else { | |
| 133 LOG(ERROR) << "\n\n!!!!! target->GetWindowBoundsInScreen().ToString():" | |
| 134 << target->GetWindowBoundsInScreen().ToString() << "\n\n\n"; | |
| 135 | |
| 136 // LOG(ERROR) << "x:" << target->bounds.x() | |
| 137 // << "x:" << target->bounds.y() | |
| 138 // << "width:" << target->bounds.width() | |
| 139 // << "height:" << target->bounds.height() ; | |
| 140 } | |
| 141 } | |
| 142 } | |
| 143 | |
| 92 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( | 144 gfx::Vector2d AppListPresenterDelegateMus::GetVisibilityAnimationOffset( |
| 93 aura::Window* root_window) { | 145 aura::Window* root_window) { |
| 94 // TODO(mfomitchev): Classic ash does different animation here depending on | 146 // TODO(mfomitchev): Classic ash does different animation here depending on |
| 95 // shelf alignment. We should probably do that too. | 147 // shelf alignment. We should probably do that too. |
| 96 return gfx::Vector2d(0, kAnimationOffset); | 148 return gfx::Vector2d(0, kAnimationOffset); |
| 97 } | 149 } |
| OLD | NEW |