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 #include "ui/views/view_targeter_delegate.h" 13 14 namespace views { 15 class ProgressBar; 16 } 17 18 namespace message_center { 19 20 class BoundedLabel; 21 class MessageCenter; 22 class MessageCenterController; 23 class NotificationButton; 24 class NotificationView; 25 class PaddedButton; 26 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(); 47 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; 55 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; 61 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; 66 set_controller(MessageCenterController * controller)67 void set_controller(MessageCenterController* controller) { 68 controller_ = controller; 69 } 70 71 protected: 72 NotificationView(MessageCenterController* controller, 73 const Notification& notification); 74 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); 80 81 friend class NotificationViewTest; 82 83 // views::ViewTargeterDelegate: 84 virtual views::View* TargetForRect(views::View* root, 85 const gfx::Rect& rect) OVERRIDE; 86 87 void CreateOrUpdateViews(const Notification& notification); 88 void SetAccessibleName(const Notification& notification); 89 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); 98 99 int GetMessageLineLimit(int title_lines, int width) const; 100 int GetMessageHeight(int width, int limit) const; 101 102 MessageCenterController* controller_; // Weak, lives longer then views. 103 104 // Describes whether the view should display a hand pointer or not. 105 bool clickable_; 106 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_; 119 120 DISALLOW_COPY_AND_ASSIGN(NotificationView); 121 }; 122 123 } // namespace message_center 124 125 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ 126