| 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/ui/ash/multi_user/multi_user_warning_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 "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 = 30; | |
| 27 const int kPaddingToCheckBox = 50; | |
| 28 const int kInset = 40; | |
| 29 const int kTopInset = 10; | |
| 30 | 26 |
| 31 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
| 32 // Dialog for multi-profiles teleport warning. | 28 // Dialog for multi-profiles teleport warning. |
| 33 class TeleportWarningView : public views::DialogDelegateView { | 29 class TeleportWarningView : public views::DialogDelegateView { |
| 34 public: | 30 public: |
| 35 explicit TeleportWarningView(const base::Callback<void(bool)>& on_accept); | 31 explicit TeleportWarningView(const base::Callback<void(bool)>& on_accept); |
| 36 ~TeleportWarningView() override; | 32 ~TeleportWarningView() 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(TeleportWarningView); | 53 DISALLOW_COPY_AND_ASSIGN(TeleportWarningView); |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 59 // TeleportWarningView implementation. | 57 // TeleportWarningView implementation. |
| 60 | 58 |
| 61 TeleportWarningView::TeleportWarningView( | 59 TeleportWarningView::TeleportWarningView( |
| 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 TeleportWarningView::~TeleportWarningView() { | 64 TeleportWarningView::~TeleportWarningView() { |
| 67 } | 65 } |
| 68 | 66 |
| 69 // static | 67 // static |
| 70 void TeleportWarningView::ShowDialog( | 68 void TeleportWarningView::ShowDialog( |
| 71 const base::Callback<void(bool)>& on_accept) { | 69 const base::Callback<void(bool)>& on_accept) { |
| 72 TeleportWarningView* dialog_view = | 70 TeleportWarningView* dialog_view = |
| 73 new TeleportWarningView(on_accept); | 71 new TeleportWarningView(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 TeleportWarningView::Accept() { | 80 bool TeleportWarningView::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* TeleportWarningView::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 TeleportWarningView::GetModalType() const { | 92 ui::ModalType TeleportWarningView::GetModalType() const { |
| 88 return ui::MODAL_TYPE_SYSTEM; | 93 return ui::MODAL_TYPE_SYSTEM; |
| 89 } | 94 } |
| 90 | 95 |
| 96 base::string16 TeleportWarningView::GetWindowTitle() const { |
| 97 return l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_TITLE); |
| 98 } |
| 99 |
| 91 gfx::Size TeleportWarningView::GetPreferredSize() const { | 100 gfx::Size TeleportWarningView::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 TeleportWarningView::InitDialog() { | 106 void TeleportWarningView::InitDialog() { |
| 96 const gfx::Insets kDialogInsets(kTopInset, kInset, kInset, kInset); | 107 SetBorder(views::Border::CreateEmptyBorder(views::kPanelVertMargin, |
| 97 | 108 views::kButtonHEdgeMarginNew, 0, |
| 98 // Create the views and layout manager and set them up. | 109 views::kButtonHEdgeMarginNew)); |
| 99 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); | 110 SetLayoutManager(new views::FillLayout()); |
| 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 // Title | |
| 107 views::Label* title_label_ = new views::Label( | |
| 108 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_TITLE)); | |
| 109 title_label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 110 ui::ResourceBundle::MediumBoldFont)); | |
| 111 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 112 grid_layout->StartRow(0, 0); | |
| 113 grid_layout->AddView(title_label_); | |
| 114 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
| 115 | 111 |
| 116 // Explanation string | 112 // Explanation string |
| 117 views::Label* label = new views::Label( | 113 views::Label* label = new views::Label( |
| 118 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_MESSAGE)); | 114 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_MESSAGE)); |
| 119 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 120 ui::ResourceBundle::MediumFont)); | |
| 121 label->SetMultiLine(true); | 115 label->SetMultiLine(true); |
| 122 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 116 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 123 label->SetAllowCharacterBreak(true); | 117 AddChildView(label); |
| 124 grid_layout->StartRow(0, 0); | |
| 125 grid_layout->AddView(label); | |
| 126 | |
| 127 // Next explanation string | |
| 128 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
| 129 views::Label* lower_label = new views::Label( | |
| 130 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_EXPLANATION)); | |
| 131 lower_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 132 ui::ResourceBundle::MediumFont)); | |
| 133 lower_label->SetMultiLine(true); | |
| 134 lower_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 135 lower_label->SetAllowCharacterBreak(true); | |
| 136 grid_layout->StartRow(0, 0); | |
| 137 grid_layout->AddView(lower_label); | |
| 138 | |
| 139 // No-show again checkbox | |
| 140 grid_layout->AddPaddingRow(0, kPaddingToCheckBox); | |
| 141 no_show_checkbox_.reset(new views::Checkbox( | |
| 142 l10n_util::GetStringUTF16(IDS_VISIT_DESKTOP_WARNING_SHOW_DISMISS))); | |
| 143 no_show_checkbox_->SetChecked(true); | |
| 144 no_show_checkbox_->SetFontList( | |
| 145 ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 146 ui::ResourceBundle::MediumFont)); | |
| 147 grid_layout->StartRow(0, 0); | |
| 148 grid_layout->AddView(no_show_checkbox_.get()); | |
| 149 | |
| 150 SetLayoutManager(grid_layout); | |
| 151 Layout(); | |
| 152 } | 118 } |
| 153 | 119 |
| 154 } // namespace | 120 } // namespace |
| 155 | 121 |
| 156 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
| 157 // Factory function. | 123 // Factory function. |
| 158 | 124 |
| 159 void ShowMultiprofilesWarningDialog( | 125 void ShowMultiprofilesWarningDialog( |
| 160 const base::Callback<void(bool)>& on_accept) { | 126 const base::Callback<void(bool)>& on_accept) { |
| 161 TeleportWarningView::ShowDialog(on_accept); | 127 TeleportWarningView::ShowDialog(on_accept); |
| 162 } | 128 } |
| 163 | 129 |
| 164 } // namespace chromeos | 130 } // namespace chromeos |
| OLD | NEW |