| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // that chrome would use, not custom image cursors. For that, we should | 139 // that chrome would use, not custom image cursors. For that, we should |
| 140 // delegate to the window manager to load images from resource packs. | 140 // delegate to the window manager to load images from resource packs. |
| 141 // | 141 // |
| 142 // We probably also need to deal with different DPIs. | 142 // We probably also need to deal with different DPIs. |
| 143 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); | 143 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); |
| 144 cursor_loader_->SetPlatformCursor(&cursor); | 144 cursor_loader_->SetPlatformCursor(&cursor); |
| 145 platform_window_->SetCursor(cursor.platform()); | 145 platform_window_->SetCursor(cursor.platform()); |
| 146 #endif | 146 #endif |
| 147 } | 147 } |
| 148 | 148 |
| 149 float DefaultPlatformDisplay::GetDeviceScaleFactor() { | |
| 150 return metrics_.device_scale_factor; | |
| 151 } | |
| 152 | |
| 153 display::Display::Rotation DefaultPlatformDisplay::GetRotation() { | |
| 154 // TODO(sky): implement me. | |
| 155 return display::Display::ROTATE_0; | |
| 156 } | |
| 157 | |
| 158 void DefaultPlatformDisplay::UpdateTextInputState( | 149 void DefaultPlatformDisplay::UpdateTextInputState( |
| 159 const ui::TextInputState& state) { | 150 const ui::TextInputState& state) { |
| 160 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 151 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 161 if (ime) | 152 if (ime) |
| 162 ime->UpdateTextInputState(state); | 153 ime->UpdateTextInputState(state); |
| 163 } | 154 } |
| 164 | 155 |
| 165 void DefaultPlatformDisplay::SetImeVisibility(bool visible) { | 156 void DefaultPlatformDisplay::SetImeVisibility(bool visible) { |
| 166 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 157 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 167 if (ime) | 158 if (ime) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 178 | 169 |
| 179 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { | 170 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { |
| 180 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; | 171 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; |
| 181 } | 172 } |
| 182 | 173 |
| 183 void DefaultPlatformDisplay::OnGpuChannelEstablished( | 174 void DefaultPlatformDisplay::OnGpuChannelEstablished( |
| 184 scoped_refptr<gpu::GpuChannelHost> channel) { | 175 scoped_refptr<gpu::GpuChannelHost> channel) { |
| 185 frame_generator_->OnGpuChannelEstablished(channel); | 176 frame_generator_->OnGpuChannelEstablished(channel); |
| 186 } | 177 } |
| 187 | 178 |
| 188 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, | 179 bool DefaultPlatformDisplay::UpdateViewportMetrics( |
| 189 const gfx::Size& pixel_size, | 180 const display::ViewportMetrics& metrics) { |
| 190 float device_scale_factor) { | 181 if (metrics_ == metrics) |
| 191 // We don't care about the origin of the platform window, as that may not be | 182 return false; |
| 192 // related to the origin of the display in our screen space. | |
| 193 if (metrics_.bounds == bounds && metrics_.pixel_size == pixel_size && | |
| 194 metrics_.device_scale_factor == device_scale_factor) | |
| 195 return; | |
| 196 | 183 |
| 197 ViewportMetrics old_metrics = metrics_; | 184 gfx::Rect bounds = platform_window_->GetBounds(); |
| 198 metrics_.bounds = bounds; | 185 if (bounds.size() != metrics.pixel_size) { |
| 199 metrics_.pixel_size = pixel_size; | 186 bounds.set_size(metrics.pixel_size); |
| 200 metrics_.device_scale_factor = device_scale_factor; | 187 platform_window_->SetBounds(bounds); |
| 201 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 188 } |
| 189 |
| 190 metrics_ = metrics; |
| 191 return true; |
| 192 } |
| 193 |
| 194 const display::ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() |
| 195 const { |
| 196 return metrics_; |
| 202 } | 197 } |
| 203 | 198 |
| 204 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { | 199 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| 205 gfx::Point location = event->location(); | 200 gfx::Point location = event->location(); |
| 206 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 201 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
| 207 event->set_root_location(location); | 202 event->set_root_location(location); |
| 208 } | 203 } |
| 209 | 204 |
| 210 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 205 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 211 // TODO(kylechar): We're updating the bounds assuming that the device scale | 206 // We only care if the window size has changed. |
| 212 // factor is 1 here. The correct thing to do is let PlatformSreen know the | 207 if (new_bounds.size() == metrics_.pixel_size) |
| 213 // display size has changed and let it update the display. | 208 return; |
| 214 gfx::Size pixel_size = new_bounds.size(); | 209 |
| 215 gfx::Rect bounds = gfx::Rect(metrics_.bounds.origin(), pixel_size); | 210 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support |
| 216 UpdateMetrics(bounds, pixel_size, metrics_.device_scale_factor); | 211 // PlatformWindow initiated resizes. For other platforms we need to do |
| 212 // something but that isn't fully flushed out. |
| 217 } | 213 } |
| 218 | 214 |
| 219 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 215 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
| 220 frame_generator_->RequestRedraw(damaged_region); | 216 frame_generator_->RequestRedraw(damaged_region); |
| 221 } | 217 } |
| 222 | 218 |
| 223 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 219 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
| 224 if (event->IsLocatedEvent()) | 220 if (event->IsLocatedEvent()) |
| 225 UpdateEventRootLocation(event->AsLocatedEvent()); | 221 UpdateEventRootLocation(event->AsLocatedEvent()); |
| 226 | 222 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 291 } |
| 296 | 292 |
| 297 ServerWindow* DefaultPlatformDisplay::GetRootWindow() { | 293 ServerWindow* DefaultPlatformDisplay::GetRootWindow() { |
| 298 return delegate_->GetRootWindow(); | 294 return delegate_->GetRootWindow(); |
| 299 } | 295 } |
| 300 | 296 |
| 301 bool DefaultPlatformDisplay::IsInHighContrastMode() { | 297 bool DefaultPlatformDisplay::IsInHighContrastMode() { |
| 302 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 298 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 303 } | 299 } |
| 304 | 300 |
| 305 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | |
| 306 return metrics_; | |
| 307 } | |
| 308 | |
| 309 } // namespace ws | 301 } // namespace ws |
| 310 | 302 |
| 311 } // namespace ui | 303 } // namespace ui |
| OLD | NEW |