Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: chrome/browser/ui/views/simple_message_box_views.cc

Issue 8553001: views: Add an Options enum to MessageBoxView control. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/views/window.h" 10 #include "chrome/browser/ui/views/window.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/message_box_flags.h"
14 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
15 #include "views/controls/message_box_view.h" 14 #include "views/controls/message_box_view.h"
16 15
17 #if defined(USE_AURA) 16 #if defined(USE_AURA)
18 #include "ui/views/focus/accelerator_handler.h" 17 #include "ui/views/focus/accelerator_handler.h"
19 #endif 18 #endif
20 19
21 namespace browser { 20 namespace browser {
22 21
23 void ShowErrorBox(gfx::NativeWindow parent, 22 void ShowErrorBox(gfx::NativeWindow parent,
(...skipping 10 matching lines...) Expand all
34 33
35 } // namespace browser 34 } // namespace browser
36 35
37 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
38 // SimpleMessageBoxViews, public: 37 // SimpleMessageBoxViews, public:
39 38
40 // static 39 // static
41 void SimpleMessageBoxViews::ShowErrorBox(gfx::NativeWindow parent_window, 40 void SimpleMessageBoxViews::ShowErrorBox(gfx::NativeWindow parent_window,
42 const string16& title, 41 const string16& title,
43 const string16& message) { 42 const string16& message) {
44 int dialog_flags = ui::MessageBoxFlags::kFlagHasMessage |
45 ui::MessageBoxFlags::kFlagHasOKButton;
46
47 // This is a reference counted object so it is given an initial increment 43 // This is a reference counted object so it is given an initial increment
48 // in the constructor with a corresponding decrement in DeleteDelegate(). 44 // in the constructor with a corresponding decrement in DeleteDelegate().
49 new SimpleMessageBoxViews(parent_window, dialog_flags, title, message); 45 new SimpleMessageBoxViews(parent_window, DIALOG_ERROR, title, message);
50 } 46 }
51 47
52 bool SimpleMessageBoxViews::ShowYesNoBox(gfx::NativeWindow parent_window, 48 bool SimpleMessageBoxViews::ShowYesNoBox(gfx::NativeWindow parent_window,
53 const string16& title, 49 const string16& title,
54 const string16& message) { 50 const string16& message) {
55 int dialog_flags = ui::MessageBoxFlags::kIsConfirmMessageBox;
56
57 // This is a reference counted object so it is given an initial increment 51 // This is a reference counted object so it is given an initial increment
58 // in the constructor plus an extra one below to ensure the dialog persists 52 // in the constructor plus an extra one below to ensure the dialog persists
59 // until we retrieve the user response.. 53 // until we retrieve the user response..
60 scoped_refptr<SimpleMessageBoxViews> dialog = 54 scoped_refptr<SimpleMessageBoxViews> dialog =
61 new SimpleMessageBoxViews(parent_window, dialog_flags, title, message); 55 new SimpleMessageBoxViews(parent_window, DIALOG_YES_NO, title, message);
62 56
63 // Make sure Chrome doesn't attempt to shut down with the dialog up. 57 // Make sure Chrome doesn't attempt to shut down with the dialog up.
64 g_browser_process->AddRefModule(); 58 g_browser_process->AddRefModule();
65 59
66 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); 60 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed();
67 MessageLoopForUI::current()->SetNestableTasksAllowed(true); 61 MessageLoopForUI::current()->SetNestableTasksAllowed(true);
68 MessageLoopForUI::current()->RunWithDispatcher(dialog); 62 MessageLoopForUI::current()->RunWithDispatcher(dialog);
69 MessageLoopForUI::current()->SetNestableTasksAllowed(old_state); 63 MessageLoopForUI::current()->SetNestableTasksAllowed(old_state);
70 64
71 g_browser_process->ReleaseModule(); 65 g_browser_process->ReleaseModule();
72 66
73 return dialog->Accepted(); 67 return dialog->Accepted();
74 } 68 }
75 69
76 bool SimpleMessageBoxViews::Cancel() { 70 bool SimpleMessageBoxViews::Cancel() {
77 disposition_ = DISPOSITION_CANCEL; 71 disposition_ = DISPOSITION_CANCEL;
78 return true; 72 return true;
79 } 73 }
80 74
81 bool SimpleMessageBoxViews::Accept() { 75 bool SimpleMessageBoxViews::Accept() {
82 disposition_ = DISPOSITION_OK; 76 disposition_ = DISPOSITION_OK;
83 return true; 77 return true;
84 } 78 }
85 79
86 int SimpleMessageBoxViews::GetDialogButtons() const { 80 int SimpleMessageBoxViews::GetDialogButtons() const {
87 // NOTE: It seems unsafe to assume that the flags for OK/cancel will always 81 if (type_ == DIALOG_ERROR)
88 // have the same value as the button ids. 82 return ui::DIALOG_BUTTON_OK;
89 int dialog_buttons = ui::DIALOG_BUTTON_NONE; 83 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
90 if (dialog_flags_ & ui::MessageBoxFlags::kFlagHasOKButton)
91 dialog_buttons = ui::DIALOG_BUTTON_OK;
92
93 if (dialog_flags_ & ui::MessageBoxFlags::kFlagHasCancelButton)
94 dialog_buttons |= ui::DIALOG_BUTTON_CANCEL;
95
96 return dialog_buttons;
97 } 84 }
98 85
99 string16 SimpleMessageBoxViews::GetDialogButtonLabel( 86 string16 SimpleMessageBoxViews::GetDialogButtonLabel(
100 ui::DialogButton button) const { 87 ui::DialogButton button) const {
101 return button == ui::DIALOG_BUTTON_OK ? l10n_util::GetStringUTF16(IDS_OK) 88 return button == ui::DIALOG_BUTTON_OK ? l10n_util::GetStringUTF16(IDS_OK)
102 : l10n_util::GetStringUTF16(IDS_CLOSE); 89 : l10n_util::GetStringUTF16(IDS_CLOSE);
103 } 90 }
104 91
105 bool SimpleMessageBoxViews::ShouldShowWindowTitle() const { 92 bool SimpleMessageBoxViews::ShouldShowWindowTitle() const {
106 return true; 93 return true;
(...skipping 20 matching lines...) Expand all
127 } 114 }
128 115
129 const views::Widget* SimpleMessageBoxViews::GetWidget() const { 116 const views::Widget* SimpleMessageBoxViews::GetWidget() const {
130 return message_box_view_->GetWidget(); 117 return message_box_view_->GetWidget();
131 } 118 }
132 119
133 //////////////////////////////////////////////////////////////////////////////// 120 ////////////////////////////////////////////////////////////////////////////////
134 // SimpleMessageBoxViews, private: 121 // SimpleMessageBoxViews, private:
135 122
136 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window, 123 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window,
137 int dialog_flags, 124 DialogType type,
138 const string16& title, 125 const string16& title,
139 const string16& message) 126 const string16& message)
140 : dialog_flags_(dialog_flags), 127 : type_(type),
141 disposition_(DISPOSITION_UNKNOWN) { 128 disposition_(DISPOSITION_UNKNOWN) {
142 message_box_title_ = title; 129 message_box_title_ = title;
143 message_box_view_ = new views::MessageBoxView(dialog_flags, 130 message_box_view_ = new views::MessageBoxView(views::MessageBoxView::NONE,
144 message, 131 message,
145 string16()); 132 string16());
146 browser::CreateViewsWindow(parent_window, this)->Show(); 133 browser::CreateViewsWindow(parent_window, this)->Show();
147 134
148 // Add reference to be released in DeleteDelegate(). 135 // Add reference to be released in DeleteDelegate().
149 AddRef(); 136 AddRef();
150 } 137 }
151 138
152 SimpleMessageBoxViews::~SimpleMessageBoxViews() { 139 SimpleMessageBoxViews::~SimpleMessageBoxViews() {
153 } 140 }
(...skipping 13 matching lines...) Expand all
167 if (disposition_ == DISPOSITION_UNKNOWN) 154 if (disposition_ == DISPOSITION_UNKNOWN)
168 return base::MessagePumpDispatcher::EVENT_PROCESSED; 155 return base::MessagePumpDispatcher::EVENT_PROCESSED;
169 return base::MessagePumpDispatcher::EVENT_QUIT; 156 return base::MessagePumpDispatcher::EVENT_QUIT;
170 } 157 }
171 #else 158 #else
172 bool SimpleMessageBoxViews::Dispatch(GdkEvent* event) { 159 bool SimpleMessageBoxViews::Dispatch(GdkEvent* event) {
173 gtk_main_do_event(event); 160 gtk_main_do_event(event);
174 return disposition_ == DISPOSITION_UNKNOWN; 161 return disposition_ == DISPOSITION_UNKNOWN;
175 } 162 }
176 #endif 163 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698