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 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
10 #include "ui/message_center/message_center_export.h"
11 #include "ui/message_center/views/message_view.h"
17 namespace message_center
{
21 class MessageCenterController
;
22 class NotificationButton
;
23 class NotificationView
;
26 // View that displays all current types of notification (web, basic, image, and
27 // list). Future notification types may be handled by other classes, in which
28 // case instances of those classes would be returned by the Create() factory
30 class MESSAGE_CENTER_EXPORT NotificationView
: public MessageView
,
31 public MessageViewController
{
33 // Creates appropriate MessageViews for notifications. Those currently are
34 // always NotificationView instances but in the future
35 // may be instances of other classes, with the class depending on the
36 // notification type. A notification is top level if it needs to be rendered
37 // outside the browser window. No custom shadows are created for top level
38 // notifications on Linux with Aura.
39 // |controller| may be NULL, but has to be set before the view is shown.
40 static NotificationView
* Create(MessageCenterController
* controller
,
41 const Notification
& notification
,
43 virtual ~NotificationView();
45 // Overridden from views::View:
46 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
47 virtual int GetHeightForWidth(int width
) const OVERRIDE
;
48 virtual void Layout() OVERRIDE
;
49 virtual void OnFocus() OVERRIDE
;
50 virtual void ScrollRectToVisible(const gfx::Rect
& rect
) OVERRIDE
;
51 virtual views::View
* GetEventHandlerForRect(const gfx::Rect
& rect
) OVERRIDE
;
52 virtual gfx::NativeCursor
GetCursor(const ui::MouseEvent
& event
) OVERRIDE
;
54 // Overridden from MessageView:
55 virtual void UpdateWithNotification(
56 const Notification
& notification
) OVERRIDE
;
57 virtual void ButtonPressed(views::Button
* sender
,
58 const ui::Event
& event
) OVERRIDE
;
60 // Overridden from MessageViewController:
61 virtual void ClickOnNotification(const std::string
& notification_id
) OVERRIDE
;
62 virtual void RemoveNotification(const std::string
& notification_id
,
63 bool by_user
) OVERRIDE
;
65 void set_controller(MessageCenterController
* controller
) {
66 controller_
= controller
;
70 NotificationView(MessageCenterController
* controller
,
71 const Notification
& notification
);
74 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, CreateOrUpdateTest
);
75 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, TestLineLimits
);
76 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, UpdateButtonsStateTest
);
77 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, UpdateButtonCountTest
);
79 void CreateOrUpdateViews(const Notification
& notification
);
80 void SetAccessibleName(const Notification
& notification
);
82 void CreateOrUpdateTitleView(const Notification
& notification
);
83 void CreateOrUpdateMessageView(const Notification
& notification
);
84 void CreateOrUpdateContextMessageView(const Notification
& notification
);
85 void CreateOrUpdateProgressBarView(const Notification
& notification
);
86 void CreateOrUpdateListItemViews(const Notification
& notification
);
87 void CreateOrUpdateIconView(const Notification
& notification
);
88 void CreateOrUpdateImageView(const Notification
& notification
);
89 void CreateOrUpdateActionButtonViews(const Notification
& notification
);
91 int GetMessageLineLimit(int title_lines
, int width
) const;
92 int GetMessageHeight(int width
, int limit
) const;
94 MessageCenterController
* controller_
; // Weak, lives longer then views.
96 // Describes whether the view should display a hand pointer or not.
99 // Weak references to NotificationView descendants owned by their parents.
100 views::View
* top_view_
;
101 BoundedLabel
* title_view_
;
102 BoundedLabel
* message_view_
;
103 BoundedLabel
* context_message_view_
;
104 std::vector
<views::View
*> item_views_
;
105 views::View
* icon_view_
;
106 views::View
* bottom_view_
;
107 views::View
* image_view_
;
108 views::ProgressBar
* progress_bar_view_
;
109 std::vector
<NotificationButton
*> action_buttons_
;
110 std::vector
<views::View
*> separators_
;
112 DISALLOW_COPY_AND_ASSIGN(NotificationView
);
115 } // namespace message_center
117 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_