// conflict with other groups that could be in the dialog content.
const int kButtonGroup = 1127;
+class MessageDialogClientView;
+
class MessageDialog : public views::WidgetDelegate,
public views::View,
public views::ButtonListener {
virtual ~MessageDialog();
void Show(base::RunLoop* run_loop = NULL);
+ void Close();
int GetResult() const;
private:
// Overridden from views::WidgetDelegate:
virtual base::string16 GetWindowTitle() const;
- virtual void WindowClosing() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
virtual views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) OVERRIDE;
+ virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
- bool should_close_;
bool delete_on_close_;
int result_;
base::string16 title_;
NativeWindow* parent_;
- views::Widget* widget_;
+ scoped_ptr<views::Widget> widget_;
views::MessageBoxView* message_box_view_;
std::vector<views::LabelButton*> buttons_;
DISALLOW_COPY_AND_ASSIGN(MessageDialog);
};
+class MessageDialogClientView : public views::ClientView {
+ public:
+ MessageDialogClientView(MessageDialog* dialog, views::Widget* widget)
+ : views::ClientView(widget, dialog),
+ dialog_(dialog) {
+ }
+
+ // views::ClientView:
+ virtual bool CanClose() OVERRIDE {
+ dialog_->Close();
+ return false;
+ }
+
+ private:
+ MessageDialog* dialog_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageDialogClientView);
+};
+
////////////////////////////////////////////////////////////////////////////////
// MessageDialog, public:
const std::string& title,
const std::string& message,
const std::string& detail)
- : should_close_(false),
- delete_on_close_(false),
+ : delete_on_close_(false),
result_(-1),
title_(base::UTF8ToUTF16(title)),
parent_(parent_window),
- widget_(NULL),
message_box_view_(NULL),
run_loop_(NULL),
dialog_scope_(new NativeWindow::DialogScope(parent_window)) {
views::Widget::InitParams params;
params.delegate = this;
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.top_level = true;
- if (parent_window)
- params.parent = parent_window->GetNativeWindow();
-
- // Use bubble style for dialog has a parent.
if (parent_) {
+ params.parent = parent_->GetNativeWindow();
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
+ // Use bubble style for dialog has a parent.
params.remove_standard_frame = true;
}
widget_params.remove_standard_frame = true;
#endif
- widget_ = new views::Widget;
+ widget_.reset(new views::Widget);
widget_->Init(params);
// Bind to ESC.
widget_->Show();
}
+void MessageDialog::Close() {
+ dialog_scope_.reset();
+
+ if (delete_on_close_) {
+ callback_.Run(GetResult());
+ base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+ } else if (run_loop_) {
+ run_loop_->Quit();
+ }
+}
+
int MessageDialog::GetResult() const {
// When the dialog is closed without choosing anything, we think the user
// chose 'Cancel', otherwise we think the default behavior is chosen.
return title_;
}
-void MessageDialog::WindowClosing() {
- should_close_ = true;
- dialog_scope_.reset();
-
- if (delete_on_close_) {
- callback_.Run(GetResult());
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
- } else if (run_loop_) {
- run_loop_->Quit();
- }
-}
-
views::Widget* MessageDialog::GetWidget() {
- return widget_;
+ return widget_.get();
}
const views::Widget* MessageDialog::GetWidget() const {
- return widget_;
+ return widget_.get();
}
views::View* MessageDialog::GetContentsView() {
return frame;
}
+views::ClientView* MessageDialog::CreateClientView(views::Widget* widget) {
+ return new MessageDialogClientView(this, widget);
+}
+
gfx::Size MessageDialog::GetPreferredSize() {
gfx::Size size(0, buttons_[0]->GetPreferredSize().height());
for (size_t i = 0; i < buttons_.size(); ++i)