Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / message_center / views / toast_contents_view.h
1 // Copyright (c) 2013 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_TOAST_CONTENTS_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_TOAST_CONTENTS_VIEW_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "ui/gfx/animation/animation_delegate.h"
11 #include "ui/gfx/native_widget_types.h"
12 #include "ui/gfx/point.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
15 #include "ui/message_center/views/message_center_controller.h"
16 #include "ui/views/widget/widget_delegate.h"
17
18 namespace gfx {
19 class Animation;
20 class SlideAnimation;
21 }
22
23 namespace views {
24 class View;
25 }
26
27 namespace message_center {
28
29 class MessagePopupCollection;
30 class MessageView;
31 class Notification;
32
33 // The widget host for a popup. Also implements MessageCenterController
34 // which delegates over to MessagePopupCollection, but takes care about
35 // checking the weakref since MessagePopupCollection may disappear before
36 // widget/views are closed/destructed.
37 class ToastContentsView : public views::WidgetDelegateView,
38                           public MessageCenterController,
39                           public gfx::AnimationDelegate {
40  public:
41   // Computes the size of a toast assuming it will host the given view.
42   static gfx::Size GetToastSizeForView(views::View* view);
43
44   ToastContentsView(const std::string& notification_id,
45                     base::WeakPtr<MessagePopupCollection> collection);
46   virtual ~ToastContentsView();
47
48   // Sets the inner view of the toast. If it has contents already,
49   // |a11y_feedback_for_updates| causes the view to notify that the
50   // accessibility message should be read after this update.
51   void SetContents(MessageView* view, bool a11y_feedback_for_updates);
52
53   // Shows the new toast for the first time, animated.
54   // |origin| is the right-bottom corner of the toast.
55   void RevealWithAnimation(gfx::Point origin);
56
57   // Disconnectes the toast from the rest of the system immediately and start
58   // an animation. Once animation finishes, closes the widget.
59   void CloseWithAnimation();
60
61   void SetBoundsWithAnimation(gfx::Rect new_bounds);
62
63   // Origin and bounds are not 'instant', but rather 'current stable values',
64   // there could be animation in progress that targets these values.
65   gfx::Point origin() { return origin_; }
66   gfx::Rect bounds() { return gfx::Rect(origin_, preferred_size_); }
67
68   const std::string& id() { return id_; }
69
70   // Overridden from views::View:
71   virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
72   virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
73   virtual void Layout() OVERRIDE;
74   virtual gfx::Size GetPreferredSize() OVERRIDE;
75   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
76
77  private:
78   // Overridden from MessageCenterController:
79   virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE;
80   virtual void RemoveNotification(const std::string& notification_id,
81                                   bool by_user) OVERRIDE;
82   virtual scoped_ptr<ui::MenuModel> CreateMenuModel(
83       const NotifierId& notifier_id,
84       const base::string16& display_source) OVERRIDE;
85   virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE;
86   virtual void ClickOnNotificationButton(const std::string& notification_id,
87                                          int button_index) OVERRIDE;
88
89   // Overridden from gfx::AnimationDelegate:
90   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
91   virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
92   virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE;
93
94   // Overridden from views::WidgetDelegate:
95   virtual views::View* GetContentsView() OVERRIDE;
96   virtual void WindowClosing() OVERRIDE;
97   virtual bool CanActivate() const OVERRIDE;
98   virtual void OnDisplayChanged() OVERRIDE;
99   virtual void OnWorkAreaChanged() OVERRIDE;
100
101   // Initialization and update.
102   void CreateWidget(gfx::NativeView parent);
103
104   // Immediately moves the toast without any sort of delay or animation.
105   void SetBoundsInstantly(gfx::Rect new_bounds);
106
107   // Given the bounds of a toast on the screen, compute the bouds for that
108   // toast in 'closed' state. The 'closed' state is used as origin/destination
109   // in reveal/closing animations.
110   gfx::Rect GetClosedToastBounds(gfx::Rect bounds);
111
112   void StartFadeIn();
113   void StartFadeOut();  // Will call Widget::Close() when animation ends.
114   void OnBoundsAnimationEndedOrCancelled(const gfx::Animation* animation);
115
116   base::WeakPtr<MessagePopupCollection> collection_;
117
118   // Id if the corresponding Notification.
119   std::string id_;
120
121   scoped_ptr<gfx::SlideAnimation> bounds_animation_;
122   scoped_ptr<gfx::SlideAnimation> fade_animation_;
123
124   bool is_animating_bounds_;
125   gfx::Rect animated_bounds_start_;
126   gfx::Rect animated_bounds_end_;
127   // Started closing animation, will close at the end.
128   bool is_closing_;
129   // Closing animation - when it ends, close the widget. Weak, only used
130   // for referential equality.
131   gfx::Animation* closing_animation_;
132
133   gfx::Point origin_;
134   gfx::Size preferred_size_;
135
136   DISALLOW_COPY_AND_ASSIGN(ToastContentsView);
137 };
138
139 }  // namespace message_center
140
141 #endif // UI_MESSAGE_CENTER_VIEWS_TOAST_CONTENTS_VIEW_H_