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

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

Issue 1883263002: mash: Repost mouse pressed event when closing Ash system tray (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 8 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') | no next file » | 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
17 namespace views { 18 namespace views {
18 19
19 namespace { 20 namespace {
21
20 static uint32_t accelerated_widget_count = 1; 22 static uint32_t accelerated_widget_count = 1;
21 23
22 } // namespace 24 } // namespace
23 25
24 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, 26 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
25 shell::Connector* connector, 27 shell::Connector* connector,
26 mus::Window* mus_window) 28 mus::Window* mus_window)
27 : delegate_(delegate), 29 : delegate_(delegate),
28 mus_window_(mus_window), 30 mus_window_(mus_window),
29 show_state_(mus::mojom::ShowState::RESTORED), 31 show_state_(mus::mojom::ShowState::RESTORED),
30 last_cursor_(mus::mojom::Cursor::CURSOR_NULL), 32 last_cursor_(mus::mojom::Cursor::CURSOR_NULL),
31 mus_window_destroyed_(false) { 33 mus_window_destroyed_(false) {
32 DCHECK(delegate_); 34 DCHECK(delegate_);
33 DCHECK(mus_window_); 35 DCHECK(mus_window_);
34 mus_window_->AddObserver(this); 36 mus_window_->AddObserver(this);
35 mus_window_->set_input_event_handler(this); 37 mus_window_->set_input_event_handler(this);
38 base::MessageLoop::current()->AddNestingObserver(this);
36 39
37 // We need accelerated widget numbers to be different for each 40 // We need accelerated widget numbers to be different for each
38 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t 41 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
39 // has this property. 42 // has this property.
40 #if defined(OS_WIN) || defined(OS_ANDROID) 43 #if defined(OS_WIN) || defined(OS_ANDROID)
41 gfx::AcceleratedWidget accelerated_widget = 44 gfx::AcceleratedWidget accelerated_widget =
42 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 45 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
43 #else 46 #else
44 gfx::AcceleratedWidget accelerated_widget = 47 gfx::AcceleratedWidget accelerated_widget =
45 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); 48 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
46 #endif 49 #endif
47 delegate_->OnAcceleratedWidgetAvailable( 50 delegate_->OnAcceleratedWidgetAvailable(
48 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); 51 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio);
49 52
50 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); 53 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_));
51 bitmap_uploader_->Init(connector); 54 bitmap_uploader_->Init(connector);
52 prop_.reset(new ui::ViewProp( 55 prop_.reset(new ui::ViewProp(
53 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, 56 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget,
54 bitmap_uploader_.get())); 57 bitmap_uploader_.get()));
55 } 58 }
56 59
57 PlatformWindowMus::~PlatformWindowMus() { 60 PlatformWindowMus::~PlatformWindowMus() {
61 base::MessageLoop::current()->RemoveNestingObserver(this);
58 if (!mus_window_) 62 if (!mus_window_)
59 return; 63 return;
60 mus_window_->RemoveObserver(this); 64 mus_window_->RemoveObserver(this);
61 mus_window_->set_input_event_handler(nullptr); 65 mus_window_->set_input_event_handler(nullptr);
62 if (!mus_window_destroyed_) 66 if (!mus_window_destroyed_)
63 mus_window_->Destroy(); 67 mus_window_->Destroy();
64 } 68 }
65 69
66 void PlatformWindowMus::Activate() { 70 void PlatformWindowMus::Activate() {
67 mus_window_->SetFocus(); 71 mus_window_->SetFocus();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 delegate_->OnWindowStateChanged(state); 220 delegate_->OnWindowStateChanged(state);
217 } 221 }
218 222
219 void PlatformWindowMus::OnRequestClose(mus::Window* window) { 223 void PlatformWindowMus::OnRequestClose(mus::Window* window) {
220 delegate_->OnCloseRequest(); 224 delegate_->OnCloseRequest();
221 } 225 }
222 226
223 void PlatformWindowMus::OnWindowInputEvent( 227 void PlatformWindowMus::OnWindowInputEvent(
224 mus::Window* view, 228 mus::Window* view,
225 const ui::Event& event, 229 const ui::Event& event,
226 std::unique_ptr<base::Callback<void(bool)>>* ack_callback) { 230 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>*
227 // It's possible dispatching the event will spin a nested message loop. Ack 231 ack_callback) {
228 // the callback now, otherwise we appear unresponsive for the life of the 232 event_ack_callback_ = std::move(*ack_callback);
229 // nested message loop. 233
230 // TODO(jamescook): Only ack the event as handled if a nested message loop 234 bool had_capture = mus_window_->HasCapture();
231 // actually starts, perhaps through an observer on MessageLoop. Otherwise 235
232 // ack the event with the actual handled state below DispatchEvent(). 236 // DispatchEvent requires a mutable event so flags like handled can be set.
233 (*ack_callback)->Run(true); 237 scoped_ptr<ui::Event> mutable_event = ui::Event::Clone(event);
234 ack_callback->reset(); 238 delegate_->DispatchEvent(mutable_event.get());
235 // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to 239
236 // accept constant pointers. 240 mus::mojom::EventResult result;
237 delegate_->DispatchEvent(ui::Event::Clone(event).get()); 241 if (mutable_event->handled())
242 result = mus::mojom::EventResult::HANDLED;
243 else if (ShouldRepostEvent(*mutable_event.get(), had_capture))
244 result = mus::mojom::EventResult::REPOST;
245 else
246 result = mus::mojom::EventResult::UNHANDLED;
247
248 // If the event wasn't already handled by a nested message loop then ack it
249 // with the handled state.
250 if (event_ack_callback_) {
251 event_ack_callback_->Run(result);
252 event_ack_callback_.reset();
253 }
254 }
255
256 void PlatformWindowMus::OnBeginNestedMessageLoop() {
257 // It's possible dispatching an event will spin a nested message loop. If we
258 // are processing an event then ack the callback now, otherwise we appear
259 // unresponsive for the life of the nested message loop.
260 if (event_ack_callback_) {
261 event_ack_callback_->Run(mus::mojom::EventResult::HANDLED);
262 event_ack_callback_.reset();
263 }
264 }
265
266 bool PlatformWindowMus::ShouldRepostEvent(const ui::Event& event,
267 bool had_capture) {
268 // Repost mouse events that cause capture loss (e.g. a mouse press that closes
269 // a menu that had capture).
270 return had_capture && !mus_window_->HasCapture() &&
271 (event.type() == ui::ET_MOUSE_PRESSED ||
272 event.type() == ui::ET_MOUSE_RELEASED);
238 } 273 }
239 274
240 } // namespace views 275 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/platform_window_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698