Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/simple_message_box_views.h" | 5 #include "chrome/browser/ui/views/simple_message_box_views.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/simple_message_box.h" | 9 #include "chrome/browser/simple_message_box.h" |
| 10 #include "chrome/browser/ui/dialog_style.h" | 10 #include "chrome/browser/ui/dialog_style.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 g_browser_process->ReleaseModule(); | 74 g_browser_process->ReleaseModule(); |
| 75 | 75 |
| 76 return dialog->accepted(); | 76 return dialog->accepted(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 80 // SimpleMessageBoxViews, private: | 80 // SimpleMessageBoxViews, private: |
| 81 | 81 |
| 82 int SimpleMessageBoxViews::GetDialogButtons() const { | 82 int SimpleMessageBoxViews::GetDialogButtons() const { |
| 83 if (type_ == DIALOG_ERROR) | 83 if (dialog_type_ == DIALOG_ERROR) |
| 84 return ui::DIALOG_BUTTON_OK; | 84 return ui::DIALOG_BUTTON_OK; |
| 85 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | 85 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 86 } | 86 } |
| 87 | 87 |
| 88 string16 SimpleMessageBoxViews::GetDialogButtonLabel( | 88 string16 SimpleMessageBoxViews::GetDialogButtonLabel( |
| 89 ui::DialogButton button) const { | 89 ui::DialogButton button) const { |
| 90 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? | 90 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? |
| 91 IDS_OK : IDS_CLOSE); | 91 IDS_OK : IDS_CLOSE); |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool SimpleMessageBoxViews::Cancel() { | 94 bool SimpleMessageBoxViews::Cancel() { |
| 95 disposition_ = DISPOSITION_CANCEL; | 95 disposition_type_ = DISPOSITION_CANCEL; |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool SimpleMessageBoxViews::Accept() { | 99 bool SimpleMessageBoxViews::Accept() { |
| 100 disposition_ = DISPOSITION_OK; | 100 disposition_type_ = DISPOSITION_OK; |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 string16 SimpleMessageBoxViews::GetWindowTitle() const { | 104 string16 SimpleMessageBoxViews::GetWindowTitle() const { |
| 105 return message_box_title_; | 105 return window_title_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void SimpleMessageBoxViews::DeleteDelegate() { | 108 void SimpleMessageBoxViews::DeleteDelegate() { |
| 109 Release(); | 109 Release(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 ui::ModalType SimpleMessageBoxViews::GetModalType() const { | 112 ui::ModalType SimpleMessageBoxViews::GetModalType() const { |
| 113 return ui::MODAL_TYPE_WINDOW; | 113 return ui::MODAL_TYPE_WINDOW; |
| 114 } | 114 } |
| 115 | 115 |
| 116 views::View* SimpleMessageBoxViews::GetContentsView() { | 116 views::View* SimpleMessageBoxViews::GetContentsView() { |
| 117 return message_box_view_; | 117 return message_box_view_; |
| 118 } | 118 } |
| 119 | 119 |
| 120 views::Widget* SimpleMessageBoxViews::GetWidget() { | 120 views::Widget* SimpleMessageBoxViews::GetWidget() { |
| 121 return message_box_view_->GetWidget(); | 121 return message_box_view_->GetWidget(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 const views::Widget* SimpleMessageBoxViews::GetWidget() const { | 124 const views::Widget* SimpleMessageBoxViews::GetWidget() const { |
| 125 return message_box_view_->GetWidget(); | 125 return message_box_view_->GetWidget(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window, | 128 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window, |
| 129 DialogType type, | 129 DialogType dialog_type, |
| 130 const string16& title, | 130 const string16& title, |
| 131 const string16& message) | 131 const string16& message) |
| 132 : type_(type), | 132 : dialog_type_(dialog_type), |
| 133 disposition_(DISPOSITION_UNKNOWN) { | 133 disposition_type_(DISPOSITION_UNKNOWN), |
| 134 message_box_title_ = title; | 134 window_title_(title) { |
| 135 message_box_view_ = new views::MessageBoxView( | 135 message_box_view_ = new views::MessageBoxView( |
|
Peter Kasting
2012/04/13 09:12:32
Nit: Why not init this in the initializer list too
| |
| 136 views::MessageBoxView::NO_OPTIONS, | 136 views::MessageBoxView::NO_OPTIONS, message, string16()); |
| 137 message, | |
| 138 string16()); | |
| 139 views::Widget::CreateWindowWithParent(this, parent_window)->Show(); | 137 views::Widget::CreateWindowWithParent(this, parent_window)->Show(); |
| 140 | 138 |
| 141 // Add reference to be released in DeleteDelegate(). | 139 // Add reference to be released in DeleteDelegate(). |
| 142 AddRef(); | 140 AddRef(); |
| 143 } | 141 } |
| 144 | 142 |
| 145 SimpleMessageBoxViews::~SimpleMessageBoxViews() { | 143 SimpleMessageBoxViews::~SimpleMessageBoxViews() { |
| 146 } | 144 } |
| 147 | 145 |
| 148 bool SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) { | 146 bool SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) { |
| 149 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 150 TranslateMessage(&event); | 148 TranslateMessage(&event); |
| 151 DispatchMessage(&event); | 149 DispatchMessage(&event); |
| 152 #elif defined(USE_AURA) | 150 #elif defined(USE_AURA) |
| 153 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event); | 151 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event); |
| 154 #endif | 152 #endif |
| 155 return disposition_ == DISPOSITION_UNKNOWN; | 153 return disposition_type_ == DISPOSITION_UNKNOWN; |
| 156 } | 154 } |
| OLD | NEW |