| 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 "ui/app_list/presenter/app_list_presenter_impl.h" | 5 #include "ui/app_list/presenter/app_list_presenter_impl.h" |
| 6 | 6 |
| 7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
| 8 #include "ui/app_list/app_list_switches.h" | 8 #include "ui/app_list/app_list_switches.h" |
| 9 #include "ui/app_list/pagination_model.h" | 9 #include "ui/app_list/pagination_model.h" |
| 10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" | 10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
| 11 #include "ui/app_list/views/app_list_view.h" | 11 #include "ui/app_list/views/app_list_view.h" |
| 12 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/display/screen.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 | 18 |
| 18 namespace app_list { | 19 namespace app_list { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Duration for show/hide animation in milliseconds. | 22 // Duration for show/hide animation in milliseconds. |
| 22 const int kAnimationDurationMs = 200; | 23 const int kAnimationDurationMs = 200; |
| 23 | 24 |
| 24 // The maximum shift in pixels when over-scroll happens. | 25 // The maximum shift in pixels when over-scroll happens. |
| 25 const int kMaxOverScrollShift = 48; | 26 const int kMaxOverScrollShift = 48; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 114 |
| 114 bool AppListPresenterImpl::GetTargetVisibility() const { | 115 bool AppListPresenterImpl::GetTargetVisibility() const { |
| 115 return is_visible_; | 116 return is_visible_; |
| 116 } | 117 } |
| 117 | 118 |
| 118 void AppListPresenterImpl::SetAppList(mojom::AppListPtr app_list) { | 119 void AppListPresenterImpl::SetAppList(mojom::AppListPtr app_list) { |
| 119 DCHECK(app_list); | 120 DCHECK(app_list); |
| 120 app_list_ = std::move(app_list); | 121 app_list_ = std::move(app_list); |
| 121 // Notify the app list interface of the current [target] visibility. | 122 // Notify the app list interface of the current [target] visibility. |
| 122 app_list_->OnTargetVisibilityChanged(GetTargetVisibility()); | 123 app_list_->OnTargetVisibilityChanged(GetTargetVisibility()); |
| 123 app_list_->OnVisibilityChanged(IsVisible()); | 124 app_list_->OnVisibilityChanged(IsVisible(), GetDisplayId()); |
| 124 } | 125 } |
| 125 | 126 |
| 126 //////////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////////// |
| 127 // AppListPresenterImpl, private: | 128 // AppListPresenterImpl, private: |
| 128 | 129 |
| 129 void AppListPresenterImpl::SetView(AppListView* view) { | 130 void AppListPresenterImpl::SetView(AppListView* view) { |
| 130 DCHECK(view_ == nullptr); | 131 DCHECK(view_ == nullptr); |
| 131 DCHECK(is_visible_); | 132 DCHECK(is_visible_); |
| 132 | 133 |
| 133 view_ = view; | 134 view_ = view; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | 180 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
| 180 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 181 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 181 is_visible_ ? 0 : kAnimationDurationMs)); | 182 is_visible_ ? 0 : kAnimationDurationMs)); |
| 182 animation.AddObserver(this); | 183 animation.AddObserver(this); |
| 183 | 184 |
| 184 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 185 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
| 185 widget->SetBounds(target_bounds); | 186 widget->SetBounds(target_bounds); |
| 186 } | 187 } |
| 187 | 188 |
| 189 int64_t AppListPresenterImpl::GetDisplayId() { |
| 190 views::Widget* widget = view_ ? view_->GetWidget() : nullptr; |
| 191 if (!widget) |
| 192 return display::kInvalidDisplayId; |
| 193 return display::Screen::GetScreen() |
| 194 ->GetDisplayNearestWindow(widget->GetNativeView()) |
| 195 .id(); |
| 196 } |
| 197 |
| 188 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
| 189 // AppListPresenterImpl, aura::client::FocusChangeObserver implementation: | 199 // AppListPresenterImpl, aura::client::FocusChangeObserver implementation: |
| 190 | 200 |
| 191 void AppListPresenterImpl::OnWindowFocused(aura::Window* gained_focus, | 201 void AppListPresenterImpl::OnWindowFocused(aura::Window* gained_focus, |
| 192 aura::Window* lost_focus) { | 202 aura::Window* lost_focus) { |
| 193 if (view_ && is_visible_) { | 203 if (view_ && is_visible_) { |
| 194 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); | 204 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); |
| 195 aura::Window* applist_container = applist_window->parent(); | 205 aura::Window* applist_container = applist_window->parent(); |
| 196 if (applist_container->Contains(lost_focus) && | 206 if (applist_container->Contains(lost_focus) && |
| 197 (!gained_focus || !applist_container->Contains(gained_focus)) && | 207 (!gained_focus || !applist_container->Contains(gained_focus)) && |
| (...skipping 29 matching lines...) Expand all Loading... |
| 227 DCHECK_EQ(view_->GetWidget(), widget); | 237 DCHECK_EQ(view_->GetWidget(), widget); |
| 228 if (is_visible_) | 238 if (is_visible_) |
| 229 Dismiss(); | 239 Dismiss(); |
| 230 ResetView(); | 240 ResetView(); |
| 231 } | 241 } |
| 232 | 242 |
| 233 void AppListPresenterImpl::OnWidgetVisibilityChanged(views::Widget* widget, | 243 void AppListPresenterImpl::OnWidgetVisibilityChanged(views::Widget* widget, |
| 234 bool visible) { | 244 bool visible) { |
| 235 DCHECK_EQ(view_->GetWidget(), widget); | 245 DCHECK_EQ(view_->GetWidget(), widget); |
| 236 if (app_list_) | 246 if (app_list_) |
| 237 app_list_->OnVisibilityChanged(visible); | 247 app_list_->OnVisibilityChanged(visible, GetDisplayId()); |
| 238 } | 248 } |
| 239 | 249 |
| 240 //////////////////////////////////////////////////////////////////////////////// | 250 //////////////////////////////////////////////////////////////////////////////// |
| 241 // AppListPresenterImpl, PaginationModelObserver implementation: | 251 // AppListPresenterImpl, PaginationModelObserver implementation: |
| 242 | 252 |
| 243 void AppListPresenterImpl::TotalPagesChanged() {} | 253 void AppListPresenterImpl::TotalPagesChanged() {} |
| 244 | 254 |
| 245 void AppListPresenterImpl::SelectedPageChanged(int old_selected, | 255 void AppListPresenterImpl::SelectedPageChanged(int old_selected, |
| 246 int new_selected) { | 256 int new_selected) { |
| 247 current_apps_page_ = new_selected; | 257 current_apps_page_ = new_selected; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } else if (should_snap_back_) { | 295 } else if (should_snap_back_) { |
| 286 should_snap_back_ = false; | 296 should_snap_back_ = false; |
| 287 ui::ScopedLayerAnimationSettings animation(widget_animator); | 297 ui::ScopedLayerAnimationSettings animation(widget_animator); |
| 288 animation.SetTransitionDuration( | 298 animation.SetTransitionDuration( |
| 289 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); | 299 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); |
| 290 widget->SetBounds(view_bounds_); | 300 widget->SetBounds(view_bounds_); |
| 291 } | 301 } |
| 292 } | 302 } |
| 293 | 303 |
| 294 } // namespace app_list | 304 } // namespace app_list |
| OLD | NEW |