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

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: Remove default args from State 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())
(...skipping 27 matching lines...) Expand all
98 101
99 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) { 102 TabContentsWrapper* LauncherUpdater::GetTab(ash::LauncherID id) {
100 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 103 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
101 ++i) { 104 ++i) {
102 if (i->second.id == id) 105 if (i->second.id == id)
103 return i->first; 106 return i->first;
104 } 107 }
105 return NULL; 108 return NULL;
106 } 109 }
107 110
111 void LauncherUpdater::ActivationChanged(TabContentsWrapper* tab, bool active) {
112 launcher_delegate_->SetItemStatus(
sky 2012/03/13 17:14:42 Might tab be NULL here?
DaveMoore 2012/03/13 23:33:56 N/A after changing to BrowserActivationStateChange
113 GetLauncherID(tab),
114 active ? ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
115 }
116
108 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents, 117 void LauncherUpdater::ActiveTabChanged(TabContentsWrapper* old_contents,
109 TabContentsWrapper* new_contents, 118 TabContentsWrapper* new_contents,
110 int index, 119 int index,
111 bool user_gesture) { 120 bool user_gesture) {
121 if (ash::wm::IsActiveWindow(window_)) {
122 ash::LauncherID old_id = GetLauncherID(old_contents);
123 ash::LauncherID new_id = GetLauncherID(new_contents);
124
125 // The new_contents state will be handled in UpdateLauncher().
126 if (old_id != new_id && old_id >= 0)
127 launcher_delegate_->SetItemStatus(old_id, ash::STATUS_RUNNING);
128 }
112 // Update immediately on a tab change. 129 // Update immediately on a tab change.
113 UpdateLauncher(new_contents); 130 UpdateLauncher(new_contents);
114 } 131 }
115 132
116 void LauncherUpdater::TabChangedAt( 133 void LauncherUpdater::TabChangedAt(
117 TabContentsWrapper* tab, 134 TabContentsWrapper* tab,
118 int index, 135 int index,
119 TabStripModelObserver::TabChangeType change_type) { 136 TabStripModelObserver::TabChangeType change_type) {
120 if (type_ == TYPE_TABBED && 137 if (type_ == TYPE_TABBED &&
121 (change_type == TabStripModelObserver::LOADING_ONLY || 138 (change_type == TabStripModelObserver::LOADING_ONLY ||
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 196
180 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) { 197 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) {
181 ash::LauncherItem new_item(launcher_model()->items()[item_index]); 198 ash::LauncherItem new_item(launcher_model()->items()[item_index]);
182 new_item.num_tabs = tab_model_->count(); 199 new_item.num_tabs = tab_model_->count();
183 launcher_model()->Set(item_index, new_item); 200 launcher_model()->Set(item_index, new_item);
184 } 201 }
185 } 202 }
186 } 203 }
187 204
188 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 205 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
206
sky 2012/03/13 17:14:42 nit: remove empty line.
DaveMoore 2012/03/13 23:33:56 Done.
207 ash::LauncherID id = GetLauncherID(tab);
208 if (id >= 0) {
sky 2012/03/13 17:14:42 When would this return <= 0?
209 ash::LauncherItemStatus status =
210 ash::wm::IsActiveWindow(window_) &&
211 tab == tab_model_->GetActiveTabContents() ?
212 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
213 launcher_delegate_->SetItemStatus(id, status);
214 }
215
189 if (type_ == TYPE_APP) 216 if (type_ == TYPE_APP)
190 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. 217 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
191 218
192 if (!tab) 219 if (!tab)
193 return; // Assume the window is going to be closed if there are no tabs. 220 return; // Assume the window is going to be closed if there are no tabs.
194 221
195 int item_index = launcher_model()->ItemIndexByID(item_id_); 222 int item_index = launcher_model()->ItemIndexByID(item_id_);
196 if (item_index == -1) 223 if (item_index == -1)
197 return; 224 return;
198 225
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // app item, which will end up using the closed item. 317 // app item, which will end up using the closed item.
291 launcher_delegate_->LauncherItemClosed(item_id_); 318 launcher_delegate_->LauncherItemClosed(item_id_);
292 AddAppItem(tab); 319 AddAppItem(tab);
293 } else { 320 } else {
294 // All the tabs are app tabs, replace the tabbed item with the app. 321 // All the tabs are app tabs, replace the tabbed item with the app.
295 launcher_delegate_->ConvertTabbedToApp( 322 launcher_delegate_->ConvertTabbedToApp(
296 item_id_, 323 item_id_,
297 launcher_delegate_->GetAppID(tab), 324 launcher_delegate_->GetAppID(tab),
298 ChromeLauncherDelegate::APP_TYPE_TAB); 325 ChromeLauncherDelegate::APP_TYPE_TAB);
299 RegisterAppItem(item_id_, tab); 326 RegisterAppItem(item_id_, tab);
300 launcher_delegate_->SetItemStatus(item_id_, ash::STATUS_RUNNING); 327 ash::LauncherItemStatus status =
328 ash::wm::IsActiveWindow(window_) &&
329 tab == tab_model_->GetActiveTabContents() ?
330 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
331 launcher_delegate_->SetItemStatus(item_id_, status);
301 } 332 }
302 item_id_ = -1; 333 item_id_ = -1;
303 } else { 334 } else {
304 AddAppItem(tab); 335 AddAppItem(tab);
305 } 336 }
306 } 337 }
307 } 338 }
308 339
309 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) { 340 void LauncherUpdater::AddAppItem(TabContentsWrapper* tab) {
341 ash::LauncherItemStatus status =
sky 2012/03/13 17:14:42 You have this code in three places. How about a Ge
DaveMoore 2012/03/13 23:33:56 Done.
342 ash::wm::IsActiveWindow(window_) &&
343 tab == tab_model_->GetActiveTabContents() ?
344 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
310 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem( 345 ash::LauncherID id = launcher_delegate_->CreateAppLauncherItem(
311 this, 346 this,
312 launcher_delegate_->GetAppID(tab), 347 launcher_delegate_->GetAppID(tab),
313 ChromeLauncherDelegate::APP_TYPE_TAB, 348 ChromeLauncherDelegate::APP_TYPE_TAB,
314 ash::STATUS_RUNNING); 349 status);
315 RegisterAppItem(id, tab); 350 RegisterAppItem(id, tab);
316 } 351 }
317 352
318 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, 353 void LauncherUpdater::RegisterAppItem(ash::LauncherID id,
319 TabContentsWrapper* tab) { 354 TabContentsWrapper* tab) {
320 AppTabDetails details; 355 AppTabDetails details;
321 details.id = id; 356 details.id = id;
322 details.app_id = launcher_delegate_->GetAppID(tab); 357 details.app_id = launcher_delegate_->GetAppID(tab);
323 app_map_[tab] = details; 358 app_map_[tab] = details;
324 } 359 }
325 360
326 void LauncherUpdater::CreateTabbedItem() { 361 void LauncherUpdater::CreateTabbedItem() {
327 DCHECK_EQ(-1, item_id_); 362 DCHECK_EQ(-1, item_id_);
328 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); 363 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this);
329 } 364 }
330 365
331 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { 366 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) {
332 if (item_id_ == id) 367 if (item_id_ == id)
333 return true; 368 return true;
334 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); 369 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end();
335 ++i) { 370 ++i) {
336 if (i->second.id == id) { 371 if (i->second.id == id) {
337 *tab = i->first; 372 *tab = i->first;
338 return true; 373 return true;
339 } 374 }
340 } 375 }
341 return false; 376 return false;
342 } 377 }
343 378
379 ash::LauncherID LauncherUpdater::GetLauncherID(TabContentsWrapper* tab) {
380 if (type_ == TYPE_APP || type_ == TYPE_PANEL)
381 return item_id_;
382 AppTabMap::iterator i = app_map_.find(tab);
383 if (i == app_map_.end())
384 return item_id_;
385 return i->second.id;
386 }
387
344 ash::LauncherModel* LauncherUpdater::launcher_model() { 388 ash::LauncherModel* LauncherUpdater::launcher_model() {
345 return launcher_delegate_->model(); 389 return launcher_delegate_->model();
346 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698