OLD | NEW |
---|---|
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 |
22 } // namespace | 26 } // namespace |
23 | 27 |
24 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, | 28 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
25 shell::Connector* connector, | 29 shell::Connector* connector, |
26 mus::Window* mus_window) | 30 mus::Window* mus_window) |
27 : delegate_(delegate), | 31 : delegate_(delegate), |
28 mus_window_(mus_window), | 32 mus_window_(mus_window), |
29 show_state_(mus::mojom::ShowState::RESTORED), | 33 show_state_(mus::mojom::ShowState::RESTORED), |
30 last_cursor_(mus::mojom::Cursor::CURSOR_NULL), | 34 last_cursor_(mus::mojom::Cursor::CURSOR_NULL), |
31 mus_window_destroyed_(false) { | 35 mus_window_destroyed_(false) { |
32 DCHECK(delegate_); | 36 DCHECK(delegate_); |
33 DCHECK(mus_window_); | 37 DCHECK(mus_window_); |
34 mus_window_->AddObserver(this); | 38 mus_window_->AddObserver(this); |
35 mus_window_->set_input_event_handler(this); | 39 mus_window_->set_input_event_handler(this); |
40 base::MessageLoop::current()->AddNestingObserver(this); | |
36 | 41 |
37 // We need accelerated widget numbers to be different for each | 42 // We need accelerated widget numbers to be different for each |
38 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t | 43 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
39 // has this property. | 44 // has this property. |
40 #if defined(OS_WIN) || defined(OS_ANDROID) | 45 #if defined(OS_WIN) || defined(OS_ANDROID) |
41 gfx::AcceleratedWidget accelerated_widget = | 46 gfx::AcceleratedWidget accelerated_widget = |
42 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 47 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
43 #else | 48 #else |
44 gfx::AcceleratedWidget accelerated_widget = | 49 gfx::AcceleratedWidget accelerated_widget = |
45 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 50 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
46 #endif | 51 #endif |
47 delegate_->OnAcceleratedWidgetAvailable( | 52 delegate_->OnAcceleratedWidgetAvailable( |
48 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); | 53 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); |
49 | 54 |
50 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); | 55 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); |
51 bitmap_uploader_->Init(connector); | 56 bitmap_uploader_->Init(connector); |
52 prop_.reset(new ui::ViewProp( | 57 prop_.reset(new ui::ViewProp( |
53 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, | 58 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, |
54 bitmap_uploader_.get())); | 59 bitmap_uploader_.get())); |
55 } | 60 } |
56 | 61 |
57 PlatformWindowMus::~PlatformWindowMus() { | 62 PlatformWindowMus::~PlatformWindowMus() { |
63 base::MessageLoop::current()->RemoveNestingObserver(this); | |
58 if (!mus_window_) | 64 if (!mus_window_) |
59 return; | 65 return; |
60 mus_window_->RemoveObserver(this); | 66 mus_window_->RemoveObserver(this); |
61 mus_window_->set_input_event_handler(nullptr); | 67 mus_window_->set_input_event_handler(nullptr); |
62 if (!mus_window_destroyed_) | 68 if (!mus_window_destroyed_) |
63 mus_window_->Destroy(); | 69 mus_window_->Destroy(); |
64 } | 70 } |
65 | 71 |
66 void PlatformWindowMus::Activate() { | 72 void PlatformWindowMus::Activate() { |
67 mus_window_->SetFocus(); | 73 mus_window_->SetFocus(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 221 } |
216 delegate_->OnWindowStateChanged(state); | 222 delegate_->OnWindowStateChanged(state); |
217 } | 223 } |
218 | 224 |
219 void PlatformWindowMus::OnRequestClose(mus::Window* window) { | 225 void PlatformWindowMus::OnRequestClose(mus::Window* window) { |
220 delegate_->OnCloseRequest(); | 226 delegate_->OnCloseRequest(); |
221 } | 227 } |
222 | 228 |
223 void PlatformWindowMus::OnWindowInputEvent( | 229 void PlatformWindowMus::OnWindowInputEvent( |
224 mus::Window* view, | 230 mus::Window* view, |
225 const ui::Event& event, | 231 const ui::Event& event_in, |
226 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* | 232 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
227 ack_callback) { | 233 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
| |
228 // It's possible dispatching the event will spin a nested message loop. Ack | 234 |
229 // the callback now, otherwise we appear unresponsive for the life of the | 235 // DispatchEvent requires a mutable event so flags like handled can be set. |
230 // nested message loop. | 236 scoped_ptr<ui::Event> event = ui::Event::Clone(event_in); |
sky
2016/04/16 16:28:33
std::unique_ptr
| |
231 (*ack_callback)->Run(mus::mojom::EventResult::HANDLED); | 237 delegate_->DispatchEvent(event.get()); |
232 ack_callback->reset(); | 238 |
233 // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to | 239 // If the event wasn't already handled by a nested message loop then ack it |
234 // accept constant pointers. | 240 // with the handled state. |
235 delegate_->DispatchEvent(ui::Event::Clone(event).get()); | 241 if (event_ack_callback_) { |
sky
2016/04/16 16:28:33
In addition to multiple nestings you should deal w
| |
242 event_ack_callback_->Run( | |
243 event->handled() ? EventResult::HANDLED : EventResult::UNHANDLED); | |
244 event_ack_callback_.reset(); | |
245 } | |
246 } | |
247 | |
248 void PlatformWindowMus::OnBeginNestedMessageLoop() { | |
249 // It's possible dispatching an event will spin a nested message loop. If we | |
250 // are processing an event then ack the callback now, otherwise we appear | |
251 // unresponsive for the life of the nested message loop. | |
252 if (event_ack_callback_) { | |
253 event_ack_callback_->Run(EventResult::HANDLED); | |
254 event_ack_callback_.reset(); | |
255 } | |
236 } | 256 } |
237 | 257 |
238 } // namespace views | 258 } // namespace views |
OLD | NEW |