| OLD | NEW |
| (Empty) |
| 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 | |
| 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/utility.h" | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/sys_string_conversions.h" | |
| 14 | |
| 15 @implementation Utility | |
| 16 | |
| 17 + (BOOL)isPad { | |
| 18 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); | |
| 19 } | |
| 20 | |
| 21 + (BOOL)isInLandscapeMode { | |
| 22 UIInterfaceOrientation orientation = | |
| 23 [UIApplication sharedApplication].statusBarOrientation; | |
| 24 | |
| 25 if ((orientation == UIInterfaceOrientationLandscapeLeft) || | |
| 26 (orientation == UIInterfaceOrientationLandscapeRight)) { | |
| 27 return YES; | |
| 28 } | |
| 29 return NO; | |
| 30 } | |
| 31 | |
| 32 + (CGSize)getOrientatedSize:(CGSize)size | |
| 33 shouldWidthBeLongestSide:(BOOL)shouldWidthBeLongestSide { | |
| 34 if (shouldWidthBeLongestSide && (size.height > size.width)) { | |
| 35 return CGSizeMake(size.height, size.width); | |
| 36 } | |
| 37 return size; | |
| 38 } | |
| 39 | |
| 40 + (void)showAlert:(NSString*)title message:(NSString*)message { | |
| 41 UIAlertController* alert; | |
| 42 alert = | |
| 43 [UIAlertController alertControllerWithTitle:title | |
| 44 message:message | |
| 45 preferredStyle:UIAlertControllerStyleAlert]; | |
| 46 | |
| 47 UIAlertAction* defaultAction = | |
| 48 [UIAlertAction actionWithTitle:@"OK" | |
| 49 style:UIAlertActionStyleDefault | |
| 50 handler:^(UIAlertAction* action){ | |
| 51 }]; | |
| 52 | |
| 53 [alert addAction:defaultAction]; | |
| 54 [[UIApplication sharedApplication].delegate.window.rootViewController | |
| 55 presentViewController:alert | |
| 56 animated:YES | |
| 57 completion:nil]; | |
| 58 } | |
| 59 | |
| 60 + (NSString*)appVersionNumberDisplayString { | |
| 61 NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; | |
| 62 | |
| 63 NSString* version = | |
| 64 [infoDictionary objectForKey:@"CFBundleShortVersionString"]; | |
| 65 | |
| 66 return [NSString stringWithFormat:@"Version %@", version]; | |
| 67 } | |
| 68 | |
| 69 + (void)bindTextureForIOS:(GLuint)glName { | |
| 70 glBindTexture(GL_TEXTURE_2D, glName); | |
| 71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 75 } | |
| 76 | |
| 77 + (void)logGLErrorCode:(NSString*)funcName { | |
| 78 GLenum errorCode = 1; | |
| 79 | |
| 80 while (errorCode != 0) { | |
| 81 errorCode = glGetError(); // I don't know why this is returning an error | |
| 82 // on the first call to this function, but if I | |
| 83 // don't read it, then stuff doesn't work... | |
| 84 VLOG_IF(0, errorCode) << "GLerror in " << | |
| 85 [funcName cStringUsingEncoding:NSUTF8StringEncoding] << ": " | |
| 86 << std::hex << errorCode << std::dec; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 + (void)drawSubRectToGLFromRectOfSize:(const webrtc::DesktopSize&)rectSize | |
| 91 subRect:(const webrtc::DesktopRect&)subRect | |
| 92 data:(const uint8_t*)data { | |
| 93 DCHECK(rectSize.width() >= subRect.width()); | |
| 94 DCHECK(rectSize.height() >= subRect.height()); | |
| 95 DCHECK(subRect.left() >= 0); | |
| 96 DCHECK(subRect.top() >= 0); | |
| 97 DCHECK(data); | |
| 98 | |
| 99 glTexSubImage2D(GL_TEXTURE_2D, 0, subRect.left(), subRect.top(), | |
| 100 subRect.width(), subRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, | |
| 101 data); | |
| 102 } | |
| 103 | |
| 104 + (void)moveMouse:(HostProxy*)controller | |
| 105 at:(const webrtc::DesktopVector&)point { | |
| 106 [controller mouseAction:point | |
| 107 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 108 whichButton:0 | |
| 109 buttonDown:NO]; | |
| 110 } | |
| 111 | |
| 112 + (void)leftClickOn:(HostProxy*)controller | |
| 113 at:(const webrtc::DesktopVector&)point { | |
| 114 [controller mouseAction:point | |
| 115 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 116 whichButton:1 | |
| 117 buttonDown:YES]; | |
| 118 [controller mouseAction:point | |
| 119 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 120 whichButton:1 | |
| 121 buttonDown:NO]; | |
| 122 } | |
| 123 | |
| 124 + (void)middleClickOn:(HostProxy*)controller | |
| 125 at:(const webrtc::DesktopVector&)point { | |
| 126 [controller mouseAction:point | |
| 127 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 128 whichButton:2 | |
| 129 buttonDown:YES]; | |
| 130 [controller mouseAction:point | |
| 131 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 132 whichButton:2 | |
| 133 buttonDown:NO]; | |
| 134 } | |
| 135 | |
| 136 + (void)rightClickOn:(HostProxy*)controller | |
| 137 at:(const webrtc::DesktopVector&)point { | |
| 138 [controller mouseAction:point | |
| 139 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 140 whichButton:3 | |
| 141 buttonDown:YES]; | |
| 142 [controller mouseAction:point | |
| 143 wheelDelta:webrtc::DesktopVector(0, 0) | |
| 144 whichButton:3 | |
| 145 buttonDown:NO]; | |
| 146 } | |
| 147 | |
| 148 + (void)mouseScroll:(HostProxy*)controller | |
| 149 at:(const webrtc::DesktopVector&)point | |
| 150 delta:(const webrtc::DesktopVector&)delta { | |
| 151 [controller mouseAction:point wheelDelta:delta whichButton:0 buttonDown:NO]; | |
| 152 } | |
| 153 | |
| 154 + (NSString*)localizedStringForKey:(NSString*)key dummyId:(int)dummyId { | |
| 155 return NSLocalizedString(key, nil); | |
| 156 } | |
| 157 | |
| 158 + (NSString*)stringWithL10nFormat:(NSString*)format | |
| 159 withReplacements:(NSArray*)replacements { | |
| 160 std::string format_str(base::SysNSStringToUTF8(format)); | |
| 161 std::vector<std::string> replacements_str; | |
| 162 | |
| 163 for (NSString* replacement in replacements) { | |
| 164 DCHECK([replacement isKindOfClass:[NSString class]]); | |
| 165 replacements_str.push_back(base::SysNSStringToUTF8(replacement)); | |
| 166 } | |
| 167 | |
| 168 std::string formatted_str( | |
| 169 base::ReplaceStringPlaceholders(format_str, replacements_str, nullptr)); | |
| 170 return base::SysUTF8ToNSString(formatted_str); | |
| 171 } | |
| 172 | |
| 173 @end | |
| OLD | NEW |