File: tab_strip_action_container.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 (234 lines) | stat: -rw-r--r-- 9,077 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// 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 CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_ACTION_CONTAINER_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_ACTION_CONTAINER_H_

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/glic/browser_ui/glic_button_controller_delegate.h"
#include "chrome/browser/ui/tabs/glic_nudge_controller.h"
#include "chrome/browser/ui/tabs/glic_nudge_delegate.h"
#include "chrome/browser/ui/tabs/organization/tab_declutter_controller.h"
#include "chrome/browser/ui/tabs/organization/tab_declutter_observer.h"
#include "chrome/browser/ui/views/tabs/tab_search_container.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "chrome/common/buildflags.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/controls/separator.h"
#include "ui/views/mouse_watcher.h"
#include "ui/views/view.h"

namespace gfx {
class Insets;
}
namespace glic {
class GlicButton;
}
class ProductSpecificationsButton;

class TabStripActionContainer : public views::View,
                                public TabDeclutterObserver,
                                public views::AnimationDelegateViews,
                                public views::MouseWatcherListener,
                                public TabOrganizationObserver,
                                public GlicNudgeDelegate,
                                public glic::GlicButtonControllerDelegate {
  METADATA_HEADER(TabStripActionContainer, views::View)

 public:
  class TabStripNudgeAnimationSession {
   public:
    enum class AnimationSessionType { SHOW, HIDE };

    TabStripNudgeAnimationSession(TabStripNudgeButton* button,
                                  TabStripActionContainer* container,
                                  AnimationSessionType session_type,
                                  base::OnceCallback<void()> on_animation_ended,
                                  bool animate_opacity = true);
    ~TabStripNudgeAnimationSession();
    void ApplyAnimationValue(const gfx::Animation* animation);
    void MarkAnimationDone(const gfx::Animation* animation);
    void Start();
    AnimationSessionType session_type() { return session_type_; }

    gfx::SlideAnimation* expansion_animation() { return &expansion_animation_; }
    void ResetExpansionAnimationForTesting(double value);
    void ResetOpacityAnimationForTesting(double value);

    void Hide();
    TabStripNudgeButton* button() { return button_; }

   private:
    base::TimeDelta GetAnimationDuration(base::TimeDelta duration);
    void ShowOpacityAnimation();
    void Show();
    raw_ptr<TabStripNudgeButton> button_ = nullptr;
    raw_ptr<TabStripActionContainer> container_ = nullptr;

    gfx::SlideAnimation expansion_animation_;
    gfx::SlideAnimation opacity_animation_;

    bool expansion_animation_done_ = false;
    bool opacity_animation_done_ = false;
    AnimationSessionType session_type_;

    // Timer for initiating the opacity animation during show.
    base::OneShotTimer opacity_animation_delay_timer_;

    // Callback to container after animation has ended.
    base::OnceCallback<void()> on_animation_ended_;

    // Adding boolean since the glic nudge is always opaque.
    bool is_opacity_animated_;

    // track animations to delay posting calls that might delete this class.
    bool is_executing_show_or_hide_ = false;
  };
  explicit TabStripActionContainer(
      TabStripController* tab_strip_controller,
      tabs::TabDeclutterController* tab_declutter_controller,
      tabs::GlicNudgeController* tab_glic_nudge_controller);
  TabStripActionContainer(const TabStripActionContainer&) = delete;
  TabStripActionContainer& operator=(const TabStripActionContainer&) = delete;
  ~TabStripActionContainer() override;

  TabStripNudgeButton* tab_declutter_button() { return tab_declutter_button_; }
  TabStripNudgeButton* auto_tab_group_button() {
    return auto_tab_group_button_;
  }

  TabStripNudgeAnimationSession* animation_session_for_testing() {
    return animation_session_.get();
  }

  TabOrganizationService* tab_organization_service_for_testing() {
    return tab_organization_service_;
  }

  glic::GlicButton* GetGlicButton() { return glic_button_; }

  ProductSpecificationsButton* GetProductSpecificationsButton() {
    return product_specifications_button_;
  }
  // TabOrganizationObserver
  void OnToggleActionUIState(const Browser* browser, bool should_show) override;

  // TabDeclutterObserver
  void OnTriggerDeclutterUIVisibility() override;

  // views::MouseWatcherListener:
  void MouseMovedOutOfHost() override;

  // GlicNudgeDelegate:
  void OnTriggerGlicNudgeUI(std::string label) override;
  bool GetIsShowingGlicNudge() override;

  // GlicButtonControllerDelegate:
  void SetGlicShowState(bool show) override;
  void SetGlicIcon(const gfx::VectorIcon& icon) override;

  void UpdateButtonBorders(gfx::Insets button_insets);

  void DidBecomeActive(BrowserWindowInterface* browser);
  void DidBecomeInactive(BrowserWindowInterface* browser);

 private:
  friend class TabStripActionContainerBrowserTest;

  void ShowTabStripNudge(TabStripNudgeButton* button);
  void HideTabStripNudge(TabStripNudgeButton* button);

  // Update the expansion mode to be executed once the mouse is no longer over
  // the nudge.
  void SetLockedExpansionMode(LockedExpansionMode mode,
                              TabStripNudgeButton* button);

#if BUILDFLAG(ENABLE_GLIC)
  std::unique_ptr<glic::GlicButton> CreateGlicButton(
      TabStripController* tab_strip_controller);
  void OnGlicButtonClicked();
  void OnGlicButtonDismissed();
  void OnGlicButtonHovered();
  void OnGlicButtonMouseDown();
#endif

  void OnTabDeclutterButtonClicked();
  void OnTabDeclutterButtonDismissed();

  void OnAutoTabGroupButtonClicked();
  void OnAutoTabGroupButtonDismissed();

  void OnTabStripNudgeButtonTimeout(TabStripNudgeButton* button);

  DeclutterTriggerCTRBucket GetDeclutterTriggerBucket(bool clicked);
  void LogDeclutterTriggerBucket(bool clicked);

  // View where, if the mouse is currently over its bounds, the expansion state
  // will not change. Changes will be staged until after the mouse exits the
  // bounds of this View.
  raw_ptr<View, DanglingUntriaged> locked_expansion_view_ = nullptr;

  // MouseWatcher is used to lock and unlock the expansion state of this
  // container.
  std::unique_ptr<views::MouseWatcher> mouse_watcher_;

  // views::AnimationDelegateViews
  void AnimationCanceled(const gfx::Animation* animation) override;
  void AnimationEnded(const gfx::Animation* animation) override;
  void AnimationProgressed(const gfx::Animation* animation) override;

  void ExecuteShowTabStripNudge(TabStripNudgeButton* button);
  void ExecuteHideTabStripNudge(TabStripNudgeButton* button);

  void OnAnimationSessionEnded();

  std::unique_ptr<TabStripNudgeButton> CreateAutoTabGroupButton(
      TabStripController* tab_strip_controller);
  std::unique_ptr<TabStripNudgeButton> CreateTabDeclutterButton(
      TabStripController* tab_strip_controller);
  void SetupButtonProperties(TabStripNudgeButton* button);

  // TODO(crbug.com/387356481) make ProductSpecificationsButton a subclass of
  // TabStripNudgeButton
  raw_ptr<ProductSpecificationsButton> product_specifications_button_ = nullptr;
  // The button currently holding the lock to be shown/hidden.
  raw_ptr<TabStripNudgeButton> locked_expansion_button_ = nullptr;
  raw_ptr<TabStripNudgeButton> tab_declutter_button_ = nullptr;
  raw_ptr<TabStripNudgeButton> auto_tab_group_button_ = nullptr;
  raw_ptr<TabOrganizationService> tab_organization_service_ = nullptr;
  raw_ptr<tabs::TabDeclutterController> tab_declutter_controller_ = nullptr;
  raw_ptr<tabs::GlicNudgeController> glic_nudge_controller_ = nullptr;
  raw_ptr<views::Separator> separator_ = nullptr;

  raw_ptr<glic::GlicButton> glic_button_ = nullptr;

  raw_ptr<const Browser> browser_;

  const raw_ptr<TabStripController> tab_strip_controller_ = nullptr;

  // Timer for hiding tab_strip_nudge_button_ after show.
  base::OneShotTimer hide_tab_strip_nudge_timer_;

  // When locked, the container is unable to change its expanded state. Changes
  // will be staged until after this is unlocked.
  LockedExpansionMode locked_expansion_mode_ = LockedExpansionMode::kNone;

  base::ScopedObservation<TabOrganizationService, TabOrganizationObserver>
      tab_organization_observation_{this};

  base::ScopedObservation<tabs::TabDeclutterController, TabDeclutterObserver>
      tab_declutter_observation_{this};

  // Prevents other features from showing tabstrip-modal UI.
  std::unique_ptr<ScopedTabStripModalUI> scoped_tab_strip_modal_ui_;

  std::list<base::CallbackListSubscription> subscriptions_;

  std::unique_ptr<TabStripNudgeAnimationSession> animation_session_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_TABS_TAB_STRIP_ACTION_CONTAINER_H_