Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_shower_views.cc |
| diff --git a/chrome/browser/ui/app_list/app_list_shower.cc b/chrome/browser/ui/app_list/app_list_shower_views.cc |
| similarity index 53% |
| rename from chrome/browser/ui/app_list/app_list_shower.cc |
| rename to chrome/browser/ui/app_list/app_list_shower_views.cc |
| index 6c6c0bbc751d2212eb0c8be845fa89cebb34b0dd..67f5a0e3358dc3c76f57b163c6eb0d08097a411a 100644 |
| --- a/chrome/browser/ui/app_list/app_list_shower.cc |
| +++ b/chrome/browser/ui/app_list/app_list_shower_views.cc |
| @@ -2,17 +2,23 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "chrome/browser/ui/app_list/app_list_shower_views.h" |
| + |
| #include "base/bind.h" |
| #include "base/message_loop/message_loop.h" |
| -#include "chrome/browser/ui/app_list/app_list_shower.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/app_list_shower_delegate.h" |
| +#include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| #include "chrome/browser/ui/app_list/scoped_keep_alive.h" |
| +#include "ui/app_list/views/app_list_view.h" |
| +#include "ui/gfx/geometry/point.h" |
| +#include "ui/gfx/screen.h" |
| -AppListShower::AppListShower(scoped_ptr<AppListFactory> factory, |
| - AppListService* service) |
| - : factory_(factory.Pass()), |
| - service_(service), |
| +AppListShower::AppListShower(AppListShowerDelegate* delegate) |
| + : delegate_(delegate), |
| profile_(NULL), |
| - can_close_app_list_(true) { |
| + app_list_(NULL), |
| + window_icon_updated_(false) { |
| } |
| AppListShower::~AppListShower() { |
| @@ -22,48 +28,46 @@ void AppListShower::ShowForProfile(Profile* requested_profile) { |
| // If the app list is already displaying |profile| just activate it (in case |
| // we have lost focus). |
| if (IsAppListVisible() && (requested_profile == profile_)) { |
| - app_list_->Show(); |
| + Show(); |
| return; |
| } |
| - if (!app_list_) { |
| + if (!HasView()) { |
| CreateViewForProfile(requested_profile); |
| } else if (requested_profile != profile_) { |
| profile_ = requested_profile; |
| - app_list_->SetProfile(requested_profile); |
| + UpdateViewForNewProfile(); |
| } |
| keep_alive_.reset(new ScopedKeepAlive); |
| if (!IsAppListVisible()) |
| - app_list_->MoveNearCursor(); |
| - app_list_->Show(); |
| + delegate_->MoveNearCursor(app_list_); |
| + Show(); |
| } |
| gfx::NativeWindow AppListShower::GetWindow() { |
| if (!IsAppListVisible()) |
| return NULL; |
| - return app_list_->GetWindow(); |
| + return app_list_->GetWidget()->GetNativeWindow(); |
| } |
| void AppListShower::CreateViewForProfile(Profile* requested_profile) { |
| profile_ = requested_profile; |
| - app_list_.reset(factory_->CreateAppList( |
| - profile_, |
| - service_, |
| - base::Bind(&AppListShower::DismissAppList, base::Unretained(this)))); |
| + app_list_ = MakeViewForCurrentProfile(); |
| + delegate_->OnViewCreated(); |
| } |
| void AppListShower::DismissAppList() { |
| - if (app_list_ && can_close_app_list_) { |
| - app_list_->Hide(); |
| + if (HasView()) { |
| + Hide(); |
| + delegate_->OnViewHidden(); |
| keep_alive_.reset(); |
| } |
| } |
| void AppListShower::HandleViewBeingDestroyed() { |
| - app_list_.reset(); |
| + app_list_ = NULL; |
| profile_ = NULL; |
| - can_close_app_list_ = true; |
| // We may end up here as the result of the OS deleting the AppList's |
| // widget (WidgetObserver::OnWidgetDestroyed). If this happens and there |
| @@ -84,7 +88,7 @@ void AppListShower::HandleViewBeingDestroyed() { |
| } |
| bool AppListShower::IsAppListVisible() const { |
| - return app_list_ && app_list_->IsVisible(); |
| + return app_list_ && app_list_->GetWidget()->IsVisible(); |
| } |
| void AppListShower::WarmupForProfile(Profile* profile) { |
| @@ -97,6 +101,38 @@ bool AppListShower::HasView() const { |
| return !!app_list_; |
| } |
| +app_list::AppListView* AppListShower::MakeViewForCurrentProfile() { |
| + // The view delegate will be owned by the app list view. The app list view |
| + // manages it's own lifetime. |
|
tapted
2014/04/29 04:20:30
its
Matt Giuca
2014/04/30 00:41:23
Oops, I wonder if that's my fault :|
tapted
2014/04/30 03:26:03
Done (I blame English - its its fault :p)
|
| + AppListViewDelegate* view_delegate = new AppListViewDelegate( |
| + profile_, delegate_->GetControllerDelegateForCreate()); |
| + app_list::AppListView* view = new app_list::AppListView(view_delegate); |
| + gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(); |
| + view->InitAsBubbleAtFixedLocation(NULL, |
| + &pagination_model_, |
| + cursor, |
| + views::BubbleBorder::FLOAT, |
| + false /* border_accepts_events */); |
| + return view; |
| +} |
| + |
| +void AppListShower::UpdateViewForNewProfile() { |
| + app_list_->SetProfileByPath(profile_->GetPath()); |
| +} |
| + |
| +void AppListShower::Show() { |
| + app_list_->GetWidget()->Show(); |
| + if (!window_icon_updated_) { |
| + app_list_->GetWidget()->GetTopLevelWidget()->UpdateWindowIcon(); |
| + window_icon_updated_ = true; |
| + } |
| + app_list_->GetWidget()->Activate(); |
| +} |
| + |
| +void AppListShower::Hide() { |
| + app_list_->GetWidget()->Hide(); |
| +} |
| + |
| void AppListShower::ResetKeepAlive() { |
| keep_alive_.reset(); |
| } |