| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 6 #error "This file requires ARC support." | |
| 7 #endif | |
| 8 | |
| 9 #import "remoting/client/ios/app/host_view_controller.h" | |
| 10 | |
| 11 #include <memory> | |
| 12 | |
| 13 #import <GLKit/GLKit.h> | |
| 14 | |
| 15 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | |
| 16 #import "remoting/client/ios/client_gestures.h" | |
| 17 #import "remoting/client/ios/session/remoting_client.h" | |
| 18 | |
| 19 #include "remoting/client/gesture_interpreter.h" | |
| 20 | |
| 21 static const CGFloat kFabInset = 15.f; | |
| 22 | |
| 23 @interface HostViewController () { | |
| 24 RemotingClient* _client; | |
| 25 MDCFloatingButton* _floatingButton; | |
| 26 | |
| 27 ClientGestures* _clientGestures; | |
| 28 } | |
| 29 @end | |
| 30 | |
| 31 @implementation HostViewController | |
| 32 | |
| 33 - (id)initWithClient:(RemotingClient*)client { | |
| 34 self = [super init]; | |
| 35 if (self) { | |
| 36 _client = client; | |
| 37 } | |
| 38 return self; | |
| 39 } | |
| 40 | |
| 41 #pragma mark - UIViewController | |
| 42 | |
| 43 - (void)loadView { | |
| 44 self.view = [[GLKView alloc] initWithFrame:CGRectZero]; | |
| 45 } | |
| 46 | |
| 47 - (void)viewDidLoad { | |
| 48 [super viewDidLoad]; | |
| 49 _floatingButton = | |
| 50 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; | |
| 51 [_floatingButton setTitle:@"+" forState:UIControlStateNormal]; | |
| 52 [_floatingButton addTarget:self | |
| 53 action:@selector(didTap:) | |
| 54 forControlEvents:UIControlEventTouchUpInside]; | |
| 55 | |
| 56 UIImage* settingsImage = [UIImage imageNamed:@"Settings"]; | |
| 57 [_floatingButton setImage:settingsImage forState:UIControlStateNormal]; | |
| 58 [_floatingButton sizeToFit]; | |
| 59 [self.view addSubview:_floatingButton]; | |
| 60 } | |
| 61 | |
| 62 - (void)viewDidUnload { | |
| 63 [super viewDidUnload]; | |
| 64 // TODO(nicholss): There needs to be a hook to tell the client we are done. | |
| 65 } | |
| 66 | |
| 67 - (BOOL)prefersStatusBarHidden { | |
| 68 return YES; | |
| 69 } | |
| 70 | |
| 71 - (void)viewDidAppear:(BOOL)animated { | |
| 72 [super viewDidAppear:animated]; | |
| 73 GLKView* glView = (GLKView*)self.view; | |
| 74 glView.context = [_client.displayHandler GetEAGLContext]; | |
| 75 [_client.displayHandler onSurfaceCreated:glView]; | |
| 76 | |
| 77 // viewDidLayoutSubviews may be called before viewDidAppear, in which case | |
| 78 // the surface is not ready and onSurfaceChanged will be no-op. | |
| 79 // Call onSurfaceChanged here to cover that case. | |
| 80 [_client surfaceChanged:self.view.frame]; | |
| 81 } | |
| 82 | |
| 83 - (void)viewWillAppear:(BOOL)animated { | |
| 84 [super viewWillAppear:animated]; | |
| 85 | |
| 86 _clientGestures = | |
| 87 [[ClientGestures alloc] initWithView:self.view client:_client]; | |
| 88 } | |
| 89 | |
| 90 - (void)viewWillDisappear:(BOOL)animated { | |
| 91 [super viewWillDisappear:animated]; | |
| 92 | |
| 93 _clientGestures = nil; | |
| 94 } | |
| 95 | |
| 96 - (void)viewDidLayoutSubviews { | |
| 97 [super viewDidLayoutSubviews]; | |
| 98 | |
| 99 [_client surfaceChanged:self.view.frame]; | |
| 100 | |
| 101 CGSize btnSize = _floatingButton.frame.size; | |
| 102 _floatingButton.frame = | |
| 103 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset, | |
| 104 self.view.frame.size.height - btnSize.height - kFabInset, | |
| 105 btnSize.width, btnSize.height); | |
| 106 } | |
| 107 | |
| 108 #pragma mark - Private | |
| 109 | |
| 110 - (void)didTap:(id)sender { | |
| 111 // TODO(nicholss): The FAB is being used to close the window at the moment | |
| 112 // just as a demo as the integration continues. This will not be the case | |
| 113 // in the final app. | |
| 114 [_client disconnectFromHost]; | |
| 115 [self dismissViewControllerAnimated:YES completion:nil]; | |
| 116 } | |
| 117 | |
| 118 @end | |
| OLD | NEW |