Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/ui/app_list/app_list_shower_views.cc

Issue 225053004: Refactor views app list services to allow more code sharing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: oops - fix some names Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_list/app_list_shower_views.h"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/ui/app_list/app_list_shower.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/app_list/app_list_shower_delegate.h"
11 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
8 #include "chrome/browser/ui/app_list/scoped_keep_alive.h" 12 #include "chrome/browser/ui/app_list/scoped_keep_alive.h"
13 #include "ui/app_list/views/app_list_view.h"
14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/screen.h"
9 16
10 AppListShower::AppListShower(scoped_ptr<AppListFactory> factory, 17 AppListShower::AppListShower(AppListShowerDelegate* delegate)
11 AppListService* service) 18 : delegate_(delegate),
12 : factory_(factory.Pass()),
13 service_(service),
14 profile_(NULL), 19 profile_(NULL),
15 can_close_app_list_(true) { 20 app_list_(NULL),
21 window_icon_updated_(false) {
16 } 22 }
17 23
18 AppListShower::~AppListShower() { 24 AppListShower::~AppListShower() {
19 } 25 }
20 26
21 void AppListShower::ShowForProfile(Profile* requested_profile) { 27 void AppListShower::ShowForProfile(Profile* requested_profile) {
22 // If the app list is already displaying |profile| just activate it (in case 28 // If the app list is already displaying |profile| just activate it (in case
23 // we have lost focus). 29 // we have lost focus).
24 if (IsAppListVisible() && (requested_profile == profile_)) { 30 if (IsAppListVisible() && (requested_profile == profile_)) {
25 app_list_->Show(); 31 Show();
26 return; 32 return;
27 } 33 }
28 34
29 if (!app_list_) { 35 if (!HasView()) {
30 CreateViewForProfile(requested_profile); 36 CreateViewForProfile(requested_profile);
31 } else if (requested_profile != profile_) { 37 } else if (requested_profile != profile_) {
32 profile_ = requested_profile; 38 profile_ = requested_profile;
33 app_list_->SetProfile(requested_profile); 39 UpdateViewForNewProfile();
34 } 40 }
35 41
36 keep_alive_.reset(new ScopedKeepAlive); 42 keep_alive_.reset(new ScopedKeepAlive);
37 if (!IsAppListVisible()) 43 if (!IsAppListVisible())
38 app_list_->MoveNearCursor(); 44 delegate_->MoveNearCursor(app_list_);
39 app_list_->Show(); 45 Show();
40 } 46 }
41 47
42 gfx::NativeWindow AppListShower::GetWindow() { 48 gfx::NativeWindow AppListShower::GetWindow() {
43 if (!IsAppListVisible()) 49 if (!IsAppListVisible())
44 return NULL; 50 return NULL;
45 return app_list_->GetWindow(); 51 return app_list_->GetWidget()->GetNativeWindow();
46 } 52 }
47 53
48 void AppListShower::CreateViewForProfile(Profile* requested_profile) { 54 void AppListShower::CreateViewForProfile(Profile* requested_profile) {
49 profile_ = requested_profile; 55 profile_ = requested_profile;
50 app_list_.reset(factory_->CreateAppList( 56 app_list_ = MakeViewForCurrentProfile();
51 profile_, 57 delegate_->OnViewCreated();
52 service_,
53 base::Bind(&AppListShower::DismissAppList, base::Unretained(this))));
54 } 58 }
55 59
56 void AppListShower::DismissAppList() { 60 void AppListShower::DismissAppList() {
57 if (app_list_ && can_close_app_list_) { 61 if (HasView()) {
58 app_list_->Hide(); 62 Hide();
63 delegate_->OnViewHidden();
59 keep_alive_.reset(); 64 keep_alive_.reset();
60 } 65 }
61 } 66 }
62 67
63 void AppListShower::HandleViewBeingDestroyed() { 68 void AppListShower::HandleViewBeingDestroyed() {
64 app_list_.reset(); 69 app_list_ = NULL;
65 profile_ = NULL; 70 profile_ = NULL;
66 can_close_app_list_ = true;
67 71
68 // We may end up here as the result of the OS deleting the AppList's 72 // We may end up here as the result of the OS deleting the AppList's
69 // widget (WidgetObserver::OnWidgetDestroyed). If this happens and there 73 // widget (WidgetObserver::OnWidgetDestroyed). If this happens and there
70 // are no browsers around then deleting the keep alive will result in 74 // are no browsers around then deleting the keep alive will result in
71 // deleting the Widget again (by way of CloseAllSecondaryWidgets). When 75 // deleting the Widget again (by way of CloseAllSecondaryWidgets). When
72 // the stack unravels we end up back in the Widget that was deleted and 76 // the stack unravels we end up back in the Widget that was deleted and
73 // crash. By delaying deletion of the keep alive we ensure the Widget has 77 // crash. By delaying deletion of the keep alive we ensure the Widget has
74 // correctly been destroyed before ending the keep alive so that 78 // correctly been destroyed before ending the keep alive so that
75 // CloseAllSecondaryWidgets() won't attempt to delete the AppList's Widget 79 // CloseAllSecondaryWidgets() won't attempt to delete the AppList's Widget
76 // again. 80 // again.
77 if (base::MessageLoop::current()) { // NULL in tests. 81 if (base::MessageLoop::current()) { // NULL in tests.
78 base::MessageLoop::current()->PostTask( 82 base::MessageLoop::current()->PostTask(
79 FROM_HERE, 83 FROM_HERE,
80 base::Bind(&AppListShower::ResetKeepAlive, base::Unretained(this))); 84 base::Bind(&AppListShower::ResetKeepAlive, base::Unretained(this)));
81 return; 85 return;
82 } 86 }
83 keep_alive_.reset(); 87 keep_alive_.reset();
84 } 88 }
85 89
86 bool AppListShower::IsAppListVisible() const { 90 bool AppListShower::IsAppListVisible() const {
87 return app_list_ && app_list_->IsVisible(); 91 return app_list_ && app_list_->GetWidget()->IsVisible();
88 } 92 }
89 93
90 void AppListShower::WarmupForProfile(Profile* profile) { 94 void AppListShower::WarmupForProfile(Profile* profile) {
91 DCHECK(!profile_); 95 DCHECK(!profile_);
92 CreateViewForProfile(profile); 96 CreateViewForProfile(profile);
93 app_list_->Prerender(); 97 app_list_->Prerender();
94 } 98 }
95 99
96 bool AppListShower::HasView() const { 100 bool AppListShower::HasView() const {
97 return !!app_list_; 101 return !!app_list_;
98 } 102 }
99 103
104 app_list::AppListView* AppListShower::MakeViewForCurrentProfile() {
105 // The view delegate will be owned by the app list view. The app list view
106 // 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)
107 AppListViewDelegate* view_delegate = new AppListViewDelegate(
108 profile_, delegate_->GetControllerDelegateForCreate());
109 app_list::AppListView* view = new app_list::AppListView(view_delegate);
110 gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
111 view->InitAsBubbleAtFixedLocation(NULL,
112 &pagination_model_,
113 cursor,
114 views::BubbleBorder::FLOAT,
115 false /* border_accepts_events */);
116 return view;
117 }
118
119 void AppListShower::UpdateViewForNewProfile() {
120 app_list_->SetProfileByPath(profile_->GetPath());
121 }
122
123 void AppListShower::Show() {
124 app_list_->GetWidget()->Show();
125 if (!window_icon_updated_) {
126 app_list_->GetWidget()->GetTopLevelWidget()->UpdateWindowIcon();
127 window_icon_updated_ = true;
128 }
129 app_list_->GetWidget()->Activate();
130 }
131
132 void AppListShower::Hide() {
133 app_list_->GetWidget()->Hide();
134 }
135
100 void AppListShower::ResetKeepAlive() { 136 void AppListShower::ResetKeepAlive() {
101 keep_alive_.reset(); 137 keep_alive_.reset();
102 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698