summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/accelerators/accelerator_dispatcher.cc8
-rw-r--r--ash/accelerators/accelerator_dispatcher.h4
-rw-r--r--ash/accelerators/nested_dispatcher_controller.cc8
-rw-r--r--ash/accelerators/nested_dispatcher_controller.h5
-rw-r--r--chrome/browser/ui/views/first_run_dialog.cc23
-rw-r--r--chrome/browser/ui/views/first_run_dialog.h14
-rw-r--r--chrome/browser/ui/views/simple_message_box_views.cc43
-rw-r--r--ui/aura/client/dispatcher_client.h2
-rw-r--r--ui/views/controls/menu/menu_controller.cc22
-rw-r--r--ui/views/widget/desktop_aura/desktop_dispatcher_client.cc8
-rw-r--r--ui/views/widget/desktop_aura/desktop_dispatcher_client.h4
11 files changed, 54 insertions, 87 deletions
diff --git a/ash/accelerators/accelerator_dispatcher.cc b/ash/accelerators/accelerator_dispatcher.cc
index 91ea13b..0395ee7 100644
--- a/ash/accelerators/accelerator_dispatcher.cc
+++ b/ash/accelerators/accelerator_dispatcher.cc
@@ -70,6 +70,7 @@ AcceleratorDispatcher::AcceleratorDispatcher(
aura::Window* associated_window)
: nested_dispatcher_(nested_dispatcher),
associated_window_(associated_window) {
+ DCHECK(nested_dispatcher_);
associated_window_->AddObserver(this);
}
@@ -120,13 +121,10 @@ uint32_t AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) {
return POST_DISPATCH_NONE;
}
- return nested_dispatcher_
- ? nested_dispatcher_->Dispatch(key_event.native_event())
- : POST_DISPATCH_PERFORM_DEFAULT;
+ return nested_dispatcher_->Dispatch(key_event.native_event());
}
- return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event)
- : POST_DISPATCH_PERFORM_DEFAULT;
+ return nested_dispatcher_->Dispatch(event);
}
} // namespace ash
diff --git a/ash/accelerators/accelerator_dispatcher.h b/ash/accelerators/accelerator_dispatcher.h
index a46368c..a7ae40a 100644
--- a/ash/accelerators/accelerator_dispatcher.h
+++ b/ash/accelerators/accelerator_dispatcher.h
@@ -15,8 +15,8 @@ namespace ash {
// Dispatcher for handling accelerators from menu.
//
// Wraps a nested dispatcher to which control is passed if no accelerator key
-// has been pressed. If the nested dispatcher is NULL, then the control is
-// passed back to the default dispatcher.
+// has been pressed.
+// TODO(pkotwicz): Port AcceleratorDispatcher to mac.
// TODO(pkotwicz): Add support for a |nested_dispatcher| which sends
// events to a system IME.
class ASH_EXPORT AcceleratorDispatcher : public base::MessagePumpDispatcher,
diff --git a/ash/accelerators/nested_dispatcher_controller.cc b/ash/accelerators/nested_dispatcher_controller.cc
index 6977f07..c551e94 100644
--- a/ash/accelerators/nested_dispatcher_controller.cc
+++ b/ash/accelerators/nested_dispatcher_controller.cc
@@ -6,7 +6,6 @@
#include "ash/accelerators/accelerator_dispatcher.h"
#include "ash/shell.h"
-#include "base/auto_reset.h"
#include "base/run_loop.h"
namespace ash {
@@ -28,14 +27,7 @@ void NestedDispatcherController::RunWithDispatcher(
// TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
// use run_loop.QuitClosure().
base::RunLoop run_loop(&dispatcher);
- base::AutoReset<base::Closure> reset_closure(&quit_closure_,
- run_loop.QuitClosure());
run_loop.Run();
}
-void NestedDispatcherController::QuitNestedMessageLoop() {
- CHECK(!quit_closure_.is_null());
- quit_closure_.Run();
-}
-
} // namespace ash
diff --git a/ash/accelerators/nested_dispatcher_controller.h b/ash/accelerators/nested_dispatcher_controller.h
index 1f8b52e..958cbae 100644
--- a/ash/accelerators/nested_dispatcher_controller.h
+++ b/ash/accelerators/nested_dispatcher_controller.h
@@ -6,7 +6,6 @@
#define ASH_ACCELERATORS_NESTED_DISPATCHER_CONTROLLER_H_
#include "ash/ash_export.h"
-#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "ui/aura/client/dispatcher_client.h"
#include "ui/aura/window.h"
@@ -23,14 +22,10 @@ class ASH_EXPORT NestedDispatcherController
NestedDispatcherController();
virtual ~NestedDispatcherController();
- // aura::client::DispatcherClient:
virtual void RunWithDispatcher(base::MessagePumpDispatcher* dispatcher,
aura::Window* associated_window) OVERRIDE;
- virtual void QuitNestedMessageLoop() OVERRIDE;
private:
- base::Closure quit_closure_;
-
DISALLOW_COPY_AND_ASSIGN(NestedDispatcherController);
};
diff --git a/chrome/browser/ui/views/first_run_dialog.cc b/chrome/browser/ui/views/first_run_dialog.cc
index dc84312..2a236b5 100644
--- a/chrome/browser/ui/views/first_run_dialog.cc
+++ b/chrome/browser/ui/views/first_run_dialog.cc
@@ -65,7 +65,7 @@ bool FirstRunDialog::Show(Profile* profile) {
aura::Window* anchor = dialog->GetWidget()->GetNativeWindow();
aura::client::DispatcherClient* client =
aura::client::GetDispatcherClient(anchor->GetRootWindow());
- client->RunWithDispatcher(NULL, anchor);
+ client->RunWithDispatcher(dialog, anchor);
dialog_shown = true;
}
#endif // defined(GOOGLE_CHROME_BUILD)
@@ -76,7 +76,8 @@ bool FirstRunDialog::Show(Profile* profile) {
FirstRunDialog::FirstRunDialog(Profile* profile)
: profile_(profile),
make_default_(NULL),
- report_crashes_(NULL) {
+ report_crashes_(NULL),
+ should_show_dialog_(true) {
GridLayout* layout = GridLayout::CreatePanel(this);
SetLayoutManager(layout);
@@ -101,13 +102,6 @@ FirstRunDialog::FirstRunDialog(Profile* profile)
FirstRunDialog::~FirstRunDialog() {
}
-void FirstRunDialog::Done() {
- aura::Window* window = GetWidget()->GetNativeView();
- aura::client::DispatcherClient* client =
- aura::client::GetDispatcherClient(window->GetRootWindow());
- client->QuitNestedMessageLoop();
-}
-
views::View* FirstRunDialog::CreateExtraView() {
views::Link* link = new views::Link(l10n_util::GetStringUTF16(
IDS_LEARN_MORE));
@@ -116,11 +110,12 @@ views::View* FirstRunDialog::CreateExtraView() {
}
void FirstRunDialog::OnClosed() {
+ should_show_dialog_ = false;
first_run::SetShouldShowWelcomePage();
- Done();
}
bool FirstRunDialog::Accept() {
+ should_show_dialog_ = false;
GetWidget()->Hide();
if (report_crashes_ && report_crashes_->checked()) {
@@ -133,7 +128,6 @@ bool FirstRunDialog::Accept() {
if (make_default_ && make_default_->checked())
ShellIntegration::SetAsDefaultBrowser();
- Done();
return true;
}
@@ -144,3 +138,10 @@ int FirstRunDialog::GetDialogButtons() const {
void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) {
platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL));
}
+
+uint32_t FirstRunDialog::Dispatch(const base::NativeEvent& event) {
+ uint32_t action = POST_DISPATCH_PERFORM_DEFAULT;
+ if (!should_show_dialog_)
+ action |= POST_DISPATCH_QUIT_LOOP;
+ return action;
+}
diff --git a/chrome/browser/ui/views/first_run_dialog.h b/chrome/browser/ui/views/first_run_dialog.h
index 2eb9d5d..9e374a6 100644
--- a/chrome/browser/ui/views/first_run_dialog.h
+++ b/chrome/browser/ui/views/first_run_dialog.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_H_
#define CHROME_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_H_
+#include "base/message_loop/message_pump_dispatcher.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/window/dialog_delegate.h"
@@ -16,7 +17,8 @@ class Link;
}
class FirstRunDialog : public views::DialogDelegateView,
- public views::LinkListener {
+ public views::LinkListener,
+ public base::MessagePumpDispatcher {
public:
// Displays the first run UI for reporting opt-in, import data etc.
// Returns true if the dialog was shown.
@@ -26,9 +28,6 @@ class FirstRunDialog : public views::DialogDelegateView,
explicit FirstRunDialog(Profile* profile);
virtual ~FirstRunDialog();
- // This terminates the nested message-loop.
- void Done();
-
// views::DialogDelegate:
virtual views::View* CreateExtraView() OVERRIDE;
virtual void OnClosed() OVERRIDE;
@@ -38,11 +37,16 @@ class FirstRunDialog : public views::DialogDelegateView,
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
+ // Overridden from MessagePumpDispatcher:
+ virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE;
+
Profile* profile_;
views::Checkbox* make_default_;
views::Checkbox* report_crashes_;
- DISALLOW_COPY_AND_ASSIGN(FirstRunDialog);
+ // Set to false as soon as the user clicks a dialog button; this tells the
+ // dispatcher we're done.
+ bool should_show_dialog_;
};
#endif // CHROME_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_H_
diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc
index c427d6b..8deeebc 100644
--- a/chrome/browser/ui/views/simple_message_box_views.cc
+++ b/chrome/browser/ui/views/simple_message_box_views.cc
@@ -19,7 +19,6 @@
#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"
@@ -38,6 +37,7 @@ 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,6 +77,10 @@ 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);
};
@@ -94,7 +98,8 @@ 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))) {
+ views::MessageBoxView::InitParams(message))),
+ should_show_dialog_(true) {
AddRef();
if (yes_text_.empty()) {
@@ -133,14 +138,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;
}
@@ -168,6 +173,13 @@ 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:
@@ -192,21 +204,6 @@ 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,
@@ -237,7 +234,7 @@ MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent,
anchor = dialog->GetWidget()->GetNativeWindow();
client = aura::client::GetDispatcherClient(anchor->GetRootWindow());
}
- client->RunWithDispatcher(NULL, anchor);
+ client->RunWithDispatcher(dialog.get(), anchor);
return dialog->result();
}
diff --git a/ui/aura/client/dispatcher_client.h b/ui/aura/client/dispatcher_client.h
index 769c266..ae8c84c 100644
--- a/ui/aura/client/dispatcher_client.h
+++ b/ui/aura/client/dispatcher_client.h
@@ -18,8 +18,6 @@ class AURA_EXPORT DispatcherClient {
public:
virtual void RunWithDispatcher(base::MessagePumpDispatcher* dispatcher,
aura::Window* associated_window) = 0;
-
- virtual void QuitNestedMessageLoop() = 0;
};
AURA_EXPORT void SetDispatcherClient(Window* root_window,
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index 6269224..ff3a5fe 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -13,7 +13,6 @@
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
-#include "ui/aura/client/dispatcher_client.h"
#include "ui/base/dragdrop/drag_utils.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/l10n/l10n_util.h"
@@ -2303,23 +2302,18 @@ void MenuController::SetExitType(ExitType type) {
// Exit nested message loops as soon as possible. We do this as
// MessagePumpDispatcher is only invoked before native events, which means
// its entirely possible for a Widget::CloseNow() task to be processed before
- // the next native message. We quite the nested message loop as soon as
- // possible to avoid having deleted views classes (such as widgets and
- // rootviews) on the stack when the nested message loop stops.
+ // the next native message. By using QuitNow() we ensures the nested message
+ // loop returns as soon as possible and avoids having deleted views classes
+ // (such as widgets and rootviews) on the stack when the nested message loop
+ // stops.
//
- // It's safe to invoke QuitNestedMessageLoop() multiple times, it only effects
- // the current loop.
+ // It's safe to invoke QuitNow multiple times, it only effects the current
+ // loop.
bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE &&
message_loop_depth_;
- if (quit_now) {
- if (owner_) {
- aura::Window* root = owner_->GetNativeWindow()->GetRootWindow();
- aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop();
- } else {
- base::MessageLoop::current()->QuitNow();
- }
- }
+ if (quit_now)
+ base::MessageLoop::current()->QuitNow();
}
void MenuController::HandleMouseLocation(SubmenuView* source,
diff --git a/ui/views/widget/desktop_aura/desktop_dispatcher_client.cc b/ui/views/widget/desktop_aura/desktop_dispatcher_client.cc
index 977d0de..be251da 100644
--- a/ui/views/widget/desktop_aura/desktop_dispatcher_client.cc
+++ b/ui/views/widget/desktop_aura/desktop_dispatcher_client.cc
@@ -4,7 +4,6 @@
#include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
-#include "base/auto_reset.h"
#include "base/run_loop.h"
namespace views {
@@ -24,14 +23,7 @@ void DesktopDispatcherClient::RunWithDispatcher(
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
base::RunLoop run_loop(nested_dispatcher);
- base::AutoReset<base::Closure> reset_closure(&quit_closure_,
- run_loop.QuitClosure());
run_loop.Run();
}
-void DesktopDispatcherClient::QuitNestedMessageLoop() {
- CHECK(!quit_closure_.is_null());
- quit_closure_.Run();
-}
-
} // namespace views
diff --git a/ui/views/widget/desktop_aura/desktop_dispatcher_client.h b/ui/views/widget/desktop_aura/desktop_dispatcher_client.h
index 1af8f94..b59f4da 100644
--- a/ui/views/widget/desktop_aura/desktop_dispatcher_client.h
+++ b/ui/views/widget/desktop_aura/desktop_dispatcher_client.h
@@ -6,7 +6,6 @@
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DISPATCHER_CLIENT_H_
#include "base/basictypes.h"
-#include "base/callback.h"
#include "ui/aura/client/dispatcher_client.h"
#include "ui/views/views_export.h"
@@ -21,11 +20,8 @@ class VIEWS_EXPORT DesktopDispatcherClient
virtual void RunWithDispatcher(base::MessagePumpDispatcher* dispatcher,
aura::Window* associated_window) OVERRIDE;
- virtual void QuitNestedMessageLoop() OVERRIDE;
private:
- base::Closure quit_closure_;
-
DISALLOW_COPY_AND_ASSIGN(DesktopDispatcherClient);
};