|
3 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
4 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */
|
5 | 5 |
|
6 |
| -#include "chrome/browser/ui/views/first_run_dialog.h" |
| 6 | +// We use our own FirstRun dialog on Windows/Linux. |
| 7 | +// ShowFirstRunDialog() is re-defined at brave_first_run_dialog.cc. |
| 8 | +#define ShowFirstRunDialog ShowFirstRunDialog_UnUsed |
7 | 9 |
|
8 |
| -#include <string> |
| 10 | +#include "src/chrome/browser/ui/views/first_run_dialog.cc" |
9 | 11 |
|
10 |
| -#include "base/bind.h" |
11 |
| -#include "base/run_loop.h" |
12 |
| -#include "brave/grit/brave_generated_resources.h" |
13 |
| -#include "build/build_config.h" |
14 |
| -#include "chrome/browser/first_run/first_run.h" |
15 |
| -#include "chrome/browser/first_run/first_run_dialog.h" |
16 |
| -#include "chrome/browser/platform_util.h" |
17 |
| -#include "chrome/browser/shell_integration.h" |
18 |
| -#include "chrome/browser/ui/browser_dialogs.h" |
19 |
| -#include "chrome/browser/ui/ui_features.h" |
20 |
| -#include "chrome/common/url_constants.h" |
21 |
| -#include "chrome/grit/chromium_strings.h" |
22 |
| -#include "chrome/grit/generated_resources.h" |
23 |
| -#include "components/strings/grit/components_strings.h" |
24 |
| -#include "ui/base/l10n/l10n_util.h" |
25 |
| -#include "ui/base/metadata/metadata_impl_macros.h" |
26 |
| -#include "ui/views/border.h" |
27 |
| -#include "ui/views/controls/button/checkbox.h" |
28 |
| -#include "ui/views/controls/link.h" |
29 |
| -#include "ui/views/layout/box_layout.h" |
30 |
| -#include "ui/views/widget/widget.h" |
31 |
| -#include "ui/views/window/dialog_delegate.h" |
32 |
| - |
33 |
| -namespace first_run { |
34 |
| - |
35 |
| -void ShowFirstRunDialog(Profile* profile) { |
36 |
| -#if BUILDFLAG(IS_MAC) |
37 |
| - if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog)) |
38 |
| - ShowFirstRunDialogViews(profile); |
39 |
| - else |
40 |
| - ShowFirstRunDialogCocoa(profile); |
41 |
| -#else |
42 |
| - ShowFirstRunDialogViews(profile); |
43 |
| -#endif |
44 |
| -} |
45 |
| - |
46 |
| -void ShowFirstRunDialogViews(Profile* profile) { |
47 |
| - base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); |
48 |
| - FirstRunDialog::Show( |
49 |
| - base::BindRepeating(&platform_util::OpenExternal, |
50 |
| - base::Unretained(profile), |
51 |
| - GURL(chrome::kLearnMoreReportingURL)), |
52 |
| - run_loop.QuitClosure()); |
53 |
| - run_loop.Run(); |
54 |
| -} |
55 |
| - |
56 |
| -} // namespace first_run |
57 |
| - |
58 |
| -// static |
59 |
| -void FirstRunDialog::Show(base::RepeatingClosure learn_more_callback, |
60 |
| - base::RepeatingClosure quit_runloop) { |
61 |
| - FirstRunDialog* dialog = new FirstRunDialog(std::move(learn_more_callback), |
62 |
| - std::move(quit_runloop)); |
63 |
| - views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); |
64 |
| -} |
65 |
| - |
66 |
| -FirstRunDialog::FirstRunDialog(base::RepeatingClosure learn_more_callback, |
67 |
| - base::RepeatingClosure quit_runloop) |
68 |
| - : quit_runloop_(quit_runloop) { |
69 |
| - // ALLOW_UNUSED_LOCAL has been removed and [[maybe_unused]] can only be used |
70 |
| - // alongside declarations, so reference it here just to silence the compiler's |
71 |
| - // -Wunused errors without having to override the header file. |
72 |
| - if (report_crashes_) |
73 |
| - report_crashes_->GetChecked(); |
74 |
| - |
75 |
| - SetTitle(l10n_util::GetStringUTF16(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE)); |
76 |
| - SetButtons(ui::DIALOG_BUTTON_OK); |
77 |
| - SetExtraView( |
78 |
| - std::make_unique<views::Link>(l10n_util::GetStringUTF16(IDS_LEARN_MORE))) |
79 |
| - ->SetCallback(std::move(learn_more_callback)); |
80 |
| - |
81 |
| - constexpr int kChildSpacing = 16; |
82 |
| - constexpr int kPadding = 24; |
83 |
| - |
84 |
| - SetLayoutManager(std::make_unique<views::BoxLayout>( |
85 |
| - views::BoxLayout::Orientation::kVertical, |
86 |
| - gfx::Insets(kPadding, kPadding, kPadding, kPadding), kChildSpacing)); |
87 |
| - |
88 |
| - constexpr int kFontSize = 15; |
89 |
| - int size_diff = kFontSize - views::Label::GetDefaultFontList().GetFontSize(); |
90 |
| - views::Label::CustomFont contents_font = { |
91 |
| - views::Label::GetDefaultFontList() |
92 |
| - .DeriveWithSizeDelta(size_diff) |
93 |
| - .DeriveWithWeight(gfx::Font::Weight::NORMAL)}; |
94 |
| - auto* contents_label = AddChildView(std::make_unique<views::Label>( |
95 |
| - l10n_util::GetStringUTF16( |
96 |
| - IDS_FIRSTRUN_DLG_COMPLETE_INSTALLATION_LABEL_BRAVE), |
97 |
| - contents_font)); |
98 |
| - contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
99 |
| - contents_label->SetMultiLine(true); |
100 |
| - constexpr int kMaxWidth = 450; |
101 |
| - contents_label->SetMaximumWidth(kMaxWidth); |
102 |
| - |
103 |
| - make_default_ = AddChildView(std::make_unique<views::Checkbox>( |
104 |
| - l10n_util::GetStringUTF16(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER_BRAVE))); |
105 |
| - make_default_->SetChecked(true); |
106 |
| - |
107 |
| - chrome::RecordDialogCreation(chrome::DialogIdentifier::FIRST_RUN_DIALOG); |
108 |
| -} |
109 |
| - |
110 |
| -FirstRunDialog::~FirstRunDialog() = default; |
111 |
| - |
112 |
| -void FirstRunDialog::Done() { |
113 |
| - CHECK(!quit_runloop_.is_null()); |
114 |
| - quit_runloop_.Run(); |
115 |
| -} |
116 |
| - |
117 |
| -bool FirstRunDialog::Accept() { |
118 |
| - GetWidget()->Hide(); |
119 |
| - |
120 |
| - if (make_default_->GetChecked()) |
121 |
| - shell_integration::SetAsDefaultBrowser(); |
122 |
| - |
123 |
| - Done(); |
124 |
| - return true; |
125 |
| -} |
126 |
| - |
127 |
| -void FirstRunDialog::WindowClosing() { |
128 |
| - first_run::SetShouldShowWelcomePage(); |
129 |
| - Done(); |
130 |
| -} |
131 |
| - |
132 |
| -BEGIN_METADATA(FirstRunDialog, views::DialogDelegateView) |
133 |
| -END_METADATA |
| 12 | +#undef ShowFirstRunDialog |
0 commit comments