Chromium Code Reviews| 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 "base/message_loop/message_loop.h" |
|
sadrul
2016/05/18 19:44:43
this can probably be removed now
Mark Dittmer
2016/05/18 19:56:22
Done.
| |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "components/bitmap_uploader/bitmap_uploader.h" | 9 #include "components/bitmap_uploader/bitmap_uploader.h" |
| 10 #include "components/mus/public/cpp/property_type_converters.h" | 10 #include "components/mus/public/cpp/property_type_converters.h" |
| 11 #include "components/mus/public/cpp/window_property.h" | 11 #include "components/mus/public/cpp/window_property.h" |
| 12 #include "components/mus/public/interfaces/window_manager.mojom.h" | 12 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 13 #include "mojo/converters/input_events/input_events_type_converters.h" | 13 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 14 #include "ui/base/view_prop.h" | 14 #include "ui/base/view_prop.h" |
| 15 #include "ui/platform_window/platform_window_delegate.h" | 15 #include "ui/platform_window/platform_window_delegate.h" |
| 16 #include "ui/views/mus/window_manager_connection.h" | 16 #include "ui/views/mus/window_manager_connection.h" |
| 17 | 17 |
| 18 using mus::mojom::EventResult; | 18 using mus::mojom::EventResult; |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 static uint32_t accelerated_widget_count = 1; | 24 static uint32_t accelerated_widget_count = 1; |
| 25 | 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 | |
| 64 } // namespace | 26 } // namespace |
| 65 | 27 |
| 66 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, | 28 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
| 67 shell::Connector* connector, | 29 shell::Connector* connector, |
| 68 mus::Window* mus_window) | 30 mus::Window* mus_window) |
| 69 : delegate_(delegate), | 31 : delegate_(delegate), |
| 70 mus_window_(mus_window), | 32 mus_window_(mus_window), |
| 71 mus_window_destroyed_(false) { | 33 mus_window_destroyed_(false) { |
| 72 DCHECK(delegate_); | 34 DCHECK(delegate_); |
| 73 DCHECK(mus_window_); | 35 DCHECK(mus_window_); |
| 74 mus_window_->set_input_event_handler(this); | |
| 75 | 36 |
| 76 // We need accelerated widget numbers to be different for each | 37 // We need accelerated widget numbers to be different for each |
| 77 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t | 38 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
| 78 // has this property. | 39 // has this property. |
| 79 #if defined(OS_WIN) || defined(OS_ANDROID) | 40 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 80 gfx::AcceleratedWidget accelerated_widget = | 41 gfx::AcceleratedWidget accelerated_widget = |
| 81 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 42 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 82 #else | 43 #else |
| 83 gfx::AcceleratedWidget accelerated_widget = | 44 gfx::AcceleratedWidget accelerated_widget = |
| 84 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 45 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 85 #endif | 46 #endif |
| 86 delegate_->OnAcceleratedWidgetAvailable( | 47 delegate_->OnAcceleratedWidgetAvailable( |
| 87 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); | 48 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); |
| 88 | 49 |
| 89 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); | 50 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); |
| 90 bitmap_uploader_->Init(connector); | 51 bitmap_uploader_->Init(connector); |
| 91 prop_.reset(new ui::ViewProp( | 52 prop_.reset(new ui::ViewProp( |
| 92 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, | 53 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, |
| 93 bitmap_uploader_.get())); | 54 bitmap_uploader_.get())); |
| 94 } | 55 } |
| 95 | 56 |
| 96 PlatformWindowMus::~PlatformWindowMus() { | 57 PlatformWindowMus::~PlatformWindowMus() {} |
| 97 if (!mus_window_) | |
| 98 return; | |
| 99 mus_window_->set_input_event_handler(nullptr); | |
| 100 } | |
| 101 | 58 |
| 102 void PlatformWindowMus::Show() {} | 59 void PlatformWindowMus::Show() {} |
| 103 | 60 |
| 104 void PlatformWindowMus::Hide() {} | 61 void PlatformWindowMus::Hide() {} |
| 105 | 62 |
| 106 void PlatformWindowMus::Close() { | 63 void PlatformWindowMus::Close() { |
| 107 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
| 108 } | 65 } |
| 109 | 66 |
| 110 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) {} | 67 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 101 } |
| 145 | 102 |
| 146 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { | 103 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { |
| 147 NOTIMPLEMENTED(); | 104 NOTIMPLEMENTED(); |
| 148 } | 105 } |
| 149 | 106 |
| 150 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { | 107 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { |
| 151 return nullptr; | 108 return nullptr; |
| 152 } | 109 } |
| 153 | 110 |
| 154 void PlatformWindowMus::OnWindowInputEvent( | |
| 155 mus::Window* view, | |
| 156 const ui::Event& event_in, | |
| 157 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | |
| 158 // Take ownership of the callback, indicating that we will handle it. | |
| 159 EventAckHandler ack_handler(std::move(*ack_callback)); | |
| 160 | |
| 161 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); | |
| 162 delegate_->DispatchEvent(event.get()); | |
| 163 // NOTE: |this| may be deleted. | |
| 164 | |
| 165 ack_handler.set_handled(event->handled()); | |
| 166 // |ack_handler| acks the event on destruction if necessary. | |
| 167 } | |
| 168 | |
| 169 } // namespace views | 111 } // namespace views |
| OLD | NEW |