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 "content/browser/renderer_host/render_widget_host_view_event_handler.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" |
6 | 6 |
7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
8 #include "base/metrics/user_metrics_action.h" | 8 #include "base/metrics/user_metrics_action.h" |
9 #include "content/browser/renderer_host/input/touch_selection_controller_client_
aura.h" | 9 #include "content/browser/renderer_host/input/touch_selection_controller_client_
aura.h" |
10 #include "content/browser/renderer_host/overscroll_controller.h" | 10 #include "content/browser/renderer_host/overscroll_controller.h" |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 synthetic_move_sent_ = true; | 714 synthetic_move_sent_ = true; |
715 window_->MoveCursorTo(center); | 715 window_->MoveCursorTo(center); |
716 return; | 716 return; |
717 } | 717 } |
718 | 718 |
719 blink::WebMouseEvent mouse_event = | 719 blink::WebMouseEvent mouse_event = |
720 ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent)); | 720 ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent)); |
721 | 721 |
722 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | 722 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || |
723 event->type() == ui::ET_MOUSE_DRAGGED) && | 723 event->type() == ui::ET_MOUSE_DRAGGED) && |
724 mouse_event.x == center.x() && | 724 mouse_event.position.x == center.x() && |
725 mouse_event.y == center.y(); | 725 mouse_event.position.y == center.y(); |
726 | 726 |
727 // For fractional scale factors, the conversion from pixels to dip and | 727 // For fractional scale factors, the conversion from pixels to dip and |
728 // vice versa could result in off by 1 or 2 errors which hurts us because | 728 // vice versa could result in off by 1 or 2 errors which hurts us because |
729 // we want to avoid sending the artificial move to center event to the | 729 // we want to avoid sending the artificial move to center event to the |
730 // renderer. Sending the move to center to the renderer cause the cursor | 730 // renderer. Sending the move to center to the renderer cause the cursor |
731 // to bounce around the center of the screen leading to the lock operation | 731 // to bounce around the center of the screen leading to the lock operation |
732 // not working correctly. | 732 // not working correctly. |
733 // Workaround is to treat a mouse move or drag event off by at most 2 px | 733 // Workaround is to treat a mouse move or drag event off by at most 2 px |
734 // from the center as a move to center event. | 734 // from the center as a move to center event. |
735 if (synthetic_move_sent_ && | 735 if (synthetic_move_sent_ && |
736 IsFractionalScaleFactor(host_view_->current_device_scale_factor())) { | 736 IsFractionalScaleFactor(host_view_->current_device_scale_factor())) { |
737 if (event->type() == ui::ET_MOUSE_MOVED || | 737 if (event->type() == ui::ET_MOUSE_MOVED || |
738 event->type() == ui::ET_MOUSE_DRAGGED) { | 738 event->type() == ui::ET_MOUSE_DRAGGED) { |
739 if ((abs(mouse_event.x - center.x()) <= 2) && | 739 if ((std::abs(mouse_event.position.x - center.x()) <= 2) && |
740 (abs(mouse_event.y - center.y()) <= 2)) { | 740 (std::abs(mouse_event.position.y - center.y()) <= 2)) { |
741 is_move_to_center_event = true; | 741 is_move_to_center_event = true; |
742 } | 742 } |
743 } | 743 } |
744 } | 744 } |
745 | 745 |
746 ModifyEventMovementAndCoords(*event, &mouse_event); | 746 ModifyEventMovementAndCoords(*event, &mouse_event); |
747 | 747 |
748 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 748 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; |
749 if (should_not_forward) { | 749 if (should_not_forward) { |
750 synthetic_move_sent_ = false; | 750 synthetic_move_sent_ = false; |
(...skipping 21 matching lines...) Expand all Loading... |
772 } | 772 } |
773 } | 773 } |
774 | 774 |
775 void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords( | 775 void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords( |
776 const ui::MouseEvent& ui_mouse_event, | 776 const ui::MouseEvent& ui_mouse_event, |
777 blink::WebMouseEvent* event) { | 777 blink::WebMouseEvent* event) { |
778 // If the mouse has just entered, we must report zero movementX/Y. Hence we | 778 // If the mouse has just entered, we must report zero movementX/Y. Hence we |
779 // reset any global_mouse_position set previously. | 779 // reset any global_mouse_position set previously. |
780 if (ui_mouse_event.type() == ui::ET_MOUSE_ENTERED || | 780 if (ui_mouse_event.type() == ui::ET_MOUSE_ENTERED || |
781 ui_mouse_event.type() == ui::ET_MOUSE_EXITED) { | 781 ui_mouse_event.type() == ui::ET_MOUSE_EXITED) { |
782 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 782 global_mouse_position_.SetPoint(event->screenPosition.x, |
| 783 event->screenPosition.y); |
783 } | 784 } |
784 | 785 |
785 // Movement is computed by taking the difference of the new cursor position | 786 // Movement is computed by taking the difference of the new cursor position |
786 // and the previous. Under mouse lock the cursor will be warped back to the | 787 // and the previous. Under mouse lock the cursor will be warped back to the |
787 // center so that we are not limited by clipping boundaries. | 788 // center so that we are not limited by clipping boundaries. |
788 // We do not measure movement as the delta from cursor to center because | 789 // We do not measure movement as the delta from cursor to center because |
789 // we may receive more mouse movement events before our warp has taken | 790 // we may receive more mouse movement events before our warp has taken |
790 // effect. | 791 // effect. |
791 event->movementX = event->globalX - global_mouse_position_.x(); | 792 event->movementX = event->screenPosition.x - global_mouse_position_.x(); |
792 event->movementY = event->globalY - global_mouse_position_.y(); | 793 event->movementY = event->screenPosition.y - global_mouse_position_.y(); |
793 | 794 |
794 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 795 global_mouse_position_.SetPoint(event->screenPosition.x, |
| 796 event->screenPosition.y); |
795 | 797 |
796 // Under mouse lock, coordinates of mouse are locked to what they were when | 798 // Under mouse lock, coordinates of mouse are locked to what they were when |
797 // mouse lock was entered. | 799 // mouse lock was entered. |
798 if (mouse_locked_) { | 800 if (mouse_locked_) { |
799 event->x = unlocked_mouse_position_.x(); | 801 event->position.x = unlocked_mouse_position_.x(); |
800 event->y = unlocked_mouse_position_.y(); | 802 event->position.y = unlocked_mouse_position_.y(); |
801 event->globalX = unlocked_global_mouse_position_.x(); | 803 event->screenPosition.x = unlocked_global_mouse_position_.x(); |
802 event->globalY = unlocked_global_mouse_position_.y(); | 804 event->screenPosition.y = unlocked_global_mouse_position_.y(); |
803 } else { | 805 } else { |
804 unlocked_mouse_position_.SetPoint(event->x, event->y); | 806 unlocked_mouse_position_.SetPoint(event->position.x, event->position.y); |
805 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); | 807 unlocked_global_mouse_position_.SetPoint(event->screenPosition.x, |
| 808 event->screenPosition.y); |
806 } | 809 } |
807 } | 810 } |
808 | 811 |
809 void RenderWidgetHostViewEventHandler::SetKeyboardFocus() { | 812 void RenderWidgetHostViewEventHandler::SetKeyboardFocus() { |
810 #if defined(OS_WIN) | 813 #if defined(OS_WIN) |
811 if (window_ && window_->delegate()->CanFocus()) { | 814 if (window_ && window_->delegate()->CanFocus()) { |
812 aura::WindowTreeHost* host = window_->GetHost(); | 815 aura::WindowTreeHost* host = window_->GetHost(); |
813 if (host) { | 816 if (host) { |
814 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); | 817 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); |
815 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) | 818 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 host_->ForwardWheelEventWithLatencyInfo(event, latency); | 879 host_->ForwardWheelEventWithLatencyInfo(event, latency); |
877 } | 880 } |
878 | 881 |
879 void RenderWidgetHostViewEventHandler::ProcessTouchEvent( | 882 void RenderWidgetHostViewEventHandler::ProcessTouchEvent( |
880 const blink::WebTouchEvent& event, | 883 const blink::WebTouchEvent& event, |
881 const ui::LatencyInfo& latency) { | 884 const ui::LatencyInfo& latency) { |
882 host_->ForwardTouchEventWithLatencyInfo(event, latency); | 885 host_->ForwardTouchEventWithLatencyInfo(event, latency); |
883 } | 886 } |
884 | 887 |
885 } // namespace content | 888 } // namespace content |
OLD | NEW |