• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
15 
16 namespace ui {
17 class MenuModel;
18 }
19 
20 namespace views {
21 class ImageButton;
22 class ImageView;
23 class Painter;
24 class ScrollView;
25 }
26 
27 namespace message_center {
28 
29 // Interface that MessageView uses to report clicks and other user actions.
30 // Provided by creator of MessageView.
31 class MessageViewController {
32  public:
33   virtual void ClickOnNotification(const std::string& notification_id) = 0;
34   virtual void RemoveNotification(const std::string& notification_id,
35                                   bool by_user) = 0;
36 };
37 
38 // Individual notifications constants.
39 const int kPaddingBetweenItems = 10;
40 const int kPaddingHorizontal = 18;
41 const int kWebNotificationButtonWidth = 32;
42 const int kWebNotificationIconSize = 40;
43 
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 {
48  public:
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();
55 
56   // Updates this view with the new data contained in the notification.
57   virtual void UpdateWithNotification(const Notification& notification);
58 
59   // Returns the insets for the shadow it will have for rich notification.
60   static gfx::Insets GetShadowInsets();
61 
62   // Creates a shadow around the notification.
63   void CreateShadowBorder();
64 
65   bool IsCloseButtonFocused();
66   void RequestFocusOnCloseButton();
67 
set_accessible_name(const base::string16 & accessible_name)68   void set_accessible_name(const base::string16& accessible_name) {
69     accessible_name_ = accessible_name;
70   }
71 
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;
81 
82   // Overridden from ui::EventHandler:
83   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
84 
85   // Overridden from ButtonListener:
86   virtual void ButtonPressed(views::Button* sender,
87                              const ui::Event& event) OVERRIDE;
88 
set_scroller(views::ScrollView * scroller)89   void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; }
notification_id()90   std::string notification_id() { return notification_id_; }
notifier_id()91   NotifierId notifier_id() { return notifier_id_; }
display_source()92   const base::string16& display_source() const { return display_source_; }
93 
94  protected:
95   // Overridden from views::SlideOutView:
96   virtual void OnSlideOut() OVERRIDE;
97 
small_image()98   views::ImageView* small_image() { return small_image_view_.get(); }
close_button()99   views::ImageButton* close_button() { return close_button_.get(); }
scroller()100   views::ScrollView* scroller() { return scroller_; }
101 
102  private:
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_;
110 
111   base::string16 accessible_name_;
112 
113   base::string16 display_source_;
114 
115   scoped_ptr<views::Painter> focus_painter_;
116 
117   DISALLOW_COPY_AND_ASSIGN(MessageView);
118 };
119 
120 }  // namespace message_center
121 
122 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_
123