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