File: tab_hover_card_bubble_view.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 (119 lines) | stat: -rw-r--r-- 4,316 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
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
// Copyright 2018 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_TAB_HOVER_CARD_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_HOVER_CARD_BUBBLE_VIEW_H_

#include <memory>
#include <optional>
#include <string_view>
#include <utility>

#include "base/callback_list.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/tabs/fade_footer_view.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "ash/public/cpp/metrics_util.h"
#endif

namespace gfx {
class ImageSkia;
}

namespace tabs {
enum class TabAlert;
}

class Tab;
class TabStyle;
class FadeLabelView;
struct TabRendererData;

// Dialog that displays an informational hover card containing page information.
class TabHoverCardBubbleView : public views::BubbleDialogDelegateView {
  METADATA_HEADER(TabHoverCardBubbleView, views::BubbleDialogDelegateView)

 public:
  static constexpr base::TimeDelta kHoverCardSlideDuration =
      base::Milliseconds(200);

  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHoverCardBubbleElementId);
  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHoverCardDomainLabelElementId);

  struct InitParams {
    // Becomes false with certain accessibility options and in tests
    bool use_animation = true;
    // Becomes false for ChromeOS tabbed system apps (e.g. Terminal)
    bool show_domain = true;
    // Becomes false when image preview setting is disabled
    bool show_image_preview = true;
    // Becomes false for ChromeOS system apps or when disabled in settings
    bool show_memory_usage = true;
  };

  explicit TabHoverCardBubbleView(Tab* tab, const InitParams& params);
  TabHoverCardBubbleView(const TabHoverCardBubbleView&) = delete;
  TabHoverCardBubbleView& operator=(const TabHoverCardBubbleView&) = delete;
  ~TabHoverCardBubbleView() override;

  // Create the CollaborationMessagingRowData from TabRendererData.
  CollaborationMessagingRowData GetCollaborationMessagingData(
      const TabRendererData& tab_data);

  // Updates and formats title, alert state, domain, and preview image.
  void UpdateCardContent(const Tab* tab);

  // Update the text fade to the given percent, which should be between 0 and 1.
  void SetTextFade(double percent);

  // Set the preview image to use for the target tab.
  void SetTargetTabImage(gfx::ImageSkia preview_image);

  // Specifies that the hover card should display a placeholder image
  // specifying that no preview for the tab is available (yet).
  void SetPlaceholderImage();

  // Accessors used by tests.
  std::u16string_view GetTitleTextForTesting() const;
  std::u16string_view GetDomainTextForTesting() const;
  views::View* GetThumbnailViewForTesting();
  FooterView* GetFooterViewForTesting();

  // Returns the percentage complete during transition animations when a
  // pre-emptive crossfade to a placeholder should start if a new image is not
  // available, or `std::nullopt` to disable crossfades entirely.
  static std::optional<double> GetPreviewImageCrossfadeStart();

 private:
  FRIEND_TEST_ALL_PREFIXES(TabHoverCardFadeFooterInteractiveUiTest,
                           BackgroundTabHoverCardContentsHaveCorrectDimensions);
  class ThumbnailView;

  // views::BubbleDialogDelegateView:
  gfx::Size CalculatePreferredSize(
      const views::SizeBounds& available_size) const override;

  raw_ptr<FadeLabelView> title_label_ = nullptr;
  raw_ptr<FadeLabelView> domain_label_ = nullptr;
  raw_ptr<ThumbnailView> thumbnail_view_ = nullptr;
  raw_ptr<FooterView> footer_view_ = nullptr;
  std::optional<tabs::TabAlert> alert_state_;
  const raw_ptr<const TabStyle> tab_style_;

  const InitParams bubble_params_;
  int corner_radius_ = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
      views::Emphasis::kHigh);
};

#endif  // CHROME_BROWSER_UI_VIEWS_TABS_TAB_HOVER_CARD_BUBBLE_VIEW_H_