| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | |
| 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "chrome/browser/infobars/infobar_manager.h" | |
| 13 #include "third_party/skia/include/core/SkColor.h" | |
| 14 | |
| 15 class InfoBar; | |
| 16 | |
| 17 // InfoBarContainer is a cross-platform base class to handle the visibility- | |
| 18 // related aspects of InfoBars. While InfoBarManager owns the InfoBars, the | |
| 19 // InfoBarContainer is responsible for telling particular InfoBars that they | |
| 20 // should be hidden or visible. | |
| 21 // | |
| 22 // Platforms need to subclass this to implement a few platform-specific | |
| 23 // functions, which are pure virtual here. | |
| 24 class InfoBarContainer : public InfoBarManager::Observer { | |
| 25 public: | |
| 26 class Delegate { | |
| 27 public: | |
| 28 // The separator color may vary depending on where the container is hosted. | |
| 29 virtual SkColor GetInfoBarSeparatorColor() const = 0; | |
| 30 | |
| 31 // The delegate is notified each time the infobar container changes height, | |
| 32 // as well as when it stops animating. | |
| 33 virtual void InfoBarContainerStateChanged(bool is_animating) = 0; | |
| 34 | |
| 35 // The delegate needs to tell us whether "unspoofable" arrows should be | |
| 36 // drawn, and if so, at what |x| coordinate. |x| may be NULL. | |
| 37 virtual bool DrawInfoBarArrows(int* x) const = 0; | |
| 38 | |
| 39 protected: | |
| 40 virtual ~Delegate(); | |
| 41 }; | |
| 42 | |
| 43 explicit InfoBarContainer(Delegate* delegate); | |
| 44 virtual ~InfoBarContainer(); | |
| 45 | |
| 46 // Changes the InfoBarManager for which this container is showing infobars. | |
| 47 // This will hide all current infobars, remove them from the container, add | |
| 48 // the infobars from |infobar_manager|, and show them all. |infobar_manager| | |
| 49 // may be NULL. | |
| 50 void ChangeInfoBarManager(InfoBarManager* infobar_manager); | |
| 51 | |
| 52 // Returns the amount by which to overlap the toolbar above, and, when | |
| 53 // |total_height| is non-NULL, set it to the height of the InfoBarContainer | |
| 54 // (including overlap). | |
| 55 int GetVerticalOverlap(int* total_height); | |
| 56 | |
| 57 // Called by the delegate when the distance between what the top infobar's | |
| 58 // "unspoofable" arrow would point to and the top infobar itself changes. | |
| 59 // This enables the top infobar to show a longer arrow (e.g. because of a | |
| 60 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if | |
| 61 // desired. | |
| 62 // | |
| 63 // IMPORTANT: This MUST NOT result in a call back to | |
| 64 // Delegate::InfoBarContainerStateChanged() unless it causes an actual | |
| 65 // change, lest we infinitely recurse. | |
| 66 void SetMaxTopArrowHeight(int height); | |
| 67 | |
| 68 // Called when a contained infobar has animated or by some other means changed | |
| 69 // its height, or when it stops animating. The container is expected to do | |
| 70 // anything necessary to respond, e.g. re-layout. | |
| 71 void OnInfoBarStateChanged(bool is_animating); | |
| 72 | |
| 73 // Called by |infobar| to request that it be removed from the container. At | |
| 74 // this point, |infobar| should already be hidden. | |
| 75 void RemoveInfoBar(InfoBar* infobar); | |
| 76 | |
| 77 const Delegate* delegate() const { return delegate_; } | |
| 78 | |
| 79 protected: | |
| 80 // Subclasses must call this during destruction, so that we can remove | |
| 81 // infobars (which will call the pure virtual functions below) while the | |
| 82 // subclass portion of |this| has not yet been destroyed. | |
| 83 void RemoveAllInfoBarsForDestruction(); | |
| 84 | |
| 85 // These must be implemented on each platform to e.g. adjust the visible | |
| 86 // object hierarchy. The first two functions should each be called exactly | |
| 87 // once during an infobar's life (see comments on RemoveInfoBar() and | |
| 88 // AddInfoBar()). | |
| 89 virtual void PlatformSpecificAddInfoBar(InfoBar* infobar, | |
| 90 size_t position) = 0; | |
| 91 // TODO(miguelg): Remove this; it is only necessary for Android, and only | |
| 92 // until the translate infobar is implemented as three different infobars like | |
| 93 // GTK does. | |
| 94 virtual void PlatformSpecificReplaceInfoBar(InfoBar* old_infobar, | |
| 95 InfoBar* new_infobar) {} | |
| 96 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0; | |
| 97 virtual void PlatformSpecificInfoBarStateChanged(bool is_animating) {} | |
| 98 | |
| 99 private: | |
| 100 typedef std::vector<InfoBar*> InfoBars; | |
| 101 | |
| 102 // InfoBarManager::Observer: | |
| 103 virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; | |
| 104 virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; | |
| 105 virtual void OnInfoBarReplaced(InfoBar* old_infobar, | |
| 106 InfoBar* new_infobar) OVERRIDE; | |
| 107 virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; | |
| 108 | |
| 109 // Adds |infobar| to this container before the existing infobar at position | |
| 110 // |position| and calls Show() on it. |animate| is passed along to | |
| 111 // infobar->Show(). Depending on the value of |callback_status|, this calls | |
| 112 // infobar->set_container(this) either before or after the call to Show() so | |
| 113 // that OnInfoBarStateChanged() either will or won't be called as a result. | |
| 114 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; | |
| 115 void AddInfoBar(InfoBar* infobar, | |
| 116 size_t position, | |
| 117 bool animate, | |
| 118 CallbackStatus callback_status); | |
| 119 | |
| 120 void UpdateInfoBarArrowTargetHeights(); | |
| 121 int ArrowTargetHeightForInfoBar(size_t infobar_index) const; | |
| 122 | |
| 123 Delegate* delegate_; | |
| 124 InfoBarManager* infobar_manager_; | |
| 125 InfoBars infobars_; | |
| 126 | |
| 127 // Calculated in SetMaxTopArrowHeight(). | |
| 128 int top_arrow_target_height_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer); | |
| 131 }; | |
| 132 | |
| 133 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_CONTAINER_H_ | |
| OLD | NEW |