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
|
// Copyright 2025 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_WEBAUTHN_COMBINED_SELECTOR_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_WEBAUTHN_COMBINED_SELECTOR_VIEWS_H_
#include <string_view>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/webauthn/sheet_models.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/layout/table_layout_view.h"
#include "ui/views/view.h"
// CombinedSelectorRadioButton is a wrapper around RadioButton so that different
// radio buttons within the same CombinedSelectorListView can be grouped
// together.
class CombinedSelectorRadioButton : public views::RadioButton {
METADATA_HEADER(CombinedSelectorRadioButton, views::RadioButton)
public:
class Delegate {
public:
virtual void OnRadioButtonChecked(int index) = 0;
};
explicit CombinedSelectorRadioButton(Delegate* delegate, int index);
View* GetSelectedViewForGroup(int group) override;
void SetChecked(bool checked) override;
bool IsGroupFocusTraversable() const override;
private:
void GetRadioButtonsInList(int group, Views* views);
bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override;
raw_ptr<Delegate> delegate_;
const int index_;
};
class CombinedSelectorTextColumnView : public views::TableLayoutView {
METADATA_HEADER(CombinedSelectorTextColumnView, views::TableLayoutView)
public:
explicit CombinedSelectorTextColumnView(
const std::vector<std::u16string_view> texts);
};
// `CombinedSelectorRowView` renders the given icon with the text in the
// following format. `radio_status` determines if a radio button should be
// rendered at the end of the row.
//
// +-------------------------------------------------------------------+
// | | title | |
// | icon | |radio?|
// | | ... more text (row by row) | |
// +-------------------------------------------------------------------+
class CombinedSelectorRowView : public views::TableLayoutView {
METADATA_HEADER(CombinedSelectorRowView, views::TableLayoutView)
public:
using RadioStatus = CombinedSelectorSheetModel::SelectionStatus;
CombinedSelectorRowView(
const ui::ImageModel& icon,
const std::vector<std::u16string_view> texts,
RadioStatus radio_status,
bool enabled = true,
CombinedSelectorRadioButton::Delegate* radio_delegate = nullptr,
int index = 0);
bool is_selected() const { return radio_status_ == RadioStatus::kSelected; }
private:
void MaybeAddRadioButton(CombinedSelectorRadioButton::Delegate* delegate,
int index);
// views::TableLayoutView:
void RequestFocus() override;
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
raw_ptr<views::View> radio_button_;
RadioStatus radio_status_;
bool enabled_ = true;
};
class CombinedSelectorListView : public views::View {
METADATA_HEADER(CombinedSelectorListView, views::View)
public:
static constexpr int kMaxRowHeight = 72;
static constexpr int kRowGap = 4;
explicit CombinedSelectorListView(
CombinedSelectorSheetModel* model,
CombinedSelectorRadioButton::Delegate* delegate);
~CombinedSelectorListView() override;
private:
// views::View:
void RequestFocus() override;
raw_ptr<views::View> selected_view_;
};
#endif // CHROME_BROWSER_UI_VIEWS_WEBAUTHN_COMBINED_SELECTOR_VIEWS_H_
|