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"
12 #include "ui/views/view_targeter_delegate.h"
18 namespace message_center
{
22 class MessageCenterController
;
23 class NotificationButton
;
24 class NotificationView
;
26 class ProportionalImageView
;
28 // View that displays all current types of notification (web, basic, image, and
29 // list). Future notification types may be handled by other classes, in which
30 // case instances of those classes would be returned by the Create() factory
32 class MESSAGE_CENTER_EXPORT NotificationView
34 public views::ViewTargeterDelegate
,
35 public MessageViewController
{
37 // Creates appropriate MessageViews for notifications. Those currently are
38 // always NotificationView instances but in the future
39 // may be instances of other classes, with the class depending on the
40 // notification type. A notification is top level if it needs to be rendered
41 // outside the browser window. No custom shadows are created for top level
42 // notifications on Linux with Aura.
43 // |controller| may be NULL, but has to be set before the view is shown.
44 static NotificationView
* Create(MessageCenterController
* controller
,
45 const Notification
& notification
,
47 ~NotificationView() override
;
49 // Overridden from views::View:
50 gfx::Size
GetPreferredSize() const override
;
51 int GetHeightForWidth(int width
) const override
;
52 void Layout() override
;
53 void OnFocus() override
;
54 void ScrollRectToVisible(const gfx::Rect
& rect
) override
;
55 gfx::NativeCursor
GetCursor(const ui::MouseEvent
& event
) override
;
57 // Overridden from MessageView:
58 void UpdateWithNotification(const Notification
& notification
) override
;
59 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
61 // Overridden from MessageViewController:
62 void ClickOnNotification(const std::string
& notification_id
) override
;
63 void RemoveNotification(const std::string
& notification_id
,
64 bool by_user
) override
;
66 void set_controller(MessageCenterController
* controller
) {
67 controller_
= controller
;
71 NotificationView(MessageCenterController
* controller
,
72 const Notification
& notification
);
75 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, CreateOrUpdateTest
);
76 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, TestLineLimits
);
77 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, TestIconSizing
);
78 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, TestImageSizing
);
79 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, UpdateButtonsStateTest
);
80 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest
, UpdateButtonCountTest
);
82 friend class NotificationViewTest
;
84 // views::ViewTargeterDelegate:
85 views::View
* TargetForRect(views::View
* root
, const gfx::Rect
& rect
) override
;
87 void CreateOrUpdateViews(const Notification
& notification
);
88 void SetAccessibleName(const Notification
& notification
);
90 void CreateOrUpdateTitleView(const Notification
& notification
);
91 void CreateOrUpdateMessageView(const Notification
& notification
);
92 void CreateOrUpdateContextMessageView(const Notification
& notification
);
93 void CreateOrUpdateProgressBarView(const Notification
& notification
);
94 void CreateOrUpdateListItemViews(const Notification
& notification
);
95 void CreateOrUpdateIconView(const Notification
& notification
);
96 void CreateOrUpdateImageView(const Notification
& notification
);
97 void CreateOrUpdateActionButtonViews(const Notification
& notification
);
99 int GetMessageLineLimit(int title_lines
, int width
) const;
100 int GetMessageHeight(int width
, int limit
) const;
102 MessageCenterController
* controller_
; // Weak, lives longer then views.
104 // Describes whether the view should display a hand pointer or not.
107 // Weak references to NotificationView descendants owned by their parents.
108 views::View
* top_view_
;
109 BoundedLabel
* title_view_
;
110 BoundedLabel
* message_view_
;
111 BoundedLabel
* context_message_view_
;
112 std::vector
<views::View
*> item_views_
;
113 ProportionalImageView
* icon_view_
;
114 views::View
* bottom_view_
;
115 views::View
* image_container_
;
116 ProportionalImageView
* image_view_
;
117 views::ProgressBar
* progress_bar_view_
;
118 std::vector
<NotificationButton
*> action_buttons_
;
119 std::vector
<views::View
*> separators_
;
121 DISALLOW_COPY_AND_ASSIGN(NotificationView
);
124 } // namespace message_center
126 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_