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