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