File: tab_search_bubble_host.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (125 lines) | stat: -rw-r--r-- 4,575 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
// 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 CHROME_BROWSER_UI_VIEWS_TAB_SEARCH_BUBBLE_HOST_H_
#define CHROME_BROWSER_UI_VIEWS_TAB_SEARCH_BUBBLE_HOST_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "chrome/browser/ui/tabs/organization/tab_organization_observer.h"
#include "chrome/browser/ui/views/bubble/webui_bubble_manager.h"
#include "chrome/browser/ui/views/bubble/webui_bubble_manager_observer.h"
#include "chrome/browser/ui/views/tabs/tab_slot_controller.h"
#include "chrome/browser/ui/webui/tab_search/tab_search.mojom.h"
#include "chrome/browser/ui/webui/tab_search/tab_search_ui.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/menu_button_controller.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/widget/widget_utils.h"

namespace views {
class Widget;
}  // namespace views

class BrowserWindowInterface;
class Profile;
class TabOrganizationService;
class TabStrip;

// TabSearchBubbleHost assumes responsibility for configuring its button,
// showing / hiding the tab search bubble and handling metrics collection.
class TabSearchBubbleHost : public views::WidgetObserver,
                            public TabOrganizationObserver,
                            public WebUIBubbleManagerObserver {
 public:
  class Observer : public base::CheckedObserver {
   public:
    virtual void OnBubbleInitializing() {}
    virtual void OnBubbleDestroying() {}
  };

  TabSearchBubbleHost(views::Button* button,
                      BrowserWindowInterface* browser_window_interface,
                      base::WeakPtr<TabStrip> tab_strip);
  TabSearchBubbleHost(const TabSearchBubbleHost&) = delete;
  TabSearchBubbleHost& operator=(const TabSearchBubbleHost&) = delete;
  ~TabSearchBubbleHost() override;

  // views::WidgetObserver:
  void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
  void OnWidgetDestroying(views::Widget* widget) override;

  // TabOrganizationObserver:
  void OnOrganizationAccepted(const Browser* browser) override;
  void OnUserInvokedFeature(const Browser* browser) override;

  // WebUIBubbleManagerObserver:
  void BeforeBubbleWidgetShowed(views::Widget* widget) override;

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  // When this is called the bubble may already be showing or be loading in.
  // This returns true if the method call results in the creation of a new Tab
  // Search bubble. Optionally use section to force the bubble to open to the
  // given tab, even if the bubble is already showing.
  bool ShowTabSearchBubble(
      bool triggered_by_keyboard_shortcut = false,
      tab_search::mojom::TabSearchSection section =
          tab_search::mojom::TabSearchSection::kSearch,
      tab_search::mojom::TabOrganizationFeature organization_feature =
          tab_search::mojom::TabOrganizationFeature::kNone);
  void CloseTabSearchBubble();

  Browser* GetBrowser();

  views::View* button() { return button_; }

  WebUIBubbleManager* webui_bubble_manager_for_testing() {
    return webui_bubble_manager_.get();
  }

  const std::optional<base::TimeTicks>& bubble_created_time_for_testing()
      const {
    return bubble_created_time_;
  }

 private:
  void ButtonPressed(const ui::Event& event);

  // The anchor button for the tab search bubble.
  const raw_ptr<views::Button> button_;

  const raw_ptr<Profile> profile_;

  std::unique_ptr<WebUIBubbleManager> webui_bubble_manager_;

  views::WidgetOpenTimer widget_open_timer_;

  // Timestamp for when the current bubble was created.
  std::optional<base::TimeTicks> bubble_created_time_;

  base::ObserverList<Observer> observers_;

  raw_ptr<views::MenuButtonController> menu_button_controller_ = nullptr;

  // A lock to keep its `button_` pressed while |bubble_| is showing or in the
  // process of being shown.
  std::unique_ptr<views::MenuButtonController::PressedLock> pressed_lock_;

  base::ScopedObservation<views::Widget, views::WidgetObserver>
      bubble_widget_observation_{this};

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

  base::ScopedObservation<WebUIBubbleManager, WebUIBubbleManagerObserver>
      webui_bubble_manager_observer_{this};

  base::WeakPtr<TabStrip> tab_strip_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_TAB_SEARCH_BUBBLE_HOST_H_