Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 "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" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Default width/height of the dialog. | |
| 22 const int kDefaultWidth = 600; | |
| 23 const int kDefaultHeight = 250; | |
| 24 | |
| 25 const int kPaddingToMessage = 20; | |
| 26 const int kPaddingToCheckBox = 50; | |
| 27 const gfx::Insets kInsets = gfx::Insets(40, 40, 40, 40); | |
|
oshima
2014/01/10 19:14:07
non POD global object is not allowed. You may move
merkulova
2014/01/14 09:55:58
Done.
merkulova
2014/01/16 10:24:01
Hi, Oshima.
On committing I discovered that non PO
| |
| 28 | |
| 29 //////////////////////////////////////////////////////////////////////////////// | |
| 30 // Dialog for multi-profiles introduction. | |
| 31 class MultiprofilesIntroView : public views::DialogDelegateView { | |
| 32 public: | |
| 33 MultiprofilesIntroView(base::Callback<void(bool)> on_accept); | |
|
oshima
2014/01/10 19:14:07
explicit
merkulova
2014/01/14 09:55:58
Done.
| |
| 34 virtual ~MultiprofilesIntroView(); | |
| 35 | |
| 36 static void ShowDialog(base::Callback<void(bool)> on_accept); | |
| 37 | |
| 38 virtual bool Accept() OVERRIDE; | |
| 39 | |
| 40 // views::WidgetDelegate overrides | |
| 41 virtual ui::ModalType GetModalType() const OVERRIDE; | |
| 42 | |
| 43 // views::View overrides | |
| 44 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 45 | |
| 46 private: | |
| 47 void InitDialog(); | |
| 48 | |
| 49 scoped_ptr<views::Checkbox> no_show_checkbox_; | |
| 50 base::Callback<void(bool)> on_accept_; | |
|
oshima
2014/01/10 19:14:07
can this be const?
merkulova
2014/01/14 09:55:58
Done.
| |
| 51 }; | |
|
oshima
2014/01/10 19:14:07
DISALLOW_COPY_AND_ASSIGN
merkulova
2014/01/14 09:55:58
Done.
| |
| 52 | |
| 53 //////////////////////////////////////////////////////////////////////////////// | |
| 54 // MultiprofilesIntroDialog implementation. | |
| 55 | |
| 56 MultiprofilesIntroView::MultiprofilesIntroView( | |
| 57 base::Callback<void(bool)> on_accept) : on_accept_(on_accept){ | |
| 58 } | |
| 59 | |
| 60 MultiprofilesIntroView::~MultiprofilesIntroView() { | |
| 61 } | |
| 62 | |
| 63 // static | |
| 64 void MultiprofilesIntroView::ShowDialog(base::Callback<void(bool)> on_accept) { | |
| 65 MultiprofilesIntroView* dialog_view = | |
| 66 new MultiprofilesIntroView(on_accept); | |
| 67 views::DialogDelegate::CreateDialogWidget( | |
| 68 dialog_view, ash::Shell::GetPrimaryRootWindow(), NULL); | |
| 69 dialog_view->InitDialog(); | |
| 70 views::Widget* widget = dialog_view->GetWidget(); | |
| 71 DCHECK(widget); | |
| 72 widget->Show(); | |
| 73 } | |
| 74 | |
| 75 bool MultiprofilesIntroView::Accept() { | |
| 76 on_accept_.Run(no_show_checkbox_->checked()); | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 ui::ModalType MultiprofilesIntroView::GetModalType() const { | |
| 81 return ui::MODAL_TYPE_SYSTEM; | |
| 82 } | |
| 83 | |
| 84 gfx::Size MultiprofilesIntroView::GetPreferredSize() { | |
| 85 return gfx::Size(kDefaultWidth, kDefaultHeight); | |
| 86 } | |
| 87 | |
| 88 void MultiprofilesIntroView::InitDialog() { | |
| 89 // Create the views and layout manager and set them up. | |
| 90 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); | |
| 91 grid_layout->SetInsets(kInsets); | |
| 92 | |
| 93 views::ColumnSet* column_set = grid_layout->AddColumnSet(0); | |
| 94 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 95 views::GridLayout::USE_PREF, 0, 0); | |
| 96 | |
| 97 views::Label* title_label_ = new views::Label( | |
| 98 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE)); | |
| 99 title_label_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 100 ui::ResourceBundle::MediumBoldFont)); | |
| 101 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
|
oshima
2014/01/10 19:14:07
Any RTL/i18n issue here?
merkulova
2014/01/14 09:55:58
It will automatically mirror the dialog for RTL lo
| |
| 102 grid_layout->StartRow(0, 0); | |
| 103 grid_layout->AddView(title_label_); | |
| 104 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
| 105 | |
| 106 // Explanation string | |
| 107 views::Label* label = new views::Label( | |
| 108 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE)); | |
| 109 label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 110 ui::ResourceBundle::MediumFont)); | |
| 111 label->SetMultiLine(true); | |
| 112 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 113 label->SetAllowCharacterBreak(true); | |
| 114 grid_layout->StartRow(0, 0); | |
| 115 grid_layout->AddView(label); | |
| 116 | |
| 117 // Next explanation string | |
| 118 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
| 119 views::Label* lower_label = new views::Label( | |
| 120 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_EXPLANATION)); | |
| 121 lower_label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 122 ui::ResourceBundle::MediumFont)); | |
| 123 lower_label->SetMultiLine(true); | |
| 124 lower_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 125 lower_label->SetAllowCharacterBreak(true); | |
| 126 grid_layout->StartRow(0, 0); | |
| 127 grid_layout->AddView(lower_label); | |
| 128 | |
| 129 // No-show again checkbox | |
| 130 grid_layout->AddPaddingRow(0, kPaddingToCheckBox); | |
| 131 no_show_checkbox_.reset(new views::Checkbox( | |
| 132 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_NOSHOW_AGAIN))); | |
| 133 no_show_checkbox_->SetChecked(true); | |
| 134 no_show_checkbox_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 135 ui::ResourceBundle::MediumFont)); | |
| 136 grid_layout->StartRow(0, 0); | |
| 137 grid_layout->AddView(no_show_checkbox_.get()); | |
| 138 | |
| 139 SetLayoutManager(grid_layout); | |
| 140 Layout(); | |
| 141 } | |
| 142 | |
| 143 } // namespace | |
| 144 | |
| 145 //////////////////////////////////////////////////////////////////////////////// | |
| 146 // Factory function. | |
| 147 | |
| 148 void ShowMultiprofilesIntroDialog(base::Callback<void(bool)> on_accept) { | |
| 149 MultiprofilesIntroView::ShowDialog(on_accept); | |
| 150 } | |
| 151 | |
| 152 } // namespace chromeos | |
| OLD | NEW |