Commit 632a3f03 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Move free static function to anonymous namespace

The free function GetFallbackImageWithStringAndColor was defined
in the middle of the @implementation part of BaseSpotlightManager
which is confusing (as one would expect to see only methods for
the class defined there).

Move the free function to an anonymous namespace and out of the
class @implementation/@interface parts to make it clearer that
it is not in fact a class method.

Bug: none
Change-Id: Iacc46d73217fa8ca65867150f729fcfdf4fed3ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388320
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803567}
parent bb809f76
...@@ -39,8 +39,41 @@ const CGFloat kFallbackIconSize = 180; ...@@ -39,8 +39,41 @@ const CGFloat kFallbackIconSize = 180;
// Radius of the rounded corner of the fallback icon. // Radius of the rounded corner of the fallback icon.
const CGFloat kFallbackRoundedCorner = 8; const CGFloat kFallbackRoundedCorner = 8;
// Create an image with a rounded square with color |backgroundColor| and
// |string| centered in color |textColor|.
UIImage* GetFallbackImageWithStringAndColor(NSString* string,
UIColor* backgroundColor,
UIColor* textColor) {
CGRect rect = CGRectMake(0, 0, kFallbackIconSize, kFallbackIconSize);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextSetStrokeColorWithColor(context, [textColor CGColor]);
UIBezierPath* rounded =
[UIBezierPath bezierPathWithRoundedRect:rect
cornerRadius:kFallbackRoundedCorner];
[rounded fill];
UIFont* font = [MDCTypography headlineFont];
font = [font fontWithSize:(kFallbackIconSize / 2)];
CGRect textRect = CGRectMake(0, (kFallbackIconSize - [font lineHeight]) / 2,
kFallbackIconSize, [font lineHeight]);
NSMutableParagraphStyle* paragraphStyle =
[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
NSMutableDictionary* attributes = [[NSMutableDictionary alloc] init];
[attributes setValue:font forKey:NSFontAttributeName];
[attributes setValue:textColor forKey:NSForegroundColorAttributeName];
[attributes setValue:paragraphStyle forKey:NSParagraphStyleAttributeName];
[string drawInRect:textRect withAttributes:attributes];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
} }
} // namespace
@interface BaseSpotlightManager () { @interface BaseSpotlightManager () {
// Domain of the spotlight manager. // Domain of the spotlight manager.
spotlight::Domain _spotlightDomain; spotlight::Domain _spotlightDomain;
...@@ -63,12 +96,6 @@ const CGFloat kFallbackRoundedCorner = 8; ...@@ -63,12 +96,6 @@ const CGFloat kFallbackRoundedCorner = 8;
// containing |URL| and |title|. // containing |URL| and |title|.
- (int64_t)getHashForURL:(const GURL&)URL title:(NSString*)title; - (int64_t)getHashForURL:(const GURL&)URL title:(NSString*)title;
// Create an image with a rounded square with color |backgroundColor| and
// |string| centered in color |textColor|.
UIImage* GetFallbackImageWithStringAndColor(NSString* string,
UIColor* backgroundColor,
UIColor* textColor);
// Returns an array of Keywords for Spotlight search. // Returns an array of Keywords for Spotlight search.
- (NSArray*)keywordsForSpotlightItems; - (NSArray*)keywordsForSpotlightItems;
...@@ -165,36 +192,6 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string, ...@@ -165,36 +192,6 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string,
attributeSet:attributeSet]]; attributeSet:attributeSet]];
} }
UIImage* GetFallbackImageWithStringAndColor(NSString* string,
UIColor* backgroundColor,
UIColor* textColor) {
CGRect rect = CGRectMake(0, 0, kFallbackIconSize, kFallbackIconSize);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextSetStrokeColorWithColor(context, [textColor CGColor]);
UIBezierPath* rounded =
[UIBezierPath bezierPathWithRoundedRect:rect
cornerRadius:kFallbackRoundedCorner];
[rounded fill];
UIFont* font = [MDCTypography headlineFont];
font = [font fontWithSize:(kFallbackIconSize / 2)];
CGRect textRect = CGRectMake(0, (kFallbackIconSize - [font lineHeight]) / 2,
kFallbackIconSize, [font lineHeight]);
NSMutableParagraphStyle* paragraphStyle =
[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
NSMutableDictionary* attributes = [[NSMutableDictionary alloc] init];
[attributes setValue:font forKey:NSFontAttributeName];
[attributes setValue:textColor forKey:NSForegroundColorAttributeName];
[attributes setValue:paragraphStyle forKey:NSParagraphStyleAttributeName];
[string drawInRect:textRect withAttributes:attributes];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)refreshItemsWithURL:(const GURL&)URLToRefresh title:(NSString*)title { - (void)refreshItemsWithURL:(const GURL&)URLToRefresh title:(NSString*)title {
NSURL* NSURL = net::NSURLWithGURL(URLToRefresh); NSURL* NSURL = net::NSURLWithGURL(URLToRefresh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment