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

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

Issue 9590001: Launch panels as popup windows in Aura, and add separate launcher icon logic for panels. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 LauncherUpdater::~LauncherUpdater() { 44 LauncherUpdater::~LauncherUpdater() {
45 tab_model_->RemoveObserver(this); 45 tab_model_->RemoveObserver(this);
46 if (item_id_ != -1) 46 if (item_id_ != -1)
47 launcher_delegate_->LauncherItemClosed(item_id_); 47 launcher_delegate_->LauncherItemClosed(item_id_);
48 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i) 48 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i)
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) { 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 =
57 type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL
58 : ChromeLauncherDelegate::APP_TYPE_WINDOW;
56 item_id_ = launcher_delegate_->CreateAppLauncherItem( 59 item_id_ = launcher_delegate_->CreateAppLauncherItem(
57 this, app_id_, ChromeLauncherDelegate::APP_TYPE_WINDOW); 60 this, app_id_, app_type);
58 } else { 61 } else {
59 // Determine if we have any tabs that should get launcher items. 62 // Determine if we have any tabs that should get launcher items.
60 std::vector<TabContentsWrapper*> app_tabs; 63 std::vector<TabContentsWrapper*> app_tabs;
61 for (int i = 0; i < tab_model_->count(); ++i) { 64 for (int i = 0; i < tab_model_->count(); ++i) {
62 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i); 65 TabContentsWrapper* tab = tab_model_->GetTabContentsAt(i);
63 if (!launcher_delegate_->GetAppID(tab).empty()) 66 if (!launcher_delegate_->GetAppID(tab).empty())
64 app_tabs.push_back(tab); 67 app_tabs.push_back(tab);
65 } 68 }
66 69
67 if (static_cast<int>(app_tabs.size()) != tab_model_->count()) 70 if (static_cast<int>(app_tabs.size()) != tab_model_->count())
68 CreateTabbedItem(); 71 CreateTabbedItem();
69 72
70 // Create items for the app tabs. 73 // Create items for the app tabs.
71 for (size_t i = 0; i < app_tabs.size(); ++i) 74 for (size_t i = 0; i < app_tabs.size(); ++i)
72 AddAppItem(app_tabs[i]); 75 AddAppItem(app_tabs[i]);
73 } 76 }
74 UpdateLauncher(tab_model_->GetActiveTabContents()); 77 UpdateLauncher(tab_model_->GetActiveTabContents());
75 } 78 }
76 79
77 // static 80 // static
78 LauncherUpdater* LauncherUpdater::Create(Browser* browser) { 81 LauncherUpdater* LauncherUpdater::Create(Browser* browser) {
79 Type type; 82 Type type;
80 std::string app_id; 83 std::string app_id;
81 if (browser->type() == Browser::TYPE_TABBED) { 84 if (browser->type() == Browser::TYPE_TABBED) {
82 type = TYPE_TABBED; 85 type = TYPE_TABBED;
83 } else if (browser->is_app()) { 86 } else if (browser->is_app()) {
84 type = TYPE_APP; 87 type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP;
85 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name()); 88 app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name());
86 } else { 89 } else {
87 return NULL; 90 return NULL;
88 } 91 }
89 LauncherUpdater* icon_updater = new LauncherUpdater( 92 LauncherUpdater* icon_updater = new LauncherUpdater(
90 browser->window()->GetNativeHandle(), browser->tabstrip_model(), 93 browser->window()->GetNativeHandle(), browser->tabstrip_model(),
91 ChromeLauncherDelegate::instance(), type, app_id); 94 ChromeLauncherDelegate::instance(), type, app_id);
92 icon_updater->Init(); 95 icon_updater->Init();
93 return icon_updater; 96 return icon_updater;
94 } 97 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 int item_index = launcher_model()->ItemIndexByID(item_id_); 138 int item_index = launcher_model()->ItemIndexByID(item_id_);
136 if (item_index == -1) 139 if (item_index == -1)
137 return; 140 return;
138 launcher_model()->SetPendingUpdate(item_index); 141 launcher_model()->SetPendingUpdate(item_index);
139 } 142 }
140 } 143 }
141 144
142 void LauncherUpdater::TabInsertedAt(TabContentsWrapper* contents, 145 void LauncherUpdater::TabInsertedAt(TabContentsWrapper* contents,
143 int index, 146 int index,
144 bool foreground) { 147 bool foreground) {
145 if (type_ == TYPE_APP) 148 if (type_ != TYPE_TABBED)
146 return; 149 return;
147 150
148 UpdateAppTabState(contents, UPDATE_TAB_INSERTED); 151 UpdateAppTabState(contents, UPDATE_TAB_INSERTED);
149 } 152 }
150 153
151 void LauncherUpdater::TabReplacedAt(TabStripModel* tab_strip_model, 154 void LauncherUpdater::TabReplacedAt(TabStripModel* tab_strip_model,
152 TabContentsWrapper* old_contents, 155 TabContentsWrapper* old_contents,
153 TabContentsWrapper* new_contents, 156 TabContentsWrapper* new_contents,
154 int index) { 157 int index) {
155 AppTabMap::iterator i = app_map_.find(old_contents); 158 AppTabMap::iterator i = app_map_.find(old_contents);
156 if (i != app_map_.end()) { 159 if (i != app_map_.end()) {
157 AppTabDetails details = i->second; 160 AppTabDetails details = i->second;
158 app_map_.erase(i); 161 app_map_.erase(i);
159 i = app_map_.end(); 162 i = app_map_.end();
160 app_map_[new_contents] = details; 163 app_map_[new_contents] = details;
161 UpdateAppTabState(new_contents, UPDATE_TAB_CHANGED); 164 UpdateAppTabState(new_contents, UPDATE_TAB_CHANGED);
162 } 165 }
163 } 166 }
164 167
165 void LauncherUpdater::TabDetachedAt(TabContentsWrapper* contents, int index) { 168 void LauncherUpdater::TabDetachedAt(TabContentsWrapper* contents, int index) {
166 if (type_ == TYPE_APP) 169 if (type_ != TYPE_TABBED)
167 return; 170 return;
168 171
169 UpdateAppTabState(contents, UPDATE_TAB_REMOVED); 172 UpdateAppTabState(contents, UPDATE_TAB_REMOVED);
170 if (tab_model_->count() <= 3) { 173 if (tab_model_->count() <= 3) {
171 // We can't rely on the active tab at this point as the model hasn't fully 174 // We can't rely on the active tab at this point as the model hasn't fully
172 // adjusted itself. We can rely on the count though. 175 // adjusted itself. We can rely on the count though.
173 int item_index = launcher_model()->ItemIndexByID(item_id_); 176 int item_index = launcher_model()->ItemIndexByID(item_id_);
174 if (item_index == -1) 177 if (item_index == -1)
175 return; 178 return;
176 179
177 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) { 180 if (launcher_model()->items()[item_index].type == ash::TYPE_TABBED) {
178 ash::LauncherItem new_item(launcher_model()->items()[item_index]); 181 ash::LauncherItem new_item(launcher_model()->items()[item_index]);
179 new_item.num_tabs = tab_model_->count(); 182 new_item.num_tabs = tab_model_->count();
180 launcher_model()->Set(item_index, new_item); 183 launcher_model()->Set(item_index, new_item);
181 } 184 }
182 } 185 }
183 } 186 }
184 187
185 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { 188 void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) {
186 if (type_ == TYPE_APP) 189 if (type_ == TYPE_APP)
187 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate. 190 return; // TYPE_APP is entirely maintained by ChromeLauncherDelegate.
188 191
189 if (!tab) 192 if (!tab)
190 return; // Assume the window is going to be closed if there are no tabs. 193 return; // Assume the window is going to be closed if there are no tabs.
191 194
192 int item_index = launcher_model()->ItemIndexByID(item_id_); 195 int item_index = launcher_model()->ItemIndexByID(item_id_);
193 if (item_index == -1) 196 if (item_index == -1)
194 return; 197 return;
195 198
196 ash::LauncherItem item; 199 ash::LauncherItem item = launcher_model()->items()[item_index];
197 if (launcher_model()->items()[item_index].type == ash::TYPE_APP) { 200 if (type_ == TYPE_PANEL) {
201 // Update the icon for app panels.
202 // TODO(stevenjb): Get a large favicon for the launcher.
203 if (!tab->favicon_tab_helper()->GetFavicon().empty())
204 item.image = tab->favicon_tab_helper()->GetFavicon();
205 else if (tab->extension_tab_helper()->GetExtensionAppIcon())
206 item.image = *tab->extension_tab_helper()->GetExtensionAppIcon();
207 else
208 item.image = Extension::GetDefaultIcon(true);
209 } else if (launcher_model()->items()[item_index].type == ash::TYPE_APP) {
198 // Use the app icon if we can. 210 // Use the app icon if we can.
199 if (tab->extension_tab_helper()->GetExtensionAppIcon()) 211 if (tab->extension_tab_helper()->GetExtensionAppIcon())
200 item.image = *tab->extension_tab_helper()->GetExtensionAppIcon(); 212 item.image = *tab->extension_tab_helper()->GetExtensionAppIcon();
201 else 213 else
202 item.image = tab->favicon_tab_helper()->GetFavicon(); 214 item.image = tab->favicon_tab_helper()->GetFavicon();
203 } else { 215 } else {
204 item.num_tabs = tab_model_->count(); 216 item.num_tabs = tab_model_->count();
205 if (tab->favicon_tab_helper()->ShouldDisplayFavicon()) { 217 if (tab->favicon_tab_helper()->ShouldDisplayFavicon()) {
206 item.image = tab->favicon_tab_helper()->GetFavicon(); 218 item.image = tab->favicon_tab_helper()->GetFavicon();
207 if (item.image.empty()) { 219 if (item.image.empty()) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 *tab = i->first; 335 *tab = i->first;
324 return true; 336 return true;
325 } 337 }
326 } 338 }
327 return false; 339 return false;
328 } 340 }
329 341
330 ash::LauncherModel* LauncherUpdater::launcher_model() { 342 ash::LauncherModel* LauncherUpdater::launcher_model() {
331 return launcher_delegate_->model(); 343 return launcher_delegate_->model();
332 } 344 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/launcher/launcher_updater.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698