Index: chrome/browser/ui/views/simple_message_box_views.cc |
diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc |
index 8deeebc76fac75a1d1cf8f6a64aaa267f072d795..c427d6b89bb695822346f26a709d2cb78d38be87 100644 |
--- a/chrome/browser/ui/views/simple_message_box_views.cc |
+++ b/chrome/browser/ui/views/simple_message_box_views.cc |
@@ -19,6 +19,7 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/gfx/native_widget_types.h" |
#include "ui/views/controls/message_box_view.h" |
+#include "ui/views/corewm/window_util.h" |
#include "ui/views/widget/widget.h" |
#include "ui/views/window/dialog_delegate.h" |
@@ -37,7 +38,6 @@ namespace { |
// destroyed before a box in an outer-loop. So to avoid this, ref-counting is |
// used so that the SimpleMessageBoxViews gets deleted at the right time. |
class SimpleMessageBoxViews : public views::DialogDelegate, |
- public base::MessagePumpDispatcher, |
public base::RefCounted<SimpleMessageBoxViews> { |
public: |
SimpleMessageBoxViews(const base::string16& title, |
@@ -63,13 +63,13 @@ class SimpleMessageBoxViews : public views::DialogDelegate, |
virtual views::Widget* GetWidget() OVERRIDE; |
virtual const views::Widget* GetWidget() const OVERRIDE; |
- // Overridden from MessagePumpDispatcher: |
- virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE; |
- |
private: |
friend class base::RefCounted<SimpleMessageBoxViews>; |
virtual ~SimpleMessageBoxViews(); |
+ // This terminates the nested message-loop. |
+ void Done(); |
+ |
const base::string16 window_title_; |
const MessageBoxType type_; |
base::string16 yes_text_; |
@@ -77,10 +77,6 @@ class SimpleMessageBoxViews : public views::DialogDelegate, |
MessageBoxResult result_; |
views::MessageBoxView* message_box_view_; |
- // Set to false as soon as the user clicks a dialog button; this tells the |
- // dispatcher we're done. |
- bool should_show_dialog_; |
- |
DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); |
}; |
@@ -98,8 +94,7 @@ SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title, |
no_text_(no_text), |
result_(MESSAGE_BOX_RESULT_NO), |
message_box_view_(new views::MessageBoxView( |
- views::MessageBoxView::InitParams(message))), |
- should_show_dialog_(true) { |
+ views::MessageBoxView::InitParams(message))) { |
AddRef(); |
if (yes_text_.empty()) { |
@@ -138,14 +133,14 @@ base::string16 SimpleMessageBoxViews::GetDialogButtonLabel( |
} |
bool SimpleMessageBoxViews::Cancel() { |
- should_show_dialog_= false; |
result_ = MESSAGE_BOX_RESULT_NO; |
+ Done(); |
return true; |
} |
bool SimpleMessageBoxViews::Accept() { |
- should_show_dialog_ = false; |
result_ = MESSAGE_BOX_RESULT_YES; |
+ Done(); |
return true; |
} |
@@ -173,13 +168,6 @@ const views::Widget* SimpleMessageBoxViews::GetWidget() const { |
return message_box_view_->GetWidget(); |
} |
-uint32_t SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) { |
- uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; |
- if (!should_show_dialog_) |
- action |= POST_DISPATCH_QUIT_LOOP; |
- return action; |
-} |
- |
//////////////////////////////////////////////////////////////////////////////// |
// SimpleMessageBoxViews, private: |
@@ -204,6 +192,21 @@ UINT GetMessageBoxFlagsFromType(MessageBoxType type) { |
} |
#endif |
+void SimpleMessageBoxViews::Done() { |
+ // The nested-loop is started from the parent's dispatcher client (if there is |
+ // one), otherwise it's started from the widget's own window's dispatcher |
+ // client. Make sure the termination of the nested loop happens from the |
+ // correct dispatcher client. |
+ aura::Window* window = GetWidget()->GetNativeView(); |
+ aura::Window* parent = views::corewm::GetTransientParent(window); |
+ aura::client::DispatcherClient* client = NULL; |
+ if (parent) |
+ client = aura::client::GetDispatcherClient(parent->GetRootWindow()); |
+ if (!client) |
+ client = aura::client::GetDispatcherClient(window->GetRootWindow()); |
+ client->QuitNestedMessageLoop(); |
+} |
+ |
MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
const base::string16& title, |
const base::string16& message, |
@@ -234,7 +237,7 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, |
anchor = dialog->GetWidget()->GetNativeWindow(); |
client = aura::client::GetDispatcherClient(anchor->GetRootWindow()); |
} |
- client->RunWithDispatcher(dialog.get(), anchor); |
+ client->RunWithDispatcher(NULL, anchor); |
return dialog->result(); |
} |