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

Unified Diff: chrome/browser/ui/search/search_model.cc

Issue 12631008: alternate ntp: implement Show/HideBars API to reduce jank when showing/hiding bars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed build break Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/search/search_model.h ('k') | chrome/browser/ui/search/search_model_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/search/search_model.cc
diff --git a/chrome/browser/ui/search/search_model.cc b/chrome/browser/ui/search/search_model.cc
index b1830e69a0dcc8e6d8c009e260bee829015927ff..6637b8fd1e41c3dc93ffc0fe05ee207ba9251261 100644
--- a/chrome/browser/ui/search/search_model.cc
+++ b/chrome/browser/ui/search/search_model.cc
@@ -16,19 +16,68 @@ SearchModel::SearchModel() {
SearchModel::~SearchModel() {
}
+// static.
+bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state,
+ const State& new_state) {
+ // If mode has changed, only change top bars visibility if new mode is not
+ // |SEARCH_SUGGESTIONS| or |SEARCH_RESULTS|. Top bars visibility for
+ // these 2 modes is determined when the mode stays the same, and:
+ // - for |NTP/SERP| pages: by SearchBox API, or
+ // - for |DEFAULT| pages: by platform-specific implementation of
+ // |InstantOverlayController| when it shows/hides the Instant overlay.
+ return old_state.mode != new_state.mode ?
+ !new_state.mode.is_search() : new_state.mode.is_search();
+}
+
+void SearchModel::SetState(const State& new_state) {
+ DCHECK(IsInstantExtendedAPIEnabled())
+ << "Please do not try to set the SearchModel mode without first "
+ << "checking if Search is enabled.";
+
+ if (state_ == new_state)
+ return;
+
+ const State old_state = state_;
+ state_ = new_state;
+
+ FOR_EACH_OBSERVER(SearchModelObserver, observers_,
+ ModelChanged(old_state, state_));
+}
+
void SearchModel::SetMode(const Mode& new_mode) {
DCHECK(IsInstantExtendedAPIEnabled())
<< "Please do not try to set the SearchModel mode without first "
<< "checking if Search is enabled.";
- if (mode_ == new_mode)
+ if (state_.mode == new_mode)
+ return;
+
+ const State old_state = state_;
+ state_.mode = new_mode;
+
+ // For |SEARCH_SUGGESTIONS| and |SEARCH_RESULTS| modes, SearchBox API will
+ // determine visibility of top bars via SetTopBarsVisible(); for other modes,
+ // top bars are always visible, if available.
+ if (!state_.mode.is_search())
+ state_.top_bars_visible = true;
+
+ FOR_EACH_OBSERVER(SearchModelObserver, observers_,
+ ModelChanged(old_state, state_));
+}
+
+void SearchModel::SetTopBarsVisible(bool visible) {
+ DCHECK(IsInstantExtendedAPIEnabled())
+ << "Please do not try to set the SearchModel mode without first "
+ << "checking if Search is enabled.";
+
+ if (state_.top_bars_visible == visible)
return;
- const Mode old_mode = mode_;
- mode_ = new_mode;
+ const State old_state = state_;
+ state_.top_bars_visible = visible;
FOR_EACH_OBSERVER(SearchModelObserver, observers_,
- ModeChanged(old_mode, mode_));
+ ModelChanged(old_state, state_));
}
void SearchModel::AddObserver(SearchModelObserver* observer) {
« no previous file with comments | « chrome/browser/ui/search/search_model.h ('k') | chrome/browser/ui/search/search_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698