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

Side by Side Diff: remoting/client/ui/desktop_viewport.cc

Issue 2891603002: [CRD iOS] Trackpad Input Mode (Closed)
Patch Set: Fix Created 3 years, 7 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 | « remoting/client/ui/desktop_viewport.h ('k') | remoting/client/ui/direct_input_strategy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/desktop_viewport.h" 5 #include "remoting/client/ui/desktop_viewport.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void DesktopViewport::MoveViewport(float dx, float dy) { 53 void DesktopViewport::MoveViewport(float dx, float dy) {
54 MoveViewportWithoutUpdate(dx, dy); 54 MoveViewportWithoutUpdate(dx, dy);
55 UpdateViewport(); 55 UpdateViewport();
56 } 56 }
57 57
58 void DesktopViewport::SetViewportCenter(float x, float y) { 58 void DesktopViewport::SetViewportCenter(float x, float y) {
59 ViewMatrix::Point old_center = GetViewportCenter(); 59 ViewMatrix::Point old_center = GetViewportCenter();
60 MoveViewport(x - old_center.x, y - old_center.y); 60 MoveViewport(x - old_center.x, y - old_center.y);
61 } 61 }
62 62
63 ViewMatrix::Point DesktopViewport::GetViewportCenter() const {
64 if (!IsViewportReady()) {
65 LOG(WARNING) << "Viewport is not ready before getting the viewport center";
66 return {0.f, 0.f};
67 }
68 return desktop_to_surface_transform_.Invert().MapPoint(
69 {surface_size_.x / 2.f, surface_size_.y / 2.f});
70 }
71
72 ViewMatrix::Point DesktopViewport::ConstrainPointToDesktop(
73 const ViewMatrix::Point& point) const {
74 if (!IsViewportReady()) {
75 LOG(WARNING) << "Cannot constrain point to desktop. Viewport is not ready.";
76 return point;
77 }
78
79 return ConstrainPointToBounds({0.f, desktop_size_.x, 0.f, desktop_size_.y},
80 point);
81 }
82
63 void DesktopViewport::RegisterOnTransformationChangedCallback( 83 void DesktopViewport::RegisterOnTransformationChangedCallback(
64 const TransformationCallback& callback, 84 const TransformationCallback& callback,
65 bool run_immediately) { 85 bool run_immediately) {
66 on_transformation_changed_ = callback; 86 on_transformation_changed_ = callback;
67 if (IsViewportReady() && run_immediately) { 87 if (IsViewportReady() && run_immediately) {
68 callback.Run(desktop_to_surface_transform_); 88 callback.Run(desktop_to_surface_transform_);
69 } 89 }
70 } 90 }
71 91
72 const ViewMatrix& DesktopViewport::GetTransformation() const { 92 const ViewMatrix& DesktopViewport::GetTransformation() const {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 225
206 if (bounds.top > bounds.bottom) { 226 if (bounds.top > bounds.bottom) {
207 float desktop_height_center = desktop_size_.y / 2.f; 227 float desktop_height_center = desktop_size_.y / 2.f;
208 bounds.top = desktop_height_center; 228 bounds.top = desktop_height_center;
209 bounds.bottom = desktop_height_center; 229 bounds.bottom = desktop_height_center;
210 } 230 }
211 231
212 return bounds; 232 return bounds;
213 } 233 }
214 234
215 ViewMatrix::Point DesktopViewport::GetViewportCenter() const {
216 return desktop_to_surface_transform_.Invert().MapPoint(
217 {surface_size_.x / 2.f, surface_size_.y / 2.f});
218 }
219
220 void DesktopViewport::MoveViewportWithoutUpdate(float dx, float dy) { 235 void DesktopViewport::MoveViewportWithoutUpdate(float dx, float dy) {
221 // <dx, dy> is defined on desktop's reference frame. Translation must be 236 // <dx, dy> is defined on desktop's reference frame. Translation must be
222 // flipped and scaled. 237 // flipped and scaled.
223 desktop_to_surface_transform_.PostTranslate( 238 desktop_to_surface_transform_.PostTranslate(
224 desktop_to_surface_transform_.MapVector({-dx, -dy})); 239 desktop_to_surface_transform_.MapVector({-dx, -dy}));
225 } 240 }
226 241
227 // static 242 // static
228 ViewMatrix::Point DesktopViewport::ConstrainPointToBounds( 243 ViewMatrix::Point DesktopViewport::ConstrainPointToBounds(
229 const Bounds& bounds, 244 const Bounds& bounds,
230 const ViewMatrix::Point& point) { 245 const ViewMatrix::Point& point) {
231 ViewMatrix::Point new_point = point; 246 ViewMatrix::Point new_point = point;
232 if (new_point.x < bounds.left) { 247 if (new_point.x < bounds.left) {
233 new_point.x = bounds.left; 248 new_point.x = bounds.left;
234 } else if (new_point.x > bounds.right) { 249 } else if (new_point.x > bounds.right) {
235 new_point.x = bounds.right; 250 new_point.x = bounds.right;
236 } 251 }
237 252
238 if (new_point.y < bounds.top) { 253 if (new_point.y < bounds.top) {
239 new_point.y = bounds.top; 254 new_point.y = bounds.top;
240 } else if (new_point.y > bounds.bottom) { 255 } else if (new_point.y > bounds.bottom) {
241 new_point.y = bounds.bottom; 256 new_point.y = bounds.bottom;
242 } 257 }
243 return new_point; 258 return new_point;
244 } 259 }
245 260
246 } // namespace remoting 261 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/ui/desktop_viewport.h ('k') | remoting/client/ui/direct_input_strategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698