Home | History | Annotate | Download | only in importer
      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/message_loop.h"
      9 #include "base/strings/utf_string_conversions.h"
     10 #include "chrome/browser/importer/importer_lock_dialog.h"
     11 #include "chrome/grit/chromium_strings.h"
     12 #include "chrome/grit/generated_resources.h"
     13 #include "chrome/grit/locale_settings.h"
     14 #include "content/public/browser/user_metrics.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 
     20 using base::UserMetricsAction;
     21 
     22 namespace importer {
     23 
     24 void ShowImportLockDialog(gfx::NativeWindow parent,
     25                           const base::Callback<void(bool)>& callback) {
     26   ImportLockDialogView::Show(parent, callback);
     27   content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown"));
     28 }
     29 
     30 }  // namespace importer
     31 
     32 // static
     33 void ImportLockDialogView::Show(gfx::NativeWindow parent,
     34                                 const base::Callback<void(bool)>& callback) {
     35   views::DialogDelegate::CreateDialogWidget(
     36       new ImportLockDialogView(callback), NULL, NULL)->Show();
     37 }
     38 
     39 ImportLockDialogView::ImportLockDialogView(
     40     const base::Callback<void(bool)>& callback)
     41     : description_label_(NULL),
     42       callback_(callback) {
     43   description_label_ = new views::Label(
     44       l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT));
     45   description_label_->SetMultiLine(true);
     46   description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
     47   AddChildView(description_label_);
     48 }
     49 
     50 ImportLockDialogView::~ImportLockDialogView() {
     51 }
     52 
     53 gfx::Size ImportLockDialogView::GetPreferredSize() const {
     54   return gfx::Size(views::Widget::GetLocalizedContentsSize(
     55       IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
     56       IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
     57 }
     58 
     59 void ImportLockDialogView::Layout() {
     60   gfx::Rect bounds(GetLocalBounds());
     61   bounds.Inset(views::kButtonHEdgeMargin, views::kPanelVertMargin);
     62   description_label_->SetBoundsRect(bounds);
     63 }
     64 
     65 base::string16 ImportLockDialogView::GetDialogButtonLabel(
     66     ui::DialogButton button) const {
     67   return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
     68       IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL);
     69 }
     70 
     71 base::string16 ImportLockDialogView::GetWindowTitle() const {
     72   return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE);
     73 }
     74 
     75 bool ImportLockDialogView::Accept() {
     76   base::MessageLoop::current()->PostTask(FROM_HERE,
     77                                          base::Bind(callback_, true));
     78   return true;
     79 }
     80 
     81 bool ImportLockDialogView::Cancel() {
     82   base::MessageLoop::current()->PostTask(FROM_HERE,
     83                                          base::Bind(callback_, false));
     84   return true;
     85 }
     86