OLD | NEW |
| (Empty) |
1 // Copyright 2016 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_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ | |
6 #define UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "ui/arc/notification/arc_notification_content_view_delegate.h" | |
13 #include "ui/arc/notification/arc_notification_item.h" | |
14 #include "ui/arc/notification/arc_notification_surface_manager.h" | |
15 #include "ui/aura/window_observer.h" | |
16 #include "ui/gfx/animation/animation_delegate.h" | |
17 #include "ui/message_center/views/padded_button.h" | |
18 #include "ui/views/controls/button/button.h" | |
19 #include "ui/views/controls/native/native_view_host.h" | |
20 | |
21 namespace exo { | |
22 class NotificationSurface; | |
23 } | |
24 | |
25 namespace gfx { | |
26 class LinearAnimation; | |
27 } | |
28 | |
29 namespace ui { | |
30 struct AXActionData; | |
31 } | |
32 | |
33 namespace views { | |
34 class FocusTraversable; | |
35 class Widget; | |
36 } | |
37 | |
38 namespace arc { | |
39 | |
40 // ArcCustomNotificationView is a view to host NotificationSurface and show the | |
41 // content in itself. This is implemented as a child of ArcNotificationView. | |
42 // TODO(yoshiki): Rename this class to ArcNotificationContentsView. | |
43 class ArcCustomNotificationView | |
44 : public views::NativeViewHost, | |
45 public views::ButtonListener, | |
46 public aura::WindowObserver, | |
47 public ArcNotificationItem::Observer, | |
48 public ArcNotificationSurfaceManager::Observer, | |
49 public gfx::AnimationDelegate { | |
50 public: | |
51 explicit ArcCustomNotificationView(ArcNotificationItem* item); | |
52 ~ArcCustomNotificationView() override; | |
53 | |
54 std::unique_ptr<ArcNotificationContentViewDelegate> | |
55 CreateContentViewDelegate(); | |
56 | |
57 private: | |
58 class ContentViewDelegate; | |
59 class EventForwarder; | |
60 class SettingsButton; | |
61 class SlideHelper; | |
62 | |
63 // A image button class used for the settings button and the close button. | |
64 // We can't use forward declaration for this class due to std::unique_ptr<> | |
65 // requires size of this class. | |
66 class ControlButton : public message_center::PaddedButton { | |
67 public: | |
68 explicit ControlButton(ArcCustomNotificationView* owner); | |
69 void OnFocus() override; | |
70 void OnBlur() override; | |
71 | |
72 private: | |
73 ArcCustomNotificationView* const owner_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(ControlButton); | |
76 }; | |
77 | |
78 void CreateCloseButton(); | |
79 void CreateSettingsButton(); | |
80 void MaybeCreateFloatingControlButtons(); | |
81 void SetSurface(exo::NotificationSurface* surface); | |
82 void UpdatePreferredSize(); | |
83 void UpdateControlButtonsVisibility(); | |
84 void UpdatePinnedState(); | |
85 void UpdateSnapshot(); | |
86 void AttachSurface(); | |
87 void ActivateToast(); | |
88 void StartControlButtonsColorAnimation(); | |
89 bool ShouldUpdateControlButtonsColor() const; | |
90 | |
91 // views::NativeViewHost | |
92 void ViewHierarchyChanged( | |
93 const ViewHierarchyChangedDetails& details) override; | |
94 void Layout() override; | |
95 void OnPaint(gfx::Canvas* canvas) override; | |
96 void OnMouseEntered(const ui::MouseEvent& event) override; | |
97 void OnMouseExited(const ui::MouseEvent& event) override; | |
98 void OnFocus() override; | |
99 void OnBlur() override; | |
100 views::FocusTraversable* GetFocusTraversable() override; | |
101 bool HandleAccessibleAction(const ui::AXActionData& action) override; | |
102 | |
103 // views::ButtonListener | |
104 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
105 | |
106 // aura::WindowObserver | |
107 void OnWindowBoundsChanged(aura::Window* window, | |
108 const gfx::Rect& old_bounds, | |
109 const gfx::Rect& new_bounds) override; | |
110 void OnWindowDestroying(aura::Window* window) override; | |
111 | |
112 // ArcNotificationItem::Observer | |
113 void OnItemDestroying() override; | |
114 void OnItemUpdated() override; | |
115 | |
116 // ArcNotificationSurfaceManager::Observer: | |
117 void OnNotificationSurfaceAdded(exo::NotificationSurface* surface) override; | |
118 void OnNotificationSurfaceRemoved(exo::NotificationSurface* surface) override; | |
119 | |
120 // AnimationDelegate | |
121 void AnimationEnded(const gfx::Animation* animation) override; | |
122 void AnimationProgressed(const gfx::Animation* animation) override; | |
123 | |
124 // If |item_| is null, we may be about to be destroyed. In this case, | |
125 // we have to be careful about what we do. | |
126 ArcNotificationItem* item_ = nullptr; | |
127 exo::NotificationSurface* surface_ = nullptr; | |
128 | |
129 const std::string notification_key_; | |
130 | |
131 // A pre-target event handler to forward events on the surface to this view. | |
132 // Using a pre-target event handler instead of a target handler on the surface | |
133 // window because it has descendant aura::Window and the events on them need | |
134 // to be handled as well. | |
135 // TODO(xiyuan): Revisit after exo::Surface no longer has an aura::Window. | |
136 std::unique_ptr<EventForwarder> event_forwarder_; | |
137 | |
138 // A helper to observe slide transform/animation and use surface layer copy | |
139 // when a slide is in progress and restore the surface when it finishes. | |
140 std::unique_ptr<SlideHelper> slide_helper_; | |
141 | |
142 // A control buttons on top of NotificationSurface. Needed because the | |
143 // aura::Window of NotificationSurface is added after hosting widget's | |
144 // RootView thus standard notification control buttons are always below | |
145 // it. | |
146 std::unique_ptr<views::Widget> floating_control_buttons_widget_; | |
147 | |
148 views::View* control_buttons_view_ = nullptr; | |
149 std::unique_ptr<ControlButton> close_button_; | |
150 ControlButton* settings_button_ = nullptr; | |
151 | |
152 // Protects from call loops between Layout and OnWindowBoundsChanged. | |
153 bool in_layout_ = false; | |
154 | |
155 std::unique_ptr<gfx::LinearAnimation> control_button_color_animation_; | |
156 | |
157 DISALLOW_COPY_AND_ASSIGN(ArcCustomNotificationView); | |
158 }; | |
159 | |
160 } // namespace arc | |
161 | |
162 #endif // UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ | |
OLD | NEW |