Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "remoting/client/gesture_interpreter.h" | 5 #include "remoting/client/gesture_interpreter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "remoting/client/chromoting_session.h" | |
| 9 #include "remoting/client/direct_input_strategy.h" | 10 #include "remoting/client/direct_input_strategy.h" |
| 11 #include "remoting/client/render_stub.h" | |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 | 14 |
| 13 const float kOneFingerFlingTimeConstant = 325.f; | 15 const float kOneFingerFlingTimeConstant = 325.f; |
| 14 | 16 |
| 15 } // namespace | 17 } // namespace |
| 16 | 18 |
| 17 namespace remoting { | 19 namespace remoting { |
| 18 GestureInterpreter::GestureInterpreter( | 20 GestureInterpreter::GestureInterpreter(RenderStub* render_stub, |
| 19 const DesktopViewport::TransformationCallback& on_transformation_changed, | 21 ChromotingSession* input_stub) |
| 20 ChromotingSession* input_stub) | 22 : render_stub_(render_stub), |
| 21 : input_stub_(input_stub), | 23 input_stub_(input_stub), |
| 22 pan_animation_(kOneFingerFlingTimeConstant, | 24 pan_animation_(kOneFingerFlingTimeConstant, |
| 23 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, | 25 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, |
| 24 base::Unretained(this))) { | 26 base::Unretained(this))) { |
| 25 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, | 27 viewport_.RegisterOnTransformationChangedCallback( |
| 26 true); | 28 base::Bind(&RenderStub::SetTransformation, |
| 29 base::Unretained(render_stub_)), | |
| 30 true); | |
| 27 | 31 |
| 28 // TODO(yuweih): This should be configurable. | 32 // TODO(yuweih): This should be configurable. |
| 29 input_strategy_.reset(new DirectInputStrategy()); | 33 input_strategy_.reset(new DirectInputStrategy()); |
| 34 render_stub_->SetCursorVisibility(input_strategy_->IsCursorVisible()); | |
| 35 SetCursorPositionOnRenderStub(); | |
| 30 } | 36 } |
| 31 | 37 |
| 32 GestureInterpreter::~GestureInterpreter() {} | 38 GestureInterpreter::~GestureInterpreter() {} |
| 33 | 39 |
| 34 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { | 40 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { |
| 35 AbortAnimations(); | 41 AbortAnimations(); |
| 36 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); | 42 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); |
| 37 } | 43 } |
| 38 | 44 |
| 39 void GestureInterpreter::Pan(float translation_x, float translation_y) { | 45 void GestureInterpreter::Pan(float translation_x, float translation_y) { |
| 40 AbortAnimations(); | 46 AbortAnimations(); |
| 41 PanWithoutAbortAnimations(translation_x, translation_y); | 47 PanWithoutAbortAnimations(translation_x, translation_y); |
| 42 } | 48 } |
| 43 | 49 |
| 44 void GestureInterpreter::Tap(float x, float y) { | 50 void GestureInterpreter::Tap(float x, float y) { |
| 45 AbortAnimations(); | 51 AbortAnimations(); |
| 52 | |
| 46 float cursor_x, cursor_y; | 53 float cursor_x, cursor_y; |
| 47 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 54 TrackAndGetPosition(x, y, &cursor_x, &cursor_y); |
| 55 StartInputFeedback(cursor_x, cursor_y, InputStrategy::TAP_FEEDBACK); | |
| 48 InjectMouseClick(cursor_x, cursor_y, | 56 InjectMouseClick(cursor_x, cursor_y, |
| 49 protocol::MouseEvent_MouseButton_BUTTON_LEFT); | 57 protocol::MouseEvent_MouseButton_BUTTON_LEFT); |
| 50 } | 58 } |
| 51 | 59 |
| 52 void GestureInterpreter::TwoFingerTap(float x, float y) { | 60 void GestureInterpreter::TwoFingerTap(float x, float y) { |
| 53 AbortAnimations(); | 61 AbortAnimations(); |
| 62 | |
| 54 float cursor_x, cursor_y; | 63 float cursor_x, cursor_y; |
| 55 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 64 TrackAndGetPosition(x, y, &cursor_x, &cursor_y); |
| 56 InjectMouseClick(cursor_x, cursor_y, | 65 InjectMouseClick(cursor_x, cursor_y, |
| 57 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); | 66 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); |
| 58 } | 67 } |
| 59 | 68 |
| 60 void GestureInterpreter::LongPress(float x, float y, GestureState state) { | 69 void GestureInterpreter::LongPress(float x, float y, GestureState state) { |
| 61 AbortAnimations(); | 70 AbortAnimations(); |
| 71 | |
| 62 float cursor_x, cursor_y; | 72 float cursor_x, cursor_y; |
| 63 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 73 TrackAndGetPosition(x, y, &cursor_x, &cursor_y); |
| 74 | |
| 75 if (state == GESTURE_BEGAN) { | |
| 76 StartInputFeedback(cursor_x, cursor_y, InputStrategy::LONG_PRESS_FEEDBACK); | |
| 77 } | |
| 64 | 78 |
| 65 is_dragging_mode_ = state != GESTURE_ENDED; | 79 is_dragging_mode_ = state != GESTURE_ENDED; |
| 66 input_stub_->SendMouseEvent(cursor_x, cursor_y, | 80 input_stub_->SendMouseEvent(cursor_x, cursor_y, |
| 67 protocol::MouseEvent_MouseButton_BUTTON_LEFT, | 81 protocol::MouseEvent_MouseButton_BUTTON_LEFT, |
| 68 is_dragging_mode_); | 82 is_dragging_mode_); |
| 69 } | 83 } |
| 70 | 84 |
| 71 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { | 85 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { |
| 72 AbortAnimations(); | 86 AbortAnimations(); |
| 73 pan_animation_.SetVelocity(velocity_x, velocity_y); | 87 pan_animation_.SetVelocity(velocity_x, velocity_y); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 85 } | 99 } |
| 86 | 100 |
| 87 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { | 101 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { |
| 88 viewport_.SetDesktopSize(width, height); | 102 viewport_.SetDesktopSize(width, height); |
| 89 } | 103 } |
| 90 | 104 |
| 91 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, | 105 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, |
| 92 float translation_y) { | 106 float translation_y) { |
| 93 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, | 107 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, |
| 94 &viewport_); | 108 &viewport_); |
| 109 SetCursorPositionOnRenderStub(); | |
|
nicholss
2017/05/12 21:42:40
I don't think "stub" is the correct term. See http
Yuwei
2017/05/13 00:41:52
Done. Renamed to RendererFacade. We did have Clip
| |
| 95 } | 110 } |
| 96 | 111 |
| 97 void GestureInterpreter::AbortAnimations() { | 112 void GestureInterpreter::AbortAnimations() { |
| 98 pan_animation_.Abort(); | 113 pan_animation_.Abort(); |
| 99 } | 114 } |
| 100 | 115 |
| 101 void GestureInterpreter::InjectMouseClick( | 116 void GestureInterpreter::InjectMouseClick( |
| 102 float x, | 117 float x, |
| 103 float y, | 118 float y, |
| 104 protocol::MouseEvent_MouseButton button) { | 119 protocol::MouseEvent_MouseButton button) { |
| 105 input_stub_->SendMouseEvent(x, y, button, true); | 120 input_stub_->SendMouseEvent(x, y, button, true); |
| 106 input_stub_->SendMouseEvent(x, y, button, false); | 121 input_stub_->SendMouseEvent(x, y, button, false); |
| 107 } | 122 } |
| 108 | 123 |
| 124 void GestureInterpreter::TrackAndGetPosition(float touch_x, | |
| 125 float touch_y, | |
| 126 float* cursor_x, | |
| 127 float* cursor_y) { | |
| 128 input_strategy_->TrackTouchInput(touch_x, touch_y, viewport_); | |
| 129 input_strategy_->GetCursorPosition(cursor_x, cursor_y); | |
| 130 } | |
| 131 | |
| 132 void GestureInterpreter::SetCursorPositionOnRenderStub() { | |
| 133 if (input_strategy_->IsCursorVisible()) { | |
| 134 float cursor_x, cursor_y; | |
| 135 input_strategy_->GetCursorPosition(&cursor_x, &cursor_y); | |
| 136 render_stub_->SetCursorPosition(cursor_x, cursor_y); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void GestureInterpreter::StartInputFeedback( | |
| 141 float cursor_x, | |
| 142 float cursor_y, | |
| 143 InputStrategy::InputFeedbackType feedback_type) { | |
| 144 // This radius is on the view's coordinates. Need to be converted to desktop | |
| 145 // coordinate. | |
| 146 float feedback_radius = input_strategy_->GetFeedbackRadius(feedback_type); | |
| 147 if (feedback_radius > 0) { | |
| 148 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving | |
| 149 // the *2 logic inside the renderer. | |
| 150 float diameter_on_desktop = | |
| 151 2.f * feedback_radius / viewport_.GetTransformation().GetScale(); | |
| 152 render_stub_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop); | |
| 153 } | |
| 154 } | |
| 155 | |
| 109 } // namespace remoting | 156 } // namespace remoting |
| OLD | NEW |