| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/omnibox/truncating_attributed_label.h" | 5 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/objc_property_releaser.h" | 9 #include "base/mac/objc_release_properties.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 | 11 |
| 12 @interface OmniboxPopupTruncatingLabel () | 12 @interface OmniboxPopupTruncatingLabel () |
| 13 - (void)setup; | 13 - (void)setup; |
| 14 - (UIImage*)getLinearGradient:(CGRect)rect; | 14 - (UIImage*)getLinearGradient:(CGRect)rect; |
| 15 @end | 15 @end |
| 16 | 16 |
| 17 @implementation OmniboxPopupTruncatingLabel { | 17 @implementation OmniboxPopupTruncatingLabel { |
| 18 // Attributed text. | 18 // Attributed text. |
| 19 base::scoped_nsobject<CATextLayer> textLayer_; | 19 base::scoped_nsobject<CATextLayer> textLayer_; |
| 20 // Gradient used to create fade effect. Changes based on view.frame size. | 20 // Gradient used to create fade effect. Changes based on view.frame size. |
| 21 base::scoped_nsobject<UIImage> gradient_; | 21 base::scoped_nsobject<UIImage> gradient_; |
| 22 | |
| 23 base::mac::ObjCPropertyReleaser propertyReleaser_OmniboxPopupTruncatingLabel_; | |
| 24 } | 22 } |
| 25 | 23 |
| 26 @synthesize truncateMode = truncateMode_; | 24 @synthesize truncateMode = truncateMode_; |
| 27 @synthesize attributedText = attributedText_; | 25 @synthesize attributedText = attributedText_; |
| 28 @synthesize highlighted = highlighted_; | 26 @synthesize highlighted = highlighted_; |
| 29 @synthesize highlightedText = highlightedText_; | 27 @synthesize highlightedText = highlightedText_; |
| 30 @synthesize textAlignment = textAlignment_; | 28 @synthesize textAlignment = textAlignment_; |
| 31 | 29 |
| 32 - (void)setup { | 30 - (void)setup { |
| 33 self.backgroundColor = [UIColor clearColor]; | 31 self.backgroundColor = [UIColor clearColor]; |
| 34 self.contentMode = UIViewContentModeRedraw; | 32 self.contentMode = UIViewContentModeRedraw; |
| 35 truncateMode_ = OmniboxPopupTruncatingTail; | 33 truncateMode_ = OmniboxPopupTruncatingTail; |
| 36 | 34 |
| 37 // Disable animations in CATextLayer. | 35 // Disable animations in CATextLayer. |
| 38 textLayer_.reset([[CATextLayer layer] retain]); | 36 textLayer_.reset([[CATextLayer layer] retain]); |
| 39 base::scoped_nsobject<NSDictionary> actions([[NSDictionary alloc] | 37 base::scoped_nsobject<NSDictionary> actions([[NSDictionary alloc] |
| 40 initWithObjectsAndKeys:[NSNull null], @"contents", nil]); | 38 initWithObjectsAndKeys:[NSNull null], @"contents", nil]); |
| 41 [textLayer_ setActions:actions]; | 39 [textLayer_ setActions:actions]; |
| 42 [textLayer_ setFrame:self.bounds]; | 40 [textLayer_ setFrame:self.bounds]; |
| 43 [textLayer_ setContentsScale:[[UIScreen mainScreen] scale]]; | 41 [textLayer_ setContentsScale:[[UIScreen mainScreen] scale]]; |
| 44 } | 42 } |
| 45 | 43 |
| 46 - (id)initWithFrame:(CGRect)frame { | 44 - (id)initWithFrame:(CGRect)frame { |
| 47 self = [super initWithFrame:frame]; | 45 self = [super initWithFrame:frame]; |
| 48 if (self) { | 46 if (self) { |
| 49 propertyReleaser_OmniboxPopupTruncatingLabel_.Init( | |
| 50 self, [OmniboxPopupTruncatingLabel class]); | |
| 51 [self setup]; | 47 [self setup]; |
| 52 } | 48 } |
| 53 return self; | 49 return self; |
| 54 } | 50 } |
| 55 | 51 |
| 56 - (void)awakeFromNib { | 52 - (void)awakeFromNib { |
| 57 [super awakeFromNib]; | 53 [super awakeFromNib]; |
| 58 [self setup]; | 54 [self setup]; |
| 59 } | 55 } |
| 60 | 56 |
| 57 - (void)dealloc { |
| 58 base::mac::ReleaseProperties(self); |
| 59 [super dealloc]; |
| 60 } |
| 61 |
| 61 - (void)setFrame:(CGRect)frame { | 62 - (void)setFrame:(CGRect)frame { |
| 62 [super setFrame:frame]; | 63 [super setFrame:frame]; |
| 63 [textLayer_ setFrame:self.bounds]; | 64 [textLayer_ setFrame:self.bounds]; |
| 64 | 65 |
| 65 // Cache the fade gradient when the frame changes. | 66 // Cache the fade gradient when the frame changes. |
| 66 if (!CGRectIsEmpty(frame) && | 67 if (!CGRectIsEmpty(frame) && |
| 67 (!gradient_.get() || !CGSizeEqualToSize([gradient_ size], frame.size))) { | 68 (!gradient_.get() || !CGSizeEqualToSize([gradient_ size], frame.size))) { |
| 68 CGRect rect = CGRectMake(0, 0, frame.size.width, frame.size.height); | 69 CGRect rect = CGRectMake(0, 0, frame.size.width, frame.size.height); |
| 69 gradient_.reset([[self getLinearGradient:rect] retain]); | 70 gradient_.reset([[self getLinearGradient:rect] retain]); |
| 70 } | 71 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 142 |
| 142 // Clean up, return image. | 143 // Clean up, return image. |
| 143 CGImageRef ref = CGBitmapContextCreateImage(context); | 144 CGImageRef ref = CGBitmapContextCreateImage(context); |
| 144 UIImage* image = [UIImage imageWithCGImage:ref]; | 145 UIImage* image = [UIImage imageWithCGImage:ref]; |
| 145 CGImageRelease(ref); | 146 CGImageRelease(ref); |
| 146 CGContextRelease(context); | 147 CGContextRelease(context); |
| 147 return image; | 148 return image; |
| 148 } | 149 } |
| 149 | 150 |
| 150 @end | 151 @end |
| OLD | NEW |