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 "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/gfx/image/image_skia.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"
31 namespace message_center
{
33 // Interface that MessageView uses to report clicks and other user actions.
34 // Provided by creator of MessageView.
35 class MessageViewController
{
37 virtual void ClickOnNotification(const std::string
& notification_id
) = 0;
38 virtual void RemoveNotification(const std::string
& notification_id
,
42 // Individual notifications constants.
43 const int kPaddingBetweenItems
= 10;
44 const int kPaddingHorizontal
= 18;
45 const int kWebNotificationButtonWidth
= 32;
46 const int kWebNotificationIconSize
= 40;
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
{
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 ~MessageView() override
;
60 // Updates this view with the new data contained in the notification.
61 virtual void UpdateWithNotification(const Notification
& notification
);
63 // Returns the insets for the shadow it will have for rich notification.
64 static gfx::Insets
GetShadowInsets();
66 // Creates a shadow around the notification.
67 void CreateShadowBorder();
69 bool IsCloseButtonFocused();
70 void RequestFocusOnCloseButton();
72 void set_accessible_name(const base::string16
& accessible_name
) {
73 accessible_name_
= accessible_name
;
76 // Overridden from views::View:
77 void GetAccessibleState(ui::AXViewState
* state
) override
;
78 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
79 bool OnKeyPressed(const ui::KeyEvent
& event
) override
;
80 bool OnKeyReleased(const ui::KeyEvent
& event
) override
;
81 void OnPaint(gfx::Canvas
* canvas
) override
;
82 void OnFocus() override
;
83 void OnBlur() override
;
84 void Layout() override
;
86 // Overridden from ui::EventHandler:
87 void OnGestureEvent(ui::GestureEvent
* event
) override
;
89 // Overridden from ButtonListener:
90 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
92 void set_scroller(views::ScrollView
* scroller
) { scroller_
= scroller
; }
93 std::string
notification_id() { return notification_id_
; }
94 NotifierId
notifier_id() { return notifier_id_
; }
95 const base::string16
& display_source() const { return display_source_
; }
98 // Overridden from views::SlideOutView:
99 void OnSlideOut() override
;
101 views::ImageView
* small_image() { return small_image_view_
.get(); }
102 views::ImageButton
* close_button() { return close_button_
.get(); }
103 views::ScrollView
* scroller() { return scroller_
; }
106 MessageViewController
* controller_
;
107 std::string notification_id_
;
108 NotifierId notifier_id_
;
109 views::View
* background_view_
; // Owned by views hierarchy.
110 scoped_ptr
<views::ImageButton
> close_button_
;
111 scoped_ptr
<views::ImageView
> small_image_view_
;
112 views::ScrollView
* scroller_
;
114 base::string16 accessible_name_
;
116 base::string16 display_source_
;
118 scoped_ptr
<views::Painter
> focus_painter_
;
120 // Changes the background color being used by |background_view_| and schedules
122 void SetDrawBackgroundAsActive(bool active
);
124 DISALLOW_COPY_AND_ASSIGN(MessageView
);
127 } // namespace message_center
129 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_