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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
// Copyright 2023 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_FADE_FOOTER_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_FADE_FOOTER_VIEW_H_
#include <string>
#include "chrome/browser/ui/views/tabs/fade_view.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout.h"
namespace tabs {
enum class TabAlert;
} // namespace tabs
struct AlertFooterRowData {
std::optional<tabs::TabAlert> alert_state;
bool should_show_discard_status = false;
int64_t memory_savings_in_bytes = 0;
};
struct PerformanceRowData {
bool show_memory_usage = false;
bool is_high_memory_usage = false;
int64_t memory_usage_in_bytes = 0;
};
struct CollaborationMessagingRowData {
bool should_show_collaboration_messaging = false;
std::u16string text;
ui::ImageModel avatar;
CollaborationMessagingRowData();
~CollaborationMessagingRowData();
CollaborationMessagingRowData(const CollaborationMessagingRowData& other);
CollaborationMessagingRowData& operator=(
const CollaborationMessagingRowData& other);
};
template <typename T>
class FooterRow : public FadeWrapper<views::View, T> {
using FadeWrapper_View_T = FadeWrapper<views::View, T>;
METADATA_TEMPLATE_HEADER(FooterRow, FadeWrapper_View_T)
public:
explicit FooterRow(bool is_fade_out_view);
~FooterRow() override = default;
virtual void SetContent(const ui::ImageModel& icon_image_model,
std::u16string label_text);
// views::View:
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
gfx::Size GetMinimumSize() const override;
// FadeWrapper:
void SetFade(double percent) override;
views::Label* footer_label() { return footer_label_; }
views::ImageView* icon() { return icon_; }
private:
const bool is_fade_out_view_ = false;
raw_ptr<views::Label> footer_label_ = nullptr;
raw_ptr<views::ImageView> icon_ = nullptr;
};
using FadeWrapper_View_AlertFooterRowData =
FadeWrapper<views::View, AlertFooterRowData>;
DECLARE_TEMPLATE_METADATA(FadeWrapper_View_AlertFooterRowData, FadeWrapper);
using FadeWrapper_View_PerformanceRowData =
FadeWrapper<views::View, PerformanceRowData>;
DECLARE_TEMPLATE_METADATA(FadeWrapper_View_PerformanceRowData, FadeWrapper);
using FadeWrapper_View_CollaborationMessagingRowData =
FadeWrapper<views::View, CollaborationMessagingRowData>;
DECLARE_TEMPLATE_METADATA(FadeWrapper_View_CollaborationMessagingRowData,
FadeWrapper);
using FooterRow_AlertFooterRowData = FooterRow<AlertFooterRowData>;
DECLARE_TEMPLATE_METADATA(FooterRow_AlertFooterRowData, FooterRow);
using FooterRow_PerformanceRowData = FooterRow<PerformanceRowData>;
DECLARE_TEMPLATE_METADATA(FooterRow_PerformanceRowData, FooterRow);
using FooterRow_CollaborationMessagingRowData =
FooterRow<CollaborationMessagingRowData>;
DECLARE_TEMPLATE_METADATA(FooterRow_CollaborationMessagingRowData, FooterRow);
class FadeAlertFooterRow : public FooterRow<AlertFooterRowData> {
using FooterRowAlertFooterRowData = FooterRow<AlertFooterRowData>;
METADATA_HEADER(FadeAlertFooterRow, FooterRowAlertFooterRowData)
public:
explicit FadeAlertFooterRow(bool is_fade_out_view)
: FooterRow<AlertFooterRowData>(is_fade_out_view) {}
~FadeAlertFooterRow() override = default;
// FadeWrapper:
void SetData(const AlertFooterRowData& data) override;
};
class FadePerformanceFooterRow : public FooterRow<PerformanceRowData> {
using FooterRowPerformanceRowData = FooterRow<PerformanceRowData>;
METADATA_HEADER(FadePerformanceFooterRow, FooterRowPerformanceRowData)
public:
explicit FadePerformanceFooterRow(bool is_fade_out_view)
: FooterRow<PerformanceRowData>(is_fade_out_view) {}
~FadePerformanceFooterRow() override = default;
// FadeWrapper:
void SetData(const PerformanceRowData& data) override;
};
class FadeCollaborationMessagingFooterRow
: public FooterRow<CollaborationMessagingRowData> {
using FooterRowCollaborationMessagingRowData =
FooterRow<CollaborationMessagingRowData>;
METADATA_HEADER(FadeCollaborationMessagingFooterRow,
FooterRowCollaborationMessagingRowData)
public:
explicit FadeCollaborationMessagingFooterRow(bool is_fade_out_view)
: FooterRow<CollaborationMessagingRowData>(is_fade_out_view) {}
~FadeCollaborationMessagingFooterRow() override = default;
// FadeWrapper:
void SetData(const CollaborationMessagingRowData& data) override;
};
class FooterView : public views::View {
METADATA_HEADER(FooterView, views::View)
public:
using AlertFadeView =
FadeView<FadeAlertFooterRow, FadeAlertFooterRow, AlertFooterRowData>;
using PerformanceFadeView = FadeView<FadePerformanceFooterRow,
FadePerformanceFooterRow,
PerformanceRowData>;
using CollaborationMessagingFadeView =
FadeView<FadeCollaborationMessagingFooterRow,
FadeCollaborationMessagingFooterRow,
CollaborationMessagingRowData>;
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHoverCardFooterElementId);
FooterView();
~FooterView() override = default;
void SetAlertData(const AlertFooterRowData& data);
void SetPerformanceData(const PerformanceRowData& data);
void SetCollaborationMessagingData(const CollaborationMessagingRowData& data);
void SetFade(double percent);
AlertFadeView* GetAlertRowForTesting() { return alert_row_; }
PerformanceFadeView* GetPerformanceRowForTesting() {
return performance_row_;
}
CollaborationMessagingFadeView* GetCollaborationMessagingRowForTesting() {
return collaboration_messaging_row_;
}
views::FlexLayout* flex_layout() { return flex_layout_; }
private:
raw_ptr<views::FlexLayout> flex_layout_ = nullptr;
raw_ptr<AlertFadeView> alert_row_ = nullptr;
raw_ptr<PerformanceFadeView> performance_row_ = nullptr;
raw_ptr<CollaborationMessagingFadeView> collaboration_messaging_row_ =
nullptr;
void UpdateVisibility();
};
#endif // CHROME_BROWSER_UI_VIEWS_TABS_FADE_FOOTER_VIEW_H_
|