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