File: policy_dialog_base.cc

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (156 lines) | stat: -rw-r--r-- 5,592 bytes parent folder | download | duplicates (6)
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
// 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.

#include "chrome/browser/chromeos/policy/dlp/dialogs/policy_dialog_base.h"

#include <memory>
#include <string>
#include <utility>

#include "ash/public/cpp/style/color_provider.h"
#include "base/functional/callback_forward.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/ui_base_types.h"
#include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/widget/widget.h"

namespace policy {

namespace {

// The corner radius.
constexpr int kDialogCornerRadius = 12;

// The insets in the upper part of the dialog.
constexpr auto kTopPanelInsets = gfx::Insets::TLBR(0, 24, 16, 24);

// The insests in the container holding the list of confidential contents.
constexpr auto kConfidentialListInsets = gfx::Insets::TLBR(8, 24, 8, 24);

// The spacing between the elements in a box layout.
constexpr int kBetweenChildSpacing = 16;

// The size of the managed icon.
constexpr int kManagedIconSize = 32;

// The size of the favicon.
constexpr int kFaviconSize = 20;

// Maximum height of the confidential content scrollable list.
// This can hold seven rows.
constexpr int kConfidentialContentListMaxHeight = 240;

}  // namespace

PolicyDialogBase::PolicyDialogBase() {
  SetShowCloseButton(false);

  set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
      views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
  set_corner_radius(kDialogCornerRadius);

  SetLayoutManager(std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kVertical));
}

PolicyDialogBase::~PolicyDialogBase() = default;

void PolicyDialogBase::SetupUpperPanel() {
  upper_panel_ = AddChildView(std::make_unique<views::View>());
  views::BoxLayout* layout =
      upper_panel_->SetLayoutManager(std::make_unique<views::BoxLayout>(
          views::BoxLayout::Orientation::kVertical, kTopPanelInsets,
          kBetweenChildSpacing));
  layout->set_cross_axis_alignment(
      views::BoxLayout::CrossAxisAlignment::kStart);

  views::ImageView* managed_icon =
      upper_panel_->AddChildView(std::make_unique<views::ImageView>());
  auto color = ash::ColorProvider::Get()->GetContentLayerColor(
      ash::ColorProvider::ContentLayerType::kIconColorPrimary);
  managed_icon->SetImage(ui::ImageModel::FromVectorIcon(
      vector_icons::kBusinessIcon, color, kManagedIconSize));
}

views::Label* PolicyDialogBase::AddTitle(const std::u16string& title) {
  DCHECK(upper_panel_);

  views::Label* title_label =
      upper_panel_->AddChildView(std::make_unique<views::Label>(title));
  title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  title_label->SetAllowCharacterBreak(true);
  title_label->SetEnabledColor(ash::ColorProvider::Get()->GetContentLayerColor(
      ash::ColorProvider::ContentLayerType::kTextColorPrimary));
  return title_label;
}

views::Label* PolicyDialogBase::AddMessage(const std::u16string& message) {
  DCHECK(upper_panel_);

  views::Label* message_label =
      upper_panel_->AddChildView(std::make_unique<views::Label>(message));
  message_label->SetMultiLine(true);
  message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  message_label->SetAllowCharacterBreak(true);
  message_label->SetEnabledColor(
      ash::ColorProvider::Get()->GetContentLayerColor(
          ash::ColorProvider::ContentLayerType::kTextColorSecondary));
  return message_label;
}

void PolicyDialogBase::SetupScrollView() {
  views::ScrollView* scroll_view =
      AddChildView(std::make_unique<views::ScrollView>());
  scroll_view->ClipHeightTo(0, kConfidentialContentListMaxHeight);
  scroll_view_container_ =
      scroll_view->SetContents(std::make_unique<views::View>());
  scroll_view_container_->SetID(kScrollViewId);
  views::BoxLayout* layout = scroll_view_container_->SetLayoutManager(
      std::make_unique<views::BoxLayout>(
          views::BoxLayout::Orientation::kVertical, kConfidentialListInsets,
          /*between_child_spacing=*/0));
  layout->set_cross_axis_alignment(
      views::BoxLayout::CrossAxisAlignment::kStart);
}

void PolicyDialogBase::AddGeneralInformation() {
  SetupUpperPanel();
  AddTitle(GetTitle());
  AddMessage(GetMessage());
}

void PolicyDialogBase::AddRowIcon(const gfx::ImageSkia& icon,
                                  views::View* row) {
  views::ImageView* icon_view =
      row->AddChildView(std::make_unique<views::ImageView>());
  icon_view->SetImageSize(gfx::Size(kFaviconSize, kFaviconSize));
  icon_view->SetImage(ui::ImageModel::FromImageSkia(icon));
}

views::Label* PolicyDialogBase::AddRowTitle(const std::u16string& title,
                                            views::View* row) {
  views::Label* label =
      row->AddChildView(std::make_unique<views::Label>(title));
  label->SetMultiLine(true);
  label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  label->SetAllowCharacterBreak(true);
  label->SetEnabledColor(ash::ColorProvider::Get()->GetContentLayerColor(
      ash::ColorProvider::ContentLayerType::kTextColorSecondary));
  return label;
}

BEGIN_METADATA(PolicyDialogBase)
END_METADATA

}  // namespace policy