File: digital_identity_multi_step_dialog.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 (115 lines) | stat: -rw-r--r-- 4,376 bytes parent folder | download | duplicates (2)
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
// Copyright 2024 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_DIGITAL_CREDENTIALS_DIGITAL_IDENTITY_MULTI_STEP_DIALOG_H_
#define CHROME_BROWSER_UI_VIEWS_DIGITAL_CREDENTIALS_DIGITAL_IDENTITY_MULTI_STEP_DIALOG_H_

#include <memory>
#include <string>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "ui/base/models/dialog_model.h"
#include "ui/color/color_variant.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout_view.h"

class DigitalIdentityMultiStepDialogDelegate;

namespace content {
class WebContents;
}

namespace views {
class BubbleDialogDelegate;
}

// Wraps views::BubbleDialogDelegate where contents can be updated in order to
// support having multiple steps in dialog.
class DigitalIdentityMultiStepDialog {
 public:
  // Configures the `illustration` to be ready for displaying in the dialog. It
  // adjusts the size and wraps it in another view. Controllers for different
  // steps in the flow will use this method to configure the coressponding
  // illustration in each step. Implementation is in the header file because
  // this is a templated method.
  template <typename T>
  static std::unique_ptr<views::BoxLayoutView> ConfigureHeaderIllustration(
      std::unique_ptr<T> illustration) {
    constexpr int kImageMarginTop = 22;
    constexpr int kImageMarginBottom = 2;
    constexpr int kImageHeight = 112;
    constexpr int kHeaderHeight =
        kImageHeight + kImageMarginTop + kImageMarginBottom;

    const gfx::Insets& insets =
        ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
            views::DialogContentType::kText, views::DialogContentType::kText);
    const int available_width =
        ChromeLayoutProvider::Get()->GetDistanceMetric(
            views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
        insets.right() - insets.left();
    const gfx::Size header_size(available_width, kHeaderHeight);
    // `illustration` will horizontally center if the width is
    // larger than the size from the Lottie file, but the height is just used to
    // truncate the image, so that is disabled with a very large value.
    illustration->SetPreferredSize(gfx::Size(available_width, 9999));
    illustration->SetBorder(views::CreateEmptyBorder(
        gfx::Insets::TLBR(kImageMarginTop, 0, kImageMarginBottom, 0)));
    illustration->SetSize(header_size);
    illustration->SetVerticalAlignment(views::ImageView::Alignment::kLeading);

    auto container_view =
        views::Builder<views::BoxLayoutView>()
            .SetOrientation(views::BoxLayout::Orientation::kVertical)
            .SetInsideBorderInsets(gfx::Insets())
            .SetPreferredSize(header_size)
            .Build();
    container_view->AddChildView(std::move(illustration));
    return container_view;
  }

  class TestApi {
   public:
    explicit TestApi(DigitalIdentityMultiStepDialog* dialog);
    ~TestApi();

    views::Widget* GetWidget();
    views::BubbleDialogDelegate* GetWidgetDelegate();

   private:
    const raw_ptr<DigitalIdentityMultiStepDialog> dialog_;
  };

  explicit DigitalIdentityMultiStepDialog(
      base::WeakPtr<content::WebContents> web_contents);
  ~DigitalIdentityMultiStepDialog();

  // Tries to show dialog. Updates the dialog contents if the dialog is already
  // showing. Runs `cancel_callback` if dialog could not be shown (and the
  // dialog is not already showing).
  void TryShow(
      const std::optional<ui::DialogModel::Button::Params>& accept_button,
      base::OnceClosure accept_callback,
      const ui::DialogModel::Button::Params& cancel_button,
      base::OnceClosure cancel_callback,
      const std::u16string& dialog_title,
      const std::u16string& body_text,
      std::unique_ptr<views::View> custom_body_field);

  ui::ColorVariant GetBackgroundColor();

 private:
  DigitalIdentityMultiStepDialogDelegate* GetWidgetDelegate();

  // The web contents the dialog is modal to.
  base::WeakPtr<content::WebContents> web_contents_;

  base::WeakPtr<views::Widget> dialog_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_DIGITAL_CREDENTIALS_DIGITAL_IDENTITY_MULTI_STEP_DIALOG_H_