Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / importer / import_lock_dialog_view.cc
blob4e63439c419315f98fdb05c1b1bcf1e38db374f9
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/importer/import_lock_dialog_view.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/importer/importer_lock_dialog.h"
13 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "chrome/grit/locale_settings.h"
16 #include "content/public/browser/user_metrics.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/layout_constants.h"
20 #include "ui/views/widget/widget.h"
22 using base::UserMetricsAction;
24 namespace importer {
26 void ShowImportLockDialog(gfx::NativeWindow parent,
27 const base::Callback<void(bool)>& callback) {
28 ImportLockDialogView::Show(parent, callback);
29 content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown"));
32 } // namespace importer
34 // static
35 void ImportLockDialogView::Show(gfx::NativeWindow parent,
36 const base::Callback<void(bool)>& callback) {
37 views::DialogDelegate::CreateDialogWidget(
38 new ImportLockDialogView(callback), NULL, NULL)->Show();
41 ImportLockDialogView::ImportLockDialogView(
42 const base::Callback<void(bool)>& callback)
43 : description_label_(NULL),
44 callback_(callback) {
45 description_label_ = new views::Label(
46 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT));
47 description_label_->SetMultiLine(true);
48 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
49 AddChildView(description_label_);
52 ImportLockDialogView::~ImportLockDialogView() {
55 gfx::Size ImportLockDialogView::GetPreferredSize() const {
56 return gfx::Size(views::Widget::GetLocalizedContentsSize(
57 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
58 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
61 void ImportLockDialogView::Layout() {
62 gfx::Rect bounds(GetLocalBounds());
63 bounds.Inset(views::kButtonHEdgeMargin, views::kPanelVertMargin);
64 description_label_->SetBoundsRect(bounds);
67 base::string16 ImportLockDialogView::GetDialogButtonLabel(
68 ui::DialogButton button) const {
69 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
70 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL);
73 base::string16 ImportLockDialogView::GetWindowTitle() const {
74 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE);
77 bool ImportLockDialogView::Accept() {
78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
79 base::Bind(callback_, true));
80 return true;
83 bool ImportLockDialogView::Cancel() {
84 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
85 base::Bind(callback_, false));
86 return true;