OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "base/i18n/rtl.h" | |
9 #include "grit/generated_resources.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 #include "ui/base/resource/resource_bundle.h" | |
12 #include "ui/views/controls/button/checkbox.h" | |
13 #include "ui/views/controls/label.h" | |
14 #include "ui/views/layout/grid_layout.h" | |
15 #include "ui/views/widget/widget.h" | |
16 #include "ui/views/window/dialog_delegate.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 namespace { | |
21 | |
22 // Default width/height of the dialog. | |
23 const int kDefaultWidth = 600; | |
24 const int kDefaultHeight = 250; | |
25 | |
26 const int kPaddingToMessage = 20; | |
27 const int kPaddingToCheckBox = 50; | |
28 const int kInset = 40; | |
29 | |
30 //////////////////////////////////////////////////////////////////////////////// | |
31 // Dialog for multi-profiles introduction. | |
32 class MultiprofilesIntroView : public views::DialogDelegateView { | |
33 public: | |
34 explicit MultiprofilesIntroView(const base::Callback<void(bool)> on_accept); | |
35 virtual ~MultiprofilesIntroView(); | |
36 | |
37 static void ShowDialog(const base::Callback<void(bool)> on_accept); | |
38 | |
39 virtual bool Accept() OVERRIDE; | |
Nikita (slow)
2014/01/14 13:44:11
nit: // views::DialogDelegate overrides.
merkulova
2014/01/14 14:29:34
Done.
| |
40 | |
41 // views::WidgetDelegate overrides | |
Nikita (slow)
2014/01/14 13:44:11
nit: Add dot at each comment sentence (here and be
merkulova
2014/01/14 14:29:34
Done.
| |
42 virtual ui::ModalType GetModalType() const OVERRIDE; | |
43 | |
44 // views::View overrides | |
45 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
46 | |
47 private: | |
48 void InitDialog(); | |
49 | |
50 scoped_ptr<views::Checkbox> no_show_checkbox_; | |
51 const base::Callback<void(bool)> on_accept_; | |
52 | |
53 static const gfx::Insets dialogInsets; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(MultiprofilesIntroView); | |
56 }; | |
57 | |
58 const gfx::Insets MultiprofilesIntroView::dialogInsets(kInset, kInset, | |
59 kInset, kInset); | |
60 | |
61 //////////////////////////////////////////////////////////////////////////////// | |
62 // MultiprofilesIntroDialog implementation. | |
63 | |
64 MultiprofilesIntroView::MultiprofilesIntroView( | |
65 const base::Callback<void(bool)> on_accept) : on_accept_(on_accept) { | |
66 } | |
67 | |
68 MultiprofilesIntroView::~MultiprofilesIntroView() { | |
69 } | |
70 | |
71 // static | |
72 void MultiprofilesIntroView::ShowDialog( | |
73 const base::Callback<void(bool)> on_accept) { | |
74 MultiprofilesIntroView* dialog_view = | |
75 new MultiprofilesIntroView(on_accept); | |
76 views::DialogDelegate::CreateDialogWidget( | |
77 dialog_view, ash::Shell::GetPrimaryRootWindow(), NULL); | |
78 dialog_view->InitDialog(); | |
79 views::Widget* widget = dialog_view->GetWidget(); | |
80 DCHECK(widget); | |
81 widget->Show(); | |
82 } | |
83 | |
84 bool MultiprofilesIntroView::Accept() { | |
85 on_accept_.Run(no_show_checkbox_->checked()); | |
86 return true; | |
87 } | |
88 | |
89 ui::ModalType MultiprofilesIntroView::GetModalType() const { | |
90 return ui::MODAL_TYPE_SYSTEM; | |
91 } | |
92 | |
93 gfx::Size MultiprofilesIntroView::GetPreferredSize() { | |
94 return gfx::Size(kDefaultWidth, kDefaultHeight); | |
95 } | |
96 | |
97 void MultiprofilesIntroView::InitDialog() { | |
Nikita (slow)
2014/01/14 13:44:11
Please make layout RTL friendly.
merkulova
2014/01/14 14:29:34
It is already friendly. The dialog is automaticall
| |
98 // Create the views and layout manager and set them up. | |
99 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); | |
100 grid_layout->SetInsets(MultiprofilesIntroView::dialogInsets); | |
101 | |
102 views::ColumnSet* column_set = grid_layout->AddColumnSet(0); | |
103 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
104 views::GridLayout::USE_PREF, 0, 0); | |
105 | |
106 views::Label* title_label_ = new views::Label( | |
107 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE)); | |
108 title_label_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
109 ui::ResourceBundle::MediumBoldFont)); | |
110 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
111 grid_layout->StartRow(0, 0); | |
112 grid_layout->AddView(title_label_); | |
113 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
114 | |
115 // Explanation string | |
Nikita (slow)
2014/01/14 13:44:11
nit: Dot at the and here and below.
merkulova
2014/01/14 14:29:34
Done.
| |
116 views::Label* label = new views::Label( | |
117 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE)); | |
118 label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
119 ui::ResourceBundle::MediumFont)); | |
120 label->SetMultiLine(true); | |
121 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
122 label->SetAllowCharacterBreak(true); | |
123 grid_layout->StartRow(0, 0); | |
124 grid_layout->AddView(label); | |
125 | |
126 // Next explanation string | |
127 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
128 views::Label* lower_label = new views::Label( | |
129 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_EXPLANATION)); | |
130 lower_label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
131 ui::ResourceBundle::MediumFont)); | |
132 lower_label->SetMultiLine(true); | |
133 lower_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
134 lower_label->SetAllowCharacterBreak(true); | |
135 grid_layout->StartRow(0, 0); | |
136 grid_layout->AddView(lower_label); | |
137 | |
138 // No-show again checkbox | |
139 grid_layout->AddPaddingRow(0, kPaddingToCheckBox); | |
140 no_show_checkbox_.reset(new views::Checkbox( | |
141 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_NOSHOW_AGAIN))); | |
142 no_show_checkbox_->SetChecked(true); | |
143 no_show_checkbox_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
144 ui::ResourceBundle::MediumFont)); | |
145 no_show_checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
146 grid_layout->StartRow(0, 0); | |
147 grid_layout->AddView(no_show_checkbox_.get()); | |
148 | |
149 SetLayoutManager(grid_layout); | |
150 Layout(); | |
Nikita (slow)
2014/01/14 13:44:11
nit: I don't think that you need to call Layout()
merkulova
2014/01/14 14:29:34
It is necessary actually. Without this call, we ge
| |
151 } | |
152 | |
153 } // namespace | |
154 | |
155 //////////////////////////////////////////////////////////////////////////////// | |
156 // Factory function. | |
157 | |
158 void ShowMultiprofilesIntroDialog(const base::Callback<void(bool)> on_accept) { | |
159 MultiprofilesIntroView::ShowDialog(on_accept); | |
160 } | |
161 | |
162 } // namespace chromeos | |
OLD | NEW |