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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/browser/importer/importer_lock_dialog.h" | 13 #include "chrome/browser/importer/importer_lock_dialog.h" |
| 14 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | 14 #include "chrome/browser/ui/views/harmony/layout_delegate.h" |
| 15 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/locale_settings.h" | 17 #include "chrome/grit/locale_settings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/layout/layout_constants.h" | 20 #include "ui/views/layout/layout_constants.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 using base::UserMetricsAction; | 23 using base::UserMetricsAction; |
| 24 | 24 |
| 25 namespace { | |
|
Ilya Sherman
2017/04/05 06:15:29
nit: Please leave a blank line after this one.
nikhil.sahni
2017/04/05 07:35:49
Done.
| |
| 26 // For storing widget ptr on creation of dialog widget | |
| 27 // using method CreateDialogWidget. | |
|
Ilya Sherman
2017/04/05 06:15:29
nit: Please re-wrap this comment to 80-col.
Ilya Sherman
2017/04/05 06:15:29
Please simplify this comment a bit to something li
nikhil.sahni
2017/04/05 07:35:49
Done.
| |
| 28 static views::Widget* g_widget = nullptr; | |
|
Ilya Sherman
2017/04/05 06:15:29
nit: Please leave a blank line after this one.
nikhil.sahni
2017/04/05 07:35:49
Done.
| |
| 29 } | |
| 30 | |
| 25 namespace importer { | 31 namespace importer { |
| 26 | 32 |
| 27 void ShowImportLockDialog(gfx::NativeWindow parent, | 33 void ShowImportLockDialog(gfx::NativeWindow parent, |
| 28 const base::Callback<void(bool)>& callback) { | 34 const base::Callback<void(bool)>& callback) { |
| 29 ImportLockDialogView::Show(parent, callback); | 35 ImportLockDialogView::Show(parent, callback); |
| 30 base::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); | 36 base::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); |
| 31 } | 37 } |
| 32 | 38 |
| 39 void HideImportLockDialog() { | |
| 40 ImportLockDialogView::Hide(); | |
| 41 } | |
| 42 | |
| 33 } // namespace importer | 43 } // namespace importer |
| 34 | 44 |
| 35 // static | 45 // static |
| 36 void ImportLockDialogView::Show(gfx::NativeWindow parent, | 46 void ImportLockDialogView::Show(gfx::NativeWindow parent, |
| 37 const base::Callback<void(bool)>& callback) { | 47 const base::Callback<void(bool)>& callback) { |
| 38 views::DialogDelegate::CreateDialogWidget( | 48 ImportLockDialogView* dialog_view = new ImportLockDialogView(callback); |
| 39 new ImportLockDialogView(callback), NULL, NULL)->Show(); | 49 g_widget = views::DialogDelegate::CreateDialogWidget(import_lock_dialog_view, |
|
Ilya Sherman
2017/04/05 06:15:29
Please update the variable name import_lock_dialog
nikhil.sahni
2017/04/05 07:35:49
Done.
| |
| 50 NULL, NULL); | |
| 51 g_widget->AddObserver(dialog_view); | |
| 52 g_widget->Show(); | |
| 53 } | |
| 54 | |
| 55 // static | |
| 56 void ImportLockDialogView::Hide() { | |
| 57 if (g_widget) | |
| 58 g_widget->Close(); | |
| 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() { |
| 54 } | 73 } |
| 55 | 74 |
| 75 void ImportLockDialogView::OnWidgetDestroying(views::Widget* widget) { | |
| 76 DCHECK_EQ(widget, g_widget); | |
| 77 g_widget = nullptr; | |
| 78 widget->RemoveObserver(this); | |
| 79 } | |
| 80 | |
| 56 gfx::Size ImportLockDialogView::GetPreferredSize() const { | 81 gfx::Size ImportLockDialogView::GetPreferredSize() const { |
| 57 return gfx::Size(views::Widget::GetLocalizedContentsSize( | 82 return gfx::Size(views::Widget::GetLocalizedContentsSize( |
| 58 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, | 83 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, |
| 59 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); | 84 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); |
| 60 } | 85 } |
| 61 | 86 |
| 62 void ImportLockDialogView::Layout() { | 87 void ImportLockDialogView::Layout() { |
| 63 gfx::Rect bounds(GetLocalBounds()); | 88 gfx::Rect bounds(GetLocalBounds()); |
| 64 bounds.Inset(views::kButtonHEdgeMarginNew, | 89 bounds.Inset(views::kButtonHEdgeMarginNew, |
| 65 LayoutDelegate::Get()->GetMetric( | 90 LayoutDelegate::Get()->GetMetric( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 106 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 82 base::Bind(callback_, true)); | 107 base::Bind(callback_, true)); |
| 83 return true; | 108 return true; |
| 84 } | 109 } |
| 85 | 110 |
| 86 bool ImportLockDialogView::Cancel() { | 111 bool ImportLockDialogView::Cancel() { |
| 87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 112 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 88 base::Bind(callback_, false)); | 113 base::Bind(callback_, false)); |
| 89 return true; | 114 return true; |
| 90 } | 115 } |
| OLD | NEW |