Index: ui/views/mus/platform_window_mus.cc |
diff --git a/ui/views/mus/platform_window_mus.cc b/ui/views/mus/platform_window_mus.cc |
index 4b72979b40ce92857c8d88346fcdc320a7a2eb10..b8f99fb53fa5b0d5daea11081824f838bca8215e 100644 |
--- a/ui/views/mus/platform_window_mus.cc |
+++ b/ui/views/mus/platform_window_mus.cc |
@@ -4,6 +4,7 @@ |
#include "ui/views/mus/platform_window_mus.h" |
+#include "base/message_loop/message_loop.h" |
#include "build/build_config.h" |
#include "components/bitmap_uploader/bitmap_uploader.h" |
#include "components/mus/public/cpp/property_type_converters.h" |
@@ -14,9 +15,12 @@ |
#include "ui/platform_window/platform_window_delegate.h" |
#include "ui/views/mus/window_manager_connection.h" |
+using mus::mojom::EventResult; |
+ |
namespace views { |
namespace { |
+ |
static uint32_t accelerated_widget_count = 1; |
} // namespace |
@@ -33,6 +37,7 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
DCHECK(mus_window_); |
mus_window_->AddObserver(this); |
mus_window_->set_input_event_handler(this); |
+ base::MessageLoop::current()->AddNestingObserver(this); |
// We need accelerated widget numbers to be different for each |
// window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
@@ -55,6 +60,7 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
} |
PlatformWindowMus::~PlatformWindowMus() { |
+ base::MessageLoop::current()->RemoveNestingObserver(this); |
if (!mus_window_) |
return; |
mus_window_->RemoveObserver(this); |
@@ -222,17 +228,31 @@ void PlatformWindowMus::OnRequestClose(mus::Window* window) { |
void PlatformWindowMus::OnWindowInputEvent( |
mus::Window* view, |
- const ui::Event& event, |
- std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* |
- ack_callback) { |
- // It's possible dispatching the event will spin a nested message loop. Ack |
- // the callback now, otherwise we appear unresponsive for the life of the |
- // nested message loop. |
- (*ack_callback)->Run(mus::mojom::EventResult::HANDLED); |
- ack_callback->reset(); |
- // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to |
- // accept constant pointers. |
- delegate_->DispatchEvent(ui::Event::Clone(event).get()); |
+ const ui::Event& event_in, |
+ std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
+ event_ack_callback_ = std::move(*ack_callback); |
sky
2016/04/16 16:28:33
I have a feeling you need to deal with multiple ne
|
+ |
+ // DispatchEvent requires a mutable event so flags like handled can be set. |
+ scoped_ptr<ui::Event> event = ui::Event::Clone(event_in); |
sky
2016/04/16 16:28:33
std::unique_ptr
|
+ delegate_->DispatchEvent(event.get()); |
+ |
+ // If the event wasn't already handled by a nested message loop then ack it |
+ // with the handled state. |
+ if (event_ack_callback_) { |
sky
2016/04/16 16:28:33
In addition to multiple nestings you should deal w
|
+ event_ack_callback_->Run( |
+ event->handled() ? EventResult::HANDLED : EventResult::UNHANDLED); |
+ event_ack_callback_.reset(); |
+ } |
+} |
+ |
+void PlatformWindowMus::OnBeginNestedMessageLoop() { |
+ // It's possible dispatching an event will spin a nested message loop. If we |
+ // are processing an event then ack the callback now, otherwise we appear |
+ // unresponsive for the life of the nested message loop. |
+ if (event_ack_callback_) { |
+ event_ack_callback_->Run(EventResult::HANDLED); |
+ event_ack_callback_.reset(); |
+ } |
} |
} // namespace views |