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

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: Fix android_dbg test failures Created 7 years, 6 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,
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 //
41 // TODO(kmadhusu): Use bool instead of a tri-state variable. Refer to
42 // crbug.com/246323 for more details.
43 InstantSupportState instant_support;
33 }; 44 };
34 45
35 SearchModel(); 46 SearchModel();
36 ~SearchModel(); 47 ~SearchModel();
37 48
38 // Returns true if visibility in top bars should be changed based on 49 // Returns true if visibility in top bars should be changed based on
39 // |old_state| and |new_state|. 50 // |old_state| and |new_state|.
40 static bool ShouldChangeTopBarsVisibility(const State& old_state, 51 static bool ShouldChangeTopBarsVisibility(const State& old_state,
41 const State& new_state); 52 const State& new_state);
42 53
43 // Change the state. Change notifications are sent to observers. 54 // Change the state. Change notifications are sent to observers.
44 void SetState(const State& state); 55 void SetState(const State& state);
45 56
46 // Get the current state. 57 // Get the current state.
47 const State& state() const { return state_; } 58 const State& state() const { return state_; }
48 59
49 // Change the mode. Change notifications are sent to observers. 60 // Change the mode. Change notifications are sent to observers.
50 void SetMode(const SearchMode& mode); 61 void SetMode(const SearchMode& mode);
51 62
52 // Get the active mode. 63 // Get the active mode.
53 const SearchMode& mode() const { return state_.mode; } 64 const SearchMode& mode() const { return state_.mode; }
54 65
55 // Set visibility of top bars. Change notifications are sent to observers. 66 // Set visibility of top bars. Change notifications are sent to observers.
56 void SetTopBarsVisible(bool visible); 67 void SetTopBarsVisible(bool visible);
57 68
58 // Get the visibility of top bars. 69 // Get the visibility of top bars.
59 bool top_bars_visible() const { return state_.top_bars_visible; } 70 bool top_bars_visible() const { return state_.top_bars_visible; }
60 71
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
61 // Add and remove observers. 81 // Add and remove observers.
62 void AddObserver(SearchModelObserver* observer); 82 void AddObserver(SearchModelObserver* observer);
63 void RemoveObserver(SearchModelObserver* observer); 83 void RemoveObserver(SearchModelObserver* observer);
64 84
65 private: 85 private:
66 // Current state of model. 86 // Current state of model.
67 State state_; 87 State state_;
68 88
69 // Observers. 89 // Observers.
70 ObserverList<SearchModelObserver> observers_; 90 ObserverList<SearchModelObserver> observers_;
71 91
72 DISALLOW_COPY_AND_ASSIGN(SearchModel); 92 DISALLOW_COPY_AND_ASSIGN(SearchModel);
73 }; 93 };
74 94
75 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_ 95 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_test_utils.cc ('k') | chrome/browser/ui/search/search_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698