| OLD | NEW |
| 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/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/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/extension_tab_helper.h" | 10 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 11 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 16 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h" |
| 19 #include "chrome/browser/ui/views/tabs/tab.h" | 19 #include "chrome/browser/ui/views/tabs/tab.h" |
| 20 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 20 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 context_menu_contents_->RunMenuAt(p); | 292 context_menu_contents_->RunMenuAt(p); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void BrowserTabStripController::UpdateLoadingAnimations() { | 295 void BrowserTabStripController::UpdateLoadingAnimations() { |
| 296 // Don't use the model count here as it's possible for this to be invoked | 296 // Don't use the model count here as it's possible for this to be invoked |
| 297 // before we've applied an update from the model (Browser::TabInsertedAt may | 297 // before we've applied an update from the model (Browser::TabInsertedAt may |
| 298 // be processed before us and invokes this). | 298 // be processed before us and invokes this). |
| 299 for (int i = 0, tab_count = tabstrip_->tab_count(); i < tab_count; ++i) { | 299 for (int i = 0, tab_count = tabstrip_->tab_count(); i < tab_count; ++i) { |
| 300 BaseTab* tab = tabstrip_->tab_at(i); | 300 BaseTab* tab = tabstrip_->tab_at(i); |
| 301 if (model_->ContainsIndex(i)) { | 301 if (model_->ContainsIndex(i)) { |
| 302 TabContentsWrapper* contents = model_->GetTabContentsAt(i); | 302 TabContents* contents = model_->GetTabContentsAt(i); |
| 303 tab->UpdateLoadingAnimation( | 303 tab->UpdateLoadingAnimation( |
| 304 TabContentsNetworkState(contents->web_contents())); | 304 TabContentsNetworkState(contents->web_contents())); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 int BrowserTabStripController::HasAvailableDragActions() const { | 309 int BrowserTabStripController::HasAvailableDragActions() const { |
| 310 return model_->delegate()->GetDragActions(); | 310 return model_->delegate()->GetDragActions(); |
| 311 } | 311 } |
| 312 | 312 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 return; | 368 return; |
| 369 | 369 |
| 370 g_browser_process->local_state()->SetInteger( | 370 g_browser_process->local_state()->SetInteger( |
| 371 prefs::kTabStripLayoutType, | 371 prefs::kTabStripLayoutType, |
| 372 static_cast<int>(tabstrip_->layout_type())); | 372 static_cast<int>(tabstrip_->layout_type())); |
| 373 } | 373 } |
| 374 | 374 |
| 375 //////////////////////////////////////////////////////////////////////////////// | 375 //////////////////////////////////////////////////////////////////////////////// |
| 376 // BrowserTabStripController, TabStripModelObserver implementation: | 376 // BrowserTabStripController, TabStripModelObserver implementation: |
| 377 | 377 |
| 378 void BrowserTabStripController::TabInsertedAt(TabContentsWrapper* contents, | 378 void BrowserTabStripController::TabInsertedAt(TabContents* contents, |
| 379 int model_index, | 379 int model_index, |
| 380 bool is_active) { | 380 bool is_active) { |
| 381 DCHECK(contents); | 381 DCHECK(contents); |
| 382 DCHECK(model_->ContainsIndex(model_index)); | 382 DCHECK(model_->ContainsIndex(model_index)); |
| 383 AddTab(contents, model_index, is_active); | 383 AddTab(contents, model_index, is_active); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void BrowserTabStripController::TabDetachedAt(TabContentsWrapper* contents, | 386 void BrowserTabStripController::TabDetachedAt(TabContents* contents, |
| 387 int model_index) { | 387 int model_index) { |
| 388 // Cancel any pending tab transition. | 388 // Cancel any pending tab transition. |
| 389 hover_tab_selector_.CancelTabTransition(); | 389 hover_tab_selector_.CancelTabTransition(); |
| 390 | 390 |
| 391 tabstrip_->RemoveTabAt(model_index); | 391 tabstrip_->RemoveTabAt(model_index); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void BrowserTabStripController::TabSelectionChanged( | 394 void BrowserTabStripController::TabSelectionChanged( |
| 395 TabStripModel* tab_strip_model, | 395 TabStripModel* tab_strip_model, |
| 396 const TabStripSelectionModel& old_model) { | 396 const TabStripSelectionModel& old_model) { |
| 397 tabstrip_->SetSelection(old_model, model_->selection_model()); | 397 tabstrip_->SetSelection(old_model, model_->selection_model()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void BrowserTabStripController::TabMoved(TabContentsWrapper* contents, | 400 void BrowserTabStripController::TabMoved(TabContents* contents, |
| 401 int from_model_index, | 401 int from_model_index, |
| 402 int to_model_index) { | 402 int to_model_index) { |
| 403 // Cancel any pending tab transition. | 403 // Cancel any pending tab transition. |
| 404 hover_tab_selector_.CancelTabTransition(); | 404 hover_tab_selector_.CancelTabTransition(); |
| 405 | 405 |
| 406 // Pass in the TabRendererData as the pinned state may have changed. | 406 // Pass in the TabRendererData as the pinned state may have changed. |
| 407 TabRendererData data; | 407 TabRendererData data; |
| 408 SetTabRendererDataFromModel(contents->web_contents(), to_model_index, &data, | 408 SetTabRendererDataFromModel(contents->web_contents(), to_model_index, &data, |
| 409 EXISTING_TAB); | 409 EXISTING_TAB); |
| 410 tabstrip_->MoveTab(from_model_index, to_model_index, data); | 410 tabstrip_->MoveTab(from_model_index, to_model_index, data); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void BrowserTabStripController::TabChangedAt(TabContentsWrapper* contents, | 413 void BrowserTabStripController::TabChangedAt(TabContents* contents, |
| 414 int model_index, | 414 int model_index, |
| 415 TabChangeType change_type) { | 415 TabChangeType change_type) { |
| 416 if (change_type == TITLE_NOT_LOADING) { | 416 if (change_type == TITLE_NOT_LOADING) { |
| 417 tabstrip_->TabTitleChangedNotLoading(model_index); | 417 tabstrip_->TabTitleChangedNotLoading(model_index); |
| 418 // We'll receive another notification of the change asynchronously. | 418 // We'll receive another notification of the change asynchronously. |
| 419 return; | 419 return; |
| 420 } | 420 } |
| 421 | 421 |
| 422 SetTabDataAt(contents, model_index); | 422 SetTabDataAt(contents, model_index); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void BrowserTabStripController::TabReplacedAt(TabStripModel* tab_strip_model, | 425 void BrowserTabStripController::TabReplacedAt(TabStripModel* tab_strip_model, |
| 426 TabContentsWrapper* old_contents, | 426 TabContents* old_contents, |
| 427 TabContentsWrapper* new_contents, | 427 TabContents* new_contents, |
| 428 int model_index) { | 428 int model_index) { |
| 429 SetTabDataAt(new_contents, model_index); | 429 SetTabDataAt(new_contents, model_index); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void BrowserTabStripController::TabPinnedStateChanged( | 432 void BrowserTabStripController::TabPinnedStateChanged( |
| 433 TabContentsWrapper* contents, | 433 TabContents* contents, |
| 434 int model_index) { | 434 int model_index) { |
| 435 // Currently none of the renderers render pinned state differently. | 435 // Currently none of the renderers render pinned state differently. |
| 436 } | 436 } |
| 437 | 437 |
| 438 void BrowserTabStripController::TabMiniStateChanged( | 438 void BrowserTabStripController::TabMiniStateChanged( |
| 439 TabContentsWrapper* contents, | 439 TabContents* contents, |
| 440 int model_index) { | 440 int model_index) { |
| 441 SetTabDataAt(contents, model_index); | 441 SetTabDataAt(contents, model_index); |
| 442 } | 442 } |
| 443 | 443 |
| 444 void BrowserTabStripController::TabBlockedStateChanged( | 444 void BrowserTabStripController::TabBlockedStateChanged( |
| 445 TabContentsWrapper* contents, | 445 TabContents* contents, |
| 446 int model_index) { | 446 int model_index) { |
| 447 SetTabDataAt(contents, model_index); | 447 SetTabDataAt(contents, model_index); |
| 448 } | 448 } |
| 449 | 449 |
| 450 //////////////////////////////////////////////////////////////////////////////// | 450 //////////////////////////////////////////////////////////////////////////////// |
| 451 // BrowserTabStripController, content::NotificationObserver implementation: | 451 // BrowserTabStripController, content::NotificationObserver implementation: |
| 452 | 452 |
| 453 void BrowserTabStripController::Observe(int type, | 453 void BrowserTabStripController::Observe(int type, |
| 454 const content::NotificationSource& source, | 454 const content::NotificationSource& source, |
| 455 const content::NotificationDetails& details) { | 455 const content::NotificationDetails& details) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 476 break; | 476 break; |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 | 479 |
| 480 void BrowserTabStripController::SetTabRendererDataFromModel( | 480 void BrowserTabStripController::SetTabRendererDataFromModel( |
| 481 WebContents* contents, | 481 WebContents* contents, |
| 482 int model_index, | 482 int model_index, |
| 483 TabRendererData* data, | 483 TabRendererData* data, |
| 484 TabStatus tab_status) { | 484 TabStatus tab_status) { |
| 485 SkBitmap* app_icon = NULL; | 485 SkBitmap* app_icon = NULL; |
| 486 TabContentsWrapper* wrapper = | 486 TabContents* tab_contents = TabContents::FromWebContents(contents); |
| 487 TabContentsWrapper::GetCurrentWrapperForContents(contents); | |
| 488 | 487 |
| 489 // Extension App icons are slightly larger than favicons, so only allow | 488 // Extension App icons are slightly larger than favicons, so only allow |
| 490 // them if permitted by the model. | 489 // them if permitted by the model. |
| 491 if (model_->delegate()->LargeIconsPermitted()) | 490 if (model_->delegate()->LargeIconsPermitted()) |
| 492 app_icon = wrapper->extension_tab_helper()->GetExtensionAppIcon(); | 491 app_icon = tab_contents->extension_tab_helper()->GetExtensionAppIcon(); |
| 493 | 492 |
| 494 if (app_icon) | 493 if (app_icon) |
| 495 data->favicon = *app_icon; | 494 data->favicon = *app_icon; |
| 496 else | 495 else |
| 497 data->favicon = wrapper->favicon_tab_helper()->GetFavicon(); | 496 data->favicon = tab_contents->favicon_tab_helper()->GetFavicon(); |
| 498 data->network_state = TabContentsNetworkState(contents); | 497 data->network_state = TabContentsNetworkState(contents); |
| 499 data->title = contents->GetTitle(); | 498 data->title = contents->GetTitle(); |
| 500 data->url = contents->GetURL(); | 499 data->url = contents->GetURL(); |
| 501 data->loading = contents->IsLoading(); | 500 data->loading = contents->IsLoading(); |
| 502 data->crashed_status = contents->GetCrashedStatus(); | 501 data->crashed_status = contents->GetCrashedStatus(); |
| 503 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); | 502 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); |
| 504 data->show_icon = wrapper->favicon_tab_helper()->ShouldDisplayFavicon(); | 503 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); |
| 505 data->mini = model_->IsMiniTab(model_index); | 504 data->mini = model_->IsMiniTab(model_index); |
| 506 data->blocked = model_->IsTabBlocked(model_index); | 505 data->blocked = model_->IsTabBlocked(model_index); |
| 507 data->app = wrapper->extension_tab_helper()->is_app(); | 506 data->app = tab_contents->extension_tab_helper()->is_app(); |
| 508 } | 507 } |
| 509 | 508 |
| 510 void BrowserTabStripController::SetTabDataAt( | 509 void BrowserTabStripController::SetTabDataAt( |
| 511 TabContentsWrapper* contents, | 510 TabContents* contents, |
| 512 int model_index) { | 511 int model_index) { |
| 513 TabRendererData data; | 512 TabRendererData data; |
| 514 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, | 513 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, |
| 515 EXISTING_TAB); | 514 EXISTING_TAB); |
| 516 tabstrip_->SetTabData(model_index, data); | 515 tabstrip_->SetTabData(model_index, data); |
| 517 } | 516 } |
| 518 | 517 |
| 519 void BrowserTabStripController::StartHighlightTabsForCommand( | 518 void BrowserTabStripController::StartHighlightTabsForCommand( |
| 520 TabStripModel::ContextMenuCommand command_id, | 519 TabStripModel::ContextMenuCommand command_id, |
| 521 BaseTab* tab) { | 520 BaseTab* tab) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 536 void BrowserTabStripController::StopHighlightTabsForCommand( | 535 void BrowserTabStripController::StopHighlightTabsForCommand( |
| 537 TabStripModel::ContextMenuCommand command_id, | 536 TabStripModel::ContextMenuCommand command_id, |
| 538 BaseTab* tab) { | 537 BaseTab* tab) { |
| 539 if (command_id == TabStripModel::CommandCloseTabsToRight || | 538 if (command_id == TabStripModel::CommandCloseTabsToRight || |
| 540 command_id == TabStripModel::CommandCloseOtherTabs) { | 539 command_id == TabStripModel::CommandCloseOtherTabs) { |
| 541 // Just tell all Tabs to stop pulsing - it's safe. | 540 // Just tell all Tabs to stop pulsing - it's safe. |
| 542 tabstrip_->StopAllHighlighting(); | 541 tabstrip_->StopAllHighlighting(); |
| 543 } | 542 } |
| 544 } | 543 } |
| 545 | 544 |
| 546 void BrowserTabStripController::AddTab(TabContentsWrapper* contents, | 545 void BrowserTabStripController::AddTab(TabContents* contents, |
| 547 int index, | 546 int index, |
| 548 bool is_active) { | 547 bool is_active) { |
| 549 // Cancel any pending tab transition. | 548 // Cancel any pending tab transition. |
| 550 hover_tab_selector_.CancelTabTransition(); | 549 hover_tab_selector_.CancelTabTransition(); |
| 551 | 550 |
| 552 TabRendererData data; | 551 TabRendererData data; |
| 553 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); | 552 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); |
| 554 tabstrip_->AddTabAt(index, data, is_active); | 553 tabstrip_->AddTabAt(index, data, is_active); |
| 555 } | 554 } |
| 556 | 555 |
| 557 void BrowserTabStripController::UpdateLayoutType() { | 556 void BrowserTabStripController::UpdateLayoutType() { |
| 558 bool adjust_layout = false; | 557 bool adjust_layout = false; |
| 559 TabStripLayoutType layout_type = | 558 TabStripLayoutType layout_type = |
| 560 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); | 559 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); |
| 561 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 560 tabstrip_->SetLayoutType(layout_type, adjust_layout); |
| 562 } | 561 } |
| OLD | NEW |