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

Side by Side Diff: ui/views/mus/platform_window_mus.cc

Issue 1891233006: mus: Fix handled status in UI event ack, add MessageLoop::NestingObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eventresult
Patch Set: review comments 3 Created 4 years, 7 months 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
« no previous file with comments | « ui/views/mus/platform_window_mus.h ('k') | ui/views/mus/platform_window_mus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/views/mus/platform_window_mus.h" 5 #include "ui/views/mus/platform_window_mus.h"
6 6
7 #include "base/message_loop/message_loop.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "components/bitmap_uploader/bitmap_uploader.h" 9 #include "components/bitmap_uploader/bitmap_uploader.h"
9 #include "components/mus/public/cpp/property_type_converters.h" 10 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "components/mus/public/cpp/window_property.h" 11 #include "components/mus/public/cpp/window_property.h"
11 #include "components/mus/public/interfaces/window_manager.mojom.h" 12 #include "components/mus/public/interfaces/window_manager.mojom.h"
12 #include "mojo/converters/input_events/input_events_type_converters.h" 13 #include "mojo/converters/input_events/input_events_type_converters.h"
13 #include "ui/base/view_prop.h" 14 #include "ui/base/view_prop.h"
14 #include "ui/platform_window/platform_window_delegate.h" 15 #include "ui/platform_window/platform_window_delegate.h"
15 #include "ui/views/mus/window_manager_connection.h" 16 #include "ui/views/mus/window_manager_connection.h"
16 17
18 using mus::mojom::EventResult;
19
17 namespace views { 20 namespace views {
18 21
19 namespace { 22 namespace {
23
20 static uint32_t accelerated_widget_count = 1; 24 static uint32_t accelerated_widget_count = 1;
21 25
26 // Handles acknowledgement of an input event, either immediately when a nested
27 // message loop starts, or upon destruction.
28 class EventAckHandler : public base::MessageLoop::NestingObserver {
29 public:
30 explicit EventAckHandler(
31 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback)
32 : ack_callback_(std::move(ack_callback)) {
33 DCHECK(ack_callback_);
34 base::MessageLoop::current()->AddNestingObserver(this);
35 }
36
37 ~EventAckHandler() override {
38 base::MessageLoop::current()->RemoveNestingObserver(this);
39 if (ack_callback_) {
40 ack_callback_->Run(handled_ ? EventResult::HANDLED
41 : EventResult::UNHANDLED);
42 }
43 }
44
45 void set_handled(bool handled) { handled_ = handled; }
46
47 // base::MessageLoop::NestingObserver:
48 void OnBeginNestedMessageLoop() override {
49 // Acknowledge the event immediately if a nested message loop starts.
50 // Otherwise we appear unresponsive for the life of the nested message loop.
51 if (ack_callback_) {
52 ack_callback_->Run(EventResult::HANDLED);
53 ack_callback_.reset();
54 }
55 }
56
57 private:
58 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_;
59 bool handled_ = false;
60
61 DISALLOW_COPY_AND_ASSIGN(EventAckHandler);
62 };
63
22 } // namespace 64 } // namespace
23 65
24 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, 66 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
25 shell::Connector* connector, 67 shell::Connector* connector,
26 mus::Window* mus_window) 68 mus::Window* mus_window)
27 : delegate_(delegate), 69 : delegate_(delegate),
28 mus_window_(mus_window), 70 mus_window_(mus_window),
29 show_state_(mus::mojom::ShowState::RESTORED), 71 show_state_(mus::mojom::ShowState::RESTORED),
30 last_cursor_(mus::mojom::Cursor::CURSOR_NULL), 72 last_cursor_(mus::mojom::Cursor::CURSOR_NULL),
31 mus_window_destroyed_(false) { 73 mus_window_destroyed_(false) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 257 }
216 delegate_->OnWindowStateChanged(state); 258 delegate_->OnWindowStateChanged(state);
217 } 259 }
218 260
219 void PlatformWindowMus::OnRequestClose(mus::Window* window) { 261 void PlatformWindowMus::OnRequestClose(mus::Window* window) {
220 delegate_->OnCloseRequest(); 262 delegate_->OnCloseRequest();
221 } 263 }
222 264
223 void PlatformWindowMus::OnWindowInputEvent( 265 void PlatformWindowMus::OnWindowInputEvent(
224 mus::Window* view, 266 mus::Window* view,
225 const ui::Event& event, 267 const ui::Event& event_in,
226 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* 268 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
227 ack_callback) { 269 // Take ownership of the callback, indicating that we will handle it.
228 // It's possible dispatching the event will spin a nested message loop. Ack 270 EventAckHandler ack_handler(std::move(*ack_callback));
229 // the callback now, otherwise we appear unresponsive for the life of the 271
230 // nested message loop. 272 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in);
231 (*ack_callback)->Run(mus::mojom::EventResult::HANDLED); 273 delegate_->DispatchEvent(event.get());
232 ack_callback->reset(); 274 // NOTE: |this| may be deleted.
233 // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to 275
234 // accept constant pointers. 276 ack_handler.set_handled(event->handled());
235 delegate_->DispatchEvent(ui::Event::Clone(event).get()); 277 // |ack_handler| acks the event on destruction if necessary.
236 } 278 }
237 279
238 } // namespace views 280 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/platform_window_mus.h ('k') | ui/views/mus/platform_window_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698