Chromium Code Reviews| Index: ios/chrome/browser/ui/background_generator.mm |
| diff --git a/ios/chrome/browser/ui/background_generator.mm b/ios/chrome/browser/ui/background_generator.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b53e799ad0c90678012fc1bbad4315a1e53bddf3 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/background_generator.mm |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/ui/background_generator.h" |
| + |
| +#import <QuartzCore/QuartzCore.h> |
| + |
| +#include "base/mac/bundle_locations.h" |
| +#include "base/mac/foundation_util.h" |
| +#include "base/mac/scoped_cftyperef.h" |
| +#import "base/mac/scoped_nsobject.h" |
| +#import "ios/chrome/browser/ui/ui_util.h" |
| + |
| +namespace background_generator { |
| + |
| +// This is a utility function that may be used as a standalone helper function |
| +// to generate a radial gradient UIImage. |
| +// TODO(blundell): This probably belongs somewhere else now. |
|
sdefresne
2015/04/02 17:20:28
nit: I'd prefer if we could resolve or remove this
|
| +UIImage* GetRadialGradient(CGRect backgroundRect, |
| + CGPoint centerPoint, |
| + CGFloat radius, |
| + CGFloat centerColor, |
| + CGFloat outsideColor, |
| + UIImage* tileImage, |
| + UIImage* logoImage) { |
| + UIGraphicsBeginImageContextWithOptions(backgroundRect.size, YES, 0); |
| + CGContextRef context = UIGraphicsGetCurrentContext(); |
| + const size_t kColorCount = 2; |
| + CGFloat gradient_colors[kColorCount * sizeof(CGFloat)] = { |
|
sdefresne
2015/04/02 17:20:28
This does not make any sense. This is initializing
|
| + centerColor, 1.0, outsideColor, 1.0}; |
| + base::ScopedCFTypeRef<CGColorSpaceRef> grey_space( |
| + CGColorSpaceCreateDeviceGray()); |
| + base::ScopedCFTypeRef<CGGradientRef> gradient( |
| + CGGradientCreateWithColorComponents(grey_space, gradient_colors, nullptr, |
| + kColorCount)); |
| + CGContextDrawRadialGradient(context, gradient, centerPoint, 0, centerPoint, |
| + radius, kCGGradientDrawsAfterEndLocation); |
| + if (tileImage) |
| + [tileImage drawAsPatternInRect:backgroundRect]; |
| + if (logoImage) { |
| + CGPoint corner = AlignPointToPixel( |
| + CGPointMake(centerPoint.x - logoImage.size.width / 2.0, |
| + centerPoint.y - logoImage.size.height / 2.0)); |
| + [logoImage drawAtPoint:corner]; |
| + } |
| + UIImage* background = UIGraphicsGetImageFromCurrentImageContext(); |
| + UIGraphicsEndImageContext(); |
| + return background; |
| +} |
| + |
| +void InstallBackgroundInView(UIView* view) { |
| + UIImageView* imageView = |
| + [[[UIImageView alloc] initWithFrame:view.bounds] autorelease]; |
| + imageView.image = [UIImage imageNamed:@"stack_view_background_noise.jpg"]; |
| + imageView.contentMode = UIViewContentModeScaleAspectFill; |
| + imageView.autoresizingMask = |
| + UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| + [view insertSubview:imageView atIndex:0]; |
| +} |
| + |
| +} // namespace background_generator |