| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "gpu/ipc/client/gpu_channel_host.h" | 8 #include "gpu/ipc/client/gpu_channel_host.h" |
| 9 #include "services/ui/display/screen_manager.h" | 9 #include "services/ui/display/screen_manager.h" |
| 10 #include "services/ui/ws/display_client_compositor_frame_sink.h" | 10 #include "services/ui/ws/display_client_compositor_frame_sink.h" |
| 11 #include "services/ui/ws/platform_display_init_params.h" | |
| 12 #include "services/ui/ws/server_window.h" | 11 #include "services/ui/ws/server_window.h" |
| 13 #include "ui/base/cursor/image_cursors.h" | 12 #include "ui/base/cursor/image_cursors.h" |
| 14 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
| 15 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 16 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 17 #include "ui/platform_window/platform_ime_controller.h" | 16 #include "ui/platform_window/platform_ime_controller.h" |
| 18 #include "ui/platform_window/platform_window.h" | 17 #include "ui/platform_window/platform_window.h" |
| 19 | 18 |
| 20 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 21 #include "ui/platform_window/win/win_window.h" | 20 #include "ui/platform_window/win/win_window.h" |
| 22 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 21 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 23 #include "ui/platform_window/x11/x11_window.h" | 22 #include "ui/platform_window/x11/x11_window.h" |
| 24 #elif defined(OS_ANDROID) | 23 #elif defined(OS_ANDROID) |
| 25 #include "ui/platform_window/android/platform_window_android.h" | 24 #include "ui/platform_window/android/platform_window_android.h" |
| 26 #elif defined(USE_OZONE) | 25 #elif defined(USE_OZONE) |
| 27 #include "ui/ozone/public/ozone_platform.h" | 26 #include "ui/ozone/public/ozone_platform.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace ui { | 29 namespace ui { |
| 31 namespace ws { | 30 namespace ws { |
| 32 | 31 |
| 33 PlatformDisplayDefault::PlatformDisplayDefault( | 32 PlatformDisplayDefault::PlatformDisplayDefault( |
| 34 const PlatformDisplayInitParams& init_params) | 33 ServerWindow* root_window, |
| 35 : display_id_(init_params.display_id), | 34 const display::ViewportMetrics& metrics) |
| 35 : root_window_(root_window), |
| 36 #if !defined(OS_ANDROID) | 36 #if !defined(OS_ANDROID) |
| 37 image_cursors_(new ImageCursors), | 37 image_cursors_(new ImageCursors), |
| 38 #endif | 38 #endif |
| 39 metrics_(init_params.metrics), | 39 metrics_(metrics), |
| 40 widget_(gfx::kNullAcceleratedWidget), | 40 widget_(gfx::kNullAcceleratedWidget), |
| 41 root_window_(init_params.root_window), | 41 init_device_scale_factor_(metrics.device_scale_factor) { |
| 42 init_device_scale_factor_(init_params.metrics.device_scale_factor) { | |
| 43 } | 42 } |
| 44 | 43 |
| 45 PlatformDisplayDefault::~PlatformDisplayDefault() { | 44 PlatformDisplayDefault::~PlatformDisplayDefault() { |
| 46 // Don't notify the delegate from the destructor. | 45 // Don't notify the delegate from the destructor. |
| 47 delegate_ = nullptr; | 46 delegate_ = nullptr; |
| 48 | 47 |
| 49 frame_generator_.reset(); | 48 frame_generator_.reset(); |
| 50 // Destroy the PlatformWindow early on as it may call us back during | 49 // Destroy the PlatformWindow early on as it may call us back during |
| 51 // destruction and we want to be in a known state. But destroy the surface | 50 // destruction and we want to be in a known state. But destroy the surface |
| 52 // first because it can still be using the platform window. | 51 // first because it can still be using the platform window. |
| 53 platform_window_.reset(); | 52 platform_window_.reset(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { | 55 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
| 57 delegate_ = delegate; | 56 delegate_ = delegate; |
| 58 | 57 |
| 59 DCHECK(!metrics_.pixel_size.IsEmpty()); | 58 const gfx::Rect& bounds = metrics_.bounds_in_pixels; |
| 59 DCHECK(!bounds.size().IsEmpty()); |
| 60 | 60 |
| 61 // TODO(kylechar): The origin here isn't right if any displays have | |
| 62 // scale_factor other than 1.0 but will prevent windows from being stacked. | |
| 63 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); | |
| 64 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
| 65 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); | 62 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); |
| 66 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 63 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 67 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); | 64 platform_window_ = base::MakeUnique<ui::X11Window>(this, bounds); |
| 68 #elif defined(OS_ANDROID) | 65 #elif defined(OS_ANDROID) |
| 69 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); | 66 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); |
| 70 platform_window_->SetBounds(bounds); | 67 platform_window_->SetBounds(bounds); |
| 71 #elif defined(USE_OZONE) | 68 #elif defined(USE_OZONE) |
| 72 platform_window_ = | 69 platform_window_ = |
| 73 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 70 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 74 #else | 71 #else |
| 75 NOTREACHED() << "Unsupported platform"; | 72 NOTREACHED() << "Unsupported platform"; |
| 76 #endif | 73 #endif |
| 77 | 74 |
| 78 platform_window_->Show(); | 75 platform_window_->Show(); |
| 79 #if !defined(OS_ANDROID) | 76 #if !defined(OS_ANDROID) |
| 80 image_cursors_->SetDisplay(delegate_->GetDisplay(), | 77 image_cursors_->SetDisplay(delegate_->GetDisplay(), |
| 81 metrics_.device_scale_factor); | 78 metrics_.device_scale_factor); |
| 82 #endif | 79 #endif |
| 83 } | 80 } |
| 84 | 81 |
| 85 int64_t PlatformDisplayDefault::GetId() const { | |
| 86 return display_id_; | |
| 87 } | |
| 88 | |
| 89 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { | 82 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { |
| 90 platform_window_->SetBounds(gfx::Rect(size)); | 83 platform_window_->SetBounds(gfx::Rect(size)); |
| 91 } | 84 } |
| 92 | 85 |
| 93 void PlatformDisplayDefault::SetTitle(const base::string16& title) { | 86 void PlatformDisplayDefault::SetTitle(const base::string16& title) { |
| 94 platform_window_->SetTitle(title); | 87 platform_window_->SetTitle(title); |
| 95 } | 88 } |
| 96 | 89 |
| 97 void PlatformDisplayDefault::SetCapture() { | 90 void PlatformDisplayDefault::SetCapture() { |
| 98 platform_window_->SetCapture(); | 91 platform_window_->SetCapture(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 121 if (ime) | 114 if (ime) |
| 122 ime->UpdateTextInputState(state); | 115 ime->UpdateTextInputState(state); |
| 123 } | 116 } |
| 124 | 117 |
| 125 void PlatformDisplayDefault::SetImeVisibility(bool visible) { | 118 void PlatformDisplayDefault::SetImeVisibility(bool visible) { |
| 126 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 119 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 127 if (ime) | 120 if (ime) |
| 128 ime->SetImeVisibility(visible); | 121 ime->SetImeVisibility(visible); |
| 129 } | 122 } |
| 130 | 123 |
| 131 gfx::Rect PlatformDisplayDefault::GetBounds() const { | |
| 132 return metrics_.bounds; | |
| 133 } | |
| 134 | |
| 135 FrameGenerator* PlatformDisplayDefault::GetFrameGenerator() { | 124 FrameGenerator* PlatformDisplayDefault::GetFrameGenerator() { |
| 136 return frame_generator_.get(); | 125 return frame_generator_.get(); |
| 137 } | 126 } |
| 138 | 127 |
| 139 bool PlatformDisplayDefault::UpdateViewportMetrics( | 128 bool PlatformDisplayDefault::UpdateViewportMetrics( |
| 140 const display::ViewportMetrics& metrics) { | 129 const display::ViewportMetrics& metrics) { |
| 141 if (metrics_ == metrics) | 130 if (metrics_ == metrics) |
| 142 return false; | 131 return false; |
| 143 | 132 |
| 144 gfx::Rect bounds = platform_window_->GetBounds(); | 133 gfx::Rect bounds = platform_window_->GetBounds(); |
| 145 if (bounds.size() != metrics.pixel_size) { | 134 if (bounds.size() != metrics.bounds_in_pixels.size()) { |
| 146 bounds.set_size(metrics.pixel_size); | 135 bounds.set_size(metrics.bounds_in_pixels.size()); |
| 147 platform_window_->SetBounds(bounds); | 136 platform_window_->SetBounds(bounds); |
| 148 } | 137 } |
| 149 | 138 |
| 150 metrics_ = metrics; | 139 metrics_ = metrics; |
| 151 if (frame_generator_) | 140 if (frame_generator_) |
| 152 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | 141 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); |
| 153 return true; | 142 return true; |
| 154 } | 143 } |
| 155 | 144 |
| 156 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() | |
| 157 const { | |
| 158 return metrics_; | |
| 159 } | |
| 160 | |
| 161 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { | 145 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { |
| 162 return widget_; | 146 return widget_; |
| 163 } | 147 } |
| 164 | 148 |
| 165 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { | 149 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| 150 // TODO(riajiang): This is broken for HDPI because it mixes PPs and DIPs. See |
| 151 // http://crbug.com/701036 for details. |
| 152 const display::Display& display = delegate_->GetDisplay(); |
| 166 gfx::Point location = event->location(); | 153 gfx::Point location = event->location(); |
| 167 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 154 location.Offset(display.bounds().x(), display.bounds().y()); |
| 168 event->set_root_location(location); | 155 event->set_root_location(location); |
| 169 } | 156 } |
| 170 | 157 |
| 171 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { | 158 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 172 // We only care if the window size has changed. | 159 // We only care if the window size has changed. |
| 173 if (new_bounds.size() == metrics_.pixel_size) | 160 if (new_bounds.size() == metrics_.bounds_in_pixels.size()) |
| 174 return; | 161 return; |
| 175 | 162 |
| 176 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support | 163 // TODO(tonikitoo): Handle the bounds changing in external window mode. The |
| 177 // PlatformWindow initiated resizes. For other platforms we need to do | 164 // window should be resized by the WS and it shouldn't involve ScreenManager. |
| 178 // something but that isn't fully flushed out. | |
| 179 } | 165 } |
| 180 | 166 |
| 181 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { | 167 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { |
| 182 if (frame_generator_) | 168 if (frame_generator_) |
| 183 frame_generator_->OnWindowDamaged(); | 169 frame_generator_->OnWindowDamaged(); |
| 184 } | 170 } |
| 185 | 171 |
| 186 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 172 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
| 187 if (event->IsLocatedEvent()) | 173 if (event->IsLocatedEvent()) |
| 188 UpdateEventRootLocation(event->AsLocatedEvent()); | 174 UpdateEventRootLocation(event->AsLocatedEvent()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // with an accelerator to a character event can change the character, for | 207 // with an accelerator to a character event can change the character, for |
| 222 // example, from 'M' to '^M'. | 208 // example, from 'M' to '^M'. |
| 223 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 209 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 224 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 210 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 225 delegate_->OnEvent(char_event); | 211 delegate_->OnEvent(char_event); |
| 226 } | 212 } |
| 227 #endif | 213 #endif |
| 228 } | 214 } |
| 229 | 215 |
| 230 void PlatformDisplayDefault::OnCloseRequest() { | 216 void PlatformDisplayDefault::OnCloseRequest() { |
| 231 display::ScreenManager::GetInstance()->RequestCloseDisplay(GetId()); | 217 // TODO(tonikitoo): Handle a close request in external window mode. The window |
| 218 // should be closed by the WS and it shouldn't involve ScreenManager. |
| 219 const int64_t display_id = delegate_->GetDisplay().id(); |
| 220 display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id); |
| 232 } | 221 } |
| 233 | 222 |
| 234 void PlatformDisplayDefault::OnClosed() {} | 223 void PlatformDisplayDefault::OnClosed() {} |
| 235 | 224 |
| 236 void PlatformDisplayDefault::OnWindowStateChanged( | 225 void PlatformDisplayDefault::OnWindowStateChanged( |
| 237 ui::PlatformWindowState new_state) {} | 226 ui::PlatformWindowState new_state) {} |
| 238 | 227 |
| 239 void PlatformDisplayDefault::OnLostCapture() { | 228 void PlatformDisplayDefault::OnLostCapture() { |
| 240 delegate_->OnNativeCaptureLost(); | 229 delegate_->OnNativeCaptureLost(); |
| 241 } | 230 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 266 } |
| 278 | 267 |
| 279 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 268 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 280 | 269 |
| 281 bool PlatformDisplayDefault::IsInHighContrastMode() { | 270 bool PlatformDisplayDefault::IsInHighContrastMode() { |
| 282 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 271 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 283 } | 272 } |
| 284 | 273 |
| 285 } // namespace ws | 274 } // namespace ws |
| 286 } // namespace ui | 275 } // namespace ui |
| OLD | NEW |