• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
7 
8 #include <vector>
9 
10 #include "ui/message_center/message_center_export.h"
11 #include "ui/message_center/views/message_view.h"
12 
13 namespace views {
14 class ProgressBar;
15 }
16 
17 namespace message_center {
18 
19 class BoundedLabel;
20 class MessageCenter;
21 class MessageCenterController;
22 class NotificationButton;
23 class NotificationView;
24 class PaddedButton;
25 
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
29 // method below.
30 class MESSAGE_CENTER_EXPORT NotificationView : public MessageView,
31                                                public MessageViewController {
32  public:
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,
42                                   bool top_level);
43   virtual ~NotificationView();
44 
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;
53 
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;
59 
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;
64 
set_controller(MessageCenterController * controller)65   void set_controller(MessageCenterController* controller) {
66     controller_ = controller;
67   }
68 
69  protected:
70   NotificationView(MessageCenterController* controller,
71                    const Notification& notification);
72 
73  private:
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);
78 
79   friend class NotificationViewTest;
80 
81   void CreateOrUpdateViews(const Notification& notification);
82   void SetAccessibleName(const Notification& notification);
83 
84   void CreateOrUpdateTitleView(const Notification& notification);
85   void CreateOrUpdateMessageView(const Notification& notification);
86   void CreateOrUpdateContextMessageView(const Notification& notification);
87   void CreateOrUpdateProgressBarView(const Notification& notification);
88   void CreateOrUpdateListItemViews(const Notification& notification);
89   void CreateOrUpdateIconView(const Notification& notification);
90   void CreateOrUpdateImageView(const Notification& notification);
91   void CreateOrUpdateActionButtonViews(const Notification& notification);
92 
93   int GetMessageLineLimit(int title_lines, int width) const;
94   int GetMessageHeight(int width, int limit) const;
95 
96   MessageCenterController* controller_;  // Weak, lives longer then views.
97 
98   // Describes whether the view should display a hand pointer or not.
99   bool clickable_;
100 
101   // Weak references to NotificationView descendants owned by their parents.
102   views::View* top_view_;
103   BoundedLabel* title_view_;
104   BoundedLabel* message_view_;
105   BoundedLabel* context_message_view_;
106   std::vector<views::View*> item_views_;
107   views::View* icon_view_;
108   views::View* bottom_view_;
109   views::View* image_view_;
110   views::ProgressBar* progress_bar_view_;
111   std::vector<NotificationButton*> action_buttons_;
112   std::vector<views::View*> separators_;
113 
114   DISALLOW_COPY_AND_ASSIGN(NotificationView);
115 };
116 
117 }  // namespace message_center
118 
119 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
120