Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / views / importer / import_lock_dialog_view.cc
blobb1e41ba6d04a32075c09acfb226b8cd8fdc6bbfb
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/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/importer/importer_lock_dialog.h"
11 #include "content/public/browser/user_metrics.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/widget/widget.h"
20 using content::UserMetricsAction;
22 // Default size of the dialog window.
23 static const int kDefaultWindowWidth = 320;
24 static const int kDefaultWindowHeight = 100;
26 namespace importer {
28 void ShowImportLockDialog(gfx::NativeWindow parent,
29 const base::Callback<void(bool)>& callback) {
30 ImportLockDialogView::Show(parent, callback);
31 content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown"));
34 } // namespace importer
36 // static
37 void ImportLockDialogView::Show(gfx::NativeWindow parent,
38 const base::Callback<void(bool)>& callback) {
39 views::DialogDelegate::CreateDialogWidget(
40 new ImportLockDialogView(callback), NULL, NULL)->Show();
43 ImportLockDialogView::ImportLockDialogView(
44 const base::Callback<void(bool)>& callback)
45 : description_label_(NULL),
46 callback_(callback) {
47 description_label_ = new views::Label(
48 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT));
49 description_label_->SetMultiLine(true);
50 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
51 AddChildView(description_label_);
54 ImportLockDialogView::~ImportLockDialogView() {
57 gfx::Size ImportLockDialogView::GetPreferredSize() {
58 return gfx::Size(views::Widget::GetLocalizedContentsSize(
59 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
60 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
63 void ImportLockDialogView::Layout() {
64 if (DialogDelegate::UseNewStyle()) {
65 description_label_->SetBounds(
66 views::kButtonHEdgeMargin,
67 views::kPanelVertMargin,
68 width() - 2 * views::kButtonHEdgeMargin,
69 height() - 2 * views::kPanelVertMargin);
70 } else {
71 description_label_->SetBounds(
72 views::kPanelHorizMargin,
73 views::kPanelVertMargin,
74 width() - 2 * views::kPanelHorizMargin,
75 height() - 2 * views::kPanelVertMargin);
79 string16 ImportLockDialogView::GetDialogButtonLabel(
80 ui::DialogButton button) const {
81 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
82 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL);
85 string16 ImportLockDialogView::GetWindowTitle() const {
86 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE);
89 bool ImportLockDialogView::Accept() {
90 base::MessageLoop::current()->PostTask(FROM_HERE,
91 base::Bind(callback_, true));
92 return true;
95 bool ImportLockDialogView::Cancel() {
96 base::MessageLoop::current()->PostTask(FROM_HERE,
97 base::Bind(callback_, false));
98 return true;