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
|
// Copyright 2019 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_AUTOFILL_PAYMENTS_PAYMENTS_VIEW_UTIL_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_PAYMENTS_PAYMENTS_VIEW_UTIL_H_
#include <memory>
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "build/branding_buildflags.h"
#include "components/autofill/core/browser/payments/legal_message_line.h"
#include "components/autofill/core/browser/ui/payments/payments_ui_closed_reasons.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/gfx/range/range.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout_view.h"
class GURL;
namespace views {
class View;
class Widget;
} // namespace views
namespace autofill {
// Used for providing additional information needed to add links in text labels.
struct TextLinkInfo {
TextLinkInfo();
TextLinkInfo(const TextLinkInfo& other);
TextLinkInfo& operator=(const TextLinkInfo& other);
TextLinkInfo(TextLinkInfo&& other);
TextLinkInfo& operator=(TextLinkInfo&& other);
~TextLinkInfo();
gfx::Range offset;
base::RepeatingCallback<void()> callback;
};
struct LabeledTextfieldWithErrorMessage {
LabeledTextfieldWithErrorMessage();
LabeledTextfieldWithErrorMessage(
const LabeledTextfieldWithErrorMessage& other);
LabeledTextfieldWithErrorMessage& operator=(
const LabeledTextfieldWithErrorMessage& other);
LabeledTextfieldWithErrorMessage(LabeledTextfieldWithErrorMessage&& other);
LabeledTextfieldWithErrorMessage& operator=(
LabeledTextfieldWithErrorMessage&& other);
~LabeledTextfieldWithErrorMessage();
std::unique_ptr<views::View> container = nullptr;
raw_ptr<views::Textfield> input = nullptr;
raw_ptr<views::Label> error_label = nullptr;
raw_ptr<views::View> error_label_placeholder = nullptr;
views::Textfield& GetInputTextField() const;
void SetErrorState(bool is_valid_input,
std::optional<std::u16string> error_message);
};
// Gets the user avatar icon if available, or else a placeholder.
ui::ImageModel GetProfileAvatar(const AccountInfo& account_info);
// Defines a title view with a label and an icon, to be used by dialogs
// that need to present the Google or Google Pay logo and custom
// horizontal padding.
class TitleWithIconAfterLabelView : public views::BoxLayoutView {
METADATA_HEADER(TitleWithIconAfterLabelView, views::BoxLayoutView)
public:
enum class Icon {
// Google Pay icon. The "Pay" portion is recolored for light/dark mode.
GOOGLE_PAY,
// Google super G.
GOOGLE_G,
// Google Pay logo next to an Affirm logo separated by a vertical line.
GOOGLE_PAY_AND_AFFIRM,
// Google Pay logo next to an Afterpay logo separated by a vertical line.
GOOGLE_PAY_AND_AFTERPAY,
// Google Pay logo next to an Zip logo separated by a vertical line.
GOOGLE_PAY_AND_ZIP,
};
TitleWithIconAfterLabelView(const std::u16string& window_title,
Icon icon_to_show);
~TitleWithIconAfterLabelView() override;
private:
// views::View:
gfx::Size GetMinimumSize() const override;
};
PaymentsUiClosedReason GetPaymentsUiClosedReasonFromWidget(
const views::Widget* widget);
// Creates a view with a legal message. Along with the legal message lines and
// link callbacks, the user email and the user avatar will be displayed at the
// bottom line of this view if both `user_email` and `user_avatar` are present.
std::unique_ptr<views::View> CreateLegalMessageView(
const LegalMessageLines& legal_message_lines,
const std::u16string& user_email,
const ui::ImageModel& user_avatar,
base::RepeatingCallback<void(const GURL&)> callback);
// TODO(crbug.com/40197696): Replace all payments' progress bars with this.
// Creates a progress bar with an explanatory text below.
std::unique_ptr<views::View> CreateProgressBarWithTextView(
const std::u16string& progress_bar_text);
// Creates a view with a left-aligned icon and right-aligned text. This is
// useful for creating rows of text with an accompanying icon in a list. The
// optional `text_link_info` can be used to add a link in the text.
std::unique_ptr<views::View> CreateTextWithIconView(
const std::u16string& text,
std::optional<TextLinkInfo> text_link_info,
const gfx::VectorIcon& icon);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// kGooglePayLogoIcon is square overall, despite the drawn portion being a
// rectangular area at the top. CreateTiledImage() will correctly clip it
// whereas setting the icon size would rescale it incorrectly and keep the
// bottom empty portion.
gfx::ImageSkia CreateTiledGooglePayLogo(int width,
int height,
const ui::ColorProvider* provider);
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Creates a view containing a label and a textfield with an optional error
// message. The view is arranged vertically with the label positioned above the
// textfield.
LabeledTextfieldWithErrorMessage CreateLabelAndTextfieldView(
const std::u16string& label_text,
std::optional<std::u16string> error_message);
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_PAYMENTS_PAYMENTS_VIEW_UTIL_H_
|