| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" | 5 #include "services/ui/ws/platform_display.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "cc/ipc/quads.mojom.h" | 9 #include "cc/ipc/quads.mojom.h" |
| 10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const PlatformDisplayInitParams& init_params) { | 48 const PlatformDisplayInitParams& init_params) { |
| 49 if (factory_) | 49 if (factory_) |
| 50 return factory_->CreatePlatformDisplay(); | 50 return factory_->CreatePlatformDisplay(); |
| 51 | 51 |
| 52 return new DefaultPlatformDisplay(init_params); | 52 return new DefaultPlatformDisplay(init_params); |
| 53 } | 53 } |
| 54 | 54 |
| 55 DefaultPlatformDisplay::DefaultPlatformDisplay( | 55 DefaultPlatformDisplay::DefaultPlatformDisplay( |
| 56 const PlatformDisplayInitParams& init_params) | 56 const PlatformDisplayInitParams& init_params) |
| 57 : id_(init_params.display_id), | 57 : id_(init_params.display_id), |
| 58 platform_screen_(init_params.platform_screen), |
| 58 #if !defined(OS_ANDROID) | 59 #if !defined(OS_ANDROID) |
| 59 cursor_loader_(ui::CursorLoader::Create()), | 60 cursor_loader_(ui::CursorLoader::Create()), |
| 60 #endif | 61 #endif |
| 61 frame_generator_(new FrameGenerator(this, init_params.surfaces_state)) { | 62 frame_generator_(new FrameGenerator(this, init_params.surfaces_state)) { |
| 62 metrics_.bounds = init_params.display_bounds; | 63 metrics_.bounds = init_params.display_bounds; |
| 63 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. | |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 66 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| 67 delegate_ = delegate; | 67 delegate_ = delegate; |
| 68 | 68 |
| 69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
| 70 platform_window_.reset(new ui::WinWindow(this, metrics_.bounds)); | 70 platform_window_.reset(new ui::WinWindow(this, metrics_.bounds)); |
| 71 #elif defined(USE_X11) | 71 #elif defined(USE_X11) |
| 72 platform_window_.reset(new ui::X11Window(this)); | 72 platform_window_.reset(new ui::X11Window(this)); |
| 73 #elif defined(OS_ANDROID) | 73 #elif defined(OS_ANDROID) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool DefaultPlatformDisplay::IsFramePending() const { | 163 bool DefaultPlatformDisplay::IsFramePending() const { |
| 164 return frame_generator_->is_frame_pending(); | 164 return frame_generator_->is_frame_pending(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 gfx::Rect DefaultPlatformDisplay::GetBounds() const { | 167 gfx::Rect DefaultPlatformDisplay::GetBounds() const { |
| 168 return metrics_.bounds; | 168 return metrics_.bounds; |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { |
| 172 return platform_screen_->GetPrimaryDisplayId() == id_; |
| 173 } |
| 174 |
| 171 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, | 175 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, |
| 172 float device_scale_factor) { | 176 float device_scale_factor) { |
| 173 if (display::Display::HasForceDeviceScaleFactor()) | 177 if (display::Display::HasForceDeviceScaleFactor()) |
| 174 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); | 178 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); |
| 175 if (metrics_.bounds == bounds && | 179 |
| 180 // We don't care about the origin of the platform window, as that may not be |
| 181 // related to the origin of the display in our screen space. |
| 182 if (metrics_.bounds.size() == bounds.size() && |
| 176 metrics_.device_scale_factor == device_scale_factor) | 183 metrics_.device_scale_factor == device_scale_factor) |
| 177 return; | 184 return; |
| 178 | 185 |
| 186 // TODO(kylechar): If the window size is updated then we may need to update |
| 187 // the origin for any other windows. |
| 179 ViewportMetrics old_metrics = metrics_; | 188 ViewportMetrics old_metrics = metrics_; |
| 180 metrics_.bounds = bounds; | 189 metrics_.bounds.set_size(bounds.size()); |
| 181 metrics_.device_scale_factor = device_scale_factor; | 190 metrics_.device_scale_factor = device_scale_factor; |
| 182 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 191 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 183 } | 192 } |
| 184 | 193 |
| 194 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| 195 gfx::Point location = event->location(); |
| 196 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
| 197 event->set_root_location(location); |
| 198 } |
| 199 |
| 185 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 200 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 186 // TODO(kylechar): We should keep track of the actual top left of the window | |
| 187 // and also the internal top left of the window (eg. first window is at 0,0). | |
| 188 UpdateMetrics(new_bounds, metrics_.device_scale_factor); | 201 UpdateMetrics(new_bounds, metrics_.device_scale_factor); |
| 189 } | 202 } |
| 190 | 203 |
| 191 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 204 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
| 192 frame_generator_->RequestRedraw(damaged_region); | 205 frame_generator_->RequestRedraw(damaged_region); |
| 193 } | 206 } |
| 194 | 207 |
| 195 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 208 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
| 209 if (event->IsLocatedEvent()) |
| 210 UpdateEventRootLocation(event->AsLocatedEvent()); |
| 211 |
| 196 if (event->IsScrollEvent()) { | 212 if (event->IsScrollEvent()) { |
| 197 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 213 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| 198 // they are once we have proper support for scroll events. | 214 // they are once we have proper support for scroll events. |
| 199 delegate_->OnEvent(ui::MouseWheelEvent(*event->AsScrollEvent())); | 215 delegate_->OnEvent(ui::MouseWheelEvent(*event->AsScrollEvent())); |
| 200 } else if (event->IsMouseEvent() && !event->IsMouseWheelEvent()) { | 216 } else if (event->IsMouseEvent() && !event->IsMouseWheelEvent()) { |
| 201 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); | 217 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); |
| 202 } else if (event->IsTouchEvent()) { | 218 } else if (event->IsTouchEvent()) { |
| 203 delegate_->OnEvent(ui::PointerEvent(*event->AsTouchEvent())); | 219 delegate_->OnEvent(ui::PointerEvent(*event->AsTouchEvent())); |
| 204 } else { | 220 } else { |
| 205 delegate_->OnEvent(*event); | 221 delegate_->OnEvent(*event); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 295 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 280 } | 296 } |
| 281 | 297 |
| 282 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 298 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { |
| 283 return metrics_; | 299 return metrics_; |
| 284 } | 300 } |
| 285 | 301 |
| 286 } // namespace ws | 302 } // namespace ws |
| 287 | 303 |
| 288 } // namespace ui | 304 } // namespace ui |
| OLD | NEW |