File: notification_input_container.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 (127 lines) | stat: -rw-r--r-- 4,380 bytes parent folder | download | duplicates (9)
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
120
121
122
123
124
125
126
127
// Copyright 2021 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_NOTIFICATION_INPUT_CONTAINER_H_
#define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_INPUT_CONTAINER_H_

#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/message_center/message_center_export.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/delegating_layout_manager.h"
#include "ui/views/view.h"

namespace ui {
class KeyEvent;
class Layer;
}  // namespace ui

namespace views {
class ImageButton;
class InkDropContainerView;
class Textfield;
}  // namespace views

namespace message_center {

class MESSAGE_CENTER_EXPORT NotificationInputDelegate {
 public:
  virtual void OnNotificationInputSubmit(size_t index,
                                         const std::u16string& text) = 0;
  virtual ~NotificationInputDelegate() = default;
};

// A view which shows a textfield with a send button for notifications.
class MESSAGE_CENTER_EXPORT NotificationInputContainer
    : public views::View,
      public views::TextfieldController,
      public views::LayoutDelegate {
  METADATA_HEADER(NotificationInputContainer, views::View)

 public:
  explicit NotificationInputContainer(
      NotificationInputDelegate* delegate = nullptr);
  NotificationInputContainer(const NotificationInputContainer&) = delete;
  NotificationInputContainer& operator=(const NotificationInputContainer&) =
      delete;
  ~NotificationInputContainer() override;

  // Initializes the view after construction. Necessary to ensure the derived
  // class is called for certain functions.
  void Init();

  // Sets `textfield_`'s  `index`. Used to keep track of this views index in the
  // row of actions in the parent view.
  void SetTextfieldIndex(int index);
  size_t GetTextfieldIndex() const;

  // Sets `textfield_`'s placeholder string to `placeholder` or the default if
  // not supplied.
  void SetPlaceholderText(const std::optional<std::u16string>& placeholder);

  // Animates the background, if one exists.
  void AnimateBackground(const ui::Event& event);

  // views::View:
  void AddLayerToRegion(ui::Layer* layer, views::LayerRegion region) override;
  void RemoveLayerFromRegions(ui::Layer* layer) override;
  void OnThemeChanged() override;

  // views::TextfieldController:
  bool HandleKeyEvent(views::Textfield* sender,
                      const ui::KeyEvent& key_event) override;
  void OnAfterUserAction(views::Textfield* sender) override;

  // Overridden from views::LayoutDelegate:
  views::ProposedLayout CalculateProposedLayout(
      const views::SizeBounds& size_bounds) const override;

  views::Textfield* textfield() const { return textfield_; }
  views::ImageButton* button() const { return button_; }

 private:
  // Installs the layout manager with appropriate spacing.
  virtual views::BoxLayout* InstallLayoutManager();

  // Installs the ink drop, and layers required to animate it without occluding
  // the textfield and button.
  virtual views::InkDropContainerView* InstallInkDrop();

  // Gets padding for `textfield_`.
  virtual gfx::Insets GetTextfieldPadding() const;

  // Gets padding for `button_`.
  virtual gfx::Insets GetSendButtonPadding() const;

  // Sets the custom highlight path for `button_`.
  virtual void SetSendButtonHighlightPath();

  // Gets the id for the default placeholder string for `textfield_`.
  virtual int GetDefaultPlaceholderStringId() const;

  // Gets the id for the default accessible name string for `button_`.
  virtual int GetDefaultAccessibleNameStringId() const;

  // Sets the visible background of `textfield_`.
  virtual void StyleTextfield();

  // Updates image and coloring for `button_`.
  virtual void UpdateButtonImage();

  // Unowned.
  const raw_ptr<NotificationInputDelegate> delegate_;

  // Owned by view hierarchy.
  const raw_ptr<views::Textfield> textfield_;
  // Owned by view hierarchy.
  const raw_ptr<views::ImageButton> button_;
  // Owned by the view hierarchy. Used to show an inkdrop effect during
  // animation.
  raw_ptr<views::InkDropContainerView> ink_drop_container_ = nullptr;
};

}  // namespace message_center

#endif  // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_INPUT_CONTAINER_H_