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_
|