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 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ |
6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "chrome/common/search_types.h" | 10 #include "chrome/common/search_types.h" |
11 | 11 |
12 class SearchModelObserver; | 12 class SearchModelObserver; |
13 | 13 |
14 // An observable model for UI components that care about search model state | 14 // An observable model for UI components that care about search model state |
15 // changes. | 15 // changes. |
16 class SearchModel { | 16 class SearchModel { |
17 public: | 17 public: |
18 struct State { | 18 struct State { |
19 State() : top_bars_visible(true) {} | 19 State(); |
20 State(const SearchMode& mode, bool top_bars_visible) | 20 State(const SearchMode& mode, |
21 : mode(mode), | 21 bool top_bars_visible, |
22 top_bars_visible(top_bars_visible) {} | 22 bool voice_search_supported); |
23 | 23 |
24 bool operator==(const State& rhs) const { | 24 bool operator==(const State& rhs) const; |
25 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible; | |
26 } | |
27 | 25 |
28 // The display mode of UI elements such as the toolbar, the tab strip, etc. | 26 // The display mode of UI elements such as the toolbar, the tab strip, etc. |
29 SearchMode mode; | 27 SearchMode mode; |
30 | 28 |
31 // The visibility of top bars such as bookmark and info bars. | 29 // The visibility of top bars such as bookmark and info bars. |
32 bool top_bars_visible; | 30 bool top_bars_visible; |
| 31 |
| 32 // Whether the page supports voice search. |
| 33 bool voice_search_supported; |
33 }; | 34 }; |
34 | 35 |
35 SearchModel(); | 36 SearchModel(); |
36 ~SearchModel(); | 37 ~SearchModel(); |
37 | 38 |
38 // Returns true if visibility in top bars should be changed based on | 39 // Returns true if visibility in top bars should be changed based on |
39 // |old_state| and |new_state|. | 40 // |old_state| and |new_state|. |
40 static bool ShouldChangeTopBarsVisibility(const State& old_state, | 41 static bool ShouldChangeTopBarsVisibility(const State& old_state, |
41 const State& new_state); | 42 const State& new_state); |
42 | 43 |
43 // Change the state. Change notifications are sent to observers. | 44 // Change the state. Change notifications are sent to observers. |
44 void SetState(const State& state); | 45 void SetState(const State& state); |
45 | 46 |
46 // Get the current state. | 47 // Get the current state. |
47 const State& state() const { return state_; } | 48 const State& state() const { return state_; } |
48 | 49 |
49 // Change the mode. Change notifications are sent to observers. | 50 // Change the mode. Change notifications are sent to observers. |
50 void SetMode(const SearchMode& mode); | 51 void SetMode(const SearchMode& mode); |
51 | 52 |
52 // Get the active mode. | 53 // Get the active mode. |
53 const SearchMode& mode() const { return state_.mode; } | 54 const SearchMode& mode() const { return state_.mode; } |
54 | 55 |
55 // Set visibility of top bars. Change notifications are sent to observers. | 56 // Set visibility of top bars. Change notifications are sent to observers. |
56 void SetTopBarsVisible(bool visible); | 57 void SetTopBarsVisible(bool visible); |
57 | 58 |
| 59 // Sets the page voice search support state. Change notifications are sent to |
| 60 // observers. |
| 61 void SetVoiceSearchSupported(bool supported); |
| 62 |
| 63 // Gets the voice search support state of the page. |
| 64 bool voice_search_supported() const { return state_.voice_search_supported; } |
| 65 |
58 // Get the visibility of top bars. | 66 // Get the visibility of top bars. |
59 bool top_bars_visible() const { return state_.top_bars_visible; } | 67 bool top_bars_visible() const { return state_.top_bars_visible; } |
60 | 68 |
61 // Add and remove observers. | 69 // Add and remove observers. |
62 void AddObserver(SearchModelObserver* observer); | 70 void AddObserver(SearchModelObserver* observer); |
63 void RemoveObserver(SearchModelObserver* observer); | 71 void RemoveObserver(SearchModelObserver* observer); |
64 | 72 |
65 private: | 73 private: |
66 // Current state of model. | 74 // Current state of model. |
67 State state_; | 75 State state_; |
68 | 76 |
69 // Observers. | 77 // Observers. |
70 ObserverList<SearchModelObserver> observers_; | 78 ObserverList<SearchModelObserver> observers_; |
71 | 79 |
72 DISALLOW_COPY_AND_ASSIGN(SearchModel); | 80 DISALLOW_COPY_AND_ASSIGN(SearchModel); |
73 }; | 81 }; |
74 | 82 |
75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ | 83 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ |
OLD | NEW |