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/view_manager/display_manager.h" | 5 #include "components/view_manager/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 0 /* sorting-context_id */); | 81 0 /* sorting-context_id */); |
82 | 82 |
83 auto surface_quad = | 83 auto surface_quad = |
84 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 84 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
85 surface_quad->SetNew(sqs, | 85 surface_quad->SetNew(sqs, |
86 bounds_at_origin /* rect */, | 86 bounds_at_origin /* rect */, |
87 bounds_at_origin /* visible_rect */, | 87 bounds_at_origin /* visible_rect */, |
88 view->surface_id()); | 88 view->surface_id()); |
89 } | 89 } |
90 | 90 |
91 float ConvertUIWheelValueToMojoValue(int offset) { | |
92 // Mojo's event type takes a value between -1 and 1. Normalize by allowing | |
93 // up to 20 of ui's offset. This is a bit arbitrary. | |
94 return std::max( | |
95 -1.0f, std::min(1.0f, static_cast<float>(offset) / | |
96 (20 * static_cast<float>( | |
97 ui::MouseWheelEvent::kWheelDelta)))); | |
98 } | |
99 | |
100 } // namespace | 91 } // namespace |
101 | 92 |
102 // static | 93 // static |
103 DisplayManagerFactory* DisplayManager::factory_ = nullptr; | 94 DisplayManagerFactory* DisplayManager::factory_ = nullptr; |
104 | 95 |
105 // static | 96 // static |
106 DisplayManager* DisplayManager::Create( | 97 DisplayManager* DisplayManager::Create( |
107 bool is_headless, | 98 bool is_headless, |
108 mojo::ApplicationImpl* app_impl, | 99 mojo::ApplicationImpl* app_impl, |
109 const scoped_refptr<gles2::GpuState>& gpu_state, | 100 const scoped_refptr<gles2::GpuState>& gpu_state, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 259 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); |
269 } | 260 } |
270 | 261 |
271 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { | 262 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { |
272 dirty_rect_.Union(damaged_region); | 263 dirty_rect_.Union(damaged_region); |
273 WantToDraw(); | 264 WantToDraw(); |
274 } | 265 } |
275 | 266 |
276 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { | 267 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { |
277 mojo::EventPtr mojo_event(mojo::Event::From(*event)); | 268 mojo::EventPtr mojo_event(mojo::Event::From(*event)); |
278 if (event->IsMouseWheelEvent()) { | 269 |
279 // Mojo's event type has a different meaning for wheel events. Convert | |
280 // between the two. | |
281 ui::MouseWheelEvent* wheel_event = | |
282 static_cast<ui::MouseWheelEvent*>(event); | |
283 DCHECK(mojo_event->pointer_data); | |
284 mojo_event->pointer_data->horizontal_wheel = | |
285 ConvertUIWheelValueToMojoValue(wheel_event->x_offset()); | |
286 mojo_event->pointer_data->horizontal_wheel = | |
287 ConvertUIWheelValueToMojoValue(wheel_event->y_offset()); | |
288 } | |
289 delegate_->OnEvent(mojo_event.Pass()); | 270 delegate_->OnEvent(mojo_event.Pass()); |
290 | 271 |
291 switch (event->type()) { | 272 switch (event->type()) { |
292 case ui::ET_MOUSE_PRESSED: | 273 case ui::ET_MOUSE_PRESSED: |
293 case ui::ET_TOUCH_PRESSED: | 274 case ui::ET_TOUCH_PRESSED: |
294 platform_window_->SetCapture(); | 275 platform_window_->SetCapture(); |
295 break; | 276 break; |
296 case ui::ET_MOUSE_RELEASED: | 277 case ui::ET_MOUSE_RELEASED: |
297 case ui::ET_TOUCH_RELEASED: | 278 case ui::ET_TOUCH_RELEASED: |
298 platform_window_->ReleaseCapture(); | 279 platform_window_->ReleaseCapture(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( | 338 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( |
358 widget, gpu_state_, surfaces_state_)); | 339 widget, gpu_state_, surfaces_state_)); |
359 } | 340 } |
360 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 341 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); |
361 } | 342 } |
362 | 343 |
363 void DefaultDisplayManager::OnActivationChanged(bool active) { | 344 void DefaultDisplayManager::OnActivationChanged(bool active) { |
364 } | 345 } |
365 | 346 |
366 } // namespace view_manager | 347 } // namespace view_manager |
OLD | NEW |