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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2688813004: Enable scrolling of UI elements. (Closed)
Patch Set: Sent scroll events to latest scrolling target Created 3 years, 10 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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/android/vr_shell/vr_shell_gl.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 for (const auto& plane : scene_->GetUiElements()) { 502 for (const auto& plane : scene_->GetUiElements()) {
503 if (!plane->IsHitTestable()) 503 if (!plane->IsHitTestable())
504 continue; 504 continue;
505 505
506 float distance_to_plane = plane->GetRayDistance(kOrigin, eye_to_target); 506 float distance_to_plane = plane->GetRayDistance(kOrigin, eye_to_target);
507 gvr::Vec3f plane_intersection_point = 507 gvr::Vec3f plane_intersection_point =
508 GetRayPoint(kOrigin, eye_to_target, distance_to_plane); 508 GetRayPoint(kOrigin, eye_to_target, distance_to_plane);
509 509
510 gvr::Vec3f rect_2d_point = 510 gvr::Vec3f rect_2d_point =
511 MatrixVectorMul(plane->transform.from_world, plane_intersection_point); 511 MatrixVectorMul(plane->transform.from_world, plane_intersection_point);
512 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) { 512 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) {
cjgrant 2017/02/14 14:08:25 Unrelated rework: Can you invert this logic, do a
tiborg 2017/02/14 21:44:23 Done.
513 float x = rect_2d_point.x + 0.5f; 513 float x = rect_2d_point.x + 0.5f;
514 float y = 0.5f - rect_2d_point.y; 514 float y = 0.5f - rect_2d_point.y;
515 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; 515 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
516 if (!is_inside) 516 if (!is_inside)
517 continue; 517 continue;
518 518
519 closest_element_distance = distance_to_plane; 519 closest_element_distance = distance_to_plane;
520 Rectf pixel_rect; 520 Rectf pixel_rect;
521 if (plane->fill == Fill::CONTENT) { 521 if (plane->fill == Fill::CONTENT) {
522 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_}; 522 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_};
523 } else { 523 } else {
524 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y, 524 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y,
525 plane->copy_rect.width, plane->copy_rect.height}; 525 plane->copy_rect.width, plane->copy_rect.height};
526 } 526 }
527 pixel_x = pixel_rect.width * x + pixel_rect.x; 527 pixel_x = pixel_rect.width * x + pixel_rect.x;
528 pixel_y = pixel_rect.height * y + pixel_rect.y; 528 pixel_y = pixel_rect.height * y + pixel_rect.y;
529 529
530 target_point_ = plane_intersection_point; 530 target_point_ = plane_intersection_point;
531 target_element_ = plane.get(); 531 target_element_ = plane.get();
532 input_target = (plane->fill == Fill::CONTENT) ? InputTarget::CONTENT 532 // For now treat UI elements, which do not show web content, as NONE input
cjgrant 2017/02/14 14:08:25 General comment on comments: It's usually best to
tiborg 2017/02/14 21:44:23 Done.
533 : InputTarget::UI; 533 // targets since they cannot make use of the input anyway.
534 switch (plane->fill) {
cjgrant 2017/02/14 14:08:25 The loop is responsible for finding target_element
tiborg 2017/02/14 21:44:23 Done.
535 case Fill::CONTENT:
536 input_target = InputTarget::CONTENT;
537 break;
538 case Fill::SPRITE:
539 input_target = InputTarget::UI;
540 break;
541 default:
542 input_target = InputTarget::NONE;
543 break;
544 }
534 } 545 }
535 } 546 }
536 SendEventsToTarget(input_target, pixel_x, pixel_y); 547 SendEventsToTarget(input_target, pixel_x, pixel_y);
537 } 548 }
538 549
539 void VrShellGl::SendEventsToTarget(InputTarget input_target, 550 void VrShellGl::SendEventsToTarget(InputTarget input_target,
540 int pixel_x, 551 int pixel_x,
541 int pixel_y) { 552 int pixel_y) {
542 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list = 553 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list =
543 controller_->DetectGestures(); 554 controller_->DetectGestures();
544 double timestamp = gesture_list.front()->timeStampSeconds(); 555 double timestamp = gesture_list.front()->timeStampSeconds();
cjgrant 2017/02/14 14:08:25 Unrelated to this CL, but I'm curious: Do all gest
tiborg 2017/02/14 21:44:23 I'm not sure but there is a function ( https://cs.
545 556
546 if (touch_pending_) { 557 if (touch_pending_) {
547 touch_pending_ = false; 558 touch_pending_ = false;
548 std::unique_ptr<WebGestureEvent> event(new WebGestureEvent( 559 std::unique_ptr<WebGestureEvent> event(new WebGestureEvent(
549 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, timestamp)); 560 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, timestamp));
550 event->sourceDevice = blink::WebGestureDeviceTouchpad; 561 event->sourceDevice = blink::WebGestureDeviceTouchpad;
551 event->x = pixel_x; 562 event->x = pixel_x;
552 event->y = pixel_y; 563 event->y = pixel_y;
553 gesture_list.push_back(std::move(event)); 564 gesture_list.push_back(std::move(event));
554 } 565 }
555 566
556 for (const auto& gesture : gesture_list) { 567 for (const auto& gesture : gesture_list) {
568 gesture->x = pixel_x;
cjgrant 2017/02/14 14:08:25 So here we change gesture, but a line above, gestu
tiborg 2017/02/14 21:44:23 I think the const is referring to the unique_ptr a
cjgrant 2017/02/14 22:37:41 Michael, thoughts on this? The const is misleadin
tiborg 2017/02/14 23:13:52 Ditched const.
569 gesture->y = pixel_y;
570 auto movableGesture = base::WrapUnique(new WebGestureEvent(*gesture));
cjgrant 2017/02/14 14:08:24 This should use MakeUnique() (ie. the new preferre
tiborg 2017/02/14 21:44:23 Done.
571
557 switch (gesture->type()) { 572 switch (gesture->type()) {
573 // Once the user starts scrolling sed all the scroll events to this
cjgrant 2017/02/14 14:08:24 /sed/send/
tiborg 2017/02/14 21:44:23 Done.
574 // element until the scrolling stops.
558 case WebInputEvent::GestureScrollBegin: 575 case WebInputEvent::GestureScrollBegin:
576 current_scroll_target = input_target;
577 if (current_scroll_target != InputTarget::NONE) {
578 SendGesture(current_scroll_target, std::move(movableGesture));
579 }
580 break;
581 case WebInputEvent::GestureScrollEnd:
582 if (current_scroll_target != InputTarget::NONE) {
583 SendGesture(current_scroll_target, std::move(movableGesture));
584 }
585 current_scroll_target = InputTarget::NONE;
586 break;
559 case WebInputEvent::GestureScrollUpdate: 587 case WebInputEvent::GestureScrollUpdate:
560 case WebInputEvent::GestureScrollEnd:
561 case WebInputEvent::GestureFlingCancel: 588 case WebInputEvent::GestureFlingCancel:
562 case WebInputEvent::GestureFlingStart: 589 case WebInputEvent::GestureFlingStart:
563 SendGesture(InputTarget::CONTENT, 590 if (current_scroll_target != InputTarget::NONE) {
564 base::WrapUnique(new WebGestureEvent(*gesture))); 591 SendGesture(current_scroll_target, std::move(movableGesture));
592 }
565 break; 593 break;
566 case WebInputEvent::GestureTapDown: 594 case WebInputEvent::GestureTapDown:
567 gesture->x = pixel_x; 595 if (input_target != InputTarget::NONE) {
568 gesture->y = pixel_y; 596 SendGesture(input_target, std::move(movableGesture));
569 if (input_target != InputTarget::NONE) 597 }
570 SendGesture(input_target,
571 base::WrapUnique(new WebGestureEvent(*gesture)));
572 break; 598 break;
573 case WebInputEvent::Undefined: 599 case WebInputEvent::Undefined:
574 break; 600 break;
575 default: 601 default:
576 NOTREACHED(); 602 NOTREACHED();
577 } 603 }
578 } 604 }
579 605
580 // Hover support 606 // Hover support
581 bool new_target = input_target != current_input_target_; 607 bool new_target = input_target != current_input_target_;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 1110 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
1085 uint32_t device_id) { 1111 uint32_t device_id) {
1086 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( 1112 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1087 gvr_api_.get(), content_tex_physical_size_, device_id); 1113 gvr_api_.get(), content_tex_physical_size_, device_id);
1088 main_thread_task_runner_->PostTask( 1114 main_thread_task_runner_->PostTask(
1089 FROM_HERE, 1115 FROM_HERE,
1090 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1116 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1091 } 1117 }
1092 1118
1093 } // namespace vr_shell 1119 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698