Skip to content

Commit

Permalink
Introduced Windows specific FirstRun dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Mar 22, 2022
1 parent eb4aaa8 commit a09befb
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,20 @@ Are you sure you want to do this?
<message name="IDS_FIRSTRUN_DLG_COMPLETE_INSTALLATION_LABEL_BRAVE" desc="Label at top of Dialog noting what's going to happen">
To ensure the best privacy online, consider setting Brave as the default browser on your computer. With Brave as default, any web link you click will open with Brave's privacy protections.
</message>
<if expr="is_win">
<message name="IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT" desc="Text for FirstRun dialog header">
Ready for the best privacy online?
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT" desc="Text for FirstRun dialog contents">
Set Brave as your default browser to get Brave's privacy protections on every web page you open.
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL" desc="Text for FirstRun dialog ok button">
Set Brave as default
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL" desc="Text for FirstRun dialog cancel button">
Maybe later
</message>
</if>
<message name="IDS_SETTINGS_WALLET_NETWORKS_ITEM" desc="The label for opening wallet networks list">
Networks
</message>
Expand Down
99 changes: 97 additions & 2 deletions browser/ui/views/first_run_dialog_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,107 @@

#include "brave/browser/ui/views/first_run_dialog_win.h"

#include "chrome/browser/first_run/first_run_dialog.h"
#include <memory>
#include <utility>

#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "brave/browser/brave_shell_integration.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/first_run/first_run.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/font.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/window/dialog_delegate.h"

namespace first_run {

void ShowFirstRunDialog(Profile* profile) {
// TODO(simonhong): Launch FirstRunDialogWin.
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
FirstRunDialogWin::Show(run_loop.QuitClosure());
run_loop.Run();
}

} // namespace first_run

// static
void FirstRunDialogWin::Show(base::RepeatingClosure quit_runloop) {
FirstRunDialogWin* dialog = new FirstRunDialogWin(std::move(quit_runloop));
views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show();
}

FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop)
: quit_runloop_(quit_runloop) {
set_should_ignore_snapping(true);
SetButtonLabel(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL));
SetButtonLabel(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL));
constexpr int kChildSpacing = 16;
constexpr int kPadding = 24;
constexpr int kTopPadding = 20;
constexpr int kBottomPadding = 55;

SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kTopPadding, kPadding, kBottomPadding, kPadding),
kChildSpacing));

constexpr int kHeaderFontSize = 16;
int size_diff =
kHeaderFontSize - views::Label::GetDefaultFontList().GetFontSize();
views::Label::CustomFont header_font = {
views::Label::GetDefaultFontList()
.DeriveWithSizeDelta(size_diff)
.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)};
auto* header_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT),
header_font));
header_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);

constexpr int kContentFontSize = 15;
size_diff =
kContentFontSize - views::Label::GetDefaultFontList().GetFontSize();
views::Label::CustomFont contents_font = {
views::Label::GetDefaultFontList()
.DeriveWithSizeDelta(size_diff)
.DeriveWithWeight(gfx::Font::Weight::NORMAL)};
auto* contents_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT),
contents_font));
contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
contents_label->SetMultiLine(true);
constexpr int kMaxWidth = 350;
contents_label->SetMaximumWidth(kMaxWidth);
}

FirstRunDialogWin::~FirstRunDialogWin() = default;

void FirstRunDialogWin::Done() {
CHECK(!quit_runloop_.is_null());
quit_runloop_.Run();
}

bool FirstRunDialogWin::Accept() {
GetWidget()->Hide();

base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
->StartSetAsDefault(base::NullCallback());

Done();
return true;
}

void FirstRunDialogWin::WindowClosing() {
first_run::SetShouldShowWelcomePage();
Done();
}

BEGIN_METADATA(FirstRunDialogWin, views::DialogDelegateView)
END_METADATA
29 changes: 28 additions & 1 deletion browser/ui/views/first_run_dialog_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@
#ifndef BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_
#define BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_

// TODO(simonhong): Implement FirstRunDialogWin.
#include "base/callback.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/window/dialog_delegate.h"

class FirstRunDialogWin : public views::DialogDelegateView {
public:
METADATA_HEADER(FirstRunDialogWin);

FirstRunDialogWin(const FirstRunDialogWin&) = delete;
FirstRunDialogWin& operator=(const FirstRunDialogWin&) = delete;

static void Show(base::RepeatingClosure quit_runloop);

private:
explicit FirstRunDialogWin(base::RepeatingClosure quit_runloop);
~FirstRunDialogWin() override;

// This terminates the nested message-loop.
void Done();

// views::DialogDelegate overrides:
bool Accept() override;

// views::WidgetDelegate overrides:
void WindowClosing() override;

base::RepeatingClosure quit_runloop_;
};

#endif // BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_

0 comments on commit a09befb

Please sign in to comment.