1 // Copyright 2018 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_MESSAGE_POPUP_VIEW_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_VIEW_H_ 7 8 #include "base/scoped_observer.h" 9 #include "ui/message_center/message_center_export.h" 10 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget_delegate.h" 12 #include "ui/views/widget/widget_observer.h" 13 14 namespace message_center { 15 16 class MessagePopupCollection; 17 class MessageView; 18 class Notification; 19 20 // The widget delegate of a notification popup. The view is owned by the widget. 21 class MESSAGE_CENTER_EXPORT MessagePopupView : public views::WidgetDelegateView, 22 public views::WidgetObserver { 23 public: 24 MessagePopupView(const Notification& notification, 25 MessagePopupCollection* popup_collection); 26 ~MessagePopupView() override; 27 28 // Update notification contents to |notification|. Virtual for unit testing. 29 virtual void UpdateContents(const Notification& notification); 30 31 // Return opacity of the widget. 32 float GetOpacity() const; 33 34 // Sets widget bounds. 35 void SetPopupBounds(const gfx::Rect& bounds); 36 37 // Set widget opacity. 38 void SetOpacity(float opacity); 39 40 // Collapses the notification unless the user is interacting with it. The 41 // request can be ignored. Virtual for unit testing. 42 virtual void AutoCollapse(); 43 44 // Shows popup. After this call, MessagePopupView should be owned by the 45 // widget. 46 void Show(); 47 48 // Closes popup. It should be callable even if Show() is not called, and 49 // in such case MessagePopupView should be deleted. Virtual for unit testing. 50 virtual void Close(); 51 52 // views::WidgetDelegateView: 53 void OnMouseEntered(const ui::MouseEvent& event) override; 54 void OnMouseExited(const ui::MouseEvent& event) override; 55 void ChildPreferredSizeChanged(views::View* child) override; 56 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 57 const char* GetClassName() const override; 58 void OnDisplayChanged() override; 59 void OnWorkAreaChanged() override; 60 void OnFocus() override; 61 62 // views::WidgetObserver: 63 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; 64 void OnWidgetDestroyed(views::Widget* widget) override; 65 is_hovered()66 bool is_hovered() const { return is_hovered_; } is_active()67 bool is_active() const { return is_active_; } 68 message_view()69 MessageView* message_view() { return message_view_; } 70 71 protected: 72 // For unit testing. 73 MessagePopupView(MessagePopupCollection* popup_collection); 74 75 private: 76 // True if the view has a widget and the widget is not closed. 77 bool IsWidgetValid() const; 78 79 // Owned by views hierarchy. 80 MessageView* message_view_; 81 82 // Unowned. 83 MessagePopupCollection* const popup_collection_; 84 85 const bool a11y_feedback_on_init_; 86 bool is_hovered_ = false; 87 bool is_active_ = false; 88 89 ScopedObserver<views::Widget, views::WidgetObserver> observer_{this}; 90 91 DISALLOW_COPY_AND_ASSIGN(MessagePopupView); 92 }; 93 94 } // namespace message_center 95 96 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_VIEW_H_ 97