| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tabs/browser_tab_strip_controller.h" | 5 #include "chrome/browser/ui/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/extensions/extension_tab_helper.h" | 9 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 10 #include "chrome/browser/favicon/favicon_tab_helper.h" | 10 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 int model_index, | 321 int model_index, |
| 322 bool active) { | 322 bool active) { |
| 323 DCHECK(contents); | 323 DCHECK(contents); |
| 324 DCHECK(model_index == TabStripModel::kNoTab || | 324 DCHECK(model_index == TabStripModel::kNoTab || |
| 325 model_->ContainsIndex(model_index)); | 325 model_->ContainsIndex(model_index)); |
| 326 | 326 |
| 327 // Cancel any pending tab transition. | 327 // Cancel any pending tab transition. |
| 328 hover_tab_selector_.CancelTabTransition(); | 328 hover_tab_selector_.CancelTabTransition(); |
| 329 | 329 |
| 330 TabRendererData data; | 330 TabRendererData data; |
| 331 SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data); | 331 SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data, |
| 332 NEW_TAB); |
| 332 tabstrip_->AddTabAt(model_index, data); | 333 tabstrip_->AddTabAt(model_index, data); |
| 333 } | 334 } |
| 334 | 335 |
| 335 void BrowserTabStripController::TabDetachedAt(TabContentsWrapper* contents, | 336 void BrowserTabStripController::TabDetachedAt(TabContentsWrapper* contents, |
| 336 int model_index) { | 337 int model_index) { |
| 337 // Cancel any pending tab transition. | 338 // Cancel any pending tab transition. |
| 338 hover_tab_selector_.CancelTabTransition(); | 339 hover_tab_selector_.CancelTabTransition(); |
| 339 | 340 |
| 340 tabstrip_->RemoveTabAt(model_index); | 341 tabstrip_->RemoveTabAt(model_index); |
| 341 } | 342 } |
| 342 | 343 |
| 343 void BrowserTabStripController::ActiveTabChanged( | 344 void BrowserTabStripController::ActiveTabChanged( |
| 344 TabContentsWrapper* old_contents, | 345 TabContentsWrapper* old_contents, |
| 345 TabContentsWrapper* contents, | 346 TabContentsWrapper* contents, |
| 346 int model_index, | 347 int model_index, |
| 347 bool user_gesture) { | 348 bool user_gesture) { |
| 348 tabstrip_->SelectTabAt(model_->GetIndexOfTabContents(old_contents), | 349 tabstrip_->SelectTabAt(model_->GetIndexOfTabContents(old_contents), |
| 349 model_index); | 350 model_index); |
| 350 } | 351 } |
| 351 | 352 |
| 352 void BrowserTabStripController::TabMoved(TabContentsWrapper* contents, | 353 void BrowserTabStripController::TabMoved(TabContentsWrapper* contents, |
| 353 int from_model_index, | 354 int from_model_index, |
| 354 int to_model_index) { | 355 int to_model_index) { |
| 355 // Cancel any pending tab transition. | 356 // Cancel any pending tab transition. |
| 356 hover_tab_selector_.CancelTabTransition(); | 357 hover_tab_selector_.CancelTabTransition(); |
| 357 | 358 |
| 358 // Update the data first as the pinned state may have changed. | 359 // Update the data first as the pinned state may have changed. |
| 359 TabRendererData data; | 360 TabRendererData data; |
| 360 SetTabRendererDataFromModel(contents->tab_contents(), to_model_index, &data); | 361 SetTabRendererDataFromModel(contents->tab_contents(), to_model_index, &data, |
| 362 EXISTING_TAB); |
| 361 tabstrip_->SetTabData(from_model_index, data); | 363 tabstrip_->SetTabData(from_model_index, data); |
| 362 | 364 |
| 363 tabstrip_->MoveTab(from_model_index, to_model_index); | 365 tabstrip_->MoveTab(from_model_index, to_model_index); |
| 364 } | 366 } |
| 365 | 367 |
| 366 void BrowserTabStripController::TabChangedAt(TabContentsWrapper* contents, | 368 void BrowserTabStripController::TabChangedAt(TabContentsWrapper* contents, |
| 367 int model_index, | 369 int model_index, |
| 368 TabChangeType change_type) { | 370 TabChangeType change_type) { |
| 369 if (change_type == TITLE_NOT_LOADING) { | 371 if (change_type == TITLE_NOT_LOADING) { |
| 370 tabstrip_->TabTitleChangedNotLoading(model_index); | 372 tabstrip_->TabTitleChangedNotLoading(model_index); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 393 int model_index) { | 395 int model_index) { |
| 394 SetTabDataAt(contents, model_index); | 396 SetTabDataAt(contents, model_index); |
| 395 } | 397 } |
| 396 | 398 |
| 397 void BrowserTabStripController::TabBlockedStateChanged( | 399 void BrowserTabStripController::TabBlockedStateChanged( |
| 398 TabContentsWrapper* contents, | 400 TabContentsWrapper* contents, |
| 399 int model_index) { | 401 int model_index) { |
| 400 SetTabDataAt(contents, model_index); | 402 SetTabDataAt(contents, model_index); |
| 401 } | 403 } |
| 402 | 404 |
| 403 void BrowserTabStripController::SetTabDataAt( | 405 //////////////////////////////////////////////////////////////////////////////// |
| 404 TabContentsWrapper* contents, | 406 // BrowserTabStripController, NotificationObserver implementation: |
| 405 int model_index) { | 407 |
| 406 TabRendererData data; | 408 void BrowserTabStripController::Observe(NotificationType type, |
| 407 SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data); | 409 const NotificationSource& source, const NotificationDetails& details) { |
| 408 tabstrip_->SetTabData(model_index, data); | 410 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); |
| 411 // Note that this notification may be fired during a model mutation and |
| 412 // possibly before the tabstrip has processed the change. |
| 413 // Here, we just re-layout each existing tab to reflect the change in its |
| 414 // closeable state, and then schedule paint for entire tabstrip. |
| 415 for (int i = 0; i < tabstrip_->tab_count(); ++i) { |
| 416 tabstrip_->base_tab_at_tab_index(i)->Layout(); |
| 417 } |
| 418 tabstrip_->SchedulePaint(); |
| 409 } | 419 } |
| 410 | 420 |
| 411 void BrowserTabStripController::SetTabRendererDataFromModel( | 421 void BrowserTabStripController::SetTabRendererDataFromModel( |
| 412 TabContents* contents, | 422 TabContents* contents, |
| 413 int model_index, | 423 int model_index, |
| 414 TabRendererData* data) { | 424 TabRendererData* data, |
| 425 TabStatus tab_status) { |
| 415 SkBitmap* app_icon = NULL; | 426 SkBitmap* app_icon = NULL; |
| 416 TabContentsWrapper* wrapper = | 427 TabContentsWrapper* wrapper = |
| 417 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 428 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 418 | 429 |
| 419 // Extension App icons are slightly larger than favicons, so only allow | 430 // Extension App icons are slightly larger than favicons, so only allow |
| 420 // them if permitted by the model. | 431 // them if permitted by the model. |
| 421 if (model_->delegate()->LargeIconsPermitted()) | 432 if (model_->delegate()->LargeIconsPermitted()) |
| 422 app_icon = wrapper->extension_tab_helper()->GetExtensionAppIcon(); | 433 app_icon = wrapper->extension_tab_helper()->GetExtensionAppIcon(); |
| 423 | 434 |
| 424 if (app_icon) | 435 if (app_icon) |
| 425 data->favicon = *app_icon; | 436 data->favicon = *app_icon; |
| 426 else | 437 else |
| 427 data->favicon = wrapper->favicon_tab_helper()->GetFavicon(); | 438 data->favicon = wrapper->favicon_tab_helper()->GetFavicon(); |
| 428 data->network_state = TabContentsNetworkState(contents); | 439 data->network_state = TabContentsNetworkState(contents); |
| 429 data->title = contents->GetTitle(); | 440 data->title = contents->GetTitle(); |
| 430 data->url = contents->GetURL(); | 441 data->url = contents->GetURL(); |
| 431 data->loading = contents->is_loading(); | 442 data->loading = contents->is_loading(); |
| 432 data->crashed_status = contents->crashed_status(); | 443 data->crashed_status = contents->crashed_status(); |
| 433 data->incognito = contents->profile()->IsOffTheRecord(); | 444 data->incognito = contents->profile()->IsOffTheRecord(); |
| 434 data->show_icon = wrapper->favicon_tab_helper()->ShouldDisplayFavicon(); | 445 data->show_icon = wrapper->favicon_tab_helper()->ShouldDisplayFavicon(); |
| 435 data->mini = model_->IsMiniTab(model_index); | 446 data->mini = model_->IsMiniTab(model_index); |
| 436 data->blocked = model_->IsTabBlocked(model_index); | 447 data->blocked = model_->IsTabBlocked(model_index); |
| 437 data->app = wrapper->extension_tab_helper()->is_app(); | 448 data->app = wrapper->extension_tab_helper()->is_app(); |
| 438 } | 449 } |
| 439 | 450 |
| 451 void BrowserTabStripController::SetTabDataAt( |
| 452 TabContentsWrapper* contents, |
| 453 int model_index) { |
| 454 TabRendererData data; |
| 455 SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data, |
| 456 EXISTING_TAB); |
| 457 tabstrip_->SetTabData(model_index, data); |
| 458 } |
| 459 |
| 440 void BrowserTabStripController::StartHighlightTabsForCommand( | 460 void BrowserTabStripController::StartHighlightTabsForCommand( |
| 441 TabStripModel::ContextMenuCommand command_id, | 461 TabStripModel::ContextMenuCommand command_id, |
| 442 BaseTab* tab) { | 462 BaseTab* tab) { |
| 443 if (command_id == TabStripModel::CommandCloseOtherTabs || | 463 if (command_id == TabStripModel::CommandCloseOtherTabs || |
| 444 command_id == TabStripModel::CommandCloseTabsToRight) { | 464 command_id == TabStripModel::CommandCloseTabsToRight) { |
| 445 int model_index = tabstrip_->GetModelIndexOfBaseTab(tab); | 465 int model_index = tabstrip_->GetModelIndexOfBaseTab(tab); |
| 446 if (IsValidIndex(model_index)) { | 466 if (IsValidIndex(model_index)) { |
| 447 std::vector<int> indices = | 467 std::vector<int> indices = |
| 448 model_->GetIndicesClosedByCommand(model_index, command_id); | 468 model_->GetIndicesClosedByCommand(model_index, command_id); |
| 449 for (std::vector<int>::const_iterator i = indices.begin(); | 469 for (std::vector<int>::const_iterator i = indices.begin(); |
| 450 i != indices.end(); ++i) { | 470 i != indices.end(); ++i) { |
| 451 tabstrip_->StartHighlight(*i); | 471 tabstrip_->StartHighlight(*i); |
| 452 } | 472 } |
| 453 } | 473 } |
| 454 } | 474 } |
| 455 } | 475 } |
| 456 | 476 |
| 457 void BrowserTabStripController::StopHighlightTabsForCommand( | 477 void BrowserTabStripController::StopHighlightTabsForCommand( |
| 458 TabStripModel::ContextMenuCommand command_id, | 478 TabStripModel::ContextMenuCommand command_id, |
| 459 BaseTab* tab) { | 479 BaseTab* tab) { |
| 460 if (command_id == TabStripModel::CommandCloseTabsToRight || | 480 if (command_id == TabStripModel::CommandCloseTabsToRight || |
| 461 command_id == TabStripModel::CommandCloseOtherTabs) { | 481 command_id == TabStripModel::CommandCloseOtherTabs) { |
| 462 // Just tell all Tabs to stop pulsing - it's safe. | 482 // Just tell all Tabs to stop pulsing - it's safe. |
| 463 tabstrip_->StopAllHighlighting(); | 483 tabstrip_->StopAllHighlighting(); |
| 464 } | 484 } |
| 465 } | 485 } |
| 466 | 486 |
| 467 //////////////////////////////////////////////////////////////////////////////// | |
| 468 // BrowserTabStripController, NotificationObserver implementation: | |
| 469 | 487 |
| 470 void BrowserTabStripController::Observe(NotificationType type, | |
| 471 const NotificationSource& source, const NotificationDetails& details) { | |
| 472 DCHECK(type.value == NotificationType::TAB_CLOSEABLE_STATE_CHANGED); | |
| 473 // Note that this notification may be fired during a model mutation and | |
| 474 // possibly before the tabstrip has processed the change. | |
| 475 // Here, we just re-layout each existing tab to reflect the change in its | |
| 476 // closeable state, and then schedule paint for entire tabstrip. | |
| 477 for (int i = 0; i < tabstrip_->tab_count(); ++i) { | |
| 478 tabstrip_->base_tab_at_tab_index(i)->Layout(); | |
| 479 } | |
| 480 tabstrip_->SchedulePaint(); | |
| 481 } | |
| OLD | NEW |