Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: components/view_manager/display_manager.cc

Issue 1313353010: Overhaul Mandoline event transport code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 0 /* sorting-context_id */); 80 0 /* sorting-context_id */);
81 81
82 auto surface_quad = 82 auto surface_quad =
83 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 83 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
84 surface_quad->SetNew(sqs, 84 surface_quad->SetNew(sqs,
85 bounds_at_origin /* rect */, 85 bounds_at_origin /* rect */,
86 bounds_at_origin /* visible_rect */, 86 bounds_at_origin /* visible_rect */,
87 view->surface_id()); 87 view->surface_id());
88 } 88 }
89 89
90 float ConvertUIWheelValueToMojoValue(int offset) {
91 // Mojo's event type takes a value between -1 and 1. Normalize by allowing
92 // up to 20 of ui's offset. This is a bit arbitrary.
93 return std::max(
94 -1.0f, std::min(1.0f, static_cast<float>(offset) /
95 (20 * static_cast<float>(
96 ui::MouseWheelEvent::kWheelDelta))));
97 }
98
99 } // namespace 90 } // namespace
100 91
101 // static 92 // static
102 DisplayManagerFactory* DisplayManager::factory_ = nullptr; 93 DisplayManagerFactory* DisplayManager::factory_ = nullptr;
103 94
104 // static 95 // static
105 DisplayManager* DisplayManager::Create( 96 DisplayManager* DisplayManager::Create(
106 bool is_headless, 97 bool is_headless,
107 mojo::ApplicationImpl* app_impl, 98 mojo::ApplicationImpl* app_impl,
108 const scoped_refptr<gles2::GpuState>& gpu_state, 99 const scoped_refptr<gles2::GpuState>& gpu_state,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 243
253 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) { 244 void DefaultDisplayManager::OnBoundsChanged(const gfx::Rect& new_bounds) {
254 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); 245 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio);
255 } 246 }
256 247
257 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) { 248 void DefaultDisplayManager::OnDamageRect(const gfx::Rect& damaged_region) {
258 } 249 }
259 250
260 void DefaultDisplayManager::DispatchEvent(ui::Event* event) { 251 void DefaultDisplayManager::DispatchEvent(ui::Event* event) {
261 mojo::EventPtr mojo_event(mojo::Event::From(*event)); 252 mojo::EventPtr mojo_event(mojo::Event::From(*event));
262 if (event->IsMouseWheelEvent()) { 253
263 // Mojo's event type has a different meaning for wheel events. Convert
264 // between the two.
265 ui::MouseWheelEvent* wheel_event =
266 static_cast<ui::MouseWheelEvent*>(event);
267 DCHECK(mojo_event->pointer_data);
268 mojo_event->pointer_data->horizontal_wheel =
269 ConvertUIWheelValueToMojoValue(wheel_event->x_offset());
270 mojo_event->pointer_data->horizontal_wheel =
271 ConvertUIWheelValueToMojoValue(wheel_event->y_offset());
272 }
273 delegate_->OnEvent(mojo_event.Pass()); 254 delegate_->OnEvent(mojo_event.Pass());
274 255
275 switch (event->type()) { 256 switch (event->type()) {
276 case ui::ET_MOUSE_PRESSED: 257 case ui::ET_MOUSE_PRESSED:
277 case ui::ET_TOUCH_PRESSED: 258 case ui::ET_TOUCH_PRESSED:
278 platform_window_->SetCapture(); 259 platform_window_->SetCapture();
279 break; 260 break;
280 case ui::ET_MOUSE_RELEASED: 261 case ui::ET_MOUSE_RELEASED:
281 case ui::ET_TOUCH_RELEASED: 262 case ui::ET_TOUCH_RELEASED:
282 platform_window_->ReleaseCapture(); 263 platform_window_->ReleaseCapture();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient( 322 top_level_display_client_.reset(new surfaces::TopLevelDisplayClient(
342 widget, gpu_state_, surfaces_state_)); 323 widget, gpu_state_, surfaces_state_));
343 } 324 }
344 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); 325 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio);
345 } 326 }
346 327
347 void DefaultDisplayManager::OnActivationChanged(bool active) { 328 void DefaultDisplayManager::OnActivationChanged(bool active) {
348 } 329 }
349 330
350 } // namespace view_manager 331 } // namespace view_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698