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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #import "remoting/client/ios/app/host_view_controller.h" | 9 #import "remoting/client/ios/app/host_view_controller.h" |
| 10 | 10 |
| 11 #import <GLKit/GLKit.h> | 11 #import <GLKit/GLKit.h> |
| 12 #include <memory> | |
| 12 | 13 |
| 14 #include "base/mac/bind_objc_block.h" | |
| 13 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | 15 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" |
| 16 #include "remoting/client/desktop_viewport.h" | |
| 17 #import "remoting/client/ios/client_gestures.h" | |
| 14 #import "remoting/client/ios/session/remoting_client.h" | 18 #import "remoting/client/ios/session/remoting_client.h" |
| 15 | 19 |
| 16 static const CGFloat kFabInset = 15.f; | 20 static const CGFloat kFabInset = 15.f; |
| 17 | 21 |
| 18 @interface HostViewController () { | 22 @interface HostViewController () { |
| 19 RemotingClient* _client; | 23 RemotingClient* _client; |
| 20 MDCFloatingButton* _floatingButton; | 24 MDCFloatingButton* _floatingButton; |
| 25 | |
| 26 // DO NOT pass |_clientGestures| to other objects. | |
| 27 ClientGestures* _clientGestures; | |
| 28 std::unique_ptr<remoting::DesktopViewport> _viewport; | |
| 21 } | 29 } |
| 22 @end | 30 @end |
| 23 | 31 |
| 24 @implementation HostViewController | 32 @implementation HostViewController |
| 25 | 33 |
| 26 - (id)initWithClient:(RemotingClient*)client { | 34 - (id)initWithClient:(RemotingClient*)client { |
| 27 self = [super init]; | 35 self = [super init]; |
| 28 if (self) { | 36 if (self) { |
| 29 _client = client; | 37 _client = client; |
| 30 } | 38 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 [_client.displayHandler onSurfaceCreated:glView]; | 76 [_client.displayHandler onSurfaceCreated:glView]; |
| 69 | 77 |
| 70 // viewDidLayoutSubviews may be called before viewDidAppear, in which case | 78 // viewDidLayoutSubviews may be called before viewDidAppear, in which case |
| 71 // the surface is not ready and onSurfaceChanged will be no-op. | 79 // the surface is not ready and onSurfaceChanged will be no-op. |
| 72 // Call onSurfaceChanged here to cover that case. | 80 // Call onSurfaceChanged here to cover that case. |
| 73 [_client.displayHandler onSurfaceChanged:glView.frame]; | 81 [_client.displayHandler onSurfaceChanged:glView.frame]; |
| 74 } | 82 } |
| 75 | 83 |
| 76 - (void)viewWillAppear:(BOOL)animated { | 84 - (void)viewWillAppear:(BOOL)animated { |
| 77 [super viewWillAppear:animated]; | 85 [super viewWillAppear:animated]; |
| 78 ((GLKView*)self.view).enableSetNeedsDisplay = true; | 86 |
| 87 _viewport.reset(new remoting::DesktopViewport()); | |
|
nicholss
2017/05/03 15:33:50
I would rather see viewport be a part of the displ
Yuwei
2017/05/03 22:28:37
I created a C++ GestureInterpreter in RemotingClie
| |
| 88 | |
| 89 _viewport->RegisterOnTransformationChangedCallback( | |
| 90 base::BindBlockArc(^(const remoting::ViewMatrix& matrix) { | |
| 91 [_client.displayHandler onPixelTransformationChanged:matrix]; | |
| 92 }), | |
| 93 true); | |
| 94 | |
| 95 _client.displayHandler.delegate = self; | |
| 96 | |
| 97 _clientGestures = | |
| 98 [[ClientGestures alloc] initWithView:self.view viewport:_viewport.get()]; | |
| 79 } | 99 } |
| 80 | 100 |
| 81 - (void)viewWillDisappear:(BOOL)animated { | 101 - (void)viewWillDisappear:(BOOL)animated { |
| 82 [super viewWillDisappear:animated]; | 102 [super viewWillDisappear:animated]; |
| 103 | |
| 104 // Explicitly free |client_gestures_| before |_viewport|. This only works if | |
| 105 // |_clientGestures| is only owned by this. | |
| 106 _clientGestures = nil; | |
| 107 _viewport.reset(); | |
| 83 } | 108 } |
| 84 | 109 |
| 85 - (void)viewDidLayoutSubviews { | 110 - (void)viewDidLayoutSubviews { |
| 86 [super viewDidLayoutSubviews]; | 111 [super viewDidLayoutSubviews]; |
| 87 | 112 |
| 88 [_client.displayHandler onSurfaceChanged:((GLKView*)self.view).frame]; | 113 CGRect surfaceFrame = ((GLKView*)self.view).frame; |
|
nicholss
2017/05/03 15:33:50
No need to cast, frame comes from UIView.
Yuwei
2017/05/03 22:28:37
Done.
| |
| 114 [_client.displayHandler onSurfaceChanged:surfaceFrame]; | |
| 115 _viewport->SetSurfaceSize(surfaceFrame.size.width, surfaceFrame.size.height); | |
| 89 | 116 |
| 90 const CGSize& btnSize = _floatingButton.frame.size; | 117 CGSize btnSize = _floatingButton.frame.size; |
| 91 _floatingButton.frame = | 118 _floatingButton.frame = |
| 92 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset, | 119 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset, |
| 93 self.view.frame.size.height - btnSize.height - kFabInset, | 120 self.view.frame.size.height - btnSize.height - kFabInset, |
| 94 btnSize.width, btnSize.height); | 121 btnSize.width, btnSize.height); |
| 95 } | 122 } |
| 96 | 123 |
| 124 #pragma mark - GlDisplayHandlerDelegate | |
| 125 - (void)canvasSizeChanged:(CGSize)size { | |
|
nicholss
2017/05/03 15:33:50
should have a space between the method and the pra
Yuwei
2017/05/03 22:28:37
Done.
| |
| 126 _viewport->SetDesktopSize(size.width, size.height); | |
| 127 } | |
| 128 | |
| 97 #pragma mark - Private | 129 #pragma mark - Private |
| 98 | 130 |
| 99 - (void)didTap:(id)sender { | 131 - (void)didTap:(id)sender { |
| 100 // TODO(nicholss): The FAB is being used to close the window at the moment | 132 // TODO(nicholss): The FAB is being used to close the window at the moment |
| 101 // just as a demo as the integration continues. This will not be the case | 133 // just as a demo as the integration continues. This will not be the case |
| 102 // in the final app. | 134 // in the final app. |
| 103 [self dismissViewControllerAnimated:YES completion:nil]; | 135 [self dismissViewControllerAnimated:YES completion:nil]; |
| 104 } | 136 } |
| 105 | 137 |
| 106 @end | 138 @end |
| OLD | NEW |