| 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> |
| 8 |
| 7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 8 #include "gpu/ipc/client/gpu_channel_host.h" | 10 #include "gpu/ipc/client/gpu_channel_host.h" |
| 9 #include "services/ui/display/screen_manager.h" | 11 #include "services/ui/display/screen_manager.h" |
| 10 #include "services/ui/ws/display_client_compositor_frame_sink.h" | 12 #include "services/ui/ws/display_client_compositor_frame_sink.h" |
| 11 #include "services/ui/ws/server_window.h" | 13 #include "services/ui/ws/server_window.h" |
| 12 #include "ui/base/cursor/image_cursors.h" | 14 #include "ui/base/cursor/image_cursors.h" |
| 13 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 14 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 15 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 16 #include "ui/platform_window/platform_ime_controller.h" | 18 #include "ui/platform_window/platform_ime_controller.h" |
| 17 #include "ui/platform_window/platform_window.h" | 19 #include "ui/platform_window/platform_window.h" |
| 18 | 20 |
| 19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 20 #include "ui/platform_window/win/win_window.h" | 22 #include "ui/platform_window/win/win_window.h" |
| 21 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 23 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 22 #include "ui/platform_window/x11/x11_window.h" | 24 #include "ui/platform_window/x11/x11_window.h" |
| 23 #elif defined(OS_ANDROID) | 25 #elif defined(OS_ANDROID) |
| 24 #include "ui/platform_window/android/platform_window_android.h" | 26 #include "ui/platform_window/android/platform_window_android.h" |
| 25 #elif defined(USE_OZONE) | 27 #elif defined(USE_OZONE) |
| 26 #include "ui/ozone/public/ozone_platform.h" | 28 #include "ui/ozone/public/ozone_platform.h" |
| 27 #endif | 29 #endif |
| 28 | 30 |
| 29 namespace ui { | 31 namespace ui { |
| 30 namespace ws { | 32 namespace ws { |
| 31 | 33 |
| 32 PlatformDisplayDefault::PlatformDisplayDefault( | 34 PlatformDisplayDefault::PlatformDisplayDefault( |
| 33 ServerWindow* root_window, | 35 ServerWindow* root_window, |
| 34 const display::ViewportMetrics& metrics) | 36 const display::ViewportMetrics& metrics, |
| 37 std::unique_ptr<ImageCursors> image_cursors) |
| 35 : root_window_(root_window), | 38 : root_window_(root_window), |
| 36 #if !defined(OS_ANDROID) | 39 image_cursors_(std::move(image_cursors)), |
| 37 image_cursors_(new ImageCursors), | |
| 38 #endif | |
| 39 metrics_(metrics), | 40 metrics_(metrics), |
| 40 widget_(gfx::kNullAcceleratedWidget) { | 41 widget_(gfx::kNullAcceleratedWidget) {} |
| 41 } | |
| 42 | 42 |
| 43 PlatformDisplayDefault::~PlatformDisplayDefault() { | 43 PlatformDisplayDefault::~PlatformDisplayDefault() { |
| 44 // Don't notify the delegate from the destructor. | 44 // Don't notify the delegate from the destructor. |
| 45 delegate_ = nullptr; | 45 delegate_ = nullptr; |
| 46 | 46 |
| 47 frame_generator_.reset(); | 47 frame_generator_.reset(); |
| 48 // Destroy the PlatformWindow early on as it may call us back during | 48 // Destroy the PlatformWindow early on as it may call us back during |
| 49 // destruction and we want to be in a known state. But destroy the surface | 49 // destruction and we want to be in a known state. But destroy the surface |
| 50 // first because it can still be using the platform window. | 50 // first because it can still be using the platform window. |
| 51 platform_window_.reset(); | 51 platform_window_.reset(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); | 69 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); |
| 70 platform_window_->SetBounds(bounds); | 70 platform_window_->SetBounds(bounds); |
| 71 #elif defined(USE_OZONE) | 71 #elif defined(USE_OZONE) |
| 72 platform_window_ = | 72 platform_window_ = |
| 73 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 73 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 74 #else | 74 #else |
| 75 NOTREACHED() << "Unsupported platform"; | 75 NOTREACHED() << "Unsupported platform"; |
| 76 #endif | 76 #endif |
| 77 | 77 |
| 78 platform_window_->Show(); | 78 platform_window_->Show(); |
| 79 #if !defined(OS_ANDROID) | 79 if (image_cursors_) { |
| 80 image_cursors_->SetDisplay(delegate_->GetDisplay(), | 80 image_cursors_->SetDisplay(delegate_->GetDisplay(), |
| 81 metrics_.device_scale_factor); | 81 metrics_.device_scale_factor); |
| 82 #endif | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { | 85 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { |
| 86 platform_window_->SetBounds(gfx::Rect(size)); | 86 platform_window_->SetBounds(gfx::Rect(size)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void PlatformDisplayDefault::SetTitle(const base::string16& title) { | 89 void PlatformDisplayDefault::SetTitle(const base::string16& title) { |
| 90 platform_window_->SetTitle(title); | 90 platform_window_->SetTitle(title); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PlatformDisplayDefault::SetCapture() { | 93 void PlatformDisplayDefault::SetCapture() { |
| 94 platform_window_->SetCapture(); | 94 platform_window_->SetCapture(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void PlatformDisplayDefault::ReleaseCapture() { | 97 void PlatformDisplayDefault::ReleaseCapture() { |
| 98 platform_window_->ReleaseCapture(); | 98 platform_window_->ReleaseCapture(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void PlatformDisplayDefault::SetCursorById(mojom::CursorType cursor_id) { | 101 void PlatformDisplayDefault::SetCursorById(mojom::CursorType cursor_id) { |
| 102 #if !defined(OS_ANDROID) | 102 if (!image_cursors_) |
| 103 return; |
| 104 |
| 103 // TODO(erg): This still isn't sufficient, and will only use native cursors | 105 // TODO(erg): This still isn't sufficient, and will only use native cursors |
| 104 // that chrome would use, not custom image cursors. For that, we should | 106 // that chrome would use, not custom image cursors. For that, we should |
| 105 // delegate to the window manager to load images from resource packs. | 107 // delegate to the window manager to load images from resource packs. |
| 106 // | 108 // |
| 107 // We probably also need to deal with different DPIs. | 109 // We probably also need to deal with different DPIs. |
| 108 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); | 110 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); |
| 109 image_cursors_->SetPlatformCursor(&cursor); | 111 image_cursors_->SetPlatformCursor(&cursor); |
| 110 platform_window_->SetCursor(cursor.platform()); | 112 platform_window_->SetCursor(cursor.platform()); |
| 111 #endif | |
| 112 } | 113 } |
| 113 | 114 |
| 114 void PlatformDisplayDefault::UpdateTextInputState( | 115 void PlatformDisplayDefault::UpdateTextInputState( |
| 115 const ui::TextInputState& state) { | 116 const ui::TextInputState& state) { |
| 116 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 117 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 117 if (ime) | 118 if (ime) |
| 118 ime->UpdateTextInputState(state); | 119 ime->UpdateTextInputState(state); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void PlatformDisplayDefault::SetImeVisibility(bool visible) { | 122 void PlatformDisplayDefault::SetImeVisibility(bool visible) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 SendEventToSink(&pointer_event); | 187 SendEventToSink(&pointer_event); |
| 187 } else if (event->IsMouseEvent()) { | 188 } else if (event->IsMouseEvent()) { |
| 188 ui::PointerEvent pointer_event(*event->AsMouseEvent()); | 189 ui::PointerEvent pointer_event(*event->AsMouseEvent()); |
| 189 SendEventToSink(&pointer_event); | 190 SendEventToSink(&pointer_event); |
| 190 } else if (event->IsTouchEvent()) { | 191 } else if (event->IsTouchEvent()) { |
| 191 ui::PointerEvent pointer_event(*event->AsTouchEvent()); | 192 ui::PointerEvent pointer_event(*event->AsTouchEvent()); |
| 192 SendEventToSink(&pointer_event); | 193 SendEventToSink(&pointer_event); |
| 193 } else { | 194 } else { |
| 194 SendEventToSink(event); | 195 SendEventToSink(event); |
| 195 } | 196 } |
| 196 | |
| 197 #if defined(USE_X11) || defined(USE_OZONE) | |
| 198 // We want to emulate the WM_CHAR generation behaviour of Windows. | |
| 199 // | |
| 200 // On Linux, we've previously inserted characters by having | |
| 201 // InputMethodAuraLinux take all key down events and send a character event | |
| 202 // to the TextInputClient. This causes a mismatch in code that has to be | |
| 203 // shared between Windows and Linux, including blink code. Now that we're | |
| 204 // trying to have one way of doing things, we need to standardize on and | |
| 205 // emulate Windows character events. | |
| 206 // | |
| 207 // This is equivalent to what we're doing in the current Linux port, but | |
| 208 // done once instead of done multiple times in different places. | |
| 209 if (event->type() == ui::ET_KEY_PRESSED) { | |
| 210 ui::KeyEvent* key_press_event = event->AsKeyEvent(); | |
| 211 ui::KeyEvent char_event(key_press_event->GetCharacter(), | |
| 212 key_press_event->key_code(), | |
| 213 key_press_event->flags()); | |
| 214 // We don't check that GetCharacter() is equal because changing a key event | |
| 215 // with an accelerator to a character event can change the character, for | |
| 216 // example, from 'M' to '^M'. | |
| 217 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | |
| 218 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | |
| 219 SendEventToSink(&char_event); | |
| 220 } | |
| 221 #endif | |
| 222 } | 197 } |
| 223 | 198 |
| 224 void PlatformDisplayDefault::OnCloseRequest() { | 199 void PlatformDisplayDefault::OnCloseRequest() { |
| 225 // TODO(tonikitoo): Handle a close request in external window mode. The window | 200 // TODO(tonikitoo): Handle a close request in external window mode. The window |
| 226 // should be closed by the WS and it shouldn't involve ScreenManager. | 201 // should be closed by the WS and it shouldn't involve ScreenManager. |
| 227 const int64_t display_id = delegate_->GetDisplay().id(); | 202 const int64_t display_id = delegate_->GetDisplay().id(); |
| 228 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); | 203 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); |
| 229 } | 204 } |
| 230 | 205 |
| 231 void PlatformDisplayDefault::OnClosed() {} | 206 void PlatformDisplayDefault::OnClosed() {} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 246 } |
| 272 | 247 |
| 273 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 248 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
| 274 NOTREACHED(); | 249 NOTREACHED(); |
| 275 } | 250 } |
| 276 | 251 |
| 277 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 252 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 278 | 253 |
| 279 } // namespace ws | 254 } // namespace ws |
| 280 } // namespace ui | 255 } // namespace ui |
| OLD | NEW |