| OLD | NEW |
| 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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 target_point_ = GetRayPoint(origin, forward, distance); | 498 target_point_ = GetRayPoint(origin, forward, distance); |
| 499 gvr::Vec3f eye_to_target = target_point_; | 499 gvr::Vec3f eye_to_target = target_point_; |
| 500 NormalizeVector(eye_to_target); | 500 NormalizeVector(eye_to_target); |
| 501 | 501 |
| 502 // Determine which UI element (if any) intersects the line between the eyes | 502 // Determine which UI element (if any) intersects the line between the eyes |
| 503 // and the controller target position. | 503 // and the controller target position. |
| 504 float closest_element_distance = std::numeric_limits<float>::infinity(); | 504 float closest_element_distance = std::numeric_limits<float>::infinity(); |
| 505 int pixel_x = 0; | 505 int pixel_x = 0; |
| 506 int pixel_y = 0; | 506 int pixel_y = 0; |
| 507 target_element_ = nullptr; | 507 target_element_ = nullptr; |
| 508 InputTarget input_target = InputTarget::NONE; | |
| 509 | 508 |
| 510 for (const auto& plane : scene_->GetUiElements()) { | 509 for (const auto& plane : scene_->GetUiElements()) { |
| 511 if (!plane->IsHitTestable()) | 510 if (!plane->IsHitTestable()) |
| 512 continue; | 511 continue; |
| 513 | 512 |
| 514 float distance_to_plane = plane->GetRayDistance(kOrigin, eye_to_target); | 513 float distance_to_plane = plane->GetRayDistance(kOrigin, eye_to_target); |
| 515 gvr::Vec3f plane_intersection_point = | 514 gvr::Vec3f plane_intersection_point = |
| 516 GetRayPoint(kOrigin, eye_to_target, distance_to_plane); | 515 GetRayPoint(kOrigin, eye_to_target, distance_to_plane); |
| 517 | 516 |
| 518 gvr::Vec3f rect_2d_point = | 517 gvr::Vec3f rect_2d_point = |
| 519 MatrixVectorMul(plane->transform.from_world, plane_intersection_point); | 518 MatrixVectorMul(plane->transform.from_world, plane_intersection_point); |
| 520 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) { | 519 if (distance_to_plane < 0 || |
| 521 float x = rect_2d_point.x + 0.5f; | 520 distance_to_plane >= closest_element_distance) { |
| 522 float y = 0.5f - rect_2d_point.y; | 521 continue; |
| 523 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; | 522 } |
| 524 if (!is_inside) | |
| 525 continue; | |
| 526 | 523 |
| 527 closest_element_distance = distance_to_plane; | 524 float x = rect_2d_point.x + 0.5f; |
| 528 Rectf pixel_rect; | 525 float y = 0.5f - rect_2d_point.y; |
| 529 if (plane->fill == Fill::CONTENT) { | 526 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; |
| 530 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_}; | 527 if (!is_inside) |
| 531 } else { | 528 continue; |
| 532 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y, | |
| 533 plane->copy_rect.width, plane->copy_rect.height}; | |
| 534 } | |
| 535 pixel_x = pixel_rect.width * x + pixel_rect.x; | |
| 536 pixel_y = pixel_rect.height * y + pixel_rect.y; | |
| 537 | 529 |
| 538 target_point_ = plane_intersection_point; | 530 closest_element_distance = distance_to_plane; |
| 539 target_element_ = plane.get(); | 531 Rectf pixel_rect; |
| 540 input_target = (plane->fill == Fill::CONTENT) ? InputTarget::CONTENT | 532 if (plane->fill == Fill::CONTENT) { |
| 541 : InputTarget::UI; | 533 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_}; |
| 534 } else { |
| 535 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y, |
| 536 plane->copy_rect.width, plane->copy_rect.height}; |
| 537 } |
| 538 pixel_x = pixel_rect.width * x + pixel_rect.x; |
| 539 pixel_y = pixel_rect.height * y + pixel_rect.y; |
| 540 |
| 541 target_point_ = plane_intersection_point; |
| 542 target_element_ = plane.get(); |
| 543 } |
| 544 |
| 545 // Treat UI elements, which do not show web content, as NONE input |
| 546 // targets since they cannot make use of the input anyway. |
| 547 InputTarget input_target = InputTarget::NONE; |
| 548 if (target_element_ != nullptr) { |
| 549 switch (target_element_->fill) { |
| 550 case Fill::CONTENT: |
| 551 input_target = InputTarget::CONTENT; |
| 552 break; |
| 553 case Fill::SPRITE: |
| 554 input_target = InputTarget::UI; |
| 555 break; |
| 556 default: |
| 557 input_target = InputTarget::NONE; |
| 558 break; |
| 542 } | 559 } |
| 543 } | 560 } |
| 544 SendEventsToTarget(input_target, pixel_x, pixel_y); | 561 SendEventsToTarget(input_target, pixel_x, pixel_y); |
| 545 } | 562 } |
| 546 | 563 |
| 547 void VrShellGl::SendEventsToTarget(InputTarget input_target, | 564 void VrShellGl::SendEventsToTarget(InputTarget input_target, |
| 548 int pixel_x, | 565 int pixel_x, |
| 549 int pixel_y) { | 566 int pixel_y) { |
| 550 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list = | 567 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list = |
| 551 controller_->DetectGestures(); | 568 controller_->DetectGestures(); |
| 552 double timestamp = gesture_list.front()->timeStampSeconds(); | 569 double timestamp = gesture_list.front()->timeStampSeconds(); |
| 553 | 570 |
| 554 if (touch_pending_) { | 571 if (touch_pending_) { |
| 555 touch_pending_ = false; | 572 touch_pending_ = false; |
| 556 std::unique_ptr<WebGestureEvent> event(new WebGestureEvent( | 573 std::unique_ptr<WebGestureEvent> event(new WebGestureEvent( |
| 557 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, timestamp)); | 574 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, timestamp)); |
| 558 event->sourceDevice = blink::WebGestureDeviceTouchpad; | 575 event->sourceDevice = blink::WebGestureDeviceTouchpad; |
| 559 event->x = pixel_x; | 576 event->x = pixel_x; |
| 560 event->y = pixel_y; | 577 event->y = pixel_y; |
| 561 gesture_list.push_back(std::move(event)); | 578 gesture_list.push_back(std::move(event)); |
| 562 } | 579 } |
| 563 | 580 |
| 564 for (const auto& gesture : gesture_list) { | 581 for (auto& gesture : gesture_list) { |
| 582 gesture->x = pixel_x; |
| 583 gesture->y = pixel_y; |
| 584 auto movableGesture = base::MakeUnique<WebGestureEvent>(*gesture); |
| 585 |
| 565 switch (gesture->type()) { | 586 switch (gesture->type()) { |
| 587 // Once the user starts scrolling send all the scroll events to this |
| 588 // element until the scrolling stops. |
| 566 case WebInputEvent::GestureScrollBegin: | 589 case WebInputEvent::GestureScrollBegin: |
| 590 current_scroll_target = input_target; |
| 591 if (current_scroll_target != InputTarget::NONE) { |
| 592 SendGesture(current_scroll_target, std::move(movableGesture)); |
| 593 } |
| 594 break; |
| 595 case WebInputEvent::GestureScrollEnd: |
| 596 if (current_scroll_target != InputTarget::NONE) { |
| 597 SendGesture(current_scroll_target, std::move(movableGesture)); |
| 598 } |
| 599 current_scroll_target = InputTarget::NONE; |
| 600 break; |
| 567 case WebInputEvent::GestureScrollUpdate: | 601 case WebInputEvent::GestureScrollUpdate: |
| 568 case WebInputEvent::GestureScrollEnd: | |
| 569 case WebInputEvent::GestureFlingCancel: | 602 case WebInputEvent::GestureFlingCancel: |
| 570 case WebInputEvent::GestureFlingStart: | 603 case WebInputEvent::GestureFlingStart: |
| 571 SendGesture(InputTarget::CONTENT, | 604 if (current_scroll_target != InputTarget::NONE) { |
| 572 base::WrapUnique(new WebGestureEvent(*gesture))); | 605 SendGesture(current_scroll_target, std::move(movableGesture)); |
| 606 } |
| 573 break; | 607 break; |
| 574 case WebInputEvent::GestureTapDown: | 608 case WebInputEvent::GestureTapDown: |
| 575 gesture->x = pixel_x; | 609 if (input_target != InputTarget::NONE) { |
| 576 gesture->y = pixel_y; | 610 SendGesture(input_target, std::move(movableGesture)); |
| 577 if (input_target != InputTarget::NONE) | 611 } |
| 578 SendGesture(input_target, | |
| 579 base::WrapUnique(new WebGestureEvent(*gesture))); | |
| 580 break; | 612 break; |
| 581 case WebInputEvent::Undefined: | 613 case WebInputEvent::Undefined: |
| 582 break; | 614 break; |
| 583 default: | 615 default: |
| 584 NOTREACHED(); | 616 NOTREACHED(); |
| 585 } | 617 } |
| 586 } | 618 } |
| 587 | 619 |
| 588 // Hover support | 620 // Hover support |
| 589 bool new_target = input_target != current_input_target_; | 621 bool new_target = input_target != current_input_target_; |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1124 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1093 uint32_t device_id) { | 1125 uint32_t device_id) { |
| 1094 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1126 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1095 gvr_api_.get(), content_tex_physical_size_, device_id); | 1127 gvr_api_.get(), content_tex_physical_size_, device_id); |
| 1096 main_thread_task_runner_->PostTask( | 1128 main_thread_task_runner_->PostTask( |
| 1097 FROM_HERE, | 1129 FROM_HERE, |
| 1098 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1130 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1099 } | 1131 } |
| 1100 | 1132 |
| 1101 } // namespace vr_shell | 1133 } // namespace vr_shell |
| OLD | NEW |