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

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

Issue 9702054: Revert 126764 - Added notion of currently active app / browser (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;
69 item_id_ = launcher_delegate_->CreateAppLauncherItem( 66 item_id_ = launcher_delegate_->CreateAppLauncherItem(
70 this, app_id_, app_type, app_status); 67 this, app_id_, app_type, ash::STATUS_RUNNING);
71 } else { 68 } else {
72 // Determine if we have any tabs that should get launcher items. 69 // Determine if we have any tabs that should get launcher items.
73 std::vector<TabContentsWrapper*> app_tabs; 70 std::vector<TabContentsWrapper*> app_tabs;
74 for (int i = 0; i < tab_model_->count(); ++i) { 71 for (int i = 0; i < tab_model_->count(); ++i) {
75 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); 72 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i);
76 if (!launcher_delegate_->GetAppID(tab).empty()) 73 if (!launcher_delegate_->GetAppID(tab).empty())
77 app_tabs.push_back(tab); 74 app_tabs.push_back(tab);
78 } 75 }
79 76
80 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) 77 if (static_cast<int>(app_tabs.size()) != tab_model_->count())
81 CreateTabbedItem(); 78 CreateTabbedItem();
82 79
83 // Create items for the app tabs. 80 // Create items for the app tabs.
84 for (size_t i = 0; i < app_tabs.size(); ++i) 81 for (size_t i = 0; i < app_tabs.size(); ++i)
85 AddAppItem(app_tabs[i]); 82 AddAppItem(app_tabs[i]);
86 } 83 }
87 // In testing scenarios we can get tab strips with no active contents. 84 UpdateLauncher(tab_model_->GetActiveTabContents());
88 if (tab_model_->GetActiveTabContents())
89 UpdateLauncher(tab_model_->GetActiveTabContents());
90 } 85 }
91 86
92 // static 87 // static
93 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { 88 LauncherUpdater* LauncherUpdater::Create(Browser* browser) {
94 Type type; 89 Type type;
95 std::string app_id; 90 std::string app_id;
96 if (browser->type() == Browser::TYPE_TABBED) { 91 if (browser->type() == Browser::TYPE_TABBED) {
97 type = TYPE_TABBED; 92 type = TYPE_TABBED;
98 } else if (browser->is_app()) { 93 } else if (browser->is_app()) {
99 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP; 94 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP;
(...skipping 10 matching lines...) Expand all
110 105
111 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) { 106 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) {
112 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 107 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
113 ++i) { 108 ++i) {
114 if (i->second.id == id) 109 if (i->second.id == id)
115 return i->first; 110 return i->first;
116 } 111 }
117 return NULL; 112 return NULL;
118 } 113 }
119 114
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
127 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, 115 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents,
128 TabContentsWrapper* new_contents, 116 TabContentsWrapper* new_contents,
129 int index, 117 int index,
130 bool user_gesture) { 118 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 }
139 // Update immediately on a tab change. 119 // Update immediately on a tab change.
140 UpdateLauncher(new_contents); 120 UpdateLauncher(new_contents);
141 } 121 }
142 122
143 void LauncherUpdater::TabChangedAt( 123 void LauncherUpdater::TabChangedAt(
144 TabContentsWrapper* tab, 124 TabContentsWrapper* tab,
145 int index, 125 int index,
146 TabStripModelObserver::TabChangeType change_type) { 126 TabStripModelObserver::TabChangeType change_type) {
147 if (type_ == TYPE_TABBED && 127 if (type_ == TYPE_TABBED &&
148 (change_type == TabStripModelObserver::LOADING_ONLY || 128 (change_type == TabStripModelObserver::LOADING_ONLY ||
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 launcher_model()->Set(item_index, new_item); 198 launcher_model()->Set(item_index, new_item);
219 } 199 }
220 } 200 }
221 } 201 }
222 202
223 void LauncherUpdater::FaviconUpdated() { 203 void LauncherUpdater::FaviconUpdated() {
224 UpdateLauncher(tab_model_->GetActiveTabContents()); 204 UpdateLauncher(tab_model_->GetActiveTabContents());
225 } 205 }
226 206
227 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 207 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
208 if (type_ == TYPE_APP)
209 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
210
228 if (!tab) 211 if (!tab)
229 return; // Assume the window is going to be closed if there are no tabs. 212 return; // Assume the window is going to be closed if there are no tabs.
230 213
231 launcher_delegate_->SetItemStatus(GetLauncherID(tab), GetStatusForTab(tab));
232
233 if (type_ == TYPE_APP)
234 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
235
236 int item_index = launcher_model()->ItemIndexByID(item_id_); 214 int item_index = launcher_model()->ItemIndexByID(item_id_);
237 if (item_index == -1) 215 if (item_index == -1)
238 return; 216 return;
239 217
240 ash::LauncherItem item = launcher_model()->items()[item_index]; 218 ash::LauncherItem item = launcher_model()->items()[item_index];
241 if (type_ == TYPE_PANEL) { 219 if (type_ == TYPE_PANEL) {
242 // Update the icon for app panels. 220 // Update the icon for app panels.
243 item.image = favicon_loader_->GetFavicon(); 221 item.image = favicon_loader_->GetFavicon();
244 if (item.image.empty()) { 222 if (item.image.empty()) {
245 if (tab->extension_tab_helper()->GetExtensionAppIcon()) 223 if (tab->extension_tab_helper()->GetExtensionAppIcon())
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // app item, which will end up using the closed item. 311 // app item, which will end up using the closed item.
334 launcher_delegate_->LauncherItemClosed(item_id_); 312 launcher_delegate_->LauncherItemClosed(item_id_);
335 AddAppItem(tab); 313 AddAppItem(tab);
336 } else { 314 } else {
337 // All the tabs are app tabs, replace the tabbed item with the app. 315 // All the tabs are app tabs, replace the tabbed item with the app.
338 launcher_delegate_->ConvertTabbedToApp( 316 launcher_delegate_->ConvertTabbedToApp(
339 item_id_, 317 item_id_,
340 launcher_delegate_->GetAppID(tab), 318 launcher_delegate_->GetAppID(tab),
341 ChromeLauncherDelegate::APP_TYPE_TAB); 319 ChromeLauncherDelegate::APP_TYPE_TAB);
342 RegisterAppItem(item_id_, tab); 320 RegisterAppItem(item_id_, tab);
343 launcher_delegate_->SetItemStatus(item_id_, GetStatusForTab(tab)); 321 launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING);
344 } 322 }
345 item_id_ = -1; 323 item_id_ = -1;
346 } else { 324 } else {
347 AddAppItem(tab); 325 AddAppItem(tab);
348 } 326 }
349 } 327 }
350 } 328 }
351 329
352 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { 330 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) {
353 ash::LauncherItemStatus status = GetStatusForTab(tab);
354 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( 331 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem(
355 this, 332 this,
356 launcher_delegate_->GetAppID(tab), 333 launcher_delegate_->GetAppID(tab),
357 ChromeLauncherDelegate::APP_TYPE_TAB, 334 ChromeLauncherDelegate::APP_TYPE_TAB,
358 status); 335 ash::STATUS_RUNNING);
359 RegisterAppItem(id, tab); 336 RegisterAppItem(id, tab);
360 } 337 }
361 338
362 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, 339 void LauncherUpdater::RegisterAppItem(ash::LauncherID id,
363 TabContentsWrapper* tab) { 340 TabContentsWrapper* tab) {
364 AppTabDetails details; 341 AppTabDetails details;
365 details.id = id; 342 details.id = id;
366 details.app_id = launcher_delegate_->GetAppID(tab); 343 details.app_id = launcher_delegate_->GetAppID(tab);
367 app_map_[tab] = details; 344 app_map_[tab] = details;
368 } 345 }
(...skipping 12 matching lines...) Expand all
381 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 358 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
382 ++i) { 359 ++i) {
383 if (i->second.id == id) { 360 if (i->second.id == id) {
384 *tab = i->first; 361 *tab = i->first;
385 return true; 362 return true;
386 } 363 }
387 } 364 }
388 return false; 365 return false;
389 } 366 }
390 367
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
407 ash::LauncherModel* LauncherUpdater::launcher_model() { 368 ash::LauncherModel* LauncherUpdater::launcher_model() {
408 return launcher_delegate_->model(); 369 return launcher_delegate_->model();
409 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698