Chromium Code Reviews| 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() == GetId(); | |
|
sky
2016/08/10 22:15:59
GetId() -> id_
kylechar
2016/08/11 15:00:37
Done.
| |
| 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) { |
| 196 if (event->IsScrollEvent()) { | 209 if (event->IsScrollEvent()) { |
| 197 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 210 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| 198 // they are once we have proper support for scroll events. | 211 // they are once we have proper support for scroll events. |
| 199 delegate_->OnEvent(ui::MouseWheelEvent(*event->AsScrollEvent())); | 212 delegate_->OnEvent(ui::MouseWheelEvent(*event->AsScrollEvent())); |
| 200 } else if (event->IsMouseEvent() && !event->IsMouseWheelEvent()) { | 213 } else if (event->IsMouseEvent() && !event->IsMouseWheelEvent()) { |
| 201 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); | 214 ui::PointerEvent pointer_event(*event->AsMouseEvent()); |
| 215 UpdateEventRootLocation(&pointer_event); | |
|
sky
2016/08/10 22:15:59
Can you update root location of event directly? (s
kylechar
2016/08/11 15:00:37
Good idea. Done.
| |
| 216 delegate_->OnEvent(pointer_event); | |
| 202 } else if (event->IsTouchEvent()) { | 217 } else if (event->IsTouchEvent()) { |
| 203 delegate_->OnEvent(ui::PointerEvent(*event->AsTouchEvent())); | 218 ui::PointerEvent pointer_event(*event->AsTouchEvent()); |
| 219 UpdateEventRootLocation(&pointer_event); | |
| 220 delegate_->OnEvent(pointer_event); | |
| 204 } else { | 221 } else { |
| 205 delegate_->OnEvent(*event); | 222 delegate_->OnEvent(*event); |
| 206 } | 223 } |
| 207 | 224 |
| 208 #if defined(USE_X11) || defined(USE_OZONE) | 225 #if defined(USE_X11) || defined(USE_OZONE) |
| 209 // We want to emulate the WM_CHAR generation behaviour of Windows. | 226 // We want to emulate the WM_CHAR generation behaviour of Windows. |
| 210 // | 227 // |
| 211 // On Linux, we've previously inserted characters by having | 228 // On Linux, we've previously inserted characters by having |
| 212 // InputMethodAuraLinux take all key down events and send a character event | 229 // InputMethodAuraLinux take all key down events and send a character event |
| 213 // to the TextInputClient. This causes a mismatch in code that has to be | 230 // to the TextInputClient. This causes a mismatch in code that has to be |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 296 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 280 } | 297 } |
| 281 | 298 |
| 282 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 299 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { |
| 283 return metrics_; | 300 return metrics_; |
| 284 } | 301 } |
| 285 | 302 |
| 286 } // namespace ws | 303 } // namespace ws |
| 287 | 304 |
| 288 } // namespace ui | 305 } // namespace ui |
| OLD | NEW |