| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/platform_display_default.h" | 5 #include "services/ui/ws/platform_display_default.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "gpu/ipc/client/gpu_channel_host.h" | 10 #include "gpu/ipc/client/gpu_channel_host.h" |
| 11 #include "services/ui/display/screen_manager.h" | 11 #include "services/ui/display/screen_manager.h" |
| 12 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" | 12 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" |
| 13 #include "services/ui/ws/server_window.h" | 13 #include "services/ui/ws/server_window.h" |
| 14 #include "services/ui/ws/threaded_image_cursors.h" |
| 14 #include "ui/base/cursor/image_cursors.h" | 15 #include "ui/base/cursor/image_cursors.h" |
| 15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| 18 #include "ui/platform_window/platform_ime_controller.h" | 19 #include "ui/platform_window/platform_ime_controller.h" |
| 19 #include "ui/platform_window/platform_window.h" | 20 #include "ui/platform_window/platform_window.h" |
| 20 | 21 |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 #include "ui/platform_window/win/win_window.h" | 23 #include "ui/platform_window/win/win_window.h" |
| 23 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 24 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 24 #include "ui/platform_window/x11/x11_window.h" | 25 #include "ui/platform_window/x11/x11_window.h" |
| 25 #elif defined(OS_ANDROID) | 26 #elif defined(OS_ANDROID) |
| 26 #include "ui/platform_window/android/platform_window_android.h" | 27 #include "ui/platform_window/android/platform_window_android.h" |
| 27 #elif defined(USE_OZONE) | 28 #elif defined(USE_OZONE) |
| 28 #include "ui/ozone/public/cursor_factory_ozone.h" | 29 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 29 #include "ui/ozone/public/ozone_platform.h" | 30 #include "ui/ozone/public/ozone_platform.h" |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 namespace ui { | 33 namespace ui { |
| 33 namespace ws { | 34 namespace ws { |
| 34 | 35 |
| 35 PlatformDisplayDefault::PlatformDisplayDefault( | 36 PlatformDisplayDefault::PlatformDisplayDefault( |
| 36 ServerWindow* root_window, | 37 ServerWindow* root_window, |
| 37 const display::ViewportMetrics& metrics, | 38 const display::ViewportMetrics& metrics, |
| 38 std::unique_ptr<ImageCursors> image_cursors) | 39 std::unique_ptr<ThreadedImageCursors> image_cursors) |
| 39 : root_window_(root_window), | 40 : root_window_(root_window), |
| 40 image_cursors_(std::move(image_cursors)), | 41 image_cursors_(std::move(image_cursors)), |
| 41 metrics_(metrics), | 42 metrics_(metrics), |
| 42 widget_(gfx::kNullAcceleratedWidget) {} | 43 widget_(gfx::kNullAcceleratedWidget) {} |
| 43 | 44 |
| 44 PlatformDisplayDefault::~PlatformDisplayDefault() { | 45 PlatformDisplayDefault::~PlatformDisplayDefault() { |
| 45 // Don't notify the delegate from the destructor. | 46 // Don't notify the delegate from the destructor. |
| 46 delegate_ = nullptr; | 47 delegate_ = nullptr; |
| 47 | 48 |
| 48 frame_generator_.reset(); | 49 frame_generator_.reset(); |
| 50 image_cursors_.reset(); |
| 49 // Destroy the PlatformWindow early on as it may call us back during | 51 // Destroy the PlatformWindow early on as it may call us back during |
| 50 // destruction and we want to be in a known state. But destroy the surface | 52 // destruction and we want to be in a known state. But destroy the surface |
| 51 // first because it can still be using the platform window. | 53 // and ImageCursorsAsync first because they can still be using the platform |
| 54 // window. |
| 52 platform_window_.reset(); | 55 platform_window_.reset(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 EventSink* PlatformDisplayDefault::GetEventSink() { | 58 EventSink* PlatformDisplayDefault::GetEventSink() { |
| 56 return delegate_->GetEventSink(); | 59 return delegate_->GetEventSink(); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { | 62 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
| 60 DCHECK(delegate); | 63 DCHECK(delegate); |
| 61 delegate_ = delegate; | 64 delegate_ = delegate; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 100 } |
| 98 | 101 |
| 99 void PlatformDisplayDefault::ReleaseCapture() { | 102 void PlatformDisplayDefault::ReleaseCapture() { |
| 100 platform_window_->ReleaseCapture(); | 103 platform_window_->ReleaseCapture(); |
| 101 } | 104 } |
| 102 | 105 |
| 103 void PlatformDisplayDefault::SetCursor(const ui::CursorData& cursor_data) { | 106 void PlatformDisplayDefault::SetCursor(const ui::CursorData& cursor_data) { |
| 104 if (!image_cursors_) | 107 if (!image_cursors_) |
| 105 return; | 108 return; |
| 106 | 109 |
| 107 ui::Cursor native_cursor(cursor_data.cursor_type()); | 110 ui::CursorType cursor_type = cursor_data.cursor_type(); |
| 108 | 111 |
| 109 #if defined(USE_OZONE) | 112 #if defined(USE_OZONE) |
| 110 if (cursor_data.cursor_type() != ui::CursorType::kCustom) { | 113 if (cursor_type != ui::CursorType::kCustom) { |
| 111 image_cursors_->SetPlatformCursor(&native_cursor); | 114 image_cursors_->SetCursor(cursor_type, platform_window_.get()); |
| 112 } else { | 115 } else { |
| 116 ui::Cursor native_cursor(cursor_type); |
| 113 // In Ozone builds, we have an interface available which turns bitmap data | 117 // In Ozone builds, we have an interface available which turns bitmap data |
| 114 // into platform cursors. | 118 // into platform cursors. |
| 115 ui::CursorFactoryOzone* cursor_factory = | 119 ui::CursorFactoryOzone* cursor_factory = |
| 116 delegate_->GetOzonePlatform()->GetCursorFactoryOzone(); | 120 delegate_->GetOzonePlatform()->GetCursorFactoryOzone(); |
| 117 native_cursor.SetPlatformCursor(cursor_factory->CreateAnimatedCursor( | 121 native_cursor.SetPlatformCursor(cursor_factory->CreateAnimatedCursor( |
| 118 cursor_data.cursor_frames(), cursor_data.hotspot_in_pixels(), | 122 cursor_data.cursor_frames(), cursor_data.hotspot_in_pixels(), |
| 119 cursor_data.frame_delay().InMilliseconds(), | 123 cursor_data.frame_delay().InMilliseconds(), |
| 120 cursor_data.scale_factor())); | 124 cursor_data.scale_factor())); |
| 125 platform_window_->SetCursor(native_cursor.platform()); |
| 121 } | 126 } |
| 122 #else | 127 #else |
| 123 // Outside of ozone builds, there isn't a single interface for creating | 128 // Outside of ozone builds, there isn't a single interface for creating |
| 124 // PlatformCursors. The closest thing to one is in //content/ instead of | 129 // PlatformCursors. The closest thing to one is in //content/ instead of |
| 125 // //ui/ which means we can't use it from here. For now, just don't handle | 130 // //ui/ which means we can't use it from here. For now, just don't handle |
| 126 // custom image cursors. | 131 // custom image cursors. |
| 127 // | 132 // |
| 128 // TODO(erg): Once blink speaks directly to mus, make blink perform its own | 133 // TODO(erg): Once blink speaks directly to mus, make blink perform its own |
| 129 // cursor management on its own mus windows so we can remove Webcursor from | 134 // cursor management on its own mus windows so we can remove Webcursor from |
| 130 // //content/ and do this in way that's safe cross-platform, instead of as an | 135 // //content/ and do this in way that's safe cross-platform, instead of as an |
| 131 // ozone-specific hack. | 136 // ozone-specific hack. |
| 132 if (cursor_data.cursor_type() == ui::CursorType::kCustom) { | 137 if (cursor_type == ui::CursorType::kCustom) { |
| 133 NOTIMPLEMENTED() << "No custom cursor support on non-ozone yet."; | 138 NOTIMPLEMENTED() << "No custom cursor support on non-ozone yet."; |
| 134 native_cursor = ui::Cursor(ui::CursorType::kPointer); | 139 cursor_type = ui::CursorType::kPointer; |
| 135 } | 140 } |
| 136 image_cursors_->SetPlatformCursor(&native_cursor); | 141 image_cursors_->SetCursor(cursor_type, platform_window_.get()); |
| 137 #endif | 142 #endif |
| 138 | |
| 139 platform_window_->SetCursor(native_cursor.platform()); | |
| 140 } | 143 } |
| 141 | 144 |
| 142 void PlatformDisplayDefault::MoveCursorTo( | 145 void PlatformDisplayDefault::MoveCursorTo( |
| 143 const gfx::Point& window_pixel_location) { | 146 const gfx::Point& window_pixel_location) { |
| 144 platform_window_->MoveCursorTo(window_pixel_location); | 147 platform_window_->MoveCursorTo(window_pixel_location); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void PlatformDisplayDefault::UpdateTextInputState( | 150 void PlatformDisplayDefault::UpdateTextInputState( |
| 148 const ui::TextInputState& state) { | 151 const ui::TextInputState& state) { |
| 149 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 152 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 272 } |
| 270 | 273 |
| 271 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 274 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
| 272 NOTREACHED(); | 275 NOTREACHED(); |
| 273 } | 276 } |
| 274 | 277 |
| 275 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 278 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 276 | 279 |
| 277 } // namespace ws | 280 } // namespace ws |
| 278 } // namespace ui | 281 } // namespace ui |
| OLD | NEW |