Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.cc

Issue 2439863004: Update two chromeos system dialogs to reuse more DialogDelegateView (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" 5 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/grit/generated_resources.h" 9 #include "chrome/grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/border.h"
12 #include "ui/views/controls/button/checkbox.h" 13 #include "ui/views/controls/button/checkbox.h"
13 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/grid_layout.h" 15 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/layout_constants.h"
15 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
16 #include "ui/views/window/dialog_delegate.h" 18 #include "ui/views/window/dialog_delegate.h"
17 19
18 namespace chromeos { 20 namespace chromeos {
19 21
20 namespace { 22 namespace {
21 23
22 // Default width/height of the dialog. 24 // Default width of the dialog.
23 const int kDefaultWidth = 600; 25 const int kDefaultWidth = 448;
24 const int kDefaultHeight = 250;
25
26 const int kPaddingToMessage = 20;
27 const int kPaddingToCheckBox = 50;
28 const int kInset = 40;
29 const int kTopInset = 10;
30 26
31 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
32 // Dialog for multi-profiles introduction. 28 // Dialog for multi-profiles introduction.
33 class MultiprofilesIntroView : public views::DialogDelegateView { 29 class MultiprofilesIntroView : public views::DialogDelegateView {
34 public: 30 public:
35 explicit MultiprofilesIntroView(const base::Callback<void(bool)> on_accept); 31 explicit MultiprofilesIntroView(const base::Callback<void(bool)> on_accept);
36 ~MultiprofilesIntroView() override; 32 ~MultiprofilesIntroView() override;
37 33
38 static void ShowDialog(const base::Callback<void(bool)> on_accept); 34 static void ShowDialog(const base::Callback<void(bool)> on_accept);
39 35
40 // views::DialogDelegate overrides. 36 // views::DialogDelegate overrides.
41 bool Accept() override; 37 bool Accept() override;
38 View* CreateExtraView() override;
42 39
43 // views::WidgetDelegate overrides. 40 // views::WidgetDelegate overrides.
44 ui::ModalType GetModalType() const override; 41 ui::ModalType GetModalType() const override;
42 base::string16 GetWindowTitle() const override;
45 43
46 // views::View overrides. 44 // views::View overrides.
47 gfx::Size GetPreferredSize() const override; 45 gfx::Size GetPreferredSize() const override;
48 46
49 private: 47 private:
50 void InitDialog(); 48 void InitDialog();
51 49
52 std::unique_ptr<views::Checkbox> no_show_checkbox_; 50 views::Checkbox* no_show_checkbox_;
53 const base::Callback<void(bool)> on_accept_; 51 const base::Callback<void(bool)> on_accept_;
54 52
55 DISALLOW_COPY_AND_ASSIGN(MultiprofilesIntroView); 53 DISALLOW_COPY_AND_ASSIGN(MultiprofilesIntroView);
56 }; 54 };
57 55
58 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
59 // MultiprofilesIntroDialog implementation. 57 // MultiprofilesIntroDialog implementation.
60 58
61 MultiprofilesIntroView::MultiprofilesIntroView( 59 MultiprofilesIntroView::MultiprofilesIntroView(
62 const base::Callback<void(bool)> on_accept) 60 const base::Callback<void(bool)> on_accept)
63 : on_accept_(on_accept) { 61 : on_accept_(on_accept) {
64 } 62 }
65 63
66 MultiprofilesIntroView::~MultiprofilesIntroView() { 64 MultiprofilesIntroView::~MultiprofilesIntroView() {
67 } 65 }
68 66
69 // static 67 // static
70 void MultiprofilesIntroView::ShowDialog( 68 void MultiprofilesIntroView::ShowDialog(
71 const base::Callback<void(bool)> on_accept) { 69 const base::Callback<void(bool)> on_accept) {
72 MultiprofilesIntroView* dialog_view = 70 MultiprofilesIntroView* dialog_view =
73 new MultiprofilesIntroView(on_accept); 71 new MultiprofilesIntroView(on_accept);
72 dialog_view->InitDialog();
74 views::DialogDelegate::CreateDialogWidget( 73 views::DialogDelegate::CreateDialogWidget(
75 dialog_view, ash::Shell::GetTargetRootWindow(), NULL); 74 dialog_view, ash::Shell::GetTargetRootWindow(), NULL);
76 dialog_view->InitDialog();
77 views::Widget* widget = dialog_view->GetWidget(); 75 views::Widget* widget = dialog_view->GetWidget();
78 DCHECK(widget); 76 DCHECK(widget);
79 widget->Show(); 77 widget->Show();
80 } 78 }
81 79
82 bool MultiprofilesIntroView::Accept() { 80 bool MultiprofilesIntroView::Accept() {
83 on_accept_.Run(no_show_checkbox_->checked()); 81 on_accept_.Run(no_show_checkbox_->checked());
84 return true; 82 return true;
85 } 83 }
86 84
85 views::View* MultiprofilesIntroView::CreateExtraView() {
86 no_show_checkbox_ = new views::Checkbox(
87 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_SHOW_DISMISS));
88 no_show_checkbox_->SetChecked(true);
89 return no_show_checkbox_;
90 }
91
87 ui::ModalType MultiprofilesIntroView::GetModalType() const { 92 ui::ModalType MultiprofilesIntroView::GetModalType() const {
88 return ui::MODAL_TYPE_SYSTEM; 93 return ui::MODAL_TYPE_SYSTEM;
89 } 94 }
90 95
96 base::string16 MultiprofilesIntroView::GetWindowTitle() const {
97 return l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE);
98 }
99
91 gfx::Size MultiprofilesIntroView::GetPreferredSize() const { 100 gfx::Size MultiprofilesIntroView::GetPreferredSize() const {
92 return gfx::Size(kDefaultWidth, kDefaultHeight); 101 return gfx::Size(
102 kDefaultWidth,
103 GetLayoutManager()->GetPreferredHeightForWidth(this, kDefaultWidth));
93 } 104 }
94 105
95 void MultiprofilesIntroView::InitDialog() { 106 void MultiprofilesIntroView::InitDialog() {
96 const gfx::Insets kDialogInsets(kTopInset, kInset, kInset, kInset); 107 SetBorder(views::Border::CreateEmptyBorder(views::kPanelVertMargin,
108 views::kButtonHEdgeMarginNew, 0,
109 views::kButtonHEdgeMarginNew));
110 SetLayoutManager(new views::FillLayout());
97 111
98 // Create the views and layout manager and set them up. 112 // Explanation string
99 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this);
100 grid_layout->SetInsets(kDialogInsets);
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_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
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.
116 views::Label* label = new views::Label( 113 views::Label* label = new views::Label(
117 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE)); 114 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE));
118 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
119 ui::ResourceBundle::MediumFont));
120 label->SetMultiLine(true); 115 label->SetMultiLine(true);
121 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 116 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
122 label->SetAllowCharacterBreak(true); 117 AddChildView(label);
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->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
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_->AdjustFontSize(ui::ResourceBundle::kMediumFontDelta);
144 no_show_checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
145 grid_layout->StartRow(0, 0);
146 grid_layout->AddView(no_show_checkbox_.get());
147
148 SetLayoutManager(grid_layout);
149 Layout();
150 } 118 }
151 119
152 } // namespace 120 } // namespace
153 121
154 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
155 // Factory function. 123 // Factory function.
156 124
157 void ShowMultiprofilesIntroDialog(const base::Callback<void(bool)> on_accept) { 125 void ShowMultiprofilesIntroDialog(const base::Callback<void(bool)> on_accept) {
158 MultiprofilesIntroView::ShowDialog(on_accept); 126 MultiprofilesIntroView::ShowDialog(on_accept);
159 } 127 }
160 128
161 } // namespace chromeos 129 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698