Chromium Code Reviews| Index: chrome/browser/ui/views/ash/launcher/launcher_updater.cc |
| diff --git a/chrome/browser/ui/views/ash/launcher/launcher_updater.cc b/chrome/browser/ui/views/ash/launcher/launcher_updater.cc |
| index 8f3c604710fae8c582a3acac0183eaff55d6780d..46c9777b8281a6781220c6d19e1eca702ada5cd6 100644 |
| --- a/chrome/browser/ui/views/ash/launcher/launcher_updater.cc |
| +++ b/chrome/browser/ui/views/ash/launcher/launcher_updater.cc |
| @@ -56,8 +56,11 @@ void LauncherUpdater::Init() { |
| ChromeLauncherDelegate::AppType app_type = |
| type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL |
| : ChromeLauncherDelegate::APP_TYPE_WINDOW; |
| + ash::LauncherItemStatus app_status = |
| + ash::wm::IsActiveWindow(window_) ? |
| + ash::STATUS_ACTIVE : ash::STATUS_RUNNING; |
| item_id_ = launcher_delegate_->CreateAppLauncherItem( |
| - this, app_id_, app_type, ash::STATUS_RUNNING); |
| + this, app_id_, app_type, app_status); |
| } else { |
| // Determine if we have any tabs that should get launcher items. |
| std::vector<TabContentsWrapper*> app_tabs; |
| @@ -74,7 +77,9 @@ void LauncherUpdater::Init() { |
| for (size_t i = 0; i < app_tabs.size(); ++i) |
| AddAppItem(app_tabs[i]); |
| } |
| - UpdateLauncher(tab_model_->GetActiveTabContents()); |
| + // In testing scenarios we can get tab strips with no active contents. |
| + if (tab_model_->GetActiveTabContents()) |
| + UpdateLauncher(tab_model_->GetActiveTabContents()); |
| } |
| // static |
| @@ -105,10 +110,25 @@ TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) { |
| return NULL; |
| } |
| +void LauncherUpdater::BrowserActivationStateChanged() { |
| + launcher_delegate_->SetItemStatus( |
| + GetLauncherID(tab_model_->GetActiveTabContents()), |
| + ash::wm::IsActiveWindow(window_) ? |
| + ash::STATUS_ACTIVE : ash::STATUS_RUNNING); |
| +} |
| + |
| void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, |
| TabContentsWrapper* new_contents, |
| int index, |
| bool user_gesture) { |
| + if (ash::wm::IsActiveWindow(window_)) { |
| + ash::LauncherID old_id = GetLauncherID(old_contents); |
| + ash::LauncherID new_id = GetLauncherID(new_contents); |
| + |
| + // The new_contents state will be handled in UpdateLauncher(). |
| + if (old_id != new_id && old_id >= 0) |
| + launcher_delegate_->SetItemStatus(old_id, ash::STATUS_RUNNING); |
|
sky
2012/03/14 04:05:44
nit: spacing
DaveMoore
2012/03/14 19:54:58
Done.
|
| + } |
| // Update immediately on a tab change. |
| UpdateLauncher(new_contents); |
| } |
| @@ -186,6 +206,8 @@ void LauncherUpdater::TabDetachedAt(TabContentsWrapper* contents, int index) { |
| } |
| void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { |
| + launcher_delegate_->SetItemStatus(GetLauncherID(tab), GetStatusForTab(tab)); |
| + |
| if (type_ == TYPE_APP) |
| return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. |
| @@ -297,7 +319,7 @@ void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, |
| launcher_delegate_->GetAppID(tab), |
| ChromeLauncherDelegate::APP_TYPE_TAB); |
| RegisterAppItem(item_id_, tab); |
| - launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING); |
| + launcher_delegate_->SetItemStatus(item_id_, GetStatusForTab(tab)); |
| } |
| item_id_ = -1; |
| } else { |
| @@ -307,11 +329,12 @@ void LauncherUpdater::UpdateAppTabState(TabContentsWrapper* tab, |
| } |
| void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { |
| + ash::LauncherItemStatus status = GetStatusForTab(tab); |
| ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( |
| this, |
| launcher_delegate_->GetAppID(tab), |
| ChromeLauncherDelegate::APP_TYPE_TAB, |
| - ash::STATUS_RUNNING); |
| + status); |
| RegisterAppItem(id, tab); |
| } |
| @@ -341,6 +364,22 @@ bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { |
| return false; |
| } |
| +ash::LauncherID LauncherUpdater::GetLauncherID(TabContentsWrapper* tab) { |
| + if (type_ == TYPE_APP || type_ == TYPE_PANEL) |
| + return item_id_; |
| + AppTabMap::iterator i = app_map_.find(tab); |
| + if (i == app_map_.end()) |
| + return item_id_; |
| + return i->second.id; |
| +} |
| + |
| +ash::LauncherItemStatus LauncherUpdater::GetStatusForTab( |
| + TabContentsWrapper* tab) { |
| + return ash::wm::IsActiveWindow(window_) && |
| + tab == tab_model_->GetActiveTabContents() ? |
| + ash::STATUS_ACTIVE : ash::STATUS_RUNNING; |
| +} |
| + |
| ash::LauncherModel* LauncherUpdater::launcher_model() { |
| return launcher_delegate_->model(); |
| } |