summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/confirm_message_box_dialog.cc
blob: dd8cbd18bbf45d187476ef1eed20cef460e31cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/views/confirm_message_box_dialog.h"

#include "app/l10n_util.h"
#include "app/message_box_flags.h"
#include "base/message_loop.h"
#include "grit/generated_resources.h"
#include "views/controls/message_box_view.h"
#include "views/widget/widget.h"
#include "views/window/window.h"

// static
bool ConfirmMessageBoxDialog::Run(gfx::NativeWindow parent,
                                  const std::wstring& message_text,
                                  const std::wstring& window_title) {
  ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(parent,
    message_text, window_title);
  MessageLoopForUI::current()->Run(dialog);
  return dialog->accepted();
}

ConfirmMessageBoxDialog::ConfirmMessageBoxDialog(gfx::NativeWindow parent,
    const std::wstring& message_text,
    const std::wstring& window_title)
    : message_text_(message_text),
      window_title_(window_title),
      accepted_(false),
      is_blocking_(true) {
  message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox,
                                         message_text_, window_title_);
  views::Window::CreateChromeWindow(parent, gfx::Rect(), this)->Show();
}

ConfirmMessageBoxDialog::~ConfirmMessageBoxDialog() {
}

void ConfirmMessageBoxDialog::DeleteDelegate() {
  delete this;
}

int ConfirmMessageBoxDialog::GetDialogButtons() const {
  return MessageBoxFlags::DIALOGBUTTON_OK |
         MessageBoxFlags::DIALOGBUTTON_CANCEL;
}

std::wstring ConfirmMessageBoxDialog::GetWindowTitle() const {
  return window_title_;
}

std::wstring ConfirmMessageBoxDialog::GetDialogButtonLabel(
    MessageBoxFlags::DialogButton button) const {
  if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
    return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
  }
  if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL)
    return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
  return DialogDelegate::GetDialogButtonLabel(button);
}

views::View* ConfirmMessageBoxDialog::GetContentsView() {
  return message_box_view_;
}

bool ConfirmMessageBoxDialog::Accept() {
  is_blocking_ = false;
  accepted_ = true;
  return true;
}

bool ConfirmMessageBoxDialog::Cancel() {
  is_blocking_ = false;
  accepted_ = false;
  return true;
}

bool ConfirmMessageBoxDialog::Dispatch(const MSG& msg) {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
  return is_blocking_;
}