OLD | NEW |
---|---|
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 suggestions mode when: |
Peter Kasting
2013/01/28 21:51:00
Readers may not know what "suggestions mode" means
kuan
2013/01/29 00:17:08
Done.
| |
38 // changes back out of suggestions mode, it reshows any infobars, and starts a | 40 // - on a website page: when instant preview is ready; |
39 // 50 ms window during which any attempts to re-hide any infobars are handled | 41 // - not on a website page: immediately; this scenario requires more complex |
Peter Kasting
2013/01/28 21:51:00
It's not clear what "not on a website page" means.
kuan
2013/01/29 00:17:08
Done.
| |
40 // without animation. This prevents glitchy-looking behavior when the user | 42 // synchronization with renderer and will be implemented as the next step; |
dhollowa
2013/01/25 21:24:08
nit: this sounds like a TODO and should be marked
Peter Kasting
2013/01/28 21:51:00
Yes, please don't discuss implementation plans in
kuan
2013/01/29 00:17:08
Done.
kuan
2013/01/29 00:17:08
Done.
| |
41 // navigates following a mode change, which otherwise would re-show the infobars | 43 // for now, hiding is immediate. |
42 // only to instantly animate them closed. The window is canceled if a tab | 44 // When the user changes back out of suggestions mode, it reshows any infobars, |
43 // change occurs. | 45 // and starts a 50 ms window during which any attempts to re-hide any infobars |
46 // are handled without animation. This prevents glitchy-looking behavior when | |
47 // the user navigates following a mode change, which otherwise would re-show the | |
48 // infobars only to instantly animate them closed. The window is canceled if a | |
dhollowa
2013/01/25 21:24:08
nit: "The *animation* is canceled..." ?
kuan
2013/01/29 00:17:08
i didn't write this comment, but hopefully i've cl
| |
49 // tab change occurs. | |
44 class InfoBarContainer : public content::NotificationObserver, | 50 class InfoBarContainer : public content::NotificationObserver, |
45 public chrome::search::SearchModelObserver { | 51 public chrome::search::SearchModelObserver, |
52 public InstantModelObserver { | |
46 public: | 53 public: |
47 class Delegate { | 54 class Delegate { |
48 public: | 55 public: |
49 // The separator color may vary depending on where the container is hosted. | 56 // The separator color may vary depending on where the container is hosted. |
50 virtual SkColor GetInfoBarSeparatorColor() const = 0; | 57 virtual SkColor GetInfoBarSeparatorColor() const = 0; |
51 | 58 |
52 // The delegate is notified each time the infobar container changes height, | 59 // The delegate is notified each time the infobar container changes height, |
53 // as well as when it stops animating. | 60 // as well as when it stops animating. |
54 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; | 61 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; |
55 | 62 |
56 // The delegate needs to tell us whether "unspoofable" arrows should be | 63 // The delegate needs to tell us whether "unspoofable" arrows should be |
57 // drawn, and if so, at what |x| coordinate. |x| may be NULL. | 64 // drawn, and if so, at what |x| coordinate. |x| may be NULL. |
58 virtual bool DrawInfoBarArrows(int* x) const = 0; | 65 virtual bool DrawInfoBarArrows(int* x) const = 0; |
59 | 66 |
60 protected: | 67 protected: |
61 virtual ~Delegate(); | 68 virtual ~Delegate(); |
62 }; | 69 }; |
63 | 70 |
64 // |search_model| may be NULL if this class is used in a window that does not | 71 // |search_model| and |instant_model| may be NULL if this class is used in a |
65 // support Instant Extended. | 72 // window that does not support Instant Extended. |
66 InfoBarContainer(Delegate* delegate, | 73 InfoBarContainer(Delegate* delegate, |
67 chrome::search::SearchModel* search_model); | 74 chrome::search::SearchModel* search_model, |
dhollowa
2013/01/25 21:24:08
The const for InstantModel is nice. Could you ple
Peter Kasting
2013/01/27 23:57:28
It does not seem at all correct that you should be
dhollowa
2013/01/28 16:43:06
That's a design choice really. What I like about
| |
75 const InstantModel* instant_model); | |
68 virtual ~InfoBarContainer(); | 76 virtual ~InfoBarContainer(); |
69 | 77 |
70 // Changes the InfoBarService for which this container is showing | 78 // Changes the InfoBarService for which this container is showing |
71 // infobars. This will remove all current infobars from the container, add | 79 // infobars. This will remove all current infobars from the container, add |
72 // the infobars from |infobar_service|, and show them all. |infobar_service| | 80 // the infobars from |infobar_service|, and show them all. |infobar_service| |
73 // may be NULL. | 81 // may be NULL. |
74 void ChangeInfoBarService(InfoBarService* infobar_service); | 82 void ChangeInfoBarService(InfoBarService* infobar_service); |
75 | 83 |
76 // Returns the amount by which to overlap the toolbar above, and, when | 84 // 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 | 85 // |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 Loading... | |
119 | 127 |
120 // content::NotificationObserver: | 128 // content::NotificationObserver: |
121 virtual void Observe(int type, | 129 virtual void Observe(int type, |
122 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
123 const content::NotificationDetails& details) OVERRIDE; | 131 const content::NotificationDetails& details) OVERRIDE; |
124 | 132 |
125 // chrome::search::SearchModelObserver: | 133 // chrome::search::SearchModelObserver: |
126 virtual void ModeChanged(const chrome::search::Mode& old_mode, | 134 virtual void ModeChanged(const chrome::search::Mode& old_mode, |
127 const chrome::search::Mode& new_mode) OVERRIDE; | 135 const chrome::search::Mode& new_mode) OVERRIDE; |
128 | 136 |
137 // InstantModelObserver: | |
138 virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; | |
139 | |
129 // Hides an InfoBar for the specified delegate, in response to a notification | 140 // Hides an InfoBar for the specified delegate, in response to a notification |
130 // from the selected InfoBarService. The InfoBar's disappearance will be | 141 // 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 | 142 // 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 | 143 // 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 | 144 // will call back to RemoveInfoBar() to remove itself once it's hidden (which |
134 // may mean synchronously). Returns the position within |infobars_| the | 145 // may mean synchronously). Returns the position within |infobars_| the |
135 // infobar was previously at. | 146 // infobar was previously at. |
136 size_t HideInfoBar(InfoBarDelegate* delegate, bool use_animation); | 147 size_t HideInfoBar(InfoBarDelegate* delegate, bool use_animation); |
137 | 148 |
138 // Hides all infobars in this container without animation. | 149 // Hides all infobars in this container without animation. |
(...skipping 19 matching lines...) Expand all Loading... | |
158 InfoBars infobars_; | 169 InfoBars infobars_; |
159 | 170 |
160 // Tracks the most recent time infobars were re-shown after being hidden due | 171 // Tracks the most recent time infobars were re-shown after being hidden due |
161 // to Instant Extended's ModeChanged. | 172 // to Instant Extended's ModeChanged. |
162 base::TimeTicks infobars_shown_time_; | 173 base::TimeTicks infobars_shown_time_; |
163 | 174 |
164 // Tracks which search mode is active, as well as mode changes, for Instant | 175 // Tracks which search mode is active, as well as mode changes, for Instant |
165 // Extended. | 176 // Extended. |
166 chrome::search::SearchModel* search_model_; | 177 chrome::search::SearchModel* search_model_; |
167 | 178 |
179 // Tracks state of instant preview for Instant Extended. | |
180 const InstantModel* instant_model_; // Weak. | |
181 | |
168 // Calculated in SetMaxTopArrowHeight(). | 182 // Calculated in SetMaxTopArrowHeight(). |
169 int top_arrow_target_height_; | 183 int top_arrow_target_height_; |
170 | 184 |
171 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); | 185 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); |
172 }; | 186 }; |
173 | 187 |
174 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | 188 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ |
OLD | NEW |