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

Side by Side Diff: chrome/browser/infobars/infobar_container.h

Issue 12036075: alternate ntp: fix website page jankiness when suggestions show and top bars are hidden (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed all comments Created 7 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_INFOBARS_INFOBAR_CONTAINER_H_ 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "chrome/browser/instant/instant_model_observer.h"
12 #include "chrome/browser/ui/search/search_model_observer.h" 13 #include "chrome/browser/ui/search/search_model_observer.h"
13 #include "chrome/common/search_types.h" 14 #include "chrome/common/search_types.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
17 18
18 class InfoBar; 19 class InfoBar;
19 class InfoBarDelegate; 20 class InfoBarDelegate;
20 class InfoBarService; 21 class InfoBarService;
22 class InstantModel;
21 23
22 namespace chrome { 24 namespace chrome {
23 namespace search { 25 namespace search {
24 class SearchModel; 26 class SearchModel;
25 } 27 }
26 } 28 }
27 29
28 // InfoBarContainer is a cross-platform base class to handle the visibility- 30 // InfoBarContainer is a cross-platform base class to handle the visibility-
29 // related aspects of InfoBars. While InfoBars own themselves, the 31 // related aspects of InfoBars. While InfoBars own themselves, the
30 // InfoBarContainer is responsible for telling particular InfoBars that they 32 // InfoBarContainer is responsible for telling particular InfoBars that they
31 // should be hidden or visible. 33 // should be hidden or visible.
32 // 34 //
33 // Platforms need to subclass this to implement a few platform-specific 35 // Platforms need to subclass this to implement a few platform-specific
34 // functions, which are pure virtual here. 36 // functions, which are pure virtual here.
35 // 37 //
36 // This class also observes changes to the SearchModel mode. If the user changes 38 // This class also observes changes to the SearchModel and InstantModel modes.
37 // into suggestions mode, it hides all the infobars temporarily. When the user 39 // It hides infobars temporarily if the user changes into |SEARCH_SUGGESTIONS|
38 // changes back out of suggestions mode, it reshows any infobars, and starts a 40 // mode (refer to chrome::search::Mode in chrome/common/search_types.h for all
39 // 50 ms window during which any attempts to re-hide any infobars are handled 41 // search modes) when:
40 // without animation. This prevents glitchy-looking behavior when the user 42 // - on a page that is not |NTP| or |SEARCH_RESULTS|: when instant preview is
41 // navigates following a mode change, which otherwise would re-show the infobars 43 // ready;
42 // only to instantly animate them closed. The window is canceled if a tab 44 // - on a page that is |NTP| or |SEARCH_RESULTS|: immediately;
43 // change occurs. 45 // TODO(kuan): this scenario requires more complex synchronization with
46 // renderer SearchBoxAPI and will be implemented as the next step;
47 // for now, hiding is immediate.
48 // When the user changes back out of |SEARCH_SUGGESTIONS| mode, it reshows any
49 // infobars, and starts a 50 ms window during which any attempts to re-hide any
50 // infobars are handled without animation. This prevents glitchy-looking
51 // behavior when the user navigates following a mode change, which otherwise
52 // would re-show the infobars only to instantly animate them closed. The window
53 // to re-hide infobars without animation is canceled if a tab change occurs.
44 class InfoBarContainer : public content::NotificationObserver, 54 class InfoBarContainer : public content::NotificationObserver,
45 public chrome::search::SearchModelObserver { 55 public chrome::search::SearchModelObserver,
56 public InstantModelObserver {
46 public: 57 public:
47 class Delegate { 58 class Delegate {
48 public: 59 public:
49 // The separator color may vary depending on where the container is hosted. 60 // The separator color may vary depending on where the container is hosted.
50 virtual SkColor GetInfoBarSeparatorColor() const = 0; 61 virtual SkColor GetInfoBarSeparatorColor() const = 0;
51 62
52 // The delegate is notified each time the infobar container changes height, 63 // The delegate is notified each time the infobar container changes height,
53 // as well as when it stops animating. 64 // as well as when it stops animating.
54 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; 65 virtual void InfoBarContainerStateChanged(bool is_animating) = 0;
55 66
56 // The delegate needs to tell us whether "unspoofable" arrows should be 67 // The delegate needs to tell us whether "unspoofable" arrows should be
57 // drawn, and if so, at what |x| coordinate. |x| may be NULL. 68 // drawn, and if so, at what |x| coordinate. |x| may be NULL.
58 virtual bool DrawInfoBarArrows(int* x) const = 0; 69 virtual bool DrawInfoBarArrows(int* x) const = 0;
59 70
60 protected: 71 protected:
61 virtual ~Delegate(); 72 virtual ~Delegate();
62 }; 73 };
63 74
64 // |search_model| may be NULL if this class is used in a window that does not 75 // |search_model| and |instant_model| may be NULL if this class is used in a
65 // support Instant Extended. 76 // window that does not support Instant Extended.
66 InfoBarContainer(Delegate* delegate, 77 InfoBarContainer(Delegate* delegate,
67 chrome::search::SearchModel* search_model); 78 chrome::search::SearchModel* search_model,
79 const InstantModel* instant_model);
68 virtual ~InfoBarContainer(); 80 virtual ~InfoBarContainer();
69 81
70 // Changes the InfoBarService for which this container is showing 82 // Changes the InfoBarService for which this container is showing
71 // infobars. This will remove all current infobars from the container, add 83 // infobars. This will remove all current infobars from the container, add
72 // the infobars from |infobar_service|, and show them all. |infobar_service| 84 // the infobars from |infobar_service|, and show them all. |infobar_service|
73 // may be NULL. 85 // may be NULL.
74 void ChangeInfoBarService(InfoBarService* infobar_service); 86 void ChangeInfoBarService(InfoBarService* infobar_service);
75 87
76 // Returns the amount by which to overlap the toolbar above, and, when 88 // Returns the amount by which to overlap the toolbar above, and, when
77 // |total_height| is non-NULL, set it to the height of the InfoBarContainer 89 // |total_height| is non-NULL, set it to the height of the InfoBarContainer
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 131
120 // content::NotificationObserver: 132 // content::NotificationObserver:
121 virtual void Observe(int type, 133 virtual void Observe(int type,
122 const content::NotificationSource& source, 134 const content::NotificationSource& source,
123 const content::NotificationDetails& details) OVERRIDE; 135 const content::NotificationDetails& details) OVERRIDE;
124 136
125 // chrome::search::SearchModelObserver: 137 // chrome::search::SearchModelObserver:
126 virtual void ModeChanged(const chrome::search::Mode& old_mode, 138 virtual void ModeChanged(const chrome::search::Mode& old_mode,
127 const chrome::search::Mode& new_mode) OVERRIDE; 139 const chrome::search::Mode& new_mode) OVERRIDE;
128 140
141 // InstantModelObserver:
142 virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE;
143
129 // Hides an InfoBar for the specified delegate, in response to a notification 144 // Hides an InfoBar for the specified delegate, in response to a notification
130 // from the selected InfoBarService. The InfoBar's disappearance will be 145 // from the selected InfoBarService. The InfoBar's disappearance will be
131 // animated if |use_animation| is true and it has been more than 50ms since 146 // animated if |use_animation| is true and it has been more than 50ms since
132 // infobars were reshown due to an Instant Extended mode change. The InfoBar 147 // infobars were reshown due to an Instant Extended mode change. The InfoBar
133 // will call back to RemoveInfoBar() to remove itself once it's hidden (which 148 // will call back to RemoveInfoBar() to remove itself once it's hidden (which
134 // may mean synchronously). Returns the position within |infobars_| the 149 // may mean synchronously). Returns the position within |infobars_| the
135 // infobar was previously at. 150 // infobar was previously at.
136 size_t HideInfoBar(InfoBarDelegate* delegate, bool use_animation); 151 size_t HideInfoBar(InfoBarDelegate* delegate, bool use_animation);
137 152
138 // Hides all infobars in this container without animation. 153 // Hides all infobars in this container without animation.
(...skipping 19 matching lines...) Expand all
158 InfoBars infobars_; 173 InfoBars infobars_;
159 174
160 // Tracks the most recent time infobars were re-shown after being hidden due 175 // Tracks the most recent time infobars were re-shown after being hidden due
161 // to Instant Extended's ModeChanged. 176 // to Instant Extended's ModeChanged.
162 base::TimeTicks infobars_shown_time_; 177 base::TimeTicks infobars_shown_time_;
163 178
164 // Tracks which search mode is active, as well as mode changes, for Instant 179 // Tracks which search mode is active, as well as mode changes, for Instant
165 // Extended. 180 // Extended.
166 chrome::search::SearchModel* search_model_; 181 chrome::search::SearchModel* search_model_;
167 182
183 // Tracks state of instant preview for Instant Extended.
184 const InstantModel* instant_model_; // Weak.
185
168 // Calculated in SetMaxTopArrowHeight(). 186 // Calculated in SetMaxTopArrowHeight().
169 int top_arrow_target_height_; 187 int top_arrow_target_height_;
170 188
171 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); 189 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer);
172 }; 190 };
173 191
174 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ 192 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/infobars/infobar_container.cc » ('j') | chrome/browser/ui/views/frame/browser_view_layout.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698