Chromium Code Reviews| Index: services/ui/ws/platform_display.cc |
| diff --git a/services/ui/ws/platform_display.cc b/services/ui/ws/platform_display.cc |
| index bb9c47774b6b6154f4a39c01b7a6321a5e6c2de8..2d43595a7258e417a8746c0dbfb9222336ad605f 100644 |
| --- a/services/ui/ws/platform_display.cc |
| +++ b/services/ui/ws/platform_display.cc |
| @@ -55,12 +55,12 @@ PlatformDisplay* PlatformDisplay::Create( |
| DefaultPlatformDisplay::DefaultPlatformDisplay( |
| const PlatformDisplayInitParams& init_params) |
| : id_(init_params.display_id), |
| + platform_screen_(init_params.platform_screen), |
| #if !defined(OS_ANDROID) |
| cursor_loader_(ui::CursorLoader::Create()), |
| #endif |
| frame_generator_(new FrameGenerator(this, init_params.surfaces_state)) { |
| metrics_.bounds = init_params.display_bounds; |
| - // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. |
| } |
| void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| @@ -168,23 +168,36 @@ gfx::Rect DefaultPlatformDisplay::GetBounds() const { |
| return metrics_.bounds; |
| } |
| +bool DefaultPlatformDisplay::IsPrimaryDisplay() const { |
| + return platform_screen_->GetPrimaryDisplayId() == GetId(); |
|
sky
2016/08/10 22:15:59
GetId() -> id_
kylechar
2016/08/11 15:00:37
Done.
|
| +} |
| + |
| void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, |
| float device_scale_factor) { |
| if (display::Display::HasForceDeviceScaleFactor()) |
| device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); |
| - if (metrics_.bounds == bounds && |
| + |
| + // We don't care about the origin of the platform window, as that may not be |
| + // related to the origin of the display in our screen space. |
| + if (metrics_.bounds.size() == bounds.size() && |
| metrics_.device_scale_factor == device_scale_factor) |
| return; |
| + // TODO(kylechar): If the window size is updated then we may need to update |
| + // the origin for any other windows. |
| ViewportMetrics old_metrics = metrics_; |
| - metrics_.bounds = bounds; |
| + metrics_.bounds.set_size(bounds.size()); |
| metrics_.device_scale_factor = device_scale_factor; |
| delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| } |
| +void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| + gfx::Point location = event->location(); |
| + location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
| + event->set_root_location(location); |
| +} |
| + |
| void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| - // TODO(kylechar): We should keep track of the actual top left of the window |
| - // and also the internal top left of the window (eg. first window is at 0,0). |
| UpdateMetrics(new_bounds, metrics_.device_scale_factor); |
| } |
| @@ -198,9 +211,13 @@ void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
| // they are once we have proper support for scroll events. |
| delegate_->OnEvent(ui::MouseWheelEvent(*event->AsScrollEvent())); |
| } else if (event->IsMouseEvent() && !event->IsMouseWheelEvent()) { |
| - delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); |
| + ui::PointerEvent pointer_event(*event->AsMouseEvent()); |
| + 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.
|
| + delegate_->OnEvent(pointer_event); |
| } else if (event->IsTouchEvent()) { |
| - delegate_->OnEvent(ui::PointerEvent(*event->AsTouchEvent())); |
| + ui::PointerEvent pointer_event(*event->AsTouchEvent()); |
| + UpdateEventRootLocation(&pointer_event); |
| + delegate_->OnEvent(pointer_event); |
| } else { |
| delegate_->OnEvent(*event); |
| } |