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_MESSAGE_VIEW_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "base/strings/string16.h" 10 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkColor.h" 12 #include "ui/gfx/image/image.h" 13 #include "ui/gfx/image/image_skia.h" 14 #include "ui/gfx/insets.h" 15 #include "ui/message_center/message_center_export.h" 16 #include "ui/message_center/notification.h" 17 #include "ui/views/controls/button/button.h" 18 #include "ui/views/controls/slide_out_view.h" 19 20 namespace ui { 21 class MenuModel; 22 } 23 24 namespace views { 25 class ImageButton; 26 class ImageView; 27 class Painter; 28 class ScrollView; 29 } 30 31 namespace message_center { 32 33 // Interface that MessageView uses to report clicks and other user actions. 34 // Provided by creator of MessageView. 35 class MessageViewController { 36 public: 37 virtual void ClickOnNotification(const std::string& notification_id) = 0; 38 virtual void RemoveNotification(const std::string& notification_id, 39 bool by_user) = 0; 40 }; 41 42 // Individual notifications constants. 43 const int kPaddingBetweenItems = 10; 44 const int kPaddingHorizontal = 18; 45 const int kWebNotificationButtonWidth = 32; 46 const int kWebNotificationIconSize = 40; 47 48 // An base class for a notification entry. Contains background, close button 49 // and other elements shared by derived notification views. 50 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView, 51 public views::ButtonListener { 52 public: 53 MessageView(MessageViewController* controller, 54 const std::string& notification_id, 55 const NotifierId& notifier_id, 56 const gfx::ImageSkia& small_image, 57 const base::string16& display_source); 58 virtual ~MessageView(); 59 60 // Updates this view with the new data contained in the notification. 61 virtual void UpdateWithNotification(const Notification& notification); 62 63 // Returns the insets for the shadow it will have for rich notification. 64 static gfx::Insets GetShadowInsets(); 65 66 // Creates a shadow around the notification. 67 void CreateShadowBorder(); 68 69 bool IsCloseButtonFocused(); 70 void RequestFocusOnCloseButton(); 71 set_accessible_name(const base::string16 & accessible_name)72 void set_accessible_name(const base::string16& accessible_name) { 73 accessible_name_ = accessible_name; 74 } 75 76 // Overridden from views::View: 77 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 78 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 79 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 80 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; 81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 82 virtual void OnFocus() OVERRIDE; 83 virtual void OnBlur() OVERRIDE; 84 virtual void Layout() OVERRIDE; 85 86 // Overridden from ui::EventHandler: 87 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 88 89 // Overridden from ButtonListener: 90 virtual void ButtonPressed(views::Button* sender, 91 const ui::Event& event) OVERRIDE; 92 set_scroller(views::ScrollView * scroller)93 void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; } notification_id()94 std::string notification_id() { return notification_id_; } notifier_id()95 NotifierId notifier_id() { return notifier_id_; } display_source()96 const base::string16& display_source() const { return display_source_; } 97 98 protected: 99 // Overridden from views::SlideOutView: 100 virtual void OnSlideOut() OVERRIDE; 101 small_image()102 views::ImageView* small_image() { return small_image_view_.get(); } close_button()103 views::ImageButton* close_button() { return close_button_.get(); } scroller()104 views::ScrollView* scroller() { return scroller_; } 105 106 private: 107 MessageViewController* controller_; 108 std::string notification_id_; 109 NotifierId notifier_id_; 110 views::View* background_view_; // Owned by views hierarchy. 111 scoped_ptr<views::ImageButton> close_button_; 112 scoped_ptr<views::ImageView> small_image_view_; 113 views::ScrollView* scroller_; 114 115 base::string16 accessible_name_; 116 117 base::string16 display_source_; 118 119 scoped_ptr<views::Painter> focus_painter_; 120 121 DISALLOW_COPY_AND_ASSIGN(MessageView); 122 }; 123 124 } // namespace message_center 125 126 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ 127