import_lock_dialog_view.cc revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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/message_loop.h" 8#include "base/utf_string_conversions.h" 9#include "chrome/browser/importer/importer.h" 10#include "grit/chromium_strings.h" 11#include "grit/generated_resources.h" 12#include "grit/locale_settings.h" 13#include "ui/base/l10n/l10n_util.h" 14#include "views/controls/label.h" 15#include "views/layout/layout_constants.h" 16#include "views/window/window.h" 17 18// Default size of the dialog window. 19static const int kDefaultWindowWidth = 320; 20static const int kDefaultWindowHeight = 100; 21 22namespace browser { 23 24void ShowImportLockDialog(gfx::NativeWindow parent, 25 ImporterHost* importer_host) { 26 ImportLockDialogView::Show(parent, importer_host); 27} 28 29} // namespace browser 30 31// static 32void ImportLockDialogView::Show(gfx::NativeWindow parent, 33 ImporterHost* importer_host) { 34 views::Window::CreateChromeWindow( 35 NULL, gfx::Rect(), 36 new ImportLockDialogView(importer_host))->Show(); 37} 38 39ImportLockDialogView::ImportLockDialogView(ImporterHost* importer_host) 40 : description_label_(NULL), 41 importer_host_(importer_host) { 42 description_label_ = new views::Label( 43 UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT))); 44 description_label_->SetMultiLine(true); 45 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 46 AddChildView(description_label_); 47} 48 49ImportLockDialogView::~ImportLockDialogView() { 50} 51 52gfx::Size ImportLockDialogView::GetPreferredSize() { 53 return gfx::Size(views::Window::GetLocalizedContentsSize( 54 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, 55 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); 56} 57 58void ImportLockDialogView::Layout() { 59 description_label_->SetBounds( 60 views::kPanelHorizMargin, 61 views::kPanelVertMargin, 62 width() - 2 * views::kPanelHorizMargin, 63 height() - 2 * views::kPanelVertMargin); 64} 65 66std::wstring ImportLockDialogView::GetDialogButtonLabel( 67 MessageBoxFlags::DialogButton button) const { 68 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { 69 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_OK)); 70 } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { 71 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_CANCEL)); 72 } 73 return std::wstring(); 74} 75 76bool ImportLockDialogView::IsModal() const { 77 return false; 78} 79 80std::wstring ImportLockDialogView::GetWindowTitle() const { 81 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE)); 82} 83 84bool ImportLockDialogView::Accept() { 85 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 86 importer_host_.get(), &ImporterHost::OnLockViewEnd, true)); 87 return true; 88} 89 90bool ImportLockDialogView::Cancel() { 91 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 92 importer_host_.get(), &ImporterHost::OnLockViewEnd, false)); 93 return true; 94} 95 96views::View* ImportLockDialogView::GetContentsView() { 97 return this; 98} 99