File: glic_tab_indicator_helper.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 (61 lines) | stat: -rw-r--r-- 2,427 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
// 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_GLIC_BROWSER_UI_GLIC_TAB_INDICATOR_HELPER_H_
#define CHROME_BROWSER_GLIC_BROWSER_UI_GLIC_TAB_INDICATOR_HELPER_H_

#include "base/callback_list.h"
#include "base/memory/raw_ref.h"
#include "chrome/browser/glic/host/context/glic_tab_data.h"
#include "components/tabs/public/tab_interface.h"

namespace glic {

// This class is partially responsible for updating tab indicators for glic
// focus. TODO(crbug.com/393557651): Simplify TabRendererData design, at which
// point this class can be fully responsible.
//
// Tab UI reflects feature state (such as the glic focused tab), but is stored
// on a per-index basis rather than a per-tab basis. This means that the UI
// needs to be updated either when the feature state changes, OR when the tab is
// moved around (either in the same tabstrip, or into a new tabstrip). The
// latter is currently handled by
// BrowserTabStripController::OnTabStripModelChanged. This class is only
// responsible for propagating glic focus changes for a fixed TabInterface,
// without handling moving.
class GlicTabIndicatorHelper {
 public:
  explicit GlicTabIndicatorHelper(tabs::TabInterface* tab);
  ~GlicTabIndicatorHelper();

 private:
  // Updates the Tab UI. This only needs to be called when the tab gains/loses
  // focus, or when the indicator status changes.
  void UpdateTab();

  // Called when the focused tab changes with the focused tab data object.
  void OnFocusedTabChanged(FocusedTabData focused_tab_data);

  // Called when the client changes the context access indicator status.
  void OnIndicatorStatusChanged(bool enabled);

  // Called when the tab is detached.
  void OnTabWillDetach(tabs::TabInterface* tab,
                       tabs::TabInterface::DetachReason reason);

  // Called when the tab is inserted.
  void OnTabDidInsert(tabs::TabInterface* tab);

  raw_ptr<tabs::TabInterface> tab_;
  bool tab_is_focused_ = false;
  bool is_detached_ = false;
  base::CallbackListSubscription focus_change_subscription_;
  base::CallbackListSubscription indicator_change_subscription_;
  base::CallbackListSubscription will_detach_subscription_;
  base::CallbackListSubscription did_insert_subscription_;
};

}  // namespace glic

#endif  // CHROME_BROWSER_GLIC_BROWSER_UI_GLIC_TAB_INDICATOR_HELPER_H_