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" |
| 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 | 26 // Handles acknowledgement of an input event, either immediately when a nested |
| 27 // message loop starts, or upon destruction. | 27 // message loop starts, or upon destruction. |
| 28 class EventAckHandler : public base::MessageLoop::NestingObserver { | 28 class EventAckHandler : public base::MessageLoop::NestingObserver { |
|
sadrul
2016/05/17 00:18:48
Remove.
Mark Dittmer
2016/05/17 14:18:11
Done.
| |
| 29 public: | 29 public: |
| 30 explicit EventAckHandler( | 30 explicit EventAckHandler( |
| 31 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) | 31 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) |
| 32 : ack_callback_(std::move(ack_callback)) { | 32 : ack_callback_(std::move(ack_callback)) { |
| 33 DCHECK(ack_callback_); | 33 DCHECK(ack_callback_); |
| 34 base::MessageLoop::current()->AddNestingObserver(this); | 34 base::MessageLoop::current()->AddNestingObserver(this); |
| 35 } | 35 } |
| 36 | 36 |
| 37 ~EventAckHandler() override { | 37 ~EventAckHandler() override { |
| 38 base::MessageLoop::current()->RemoveNestingObserver(this); | 38 base::MessageLoop::current()->RemoveNestingObserver(this); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, | 66 PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate, |
| 67 shell::Connector* connector, | 67 shell::Connector* connector, |
| 68 mus::Window* mus_window) | 68 mus::Window* mus_window) |
| 69 : delegate_(delegate), | 69 : delegate_(delegate), |
| 70 mus_window_(mus_window), | 70 mus_window_(mus_window), |
| 71 mus_window_destroyed_(false) { | 71 mus_window_destroyed_(false) { |
| 72 DCHECK(delegate_); | 72 DCHECK(delegate_); |
| 73 DCHECK(mus_window_); | 73 DCHECK(mus_window_); |
| 74 mus_window_->set_input_event_handler(this); | |
| 75 | 74 |
| 76 // We need accelerated widget numbers to be different for each | 75 // We need accelerated widget numbers to be different for each |
| 77 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t | 76 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
| 78 // has this property. | 77 // has this property. |
| 79 #if defined(OS_WIN) || defined(OS_ANDROID) | 78 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 80 gfx::AcceleratedWidget accelerated_widget = | 79 gfx::AcceleratedWidget accelerated_widget = |
| 81 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 80 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 82 #else | 81 #else |
| 83 gfx::AcceleratedWidget accelerated_widget = | 82 gfx::AcceleratedWidget accelerated_widget = |
| 84 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 83 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 85 #endif | 84 #endif |
| 86 delegate_->OnAcceleratedWidgetAvailable( | 85 delegate_->OnAcceleratedWidgetAvailable( |
| 87 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); | 86 accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio); |
| 88 | 87 |
| 89 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); | 88 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_)); |
| 90 bitmap_uploader_->Init(connector); | 89 bitmap_uploader_->Init(connector); |
| 91 prop_.reset(new ui::ViewProp( | 90 prop_.reset(new ui::ViewProp( |
| 92 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, | 91 accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget, |
| 93 bitmap_uploader_.get())); | 92 bitmap_uploader_.get())); |
| 94 } | 93 } |
| 95 | 94 |
| 96 PlatformWindowMus::~PlatformWindowMus() { | 95 PlatformWindowMus::~PlatformWindowMus() {} |
| 97 if (!mus_window_) | |
| 98 return; | |
| 99 mus_window_->set_input_event_handler(nullptr); | |
| 100 } | |
| 101 | 96 |
| 102 void PlatformWindowMus::Show() {} | 97 void PlatformWindowMus::Show() {} |
| 103 | 98 |
| 104 void PlatformWindowMus::Hide() {} | 99 void PlatformWindowMus::Hide() {} |
| 105 | 100 |
| 106 void PlatformWindowMus::Close() { | 101 void PlatformWindowMus::Close() { |
| 107 NOTIMPLEMENTED(); | 102 NOTIMPLEMENTED(); |
| 108 } | 103 } |
| 109 | 104 |
| 110 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) {} | 105 void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 139 } |
| 145 | 140 |
| 146 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { | 141 void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) { |
| 147 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 148 } | 143 } |
| 149 | 144 |
| 150 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { | 145 ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() { |
| 151 return nullptr; | 146 return nullptr; |
| 152 } | 147 } |
| 153 | 148 |
| 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 | 149 } // namespace views |
| OLD | NEW |