| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 if (event->flags() & ui::EF_IS_NON_CLIENT) { | 712 if (event->flags() & ui::EF_IS_NON_CLIENT) { |
| 713 // TODO(jonross): ideally this would not be done for mus (crbug.com/621412) | 713 // TODO(jonross): ideally this would not be done for mus (crbug.com/621412) |
| 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 = |
| 723 event->type() == ui::ET_MOUSE_DRAGGED) && | 723 (event->type() == ui::ET_MOUSE_MOVED || |
| 724 mouse_event.x == center.x() && | 724 event->type() == ui::ET_MOUSE_DRAGGED) && |
| 725 mouse_event.y == center.y(); | 725 mouse_event.positionInWidget().x == center.x() && |
| 726 mouse_event.positionInWidget().y == center.y(); |
| 726 | 727 |
| 727 // For fractional scale factors, the conversion from pixels to dip and | 728 // 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 | 729 // 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 | 730 // 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 | 731 // 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 | 732 // to bounce around the center of the screen leading to the lock operation |
| 732 // not working correctly. | 733 // not working correctly. |
| 733 // Workaround is to treat a mouse move or drag event off by at most 2 px | 734 // 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. | 735 // from the center as a move to center event. |
| 735 if (synthetic_move_sent_ && | 736 if (synthetic_move_sent_ && |
| 736 IsFractionalScaleFactor(host_view_->current_device_scale_factor())) { | 737 IsFractionalScaleFactor(host_view_->current_device_scale_factor())) { |
| 737 if (event->type() == ui::ET_MOUSE_MOVED || | 738 if (event->type() == ui::ET_MOUSE_MOVED || |
| 738 event->type() == ui::ET_MOUSE_DRAGGED) { | 739 event->type() == ui::ET_MOUSE_DRAGGED) { |
| 739 if ((abs(mouse_event.x - center.x()) <= 2) && | 740 if ((std::abs(mouse_event.positionInWidget().x - center.x()) <= 2) && |
| 740 (abs(mouse_event.y - center.y()) <= 2)) { | 741 (std::abs(mouse_event.positionInWidget().y - center.y()) <= 2)) { |
| 741 is_move_to_center_event = true; | 742 is_move_to_center_event = true; |
| 742 } | 743 } |
| 743 } | 744 } |
| 744 } | 745 } |
| 745 | 746 |
| 746 ModifyEventMovementAndCoords(*event, &mouse_event); | 747 ModifyEventMovementAndCoords(*event, &mouse_event); |
| 747 | 748 |
| 748 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 749 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; |
| 749 if (should_not_forward) { | 750 if (should_not_forward) { |
| 750 synthetic_move_sent_ = false; | 751 synthetic_move_sent_ = false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 772 } | 773 } |
| 773 } | 774 } |
| 774 | 775 |
| 775 void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords( | 776 void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords( |
| 776 const ui::MouseEvent& ui_mouse_event, | 777 const ui::MouseEvent& ui_mouse_event, |
| 777 blink::WebMouseEvent* event) { | 778 blink::WebMouseEvent* event) { |
| 778 // If the mouse has just entered, we must report zero movementX/Y. Hence we | 779 // If the mouse has just entered, we must report zero movementX/Y. Hence we |
| 779 // reset any global_mouse_position set previously. | 780 // reset any global_mouse_position set previously. |
| 780 if (ui_mouse_event.type() == ui::ET_MOUSE_ENTERED || | 781 if (ui_mouse_event.type() == ui::ET_MOUSE_ENTERED || |
| 781 ui_mouse_event.type() == ui::ET_MOUSE_EXITED) { | 782 ui_mouse_event.type() == ui::ET_MOUSE_EXITED) { |
| 782 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 783 global_mouse_position_.SetPoint(event->positionInScreen().x, |
| 784 event->positionInScreen().y); |
| 783 } | 785 } |
| 784 | 786 |
| 785 // Movement is computed by taking the difference of the new cursor position | 787 // 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 | 788 // 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. | 789 // center so that we are not limited by clipping boundaries. |
| 788 // We do not measure movement as the delta from cursor to center because | 790 // 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 | 791 // we may receive more mouse movement events before our warp has taken |
| 790 // effect. | 792 // effect. |
| 791 event->movementX = event->globalX - global_mouse_position_.x(); | 793 event->movementX = event->positionInScreen().x - global_mouse_position_.x(); |
| 792 event->movementY = event->globalY - global_mouse_position_.y(); | 794 event->movementY = event->positionInScreen().y - global_mouse_position_.y(); |
| 793 | 795 |
| 794 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 796 global_mouse_position_.SetPoint(event->positionInScreen().x, |
| 797 event->positionInScreen().y); |
| 795 | 798 |
| 796 // Under mouse lock, coordinates of mouse are locked to what they were when | 799 // Under mouse lock, coordinates of mouse are locked to what they were when |
| 797 // mouse lock was entered. | 800 // mouse lock was entered. |
| 798 if (mouse_locked_) { | 801 if (mouse_locked_) { |
| 799 event->x = unlocked_mouse_position_.x(); | 802 event->setPositionInWidget(unlocked_mouse_position_.x(), |
| 800 event->y = unlocked_mouse_position_.y(); | 803 unlocked_mouse_position_.y()); |
| 801 event->globalX = unlocked_global_mouse_position_.x(); | 804 event->setPositionInScreen(unlocked_global_mouse_position_.x(), |
| 802 event->globalY = unlocked_global_mouse_position_.y(); | 805 unlocked_global_mouse_position_.y()); |
| 803 } else { | 806 } else { |
| 804 unlocked_mouse_position_.SetPoint(event->x, event->y); | 807 unlocked_mouse_position_.SetPoint(event->positionInWidget().x, |
| 805 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); | 808 event->positionInWidget().y); |
| 809 unlocked_global_mouse_position_.SetPoint(event->positionInScreen().x, |
| 810 event->positionInScreen().y); |
| 806 } | 811 } |
| 807 } | 812 } |
| 808 | 813 |
| 809 void RenderWidgetHostViewEventHandler::SetKeyboardFocus() { | 814 void RenderWidgetHostViewEventHandler::SetKeyboardFocus() { |
| 810 #if defined(OS_WIN) | 815 #if defined(OS_WIN) |
| 811 if (window_ && window_->delegate()->CanFocus()) { | 816 if (window_ && window_->delegate()->CanFocus()) { |
| 812 aura::WindowTreeHost* host = window_->GetHost(); | 817 aura::WindowTreeHost* host = window_->GetHost(); |
| 813 if (host) { | 818 if (host) { |
| 814 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); | 819 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); |
| 815 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) | 820 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); | 881 host_->ForwardWheelEventWithLatencyInfo(event, latency); |
| 877 } | 882 } |
| 878 | 883 |
| 879 void RenderWidgetHostViewEventHandler::ProcessTouchEvent( | 884 void RenderWidgetHostViewEventHandler::ProcessTouchEvent( |
| 880 const blink::WebTouchEvent& event, | 885 const blink::WebTouchEvent& event, |
| 881 const ui::LatencyInfo& latency) { | 886 const ui::LatencyInfo& latency) { |
| 882 host_->ForwardTouchEventWithLatencyInfo(event, latency); | 887 host_->ForwardTouchEventWithLatencyInfo(event, latency); |
| 883 } | 888 } |
| 884 | 889 |
| 885 } // namespace content | 890 } // namespace content |
| OLD | NEW |