File: split_view_iph_controller.h

package info (click to toggle)
chromium 141.0.7390.107-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,246,132 kB
  • sloc: cpp: 35,264,965; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,635; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,313; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (79 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download | duplicates (4)
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
// Copyright 2025 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_TABS_SPLIT_VIEW_IPH_CONTROLLER_H_
#define CHROME_BROWSER_UI_TABS_SPLIT_VIEW_IPH_CONTROLLER_H_

#include "base/containers/circular_deque.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/tabs/public/tab_interface.h"
#include "ui/base/unowned_user_data/scoped_unowned_user_data.h"

class BrowserView;

namespace ui {
class TrackedElement;
}  // namespace ui

// Provides the logic to show the IPH promo for the split view feature.
//
// Current IPH logic has two scenarios:
//
// 1. When a user creates a split view two or more times, show an IPH promo
//    that asks the user if they want to pin the Split View button.
// 2. When a user switches between the same two tabs three or more times, show
//    an IPH tutorial that guides the user to add a tab to a split view.
class SplitViewIphController : public TabStripModelObserver {
 public:
  DECLARE_USER_DATA(SplitViewIphController);
  explicit SplitViewIphController(BrowserWindowInterface* interface);
  ~SplitViewIphController() override;

  SplitViewIphController(const SplitViewIphController&) = delete;
  SplitViewIphController& operator=(const SplitViewIphController&) = delete;

  static SplitViewIphController* From(BrowserWindowInterface* interface);

  // Returns the most recently inactive tab
  ui::TrackedElement* GetTabSwitchIPHAnchor(BrowserView* browser_view);

  int get_recent_tabs_size() const { return recent_tabs_.size(); }
  int get_tab_switch_count() const { return tab_switch_count_; }

  // TabStripModelObserver
  void OnSplitTabChanged(const SplitTabChange& change) override;
  void OnTabStripModelChanged(
      TabStripModel* tab_strip_model,
      const TabStripModelChange& change,
      const TabStripSelectionChange& selection) override;

 private:
  static constexpr int kNumTabsTracked = 2;
  static constexpr int kMostRecentTabTrackerIndex = 0;
  static constexpr int kLeastRecentTabTrackerIndex = 1;

  void MaybeShowPromo(const base::Feature& feature);

  // Add new tab to tracked tabs while removing the least recently used tab
  void AddNewTabToTracker(tabs::TabInterface* new_tab);

  // Remove tabs from tracked tabs
  void RemoveTabFromTracker(const TabStripModelChange::Remove* remove_contents);

  const raw_ptr<BrowserWindowInterface> browser_window_interface_;

  // Number of times user has switched between the same two tabs.
  int tab_switch_count_ = 0;

  // Two most recently active tabs. Front is current active tab, end is previous
  // active tab. When a third tab becomes active, push to front, which will
  // evict the oldest from the end.
  base::circular_deque<tabs::TabInterface*> recent_tabs_;

  ui::ScopedUnownedUserData<SplitViewIphController> scoped_data_;
};

#endif  // CHROME_BROWSER_UI_TABS_SPLIT_VIEW_IPH_CONTROLLER_H_