| 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/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 void BrowserTabStripController::TabChangedAt(TabContents* contents, | 411 void BrowserTabStripController::TabChangedAt(TabContents* contents, |
| 412 int model_index, | 412 int model_index, |
| 413 TabChangeType change_type) { | 413 TabChangeType change_type) { |
| 414 if (change_type == TITLE_NOT_LOADING) { | 414 if (change_type == TITLE_NOT_LOADING) { |
| 415 tabstrip_->TabTitleChangedNotLoading(model_index); | 415 tabstrip_->TabTitleChangedNotLoading(model_index); |
| 416 // We'll receive another notification of the change asynchronously. | 416 // We'll receive another notification of the change asynchronously. |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 | 419 |
| 420 SetTabDataAt(contents, model_index); | 420 SetTabDataAt(contents->web_contents(), model_index); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void BrowserTabStripController::TabReplacedAt(TabStripModel* tab_strip_model, | 423 void BrowserTabStripController::TabReplacedAt(TabStripModel* tab_strip_model, |
| 424 TabContents* old_contents, | 424 TabContents* old_contents, |
| 425 TabContents* new_contents, | 425 TabContents* new_contents, |
| 426 int model_index) { | 426 int model_index) { |
| 427 SetTabDataAt(new_contents, model_index); | 427 SetTabDataAt(new_contents->web_contents(), model_index); |
| 428 } | 428 } |
| 429 | 429 |
| 430 void BrowserTabStripController::TabPinnedStateChanged( | 430 void BrowserTabStripController::TabPinnedStateChanged( |
| 431 TabContents* contents, | 431 TabContents* contents, |
| 432 int model_index) { | 432 int model_index) { |
| 433 // Currently none of the renderers render pinned state differently. | 433 // Currently none of the renderers render pinned state differently. |
| 434 } | 434 } |
| 435 | 435 |
| 436 void BrowserTabStripController::TabMiniStateChanged( | 436 void BrowserTabStripController::TabMiniStateChanged(TabContents* contents, |
| 437 TabContents* contents, | 437 int model_index) { |
| 438 int model_index) { | 438 SetTabDataAt(contents->web_contents(), model_index); |
| 439 SetTabDataAt(contents, model_index); | |
| 440 } | 439 } |
| 441 | 440 |
| 442 void BrowserTabStripController::TabBlockedStateChanged( | 441 void BrowserTabStripController::TabBlockedStateChanged(TabContents* contents, |
| 443 TabContents* contents, | 442 int model_index) { |
| 444 int model_index) { | 443 SetTabDataAt(contents->web_contents(), model_index); |
| 445 SetTabDataAt(contents, model_index); | |
| 446 } | 444 } |
| 447 | 445 |
| 448 //////////////////////////////////////////////////////////////////////////////// | 446 //////////////////////////////////////////////////////////////////////////////// |
| 449 // BrowserTabStripController, chrome::search::SearchModelObserver: | 447 // BrowserTabStripController, chrome::search::SearchModelObserver: |
| 450 | 448 |
| 451 void BrowserTabStripController::ModeChanged( | 449 void BrowserTabStripController::ModeChanged( |
| 452 const chrome::search::Mode& old_mode, | 450 const chrome::search::Mode& old_mode, |
| 453 const chrome::search::Mode& new_mode) { | 451 const chrome::search::Mode& new_mode) { |
| 454 // Mode has changed, set tab data based on new mode, which will trigger | 452 // Mode has changed, set tab data based on new mode, which will trigger |
| 455 // repainting of tab's background. | 453 // repainting of tab's background. |
| 456 int active_index = GetActiveIndex(); | 454 int active_index = GetActiveIndex(); |
| 457 DCHECK_NE(active_index, -1); | 455 DCHECK_NE(active_index, -1); |
| 458 SetTabDataAt(chrome::GetTabContentsAt(browser_, active_index), active_index); | 456 SetTabDataAt(chrome::GetWebContentsAt(browser_, active_index), active_index); |
| 459 } | 457 } |
| 460 | 458 |
| 461 //////////////////////////////////////////////////////////////////////////////// | 459 //////////////////////////////////////////////////////////////////////////////// |
| 462 // BrowserTabStripController, chrome::search::ToolbarSearchAnimator::Observer: | 460 // BrowserTabStripController, chrome::search::ToolbarSearchAnimator::Observer: |
| 463 | 461 |
| 464 void BrowserTabStripController::OnToolbarBackgroundAnimatorProgressed() { | 462 void BrowserTabStripController::OnToolbarBackgroundAnimatorProgressed() { |
| 465 // We're fading in the tab background, set tab data based on new background | 463 // We're fading in the tab background, set tab data based on new background |
| 466 // state and possibly opacity value, which will trigger repainting of tab's | 464 // state and possibly opacity value, which will trigger repainting of tab's |
| 467 // background. | 465 // background. |
| 468 int active_index = GetActiveIndex(); | 466 int active_index = GetActiveIndex(); |
| 469 DCHECK_NE(active_index, -1); | 467 DCHECK_NE(active_index, -1); |
| 470 SetTabDataAt(chrome::GetTabContentsAt(browser_, active_index), active_index); | 468 SetTabDataAt(chrome::GetWebContentsAt(browser_, active_index), active_index); |
| 471 } | 469 } |
| 472 | 470 |
| 473 void BrowserTabStripController::OnToolbarBackgroundAnimatorCanceled( | 471 void BrowserTabStripController::OnToolbarBackgroundAnimatorCanceled( |
| 474 TabContents* tab_contents) { | 472 content::WebContents* web_contents) { |
| 475 // Fade in of tab background has been canceled, which can happen in 2 | 473 // Fade in of tab background has been canceled, which can happen in 2 |
| 476 // scenarios: | 474 // scenarios: |
| 477 // 1) a deactivated or detached or closing tab, whose |tab_contents| is the | 475 // 1) a deactivated or detached or closing tab, whose |tab_contents| is the |
| 478 // the formal parameter: make sure |tab_contents| still exist in tab model. | 476 // the formal parameter: make sure |tab_contents| still exist in tab model. |
| 479 // 2) mode change of active tab, as indicated by a NULL |tab_contents|: make | 477 // 2) mode change of active tab, as indicated by a NULL |tab_contents|: make |
| 480 // sure active tab exists, and retrieve its |tab_contents|. | 478 // sure active tab exists, and retrieve its |tab_contents|. |
| 481 // If we proceed, set tab data so that | 479 // If we proceed, set tab data so that |
| 482 // |TabRendererData::gradient_background_opacity| will be reset. | 480 // |TabRendererData::gradient_background_opacity| will be reset. |
| 483 // Repainting of tab's background will be triggered in the process. | 481 // Repainting of tab's background will be triggered in the process. |
| 484 int index = tab_contents ? model_->GetIndexOfTabContents(tab_contents) : | 482 int index = web_contents ? model_->GetIndexOfWebContents(web_contents) : |
| 485 GetActiveIndex(); | 483 GetActiveIndex(); |
| 486 if (index == -1) | 484 if (index == -1) |
| 487 return; | 485 return; |
| 488 SetTabDataAt(tab_contents ? tab_contents : | 486 SetTabDataAt(web_contents ? web_contents : |
| 489 chrome::GetTabContentsAt(browser_, index), index); | 487 chrome::GetWebContentsAt(browser_, index), index); |
| 490 } | 488 } |
| 491 | 489 |
| 492 //////////////////////////////////////////////////////////////////////////////// | 490 //////////////////////////////////////////////////////////////////////////////// |
| 493 // BrowserTabStripController, content::NotificationObserver implementation: | 491 // BrowserTabStripController, content::NotificationObserver implementation: |
| 494 | 492 |
| 495 void BrowserTabStripController::Observe(int type, | 493 void BrowserTabStripController::Observe(int type, |
| 496 const content::NotificationSource& source, | 494 const content::NotificationSource& source, |
| 497 const content::NotificationDetails& details) { | 495 const content::NotificationDetails& details) { |
| 498 switch (type) { | 496 switch (type) { |
| 499 case chrome::NOTIFICATION_PREF_CHANGED: | 497 case chrome::NOTIFICATION_PREF_CHANGED: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 527 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); | 525 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); |
| 528 data->mini = model_->IsMiniTab(model_index); | 526 data->mini = model_->IsMiniTab(model_index); |
| 529 data->blocked = model_->IsTabBlocked(model_index); | 527 data->blocked = model_->IsTabBlocked(model_index); |
| 530 data->app = extensions::TabHelper::FromWebContents(contents)->is_app(); | 528 data->app = extensions::TabHelper::FromWebContents(contents)->is_app(); |
| 531 data->mode = browser_->search_model()->mode().mode; | 529 data->mode = browser_->search_model()->mode().mode; |
| 532 // Get current gradient background animation to paint. | 530 // Get current gradient background animation to paint. |
| 533 data->gradient_background_opacity = browser_->search_delegate()-> | 531 data->gradient_background_opacity = browser_->search_delegate()-> |
| 534 toolbar_search_animator().GetGradientOpacity(); | 532 toolbar_search_animator().GetGradientOpacity(); |
| 535 } | 533 } |
| 536 | 534 |
| 537 void BrowserTabStripController::SetTabDataAt( | 535 void BrowserTabStripController::SetTabDataAt(content::WebContents* web_contents, |
| 538 TabContents* contents, | 536 int model_index) { |
| 539 int model_index) { | |
| 540 TabRendererData data; | 537 TabRendererData data; |
| 541 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, | 538 SetTabRendererDataFromModel(web_contents, model_index, &data, EXISTING_TAB); |
| 542 EXISTING_TAB); | |
| 543 tabstrip_->SetTabData(model_index, data); | 539 tabstrip_->SetTabData(model_index, data); |
| 544 } | 540 } |
| 545 | 541 |
| 546 void BrowserTabStripController::StartHighlightTabsForCommand( | 542 void BrowserTabStripController::StartHighlightTabsForCommand( |
| 547 TabStripModel::ContextMenuCommand command_id, | 543 TabStripModel::ContextMenuCommand command_id, |
| 548 BaseTab* tab) { | 544 BaseTab* tab) { |
| 549 if (command_id == TabStripModel::CommandCloseOtherTabs || | 545 if (command_id == TabStripModel::CommandCloseOtherTabs || |
| 550 command_id == TabStripModel::CommandCloseTabsToRight) { | 546 command_id == TabStripModel::CommandCloseTabsToRight) { |
| 551 int model_index = tabstrip_->GetModelIndexOfBaseTab(tab); | 547 int model_index = tabstrip_->GetModelIndexOfBaseTab(tab); |
| 552 if (IsValidIndex(model_index)) { | 548 if (IsValidIndex(model_index)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 580 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); | 576 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); |
| 581 tabstrip_->AddTabAt(index, data, is_active); | 577 tabstrip_->AddTabAt(index, data, is_active); |
| 582 } | 578 } |
| 583 | 579 |
| 584 void BrowserTabStripController::UpdateLayoutType() { | 580 void BrowserTabStripController::UpdateLayoutType() { |
| 585 bool adjust_layout = false; | 581 bool adjust_layout = false; |
| 586 TabStripLayoutType layout_type = | 582 TabStripLayoutType layout_type = |
| 587 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); | 583 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); |
| 588 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 584 tabstrip_->SetLayoutType(layout_type, adjust_layout); |
| 589 } | 585 } |
| OLD | NEW |