File: caption_bubble_context.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 (88 lines) | stat: -rw-r--r-- 3,619 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
// 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 COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTEXT_H_
#define COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTEXT_H_

#include <memory>
#include <string>

#include "base/functional/callback.h"
#include "components/live_caption/caption_bubble_session_observer.h"
#include "ui/gfx/geometry/rect.h"

namespace content {
class WebContents;
}

namespace captions {

using OpenCaptionSettingsCallback = base::RepeatingCallback<void()>;

///////////////////////////////////////////////////////////////////////////////
// Caption Bubble Context
//
//  The context for an audio stream used by the caption bubble. The context is
//  used for two things: for positioning the caption bubble within the context
//  widget (on Chrome browser, the browser window; on ash, the entire screen),
//  and for activating the window or tab when the Back To Tab button is clicked.
//
class CaptionBubbleContext {
 public:
  CaptionBubbleContext() = default;
  virtual ~CaptionBubbleContext() = default;
  CaptionBubbleContext(const CaptionBubbleContext&) = delete;
  CaptionBubbleContext& operator=(const CaptionBubbleContext&) = delete;

  using GetBoundsCallback = base::OnceCallback<void(const gfx::Rect&)>;

  // Calls the given callback with the bounds of the context widget. On Chrome
  // browser, this is the bounds in screen of the top level widget of the
  // browser window. When Live Caption is implemented in ash, this will be
  // bounds of the top level widget of the ash window.
  //
  // If the context can't provide bounds, the callback is never executed.
  virtual void GetBounds(GetBoundsCallback callback) const = 0;

  // Returns the unique identifier for a caption bubble session. A caption
  // bubble session is per-tab and resets when a user navigates away or reloads
  // the page.
  virtual const std::string GetSessionId() const = 0;

  // Activates the context. In Live Caption on browser, this activates the
  // browser window and tab of the web contents. Called when the Back To Tab
  // button is clicked in the CaptionBubble.
  virtual void Activate() = 0;

  // Whether or not the context is activatable. When Activate() is implemented
  // in child classes, the child classes must set this to be true.
  virtual bool IsActivatable() const = 0;

  // Whether the caption bubble should be positioned to avoid covering too much
  // of the context area. For Live Caption, this should only be true for
  // non-browser web contents.
  virtual bool ShouldAvoidOverlap() const = 0;

  // Gets a session observer for the caption bubble context. On Chrome
  // browser, a caption bubble session is per-tab and resets when a user
  // navigates away or reloads the page.
  //
  // When this method is called, previously-created session observers are
  // invalidated (i.e. they might not execute their session-end callback) but
  // not destroyed.
  //
  // TODO(launch/4200463): Implement this for Ash if necessary.
  virtual std::unique_ptr<CaptionBubbleSessionObserver>
  GetCaptionBubbleSessionObserver() = 0;

  // Gets a callback that can be used to navigate to the caption settings page.
  // This callback is attached to the caption bubble context because
  // //components/live_caption:live_caption can't directly use the WebContents
  // to trigger a navigation due to dependency restrictions.
  virtual OpenCaptionSettingsCallback GetOpenCaptionSettingsCallback() = 0;
};

}  // namespace captions

#endif  // COMPONENTS_LIVE_CAPTION_CAPTION_BUBBLE_CONTEXT_H_