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() | 10 SearchModel::State::State() |
11 : top_bars_visible(true), | 11 : top_bars_visible(true), |
12 instant_support(INSTANT_SUPPORT_UNKNOWN) { | 12 instant_support(INSTANT_SUPPORT_UNKNOWN), |
| 13 voice_search_supported(false) { |
13 } | 14 } |
14 | 15 |
15 SearchModel::State::State(const SearchMode& mode, | 16 SearchModel::State::State(const SearchMode& mode, |
16 bool top_bars_visible, | 17 bool top_bars_visible, |
17 InstantSupportState instant_support) | 18 InstantSupportState instant_support, |
| 19 bool voice_search_supported) |
18 : mode(mode), | 20 : mode(mode), |
19 top_bars_visible(top_bars_visible), | 21 top_bars_visible(top_bars_visible), |
20 instant_support(instant_support) { | 22 instant_support(instant_support), |
| 23 voice_search_supported(voice_search_supported) { |
21 } | 24 } |
22 | 25 |
23 bool SearchModel::State::operator==(const State& rhs) const { | 26 bool SearchModel::State::operator==(const State& rhs) const { |
24 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible && | 27 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible && |
25 instant_support == rhs.instant_support; | 28 instant_support == rhs.instant_support && |
| 29 voice_search_supported == rhs.voice_search_supported; |
26 } | 30 } |
27 | 31 |
28 SearchModel::SearchModel() { | 32 SearchModel::SearchModel() { |
29 } | 33 } |
30 | 34 |
31 SearchModel::~SearchModel() { | 35 SearchModel::~SearchModel() { |
32 } | 36 } |
33 | 37 |
34 // static. | 38 // static. |
35 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state, | 39 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // top bars are always visible, if available. | 79 // top bars are always visible, if available. |
76 if (!state_.mode.is_search()) | 80 if (!state_.mode.is_search()) |
77 state_.top_bars_visible = true; | 81 state_.top_bars_visible = true; |
78 | 82 |
79 FOR_EACH_OBSERVER(SearchModelObserver, observers_, | 83 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
80 ModelChanged(old_state, state_)); | 84 ModelChanged(old_state, state_)); |
81 } | 85 } |
82 | 86 |
83 void SearchModel::SetTopBarsVisible(bool visible) { | 87 void SearchModel::SetTopBarsVisible(bool visible) { |
84 DCHECK(chrome::IsInstantExtendedAPIEnabled()) | 88 DCHECK(chrome::IsInstantExtendedAPIEnabled()) |
85 << "Please do not try to set the SearchModel mode without first " | 89 << "Please do not try to set the SearchModel state without first " |
86 << "checking if Search is enabled."; | 90 << "checking if Search is enabled."; |
87 | 91 |
88 if (state_.top_bars_visible == visible) | 92 if (state_.top_bars_visible == visible) |
89 return; | 93 return; |
90 | 94 |
91 const State old_state = state_; | 95 const State old_state = state_; |
92 state_.top_bars_visible = visible; | 96 state_.top_bars_visible = visible; |
93 | 97 |
94 FOR_EACH_OBSERVER(SearchModelObserver, observers_, | 98 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
95 ModelChanged(old_state, state_)); | 99 ModelChanged(old_state, state_)); |
96 } | 100 } |
97 | 101 |
98 void SearchModel::SetInstantSupportState(InstantSupportState instant_support) { | 102 void SearchModel::SetInstantSupportState(InstantSupportState instant_support) { |
99 DCHECK(chrome::IsInstantExtendedAPIEnabled()) | 103 DCHECK(chrome::IsInstantExtendedAPIEnabled()) |
100 << "Please do not try to set the SearchModel mode without first " | 104 << "Please do not try to set the SearchModel state without first " |
101 << "checking if Search is enabled."; | 105 << "checking if Search is enabled."; |
102 | 106 |
103 if (state_.instant_support == instant_support) | 107 if (state_.instant_support == instant_support) |
104 return; | 108 return; |
105 | 109 |
106 const State old_state = state_; | 110 const State old_state = state_; |
107 state_.instant_support = instant_support; | 111 state_.instant_support = instant_support; |
108 FOR_EACH_OBSERVER(SearchModelObserver, observers_, | 112 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
109 ModelChanged(old_state, state_)); | 113 ModelChanged(old_state, state_)); |
110 } | 114 } |
111 | 115 |
| 116 void SearchModel::SetVoiceSearchSupported(bool supported) { |
| 117 DCHECK(chrome::IsInstantExtendedAPIEnabled()) |
| 118 << "Please do not try to set the SearchModel state without first " |
| 119 << "checking if Search is enabled."; |
| 120 |
| 121 if (state_.voice_search_supported == supported) |
| 122 return; |
| 123 |
| 124 const State old_state = state_; |
| 125 state_.voice_search_supported = supported; |
| 126 |
| 127 FOR_EACH_OBSERVER(SearchModelObserver, observers_, |
| 128 ModelChanged(old_state, state_)); |
| 129 } |
| 130 |
112 void SearchModel::AddObserver(SearchModelObserver* observer) { | 131 void SearchModel::AddObserver(SearchModelObserver* observer) { |
113 observers_.AddObserver(observer); | 132 observers_.AddObserver(observer); |
114 } | 133 } |
115 | 134 |
116 void SearchModel::RemoveObserver(SearchModelObserver* observer) { | 135 void SearchModel::RemoveObserver(SearchModelObserver* observer) { |
117 observers_.RemoveObserver(observer); | 136 observers_.RemoveObserver(observer); |
118 } | 137 } |
OLD | NEW |