File: message_popup_view.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,075 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_VIEW_H_
#define UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_VIEW_H_

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "ui/message_center/message_center_export.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h"

namespace message_center {

class MessagePopupCollection;
class MessageView;
class Notification;

// The widget delegate of a notification popup. The view is owned by the widget.
class MESSAGE_CENTER_EXPORT MessagePopupView
    : public views::FocusChangeListener,
      public views::WidgetDelegateView {
  METADATA_HEADER(MessagePopupView, views::WidgetDelegateView)

 public:
  MessagePopupView(MessageView* message_view,
                   MessagePopupCollection* popup_collection,
                   bool a11y_feedback_on_init);
  MessagePopupView(const MessagePopupView&) = delete;
  MessagePopupView& operator=(const MessagePopupView&) = delete;
  ~MessagePopupView() override;

  // Update notification contents to |notification|. Virtual for unit testing.
  virtual void UpdateContents(const Notification& notification);

  // Updates the content of the child notification view inside this popup.
  // Virtual for unit testing.
  virtual void UpdateContentsForChildNotification(
      const std::string& notification_id,
      const Notification& notification);

  // Return opacity of the widget.
  float GetOpacity() const;

  // Sets widget bounds.
  void SetPopupBounds(const gfx::Rect& bounds);

  // Set widget opacity.
  void SetOpacity(float opacity);

  // Collapses the notification unless the user is interacting with it. The
  // request can be ignored. Virtual for unit testing.
  virtual void AutoCollapse();

  // Shows popup. After this call, MessagePopupView should be owned by the
  // widget.
  std::unique_ptr<views::Widget> Show();

  // Closes popup. It should be callable even if Show() is not called, and
  // in such case MessagePopupView should be deleted. Virtual for unit testing.
  virtual void Close();

  // views::FocusChangeListener,
  void OnDidChangeFocus(views::View* before, views::View* now) override;

  // views::WidgetDelegateView:
  void OnMouseEntered(const ui::MouseEvent& event) override;
  void OnMouseExited(const ui::MouseEvent& event) override;
  void ChildPreferredSizeChanged(views::View* child) override;
  void OnDisplayChanged() override;
  void OnWorkAreaChanged() override;
  void OnFocus() override;
  void AddedToWidget() override;
  void RemovedFromWidget() override;

  bool is_hovered() const { return is_hovered_; }
  bool is_focused() const { return is_focused_; }

  MessageView* message_view() { return message_view_; }

  bool view_added_to_widget() { return view_added_to_widget_; }

 protected:
  // For unit testing.
  explicit MessagePopupView(MessagePopupCollection* popup_collection);

 private:
  // True if the view has a widget and the widget is not closed.
  bool IsWidgetValid() const;
  void UpdateAccessibleName(const std::u16string& new_name) const;

  void OnMessageViewNameUpdated(
      bool should_make_spoken_feedback_for_popup_updates);

  // Owned by views hierarchy.
  raw_ptr<MessageView> message_view_;

  // Unowned.
  const raw_ptr<MessagePopupCollection> popup_collection_;

  const bool a11y_feedback_on_init_;
  bool is_hovered_ = false;
  bool is_focused_ = false;
  // Was this view ever hosted in a Widget? If so, the Widget will "own" this
  // view and delete it accordingly. Otherwise, the MessagePopupCollection is
  // responsible for its destruction.
  bool view_added_to_widget_ = false;

  // Owned by the widget associated with this view.
  raw_ptr<views::FocusManager> focus_manager_ = nullptr;

  base::WeakPtrFactory<MessagePopupView> weak_ptr_factory_{this};
};

}  // namespace message_center

#endif  // UI_MESSAGE_CENTER_VIEWS_MESSAGE_POPUP_VIEW_H_