OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_INFOBARS_CORE_INFOBAR_CONTAINER_H_ | 5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_CONTAINER_H_ |
6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_CONTAINER_H_ | 6 #define COMPONENTS_INFOBARS_CORE_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/time.h" | 11 #include "base/time/time.h" |
12 #include "components/infobars/core/infobar_manager.h" | 12 #include "components/infobars/core/infobar_manager.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 | 14 |
| 15 namespace gfx { |
| 16 class SlideAnimation; |
| 17 } |
| 18 |
15 namespace infobars { | 19 namespace infobars { |
16 | 20 |
17 class InfoBar; | 21 class InfoBar; |
18 | 22 |
19 // InfoBarContainer is a cross-platform base class to handle the visibility- | 23 // InfoBarContainer is a cross-platform base class to handle the visibility- |
20 // related aspects of InfoBars. While InfoBarManager owns the InfoBars, the | 24 // related aspects of InfoBars. While InfoBarManager owns the InfoBars, the |
21 // InfoBarContainer is responsible for telling particular InfoBars that they | 25 // InfoBarContainer is responsible for telling particular InfoBars that they |
22 // should be hidden or visible. | 26 // should be hidden or visible. |
23 // | 27 // |
24 // Platforms need to subclass this to implement a few platform-specific | 28 // Platforms need to subclass this to implement a few platform-specific |
25 // functions, which are pure virtual here. | 29 // functions, which are pure virtual here. |
26 class InfoBarContainer : public InfoBarManager::Observer { | 30 class InfoBarContainer : public InfoBarManager::Observer { |
27 public: | 31 public: |
28 class Delegate { | 32 class Delegate { |
29 public: | 33 public: |
30 // The separator color may vary depending on where the container is hosted. | 34 // The separator color may vary depending on where the container is hosted. |
31 virtual SkColor GetInfoBarSeparatorColor() const = 0; | 35 virtual SkColor GetInfoBarSeparatorColor() const = 0; |
32 | 36 |
33 // The delegate is notified each time the infobar container changes height, | 37 // The delegate is notified each time the infobar container changes height, |
34 // as well as when it stops animating. | 38 // as well as when it stops animating. |
35 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; | 39 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; |
36 | 40 |
37 // The delegate needs to tell us whether "unspoofable" arrows should be | 41 // The delegate needs to tell us whether "unspoofable" arrows should be |
38 // drawn, and if so, at what |x| coordinate. |x| may be NULL. | 42 // drawn, and if so, at what |x| coordinate. |x| may be NULL. |
39 virtual bool DrawInfoBarArrows(int* x) const = 0; | 43 virtual bool DrawInfoBarArrows(int* x) const = 0; |
40 | 44 |
| 45 // Computes the target arrow height for infobar number |index|, given its |
| 46 // animation. |
| 47 virtual int ArrowTargetHeightForInfoBar( |
| 48 size_t index, |
| 49 const gfx::SlideAnimation& animation) const = 0; |
| 50 |
| 51 // Computes the sizes of the infobar arrow (height and half width) and bar |
| 52 // (height) given the infobar's animation and its target element heights. |
| 53 // |bar_target_height| may be -1, which means "use the default bar target |
| 54 // height". |
| 55 virtual void ComputeInfoBarElementSizes( |
| 56 const gfx::SlideAnimation& animation, |
| 57 int arrow_target_height, |
| 58 int bar_target_height, |
| 59 int* arrow_height, |
| 60 int* arrow_half_width, |
| 61 int* bar_height) const = 0; |
| 62 |
41 protected: | 63 protected: |
42 virtual ~Delegate(); | 64 virtual ~Delegate(); |
43 }; | 65 }; |
44 | 66 |
45 explicit InfoBarContainer(Delegate* delegate); | 67 explicit InfoBarContainer(Delegate* delegate); |
46 virtual ~InfoBarContainer(); | 68 virtual ~InfoBarContainer(); |
47 | 69 |
48 // Changes the InfoBarManager for which this container is showing infobars. | 70 // Changes the InfoBarManager for which this container is showing infobars. |
49 // This will hide all current infobars, remove them from the container, add | 71 // This will hide all current infobars, remove them from the container, add |
50 // the infobars from |infobar_manager|, and show them all. |infobar_manager| | 72 // the infobars from |infobar_manager|, and show them all. |infobar_manager| |
51 // may be NULL. | 73 // may be NULL. |
52 void ChangeInfoBarManager(InfoBarManager* infobar_manager); | 74 void ChangeInfoBarManager(InfoBarManager* infobar_manager); |
53 | 75 |
54 // Returns the amount by which to overlap the toolbar above, and, when | 76 // Returns the amount by which to overlap the toolbar above, and, when |
55 // |total_height| is non-NULL, set it to the height of the InfoBarContainer | 77 // |total_height| is non-NULL, set it to the height of the InfoBarContainer |
56 // (including overlap). | 78 // (including overlap). |
57 int GetVerticalOverlap(int* total_height) const; | 79 int GetVerticalOverlap(int* total_height) const; |
58 | 80 |
59 // Called by the delegate when the distance between what the top infobar's | 81 // Triggers a recalculation of all infobar arrow heights. |
60 // "unspoofable" arrow would point to and the top infobar itself changes. | |
61 // This enables the top infobar to show a longer arrow (e.g. because of a | |
62 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if | |
63 // desired. | |
64 // | 82 // |
65 // IMPORTANT: This MUST NOT result in a call back to | 83 // IMPORTANT: This MUST NOT result in a call back to |
66 // Delegate::InfoBarContainerStateChanged() unless it causes an actual | 84 // Delegate::InfoBarContainerStateChanged() unless it causes an actual |
67 // change, lest we infinitely recurse. | 85 // change, lest we infinitely recurse. |
68 void SetMaxTopArrowHeight(int height); | 86 void UpdateInfoBarArrowTargetHeights(); |
69 | 87 |
70 // Called when a contained infobar has animated or by some other means changed | 88 // Called when a contained infobar has animated or by some other means changed |
71 // its height, or when it stops animating. The container is expected to do | 89 // its height, or when it stops animating. The container is expected to do |
72 // anything necessary to respond, e.g. re-layout. | 90 // anything necessary to respond, e.g. re-layout. |
73 void OnInfoBarStateChanged(bool is_animating); | 91 void OnInfoBarStateChanged(bool is_animating); |
74 | 92 |
75 // Called by |infobar| to request that it be removed from the container. At | 93 // Called by |infobar| to request that it be removed from the container. At |
76 // this point, |infobar| should already be hidden. | 94 // this point, |infobar| should already be hidden. |
77 void RemoveInfoBar(InfoBar* infobar); | 95 void RemoveInfoBar(InfoBar* infobar); |
78 | 96 |
(...skipping 23 matching lines...) Expand all Loading... |
102 typedef std::vector<InfoBar*> InfoBars; | 120 typedef std::vector<InfoBar*> InfoBars; |
103 | 121 |
104 // InfoBarManager::Observer: | 122 // InfoBarManager::Observer: |
105 void OnInfoBarAdded(InfoBar* infobar) override; | 123 void OnInfoBarAdded(InfoBar* infobar) override; |
106 void OnInfoBarRemoved(InfoBar* infobar, bool animate) override; | 124 void OnInfoBarRemoved(InfoBar* infobar, bool animate) override; |
107 void OnInfoBarReplaced(InfoBar* old_infobar, InfoBar* new_infobar) override; | 125 void OnInfoBarReplaced(InfoBar* old_infobar, InfoBar* new_infobar) override; |
108 void OnManagerShuttingDown(InfoBarManager* manager) override; | 126 void OnManagerShuttingDown(InfoBarManager* manager) override; |
109 | 127 |
110 // Adds |infobar| to this container before the existing infobar at position | 128 // Adds |infobar| to this container before the existing infobar at position |
111 // |position| and calls Show() on it. |animate| is passed along to | 129 // |position| and calls Show() on it. |animate| is passed along to |
112 // infobar->Show(). Depending on the value of |callback_status|, this calls | 130 // infobar->Show(). |
113 // infobar->set_container(this) either before or after the call to Show() so | 131 void AddInfoBar(InfoBar* infobar, size_t position, bool animate); |
114 // that OnInfoBarStateChanged() either will or won't be called as a result. | |
115 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; | |
116 void AddInfoBar(InfoBar* infobar, | |
117 size_t position, | |
118 bool animate, | |
119 CallbackStatus callback_status); | |
120 | |
121 void UpdateInfoBarArrowTargetHeights(); | |
122 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; | |
123 | 132 |
124 Delegate* delegate_; | 133 Delegate* delegate_; |
125 InfoBarManager* infobar_manager_; | 134 InfoBarManager* infobar_manager_; |
126 InfoBars infobars_; | 135 InfoBars infobars_; |
127 | 136 |
128 // Calculated in SetMaxTopArrowHeight(). | 137 // Normally false. When true, OnInfoBarStateChanged() becomes a no-op. We |
129 int top_arrow_target_height_; | 138 // use this to ensure that ChangeInfoBarManager() only executes the |
| 139 // functionality in OnInfoBarStateChanged() once, to minimize unnecessary |
| 140 // layout and painting. |
| 141 bool ignore_infobar_state_changed_; |
130 | 142 |
131 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); | 143 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); |
132 }; | 144 }; |
133 | 145 |
134 } // namespace infobars | 146 } // namespace infobars |
135 | 147 |
136 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_CONTAINER_H_ | 148 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_CONTAINER_H_ |
OLD | NEW |