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

Side by Side Diff: chrome/browser/ui/search/search_model.cc

Issue 17132011: Add setVoiceSearchSupported to the searchbox API. This will be used to determine whether to show a … (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Respond and revert changes. Created 7 years, 6 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
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/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 voice_search_supported(false) {
13 }
14
15 SearchModel::State::State(const SearchMode& mode,
16 bool top_bars_visible,
17 bool voice_search_supported)
18 : mode(mode),
19 top_bars_visible(top_bars_visible),
20 voice_search_supported(voice_search_supported) {
21 }
22
23 bool SearchModel::State::operator==(const State& rhs) const {
24 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible &&
25 voice_search_supported == rhs.voice_search_supported;
26 }
27
28
10 SearchModel::SearchModel() { 29 SearchModel::SearchModel() {
11 } 30 }
12 31
13 SearchModel::~SearchModel() { 32 SearchModel::~SearchModel() {
14 } 33 }
15 34
16 // static. 35 // static.
17 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state, 36 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state,
18 const State& new_state) { 37 const State& new_state) {
19 // If mode has changed, only change top bars visibility if new mode is not 38 // If mode has changed, only change top bars visibility if new mode is not
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // top bars are always visible, if available. 76 // top bars are always visible, if available.
58 if (!state_.mode.is_search()) 77 if (!state_.mode.is_search())
59 state_.top_bars_visible = true; 78 state_.top_bars_visible = true;
60 79
61 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 80 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
62 ModelChanged(old_state, state_)); 81 ModelChanged(old_state, state_));
63 } 82 }
64 83
65 void SearchModel::SetTopBarsVisible(bool visible) { 84 void SearchModel::SetTopBarsVisible(bool visible) {
66 DCHECK(chrome::IsInstantExtendedAPIEnabled()) 85 DCHECK(chrome::IsInstantExtendedAPIEnabled())
67 << "Please do not try to set the SearchModel mode without first " 86 << "Please do not try to set the SearchModel state without first "
68 << "checking if Search is enabled."; 87 << "checking if Search is enabled.";
69 88
70 if (state_.top_bars_visible == visible) 89 if (state_.top_bars_visible == visible)
71 return; 90 return;
72 91
73 const State old_state = state_; 92 const State old_state = state_;
74 state_.top_bars_visible = visible; 93 state_.top_bars_visible = visible;
75 94
76 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 95 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
77 ModelChanged(old_state, state_)); 96 ModelChanged(old_state, state_));
78 } 97 }
79 98
99 void SearchModel::SetVoiceSearchSupported(bool supported) {
100 DCHECK(chrome::IsInstantExtendedAPIEnabled())
101 << "Please do not try to set the SearchModel state without first "
102 << "checking if Search is enabled.";
103
104 if (state_.voice_search_supported == supported)
105 return;
106
107 const State old_state = state_;
108 state_.voice_search_supported = supported;
109
110 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
111 ModelChanged(old_state, state_));
112 }
113
80 void SearchModel::AddObserver(SearchModelObserver* observer) { 114 void SearchModel::AddObserver(SearchModelObserver* observer) {
81 observers_.AddObserver(observer); 115 observers_.AddObserver(observer);
82 } 116 }
83 117
84 void SearchModel::RemoveObserver(SearchModelObserver* observer) { 118 void SearchModel::RemoveObserver(SearchModelObserver* observer) {
85 observers_.RemoveObserver(observer); 119 observers_.RemoveObserver(observer);
86 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698