Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Unified Diff: ios/chrome/browser/ui/background_generator.mm

Issue 1058933002: [iOS] Upstream //ios/chrome/browser/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@upstreamMemory
Patch Set: Review comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/background_generator.h ('k') | ios/chrome/browser/ui/file_locations.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a115d830106b0a99bacda307e2caf5a9e5f01d5f
--- /dev/null
+++ b/ios/chrome/browser/ui/background_generator.mm
@@ -0,0 +1,57 @@
+// 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"
+
+// This is a utility function that may be used as a standalone helper function
+// to generate a radial gradient UIImage.
+UIImage* GetRadialGradient(CGRect backgroundRect,
+ CGPoint centerPoint,
+ CGFloat radius,
+ CGFloat centerColor,
+ CGFloat outsideColor,
+ UIImage* tileImage,
+ UIImage* logoImage) {
+ UIGraphicsBeginImageContextWithOptions(backgroundRect.size, YES, 0);
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGFloat gradient_colors[4] = {centerColor, 1.0, outsideColor, 1.0};
+ const size_t kColorCount = 2;
+ base::ScopedCFTypeRef<CGColorSpaceRef> grey_space(
+ CGColorSpaceCreateDeviceGray());
+ DCHECK_EQ(2u, CGColorSpaceGetNumberOfComponents(grey_space));
+ 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];
+}
« no previous file with comments | « ios/chrome/browser/ui/background_generator.h ('k') | ios/chrome/browser/ui/file_locations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698