1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
8 #include "grit/generated_resources.h"
9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/views/controls/button/checkbox.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/layout/grid_layout.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/window/dialog_delegate.h"
21 // Default width/height of the dialog.
22 const int kDefaultWidth
= 600;
23 const int kDefaultHeight
= 250;
25 const int kPaddingToMessage
= 20;
26 const int kPaddingToCheckBox
= 50;
27 const int kInset
= 40;
29 ////////////////////////////////////////////////////////////////////////////////
30 // Dialog for multi-profiles introduction.
31 class MultiprofilesIntroView
: public views::DialogDelegateView
{
33 explicit MultiprofilesIntroView(const base::Callback
<void(bool)> on_accept
);
34 virtual ~MultiprofilesIntroView();
36 static void ShowDialog(const base::Callback
<void(bool)> on_accept
);
38 // views::DialogDelegate overrides.
39 virtual bool Accept() OVERRIDE
;
41 // views::WidgetDelegate overrides.
42 virtual ui::ModalType
GetModalType() const OVERRIDE
;
44 // views::View overrides.
45 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
50 scoped_ptr
<views::Checkbox
> no_show_checkbox_
;
51 const base::Callback
<void(bool)> on_accept_
;
53 DISALLOW_COPY_AND_ASSIGN(MultiprofilesIntroView
);
56 ////////////////////////////////////////////////////////////////////////////////
57 // MultiprofilesIntroDialog implementation.
59 MultiprofilesIntroView::MultiprofilesIntroView(
60 const base::Callback
<void(bool)> on_accept
)
61 : on_accept_(on_accept
) {
64 MultiprofilesIntroView::~MultiprofilesIntroView() {
68 void MultiprofilesIntroView::ShowDialog(
69 const base::Callback
<void(bool)> on_accept
) {
70 MultiprofilesIntroView
* dialog_view
=
71 new MultiprofilesIntroView(on_accept
);
72 views::DialogDelegate::CreateDialogWidget(
73 dialog_view
, ash::Shell::GetTargetRootWindow(), NULL
);
74 dialog_view
->InitDialog();
75 views::Widget
* widget
= dialog_view
->GetWidget();
80 bool MultiprofilesIntroView::Accept() {
81 on_accept_
.Run(no_show_checkbox_
->checked());
85 ui::ModalType
MultiprofilesIntroView::GetModalType() const {
86 return ui::MODAL_TYPE_SYSTEM
;
89 gfx::Size
MultiprofilesIntroView::GetPreferredSize() {
90 return gfx::Size(kDefaultWidth
, kDefaultHeight
);
93 void MultiprofilesIntroView::InitDialog() {
94 const gfx::Insets
kDialogInsets(kInset
, kInset
, kInset
, kInset
);
96 // Create the views and layout manager and set them up.
97 views::GridLayout
* grid_layout
= views::GridLayout::CreatePanel(this);
98 grid_layout
->SetInsets(kDialogInsets
);
100 views::ColumnSet
* column_set
= grid_layout
->AddColumnSet(0);
101 column_set
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 1,
102 views::GridLayout::USE_PREF
, 0, 0);
104 views::Label
* title_label_
= new views::Label(
105 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE
));
106 title_label_
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
107 ui::ResourceBundle::MediumBoldFont
));
108 title_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
109 grid_layout
->StartRow(0, 0);
110 grid_layout
->AddView(title_label_
);
111 grid_layout
->AddPaddingRow(0, kPaddingToMessage
);
113 // Explanation string.
114 views::Label
* label
= new views::Label(
115 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE
));
116 label
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
117 ui::ResourceBundle::MediumFont
));
118 label
->SetMultiLine(true);
119 label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
120 label
->SetAllowCharacterBreak(true);
121 grid_layout
->StartRow(0, 0);
122 grid_layout
->AddView(label
);
124 // Next explanation string.
125 grid_layout
->AddPaddingRow(0, kPaddingToMessage
);
126 views::Label
* lower_label
= new views::Label(
127 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_EXPLANATION
));
128 lower_label
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
129 ui::ResourceBundle::MediumFont
));
130 lower_label
->SetMultiLine(true);
131 lower_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
132 lower_label
->SetAllowCharacterBreak(true);
133 grid_layout
->StartRow(0, 0);
134 grid_layout
->AddView(lower_label
);
136 // No-show again checkbox.
137 grid_layout
->AddPaddingRow(0, kPaddingToCheckBox
);
138 no_show_checkbox_
.reset(new views::Checkbox(
139 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_NOSHOW_AGAIN
)));
140 no_show_checkbox_
->SetChecked(true);
141 no_show_checkbox_
->SetFontList(
142 ui::ResourceBundle::GetSharedInstance().GetFontList(
143 ui::ResourceBundle::MediumFont
));
144 no_show_checkbox_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
145 grid_layout
->StartRow(0, 0);
146 grid_layout
->AddView(no_show_checkbox_
.get());
148 SetLayoutManager(grid_layout
);
154 ////////////////////////////////////////////////////////////////////////////////
157 void ShowMultiprofilesIntroDialog(const base::Callback
<void(bool)> on_accept
) {
158 MultiprofilesIntroView::ShowDialog(on_accept
);
161 } // namespace chromeos