| 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 "components/mus/display_manager.h" | 5 #include "components/mus/display_manager.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/delegated_frame_data.h" | 9 #include "cc/output/delegated_frame_data.h" |
| 10 #include "cc/quads/render_pass.h" | 10 #include "cc/quads/render_pass.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | 74 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
| 75 bounds_at_origin /* visible_layer_bounds */, | 75 bounds_at_origin /* visible_layer_bounds */, |
| 76 bounds_at_origin /* clip_rect */, false /* is_clipped */, view->opacity(), | 76 bounds_at_origin /* clip_rect */, false /* is_clipped */, view->opacity(), |
| 77 SkXfermode::kSrc_Mode, 0 /* sorting-context_id */); | 77 SkXfermode::kSrc_Mode, 0 /* sorting-context_id */); |
| 78 | 78 |
| 79 auto surface_quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 79 auto surface_quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 80 surface_quad->SetNew(sqs, bounds_at_origin /* rect */, | 80 surface_quad->SetNew(sqs, bounds_at_origin /* rect */, |
| 81 bounds_at_origin /* visible_rect */, view->surface_id()); | 81 bounds_at_origin /* visible_rect */, view->surface_id()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 float ConvertUIWheelValueToMojoValue(int offset) { |
| 85 // Mojo's event type takes a value between -1 and 1. Normalize by allowing |
| 86 // up to 20 of ui's offset. This is a bit arbitrary. |
| 87 return std::max( |
| 88 -1.0f, std::min(1.0f, static_cast<float>(offset) / |
| 89 (20 * static_cast<float>( |
| 90 ui::MouseWheelEvent::kWheelDelta)))); |
| 91 } |
| 92 |
| 84 } // namespace | 93 } // namespace |
| 85 | 94 |
| 86 // static | 95 // static |
| 87 DisplayManagerFactory* DisplayManager::factory_ = nullptr; | 96 DisplayManagerFactory* DisplayManager::factory_ = nullptr; |
| 88 | 97 |
| 89 // static | 98 // static |
| 90 DisplayManager* DisplayManager::Create( | 99 DisplayManager* DisplayManager::Create( |
| 91 bool is_headless, | 100 bool is_headless, |
| 92 mojo::ApplicationImpl* app_impl, | 101 mojo::ApplicationImpl* app_impl, |
| 93 const scoped_refptr<gles2::GpuState>& gpu_state, | 102 const scoped_refptr<gles2::GpuState>& gpu_state, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 259 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
| 251 } | 260 } |
| 252 | 261 |
| 253 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 262 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
| 254 dirty_rect_.Union(damaged_region); | 263 dirty_rect_.Union(damaged_region); |
| 255 WantToDraw(); | 264 WantToDraw(); |
| 256 } | 265 } |
| 257 | 266 |
| 258 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 267 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
| 259 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 268 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
| 269 if (event->IsMouseWheelEvent()) { |
| 270 // Mojo's event type has a different meaning for wheel events. Convert |
| 271 // between the two. |
| 272 ui::MouseWheelEvent* wheel_event = static_cast<ui::MouseWheelEvent*>(event); |
| 273 DCHECK(mojo_event->pointer_data); |
| 274 mojo_event->pointer_data->horizontal_wheel = |
| 275 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); |
| 276 mojo_event->pointer_data->horizontal_wheel = |
| 277 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); |
| 278 } |
| 260 delegate_->OnEvent(mojo_event.Pass()); | 279 delegate_->OnEvent(mojo_event.Pass()); |
| 261 | 280 |
| 262 switch (event->type()) { | 281 switch (event->type()) { |
| 263 case ui::ET_MOUSE_PRESSED: | 282 case ui::ET_MOUSE_PRESSED: |
| 264 case ui::ET_TOUCH_PRESSED: | 283 case ui::ET_TOUCH_PRESSED: |
| 265 platform_window_->SetCapture(); | 284 platform_window_->SetCapture(); |
| 266 break; | 285 break; |
| 267 case ui::ET_MOUSE_RELEASED: | 286 case ui::ET_MOUSE_RELEASED: |
| 268 case ui::ET_TOUCH_RELEASED: | 287 case ui::ET_TOUCH_RELEASED: |
| 269 platform_window_->ReleaseCapture(); | 288 platform_window_->ReleaseCapture(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (widget != gfx::kNullAcceleratedWidget) { | 343 if (widget != gfx::kNullAcceleratedWidget) { |
| 325 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( | 344 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( |
| 326 widget, gpu_state_, surfaces_state_)); | 345 widget, gpu_state_, surfaces_state_)); |
| 327 } | 346 } |
| 328 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 347 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
| 329 } | 348 } |
| 330 | 349 |
| 331 void DefaultDisplayManager::OnActivationChanged(bool active) {} | 350 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
| 332 | 351 |
| 333 } // namespace view_manager | 352 } // namespace view_manager |
| OLD | NEW |