| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/views/chrome_cleaner_dialog.h" | 5 #include "chrome/browser/ui/views/chrome_cleaner_dialog.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "chrome/browser/safe_browsing/chrome_cleaner_dialog_controller.h" | 8 #include "chrome/browser/safe_browsing/chrome_cleaner_dialog_controller.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "components/constrained_window/constrained_window_views.h" | 12 #include "components/constrained_window/constrained_window_views.h" |
| 13 #include "ui/base/ui_base_types.h" | 13 #include "ui/base/ui_base_types.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
| 16 #include "ui/gfx/text_constants.h" | 16 #include "ui/gfx/text_constants.h" |
| 17 #include "ui/views/controls/button/md_text_button.h" |
| 17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
| 19 #include "ui/views/layout/layout_constants.h" | 20 #include "ui/views/layout/layout_constants.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 | 22 |
| 22 namespace chrome { | 23 namespace chrome { |
| 23 | 24 |
| 24 void ShowChromeCleanerPrompt( | 25 void ShowChromeCleanerPrompt( |
| 25 Browser* browser, | 26 Browser* browser, |
| 26 safe_browsing::ChromeCleanerDialogController* controller) { | 27 safe_browsing::ChromeCleanerDialogController* controller) { |
| 27 ChromeCleanerDialog* dialog = new ChromeCleanerDialog(controller); | 28 ChromeCleanerDialog* dialog = new ChromeCleanerDialog(controller); |
| 28 dialog->Show(browser); | 29 dialog->Show(browser); |
| 29 } | 30 } |
| 30 | 31 |
| 31 } // namespace chrome | 32 } // namespace chrome |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 constexpr int kDialogWidth = 448; | 35 constexpr int kDialogWidth = 448; |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 38 // ChromeCleanerDialog | 39 // ChromeCleanerDialog |
| 39 | 40 |
| 40 ChromeCleanerDialog::ChromeCleanerDialog( | 41 ChromeCleanerDialog::ChromeCleanerDialog( |
| 41 safe_browsing::ChromeCleanerDialogController* controller) | 42 safe_browsing::ChromeCleanerDialogController* controller) |
| 42 : browser_(nullptr), | 43 : browser_(nullptr), controller_(controller) { |
| 43 controller_(controller), | |
| 44 advanced_button_( | |
| 45 new views::LabelButton(this, controller_->GetAdvancedButtonLabel())) { | |
| 46 DCHECK(controller_); | 44 DCHECK(controller_); |
| 47 | 45 |
| 48 SetLayoutManager(new views::BoxLayout( | 46 SetLayoutManager(new views::BoxLayout( |
| 49 /*orientation=*/views::BoxLayout::kVertical, | 47 /*orientation=*/views::BoxLayout::kVertical, |
| 50 /*inside_border_horizontal_spacing=*/views::kButtonHEdgeMarginNew, | 48 /*inside_border_horizontal_spacing=*/views::kButtonHEdgeMarginNew, |
| 51 /*inside_border_vertical_spacing=*/views::kPanelVertMargin, | 49 /*inside_border_vertical_spacing=*/views::kPanelVertMargin, |
| 52 /*between_child_spacing=*/0)); | 50 /*between_child_spacing=*/0)); |
| 53 views::Label* label = new views::Label(controller_->GetMainText()); | 51 views::Label* label = new views::Label(controller_->GetMainText()); |
| 54 label->SetMultiLine(true); | 52 label->SetMultiLine(true); |
| 55 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 53 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 56 AddChildView(label); | 54 AddChildView(label); |
| 57 | |
| 58 advanced_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 59 } | 55 } |
| 60 | 56 |
| 61 ChromeCleanerDialog::~ChromeCleanerDialog() { | 57 ChromeCleanerDialog::~ChromeCleanerDialog() { |
| 62 // Make sure the controller is correctly notified in case the dialog widget is | 58 // Make sure the controller is correctly notified in case the dialog widget is |
| 63 // closed by some other means than the dialog buttons. | 59 // closed by some other means than the dialog buttons. |
| 64 if (controller_) | 60 if (controller_) |
| 65 controller_->Cancel(); | 61 controller_->Cancel(); |
| 66 } | 62 } |
| 67 | 63 |
| 68 void ChromeCleanerDialog::Show(Browser* browser) { | 64 void ChromeCleanerDialog::Show(Browser* browser) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 ui::DialogButton button) const { | 96 ui::DialogButton button) const { |
| 101 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); | 97 DCHECK(button == ui::DIALOG_BUTTON_OK || button == ui::DIALOG_BUTTON_CANCEL); |
| 102 DCHECK(controller_); | 98 DCHECK(controller_); |
| 103 | 99 |
| 104 return button == ui::DIALOG_BUTTON_OK | 100 return button == ui::DIALOG_BUTTON_OK |
| 105 ? controller_->GetAcceptButtonLabel() | 101 ? controller_->GetAcceptButtonLabel() |
| 106 : DialogDelegate::GetDialogButtonLabel(button); | 102 : DialogDelegate::GetDialogButtonLabel(button); |
| 107 } | 103 } |
| 108 | 104 |
| 109 views::View* ChromeCleanerDialog::CreateExtraView() { | 105 views::View* ChromeCleanerDialog::CreateExtraView() { |
| 110 return advanced_button_; | 106 return views::MdTextButton::CreateSecondaryUiButton( |
| 107 this, controller_->GetAdvancedButtonLabel()); |
| 111 } | 108 } |
| 112 | 109 |
| 113 bool ChromeCleanerDialog::Accept() { | 110 bool ChromeCleanerDialog::Accept() { |
| 114 if (controller_) { | 111 if (controller_) { |
| 115 controller_->Accept(); | 112 controller_->Accept(); |
| 116 controller_ = nullptr; | 113 controller_ = nullptr; |
| 117 } | 114 } |
| 118 return true; | 115 return true; |
| 119 } | 116 } |
| 120 | 117 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 // View overrides. | 134 // View overrides. |
| 138 | 135 |
| 139 gfx::Size ChromeCleanerDialog::GetPreferredSize() const { | 136 gfx::Size ChromeCleanerDialog::GetPreferredSize() const { |
| 140 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); | 137 return gfx::Size(kDialogWidth, GetHeightForWidth(kDialogWidth)); |
| 141 } | 138 } |
| 142 | 139 |
| 143 // views::ButtonListener overrides. | 140 // views::ButtonListener overrides. |
| 144 | 141 |
| 145 void ChromeCleanerDialog::ButtonPressed(views::Button* sender, | 142 void ChromeCleanerDialog::ButtonPressed(views::Button* sender, |
| 146 const ui::Event& event) { | 143 const ui::Event& event) { |
| 147 DCHECK_EQ(sender, advanced_button_); | |
| 148 DCHECK(browser_); | 144 DCHECK(browser_); |
| 149 | 145 |
| 150 // TODO(alito): Navigate to the webui version of the Chrome Cleaner UI when | 146 // TODO(alito): Navigate to the webui version of the Chrome Cleaner UI when |
| 151 // that is implemented. | 147 // that is implemented. |
| 152 if (controller_) { | 148 if (controller_) { |
| 153 controller_->AdvancedButtonClicked(); | 149 controller_->AdvancedButtonClicked(); |
| 154 controller_ = nullptr; | 150 controller_ = nullptr; |
| 155 } | 151 } |
| 156 GetWidget()->Close(); | 152 GetWidget()->Close(); |
| 157 } | 153 } |
| OLD | NEW |