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

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

Issue 6989001: Misc. infobar stuff: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
(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_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
7 #pragma once
8
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "content/common/notification_observer.h"
13 #include "content/common/notification_registrar.h"
14 #include "third_party/skia/include/core/SkColor.h"
15
16 class InfoBar;
17 class InfoBarDelegate;
18 class TabContents;
19 class TabContentsWrapper;
20
21 // InfoBarContainer is a cross-platform base class to handle the visibility-
22 // related aspects of InfoBars. While InfoBars own themselves, the
23 // InfoBarContainer is responsible for telling particular InfoBars that they
24 // should be hidden or visible.
25 //
26 // Platforms need to subclass this to implement a few platform-specific
27 // functions, which are pure virtual here.
28 class InfoBarContainer : public NotificationObserver {
29 public:
30 class Delegate {
31 public:
32 // The separator color may vary depending on where the container is hosted.
33 virtual SkColor GetInfoBarSeparatorColor() const = 0;
34
35 // The delegate is notified each time the infobar container changes height,
36 // as well as when it stops animating.
37 virtual void InfoBarContainerStateChanged(bool is_animating) = 0;
38
39 // The delegate needs to tell us whether "unspoofable" arrows should be
40 // drawn, and if so, at what |x| coordinate. |x| may be NULL.
41 virtual bool DrawInfoBarArrows(int* x) const = 0;
42
43 protected:
44 virtual ~Delegate();
45 };
46
47 explicit InfoBarContainer(Delegate* delegate);
48 virtual ~InfoBarContainer();
49
50 // Changes the TabContents for which this container is showing infobars. This
51 // will remove all current infobars from the container, add the infobars from
52 // |contents|, and show them all. |contents| may be NULL.
53 void ChangeTabContents(TabContentsWrapper* contents);
54
55 // Returns the amount by which to overlap the toolbar above, and, when
56 // |total_height| is non-NULL, set it to the height of the InfoBarContainer
57 // (including overlap).
58 int GetVerticalOverlap(int* total_height);
59
60 // Called by the delegate when the distance between what the top infobar's
61 // "unspoofable" arrow would point to and the top infobar itself changes.
62 // This enables the top infobar to show a longer arrow (e.g. because of a
63 // visible bookmark bar) or shorter (e.g. due to being in a popup window) if
64 // desired.
65 //
66 // IMPORTANT: This MUST NOT result in a call back to
67 // Delegate::InfoBarContainerStateChanged() unless it causes an actual
68 // change, lest we infinitely recurse.
69 void SetMaxTopArrowHeight(int height);
70
71 // Called when a contained infobar has animated or by some other means changed
72 // its height, or when it stops animating. The container is expected to do
73 // anything necessary to respond, e.g. re-layout.
74 void OnInfoBarStateChanged(bool is_animating);
75
76 // Removes the specified InfoBarDelegate from the selected TabContents. This
77 // will notify us back and cause us to close the InfoBar. This is called from
78 // the InfoBar's close button handler.
79 void RemoveDelegate(InfoBarDelegate* delegate);
80
81 // Called by |infobar| to request that it be removed from the container, as it
82 // is about to delete itself. At this point, |infobar| should already be
83 // hidden.
84 void RemoveInfoBar(InfoBar* infobar);
85
86 const Delegate* delegate() const { return delegate_; }
87
88 protected:
89 // Subclasses must call this during destruction, so that we can remove
90 // infobars (which will call the pure virtual functions below) while the
91 // subclass portion of |this| has not yet been destroyed.
92 void RemoveAllInfoBarsForDestruction();
93
94 // These must be implemented on each platform to e.g. adjust the visible
95 // object hierarchy.
96 virtual void PlatformSpecificAddInfoBar(InfoBar* infobar) = 0;
97 virtual void PlatformSpecificRemoveInfoBar(InfoBar* infobar) = 0;
98
99 private:
100 typedef std::vector<InfoBar*> InfoBars;
101
102 // NotificationObserver:
103 virtual void Observe(NotificationType type,
104 const NotificationSource& source,
105 const NotificationDetails& details) OVERRIDE;
106
107 // Removes an InfoBar for the specified delegate, in response to a
108 // notification from the selected TabContents. The InfoBar's disappearance
109 // will be animated if |use_animation| is true.
110 void RemoveInfoBar(InfoBarDelegate* delegate, bool use_animation);
111
112 // Adds |infobar| to this container and calls Show() on it. |animate| is
113 // passed along to infobar->Show(). Depending on the value of
114 // |callback_status|, this calls infobar->set_container(this) either before or
115 // after the call to Show() so that OnInfoBarAnimated() either will or won't
116 // be called as a result.
117 enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK };
118 void AddInfoBar(InfoBar* infobar,
119 bool animate,
120 CallbackStatus callback_status);
121
122 void UpdateInfoBarArrowTargetHeights();
123 int ArrowTargetHeightForInfoBar(size_t infobar_index) const;
124
125 NotificationRegistrar registrar_;
126 Delegate* delegate_;
127 TabContentsWrapper* tab_contents_;
128 InfoBars infobars_;
129
130 // Calculated in SetMaxTopArrowHeight().
131 int top_arrow_target_height_;
132
133 DISALLOW_COPY_AND_ASSIGN(InfoBarContainer);
134 };
135
136 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_CONTAINER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar.cc ('k') | chrome/browser/ui/views/infobars/infobar_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698