| 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(Browser* browser, | 115 BrowserTabStripController::BrowserTabStripController(TabStripModel* model) |
| 116 TabStripModel* model) | |
| 117 : model_(model), | 116 : model_(model), |
| 118 tabstrip_(NULL), | 117 tabstrip_(NULL) { |
| 119 browser_(browser) { | |
| 120 model_->AddObserver(this); | 118 model_->AddObserver(this); |
| 121 | 119 |
| 122 notification_registrar_.Add(this, | 120 notification_registrar_.Add(this, |
| 123 NotificationType::TAB_CLOSEABLE_STATE_CHANGED, | 121 NotificationType::TAB_CLOSEABLE_STATE_CHANGED, |
| 124 NotificationService::AllSources()); | 122 NotificationService::AllSources()); |
| 125 } | 123 } |
| 126 | 124 |
| 127 BrowserTabStripController::~BrowserTabStripController() { | 125 BrowserTabStripController::~BrowserTabStripController() { |
| 128 // When we get here the TabStrip is being deleted. We need to explicitly | 126 // When we get here the TabStrip is being deleted. We need to explicitly |
| 129 // cancel the menu, otherwise it may try to invoke something on the tabstrip | 127 // 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... |
| 264 bool BrowserTabStripController::IsCompatibleWith(BaseTabStrip* other) const { | 262 bool BrowserTabStripController::IsCompatibleWith(BaseTabStrip* other) const { |
| 265 Profile* other_profile = | 263 Profile* other_profile = |
| 266 static_cast<BrowserTabStripController*>(other->controller())->profile(); | 264 static_cast<BrowserTabStripController*>(other->controller())->profile(); |
| 267 return other_profile == profile(); | 265 return other_profile == profile(); |
| 268 } | 266 } |
| 269 | 267 |
| 270 void BrowserTabStripController::CreateNewTab() { | 268 void BrowserTabStripController::CreateNewTab() { |
| 271 UserMetrics::RecordAction(UserMetricsAction("NewTab_Button"), | 269 UserMetrics::RecordAction(UserMetricsAction("NewTab_Button"), |
| 272 model_->profile()); | 270 model_->profile()); |
| 273 | 271 |
| 274 if (browser_ && browser_->OpenAppsPanelAsNewTab()) | 272 TabContents* selected_tab = model_->GetSelectedTabContents(); |
| 273 if (!selected_tab) |
| 274 return; |
| 275 |
| 276 Browser* browser = selected_tab->delegate()->GetBrowser(); |
| 277 if (browser->OpenAppsPanelAsNewTab()) |
| 275 return; | 278 return; |
| 276 | 279 |
| 277 model_->delegate()->AddBlankTab(true); | 280 model_->delegate()->AddBlankTab(true); |
| 278 } | 281 } |
| 279 | 282 |
| 280 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
| 281 // BrowserTabStripController, TabStripModelObserver implementation: | 284 // BrowserTabStripController, TabStripModelObserver implementation: |
| 282 | 285 |
| 283 void BrowserTabStripController::TabInsertedAt(TabContents* contents, | 286 void BrowserTabStripController::TabInsertedAt(TabContents* contents, |
| 284 int model_index, | 287 int model_index, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 int model_index) { | 361 int model_index) { |
| 359 TabRendererData data; | 362 TabRendererData data; |
| 360 SetTabRendererDataFromModel(contents, model_index, &data); | 363 SetTabRendererDataFromModel(contents, model_index, &data); |
| 361 tabstrip_->SetTabData(model_index, data); | 364 tabstrip_->SetTabData(model_index, data); |
| 362 } | 365 } |
| 363 | 366 |
| 364 void BrowserTabStripController::SetTabRendererDataFromModel( | 367 void BrowserTabStripController::SetTabRendererDataFromModel( |
| 365 TabContents* contents, | 368 TabContents* contents, |
| 366 int model_index, | 369 int model_index, |
| 367 TabRendererData* data) { | 370 TabRendererData* data) { |
| 368 SkBitmap* app_icon = NULL; | 371 SkBitmap* app_icon = contents->GetExtensionAppIcon(); |
| 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 | |
| 375 if (app_icon) | 372 if (app_icon) |
| 376 data->favicon = *app_icon; | 373 data->favicon = *app_icon; |
| 377 else | 374 else |
| 378 data->favicon = contents->GetFavIcon(); | 375 data->favicon = contents->GetFavIcon(); |
| 379 data->network_state = TabContentsNetworkState(contents); | 376 data->network_state = TabContentsNetworkState(contents); |
| 380 data->title = contents->GetTitle(); | 377 data->title = contents->GetTitle(); |
| 381 data->loading = contents->is_loading(); | 378 data->loading = contents->is_loading(); |
| 382 data->crashed = contents->is_crashed(); | 379 data->crashed = contents->is_crashed(); |
| 383 data->off_the_record = contents->profile()->IsOffTheRecord(); | 380 data->off_the_record = contents->profile()->IsOffTheRecord(); |
| 384 data->show_icon = contents->ShouldDisplayFavIcon(); | 381 data->show_icon = contents->ShouldDisplayFavIcon(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); | 420 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); |
| 424 // Note that this notification may be fired during a model mutation and | 421 // Note that this notification may be fired during a model mutation and |
| 425 // possibly before the tabstrip has processed the change. | 422 // possibly before the tabstrip has processed the change. |
| 426 // Here, we just re-layout each existing tab to reflect the change in its | 423 // Here, we just re-layout each existing tab to reflect the change in its |
| 427 // closeable state, and then schedule paint for entire tabstrip. | 424 // closeable state, and then schedule paint for entire tabstrip. |
| 428 for (int i = 0; i < tabstrip_->tab_count(); ++i) { | 425 for (int i = 0; i < tabstrip_->tab_count(); ++i) { |
| 429 tabstrip_->base_tab_at_tab_index(i)->Layout(); | 426 tabstrip_->base_tab_at_tab_index(i)->Layout(); |
| 430 } | 427 } |
| 431 tabstrip_->SchedulePaint(); | 428 tabstrip_->SchedulePaint(); |
| 432 } | 429 } |
| OLD | NEW |