Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / ui / message_center / views / notification_view.h
blobc7612cc6f55fc310543e26ae1de9f9f159f2611c
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_
8 #include <vector>
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"
14 class GURL;
16 namespace views {
17 class ProgressBar;
20 namespace message_center {
22 class BoundedLabel;
23 class MessageCenter;
24 class MessageCenterController;
25 class NotificationButton;
26 class NotificationView;
27 class PaddedButton;
28 class ProportionalImageView;
30 // View that displays all current types of notification (web, basic, image, and
31 // list). Future notification types may be handled by other classes, in which
32 // case instances of those classes would be returned by the Create() factory
33 // method below.
34 class MESSAGE_CENTER_EXPORT NotificationView
35 : public MessageView,
36 public views::ViewTargeterDelegate,
37 public MessageViewController {
38 public:
39 // Creates appropriate MessageViews for notifications. Those currently are
40 // always NotificationView instances but in the future
41 // may be instances of other classes, with the class depending on the
42 // notification type. A notification is top level if it needs to be rendered
43 // outside the browser window. No custom shadows are created for top level
44 // notifications on Linux with Aura.
45 // |controller| may be NULL, but has to be set before the view is shown.
46 static NotificationView* Create(MessageCenterController* controller,
47 const Notification& notification,
48 bool top_level);
49 ~NotificationView() override;
51 // Overridden from views::View:
52 gfx::Size GetPreferredSize() const override;
53 int GetHeightForWidth(int width) const override;
54 void Layout() override;
55 void OnFocus() override;
56 void ScrollRectToVisible(const gfx::Rect& rect) override;
57 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
59 // Overridden from MessageView:
60 void UpdateWithNotification(const Notification& notification) override;
61 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
63 // Overridden from MessageViewController:
64 void ClickOnNotification(const std::string& notification_id) override;
65 void RemoveNotification(const std::string& notification_id,
66 bool by_user) override;
68 void set_controller(MessageCenterController* controller) {
69 controller_ = controller;
72 protected:
73 NotificationView(MessageCenterController* controller,
74 const Notification& notification);
76 private:
77 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, CreateOrUpdateTest);
78 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, FormatContextMessageTest);
79 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, TestLineLimits);
80 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, TestIconSizing);
81 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, TestImageSizing);
82 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonsStateTest);
83 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonCountTest);
85 friend class NotificationViewTest;
87 // views::ViewTargeterDelegate:
88 views::View* TargetForRect(views::View* root, const gfx::Rect& rect) override;
90 void CreateOrUpdateViews(const Notification& notification);
91 void SetAccessibleName(const Notification& notification);
93 void CreateOrUpdateTitleView(const Notification& notification);
94 void CreateOrUpdateMessageView(const Notification& notification);
95 void CreateOrUpdateContextMessageView(const Notification& notification);
96 void CreateOrUpdateProgressBarView(const Notification& notification);
97 void CreateOrUpdateListItemViews(const Notification& notification);
98 void CreateOrUpdateIconView(const Notification& notification);
99 void CreateOrUpdateImageView(const Notification& notification);
100 void CreateOrUpdateActionButtonViews(const Notification& notification);
102 int GetMessageLineLimit(int title_lines, int width) const;
103 int GetMessageHeight(int width, int limit) const;
105 // Formats the context message to be displayed based on |context|
106 // so it shows as much information as possible
107 // given the space available in the ContextMessage section of the
108 // notification.
109 base::string16 FormatContextMessage(const Notification& notification) const;
111 MessageCenterController* controller_; // Weak, lives longer then views.
113 // Describes whether the view should display a hand pointer or not.
114 bool clickable_;
116 // Weak references to NotificationView descendants owned by their parents.
117 views::View* top_view_;
118 BoundedLabel* title_view_;
119 BoundedLabel* message_view_;
120 BoundedLabel* context_message_view_;
121 std::vector<views::View*> item_views_;
122 ProportionalImageView* icon_view_;
123 views::View* bottom_view_;
124 views::View* image_container_;
125 ProportionalImageView* image_view_;
126 views::ProgressBar* progress_bar_view_;
127 std::vector<NotificationButton*> action_buttons_;
128 std::vector<views::View*> separators_;
130 DISALLOW_COPY_AND_ASSIGN(NotificationView);
133 } // namespace message_center
135 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_