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

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

Powered by Google App Engine
This is Rietveld 408576698