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

Side by Side 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 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 #include "chrome/browser/ui/search/search_model.h" 5 #include "chrome/browser/ui/search/search_model.h"
6 6
7 #include "chrome/browser/search/search.h" 7 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/ui/search/search_model_observer.h" 8 #include "chrome/browser/ui/search/search_model_observer.h"
9 9
10 namespace chrome { 10 namespace chrome {
11 namespace search { 11 namespace search {
12 12
13 SearchModel::SearchModel() { 13 SearchModel::SearchModel() {
14 } 14 }
15 15
16 SearchModel::~SearchModel() { 16 SearchModel::~SearchModel() {
17 } 17 }
18 18
19 // static.
20 bool SearchModel::ShouldChangeTopBarsVisibility(const State& old_state,
21 const State& new_state) {
22 // If mode has changed, only change top bars visibility if new mode is not
23 // |SEARCH_SUGGESTIONS| or |SEARCH_RESULTS|. Top bars visibility for
24 // these 2 modes is determined when the mode stays the same, and:
25 // - for |NTP/SERP| pages: by SearchBox API, or
26 // - for |DEFAULT| pages: by platform-specific implementation of
27 // |InstantOverlayController| when it shows/hides the Instant overlay.
28 return old_state.mode != new_state.mode ?
29 !new_state.mode.is_search() : new_state.mode.is_search();
30 }
31
32 void SearchModel::SetState(const State& new_state) {
33 DCHECK(IsInstantExtendedAPIEnabled())
34 << "Please do not try to set the SearchModel mode without first "
35 << "checking if Search is enabled.";
36
37 if (state_ == new_state)
38 return;
39
40 const State old_state = state_;
41 state_ = new_state;
42
43 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
44 ModelChanged(old_state, state_));
45 }
46
19 void SearchModel::SetMode(const Mode& new_mode) { 47 void SearchModel::SetMode(const Mode& new_mode) {
20 DCHECK(IsInstantExtendedAPIEnabled()) 48 DCHECK(IsInstantExtendedAPIEnabled())
21 << "Please do not try to set the SearchModel mode without first " 49 << "Please do not try to set the SearchModel mode without first "
22 << "checking if Search is enabled."; 50 << "checking if Search is enabled.";
23 51
24 if (mode_ == new_mode) 52 if (state_.mode == new_mode)
25 return; 53 return;
26 54
27 const Mode old_mode = mode_; 55 const State old_state = state_;
28 mode_ = new_mode; 56 state_.mode = new_mode;
57
58 // For |SEARCH_SUGGESTIONS| and |SEARCH_RESULTS| modes, SearchBox API will
59 // determine visibility of top bars via SetTopBarsVisible(); for other modes,
60 // top bars are always visible, if available.
61 if (!state_.mode.is_search())
62 state_.top_bars_visible = true;
29 63
30 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 64 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
31 ModeChanged(old_mode, mode_)); 65 ModelChanged(old_state, state_));
66 }
67
68 void SearchModel::SetTopBarsVisible(bool visible) {
69 DCHECK(IsInstantExtendedAPIEnabled())
70 << "Please do not try to set the SearchModel mode without first "
71 << "checking if Search is enabled.";
72
73 if (state_.top_bars_visible == visible)
74 return;
75
76 const State old_state = state_;
77 state_.top_bars_visible = visible;
78
79 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
80 ModelChanged(old_state, state_));
32 } 81 }
33 82
34 void SearchModel::AddObserver(SearchModelObserver* observer) { 83 void SearchModel::AddObserver(SearchModelObserver* observer) {
35 observers_.AddObserver(observer); 84 observers_.AddObserver(observer);
36 } 85 }
37 86
38 void SearchModel::RemoveObserver(SearchModelObserver* observer) { 87 void SearchModel::RemoveObserver(SearchModelObserver* observer) {
39 observers_.RemoveObserver(observer); 88 observers_.RemoveObserver(observer);
40 } 89 }
41 90
42 } // namespace search 91 } // namespace search
43 } // namespace chrome 92 } // namespace chrome
OLDNEW
« 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