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

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

Issue 9702072: Second try for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | 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/views/ash/launcher/launcher_updater.h" 5 #include "chrome/browser/ui/views/ash/launcher/launcher_updater.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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (type_ == TYPE_PANEL) { 56 if (type_ == TYPE_PANEL) {
57 favicon_loader_.reset( 57 favicon_loader_.reset(
58 new LauncherFaviconLoader( 58 new LauncherFaviconLoader(
59 this, tab_model_->GetActiveTabContents()->web_contents())); 59 this, tab_model_->GetActiveTabContents()->web_contents()));
60 } 60 }
61 if (type_ == TYPE_APP || type_ == TYPE_PANEL) { 61 if (type_ == TYPE_APP || type_ == TYPE_PANEL) {
62 // App type never changes, create the launcher item immediately. 62 // App type never changes, create the launcher item immediately.
63 ChromeLauncherDelegate::AppType app_type = 63 ChromeLauncherDelegate::AppType app_type =
64 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL 64 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL
65 : ChromeLauncherDelegate::APP_TYPE_WINDOW; 65 : ChromeLauncherDelegate::APP_TYPE_WINDOW;
66 ash::LauncherItemStatus app_status =
67 ash::wm::IsActiveWindow(window_) ?
68 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
66 item_id_ = launcher_delegate_->CreateAppLauncherItem( 69 item_id_ = launcher_delegate_->CreateAppLauncherItem(
67 this, app_id_, app_type, ash::STATUS_RUNNING); 70 this, app_id_, app_type, app_status);
68 } else { 71 } else {
69 // Determine if we have any tabs that should get launcher items. 72 // Determine if we have any tabs that should get launcher items.
70 std::vector<TabContentsWrapper*> app_tabs; 73 std::vector<TabContentsWrapper*> app_tabs;
71 for (int i = 0; i < tab_model_->count(); ++i) { 74 for (int i = 0; i < tab_model_->count(); ++i) {
72 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); 75 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i);
73 if (!launcher_delegate_->GetAppID(tab).empty()) 76 if (!launcher_delegate_->GetAppID(tab).empty())
74 app_tabs.push_back(tab); 77 app_tabs.push_back(tab);
75 } 78 }
76 79
77 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) 80 if (static_cast<int>(app_tabs.size()) != tab_model_->count())
78 CreateTabbedItem(); 81 CreateTabbedItem();
79 82
80 // Create items for the app tabs. 83 // Create items for the app tabs.
81 for (size_t i = 0; i < app_tabs.size(); ++i) 84 for (size_t i = 0; i < app_tabs.size(); ++i)
82 AddAppItem(app_tabs[i]); 85 AddAppItem(app_tabs[i]);
83 } 86 }
84 UpdateLauncher(tab_model_->GetActiveTabContents()); 87 // In testing scenarios we can get tab strips with no active contents.
88 if (tab_model_->GetActiveTabContents())
89 UpdateLauncher(tab_model_->GetActiveTabContents());
85 } 90 }
86 91
87 // static 92 // static
88 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { 93 LauncherUpdater* LauncherUpdater::Create(Browser* browser) {
89 Type type; 94 Type type;
90 std::string app_id; 95 std::string app_id;
91 if (browser->type() == Browser::TYPE_TABBED) { 96 if (browser->type() == Browser::TYPE_TABBED) {
92 type = TYPE_TABBED; 97 type = TYPE_TABBED;
93 } else if (browser->is_app()) { 98 } else if (browser->is_app()) {
94 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP; 99 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP;
(...skipping 10 matching lines...) Expand all
105 110
106 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) { 111 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) {
107 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 112 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
108 ++i) { 113 ++i) {
109 if (i->second.id == id) 114 if (i->second.id == id)
110 return i->first; 115 return i->first;
111 } 116 }
112 return NULL; 117 return NULL;
113 } 118 }
114 119
120 void LauncherUpdater::BrowserActivationStateChanged() {
121 // This can happen in tests.
122 if (type_ == TYPE_TABBED && tab_model_->GetActiveTabContents() == NULL)
123 return;
124
125 launcher_delegate_->SetItemStatus(
126 GetLauncherID(tab_model_->GetActiveTabContents()),
127 ash::wm::IsActiveWindow(window_) ?
128 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
129 }
130
115 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, 131 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents,
116 TabContentsWrapper* new_contents, 132 TabContentsWrapper* new_contents,
117 int index, 133 int index,
118 bool user_gesture) { 134 bool user_gesture) {
135 if (ash::wm::IsActiveWindow(window_)) {
136 ash::LauncherID old_id = GetLauncherID(old_contents);
137 ash::LauncherID new_id = GetLauncherID(new_contents);
138
139 // The new_contents state will be handled in UpdateLauncher().
140 if (old_id != new_id && old_id >= 0)
141 launcher_delegate_->SetItemStatus(old_id, ash::STATUS_RUNNING);
142 }
119 // Update immediately on a tab change. 143 // Update immediately on a tab change.
120 UpdateLauncher(new_contents); 144 UpdateLauncher(new_contents);
121 } 145 }
122 146
123 void LauncherUpdater::TabChangedAt( 147 void LauncherUpdater::TabChangedAt(
124 TabContentsWrapper* tab, 148 TabContentsWrapper* tab,
125 int index, 149 int index,
126 TabStripModelObserver::TabChangeType change_type) { 150 TabStripModelObserver::TabChangeType change_type) {
127 if (type_ == TYPE_TABBED && 151 if (type_ == TYPE_TABBED &&
128 (change_type == TabStripModelObserver::LOADING_ONLY || 152 (change_type == TabStripModelObserver::LOADING_ONLY ||
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 launcher_model()->Set(item_index, new_item); 222 launcher_model()->Set(item_index, new_item);
199 } 223 }
200 } 224 }
201 } 225 }
202 226
203 void LauncherUpdater::FaviconUpdated() { 227 void LauncherUpdater::FaviconUpdated() {
204 UpdateLauncher(tab_model_->GetActiveTabContents()); 228 UpdateLauncher(tab_model_->GetActiveTabContents());
205 } 229 }
206 230
207 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 231 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
232 if (!tab)
233 return; // Assume the window is going to be closed if there are no tabs.
234
235 launcher_delegate_->SetItemStatus(GetLauncherID(tab), GetStatusForTab(tab));
236
208 if (type_ == TYPE_APP) 237 if (type_ == TYPE_APP)
209 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. 238 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
210 239
211 if (!tab)
212 return; // Assume the window is going to be closed if there are no tabs.
213
214 int item_index = launcher_model()->ItemIndexByID(item_id_); 240 int item_index = launcher_model()->ItemIndexByID(item_id_);
215 if (item_index == -1) 241 if (item_index == -1)
216 return; 242 return;
217 243
218 ash::LauncherItem item = launcher_model()->items()[item_index]; 244 ash::LauncherItem item = launcher_model()->items()[item_index];
219 if (type_ == TYPE_PANEL) { 245 if (type_ == TYPE_PANEL) {
220 // Update the icon for app panels. 246 // Update the icon for app panels.
221 item.image = favicon_loader_->GetFavicon(); 247 item.image = favicon_loader_->GetFavicon();
222 if (item.image.empty()) { 248 if (item.image.empty()) {
223 if (tab->extension_tab_helper()->GetExtensionAppIcon()) 249 if (tab->extension_tab_helper()->GetExtensionAppIcon())
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // app item, which will end up using the closed item. 337 // app item, which will end up using the closed item.
312 launcher_delegate_->LauncherItemClosed(item_id_); 338 launcher_delegate_->LauncherItemClosed(item_id_);
313 AddAppItem(tab); 339 AddAppItem(tab);
314 } else { 340 } else {
315 // All the tabs are app tabs, replace the tabbed item with the app. 341 // All the tabs are app tabs, replace the tabbed item with the app.
316 launcher_delegate_->ConvertTabbedToApp( 342 launcher_delegate_->ConvertTabbedToApp(
317 item_id_, 343 item_id_,
318 launcher_delegate_->GetAppID(tab), 344 launcher_delegate_->GetAppID(tab),
319 ChromeLauncherDelegate::APP_TYPE_TAB); 345 ChromeLauncherDelegate::APP_TYPE_TAB);
320 RegisterAppItem(item_id_, tab); 346 RegisterAppItem(item_id_, tab);
321 launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING); 347 launcher_delegate_->SetItemStatus(item_id_, GetStatusForTab(tab));
322 } 348 }
323 item_id_ = -1; 349 item_id_ = -1;
324 } else { 350 } else {
325 AddAppItem(tab); 351 AddAppItem(tab);
326 } 352 }
327 } 353 }
328 } 354 }
329 355
330 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { 356 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) {
357 ash::LauncherItemStatus status = GetStatusForTab(tab);
331 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( 358 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem(
332 this, 359 this,
333 launcher_delegate_->GetAppID(tab), 360 launcher_delegate_->GetAppID(tab),
334 ChromeLauncherDelegate::APP_TYPE_TAB, 361 ChromeLauncherDelegate::APP_TYPE_TAB,
335 ash::STATUS_RUNNING); 362 status);
336 RegisterAppItem(id, tab); 363 RegisterAppItem(id, tab);
337 } 364 }
338 365
339 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, 366 void LauncherUpdater::RegisterAppItem(ash::LauncherID id,
340 TabContentsWrapper* tab) { 367 TabContentsWrapper* tab) {
341 AppTabDetails details; 368 AppTabDetails details;
342 details.id = id; 369 details.id = id;
343 details.app_id = launcher_delegate_->GetAppID(tab); 370 details.app_id = launcher_delegate_->GetAppID(tab);
344 app_map_[tab] = details; 371 app_map_[tab] = details;
345 } 372 }
(...skipping 12 matching lines...) Expand all
358 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 385 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
359 ++i) { 386 ++i) {
360 if (i->second.id == id) { 387 if (i->second.id == id) {
361 *tab = i->first; 388 *tab = i->first;
362 return true; 389 return true;
363 } 390 }
364 } 391 }
365 return false; 392 return false;
366 } 393 }
367 394
395 ash::LauncherID LauncherUpdater::GetLauncherID(TabContentsWrapper* tab) {
396 if (type_ == TYPE_APP || type_ == TYPE_PANEL)
397 return item_id_;
398 AppTabMap::iterator i = app_map_.find(tab);
399 if (i == app_map_.end())
400 return item_id_;
401 return i->second.id;
402 }
403
404 ash::LauncherItemStatus LauncherUpdater::GetStatusForTab(
405 TabContentsWrapper* tab) {
406 return ash::wm::IsActiveWindow(window_) &&
407 tab == tab_model_->GetActiveTabContents() ?
408 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
409 }
410
368 ash::LauncherModel* LauncherUpdater::launcher_model() { 411 ash::LauncherModel* LauncherUpdater::launcher_model() {
369 return launcher_delegate_->model(); 412 return launcher_delegate_->model();
370 } 413 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698