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