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

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: Review issues 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 launcher_delegate_->LauncherItemClosed(i->second.id); 49 launcher_delegate_->LauncherItemClosed(i->second.id);
50 } 50 }
51 51
52 void LauncherUpdater::Init() { 52 void LauncherUpdater::Init() {
53 tab_model_->AddObserver(this); 53 tab_model_->AddObserver(this);
54 if (type_ == TYPE_APP || type_ == TYPE_PANEL) { 54 if (type_ == TYPE_APP || type_ == TYPE_PANEL) {
55 // App type never changes, create the launcher item immediately. 55 // App type never changes, create the launcher item immediately.
56 ChromeLauncherDelegate::AppType app_type = 56 ChromeLauncherDelegate::AppType app_type =
57 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL 57 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL
58 : ChromeLauncherDelegate::APP_TYPE_WINDOW; 58 : ChromeLauncherDelegate::APP_TYPE_WINDOW;
59 ash::LauncherItemStatus app_status =
60 ash::wm::IsActiveWindow(window_) ?
61 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
59 item_id_ = launcher_delegate_->CreateAppLauncherItem( 62 item_id_ = launcher_delegate_->CreateAppLauncherItem(
60 this, app_id_, app_type, ash::STATUS_RUNNING); 63 this, app_id_, app_type, app_status);
61 } else { 64 } else {
62 // Determine if we have any tabs that should get launcher items. 65 // Determine if we have any tabs that should get launcher items.
63 std::vector<TabContentsWrapper*> app_tabs; 66 std::vector<TabContentsWrapper*> app_tabs;
64 for (int i = 0; i < tab_model_->count(); ++i) { 67 for (int i = 0; i < tab_model_->count(); ++i) {
65 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); 68 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i);
66 if (!launcher_delegate_->GetAppID(tab).empty()) 69 if (!launcher_delegate_->GetAppID(tab).empty())
67 app_tabs.push_back(tab); 70 app_tabs.push_back(tab);
68 } 71 }
69 72
70 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) 73 if (static_cast<int>(app_tabs.size()) != tab_model_->count())
71 CreateTabbedItem(); 74 CreateTabbedItem();
72 75
73 // Create items for the app tabs. 76 // Create items for the app tabs.
74 for (size_t i = 0; i < app_tabs.size(); ++i) 77 for (size_t i = 0; i < app_tabs.size(); ++i)
75 AddAppItem(app_tabs[i]); 78 AddAppItem(app_tabs[i]);
76 } 79 }
77 UpdateLauncher(tab_model_->GetActiveTabContents()); 80 // In testing scenarios we can get tab strips with no active contents.
81 if (tab_model_->GetActiveTabContents())
82 UpdateLauncher(tab_model_->GetActiveTabContents());
78 } 83 }
79 84
80 // static 85 // static
81 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { 86 LauncherUpdater* LauncherUpdater::Create(Browser* browser) {
82 Type type; 87 Type type;
83 std::string app_id; 88 std::string app_id;
84 if (browser->type() == Browser::TYPE_TABBED) { 89 if (browser->type() == Browser::TYPE_TABBED) {
85 type = TYPE_TABBED; 90 type = TYPE_TABBED;
86 } else if (browser->is_app()) { 91 } else if (browser->is_app()) {
87 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP; 92 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP;
(...skipping 10 matching lines...) Expand all
98 103
99 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) { 104 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) {
100 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 105 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
101 ++i) { 106 ++i) {
102 if (i->second.id == id) 107 if (i->second.id == id)
103 return i->first; 108 return i->first;
104 } 109 }
105 return NULL; 110 return NULL;
106 } 111 }
107 112
113 void LauncherUpdater::BrowserActivationStateChanged() {
114 launcher_delegate_->SetItemStatus(
115 GetLauncherID(tab_model_->GetActiveTabContents()),
116 ash::wm::IsActiveWindow(window_) ?
117 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
118 }
119
108 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, 120 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents,
109 TabContentsWrapper* new_contents, 121 TabContentsWrapper* new_contents,
110 int index, 122 int index,
111 bool user_gesture) { 123 bool user_gesture) {
124 if (ash::wm::IsActiveWindow(window_)) {
125 ash::LauncherID old_id = GetLauncherID(old_contents);
126 ash::LauncherID new_id = GetLauncherID(new_contents);
127
128 // The new_contents state will be handled in UpdateLauncher().
129 if (old_id != new_id && old_id >= 0)
130 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.
131 }
112 // Update immediately on a tab change. 132 // Update immediately on a tab change.
113 UpdateLauncher(new_contents); 133 UpdateLauncher(new_contents);
114 } 134 }
115 135
116 void LauncherUpdater::TabChangedAt( 136 void LauncherUpdater::TabChangedAt(
117 TabContentsWrapper* tab, 137 TabContentsWrapper* tab,
118 int index, 138 int index,
119 TabStripModelObserver::TabChangeType change_type) { 139 TabStripModelObserver::TabChangeType change_type) {
120 if (type_ == TYPE_TABBED && 140 if (type_ == TYPE_TABBED &&
121 (change_type == TabStripModelObserver::LOADING_ONLY || 141 (change_type == TabStripModelObserver::LOADING_ONLY ||
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 199
180 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) { 200 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) {
181 ash::LauncherItem new_item(launcher_model()->items()[item_index]); 201 ash::LauncherItem new_item(launcher_model()->items()[item_index]);
182 new_item.num_tabs = tab_model_->count(); 202 new_item.num_tabs = tab_model_->count();
183 launcher_model()->Set(item_index, new_item); 203 launcher_model()->Set(item_index, new_item);
184 } 204 }
185 } 205 }
186 } 206 }
187 207
188 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 208 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
209 launcher_delegate_->SetItemStatus(GetLauncherID(tab), GetStatusForTab(tab));
210
189 if (type_ == TYPE_APP) 211 if (type_ == TYPE_APP)
190 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. 212 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
191 213
192 if (!tab) 214 if (!tab)
sky 2012/03/14 04:05:44 Should this be before 209 now?
DaveMoore 2012/03/14 19:54:58 Done.
193 return; // Assume the window is going to be closed if there are no tabs. 215 return; // Assume the window is going to be closed if there are no tabs.
194 216
195 int item_index = launcher_model()->ItemIndexByID(item_id_); 217 int item_index = launcher_model()->ItemIndexByID(item_id_);
196 if (item_index == -1) 218 if (item_index == -1)
197 return; 219 return;
198 220
199 ash::LauncherItem item = launcher_model()->items()[item_index]; 221 ash::LauncherItem item = launcher_model()->items()[item_index];
200 if (type_ == TYPE_PANEL) { 222 if (type_ == TYPE_PANEL) {
201 // Update the icon for app panels. 223 // Update the icon for app panels.
202 // TODO(stevenjb): Get a large favicon for the launcher. 224 // TODO(stevenjb): Get a large favicon for the launcher.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // app item, which will end up using the closed item. 312 // app item, which will end up using the closed item.
291 launcher_delegate_->LauncherItemClosed(item_id_); 313 launcher_delegate_->LauncherItemClosed(item_id_);
292 AddAppItem(tab); 314 AddAppItem(tab);
293 } else { 315 } else {
294 // All the tabs are app tabs, replace the tabbed item with the app. 316 // All the tabs are app tabs, replace the tabbed item with the app.
295 launcher_delegate_->ConvertTabbedToApp( 317 launcher_delegate_->ConvertTabbedToApp(
296 item_id_, 318 item_id_,
297 launcher_delegate_->GetAppID(tab), 319 launcher_delegate_->GetAppID(tab),
298 ChromeLauncherDelegate::APP_TYPE_TAB); 320 ChromeLauncherDelegate::APP_TYPE_TAB);
299 RegisterAppItem(item_id_, tab); 321 RegisterAppItem(item_id_, tab);
300 launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING); 322 launcher_delegate_->SetItemStatus(item_id_, GetStatusForTab(tab));
301 } 323 }
302 item_id_ = -1; 324 item_id_ = -1;
303 } else { 325 } else {
304 AddAppItem(tab); 326 AddAppItem(tab);
305 } 327 }
306 } 328 }
307 } 329 }
308 330
309 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { 331 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) {
332 ash::LauncherItemStatus status = GetStatusForTab(tab);
310 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( 333 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem(
311 this, 334 this,
312 launcher_delegate_->GetAppID(tab), 335 launcher_delegate_->GetAppID(tab),
313 ChromeLauncherDelegate::APP_TYPE_TAB, 336 ChromeLauncherDelegate::APP_TYPE_TAB,
314 ash::STATUS_RUNNING); 337 status);
315 RegisterAppItem(id, tab); 338 RegisterAppItem(id, tab);
316 } 339 }
317 340
318 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, 341 void LauncherUpdater::RegisterAppItem(ash::LauncherID id,
319 TabContentsWrapper* tab) { 342 TabContentsWrapper* tab) {
320 AppTabDetails details; 343 AppTabDetails details;
321 details.id = id; 344 details.id = id;
322 details.app_id = launcher_delegate_->GetAppID(tab); 345 details.app_id = launcher_delegate_->GetAppID(tab);
323 app_map_[tab] = details; 346 app_map_[tab] = details;
324 } 347 }
325 348
326 void LauncherUpdater::CreateTabbedItem() { 349 void LauncherUpdater::CreateTabbedItem() {
327 DCHECK_EQ(-1, item_id_); 350 DCHECK_EQ(-1, item_id_);
328 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); 351 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this);
329 } 352 }
330 353
331 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { 354 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) {
332 if (item_id_ == id) 355 if (item_id_ == id)
333 return true; 356 return true;
334 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 357 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
335 ++i) { 358 ++i) {
336 if (i->second.id == id) { 359 if (i->second.id == id) {
337 *tab = i->first; 360 *tab = i->first;
338 return true; 361 return true;
339 } 362 }
340 } 363 }
341 return false; 364 return false;
342 } 365 }
343 366
367 ash::LauncherID LauncherUpdater::GetLauncherID(TabContentsWrapper* tab) {
368 if (type_ == TYPE_APP || type_ == TYPE_PANEL)
369 return item_id_;
370 AppTabMap::iterator i = app_map_.find(tab);
371 if (i == app_map_.end())
372 return item_id_;
373 return i->second.id;
374 }
375
376 ash::LauncherItemStatus LauncherUpdater::GetStatusForTab(
377 TabContentsWrapper* tab) {
378 return ash::wm::IsActiveWindow(window_) &&
379 tab == tab_model_->GetActiveTabContents() ?
380 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
381 }
382
344 ash::LauncherModel* LauncherUpdater::launcher_model() { 383 ash::LauncherModel* LauncherUpdater::launcher_model() {
345 return launcher_delegate_->model(); 384 return launcher_delegate_->model();
346 } 385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698