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 | |
93 } // namespace | 84 } // namespace |
94 | 85 |
95 // static | 86 // static |
96 DisplayManagerFactory* DisplayManager::factory_ = nullptr; | 87 DisplayManagerFactory* DisplayManager::factory_ = nullptr; |
97 | 88 |
98 // static | 89 // static |
99 DisplayManager* DisplayManager::Create( | 90 DisplayManager* DisplayManager::Create( |
100 bool is_headless, | 91 bool is_headless, |
101 mojo::ApplicationImpl* app_impl, | 92 mojo::ApplicationImpl* app_impl, |
102 const scoped_refptr<GpuState>& gpu_state, | 93 const scoped_refptr<GpuState>& gpu_state, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 250 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
260 } | 251 } |
261 | 252 |
262 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 253 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
263 dirty_rect_.Union(damaged_region); | 254 dirty_rect_.Union(damaged_region); |
264 WantToDraw(); | 255 WantToDraw(); |
265 } | 256 } |
266 | 257 |
267 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 258 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
268 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 259 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 } | |
279 delegate_->OnEvent(mojo_event.Pass()); | 260 delegate_->OnEvent(mojo_event.Pass()); |
280 | 261 |
281 switch (event->type()) { | 262 switch (event->type()) { |
282 case ui::ET_MOUSE_PRESSED: | 263 case ui::ET_MOUSE_PRESSED: |
283 case ui::ET_TOUCH_PRESSED: | 264 case ui::ET_TOUCH_PRESSED: |
284 platform_window_->SetCapture(); | 265 platform_window_->SetCapture(); |
285 break; | 266 break; |
286 case ui::ET_MOUSE_RELEASED: | 267 case ui::ET_MOUSE_RELEASED: |
287 case ui::ET_TOUCH_RELEASED: | 268 case ui::ET_TOUCH_RELEASED: |
288 platform_window_->ReleaseCapture(); | 269 platform_window_->ReleaseCapture(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (widget != gfx::kNullAcceleratedWidget) { | 323 if (widget != gfx::kNullAcceleratedWidget) { |
343 top_level_display_client_.reset( | 324 top_level_display_client_.reset( |
344 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); | 325 new TopLevelDisplayClient(widget, gpu_state_, surfaces_state_)); |
345 } | 326 } |
346 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 327 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
347 } | 328 } |
348 | 329 |
349 void DefaultDisplayManager::OnActivationChanged(bool active) {} | 330 void DefaultDisplayManager::OnActivationChanged(bool active) {} |
350 | 331 |
351 } // namespace mus | 332 } // namespace mus |
OLD | NEW |