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

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

Issue 14911005: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 7 years, 7 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 | Annotate | Revision Log
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 #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, bool top_bars_visible);
21 : mode(mode),
22 top_bars_visible(top_bars_visible) {}
23 28
24 bool operator==(const State& rhs) const { 29 bool operator==(const State& rhs) const;
25 return mode == rhs.mode && top_bars_visible == rhs.top_bars_visible;
26 }
27 30
28 // The display mode of UI elements such as the toolbar, the tab strip, etc. 31 // The display mode of UI elements such as the toolbar, the tab strip, etc.
29 SearchMode mode; 32 SearchMode mode;
30 33
31 // The visibility of top bars such as bookmark and info bars. 34 // The visibility of top bars such as bookmark and info bars.
32 bool top_bars_visible; 35 bool top_bars_visible;
36
37 // Does the current page support Instant?
38 InstantSupportState instant_support;
33 }; 39 };
34 40
35 SearchModel(); 41 SearchModel();
36 ~SearchModel(); 42 ~SearchModel();
37 43
38 // Returns true if visibility in top bars should be changed based on 44 // Returns true if visibility in top bars should be changed based on
39 // |old_state| and |new_state|. 45 // |old_state| and |new_state|.
40 static bool ShouldChangeTopBarsVisibility(const State& old_state, 46 static bool ShouldChangeTopBarsVisibility(const State& old_state,
41 const State& new_state); 47 const State& new_state);
42 48
43 // Change the state. Change notifications are sent to observers. 49 // Change the state. Change notifications are sent to observers.
44 void SetState(const State& state); 50 void SetState(const State& state);
45 51
46 // Get the current state. 52 // Get the current state.
47 const State& state() const { return state_; } 53 const State& state() const { return state_; }
48 54
49 // Change the mode. Change notifications are sent to observers. 55 // Change the mode. Change notifications are sent to observers.
50 void SetMode(const SearchMode& mode); 56 void SetMode(const SearchMode& mode);
51 57
52 // Get the active mode. 58 // Get the active mode.
53 const SearchMode& mode() const { return state_.mode; } 59 const SearchMode& mode() const { return state_.mode; }
54 60
55 // Set visibility of top bars. Change notifications are sent to observers. 61 // Set visibility of top bars. Change notifications are sent to observers.
56 void SetTopBarsVisible(bool visible); 62 void SetTopBarsVisible(bool visible);
57 63
58 // Get the visibility of top bars. 64 // Get the visibility of top bars.
59 bool top_bars_visible() const { return state_.top_bars_visible; } 65 bool top_bars_visible() const { return state_.top_bars_visible; }
60 66
67 // Set whether the page supports Instant. Change notifications are sent to
68 // observers.
69 void SetSupportsInstant(bool supports_instant);
70
71 // Get whether the page supports Instant.
72 InstantSupportState instant_support() const {
73 return state_.instant_support;
74 }
75
61 // Add and remove observers. 76 // Add and remove observers.
62 void AddObserver(SearchModelObserver* observer); 77 void AddObserver(SearchModelObserver* observer);
63 void RemoveObserver(SearchModelObserver* observer); 78 void RemoveObserver(SearchModelObserver* observer);
64 79
65 private: 80 private:
66 // Current state of model. 81 // Current state of model.
67 State state_; 82 State state_;
68 83
69 // Observers. 84 // Observers.
70 ObserverList<SearchModelObserver> observers_; 85 ObserverList<SearchModelObserver> observers_;
71 86
72 DISALLOW_COPY_AND_ASSIGN(SearchModel); 87 DISALLOW_COPY_AND_ASSIGN(SearchModel);
73 }; 88 };
74 89
75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ 90 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698