Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1186)

Side by Side Diff: ui/arc/notification/arc_notification_content_view.h

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

Powered by Google App Engine
This is Rietveld 408576698