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
|
// Copyright 2020 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/ui/views/apps/app_dialog/app_dialog_view.h"
#include <memory>
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/style/typography.h"
#include "ui/views/view_class_properties.h"
namespace {
constexpr int kSubtitleBottomMargin = 4;
constexpr int kTitleTopMargin = 4;
} // namespace
AppDialogView::AppDialogView(const ui::ImageModel& image)
: BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE) {
SetIcon(image);
SetShowIcon(true);
SetShowCloseButton(false);
SetModalType(ui::mojom::ModalType::kSystem);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH));
}
AppDialogView::~AppDialogView() = default;
std::optional<std::u16string> AppDialogView::GetTitleTextForTesting() const {
if (title_) {
return std::u16string(title_->GetText());
}
return std::nullopt;
}
void AppDialogView::InitializeView() {
SetButtons(static_cast<int>(ui::mojom::DialogButton::kOk));
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
}
void AppDialogView::AddTitle(const std::u16string& title_text) {
title_ = AddChildView(std::make_unique<views::Label>(
title_text, views::style::CONTEXT_DIALOG_TITLE,
views::style::STYLE_HEADLINE_3));
title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title_->SetMultiLine(true);
title_->SetProperty(views::kMarginsKey,
gfx::Insets::TLBR(kTitleTopMargin, 0, 0, 0));
SetAccessibleTitle(title_text);
}
void AppDialogView::AddSubtitle(const std::u16string& subtitle_text) {
subtitle_ = AddChildView(std::make_unique<views::Label>(
subtitle_text, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_PRIMARY));
subtitle_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
subtitle_->SetMultiLine(true);
subtitle_->SetProperty(views::kMarginsKey,
gfx::Insets::TLBR(0, 0, kSubtitleBottomMargin, 0));
}
void AppDialogView::SetTitleText(const std::u16string& text) {
CHECK(title_);
title_->SetText(text);
}
void AppDialogView::SetSubtitleText(const std::u16string& text) {
CHECK(subtitle_);
subtitle_->SetText(text);
if (GetWidget()) {
GetWidget()->UpdateAccessibleNameForRootView();
}
}
std::u16string AppDialogView::GetAccessibleWindowTitle() const {
if (title_) {
return std::u16string(title_->GetText());
}
return std::u16string();
}
BEGIN_METADATA(AppDialogView)
END_METADATA
|