1 // Copyright (c) 2012 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.
5 // Handles the visible notification (or balloons).
7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_
8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/point.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
17 class BalloonCollection
;
22 // Interface for a view that displays a balloon.
25 virtual ~BalloonView() {}
27 // Show the view on the screen.
28 virtual void Show(Balloon
* balloon
) = 0;
30 // Notify that the content of notification has chagned.
31 virtual void Update() = 0;
33 // Reposition the view to match the position of its balloon.
34 virtual void RepositionToBalloon() = 0;
37 virtual void Close(bool by_user
) = 0;
39 // The total size of the view.
40 virtual gfx::Size
GetSize() const = 0;
42 // The host for the view's contents. May be NULL if an implementation does
43 // not have a host associated with it (i.e. does not do html rendering).
44 virtual BalloonHost
* GetHost() const = 0;
46 // Returns the horizontal margin the content is inset by.
47 static int GetHorizontalMargin();
50 // Represents a Notification on the screen.
53 Balloon(const Notification
& notification
,
55 BalloonCollection
* collection
);
58 const Notification
& notification() const { return *notification_
.get(); }
59 Profile
* profile() const { return profile_
; }
61 gfx::Point
GetPosition() const {
62 return position_
+ offset_
;
64 void SetPosition(const gfx::Point
& upper_left
, bool reposition
);
66 const gfx::Vector2d
& offset() const { return offset_
; }
67 void set_offset(const gfx::Vector2d
& offset
) { offset_
= offset
; }
68 void add_offset(const gfx::Vector2d
& offset
) { offset_
.Add(offset
); }
70 const gfx::Size
& content_size() const { return content_size_
; }
71 void set_content_size(const gfx::Size
& size
) { content_size_
= size
; }
73 const BalloonCollection
* collection() const { return collection_
; }
75 const gfx::Size
& min_scrollbar_size() const { return min_scrollbar_size_
; }
76 void set_min_scrollbar_size(const gfx::Size
& size
) {
77 min_scrollbar_size_
= size
;
80 // Request a new content size for this balloon. This will get passed
81 // to the balloon collection for checking against available space and
82 // min/max restrictions.
83 void ResizeDueToAutoResize(const gfx::Size
& size
);
85 // Provides a view for this balloon. Ownership transfers to this object.
86 void set_view(BalloonView
* balloon_view
);
88 // Returns the balloon view associated with the balloon.
89 BalloonView
* balloon_view() const { return balloon_view_
.get(); }
91 // Returns the viewing size for the balloon (content + frame).
92 gfx::Size
GetViewSize() const { return balloon_view_
->GetSize(); }
97 // Notify that the content of notification has changed.
98 virtual void Update(const Notification
& notification
);
100 // Called when the balloon is clicked by the user.
101 virtual void OnClick();
103 // Called when the user clicks a button in the balloon.
104 virtual void OnButtonClick(int button_index
);
106 // Called when the balloon is closed, either by user (through the UI)
108 virtual void OnClose(bool by_user
);
110 // Called by script to cause the balloon to close.
111 virtual void CloseByScript();
113 // Returns the ID of the extension that created this balloon's notification.
114 std::string
GetExtensionId();
117 // Non-owned pointer to the profile.
120 // The notification being shown in this balloon.
121 scoped_ptr
<Notification
> notification_
;
123 // The collection that this balloon belongs to. Non-owned pointer.
124 BalloonCollection
* collection_
;
126 // The actual UI element for the balloon.
127 scoped_ptr
<BalloonView
> balloon_view_
;
129 // Position and size of the balloon on the screen.
130 gfx::Point position_
;
131 gfx::Size content_size_
;
133 // Temporary offset for balloons that need to be positioned in a non-standard
134 // position for keeping the close buttons under the mouse cursor.
135 gfx::Vector2d offset_
;
137 // Smallest size for this balloon where scrollbars will be shown.
138 gfx::Size min_scrollbar_size_
;
140 DISALLOW_COPY_AND_ASSIGN(Balloon
);
143 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_