| 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/search/search_delegate.h" | 5 #include "chrome/browser/ui/search/search_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/search/search_model.h" | 7 #include "chrome/browser/ui/search/search_model.h" |
| 8 #include "chrome/browser/ui/search/search_tab_helper.h" | 8 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 9 | 9 |
| 10 namespace chrome { | 10 namespace chrome { |
| 11 namespace search { | 11 namespace search { |
| 12 | 12 |
| 13 SearchDelegate::SearchDelegate(SearchModel* browser_search_model, | 13 SearchDelegate::SearchDelegate(SearchModel* browser_search_model, |
| 14 ToolbarModel* toolbar_model) | 14 ToolbarModel* toolbar_model) |
| 15 : browser_model_(browser_search_model), | 15 : browser_model_(browser_search_model), |
| 16 tab_model_() { | 16 tab_model_() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 SearchDelegate::~SearchDelegate() { | 19 SearchDelegate::~SearchDelegate() { |
| 20 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; | 20 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void SearchDelegate::ModeChanged(const Mode& old_mode, const Mode& new_mode) { | 23 void SearchDelegate::ModeChanged(const Mode& old_mode, const Mode& new_mode) { |
| 24 browser_model_->SetMode(new_mode); | 24 browser_model_->SetMode(new_mode); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void SearchDelegate::TopBarsVisibilityChanged(const Mode& mode, bool visible) { |
| 28 browser_model_->SetTopBarsVisible(visible); |
| 29 } |
| 30 |
| 27 void SearchDelegate::OnTabActivated(content::WebContents* web_contents) { | 31 void SearchDelegate::OnTabActivated(content::WebContents* web_contents) { |
| 28 if (tab_model_) | 32 if (tab_model_) |
| 29 tab_model_->RemoveObserver(this); | 33 tab_model_->RemoveObserver(this); |
| 30 tab_model_ = | 34 tab_model_ = |
| 31 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model(); | 35 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model(); |
| 32 browser_model_->SetMode(tab_model_->mode()); | 36 browser_model_->SetMode(tab_model_->mode()); |
| 37 browser_model_->SetTopBarsVisible(tab_model_->show_top_bars()); |
| 33 tab_model_->AddObserver(this); | 38 tab_model_->AddObserver(this); |
| 34 } | 39 } |
| 35 | 40 |
| 36 void SearchDelegate::OnTabDeactivated(content::WebContents* web_contents) { | 41 void SearchDelegate::OnTabDeactivated(content::WebContents* web_contents) { |
| 37 StopObservingTab(web_contents); | 42 StopObservingTab(web_contents); |
| 38 } | 43 } |
| 39 | 44 |
| 40 void SearchDelegate::OnTabDetached(content::WebContents* web_contents) { | 45 void SearchDelegate::OnTabDetached(content::WebContents* web_contents) { |
| 41 StopObservingTab(web_contents); | 46 StopObservingTab(web_contents); |
| 42 } | 47 } |
| 43 | 48 |
| 44 void SearchDelegate::StopObservingTab(content::WebContents* web_contents) { | 49 void SearchDelegate::StopObservingTab(content::WebContents* web_contents) { |
| 45 chrome::search::SearchTabHelper* search_tab_helper = | 50 chrome::search::SearchTabHelper* search_tab_helper = |
| 46 chrome::search::SearchTabHelper::FromWebContents(web_contents); | 51 chrome::search::SearchTabHelper::FromWebContents(web_contents); |
| 47 if (search_tab_helper->model() == tab_model_) { | 52 if (search_tab_helper->model() == tab_model_) { |
| 48 tab_model_->RemoveObserver(this); | 53 tab_model_->RemoveObserver(this); |
| 49 tab_model_ = NULL; | 54 tab_model_ = NULL; |
| 50 } | 55 } |
| 51 } | 56 } |
| 52 | 57 |
| 53 } // namespace search | 58 } // namespace search |
| 54 } // namespace chrome | 59 } // namespace chrome |
| OLD | NEW |