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