Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / message_center / views / message_view.h
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   ~MessageView() override;
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
72   void set_accessible_name(const base::string16& accessible_name) {
73     accessible_name_ = accessible_name;
74   }
75
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;
85
86   // Overridden from ui::EventHandler:
87   void OnGestureEvent(ui::GestureEvent* event) override;
88
89   // Overridden from ButtonListener:
90   void ButtonPressed(views::Button* sender, const ui::Event& event) override;
91
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_; }
96
97  protected:
98   // Overridden from views::SlideOutView:
99   void OnSlideOut() override;
100
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_; }
104
105  private:
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_;
113
114   base::string16 accessible_name_;
115
116   base::string16 display_source_;
117
118   scoped_ptr<views::Painter> focus_painter_;
119
120   // Changes the background color being used by |background_view_| and schedules
121   // a paint.
122   void SetDrawBackgroundAsActive(bool active);
123
124   DISALLOW_COPY_AND_ASSIGN(MessageView);
125 };
126
127 }  // namespace message_center
128
129 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_