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

Side by Side Diff: ios/chrome/browser/ui/uikit_ui_util.mm

Issue 2602903002: Factor iOS native image loading into a utility function. (Closed)
Patch Set: Fixed BUILD files. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/uikit_ui_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "ios/chrome/browser/ui/uikit_ui_util.h" 5 #import "ios/chrome/browser/ui/uikit_ui_util.h"
6 6
7 #import <Accelerate/Accelerate.h> 7 #import <Accelerate/Accelerate.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #import <QuartzCore/QuartzCore.h> 9 #import <QuartzCore/QuartzCore.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 #import <UIKit/UIKit.h> 12 #import <UIKit/UIKit.h>
13 #include <cmath> 13 #include <cmath>
14 14
15 #include "base/ios/ios_util.h" 15 #include "base/ios/ios_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/mac/foundation_util.h" 17 #include "base/mac/foundation_util.h"
18 #include "ios/chrome/browser/experimental_flags.h" 18 #include "ios/chrome/browser/experimental_flags.h"
19 #include "ios/chrome/browser/ui/rtl_geometry.h"
19 #include "ios/chrome/browser/ui/ui_util.h" 20 #include "ios/chrome/browser/ui/ui_util.h"
20 #include "ios/web/public/web_thread.h" 21 #include "ios/web/public/web_thread.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/l10n/l10n_util_mac.h" 23 #include "ui/base/l10n/l10n_util_mac.h"
24 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/ios/uikit_util.h" 25 #include "ui/gfx/ios/uikit_util.h"
24 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" 26 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h"
25 27
26 #if !defined(__has_feature) || !__has_feature(objc_arc) 28 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support." 29 #error "This file requires ARC support."
28 #endif 30 #endif
29 31
30 namespace { 32 namespace {
31 33
32 // Linearly interpolate between |a| and |b| by fraction |f|. Satisfies 34 // Linearly interpolate between |a| and |b| by fraction |f|. Satisfies
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return NO; 220 return NO;
219 case kCGImageAlphaPremultipliedLast: 221 case kCGImageAlphaPremultipliedLast:
220 case kCGImageAlphaPremultipliedFirst: 222 case kCGImageAlphaPremultipliedFirst:
221 case kCGImageAlphaLast: 223 case kCGImageAlphaLast:
222 case kCGImageAlphaFirst: 224 case kCGImageAlphaFirst:
223 case kCGImageAlphaOnly: 225 case kCGImageAlphaOnly:
224 return YES; 226 return YES;
225 } 227 }
226 } 228 }
227 229
230 UIImage* NativeReversableImage(int imageID, BOOL reversable) {
231 DCHECK(imageID);
232 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
233 UIImage* image = rb.GetNativeImageNamed(imageID).ToUIImage();
234 return (reversable && UseRTLLayout())
235 ? [image imageFlippedForRightToLeftLayoutDirection]
236 : image;
237 }
238
239 UIImage* NativeImage(int imageID) {
240 return NativeReversableImage(imageID, NO);
noyau (Ping after 24h) 2017/01/02 10:11:32 Late driveby: Will this now reverse all images if
marq (ping after 24h) 2017/01/09 09:46:14 NativeImage(image_id) will never reverse the image
241 }
242
228 UIImage* ResizeImage(UIImage* image, 243 UIImage* ResizeImage(UIImage* image,
229 CGSize targetSize, 244 CGSize targetSize,
230 ProjectionMode projectionMode) { 245 ProjectionMode projectionMode) {
231 return ResizeImage(image, targetSize, projectionMode, NO); 246 return ResizeImage(image, targetSize, projectionMode, NO);
232 } 247 }
233 248
234 UIImage* ResizeImage(UIImage* image, 249 UIImage* ResizeImage(UIImage* image,
235 CGSize targetSize, 250 CGSize targetSize,
236 ProjectionMode projectionMode, 251 ProjectionMode projectionMode,
237 BOOL opaque) { 252 BOOL opaque) {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 DCHECK(!gFirstResponder); 654 DCHECK(!gFirstResponder);
640 [[UIApplication sharedApplication] 655 [[UIApplication sharedApplication]
641 sendAction:@selector(cr_markSelfCurrentFirstResponder) 656 sendAction:@selector(cr_markSelfCurrentFirstResponder)
642 to:nil 657 to:nil
643 from:nil 658 from:nil
644 forEvent:nil]; 659 forEvent:nil];
645 UIResponder* firstResponder = gFirstResponder; 660 UIResponder* firstResponder = gFirstResponder;
646 gFirstResponder = nil; 661 gFirstResponder = nil;
647 return firstResponder; 662 return firstResponder;
648 } 663 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/uikit_ui_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698