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

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

Issue 9689047: Added notion of currently active app / browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mid air collision 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 launcher_delegate_->SetItemStatus(
122 GetLauncherID(tab_model_->GetActiveTabContents()),
123 ash::wm::IsActiveWindow(window_) ?
124 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
125 }
126
115 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, 127 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents,
116 TabContentsWrapper* new_contents, 128 TabContentsWrapper* new_contents,
117 int index, 129 int index,
118 bool user_gesture) { 130 bool user_gesture) {
131 if (ash::wm::IsActiveWindow(window_)) {
132 ash::LauncherID old_id = GetLauncherID(old_contents);
133 ash::LauncherID new_id = GetLauncherID(new_contents);
134
135 // The new_contents state will be handled in UpdateLauncher().
136 if (old_id != new_id && old_id >= 0)
137 launcher_delegate_->SetItemStatus(old_id, ash::STATUS_RUNNING);
138 }
119 // Update immediately on a tab change. 139 // Update immediately on a tab change.
120 UpdateLauncher(new_contents); 140 UpdateLauncher(new_contents);
121 } 141 }
122 142
123 void LauncherUpdater::TabChangedAt( 143 void LauncherUpdater::TabChangedAt(
124 TabContentsWrapper* tab, 144 TabContentsWrapper* tab,
125 int index, 145 int index,
126 TabStripModelObserver::TabChangeType change_type) { 146 TabStripModelObserver::TabChangeType change_type) {
127 if (type_ == TYPE_TABBED && 147 if (type_ == TYPE_TABBED &&
128 (change_type == TabStripModelObserver::LOADING_ONLY || 148 (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); 218 launcher_model()->Set(item_index, new_item);
199 } 219 }
200 } 220 }
201 } 221 }
202 222
203 void LauncherUpdater::FaviconUpdated() { 223 void LauncherUpdater::FaviconUpdated() {
204 UpdateLauncher(tab_model_->GetActiveTabContents()); 224 UpdateLauncher(tab_model_->GetActiveTabContents());
205 } 225 }
206 226
207 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 227 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
228 if (!tab)
229 return; // Assume the window is going to be closed if there are no tabs.
230
231 launcher_delegate_->SetItemStatus(GetLauncherID(tab), GetStatusForTab(tab));
232
208 if (type_ == TYPE_APP) 233 if (type_ == TYPE_APP)
209 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. 234 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
210 235
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_); 236 int item_index = launcher_model()->ItemIndexByID(item_id_);
215 if (item_index == -1) 237 if (item_index == -1)
216 return; 238 return;
217 239
218 ash::LauncherItem item = launcher_model()->items()[item_index]; 240 ash::LauncherItem item = launcher_model()->items()[item_index];
219 if (type_ == TYPE_PANEL) { 241 if (type_ == TYPE_PANEL) {
220 // Update the icon for app panels. 242 // Update the icon for app panels.
221 item.image = favicon_loader_->GetFavicon(); 243 item.image = favicon_loader_->GetFavicon();
222 if (item.image.empty()) { 244 if (item.image.empty()) {
223 if (tab->extension_tab_helper()->GetExtensionAppIcon()) 245 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. 333 // app item, which will end up using the closed item.
312 launcher_delegate_->LauncherItemClosed(item_id_); 334 launcher_delegate_->LauncherItemClosed(item_id_);
313 AddAppItem(tab); 335 AddAppItem(tab);
314 } else { 336 } else {
315 // All the tabs are app tabs, replace the tabbed item with the app. 337 // All the tabs are app tabs, replace the tabbed item with the app.
316 launcher_delegate_->ConvertTabbedToApp( 338 launcher_delegate_->ConvertTabbedToApp(
317 item_id_, 339 item_id_,
318 launcher_delegate_->GetAppID(tab), 340 launcher_delegate_->GetAppID(tab),
319 ChromeLauncherDelegate::APP_TYPE_TAB); 341 ChromeLauncherDelegate::APP_TYPE_TAB);
320 RegisterAppItem(item_id_, tab); 342 RegisterAppItem(item_id_, tab);
321 launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING); 343 launcher_delegate_->SetItemStatus(item_id_, GetStatusForTab(tab));
322 } 344 }
323 item_id_ = -1; 345 item_id_ = -1;
324 } else { 346 } else {
325 AddAppItem(tab); 347 AddAppItem(tab);
326 } 348 }
327 } 349 }
328 } 350 }
329 351
330 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { 352 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) {
353 ash::LauncherItemStatus status = GetStatusForTab(tab);
331 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( 354 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem(
332 this, 355 this,
333 launcher_delegate_->GetAppID(tab), 356 launcher_delegate_->GetAppID(tab),
334 ChromeLauncherDelegate::APP_TYPE_TAB, 357 ChromeLauncherDelegate::APP_TYPE_TAB,
335 ash::STATUS_RUNNING); 358 status);
336 RegisterAppItem(id, tab); 359 RegisterAppItem(id, tab);
337 } 360 }
338 361
339 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, 362 void LauncherUpdater::RegisterAppItem(ash::LauncherID id,
340 TabContentsWrapper* tab) { 363 TabContentsWrapper* tab) {
341 AppTabDetails details; 364 AppTabDetails details;
342 details.id = id; 365 details.id = id;
343 details.app_id = launcher_delegate_->GetAppID(tab); 366 details.app_id = launcher_delegate_->GetAppID(tab);
344 app_map_[tab] = details; 367 app_map_[tab] = details;
345 } 368 }
(...skipping 12 matching lines...) Expand all
358 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 381 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
359 ++i) { 382 ++i) {
360 if (i->second.id == id) { 383 if (i->second.id == id) {
361 *tab = i->first; 384 *tab = i->first;
362 return true; 385 return true;
363 } 386 }
364 } 387 }
365 return false; 388 return false;
366 } 389 }
367 390
391 ash::LauncherID LauncherUpdater::GetLauncherID(TabContentsWrapper* tab) {
392 if (type_ == TYPE_APP || type_ == TYPE_PANEL)
393 return item_id_;
394 AppTabMap::iterator i = app_map_.find(tab);
395 if (i == app_map_.end())
396 return item_id_;
397 return i->second.id;
398 }
399
400 ash::LauncherItemStatus LauncherUpdater::GetStatusForTab(
401 TabContentsWrapper* tab) {
402 return ash::wm::IsActiveWindow(window_) &&
403 tab == tab_model_->GetActiveTabContents() ?
404 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
405 }
406
368 ash::LauncherModel* LauncherUpdater::launcher_model() { 407 ash::LauncherModel* LauncherUpdater::launcher_model() {
369 return launcher_delegate_->model(); 408 return launcher_delegate_->model();
370 } 409 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698