File: fake_base_tab_strip_controller.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 (137 lines) | stat: -rw-r--r-- 5,722 bytes parent folder | download | duplicates (3)
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
// Copyright 2012 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_FAKE_BASE_TAB_STRIP_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_FAKE_BASE_TAB_STRIP_CONTROLLER_H_

#include <memory>
#include <optional>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip_types.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"

class TabGroup;

class FakeBaseTabStripController : public TabStripController {
 public:
  FakeBaseTabStripController();
  FakeBaseTabStripController(const FakeBaseTabStripController&) = delete;
  FakeBaseTabStripController& operator=(const FakeBaseTabStripController&) =
      delete;
  ~FakeBaseTabStripController() override;

  void AddTab(int index,
              TabActive is_active,
              TabPinned is_pinned = TabPinned::kUnpinned);
  void RemoveTab(int index);

  void MoveTabIntoGroup(int index,
                        std::optional<tab_groups::TabGroupId> new_group);

  ui::ListSelectionModel* selection_model() { return &selection_model_; }

  void set_tab_strip(TabStrip* tab_strip) { tab_strip_ = tab_strip; }

  // TabStripController overrides:
  const ui::ListSelectionModel& GetSelectionModel() const override;
  int GetCount() const override;
  bool IsValidIndex(int index) const override;
  bool IsActiveTab(int index) const override;
  std::optional<int> GetActiveIndex() const override;
  bool IsTabSelected(int index) const override;
  bool IsTabPinned(int index) const override;
  void SelectTab(int index, const ui::Event& event) override;
  void RecordMetricsOnTabSelectionChange(
      std::optional<tab_groups::TabGroupId> group) override;
  void ExtendSelectionTo(int index) override;
  void ToggleSelected(int index) override;
  void AddSelectionFromAnchorTo(int index) override;
  void OnCloseTab(int index,
                  CloseTabSource source,
                  base::OnceCallback<void(CloseTabSource)> callback) override;
  void CloseTab(int index) override;
  void ToggleTabAudioMute(int index) override;
  void MoveTab(int from_index, int to_index) override;
  void MoveGroup(const tab_groups::TabGroupId&, int to_index) override;
  void ToggleTabGroupCollapsedState(
      const tab_groups::TabGroupId group,
      ToggleTabGroupCollapsedStateOrigin origin) override;
  void ShowContextMenuForTab(Tab* tab,
                             const gfx::Point& p,
                             ui::mojom::MenuSourceType source_type) override;
  int HasAvailableDragActions() const override;
  void OnDropIndexUpdate(std::optional<int> index, bool drop_before) override;
  void CreateNewTab() override;
  void CreateNewTabWithLocation(const std::u16string& loc) override;
  void OnStartedDragging(bool dragging_window) override;
  void OnStoppedDragging() override;
  void OnKeyboardFocusedTabChanged(std::optional<int> index) override;
  std::u16string GetGroupTitle(
      const tab_groups::TabGroupId& group_id) const override;
  std::u16string GetGroupContentString(
      const tab_groups::TabGroupId& group_id) const override;
  tab_groups::TabGroupColorId GetGroupColorId(
      const tab_groups::TabGroupId& group_id) const override;
  bool IsGroupCollapsed(const tab_groups::TabGroupId& group) const override;
  void SetVisualDataForGroup(
      const tab_groups::TabGroupId& group,
      const tab_groups::TabGroupVisualData& visual_data) override;
  std::optional<int> GetFirstTabInGroup(
      const tab_groups::TabGroupId& group) const override;
  gfx::Range ListTabsInGroup(
      const tab_groups::TabGroupId& group) const override;
  void AddTabToGroup(int model_index,
                     const tab_groups::TabGroupId& group) override;
  void RemoveTabFromGroup(int model_index) override;
  bool IsFrameCondensed() const override;
  bool HasVisibleBackgroundTabShapes() const override;
  bool EverHasVisibleBackgroundTabShapes() const override;
  bool CanDrawStrokes() const override;
  bool IsFrameButtonsRightAligned() const override;
  SkColor GetFrameColor(BrowserFrameActiveState active_state) const override;
  std::optional<int> GetCustomBackgroundId(
      BrowserFrameActiveState active_state) const override;
  std::u16string GetAccessibleTabName(const Tab* tab) const override;
  TabGroup* GetTabGroup(const tab_groups::TabGroupId& group_id) const override;
  Profile* GetProfile() const override;
  BrowserWindowInterface* GetBrowserWindowInterface() override;
  Browser* GetBrowser() override;
  bool CanShowModalUI() const override;
  std::unique_ptr<ScopedTabStripModalUI> ShowModalUI() override;

#if BUILDFLAG(IS_CHROMEOS)
  bool IsLockedForOnTask() override;

  // Sets OnTask locked for testing purposes. Only relevant for non-web browser
  // scenarios.
  void SetLockedForOnTask(bool locked) { on_task_locked_ = locked; }
#endif

 private:
  void SetActiveIndex(int new_index);

  // If not nullptr, is kept in sync as `this` is changed.
  raw_ptr<TabStrip> tab_strip_ = nullptr;

  int num_tabs_ = 0;
  int num_pinned_tabs_ = 0;
  std::optional<int> active_index_ = std::nullopt;
#if BUILDFLAG(IS_CHROMEOS)
  bool on_task_locked_ = false;
#endif

  tab_groups::TabGroupVisualData fake_group_data_;
  std::vector<std::optional<tab_groups::TabGroupId>> tab_groups_;

  ui::ListSelectionModel selection_model_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_TABS_FAKE_BASE_TAB_STRIP_CONTROLLER_H_