import_lock_dialog_view.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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. 4 5#include "chrome/browser/ui/views/importer/import_lock_dialog_view.h" 6 7#include "base/bind.h" 8#include "base/message_loop.h" 9#include "base/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" 19 20using content::UserMetricsAction; 21 22// Default size of the dialog window. 23static const int kDefaultWindowWidth = 320; 24static const int kDefaultWindowHeight = 100; 25 26namespace importer { 27 28void ShowImportLockDialog(gfx::NativeWindow parent, 29 const base::Callback<void(bool)>& callback) { 30 ImportLockDialogView::Show(parent, callback); 31 content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); 32} 33 34} // namespace importer 35 36// static 37void ImportLockDialogView::Show(gfx::NativeWindow parent, 38 const base::Callback<void(bool)>& callback) { 39 views::DialogDelegate::CreateDialogWidget( 40 new ImportLockDialogView(callback), NULL, NULL)->Show(); 41} 42 43ImportLockDialogView::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_); 52} 53 54ImportLockDialogView::~ImportLockDialogView() { 55} 56 57gfx::Size ImportLockDialogView::GetPreferredSize() { 58 return gfx::Size(views::Widget::GetLocalizedContentsSize( 59 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, 60 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); 61} 62 63void 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); 76 } 77} 78 79string16 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); 83} 84 85string16 ImportLockDialogView::GetWindowTitle() const { 86 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE); 87} 88 89bool ImportLockDialogView::Accept() { 90 base::MessageLoop::current()->PostTask(FROM_HERE, 91 base::Bind(callback_, true)); 92 return true; 93} 94 95bool ImportLockDialogView::Cancel() { 96 base::MessageLoop::current()->PostTask(FROM_HERE, 97 base::Bind(callback_, false)); 98 return true; 99} 100