OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tabs/browser_tab_strip_controller.h" | 5 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // The last command that was selected, so that we can start/stop highlighting | 105 // The last command that was selected, so that we can start/stop highlighting |
106 // appropriately as the user moves through the menu. | 106 // appropriately as the user moves through the menu. |
107 TabStripModel::ContextMenuCommand last_command_; | 107 TabStripModel::ContextMenuCommand last_command_; |
108 | 108 |
109 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); | 109 DISALLOW_COPY_AND_ASSIGN(TabContextMenuContents); |
110 }; | 110 }; |
111 | 111 |
112 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
113 // BrowserTabStripController, public: | 113 // BrowserTabStripController, public: |
114 | 114 |
115 BrowserTabStripController::BrowserTabStripController(TabStripModel* model) | 115 BrowserTabStripController::BrowserTabStripController(Browser* browser, |
| 116 TabStripModel* model) |
116 : model_(model), | 117 : model_(model), |
117 tabstrip_(NULL) { | 118 tabstrip_(NULL), |
| 119 browser_(browser) { |
118 model_->AddObserver(this); | 120 model_->AddObserver(this); |
119 | 121 |
120 notification_registrar_.Add(this, | 122 notification_registrar_.Add(this, |
121 NotificationType::TAB_CLOSEABLE_STATE_CHANGED, | 123 NotificationType::TAB_CLOSEABLE_STATE_CHANGED, |
122 NotificationService::AllSources()); | 124 NotificationService::AllSources()); |
123 } | 125 } |
124 | 126 |
125 BrowserTabStripController::~BrowserTabStripController() { | 127 BrowserTabStripController::~BrowserTabStripController() { |
126 // When we get here the TabStrip is being deleted. We need to explicitly | 128 // When we get here the TabStrip is being deleted. We need to explicitly |
127 // cancel the menu, otherwise it may try to invoke something on the tabstrip | 129 // cancel the menu, otherwise it may try to invoke something on the tabstrip |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 bool BrowserTabStripController::IsCompatibleWith(BaseTabStrip* other) const { | 264 bool BrowserTabStripController::IsCompatibleWith(BaseTabStrip* other) const { |
263 Profile* other_profile = | 265 Profile* other_profile = |
264 static_cast<BrowserTabStripController*>(other->controller())->profile(); | 266 static_cast<BrowserTabStripController*>(other->controller())->profile(); |
265 return other_profile == profile(); | 267 return other_profile == profile(); |
266 } | 268 } |
267 | 269 |
268 void BrowserTabStripController::CreateNewTab() { | 270 void BrowserTabStripController::CreateNewTab() { |
269 UserMetrics::RecordAction(UserMetricsAction("NewTab_Button"), | 271 UserMetrics::RecordAction(UserMetricsAction("NewTab_Button"), |
270 model_->profile()); | 272 model_->profile()); |
271 | 273 |
272 TabContents* selected_tab = model_->GetSelectedTabContents(); | 274 if (browser_ && browser_->OpenAppsPanelAsNewTab()) |
273 if (!selected_tab) | |
274 return; | |
275 | |
276 Browser* browser = selected_tab->delegate()->GetBrowser(); | |
277 if (browser->OpenAppsPanelAsNewTab()) | |
278 return; | 275 return; |
279 | 276 |
280 model_->delegate()->AddBlankTab(true); | 277 model_->delegate()->AddBlankTab(true); |
281 } | 278 } |
282 | 279 |
283 //////////////////////////////////////////////////////////////////////////////// | 280 //////////////////////////////////////////////////////////////////////////////// |
284 // BrowserTabStripController, TabStripModelObserver implementation: | 281 // BrowserTabStripController, TabStripModelObserver implementation: |
285 | 282 |
286 void BrowserTabStripController::TabInsertedAt(TabContents* contents, | 283 void BrowserTabStripController::TabInsertedAt(TabContents* contents, |
287 int model_index, | 284 int model_index, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 int model_index) { | 358 int model_index) { |
362 TabRendererData data; | 359 TabRendererData data; |
363 SetTabRendererDataFromModel(contents, model_index, &data); | 360 SetTabRendererDataFromModel(contents, model_index, &data); |
364 tabstrip_->SetTabData(model_index, data); | 361 tabstrip_->SetTabData(model_index, data); |
365 } | 362 } |
366 | 363 |
367 void BrowserTabStripController::SetTabRendererDataFromModel( | 364 void BrowserTabStripController::SetTabRendererDataFromModel( |
368 TabContents* contents, | 365 TabContents* contents, |
369 int model_index, | 366 int model_index, |
370 TabRendererData* data) { | 367 TabRendererData* data) { |
371 SkBitmap* app_icon = contents->GetExtensionAppIcon(); | 368 SkBitmap* app_icon = NULL; |
| 369 |
| 370 // Extension App icons are slightly larger than favicons, so only allow |
| 371 // them if permitted by the model. |
| 372 if (model_->delegate()->LargeIconsPermitted()) |
| 373 app_icon = contents->GetExtensionAppIcon(); |
| 374 |
372 if (app_icon) | 375 if (app_icon) |
373 data->favicon = *app_icon; | 376 data->favicon = *app_icon; |
374 else | 377 else |
375 data->favicon = contents->GetFavIcon(); | 378 data->favicon = contents->GetFavIcon(); |
376 data->network_state = TabContentsNetworkState(contents); | 379 data->network_state = TabContentsNetworkState(contents); |
377 data->title = contents->GetTitle(); | 380 data->title = contents->GetTitle(); |
378 data->loading = contents->is_loading(); | 381 data->loading = contents->is_loading(); |
379 data->crashed = contents->is_crashed(); | 382 data->crashed = contents->is_crashed(); |
380 data->off_the_record = contents->profile()->IsOffTheRecord(); | 383 data->off_the_record = contents->profile()->IsOffTheRecord(); |
381 data->show_icon = contents->ShouldDisplayFavIcon(); | 384 data->show_icon = contents->ShouldDisplayFavIcon(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); | 423 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); |
421 // Note that this notification may be fired during a model mutation and | 424 // Note that this notification may be fired during a model mutation and |
422 // possibly before the tabstrip has processed the change. | 425 // possibly before the tabstrip has processed the change. |
423 // Here, we just re-layout each existing tab to reflect the change in its | 426 // Here, we just re-layout each existing tab to reflect the change in its |
424 // closeable state, and then schedule paint for entire tabstrip. | 427 // closeable state, and then schedule paint for entire tabstrip. |
425 for (int i = 0; i < tabstrip_->tab_count(); ++i) { | 428 for (int i = 0; i < tabstrip_->tab_count(); ++i) { |
426 tabstrip_->base_tab_at_tab_index(i)->Layout(); | 429 tabstrip_->base_tab_at_tab_index(i)->Layout(); |
427 } | 430 } |
428 tabstrip_->SchedulePaint(); | 431 tabstrip_->SchedulePaint(); |
429 } | 432 } |
OLD | NEW |