Update metrics verification for dev-proxy.
[chromium-blink-merge.git] / ui / message_center / views / notification_view.h
blob623f1201a4bc1ce3ddeca2de4a532decf1df5f62
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 namespace views {
15 class ProgressBar;
18 namespace message_center {
20 class BoundedLabel;
21 class MessageCenter;
22 class MessageCenterController;
23 class NotificationButton;
24 class NotificationView;
25 class PaddedButton;
27 // View that displays all current types of notification (web, basic, image, and
28 // list). Future notification types may be handled by other classes, in which
29 // case instances of those classes would be returned by the Create() factory
30 // method below.
31 class MESSAGE_CENTER_EXPORT NotificationView
32 : public MessageView,
33 public views::ViewTargeterDelegate,
34 public MessageViewController {
35 public:
36 // Creates appropriate MessageViews for notifications. Those currently are
37 // always NotificationView instances but in the future
38 // may be instances of other classes, with the class depending on the
39 // notification type. A notification is top level if it needs to be rendered
40 // outside the browser window. No custom shadows are created for top level
41 // notifications on Linux with Aura.
42 // |controller| may be NULL, but has to be set before the view is shown.
43 static NotificationView* Create(MessageCenterController* controller,
44 const Notification& notification,
45 bool top_level);
46 virtual ~NotificationView();
48 // Overridden from views::View:
49 virtual gfx::Size GetPreferredSize() const OVERRIDE;
50 virtual int GetHeightForWidth(int width) const OVERRIDE;
51 virtual void Layout() OVERRIDE;
52 virtual void OnFocus() OVERRIDE;
53 virtual void ScrollRectToVisible(const gfx::Rect& rect) OVERRIDE;
54 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
56 // Overridden from MessageView:
57 virtual void UpdateWithNotification(
58 const Notification& notification) OVERRIDE;
59 virtual void ButtonPressed(views::Button* sender,
60 const ui::Event& event) OVERRIDE;
62 // Overridden from MessageViewController:
63 virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE;
64 virtual void RemoveNotification(const std::string& notification_id,
65 bool by_user) OVERRIDE;
67 void set_controller(MessageCenterController* controller) {
68 controller_ = controller;
71 protected:
72 NotificationView(MessageCenterController* controller,
73 const Notification& notification);
75 private:
76 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, CreateOrUpdateTest);
77 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, TestLineLimits);
78 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonsStateTest);
79 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, UpdateButtonCountTest);
81 friend class NotificationViewTest;
83 // views::ViewTargeterDelegate:
84 virtual views::View* TargetForRect(views::View* root,
85 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.
105 bool clickable_;
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 views::View* icon_view_;
114 views::View* bottom_view_;
115 views::View* image_view_;
116 views::ProgressBar* progress_bar_view_;
117 std::vector<NotificationButton*> action_buttons_;
118 std::vector<views::View*> separators_;
120 DISALLOW_COPY_AND_ASSIGN(NotificationView);
123 } // namespace message_center
125 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_