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

Unified Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2688813004: Enable scrolling of UI elements. (Closed)
Patch Set: Ditched const, rebased on ToT 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/vr_shell_gl.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell_gl.cc b/chrome/browser/android/vr_shell/vr_shell_gl.cc
index ebad9609b13279e95d7d7fa6ed4ec067045798a4..c846aef7efb62167301b37c01af3086c41e9ed3e 100644
--- a/chrome/browser/android/vr_shell/vr_shell_gl.cc
+++ b/chrome/browser/android/vr_shell/vr_shell_gl.cc
@@ -505,7 +505,6 @@ void VrShellGl::UpdateController(const gvr::Vec3f& forward_vector) {
int pixel_x = 0;
int pixel_y = 0;
target_element_ = nullptr;
- InputTarget input_target = InputTarget::NONE;
for (const auto& plane : scene_->GetUiElements()) {
if (!plane->IsHitTestable())
@@ -517,28 +516,46 @@ void VrShellGl::UpdateController(const gvr::Vec3f& forward_vector) {
gvr::Vec3f rect_2d_point =
MatrixVectorMul(plane->transform.from_world, plane_intersection_point);
- if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) {
- float x = rect_2d_point.x + 0.5f;
- float y = 0.5f - rect_2d_point.y;
- bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
- if (!is_inside)
- continue;
-
- closest_element_distance = distance_to_plane;
- Rectf pixel_rect;
- if (plane->fill == Fill::CONTENT) {
- pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_};
- } else {
- pixel_rect = {plane->copy_rect.x, plane->copy_rect.y,
- plane->copy_rect.width, plane->copy_rect.height};
- }
- pixel_x = pixel_rect.width * x + pixel_rect.x;
- pixel_y = pixel_rect.height * y + pixel_rect.y;
+ if (distance_to_plane < 0 ||
+ distance_to_plane >= closest_element_distance) {
+ continue;
+ }
+
+ float x = rect_2d_point.x + 0.5f;
+ float y = 0.5f - rect_2d_point.y;
+ bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
+ if (!is_inside)
+ continue;
+
+ closest_element_distance = distance_to_plane;
+ Rectf pixel_rect;
+ if (plane->fill == Fill::CONTENT) {
+ pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_};
+ } else {
+ pixel_rect = {plane->copy_rect.x, plane->copy_rect.y,
+ plane->copy_rect.width, plane->copy_rect.height};
+ }
+ pixel_x = pixel_rect.width * x + pixel_rect.x;
+ pixel_y = pixel_rect.height * y + pixel_rect.y;
+
+ target_point_ = plane_intersection_point;
+ target_element_ = plane.get();
+ }
- target_point_ = plane_intersection_point;
- target_element_ = plane.get();
- input_target = (plane->fill == Fill::CONTENT) ? InputTarget::CONTENT
- : InputTarget::UI;
+ // Treat UI elements, which do not show web content, as NONE input
+ // targets since they cannot make use of the input anyway.
+ InputTarget input_target = InputTarget::NONE;
+ if (target_element_ != nullptr) {
+ switch (target_element_->fill) {
+ case Fill::CONTENT:
+ input_target = InputTarget::CONTENT;
+ break;
+ case Fill::SPRITE:
+ input_target = InputTarget::UI;
+ break;
+ default:
+ input_target = InputTarget::NONE;
+ break;
}
}
SendEventsToTarget(input_target, pixel_x, pixel_y);
@@ -561,22 +578,37 @@ void VrShellGl::SendEventsToTarget(InputTarget input_target,
gesture_list.push_back(std::move(event));
}
- for (const auto& gesture : gesture_list) {
+ for (auto& gesture : gesture_list) {
+ gesture->x = pixel_x;
+ gesture->y = pixel_y;
+ auto movableGesture = base::MakeUnique<WebGestureEvent>(*gesture);
+
switch (gesture->type()) {
+ // Once the user starts scrolling send all the scroll events to this
+ // element until the scrolling stops.
case WebInputEvent::GestureScrollBegin:
- case WebInputEvent::GestureScrollUpdate:
+ current_scroll_target = input_target;
+ if (current_scroll_target != InputTarget::NONE) {
+ SendGesture(current_scroll_target, std::move(movableGesture));
+ }
+ break;
case WebInputEvent::GestureScrollEnd:
+ if (current_scroll_target != InputTarget::NONE) {
+ SendGesture(current_scroll_target, std::move(movableGesture));
+ }
+ current_scroll_target = InputTarget::NONE;
+ break;
+ case WebInputEvent::GestureScrollUpdate:
case WebInputEvent::GestureFlingCancel:
case WebInputEvent::GestureFlingStart:
- SendGesture(InputTarget::CONTENT,
- base::WrapUnique(new WebGestureEvent(*gesture)));
+ if (current_scroll_target != InputTarget::NONE) {
+ SendGesture(current_scroll_target, std::move(movableGesture));
+ }
break;
case WebInputEvent::GestureTapDown:
- gesture->x = pixel_x;
- gesture->y = pixel_y;
- if (input_target != InputTarget::NONE)
- SendGesture(input_target,
- base::WrapUnique(new WebGestureEvent(*gesture)));
+ if (input_target != InputTarget::NONE) {
+ SendGesture(input_target, std::move(movableGesture));
+ }
break;
case WebInputEvent::Undefined:
break;
« 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