Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/importer/import_lock_dialog_view.h" | 5 #include "chrome/browser/ui/views/importer/import_lock_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 using base::UserMetricsAction; | 23 using base::UserMetricsAction; |
| 24 | 24 |
| 25 namespace importer { | 25 namespace importer { |
| 26 | 26 |
| 27 void ShowImportLockDialog(gfx::NativeWindow parent, | 27 void ShowImportLockDialog(gfx::NativeWindow parent, |
| 28 const base::Callback<void(bool)>& callback) { | 28 const base::Callback<void(bool)>& callback) { |
| 29 ImportLockDialogView::Show(parent, callback); | 29 ImportLockDialogView::Show(parent, callback); |
| 30 base::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); | 30 base::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void HideImportLockDialog() { | |
| 34 ImportLockDialogView::Hide(); | |
| 35 } | |
| 36 | |
| 33 } // namespace importer | 37 } // namespace importer |
| 34 | 38 |
| 39 // For storing widget ptr on creation of dialog widget | |
| 40 // using method CreateDialogWidget. | |
| 41 namespace { | |
| 42 static views::Widget* g_widget = nullptr; | |
| 43 } | |
| 44 | |
| 45 // static | |
| 46 void ImportLockDialogView::Hide() { | |
| 47 if (g_widget) { | |
| 48 g_widget->Close(); | |
| 49 g_widget = nullptr; | |
| 50 } | |
| 51 } | |
| 52 | |
| 35 // static | 53 // static |
| 36 void ImportLockDialogView::Show(gfx::NativeWindow parent, | 54 void ImportLockDialogView::Show(gfx::NativeWindow parent, |
| 37 const base::Callback<void(bool)>& callback) { | 55 const base::Callback<void(bool)>& callback) { |
| 38 views::DialogDelegate::CreateDialogWidget( | 56 g_widget = views::DialogDelegate::CreateDialogWidget( |
| 39 new ImportLockDialogView(callback), NULL, NULL)->Show(); | 57 new ImportLockDialogView(callback), NULL, NULL); |
| 58 g_widget->Show(); | |
| 40 } | 59 } |
| 41 | 60 |
| 42 ImportLockDialogView::ImportLockDialogView( | 61 ImportLockDialogView::ImportLockDialogView( |
| 43 const base::Callback<void(bool)>& callback) | 62 const base::Callback<void(bool)>& callback) |
| 44 : description_label_(NULL), | 63 : description_label_(NULL), |
| 45 callback_(callback) { | 64 callback_(callback) { |
| 46 description_label_ = new views::Label( | 65 description_label_ = new views::Label( |
| 47 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)); | 66 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)); |
| 48 description_label_->SetMultiLine(true); | 67 description_label_->SetMultiLine(true); |
| 49 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 68 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 50 AddChildView(description_label_); | 69 AddChildView(description_label_); |
| 51 } | 70 } |
| 52 | 71 |
| 53 ImportLockDialogView::~ImportLockDialogView() { | 72 ImportLockDialogView::~ImportLockDialogView() { |
| 73 g_widget = nullptr; | |
|
nikhil.sahni
2017/04/03 13:05:11
Even Destructor is called on Exiting so added chec
| |
| 54 } | 74 } |
| 55 | 75 |
| 56 gfx::Size ImportLockDialogView::GetPreferredSize() const { | 76 gfx::Size ImportLockDialogView::GetPreferredSize() const { |
| 57 return gfx::Size(views::Widget::GetLocalizedContentsSize( | 77 return gfx::Size(views::Widget::GetLocalizedContentsSize( |
| 58 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, | 78 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, |
| 59 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); | 79 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); |
| 60 } | 80 } |
| 61 | 81 |
| 62 void ImportLockDialogView::Layout() { | 82 void ImportLockDialogView::Layout() { |
| 63 gfx::Rect bounds(GetLocalBounds()); | 83 gfx::Rect bounds(GetLocalBounds()); |
| 64 bounds.Inset(views::kButtonHEdgeMarginNew, | 84 bounds.Inset(views::kButtonHEdgeMarginNew, |
| 65 LayoutDelegate::Get()->GetMetric( | 85 LayoutDelegate::Get()->GetMetric( |
| 66 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); | 86 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); |
| 67 description_label_->SetBoundsRect(bounds); | 87 description_label_->SetBoundsRect(bounds); |
| 68 } | 88 } |
| 69 | 89 |
| 70 base::string16 ImportLockDialogView::GetDialogButtonLabel( | 90 base::string16 ImportLockDialogView::GetDialogButtonLabel( |
| 71 ui::DialogButton button) const { | 91 ui::DialogButton button) const { |
| 72 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? | 92 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? |
| 73 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL); | 93 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL); |
| 74 } | 94 } |
| 75 | 95 |
| 76 base::string16 ImportLockDialogView::GetWindowTitle() const { | 96 base::string16 ImportLockDialogView::GetWindowTitle() const { |
| 77 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE); | 97 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE); |
| 78 } | 98 } |
| 79 | 99 |
| 80 bool ImportLockDialogView::Accept() { | 100 bool ImportLockDialogView::Accept() { |
| 81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 101 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 82 base::Bind(callback_, true)); | 102 base::Bind(callback_, true)); |
| 103 g_widget = nullptr; | |
|
nikhil.sahni
2017/04/03 13:05:11
On Pressing "Continue" this function gets called s
| |
| 83 return true; | 104 return true; |
| 84 } | 105 } |
| 85 | 106 |
| 86 bool ImportLockDialogView::Cancel() { | 107 bool ImportLockDialogView::Cancel() { |
| 87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 108 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 88 base::Bind(callback_, false)); | 109 base::Bind(callback_, false)); |
| 110 g_widget = nullptr; | |
|
nikhil.sahni
2017/04/03 13:05:11
On pressing "Skip Import" and "Cross Button of the
| |
| 89 return true; | 111 return true; |
| 90 } | 112 } |
| OLD | NEW |