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

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc

Issue 11364196: Remove TabContents from TabStripModelObserver::ActiveTabChanged. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/launcher/browser_launcher_item_controller.h" 5 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h" 8 #include "ash/launcher/launcher_model.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status); 58 launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status);
59 } else { 59 } else {
60 launcher_controller()->CreateTabbedLauncherItem( 60 launcher_controller()->CreateTabbedLauncherItem(
61 this, 61 this,
62 is_incognito_ ? ChromeLauncherController::STATE_INCOGNITO : 62 is_incognito_ ? ChromeLauncherController::STATE_INCOGNITO :
63 ChromeLauncherController::STATE_NOT_INCOGNITO, 63 ChromeLauncherController::STATE_NOT_INCOGNITO,
64 app_status); 64 app_status);
65 } 65 }
66 // In testing scenarios we can get tab strips with no active contents. 66 // In testing scenarios we can get tab strips with no active contents.
67 if (tab_model_->GetActiveTabContents()) 67 if (tab_model_->GetActiveTabContents())
68 UpdateLauncher(tab_model_->GetActiveTabContents()); 68 UpdateLauncher(tab_model_->GetActiveWebContents());
69 } 69 }
70 70
71 // static 71 // static
72 BrowserLauncherItemController* BrowserLauncherItemController::Create( 72 BrowserLauncherItemController* BrowserLauncherItemController::Create(
73 Browser* browser) { 73 Browser* browser) {
74 // Under testing this can be called before the controller is created. 74 // Under testing this can be called before the controller is created.
75 if (!ChromeLauncherController::instance()) 75 if (!ChromeLauncherController::instance())
76 return NULL; 76 return NULL;
77 77
78 Type type; 78 Type type;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void BrowserLauncherItemController::LauncherItemChanged( 161 void BrowserLauncherItemController::LauncherItemChanged(
162 int index, 162 int index,
163 const ash::LauncherItem& old_item) { 163 const ash::LauncherItem& old_item) {
164 if (launcher_model()->items()[index].status == ash::STATUS_ACTIVE && 164 if (launcher_model()->items()[index].status == ash::STATUS_ACTIVE &&
165 old_item.status == ash::STATUS_RUNNING) { 165 old_item.status == ash::STATUS_RUNNING) {
166 Activate(); 166 Activate();
167 } 167 }
168 } 168 }
169 169
170 void BrowserLauncherItemController::ActiveTabChanged( 170 void BrowserLauncherItemController::ActiveTabChanged(
171 TabContents* old_contents, 171 content::WebContents* old_contents,
172 TabContents* new_contents, 172 content::WebContents* new_contents,
173 int index, 173 int index,
174 bool user_gesture) { 174 bool user_gesture) {
175 // Update immediately on a tab change. 175 // Update immediately on a tab change.
176 if (old_contents) 176 if (old_contents)
177 UpdateAppState(old_contents->web_contents()); 177 UpdateAppState(old_contents);
178 UpdateAppState(new_contents->web_contents()); 178 UpdateAppState(new_contents);
179 UpdateLauncher(new_contents); 179 UpdateLauncher(new_contents);
180 } 180 }
181 181
182 void BrowserLauncherItemController::TabInsertedAt( 182 void BrowserLauncherItemController::TabInsertedAt(
183 content::WebContents* contents, 183 content::WebContents* contents,
184 int index, 184 int index,
185 bool foreground) { 185 bool foreground) {
186 UpdateAppState(contents); 186 UpdateAppState(contents);
187 } 187 }
188 188
189 void BrowserLauncherItemController::TabDetachedAt( 189 void BrowserLauncherItemController::TabDetachedAt(
190 content::WebContents* contents, 190 content::WebContents* contents,
191 int index) { 191 int index) {
192 launcher_controller()->UpdateAppState( 192 launcher_controller()->UpdateAppState(
193 contents, ChromeLauncherController::APP_STATE_REMOVED); 193 contents, ChromeLauncherController::APP_STATE_REMOVED);
194 } 194 }
195 195
196 void BrowserLauncherItemController::TabChangedAt( 196 void BrowserLauncherItemController::TabChangedAt(
197 TabContents* tab, 197 TabContents* tab,
198 int index, 198 int index,
199 TabStripModelObserver::TabChangeType change_type) { 199 TabStripModelObserver::TabChangeType change_type) {
200 UpdateAppState(tab->web_contents()); 200 UpdateAppState(tab->web_contents());
201 if (index != tab_model_->active_index() || 201 if (index != tab_model_->active_index() ||
202 !(change_type != TabStripModelObserver::LOADING_ONLY && 202 !(change_type != TabStripModelObserver::LOADING_ONLY &&
203 change_type != TabStripModelObserver::TITLE_NOT_LOADING)) { 203 change_type != TabStripModelObserver::TITLE_NOT_LOADING)) {
204 return; 204 return;
205 } 205 }
206 206
207 UpdateLauncher(tab); 207 UpdateLauncher(tab->web_contents());
208 } 208 }
209 209
210 void BrowserLauncherItemController::TabReplacedAt( 210 void BrowserLauncherItemController::TabReplacedAt(
211 TabStripModel* tab_strip_model, 211 TabStripModel* tab_strip_model,
212 TabContents* old_contents, 212 TabContents* old_contents,
213 TabContents* new_contents, 213 TabContents* new_contents,
214 int index) { 214 int index) {
215 launcher_controller()->UpdateAppState( 215 launcher_controller()->UpdateAppState(
216 old_contents->web_contents(), 216 old_contents->web_contents(),
217 ChromeLauncherController::APP_STATE_REMOVED); 217 ChromeLauncherController::APP_STATE_REMOVED);
218 UpdateAppState(new_contents->web_contents()); 218 UpdateAppState(new_contents->web_contents());
219 } 219 }
220 220
221 void BrowserLauncherItemController::FaviconUpdated() { 221 void BrowserLauncherItemController::FaviconUpdated() {
222 UpdateLauncher(tab_model_->GetActiveTabContents()); 222 UpdateLauncher(tab_model_->GetActiveWebContents());
223 } 223 }
224 224
225 void BrowserLauncherItemController::OnWindowPropertyChanged( 225 void BrowserLauncherItemController::OnWindowPropertyChanged(
226 aura::Window* window, 226 aura::Window* window,
227 const void* key, 227 const void* key,
228 intptr_t old) { 228 intptr_t old) {
229 if (key == aura::client::kDrawAttentionKey) 229 if (key == aura::client::kDrawAttentionKey)
230 UpdateItemStatus(); 230 UpdateItemStatus();
231 } 231 }
232 232
233 void BrowserLauncherItemController::UpdateItemStatus() { 233 void BrowserLauncherItemController::UpdateItemStatus() {
234 ash::LauncherItemStatus status; 234 ash::LauncherItemStatus status;
235 if (ash::wm::IsActiveWindow(window_)) { 235 if (ash::wm::IsActiveWindow(window_)) {
236 // Clear attention state if active. 236 // Clear attention state if active.
237 if (window_->GetProperty(aura::client::kDrawAttentionKey)) 237 if (window_->GetProperty(aura::client::kDrawAttentionKey))
238 window_->SetProperty(aura::client::kDrawAttentionKey, false); 238 window_->SetProperty(aura::client::kDrawAttentionKey, false);
239 status = ash::STATUS_ACTIVE; 239 status = ash::STATUS_ACTIVE;
240 } else if (window_->GetProperty(aura::client::kDrawAttentionKey)) { 240 } else if (window_->GetProperty(aura::client::kDrawAttentionKey)) {
241 status = ash::STATUS_ATTENTION; 241 status = ash::STATUS_ATTENTION;
242 } else { 242 } else {
243 status = ash::STATUS_RUNNING; 243 status = ash::STATUS_RUNNING;
244 } 244 }
245 launcher_controller()->SetItemStatus(launcher_id(), status); 245 launcher_controller()->SetItemStatus(launcher_id(), status);
246 } 246 }
247 247
248 void BrowserLauncherItemController::UpdateLauncher(TabContents* tab) { 248 void BrowserLauncherItemController::UpdateLauncher(content::WebContents* tab) {
249 if (type() == TYPE_APP_PANEL) 249 if (type() == TYPE_APP_PANEL)
250 return; // Maintained entirely by ChromeLauncherController. 250 return; // Maintained entirely by ChromeLauncherController.
251 251
252 if (!tab) 252 if (!tab)
253 return; // Assume the window is going to be closed if there are no tabs. 253 return; // Assume the window is going to be closed if there are no tabs.
254 254
255 int item_index = launcher_model()->ItemIndexByID(launcher_id()); 255 int item_index = launcher_model()->ItemIndexByID(launcher_id());
256 if (item_index == -1) 256 if (item_index == -1)
257 return; 257 return;
258 258
259 ash::LauncherItem item = launcher_model()->items()[item_index]; 259 ash::LauncherItem item = launcher_model()->items()[item_index];
260 if (type() == TYPE_EXTENSION_PANEL) { 260 if (type() == TYPE_EXTENSION_PANEL) {
261 if (!favicon_loader_.get() || 261 if (!favicon_loader_.get() || favicon_loader_->web_contents() != tab)
262 favicon_loader_->web_contents() != tab->web_contents()) { 262 favicon_loader_.reset(new LauncherFaviconLoader(this, tab));
263 favicon_loader_.reset( 263
264 new LauncherFaviconLoader(this, tab->web_contents()));
265 }
266 // Update the icon for extension panels. 264 // Update the icon for extension panels.
267 extensions::TabHelper* extensions_tab_helper = 265 extensions::TabHelper* extensions_tab_helper =
268 extensions::TabHelper::FromWebContents(tab->web_contents()); 266 extensions::TabHelper::FromWebContents(tab);
269 gfx::ImageSkia new_image = gfx::ImageSkia(favicon_loader_->GetFavicon()); 267 gfx::ImageSkia new_image = gfx::ImageSkia(favicon_loader_->GetFavicon());
270 if (new_image.isNull() && extensions_tab_helper->GetExtensionAppIcon()) 268 if (new_image.isNull() && extensions_tab_helper->GetExtensionAppIcon())
271 new_image = gfx::ImageSkia(*extensions_tab_helper->GetExtensionAppIcon()); 269 new_image = gfx::ImageSkia(*extensions_tab_helper->GetExtensionAppIcon());
272 // Only update the icon if we have a new image, or none has been set yet. 270 // Only update the icon if we have a new image, or none has been set yet.
273 // This avoids flickering to an empty image when a pinned app is opened. 271 // This avoids flickering to an empty image when a pinned app is opened.
274 if (!new_image.isNull()) 272 if (!new_image.isNull())
275 item.image = new_image; 273 item.image = new_image;
276 else if (item.image.isNull()) 274 else if (item.image.isNull())
277 item.image = extensions::Extension::GetDefaultIcon(true); 275 item.image = extensions::Extension::GetDefaultIcon(true);
278 } else { 276 } else {
279 DCHECK_EQ(TYPE_TABBED, type()); 277 DCHECK_EQ(TYPE_TABBED, type());
280 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 278 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
281 FaviconTabHelper* favicon_tab_helper = 279 FaviconTabHelper* favicon_tab_helper =
282 FaviconTabHelper::FromWebContents(tab->web_contents()); 280 FaviconTabHelper::FromWebContents(tab);
283 if (favicon_tab_helper->ShouldDisplayFavicon()) { 281 if (favicon_tab_helper->ShouldDisplayFavicon()) {
284 item.image = favicon_tab_helper->GetFavicon().AsImageSkia(); 282 item.image = favicon_tab_helper->GetFavicon().AsImageSkia();
285 if (item.image.isNull()) { 283 if (item.image.isNull()) {
286 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 284 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
287 } 285 }
288 } else { 286 } else {
289 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 287 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
290 } 288 }
291 } 289 }
292 launcher_model()->Set(item_index, item); 290 launcher_model()->Set(item_index, item);
(...skipping 11 matching lines...) Expand all
304 app_state = ChromeLauncherController::APP_STATE_ACTIVE; 302 app_state = ChromeLauncherController::APP_STATE_ACTIVE;
305 } else { 303 } else {
306 app_state = ChromeLauncherController::APP_STATE_INACTIVE; 304 app_state = ChromeLauncherController::APP_STATE_INACTIVE;
307 } 305 }
308 launcher_controller()->UpdateAppState(tab, app_state); 306 launcher_controller()->UpdateAppState(tab, app_state);
309 } 307 }
310 308
311 ash::LauncherModel* BrowserLauncherItemController::launcher_model() { 309 ash::LauncherModel* BrowserLauncherItemController::launcher_model() {
312 return launcher_controller()->model(); 310 return launcher_controller()->model();
313 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698