Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc

Issue 10662032: alternate ntp (cros/partial-win): add tab-related stuff and toolbar/tab background change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed scott's comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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_NE(active_index, -1);
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_NE(active_index, -1);
462 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index);
463 }
464
465 void BrowserTabStripController::OnToolbarBackgroundAnimatorCanceled(
466 TabContents* tab_contents) {
467 // Fade in of tab background has been canceled, which can happen in 2
468 // scenarios:
469 // 1) a deactivated or detached or closing tab, whose |tab_contents| is the
470 // the formal parameter: make sure |tab_contents| still exist in tab model.
471 // 2) mode change of active tab, as indicated by a NULL |tab_contents|: make
472 // sure active tab exists, and retrieve its |tab_contents|.
473 // If we proceed, set tab data so that |TabRendererData::background_state| and
474 // |TabRendererData::search_background_opacity| will be reset.
475 // Repainting of tab's background will be triggered in the process.
476 int index = tab_contents ? model_->GetIndexOfTabContents(tab_contents) :
477 GetActiveIndex();
478 if (index == -1)
479 return;
480 SetTabDataAt(tab_contents ? tab_contents : browser_->GetTabContentsAt(index),
481 index);
482 }
483
484 ////////////////////////////////////////////////////////////////////////////////
436 // BrowserTabStripController, content::NotificationObserver implementation: 485 // BrowserTabStripController, content::NotificationObserver implementation:
437 486
438 void BrowserTabStripController::Observe(int type, 487 void BrowserTabStripController::Observe(int type,
439 const content::NotificationSource& source, 488 const content::NotificationSource& source,
440 const content::NotificationDetails& details) { 489 const content::NotificationDetails& details) {
441 switch (type) { 490 switch (type) {
442 case chrome::NOTIFICATION_PREF_CHANGED: 491 case chrome::NOTIFICATION_PREF_CHANGED:
443 if (*content::Details<std::string>(details).ptr() == 492 if (*content::Details<std::string>(details).ptr() ==
444 prefs::kTabStripLayoutType) { 493 prefs::kTabStripLayoutType) {
445 UpdateLayoutType(); 494 UpdateLayoutType();
(...skipping 21 matching lines...) Expand all
467 data->network_state = TabContentsNetworkState(contents); 516 data->network_state = TabContentsNetworkState(contents);
468 data->title = contents->GetTitle(); 517 data->title = contents->GetTitle();
469 data->url = contents->GetURL(); 518 data->url = contents->GetURL();
470 data->loading = contents->IsLoading(); 519 data->loading = contents->IsLoading();
471 data->crashed_status = contents->GetCrashedStatus(); 520 data->crashed_status = contents->GetCrashedStatus();
472 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); 521 data->incognito = contents->GetBrowserContext()->IsOffTheRecord();
473 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); 522 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon();
474 data->mini = model_->IsMiniTab(model_index); 523 data->mini = model_->IsMiniTab(model_index);
475 data->blocked = model_->IsTabBlocked(model_index); 524 data->blocked = model_->IsTabBlocked(model_index);
476 data->app = tab_contents->extension_tab_helper()->is_app(); 525 data->app = tab_contents->extension_tab_helper()->is_app();
526 data->mode = browser_->search_model()->mode().mode;
527 if (data->mode == chrome::search::Mode::MODE_SEARCH) {
528 // Get current state of background animation to paint for SEARCH mode.
529 browser_->search_delegate()->toolbar_search_animator().
530 GetCurrentBackgroundState(&data->background_state,
531 &data->search_background_opacity);
532 } else {
533 data->background_state =
534 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_DEFAULT;
535 // Valid opacity value of double data type is 0f to 1f, so use -1f to
536 // indicate an invalid value.
537 data->search_background_opacity = -1.0f;
538 }
477 } 539 }
478 540
479 void BrowserTabStripController::SetTabDataAt( 541 void BrowserTabStripController::SetTabDataAt(
480 TabContents* contents, 542 TabContents* contents,
481 int model_index) { 543 int model_index) {
482 TabRendererData data; 544 TabRendererData data;
483 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, 545 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data,
484 EXISTING_TAB); 546 EXISTING_TAB);
485 tabstrip_->SetTabData(model_index, data); 547 tabstrip_->SetTabData(model_index, data);
486 } 548 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); 584 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB);
523 tabstrip_->AddTabAt(index, data, is_active); 585 tabstrip_->AddTabAt(index, data, is_active);
524 } 586 }
525 587
526 void BrowserTabStripController::UpdateLayoutType() { 588 void BrowserTabStripController::UpdateLayoutType() {
527 bool adjust_layout = false; 589 bool adjust_layout = false;
528 TabStripLayoutType layout_type = 590 TabStripLayoutType layout_type =
529 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); 591 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout);
530 tabstrip_->SetLayoutType(layout_type, adjust_layout); 592 tabstrip_->SetLayoutType(layout_type, adjust_layout);
531 } 593 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/browser_tab_strip_controller.h ('k') | chrome/browser/ui/views/tabs/tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698