Chromium Code Reviews| 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/search/search.h" | |
| 16 #include "chrome/browser/ui/search/search_delegate.h" | |
| 17 #include "chrome/browser/ui/search/search_model.h" | |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 19 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h" |
| 19 #include "chrome/browser/ui/views/tabs/tab.h" | 22 #include "chrome/browser/ui/views/tabs/tab.h" |
| 20 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 23 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 24 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
| 160 // BrowserTabStripController, public: | 163 // BrowserTabStripController, public: |
| 161 | 164 |
| 162 BrowserTabStripController::BrowserTabStripController(Browser* browser, | 165 BrowserTabStripController::BrowserTabStripController(Browser* browser, |
| 163 TabStripModel* model) | 166 TabStripModel* model) |
| 164 : model_(model), | 167 : model_(model), |
| 165 tabstrip_(NULL), | 168 tabstrip_(NULL), |
| 166 browser_(browser), | 169 browser_(browser), |
| 167 hover_tab_selector_(model) { | 170 hover_tab_selector_(model) { |
| 168 model_->AddObserver(this); | 171 model_->AddObserver(this); |
| 172 browser_->search_model()->AddObserver(this); | |
| 173 browser_->search_delegate()->toolbar_search_animator().AddObserver(this); | |
| 169 | 174 |
| 170 local_pref_registrar_.Init(g_browser_process->local_state()); | 175 local_pref_registrar_.Init(g_browser_process->local_state()); |
| 171 local_pref_registrar_.Add(prefs::kTabStripLayoutType, this); | 176 local_pref_registrar_.Add(prefs::kTabStripLayoutType, this); |
| 172 } | 177 } |
| 173 | 178 |
| 174 BrowserTabStripController::~BrowserTabStripController() { | 179 BrowserTabStripController::~BrowserTabStripController() { |
| 175 // When we get here the TabStrip is being deleted. We need to explicitly | 180 // When we get here the TabStrip is being deleted. We need to explicitly |
| 176 // cancel the menu, otherwise it may try to invoke something on the tabstrip | 181 // cancel the menu, otherwise it may try to invoke something on the tabstrip |
| 177 // from its destructor. | 182 // from its destructor. |
| 178 if (context_menu_contents_.get()) | 183 if (context_menu_contents_.get()) |
| 179 context_menu_contents_->Cancel(); | 184 context_menu_contents_->Cancel(); |
| 180 | 185 |
| 181 model_->RemoveObserver(this); | 186 model_->RemoveObserver(this); |
| 187 browser_->search_delegate()->toolbar_search_animator().RemoveObserver(this); | |
| 188 browser_->search_model()->RemoveObserver(this); | |
| 182 } | 189 } |
| 183 | 190 |
| 184 void BrowserTabStripController::InitFromModel(TabStrip* tabstrip) { | 191 void BrowserTabStripController::InitFromModel(TabStrip* tabstrip) { |
| 185 tabstrip_ = tabstrip; | 192 tabstrip_ = tabstrip; |
| 186 | 193 |
| 187 UpdateLayoutType(); | 194 UpdateLayoutType(); |
| 188 | 195 |
| 189 // Walk the model, calling our insertion observer method for each item within | 196 // Walk the model, calling our insertion observer method for each item within |
| 190 // it. | 197 // it. |
| 191 for (int i = 0; i < model_->count(); ++i) | 198 for (int i = 0; i < model_->count(); ++i) |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 SetTabDataAt(contents, model_index); | 433 SetTabDataAt(contents, model_index); |
| 427 } | 434 } |
| 428 | 435 |
| 429 void BrowserTabStripController::TabBlockedStateChanged( | 436 void BrowserTabStripController::TabBlockedStateChanged( |
| 430 TabContents* contents, | 437 TabContents* contents, |
| 431 int model_index) { | 438 int model_index) { |
| 432 SetTabDataAt(contents, model_index); | 439 SetTabDataAt(contents, model_index); |
| 433 } | 440 } |
| 434 | 441 |
| 435 //////////////////////////////////////////////////////////////////////////////// | 442 //////////////////////////////////////////////////////////////////////////////// |
| 443 // BrowserTabStripController, chrome::search::SearchModelObserver: | |
| 444 | |
| 445 void BrowserTabStripController::ModeChanged(const chrome::search::Mode& mode) { | |
| 446 // Mode has changed, set tab data based on new mode, which will trigger | |
| 447 // repainting of tab's background. | |
| 448 int active_index = GetActiveIndex(); | |
| 449 DCHECK(active_index != -1); | |
|
sky
2012/06/27 21:23:47
DCHECK_NE
kuan
2012/06/27 21:31:39
Done.
| |
| 450 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index); | |
| 451 } | |
| 452 | |
| 453 //////////////////////////////////////////////////////////////////////////////// | |
| 454 // BrowserTabStripController, chrome::search::ToolbarSearchAnimator::Observer: | |
| 455 | |
| 456 void BrowserTabStripController::OnToolbarBackgroundAnimatorProgressed() { | |
| 457 // We're fading in the tab background, set tab data based on new background | |
| 458 // state and possibly opacity value, which will trigger repainting of tab's | |
| 459 // background. | |
| 460 int active_index = GetActiveIndex(); | |
| 461 DCHECK(active_index != -1); | |
|
sky
2012/06/27 21:23:47
DCHECK_NE
kuan
2012/06/27 21:31:39
Done.
| |
| 462 if (active_index == -1) | |
|
sky
2012/06/27 21:23:47
As discussed, remove this.
kuan
2012/06/27 21:31:39
Done.
| |
| 463 return; | |
| 464 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index); | |
| 465 } | |
| 466 | |
| 467 void BrowserTabStripController::OnToolbarBackgroundAnimatorCanceled( | |
| 468 TabContents* tab_contents) { | |
| 469 // Fade in of tab background has been canceled, which can happen in 2 | |
| 470 // scenarios: | |
| 471 // 1) a deactivated or detached or closing tab, whose |tab_contents| is the | |
| 472 // the formal parameter: make sure |tab_contents| still exist in tab model. | |
| 473 // 2) mode change of active tab, as indicated by a NULL |tab_contents|: make | |
| 474 // sure active tab exists, and retrieve its |tab_contents|. | |
| 475 // If we proceed, set tab data so that |TabRendererData::background_state| and | |
| 476 // |TabRendererData::search_background_opacity| will be reset. | |
| 477 // Repainting of tab's background will be triggered in the process. | |
| 478 int index = tab_contents ? model_->GetIndexOfTabContents(tab_contents) : | |
| 479 GetActiveIndex(); | |
| 480 if (index == -1) | |
| 481 return; | |
| 482 SetTabDataAt(tab_contents ? tab_contents : browser_->GetTabContentsAt(index), | |
| 483 index); | |
| 484 } | |
| 485 | |
| 486 //////////////////////////////////////////////////////////////////////////////// | |
| 436 // BrowserTabStripController, content::NotificationObserver implementation: | 487 // BrowserTabStripController, content::NotificationObserver implementation: |
| 437 | 488 |
| 438 void BrowserTabStripController::Observe(int type, | 489 void BrowserTabStripController::Observe(int type, |
| 439 const content::NotificationSource& source, | 490 const content::NotificationSource& source, |
| 440 const content::NotificationDetails& details) { | 491 const content::NotificationDetails& details) { |
| 441 switch (type) { | 492 switch (type) { |
| 442 case chrome::NOTIFICATION_PREF_CHANGED: | 493 case chrome::NOTIFICATION_PREF_CHANGED: |
| 443 if (*content::Details<std::string>(details).ptr() == | 494 if (*content::Details<std::string>(details).ptr() == |
| 444 prefs::kTabStripLayoutType) { | 495 prefs::kTabStripLayoutType) { |
| 445 UpdateLayoutType(); | 496 UpdateLayoutType(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 467 data->network_state = TabContentsNetworkState(contents); | 518 data->network_state = TabContentsNetworkState(contents); |
| 468 data->title = contents->GetTitle(); | 519 data->title = contents->GetTitle(); |
| 469 data->url = contents->GetURL(); | 520 data->url = contents->GetURL(); |
| 470 data->loading = contents->IsLoading(); | 521 data->loading = contents->IsLoading(); |
| 471 data->crashed_status = contents->GetCrashedStatus(); | 522 data->crashed_status = contents->GetCrashedStatus(); |
| 472 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); | 523 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); |
| 473 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); | 524 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); |
| 474 data->mini = model_->IsMiniTab(model_index); | 525 data->mini = model_->IsMiniTab(model_index); |
| 475 data->blocked = model_->IsTabBlocked(model_index); | 526 data->blocked = model_->IsTabBlocked(model_index); |
| 476 data->app = tab_contents->extension_tab_helper()->is_app(); | 527 data->app = tab_contents->extension_tab_helper()->is_app(); |
| 528 data->mode = browser_->search_model()->mode().mode; | |
| 529 if (data->mode == chrome::search::Mode::MODE_SEARCH) { | |
| 530 // Get current state of background animation to paint for SEARCH mode. | |
| 531 browser_->search_delegate()->toolbar_search_animator(). | |
| 532 GetCurrentBackgroundState(&data->background_state, | |
| 533 &data->search_background_opacity); | |
| 534 } else { | |
| 535 data->background_state = | |
| 536 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_DEFAULT; | |
| 537 // Valid opacity value of double data type is 0f to 1f, so use -1f to | |
| 538 // indicate an invalid value. | |
| 539 data->search_background_opacity = -1.0f; | |
| 540 } | |
| 477 } | 541 } |
| 478 | 542 |
| 479 void BrowserTabStripController::SetTabDataAt( | 543 void BrowserTabStripController::SetTabDataAt( |
| 480 TabContents* contents, | 544 TabContents* contents, |
| 481 int model_index) { | 545 int model_index) { |
| 482 TabRendererData data; | 546 TabRendererData data; |
| 483 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, | 547 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, |
| 484 EXISTING_TAB); | 548 EXISTING_TAB); |
| 485 tabstrip_->SetTabData(model_index, data); | 549 tabstrip_->SetTabData(model_index, data); |
| 486 } | 550 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); | 586 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); |
| 523 tabstrip_->AddTabAt(index, data, is_active); | 587 tabstrip_->AddTabAt(index, data, is_active); |
| 524 } | 588 } |
| 525 | 589 |
| 526 void BrowserTabStripController::UpdateLayoutType() { | 590 void BrowserTabStripController::UpdateLayoutType() { |
| 527 bool adjust_layout = false; | 591 bool adjust_layout = false; |
| 528 TabStripLayoutType layout_type = | 592 TabStripLayoutType layout_type = |
| 529 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); | 593 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); |
| 530 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 594 tabstrip_->SetLayoutType(layout_type, adjust_layout); |
| 531 } | 595 } |
| OLD | NEW |