| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/chrome/browser/ui/ui_util.h" | 5 #include "ios/chrome/browser/ui/ui_util.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 CGFloat aspectRatio = originalSize.width / originalSize.height; | 104 CGFloat aspectRatio = originalSize.width / originalSize.height; |
| 105 CGFloat targetAspectRatio = targetSize.width / targetSize.height; | 105 CGFloat targetAspectRatio = targetSize.width / targetSize.height; |
| 106 switch (projectionMode) { | 106 switch (projectionMode) { |
| 107 case ProjectionMode::kFill: | 107 case ProjectionMode::kFill: |
| 108 // Don't preserve the aspect ratio. | 108 // Don't preserve the aspect ratio. |
| 109 projectTo.size = targetSize; | 109 projectTo.size = targetSize; |
| 110 break; | 110 break; |
| 111 | 111 |
| 112 case ProjectionMode::kAspectFill: | 112 case ProjectionMode::kAspectFill: |
| 113 case ProjectionMode::kAspectFillAlignTop: |
| 113 if (targetAspectRatio < aspectRatio) { | 114 if (targetAspectRatio < aspectRatio) { |
| 114 // Clip the x-axis. | 115 // Clip the x-axis. |
| 115 projectTo.size.width = targetSize.height * aspectRatio; | 116 projectTo.size.width = targetSize.height * aspectRatio; |
| 116 projectTo.size.height = targetSize.height; | 117 projectTo.size.height = targetSize.height; |
| 117 projectTo.origin.x = (targetSize.width - projectTo.size.width) / 2; | 118 projectTo.origin.x = (targetSize.width - projectTo.size.width) / 2; |
| 118 projectTo.origin.y = 0; | 119 projectTo.origin.y = 0; |
| 119 } else { | 120 } else { |
| 120 // Clip the y-axis. | 121 // Clip the y-axis. |
| 121 projectTo.size.width = targetSize.width; | 122 projectTo.size.width = targetSize.width; |
| 122 projectTo.size.height = targetSize.width / aspectRatio; | 123 projectTo.size.height = targetSize.width / aspectRatio; |
| 123 projectTo.origin.x = 0; | 124 projectTo.origin.x = 0; |
| 124 projectTo.origin.y = (targetSize.height - projectTo.size.height) / 2; | 125 projectTo.origin.y = (targetSize.height - projectTo.size.height) / 2; |
| 125 } | 126 } |
| 127 if (projectionMode == ProjectionMode::kAspectFillAlignTop) { |
| 128 projectTo.origin.y = 0; |
| 129 } |
| 126 break; | 130 break; |
| 127 | 131 |
| 128 case ProjectionMode::kAspectFit: | 132 case ProjectionMode::kAspectFit: |
| 129 if (targetAspectRatio < aspectRatio) { | 133 if (targetAspectRatio < aspectRatio) { |
| 130 projectTo.size.width = targetSize.width; | 134 projectTo.size.width = targetSize.width; |
| 131 projectTo.size.height = projectTo.size.width / aspectRatio; | 135 projectTo.size.height = projectTo.size.width / aspectRatio; |
| 132 targetSize = projectTo.size; | 136 targetSize = projectTo.size; |
| 133 } else { | 137 } else { |
| 134 projectTo.size.height = targetSize.height; | 138 projectTo.size.height = targetSize.height; |
| 135 projectTo.size.width = projectTo.size.height * aspectRatio; | 139 projectTo.size.width = projectTo.size.height * aspectRatio; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 148 projectTo.size = targetSize; | 152 projectTo.size = targetSize; |
| 149 break; | 153 break; |
| 150 } | 154 } |
| 151 | 155 |
| 152 projectTo = CGRectIntegral(projectTo); | 156 projectTo = CGRectIntegral(projectTo); |
| 153 // There's no CGSizeIntegral, faking one instead. | 157 // There's no CGSizeIntegral, faking one instead. |
| 154 CGRect integralRect = CGRectZero; | 158 CGRect integralRect = CGRectZero; |
| 155 integralRect.size = targetSize; | 159 integralRect.size = targetSize; |
| 156 targetSize = CGRectIntegral(integralRect).size; | 160 targetSize = CGRectIntegral(integralRect).size; |
| 157 } | 161 } |
| OLD | NEW |