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(); | |
sky
2012/06/26 17:11:27
Might this happen when there is no active tab?
kuan
2012/06/26 23:25:49
Done.
| |
449 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index); | |
450 } | |
451 | |
452 //////////////////////////////////////////////////////////////////////////////// | |
453 // BrowserTabStripController, chrome::search::ToolbarSearchAnimator::Observer: | |
454 | |
455 void BrowserTabStripController::BackgroundChanging() { | |
456 // We're fading in the tab background, set tab data based on new background | |
457 // state and possibly opacity value, which will trigger repainting of tab's | |
458 // background. | |
459 int active_index = GetActiveIndex(); | |
460 DCHECK(active_index != -1); | |
461 if (active_index == -1) | |
462 return; | |
463 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index); | |
464 } | |
465 | |
466 void BrowserTabStripController::BackgroundChanged() { | |
467 // We've finished fading in the tab background, set tab data so that | |
468 // |TabRendererData::background_state| and | |
469 // |TabRendererData::new_background_opacity| will be reset, repainting | |
470 // of tab's background will be triggered in the process. | |
471 int active_index = GetActiveIndex(); | |
472 DCHECK(active_index != -1); | |
473 if (active_index == -1) | |
474 return; | |
475 SetTabDataAt(browser_->GetTabContentsAt(active_index), active_index); | |
476 } | |
477 | |
478 void BrowserTabStripController::BackgroundChangeCanceled( | |
479 TabContents* tab_contents) { | |
480 // Fade in of tab background has been canceled. | |
481 // If |tab_contents| is not NULL and tab strip model contains |tab_contents|, | |
482 // set tab data so that |TabRendererData::background_state| and | |
483 // |TabRendererData::new_background_opacity| will be reset; repainting | |
484 // of tab's background will be triggered in the process. | |
485 if (!tab_contents) | |
486 return; | |
487 int index = model_->GetIndexOfTabContents(tab_contents); | |
488 if (index == -1) | |
489 return; | |
490 SetTabDataAt(tab_contents, index); | |
491 } | |
492 | |
493 //////////////////////////////////////////////////////////////////////////////// | |
436 // BrowserTabStripController, content::NotificationObserver implementation: | 494 // BrowserTabStripController, content::NotificationObserver implementation: |
437 | 495 |
438 void BrowserTabStripController::Observe(int type, | 496 void BrowserTabStripController::Observe(int type, |
439 const content::NotificationSource& source, | 497 const content::NotificationSource& source, |
440 const content::NotificationDetails& details) { | 498 const content::NotificationDetails& details) { |
441 switch (type) { | 499 switch (type) { |
442 case chrome::NOTIFICATION_PREF_CHANGED: | 500 case chrome::NOTIFICATION_PREF_CHANGED: |
443 if (*content::Details<std::string>(details).ptr() == | 501 if (*content::Details<std::string>(details).ptr() == |
444 prefs::kTabStripLayoutType) { | 502 prefs::kTabStripLayoutType) { |
445 UpdateLayoutType(); | 503 UpdateLayoutType(); |
(...skipping 21 matching lines...) Expand all Loading... | |
467 data->network_state = TabContentsNetworkState(contents); | 525 data->network_state = TabContentsNetworkState(contents); |
468 data->title = contents->GetTitle(); | 526 data->title = contents->GetTitle(); |
469 data->url = contents->GetURL(); | 527 data->url = contents->GetURL(); |
470 data->loading = contents->IsLoading(); | 528 data->loading = contents->IsLoading(); |
471 data->crashed_status = contents->GetCrashedStatus(); | 529 data->crashed_status = contents->GetCrashedStatus(); |
472 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); | 530 data->incognito = contents->GetBrowserContext()->IsOffTheRecord(); |
473 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); | 531 data->show_icon = tab_contents->favicon_tab_helper()->ShouldDisplayFavicon(); |
474 data->mini = model_->IsMiniTab(model_index); | 532 data->mini = model_->IsMiniTab(model_index); |
475 data->blocked = model_->IsTabBlocked(model_index); | 533 data->blocked = model_->IsTabBlocked(model_index); |
476 data->app = tab_contents->extension_tab_helper()->is_app(); | 534 data->app = tab_contents->extension_tab_helper()->is_app(); |
535 data->search_enabled = | |
536 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()); | |
537 data->mode = browser_->search_model()->mode().mode; | |
538 if (data->mode == chrome::search::Mode::MODE_SEARCH) { | |
539 // Get current state of background animation to paint for SEARCH mode. | |
540 browser_->search_delegate()->toolbar_search_animator(). | |
541 GetCurrentBackgroundState(&data->background_state, | |
542 &data->new_background_opacity); | |
543 } else { | |
544 data->background_state = chrome::search::ToolbarSearchAnimator:: | |
545 BACKGROUND_STATE_SHOW_NON_APPLICABLE; | |
546 // Valid opacity value of int data type is 0 to 255, so use -1 to indicate | |
547 // an invalid value. | |
548 data->new_background_opacity = -1; | |
549 } | |
477 } | 550 } |
478 | 551 |
479 void BrowserTabStripController::SetTabDataAt( | 552 void BrowserTabStripController::SetTabDataAt( |
480 TabContents* contents, | 553 TabContents* contents, |
481 int model_index) { | 554 int model_index) { |
482 TabRendererData data; | 555 TabRendererData data; |
483 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, | 556 SetTabRendererDataFromModel(contents->web_contents(), model_index, &data, |
484 EXISTING_TAB); | 557 EXISTING_TAB); |
485 tabstrip_->SetTabData(model_index, data); | 558 tabstrip_->SetTabData(model_index, data); |
486 } | 559 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); | 595 SetTabRendererDataFromModel(contents->web_contents(), index, &data, NEW_TAB); |
523 tabstrip_->AddTabAt(index, data, is_active); | 596 tabstrip_->AddTabAt(index, data, is_active); |
524 } | 597 } |
525 | 598 |
526 void BrowserTabStripController::UpdateLayoutType() { | 599 void BrowserTabStripController::UpdateLayoutType() { |
527 bool adjust_layout = false; | 600 bool adjust_layout = false; |
528 TabStripLayoutType layout_type = | 601 TabStripLayoutType layout_type = |
529 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); | 602 DetermineTabStripLayout(g_browser_process->local_state(), &adjust_layout); |
530 tabstrip_->SetLayoutType(layout_type, adjust_layout); | 603 tabstrip_->SetLayoutType(layout_type, adjust_layout); |
531 } | 604 } |
OLD | NEW |