| 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_CUSTOM_NOTIFICATION_VIEW_H_ | 5 #ifndef UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ |
| 6 #define UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ | 6 #define UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_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_custom_notification_item.h" | 12 #include "ui/arc/notification/arc_custom_notification_item.h" |
| 13 #include "ui/arc/notification/arc_notification_surface_manager.h" |
| 13 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 14 #include "ui/views/controls/button/button.h" | 15 #include "ui/views/controls/button/button.h" |
| 15 #include "ui/views/controls/native/native_view_host.h" | 16 #include "ui/views/controls/native/native_view_host.h" |
| 16 | 17 |
| 17 namespace exo { | 18 namespace exo { |
| 18 class NotificationSurface; | 19 class NotificationSurface; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 class ImageButton; | 23 class ImageButton; |
| 23 class Widget; | 24 class Widget; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace arc { | 27 namespace arc { |
| 27 | 28 |
| 28 class ArcCustomNotificationView : public views::NativeViewHost, | 29 class ArcCustomNotificationView |
| 29 public views::ButtonListener, | 30 : public views::NativeViewHost, |
| 30 public aura::WindowObserver, | 31 public views::ButtonListener, |
| 31 public ArcCustomNotificationItem::Observer { | 32 public aura::WindowObserver, |
| 33 public ArcCustomNotificationItem::Observer, |
| 34 public ArcNotificationSurfaceManager::Observer { |
| 32 public: | 35 public: |
| 33 ArcCustomNotificationView(ArcCustomNotificationItem* item, | 36 explicit ArcCustomNotificationView(ArcCustomNotificationItem* item); |
| 34 exo::NotificationSurface* surface); | |
| 35 ~ArcCustomNotificationView() override; | 37 ~ArcCustomNotificationView() override; |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 class EventForwarder; | 40 class EventForwarder; |
| 39 class SlideHelper; | 41 class SlideHelper; |
| 40 | 42 |
| 41 void CreateFloatingCloseButton(); | 43 void CreateFloatingCloseButton(); |
| 42 void SetSurface(exo::NotificationSurface* surface); | 44 void SetSurface(exo::NotificationSurface* surface); |
| 43 void UpdatePreferredSize(); | 45 void UpdatePreferredSize(); |
| 44 void UpdateCloseButtonVisiblity(); | 46 void UpdateCloseButtonVisiblity(); |
| 47 void UpdatePinnedState(); |
| 48 void UpdateSnapshot(); |
| 49 void AttachSurface(); |
| 45 | 50 |
| 46 // views::NativeViewHost | 51 // views::NativeViewHost |
| 47 void ViewHierarchyChanged( | 52 void ViewHierarchyChanged( |
| 48 const ViewHierarchyChangedDetails& details) override; | 53 const ViewHierarchyChangedDetails& details) override; |
| 49 void Layout() override; | 54 void Layout() override; |
| 55 void OnPaint(gfx::Canvas* canvas) override; |
| 50 void OnKeyEvent(ui::KeyEvent* event) override; | 56 void OnKeyEvent(ui::KeyEvent* event) override; |
| 51 void OnGestureEvent(ui::GestureEvent* event) override; | 57 void OnGestureEvent(ui::GestureEvent* event) override; |
| 52 void OnMouseEntered(const ui::MouseEvent& event) override; | 58 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 53 void OnMouseExited(const ui::MouseEvent& event) override; | 59 void OnMouseExited(const ui::MouseEvent& event) override; |
| 54 | 60 |
| 55 // views::ButtonListener | 61 // views::ButtonListener |
| 56 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 62 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 57 | 63 |
| 58 // aura::WindowObserver | 64 // aura::WindowObserver |
| 59 void OnWindowBoundsChanged(aura::Window* window, | 65 void OnWindowBoundsChanged(aura::Window* window, |
| 60 const gfx::Rect& old_bounds, | 66 const gfx::Rect& old_bounds, |
| 61 const gfx::Rect& new_bounds) override; | 67 const gfx::Rect& new_bounds) override; |
| 62 void OnWindowDestroying(aura::Window* window) override; | 68 void OnWindowDestroying(aura::Window* window) override; |
| 63 | 69 |
| 64 // ArcCustomNotificationItem::Observer | 70 // ArcCustomNotificationItem::Observer |
| 65 void OnItemDestroying() override; | 71 void OnItemDestroying() override; |
| 66 void OnItemPinnedChanged() override; | 72 void OnItemUpdated() override; |
| 67 void OnItemNotificationSurfaceRemoved() override; | 73 |
| 74 // ArcNotificationSurfaceManager::Observer: |
| 75 void OnNotificationSurfaceAdded(exo::NotificationSurface* surface) override; |
| 76 void OnNotificationSurfaceRemoved(exo::NotificationSurface* surface) override; |
| 68 | 77 |
| 69 ArcCustomNotificationItem* item_ = nullptr; | 78 ArcCustomNotificationItem* item_ = nullptr; |
| 70 exo::NotificationSurface* surface_ = nullptr; | 79 exo::NotificationSurface* surface_ = nullptr; |
| 71 | 80 |
| 81 const std::string notification_key_; |
| 82 |
| 72 // A pre-target event handler to forward events on the surface to this view. | 83 // A pre-target event handler to forward events on the surface to this view. |
| 73 // Using a pre-target event handler instead of a target handler on the surface | 84 // Using a pre-target event handler instead of a target handler on the surface |
| 74 // window because it has descendant aura::Window and the events on them need | 85 // window because it has descendant aura::Window and the events on them need |
| 75 // to be handled as well. | 86 // to be handled as well. |
| 76 // TODO(xiyuan): Revisit after exo::Surface no longer has an aura::Window. | 87 // TODO(xiyuan): Revisit after exo::Surface no longer has an aura::Window. |
| 77 std::unique_ptr<EventForwarder> event_forwarder_; | 88 std::unique_ptr<EventForwarder> event_forwarder_; |
| 78 | 89 |
| 79 // A helper to observe slide transform/animation and use surface layer copy | 90 // A helper to observe slide transform/animation and use surface layer copy |
| 80 // when a slide is in progress and restore the surface when it finishes. | 91 // when a slide is in progress and restore the surface when it finishes. |
| 81 std::unique_ptr<SlideHelper> slide_helper_; | 92 std::unique_ptr<SlideHelper> slide_helper_; |
| 82 | 93 |
| 83 // A close button on top of NotificationSurface. Needed because the | 94 // A close button on top of NotificationSurface. Needed because the |
| 84 // aura::Window of NotificationSurface is added after hosting widget's | 95 // aura::Window of NotificationSurface is added after hosting widget's |
| 85 // RootView thus standard notification close button is always below | 96 // RootView thus standard notification close button is always below |
| 86 // it. | 97 // it. |
| 87 std::unique_ptr<views::Widget> floating_close_button_widget_; | 98 std::unique_ptr<views::Widget> floating_close_button_widget_; |
| 88 | 99 |
| 89 views::ImageButton* floating_close_button_ = nullptr; | 100 views::ImageButton* floating_close_button_ = nullptr; |
| 90 | 101 |
| 91 // Protects from call loops between Layout and OnWindowBoundsChanged. | 102 // Protects from call loops between Layout and OnWindowBoundsChanged. |
| 92 bool in_layout_ = false; | 103 bool in_layout_ = false; |
| 93 | 104 |
| 94 DISALLOW_COPY_AND_ASSIGN(ArcCustomNotificationView); | 105 DISALLOW_COPY_AND_ASSIGN(ArcCustomNotificationView); |
| 95 }; | 106 }; |
| 96 | 107 |
| 97 } // namespace arc | 108 } // namespace arc |
| 98 | 109 |
| 99 #endif // UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ | 110 #endif // UI_ARC_NOTIFICATION_ARC_CUSTOM_NOTIFICATION_VIEW_H_ |
| OLD | NEW |