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 // Represents whether a page supports Instant. | |
15 enum InstantSupportState { | |
16 INSTANT_SUPPORT_NO, | |
17 INSTANT_SUPPORT_YES, | |
18 INSTANT_SUPPORT_UNKNOWN, | |
19 }; | |
20 | |
21 // 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 |
22 // changes. | 15 // changes. |
23 class SearchModel { | 16 class SearchModel { |
24 public: | 17 public: |
25 struct State { | 18 struct State { |
26 State(); | 19 State() : top_bars_visible(true) {} |
27 State(const SearchMode& mode, | 20 State(const SearchMode& mode, bool top_bars_visible) |
28 bool top_bars_visible, | 21 : mode(mode), |
29 InstantSupportState instant_support); | 22 top_bars_visible(top_bars_visible) {} |
30 | 23 |
31 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 } |
32 | 27 |
33 // The display mode of UI elements such as the toolbar, the tab strip, etc. | 28 // The display mode of UI elements such as the toolbar, the tab strip, etc. |
34 SearchMode mode; | 29 SearchMode mode; |
35 | 30 |
36 // The visibility of top bars such as bookmark and info bars. | 31 // The visibility of top bars such as bookmark and info bars. |
37 bool top_bars_visible; | 32 bool top_bars_visible; |
38 | |
39 // Does the current page support Instant? | |
40 // | |
41 // TODO(kmadhusu): Use bool instead of a tri-state variable. Refer to | |
42 // crbug.com/246323 for more details. | |
43 InstantSupportState instant_support; | |
44 }; | 33 }; |
45 | 34 |
46 SearchModel(); | 35 SearchModel(); |
47 ~SearchModel(); | 36 ~SearchModel(); |
48 | 37 |
49 // Returns true if visibility in top bars should be changed based on | 38 // Returns true if visibility in top bars should be changed based on |
50 // |old_state| and |new_state|. | 39 // |old_state| and |new_state|. |
51 static bool ShouldChangeTopBarsVisibility(const State& old_state, | 40 static bool ShouldChangeTopBarsVisibility(const State& old_state, |
52 const State& new_state); | 41 const State& new_state); |
53 | 42 |
54 // Change the state. Change notifications are sent to observers. | 43 // Change the state. Change notifications are sent to observers. |
55 void SetState(const State& state); | 44 void SetState(const State& state); |
56 | 45 |
57 // Get the current state. | 46 // Get the current state. |
58 const State& state() const { return state_; } | 47 const State& state() const { return state_; } |
59 | 48 |
60 // Change the mode. Change notifications are sent to observers. | 49 // Change the mode. Change notifications are sent to observers. |
61 void SetMode(const SearchMode& mode); | 50 void SetMode(const SearchMode& mode); |
62 | 51 |
63 // Get the active mode. | 52 // Get the active mode. |
64 const SearchMode& mode() const { return state_.mode; } | 53 const SearchMode& mode() const { return state_.mode; } |
65 | 54 |
66 // Set visibility of top bars. Change notifications are sent to observers. | 55 // Set visibility of top bars. Change notifications are sent to observers. |
67 void SetTopBarsVisible(bool visible); | 56 void SetTopBarsVisible(bool visible); |
68 | 57 |
69 // Get the visibility of top bars. | 58 // Get the visibility of top bars. |
70 bool top_bars_visible() const { return state_.top_bars_visible; } | 59 bool top_bars_visible() const { return state_.top_bars_visible; } |
71 | 60 |
72 // Set whether the page supports Instant. Change notifications are sent to | |
73 // observers. | |
74 void SetSupportsInstant(bool supports_instant); | |
75 | |
76 // Get whether the page supports Instant. | |
77 InstantSupportState instant_support() const { | |
78 return state_.instant_support; | |
79 } | |
80 | |
81 // Add and remove observers. | 61 // Add and remove observers. |
82 void AddObserver(SearchModelObserver* observer); | 62 void AddObserver(SearchModelObserver* observer); |
83 void RemoveObserver(SearchModelObserver* observer); | 63 void RemoveObserver(SearchModelObserver* observer); |
84 | 64 |
85 private: | 65 private: |
86 // Current state of model. | 66 // Current state of model. |
87 State state_; | 67 State state_; |
88 | 68 |
89 // Observers. | 69 // Observers. |
90 ObserverList<SearchModelObserver> observers_; | 70 ObserverList<SearchModelObserver> observers_; |
91 | 71 |
92 DISALLOW_COPY_AND_ASSIGN(SearchModel); | 72 DISALLOW_COPY_AND_ASSIGN(SearchModel); |
93 }; | 73 }; |
94 | 74 |
95 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ | 75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ |
OLD | NEW |