File: mahi_panel_view.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 3,746 bytes parent folder | download | duplicates (5)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_MAHI_MAHI_PANEL_VIEW_H_
#define ASH_SYSTEM_MAHI_MAHI_PANEL_VIEW_H_

#include <optional>
#include <string>

#include "ash/ash_export.h"
#include "ash/system/mahi/mahi_ui_controller.h"
#include "ash/wm/system_panel_view.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/textfield/textfield_controller.h"

namespace ui {
class LocatedEvent;
}

namespace views {
class FlexLayoutView;
class Textfield;
}  // namespace views

namespace ash {

class IconButton;
class MahiContentSourceButton;
class MahiQuestionAnswerView;
class MahiUiUpdate;
class SummaryOutlinesElucidationSection;
enum class VisibilityState;

// The code for Mahi main panel view. This view is placed within
// `MahiPanelWidget`.
class ASH_EXPORT MahiPanelView : public SystemPanelView,
                                 public views::TextfieldController,
                                 public MahiUiController::Delegate {
  METADATA_HEADER(MahiPanelView, SystemPanelView)

 public:
  explicit MahiPanelView(MahiUiController* ui_controller);
  MahiPanelView(const MahiPanelView&) = delete;
  MahiPanelView& operator=(const MahiPanelView&) = delete;
  ~MahiPanelView() override;

  // Shows the pop in animation for the panel.
  void AnimatePopIn(const gfx::Rect& start_bounds);

  // SystemPanelView:
  void OnBoundsChanged(const gfx::Rect& previous_bounds) override;

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

  // MahiUiController::Delegate:
  views::View* GetView() override;
  bool GetViewVisibility(VisibilityState state) const override;
  void OnUpdated(const MahiUiUpdate& update) override;

  // Creates the header row, which includes a back button (visible only
  // in the Q&A view), the panel title, an experiment badge and a close button.
  std::unique_ptr<views::View> CreateHeaderRow();

  // Callbacks for buttons and link.
  void OnCloseButtonPressed(const ui::Event& event);
  void OnLearnMoreLinkClicked();
  void OnBackButtonPressed();
  void OnSendButtonPressed();

  // Handles drag events to reposition the panel. Events that are not part of a
  // drag event sequence are ignored.
  void HandleDragEventIfNeeded(ui::LocatedEvent* event);

  // Callbacks when the feedback buttons are toggled from inactive to active.
  void OnThumbsUpButtonActive();
  void OnThumbsDownButtonActive();

  // `ui_controller_` will outlive `this`.
  const raw_ptr<MahiUiController> ui_controller_;

  // Owned by the views hierarchy.
  raw_ptr<views::FlexLayoutView> main_container_ = nullptr;
  raw_ptr<views::View> back_button_ = nullptr;
  raw_ptr<MahiContentSourceButton> content_source_button_ = nullptr;
  raw_ptr<MahiQuestionAnswerView> question_answer_view_ = nullptr;
  raw_ptr<SummaryOutlinesElucidationSection> summary_outlines_section_ =
      nullptr;
  raw_ptr<views::Textfield> question_textfield_ = nullptr;
  raw_ptr<IconButton> send_button_ = nullptr;
  raw_ptr<IconButton> thumbs_up_button_ = nullptr;
  raw_ptr<IconButton> thumbs_down_button_ = nullptr;

  // Whether a question is sent and waiting for answer / error response.
  bool pending_answer_ = false;

  // The time when this view is constructed, which is when the user opens this
  // view.
  base::TimeTicks open_time_;

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

}  // namespace ash

#endif  // ASH_SYSTEM_MAHI_MAHI_PANEL_VIEW_H_