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_model.h" | 5 #include "chrome/browser/ui/search/search_model.h" |
6 | 6 |
7 #include "chrome/browser/search/search.h" | 7 #include "chrome/browser/search/search.h" |
8 #include "chrome/browser/ui/search/search_model_observer.h" | 8 #include "chrome/browser/ui/search/search_model_observer.h" |
9 | 9 |
| 10 SearchModel::State::State() |
| 11 : top_bars_visible(true), |
| 12 instant_support(INSTANT_SUPPORT_UNKNOWN) { |
| 13 } |
| 14 |
| 15 SearchModel::State::State(const SearchMode& mode, |
| 16 bool top_bars_visible, |
| 17 InstantSupportState instant_support) |
| 18 : mode(mode), |
| 19 top_bars_visible(top_bars_visible), |
| 20 instant_support(instant_support) { |
| 21 } |
| 22 |
| 23 bool SearchModel::State::operator==(const State& rhs) const { |
| 24 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible && |
| 25 instant_support == rhs.instant_support; |
| 26 } |
| 27 |
10 SearchModel::SearchModel() { | 28 SearchModel::SearchModel() { |
11 } | 29 } |
12 | 30 |
13 SearchModel::~SearchModel() { | 31 SearchModel::~SearchModel() { |
14 } | 32 } |
15 | 33 |
16 // static. | 34 // static. |
17 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state, | 35 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state, |
18 const State& new_state) { | 36 const State& new_state) { |
19 // If mode has changed, only change top bars visibility if new mode is not | 37 // If mode has changed, only change top bars visibility if new mode is not |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (state_.top_bars_visible == visible) | 88 if (state_.top_bars_visible == visible) |
71 return; | 89 return; |
72 | 90 |
73 const State old_state = state_; | 91 const State old_state = state_; |
74 state_.top_bars_visible = visible; | 92 state_.top_bars_visible = visible; |
75 | 93 |
76 FOR_EACH_OBSERVER(SearchModelObserver, observers_, | 94 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
77 ModelChanged(old_state, state_)); | 95 ModelChanged(old_state, state_)); |
78 } | 96 } |
79 | 97 |
| 98 void SearchModel::SetSupportsInstant(bool supports_instant) { |
| 99 DCHECK(chrome::IsInstantExtendedAPIEnabled()) |
| 100 << "Please do not try to set the SearchModel mode without first " |
| 101 << "checking if Search is enabled."; |
| 102 |
| 103 InstantSupportState new_instant_support = supports_instant ? |
| 104 INSTANT_SUPPORT_YES : INSTANT_SUPPORT_NO; |
| 105 |
| 106 if (state_.instant_support == new_instant_support) |
| 107 return; |
| 108 |
| 109 const State old_state = state_; |
| 110 state_.instant_support = new_instant_support; |
| 111 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
| 112 ModelChanged(old_state, state_)); |
| 113 } |
| 114 |
80 void SearchModel::AddObserver(SearchModelObserver* observer) { | 115 void SearchModel::AddObserver(SearchModelObserver* observer) { |
81 observers_.AddObserver(observer); | 116 observers_.AddObserver(observer); |
82 } | 117 } |
83 | 118 |
84 void SearchModel::RemoveObserver(SearchModelObserver* observer) { | 119 void SearchModel::RemoveObserver(SearchModelObserver* observer) { |
85 observers_.RemoveObserver(observer); | 120 observers_.RemoveObserver(observer); |
86 } | 121 } |
OLD | NEW |