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

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

Issue 2936853003: VR: Send separate down and up events for controller clicks. (Closed)
Patch Set: Created 3 years, 6 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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 result.m[2][2] = C; 156 result.m[2][2] = C;
157 result.m[2][3] = D; 157 result.m[2][3] = D;
158 result.m[3][2] = -1; 158 result.m[3][2] = -1;
159 159
160 return result; 160 return result;
161 } 161 }
162 162
163 std::unique_ptr<blink::WebMouseEvent> MakeMouseEvent( 163 std::unique_ptr<blink::WebMouseEvent> MakeMouseEvent(
164 blink::WebInputEvent::Type type, 164 blink::WebInputEvent::Type type,
165 double timestamp, 165 double timestamp,
166 const gfx::Point& loc) { 166 const gfx::Point& loc,
167 std::unique_ptr<blink::WebMouseEvent> mouse_event(new blink::WebMouseEvent( 167 bool down) {
168 type, blink::WebInputEvent::kNoModifiers, timestamp)); 168 blink::WebInputEvent::Modifiers mods =
cjgrant 2017/06/13 19:39:04 s/mods/modifiers/ ? And s/loc/location/ above?
mthiesse 2017/06/13 19:55:45 Done.
169 down ? blink::WebInputEvent::kLeftButtonDown
170 : blink::WebInputEvent::kNoModifiers;
171 std::unique_ptr<blink::WebMouseEvent> mouse_event(
172 new blink::WebMouseEvent(type, mods, timestamp));
169 mouse_event->pointer_type = blink::WebPointerProperties::PointerType::kMouse; 173 mouse_event->pointer_type = blink::WebPointerProperties::PointerType::kMouse;
174 mouse_event->button = blink::WebPointerProperties::Button::kLeft;
170 mouse_event->SetPositionInWidget(loc.x(), loc.y()); 175 mouse_event->SetPositionInWidget(loc.x(), loc.y());
171 mouse_event->click_count = 1; 176 mouse_event->click_count = 1;
172 177
173 return mouse_event; 178 return mouse_event;
174 } 179 }
175 180
176 181
177 void MatfToGvrMat(const vr::Mat4f& in, gvr::Mat4f* out) { 182 void MatfToGvrMat(const vr::Mat4f& in, gvr::Mat4f* out) {
178 // If our std::array implementation doesn't have any non-data members, we can 183 // If our std::array implementation doesn't have any non-data members, we can
179 // just cast the gvr matrix to an std::array. 184 // just cast the gvr matrix to an std::array.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 604 }
600 } 605 }
601 // If we're still scrolling, don't hover (and we can't be clicking, because 606 // If we're still scrolling, don't hover (and we can't be clicking, because
602 // click ends scroll). 607 // click ends scroll).
603 if (in_scroll_) 608 if (in_scroll_)
604 return; 609 return;
605 SendHoverLeave(target_element); 610 SendHoverLeave(target_element);
606 if (!SendHoverEnter(target_element, target_local_point, local_point_pixels)) { 611 if (!SendHoverEnter(target_element, target_local_point, local_point_pixels)) {
607 SendHoverMove(target_local_point, local_point_pixels); 612 SendHoverMove(target_local_point, local_point_pixels);
608 } 613 }
609 SendButtonDown(target_element, target_local_point); 614 SendButtonDown(target_element, target_local_point, local_point_pixels);
610 if (!SendButtonUp(target_element, target_local_point)) 615 if (!SendButtonUp(target_element, target_local_point, local_point_pixels))
611 SendTap(target_element, target_local_point, local_point_pixels); 616 SendTap(target_element, target_local_point, local_point_pixels);
612 } 617 }
613 618
614 void VrShellGl::HandleWebVrCompatibilityClick() { 619 void VrShellGl::HandleWebVrCompatibilityClick() {
615 if (!ShouldDrawWebVr()) 620 if (!ShouldDrawWebVr())
616 return; 621 return;
617 622
618 // Process screen touch events for Cardboard button compatibility. 623 // Process screen touch events for Cardboard button compatibility.
619 // Also send tap events for controller "touchpad click" events. 624 // Also send tap events for controller "touchpad click" events.
620 if (touch_pending_ || 625 if (touch_pending_ ||
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT); 704 DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT);
700 SendGestureToContent(std::move(gesture_list.front())); 705 SendGestureToContent(std::move(gesture_list.front()));
701 gesture_list.erase(gesture_list.begin()); 706 gesture_list.erase(gesture_list.begin());
702 } 707 }
703 708
704 void VrShellGl::SendHoverLeave(UiElement* target) { 709 void VrShellGl::SendHoverLeave(UiElement* target) {
705 if (!hover_target_ || (target == hover_target_)) 710 if (!hover_target_ || (target == hover_target_))
706 return; 711 return;
707 if (hover_target_->fill() == Fill::CONTENT) { 712 if (hover_target_->fill() == Fill::CONTENT) {
708 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseLeave, 713 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseLeave,
709 NowSeconds(), gfx::Point())); 714 NowSeconds(), gfx::Point(), in_click_));
710 } else { 715 } else {
711 hover_target_->OnHoverLeave(); 716 hover_target_->OnHoverLeave();
712 } 717 }
713 hover_target_ = nullptr; 718 hover_target_ = nullptr;
714 } 719 }
715 720
716 bool VrShellGl::SendHoverEnter(UiElement* target, 721 bool VrShellGl::SendHoverEnter(UiElement* target,
717 const gfx::PointF& target_point, 722 const gfx::PointF& target_point,
718 const gfx::Point& local_point_pixels) { 723 const gfx::Point& local_point_pixels) {
719 if (!target || target == hover_target_) 724 if (!target || target == hover_target_)
720 return false; 725 return false;
721 if (target->fill() == Fill::CONTENT) { 726 if (target->fill() == Fill::CONTENT) {
722 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseEnter, 727 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseEnter,
723 NowSeconds(), local_point_pixels)); 728 NowSeconds(), local_point_pixels,
729 in_click_));
724 } else { 730 } else {
725 target->OnHoverEnter(target_point); 731 target->OnHoverEnter(target_point);
726 } 732 }
727 hover_target_ = target; 733 hover_target_ = target;
728 return true; 734 return true;
729 } 735 }
730 736
731 void VrShellGl::SendHoverMove(const gfx::PointF& target_point, 737 void VrShellGl::SendHoverMove(const gfx::PointF& target_point,
732 const gfx::Point& local_point_pixels) { 738 const gfx::Point& local_point_pixels) {
733 if (!hover_target_) 739 if (!hover_target_)
734 return; 740 return;
735 if (hover_target_->fill() == Fill::CONTENT) { 741 if (hover_target_->fill() == Fill::CONTENT) {
736 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseMove, 742 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseMove,
737 NowSeconds(), local_point_pixels)); 743 NowSeconds(), local_point_pixels,
744 in_click_));
738 } else { 745 } else {
739 hover_target_->OnMove(target_point); 746 hover_target_->OnMove(target_point);
740 } 747 }
741 } 748 }
742 749
743 void VrShellGl::SendButtonDown(UiElement* target, 750 void VrShellGl::SendButtonDown(UiElement* target,
744 const gfx::PointF& target_point) { 751 const gfx::PointF& target_point,
752 const gfx::Point& local_point_pixels) {
745 if (in_click_) 753 if (in_click_)
746 return; 754 return;
747 if (!controller_->ButtonDownHappened(gvr::kControllerButtonClick)) 755 if (!controller_->ButtonDownHappened(gvr::kControllerButtonClick))
748 return; 756 return;
749 input_locked_element_ = target; 757 input_locked_element_ = target;
750 in_click_ = true; 758 in_click_ = true;
751 // We don't support down/up for content yet. 759 if (!target)
752 if (!target || target->fill() == Fill::CONTENT)
753 return; 760 return;
754 target->OnButtonDown(target_point); 761 if (target->fill() == Fill::CONTENT) {
762 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseDown,
763 NowSeconds(), local_point_pixels,
764 in_click_));
765 } else {
766 target->OnButtonDown(target_point);
767 }
755 } 768 }
756 769
757 bool VrShellGl::SendButtonUp(UiElement* target, 770 bool VrShellGl::SendButtonUp(UiElement* target,
758 const gfx::PointF& target_point) { 771 const gfx::PointF& target_point,
772 const gfx::Point& local_point_pixels) {
759 if (!in_click_) 773 if (!in_click_)
760 return false; 774 return false;
761 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick)) 775 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick) &&
776 controller_->ButtonState(gvr::kControllerButtonClick))
762 return false; 777 return false;
763 in_click_ = false; 778 in_click_ = false;
764 if (!input_locked_element_) 779 if (!input_locked_element_)
765 return true; 780 return true;
766 DCHECK(input_locked_element_ == target); 781 DCHECK(input_locked_element_ == target);
767 input_locked_element_ = nullptr; 782 input_locked_element_ = nullptr;
768 // We don't support down/up for content yet. 783 if (target->fill() == Fill::CONTENT) {
769 if (target->fill() == Fill::CONTENT) 784 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseUp,
770 return false; 785 NowSeconds(), local_point_pixels,
771 target->OnButtonUp(target_point); 786 in_click_));
787 } else {
788 target->OnButtonUp(target_point);
789 }
772 return true; 790 return true;
773 } 791 }
774 792
775 void VrShellGl::SendTap(UiElement* target, 793 void VrShellGl::SendTap(UiElement* target,
776 const gfx::PointF& target_point, 794 const gfx::PointF& target_point,
777 const gfx::Point& local_point_pixels) { 795 const gfx::Point& local_point_pixels) {
778 if (!target) 796 if (!target)
779 return; 797 return;
780 if (controller_->ButtonUpHappened(gvr::kControllerButtonClick) &&
781 target->fill() == Fill::CONTENT)
782 touch_pending_ = true;
783 if (!touch_pending_) 798 if (!touch_pending_)
784 return; 799 return;
785 touch_pending_ = false; 800 touch_pending_ = false;
786 if (target->fill() == Fill::CONTENT) { 801 if (target->fill() == Fill::CONTENT) {
787 auto gesture = base::MakeUnique<blink::WebGestureEvent>( 802 auto gesture = base::MakeUnique<blink::WebGestureEvent>(
788 blink::WebInputEvent::kGestureTapDown, 803 blink::WebInputEvent::kGestureTapDown,
789 blink::WebInputEvent::kNoModifiers, NowSeconds()); 804 blink::WebInputEvent::kNoModifiers, NowSeconds());
790 gesture->source_device = blink::kWebGestureDeviceTouchpad; 805 gesture->source_device = blink::kWebGestureDeviceTouchpad;
791 gesture->x = local_point_pixels.x(); 806 gesture->x = local_point_pixels.x();
792 gesture->y = local_point_pixels.y(); 807 gesture->y = local_point_pixels.y();
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 // This assumes that the initial webvr_surface_size_ was set to the 1596 // This assumes that the initial webvr_surface_size_ was set to the
1582 // appropriate recommended render resolution as the default size during 1597 // appropriate recommended render resolution as the default size during
1583 // InitializeGl. Revisit if the initialization order changes. 1598 // InitializeGl. Revisit if the initialization order changes.
1584 device::mojom::VRDisplayInfoPtr info = 1599 device::mojom::VRDisplayInfoPtr info =
1585 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1600 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1586 webvr_surface_size_, device_id); 1601 webvr_surface_size_, device_id);
1587 browser_->RunVRDisplayInfoCallback(callback, &info); 1602 browser_->RunVRDisplayInfoCallback(callback, &info);
1588 } 1603 }
1589 1604
1590 } // namespace vr_shell 1605 } // 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