Commit 8f677050 authored by gambard's avatar gambard Committed by Commit bot

[ObjC ARC] Converts ios/chrome/browser/ui/util:util to ARC.

Automatically generated ARCMigrate commit
Notable issues:static_cast changed to __bridge cast.
BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2819283004
Cr-Commit-Position: refs/heads/master@{#467946}
parent 5db6d158
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
source_set("util") { source_set("util") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"CRUILabel+AttributeUtils.h", "CRUILabel+AttributeUtils.h",
"CRUILabel+AttributeUtils.mm", "CRUILabel+AttributeUtils.mm",
......
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
#import <objc/runtime.h> #import <objc/runtime.h>
#import "base/ios/weak_nsobject.h" #include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/util/label_observer.h" #import "ios/chrome/browser/ui/util/label_observer.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// They key under which to associate the line height with the label. // They key under which to associate the line height with the label.
const void* const kLineHeightKey = &kLineHeightKey; const void* const kLineHeightKey = &kLineHeightKey;
...@@ -57,15 +60,14 @@ CGFloat GetAssociatedLineHeight(UILabel* label) { ...@@ -57,15 +60,14 @@ CGFloat GetAssociatedLineHeight(UILabel* label) {
if (!self.text.length || !self.attributedText.string.length) if (!self.text.length || !self.attributedText.string.length)
return; return;
base::scoped_nsobject<NSMutableAttributedString> newString( NSMutableAttributedString* newString = [self.attributedText mutableCopy];
[self.attributedText mutableCopy]);
DCHECK([newString length]); DCHECK([newString length]);
NSParagraphStyle* style = [newString attribute:NSParagraphStyleAttributeName NSParagraphStyle* style = [newString attribute:NSParagraphStyleAttributeName
atIndex:0 atIndex:0
effectiveRange:nullptr]; effectiveRange:nullptr];
if (!style) if (!style)
style = [NSParagraphStyle defaultParagraphStyle]; style = [NSParagraphStyle defaultParagraphStyle];
base::scoped_nsobject<NSMutableParagraphStyle> newStyle([style mutableCopy]); NSMutableParagraphStyle* newStyle = [style mutableCopy];
[newStyle setMinimumLineHeight:lineHeight]; [newStyle setMinimumLineHeight:lineHeight];
[newStyle setMaximumLineHeight:lineHeight]; [newStyle setMaximumLineHeight:lineHeight];
[newString addAttribute:NSParagraphStyleAttributeName [newString addAttribute:NSParagraphStyleAttributeName
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/util/manual_text_framer.h" #import "ios/chrome/browser/ui/util/manual_text_framer.h"
#import "ios/chrome/browser/ui/util/text_frame.h" #import "ios/chrome/browser/ui/util/text_frame.h"
#import "ios/chrome/browser/ui/util/unicode_util.h" #import "ios/chrome/browser/ui/util/unicode_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace core_text_util { namespace core_text_util {
namespace { namespace {
...@@ -26,11 +29,11 @@ CFRange GetValidRangeForTextFrame(CTFrameRef text_frame, ...@@ -26,11 +29,11 @@ CFRange GetValidRangeForTextFrame(CTFrameRef text_frame,
bool is_rtl = bool is_rtl =
GetEffectiveWritingDirection(string) == NSWritingDirectionRightToLeft; GetEffectiveWritingDirection(string) == NSWritingDirectionRightToLeft;
for (id line_id in base::mac::CFToNSCast(CTFrameGetLines(text_frame))) { for (id line_id in base::mac::CFToNSCast(CTFrameGetLines(text_frame))) {
CTLineRef line = static_cast<CTLineRef>(line_id); CTLineRef line = (__bridge CTLineRef)(line_id);
NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(line)); NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(line));
NSInteger run_idx = is_rtl ? runs.count - 1 : 0; NSInteger run_idx = is_rtl ? runs.count - 1 : 0;
while (run_idx >= 0 && run_idx < static_cast<NSInteger>(runs.count)) { while (run_idx >= 0 && run_idx < static_cast<NSInteger>(runs.count)) {
CTRunRef run = static_cast<CTRunRef>(runs[run_idx]); CTRunRef run = (__bridge CTRunRef)(runs[run_idx]);
CFRange run_range = CTRunGetStringRange(run); CFRange run_range = CTRunGetStringRange(run);
if (run_range.location == range.location + range.length) if (run_range.location == range.location + range.length)
range.length += run_range.length; range.length += run_range.length;
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* AdjustStringForLocaleDirection(NSString* text) { NSString* AdjustStringForLocaleDirection(NSString* text) {
base::string16 converted_text = base::SysNSStringToUTF16(text); base::string16 converted_text = base::SysNSStringToUTF16(text);
bool has_changed = bool has_changed =
...@@ -15,5 +19,5 @@ NSString* AdjustStringForLocaleDirection(NSString* text) { ...@@ -15,5 +19,5 @@ NSString* AdjustStringForLocaleDirection(NSString* text) {
if (has_changed) { if (has_changed) {
return base::SysUTF16ToNSString(converted_text); return base::SysUTF16ToNSString(converted_text);
} }
return [[text copy] autorelease]; return [text copy];
} }
...@@ -35,7 +35,7 @@ class GURL; ...@@ -35,7 +35,7 @@ class GURL;
// Sets the link color for any defined links, updating the controlled label's // Sets the link color for any defined links, updating the controlled label's
// attributed text accordingly. // attributed text accordingly.
@property(nonatomic, assign) UIColor* linkColor; @property(nonatomic, copy) UIColor* linkColor;
// Sets the link underline style for any defined links, updating the controlled // Sets the link underline style for any defined links, updating the controlled
// label's attributed text accordingly. // label's attributed text accordingly.
...@@ -43,7 +43,7 @@ class GURL; ...@@ -43,7 +43,7 @@ class GURL;
// Sets the link font for any defined links, updating the controlled label's // Sets the link font for any defined links, updating the controlled label's
// attributed text accordingly. // attributed text accordingly.
@property(nonatomic, retain) UIFont* linkFont; @property(nonatomic, strong) UIFont* linkFont;
// Creates a new controller for |label|, keeping a strong reference. |action| is // Creates a new controller for |label|, keeping a strong reference. |action| is
// the block called for any tapped link. // the block called for any tapped link.
......
...@@ -8,11 +8,8 @@ ...@@ -8,11 +8,8 @@
#include <vector> #include <vector>
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_block.h"
#import "base/mac/scoped_nsobject.h"
#import "base/strings/sys_string_conversions.h" #import "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/util/label_observer.h" #import "ios/chrome/browser/ui/util/label_observer.h"
...@@ -21,14 +18,15 @@ ...@@ -21,14 +18,15 @@
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#pragma mark - LinkLayout #pragma mark - LinkLayout
// Object encapsulating the range of a link and the frames corresponding with // Object encapsulating the range of a link and the frames corresponding with
// that range. // that range.
@interface LinkLayout : NSObject { @interface LinkLayout : NSObject
// Backing objects for properties of same name.
base::scoped_nsobject<NSArray> _frames;
}
// Designated initializer. // Designated initializer.
- (instancetype)initWithRange:(NSRange)range NS_DESIGNATED_INITIALIZER; - (instancetype)initWithRange:(NSRange)range NS_DESIGNATED_INITIALIZER;
...@@ -38,13 +36,14 @@ ...@@ -38,13 +36,14 @@
@property(nonatomic, readonly) NSRange range; @property(nonatomic, readonly) NSRange range;
// The frames calculated for |_range|. // The frames calculated for |_range|.
@property(nonatomic, retain) NSArray* frames; @property(nonatomic, strong) NSArray* frames;
@end @end
@implementation LinkLayout @implementation LinkLayout
@synthesize range = _range; @synthesize range = _range;
@synthesize frames = _frames;
- (instancetype)initWithRange:(NSRange)range { - (instancetype)initWithRange:(NSRange)range {
if ((self = [super init])) { if ((self = [super init])) {
...@@ -55,31 +54,21 @@ ...@@ -55,31 +54,21 @@
return self; return self;
} }
#pragma mark - Accessors
- (void)setFrames:(NSArray*)frames {
_frames.reset([frames retain]);
}
- (NSArray*)frames {
return _frames.get();
}
@end @end
#pragma mark - LabelLinkController #pragma mark - LabelLinkController
@interface LabelLinkController () @interface LabelLinkController ()
// Private property exposed publically in testing interface. // Private property exposed publically in testing interface.
@property(nonatomic, assign) Class textMapperClass; @property(nonatomic, unsafe_unretained) Class textMapperClass;
// The original attributed text set on the label. This may be different from // The original attributed text set on the label. This may be different from
// the label's |attributedText| property, as additional style attributes may be // the label's |attributedText| property, as additional style attributes may be
// introduced for links. // introduced for links.
@property(nonatomic, readonly) NSAttributedString* originalLabelText; @property(nonatomic, strong, readonly) NSAttributedString* originalLabelText;
// The array of TransparentLinkButtons inserted above the label. // The array of TransparentLinkButtons inserted above the label.
@property(nonatomic, readonly) NSArray* linkButtons; @property(nonatomic, strong, readonly) NSMutableArray* linkButtons;
// Adds LabelObserverActions to the LabelObserver corresponding to |_label|. // Adds LabelObserverActions to the LabelObserver corresponding to |_label|.
- (void)addLabelObserverActions; - (void)addLabelObserverActions;
...@@ -132,73 +121,63 @@ ...@@ -132,73 +121,63 @@
@implementation LabelLinkController { @implementation LabelLinkController {
// Ivars immutable for the lifetime of the object. // Ivars immutable for the lifetime of the object.
base::mac::ScopedBlock<ProceduralBlockWithURL> _action; ProceduralBlockWithURL _action;
base::scoped_nsobject<UILabel> _label; UILabel* _label;
base::scoped_nsobject<UITapGestureRecognizer> _linkTapRecognizer; UITapGestureRecognizer* _linkTapRecognizer;
// Ivas backing properties.
base::scoped_nsobject<UIColor> _linkColor;
base::scoped_nsobject<UIFont> _linkFont;
// Ivars that reset when label text changes. // Ivars that reset when label text changes.
base::scoped_nsobject<NSMutableDictionary> _layoutsForURLs; NSMutableDictionary* _layoutsForURLs;
base::scoped_nsobject<NSAttributedString> _originalLabelText;
CGRect _lastLabelFrame; CGRect _lastLabelFrame;
// Ivars that reset when text or bounds change. // Ivars that reset when text or bounds change.
base::scoped_nsprotocol<id<TextRegionMapper>> _textMapper; id<TextRegionMapper> _textMapper;
// Internal tracking. // Internal tracking.
BOOL _justUpdatedStyles; BOOL _justUpdatedStyles;
base::scoped_nsobject<NSMutableArray> _linkButtons; LabelObserver* _labelObserver;
base::scoped_nsobject<LabelObserver> _labelObserver;
} }
@synthesize showTapAreas = _showTapAreas; @synthesize showTapAreas = _showTapAreas;
@synthesize textMapperClass = _textMapperClass; @synthesize textMapperClass = _textMapperClass;
@synthesize linkUnderlineStyle = _linkUnderlineStyle; @synthesize linkUnderlineStyle = _linkUnderlineStyle;
@synthesize linkButtons = _linkButtons;
@synthesize originalLabelText = _originalLabelText;
@synthesize linkFont = _linkFont;
@synthesize linkColor = _linkColor;
- (instancetype)initWithLabel:(UILabel*)label - (instancetype)initWithLabel:(UILabel*)label
action:(ProceduralBlockWithURL)action { action:(ProceduralBlockWithURL)action {
if ((self = [super init])) { if ((self = [super init])) {
DCHECK(label); DCHECK(label);
_label.reset([label retain]); _label = label;
_action.reset(action, base::scoped_policy::RETAIN); _action = [action copy];
_linkUnderlineStyle = NSUnderlineStyleNone; _linkUnderlineStyle = NSUnderlineStyleNone;
[self reset]; [self reset];
_labelObserver.reset([[LabelObserver observerForLabel:_label] retain]); _labelObserver = [LabelObserver observerForLabel:_label];
[_labelObserver startObserving]; [_labelObserver startObserving];
[self addLabelObserverActions]; [self addLabelObserverActions];
self.textMapperClass = [CoreTextRegionMapper class]; self.textMapperClass = [CoreTextRegionMapper class];
_linkButtons.reset([[NSMutableArray alloc] init]); _linkButtons = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
- (NSAttributedString*)originalLabelText {
return _originalLabelText.get();
}
- (NSArray*)linkButtons {
return _linkButtons.get();
}
- (void)addLabelObserverActions { - (void)addLabelObserverActions {
base::WeakNSObject<LabelLinkController> weakSelf(self); __weak LabelLinkController* weakSelf = self;
[_labelObserver addStyleChangedAction:^(UILabel* label) { [_labelObserver addStyleChangedAction:^(UILabel* label) {
// One of the style properties has been changed, which will silently // One of the style properties has been changed, which will silently
// update the label's attributedText. // update the label's attributedText.
if (!weakSelf) if (!weakSelf)
return; return;
base::scoped_nsobject<LabelLinkController> strongSelf([weakSelf retain]); LabelLinkController* strongSelf = weakSelf;
[strongSelf labelStyleInvalidated]; [strongSelf labelStyleInvalidated];
}]; }];
[_labelObserver addTextChangedAction:^(UILabel* label) { [_labelObserver addTextChangedAction:^(UILabel* label) {
if (!weakSelf) if (!weakSelf)
return; return;
base::scoped_nsobject<LabelLinkController> strongSelf([weakSelf retain]); LabelLinkController* strongSelf = weakSelf;
NSString* originalText = [[strongSelf originalLabelText] string]; NSString* originalText = [[strongSelf originalLabelText] string];
if ([label.text isEqualToString:originalText]) { if ([label.text isEqualToString:originalText]) {
// The actual text of the label didn't change, so this was a change to // The actual text of the label didn't change, so this was a change to
...@@ -212,7 +191,7 @@ ...@@ -212,7 +191,7 @@
[_labelObserver addLayoutChangedAction:^(UILabel* label) { [_labelObserver addLayoutChangedAction:^(UILabel* label) {
if (!weakSelf) if (!weakSelf)
return; return;
base::scoped_nsobject<LabelLinkController> strongSelf([weakSelf retain]); LabelLinkController* strongSelf = weakSelf;
[strongSelf labelLayoutInvalidated]; [strongSelf labelLayoutInvalidated];
NSArray* linkButtons = [strongSelf linkButtons]; NSArray* linkButtons = [strongSelf linkButtons];
// If this layout change corresponds to |label|'s moving to a new superview, // If this layout change corresponds to |label|'s moving to a new superview,
...@@ -226,26 +205,20 @@ ...@@ -226,26 +205,20 @@
- (void)dealloc { - (void)dealloc {
[self clearTapButtons]; [self clearTapButtons];
[_labelObserver stopObserving]; [_labelObserver stopObserving];
[super dealloc];
} }
- (void)addLinkWithRange:(NSRange)range url:(GURL)url { - (void)addLinkWithRange:(NSRange)range url:(GURL)url {
DCHECK(url.is_valid()); DCHECK(url.is_valid());
if (!_layoutsForURLs) if (!_layoutsForURLs)
_layoutsForURLs.reset([[NSMutableDictionary alloc] init]); _layoutsForURLs = [[NSMutableDictionary alloc] init];
NSURL* key = net::NSURLWithGURL(url); NSURL* key = net::NSURLWithGURL(url);
base::scoped_nsobject<LinkLayout> layout( LinkLayout* layout = [[LinkLayout alloc] initWithRange:range];
[[LinkLayout alloc] initWithRange:range]);
[_layoutsForURLs setObject:layout forKey:key]; [_layoutsForURLs setObject:layout forKey:key];
[self updateStyles]; [self updateStyles];
} }
- (UIColor*)linkColor {
return _linkColor.get();
}
- (void)setLinkColor:(UIColor*)linkColor { - (void)setLinkColor:(UIColor*)linkColor {
_linkColor.reset([linkColor copy]); _linkColor = [linkColor copy];
[self updateStyles]; [self updateStyles];
} }
...@@ -254,18 +227,14 @@ ...@@ -254,18 +227,14 @@
[self updateStyles]; [self updateStyles];
} }
- (UIFont*)linkFont {
return _linkFont.get();
}
- (void)setLinkFont:(UIFont*)linkFont { - (void)setLinkFont:(UIFont*)linkFont {
_linkFont.reset([linkFont retain]); _linkFont = linkFont;
[self updateStyles]; [self updateStyles];
} }
- (void)setShowTapAreas:(BOOL)showTapAreas { - (void)setShowTapAreas:(BOOL)showTapAreas {
#ifndef NDEBUG #ifndef NDEBUG
for (TransparentLinkButton* button in _linkButtons.get()) { for (TransparentLinkButton* button in _linkButtons) {
button.debug = showTapAreas; button.debug = showTapAreas;
} }
#endif // NDEBUG #endif // NDEBUG
...@@ -275,14 +244,14 @@ ...@@ -275,14 +244,14 @@
#pragma mark - internal methods #pragma mark - internal methods
- (void)reset { - (void)reset {
_originalLabelText.reset([[_label attributedText] copy]); _originalLabelText = [[_label attributedText] copy];
_textMapper.reset(); _textMapper = nil;
_lastLabelFrame = CGRectZero; _lastLabelFrame = CGRectZero;
_layoutsForURLs.reset(); _layoutsForURLs = nil;
} }
- (void)labelLayoutInvalidated { - (void)labelLayoutInvalidated {
_textMapper.reset(); _textMapper = nil;
[self updateTapRects]; [self updateTapRects];
} }
...@@ -297,7 +266,7 @@ ...@@ -297,7 +266,7 @@
// prevents proper style updates after successive label format changes. // prevents proper style updates after successive label format changes.
_justUpdatedStyles = NO; _justUpdatedStyles = NO;
} else if (![_originalLabelText isEqual:[_label attributedText]]) { } else if (![_originalLabelText isEqual:[_label attributedText]]) {
_originalLabelText.reset([[_label attributedText] copy]); _originalLabelText = [[_label attributedText] copy];
[self updateStyles]; [self updateStyles];
} }
_lastLabelFrame = CGRectZero; _lastLabelFrame = CGRectZero;
...@@ -308,8 +277,8 @@ ...@@ -308,8 +277,8 @@
if (![_layoutsForURLs count]) if (![_layoutsForURLs count])
return; return;
__block base::scoped_nsobject<NSMutableAttributedString> labelText( __block NSMutableAttributedString* labelText =
[_originalLabelText mutableCopy]); [_originalLabelText mutableCopy];
[_layoutsForURLs enumerateKeysAndObjectsUsingBlock:^( [_layoutsForURLs enumerateKeysAndObjectsUsingBlock:^(
NSURL* key, LinkLayout* layout, BOOL* stop) { NSURL* key, LinkLayout* layout, BOOL* stop) {
if (_linkColor) { if (_linkColor) {
...@@ -330,7 +299,7 @@ ...@@ -330,7 +299,7 @@
}]; }];
_justUpdatedStyles = YES; _justUpdatedStyles = YES;
[_label setAttributedText:labelText]; [_label setAttributedText:labelText];
_textMapper.reset(); _textMapper = nil;
} }
- (void)updateTapRects { - (void)updateTapRects {
...@@ -352,7 +321,7 @@ ...@@ -352,7 +321,7 @@
[self resetTextMapper]; [self resetTextMapper];
for (LinkLayout* layout in [_layoutsForURLs allValues]) { for (LinkLayout* layout in [_layoutsForURLs allValues]) {
base::scoped_nsobject<NSMutableArray> frames([[NSMutableArray alloc] init]); NSMutableArray* frames = [[NSMutableArray alloc] init];
NSArray* rects = [_textMapper rectsForRange:layout.range]; NSArray* rects = [_textMapper rectsForRange:layout.range];
for (NSUInteger rectIdx = 0; rectIdx < [rects count]; ++rectIdx) { for (NSUInteger rectIdx = 0; rectIdx < [rects count]; ++rectIdx) {
CGRect frame = [rects[rectIdx] CGRectValue]; CGRect frame = [rects[rectIdx] CGRectValue];
...@@ -366,13 +335,13 @@ ...@@ -366,13 +335,13 @@
- (void)resetTextMapper { - (void)resetTextMapper {
DCHECK([self.textMapperClass conformsToProtocol:@protocol(TextRegionMapper)]); DCHECK([self.textMapperClass conformsToProtocol:@protocol(TextRegionMapper)]);
_textMapper.reset([[self.textMapperClass alloc] _textMapper = [[self.textMapperClass alloc]
initWithAttributedString:[_label attributedText] initWithAttributedString:[_label attributedText]
bounds:[_label bounds]]); bounds:[_label bounds]];
} }
- (void)clearTapButtons { - (void)clearTapButtons {
for (TransparentLinkButton* button in _linkButtons.get()) { for (TransparentLinkButton* button in _linkButtons) {
[button removeFromSuperview]; [button removeFromSuperview];
} }
[_linkButtons removeAllObjects]; [_linkButtons removeAllObjects];
...@@ -388,7 +357,7 @@ ...@@ -388,7 +357,7 @@
// superview, repatriate them. // superview, repatriate them.
if (base::mac::ObjCCast<TransparentLinkButton>(_linkButtons[0]).superview != if (base::mac::ObjCCast<TransparentLinkButton>(_linkButtons[0]).superview !=
[_label superview]) { [_label superview]) {
for (TransparentLinkButton* button in _linkButtons.get()) { for (TransparentLinkButton* button in _linkButtons) {
CGRect newFrame = CGRect newFrame =
[[_label superview] convertRect:button.frame fromView:button]; [[_label superview] convertRect:button.frame fromView:button];
[[_label superview] insertSubview:button aboveSubview:_label]; [[_label superview] insertSubview:button aboveSubview:_label];
...@@ -426,7 +395,7 @@ ...@@ -426,7 +395,7 @@
- (void)linkButtonTapped:(id)sender { - (void)linkButtonTapped:(id)sender {
TransparentLinkButton* button = TransparentLinkButton* button =
base::mac::ObjCCast<TransparentLinkButton>(sender); base::mac::ObjCCast<TransparentLinkButton>(sender);
_action.get()(button.URL); _action(button.URL);
} }
#pragma mark - Test facilitators #pragma mark - Test facilitators
...@@ -443,7 +412,7 @@ ...@@ -443,7 +412,7 @@
for (NSValue* frameValue in layout.frames) { for (NSValue* frameValue in layout.frames) {
CGRect frame = [frameValue CGRectValue]; CGRect frame = [frameValue CGRectValue];
if (CGRectContainsPoint(frame, point)) { if (CGRectContainsPoint(frame, point)) {
_action.get()(net::GURLWithNSURL(key)); _action(net::GURLWithNSURL(key));
*stop = YES; *stop = YES;
break; break;
} }
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
#import <objc/runtime.h> #import <objc/runtime.h>
#import "base/ios/weak_nsobject.h"
#import "base/mac/scoped_block.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// The key under which LabelObservers are associated with their labels. // The key under which LabelObservers are associated with their labels.
const void* const kLabelObserverKey = &kLabelObserverKey; const void* const kLabelObserverKey = &kLabelObserverKey;
...@@ -26,11 +27,11 @@ NSString* GetStringValue(id value) { ...@@ -26,11 +27,11 @@ NSString* GetStringValue(id value) {
@interface LabelObserver () { @interface LabelObserver () {
// The label being observed. // The label being observed.
base::WeakNSObject<UILabel> _label; __weak UILabel* _label;
// Arrays used to store registered actions. // Arrays used to store registered actions.
base::scoped_nsobject<NSMutableArray> _styleActions; NSMutableArray* _styleActions;
base::scoped_nsobject<NSMutableArray> _layoutActions; NSMutableArray* _layoutActions;
base::scoped_nsobject<NSMutableArray> _textActions; NSMutableArray* _textActions;
} }
// Whether or not observer actions are currently being executed. This is used // Whether or not observer actions are currently being executed. This is used
...@@ -89,7 +90,7 @@ static NSSet* textKeys; ...@@ -89,7 +90,7 @@ static NSSet* textKeys;
- (instancetype)initWithLabel:(UILabel*)label { - (instancetype)initWithLabel:(UILabel*)label {
if ((self = [super init])) { if ((self = [super init])) {
DCHECK(label); DCHECK(label);
_label.reset(label); _label = label;
[self resetLabelAttributes]; [self resetLabelAttributes];
} }
return self; return self;
...@@ -98,7 +99,6 @@ static NSSet* textKeys; ...@@ -98,7 +99,6 @@ static NSSet* textKeys;
- (void)dealloc { - (void)dealloc {
objc_setAssociatedObject(_label, kLabelObserverKey, nil, objc_setAssociatedObject(_label, kLabelObserverKey, nil,
OBJC_ASSOCIATION_ASSIGN); OBJC_ASSOCIATION_ASSIGN);
[super dealloc];
} }
#pragma mark - Public interface #pragma mark - Public interface
...@@ -111,7 +111,6 @@ static NSSet* textKeys; ...@@ -111,7 +111,6 @@ static NSSet* textKeys;
observer = [[LabelObserver alloc] initWithLabel:label]; observer = [[LabelObserver alloc] initWithLabel:label];
objc_setAssociatedObject(label, kLabelObserverKey, observer, objc_setAssociatedObject(label, kLabelObserverKey, observer,
OBJC_ASSOCIATION_ASSIGN); OBJC_ASSOCIATION_ASSIGN);
[observer autorelease];
} }
return observer; return observer;
} }
...@@ -136,24 +135,24 @@ static NSSet* textKeys; ...@@ -136,24 +135,24 @@ static NSSet* textKeys;
- (void)addStyleChangedAction:(LabelObserverAction)action { - (void)addStyleChangedAction:(LabelObserverAction)action {
DCHECK(action); DCHECK(action);
if (!_styleActions) if (!_styleActions)
_styleActions.reset([[NSMutableArray alloc] init]); _styleActions = [[NSMutableArray alloc] init];
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]); LabelObserverAction actionCopy = [action copy];
[_styleActions addObject:actionCopy]; [_styleActions addObject:actionCopy];
} }
- (void)addLayoutChangedAction:(LabelObserverAction)action { - (void)addLayoutChangedAction:(LabelObserverAction)action {
DCHECK(action); DCHECK(action);
if (!_layoutActions) if (!_layoutActions)
_layoutActions.reset([[NSMutableArray alloc] init]); _layoutActions = [[NSMutableArray alloc] init];
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]); LabelObserverAction actionCopy = [action copy];
[_layoutActions addObject:actionCopy]; [_layoutActions addObject:actionCopy];
} }
- (void)addTextChangedAction:(LabelObserverAction)action { - (void)addTextChangedAction:(LabelObserverAction)action {
DCHECK(action); DCHECK(action);
if (!_textActions) if (!_textActions)
_textActions.reset([[NSMutableArray alloc] init]); _textActions = [[NSMutableArray alloc] init];
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]); LabelObserverAction actionCopy = [action copy];
[_textActions addObject:actionCopy]; [_textActions addObject:actionCopy];
} }
...@@ -190,8 +189,8 @@ static NSSet* textKeys; ...@@ -190,8 +189,8 @@ static NSSet* textKeys;
[NSMutableDictionary dictionaryWithCapacity:styleKeys.count]; [NSMutableDictionary dictionaryWithCapacity:styleKeys.count];
for (NSString* property in styleKeys) for (NSString* property in styleKeys)
labelStyle[property] = [_label valueForKey:property]; labelStyle[property] = [_label valueForKey:property];
base::scoped_nsobject<NSAttributedString> attributedText( NSAttributedString* attributedText =
[[NSAttributedString alloc] initWithString:[_label text]]); [[NSAttributedString alloc] initWithString:[_label text]];
[_label setAttributedText:attributedText]; [_label setAttributedText:attributedText];
for (NSString* property in styleKeys) for (NSString* property in styleKeys)
[_label setValue:labelStyle[property] forKey:property]; [_label setValue:labelStyle[property] forKey:property];
...@@ -204,7 +203,7 @@ static NSSet* textKeys; ...@@ -204,7 +203,7 @@ static NSSet* textKeys;
if (self.respondingToKVO) if (self.respondingToKVO)
return; return;
self.respondingToKVO = YES; self.respondingToKVO = YES;
DCHECK_EQ(object, _label.get()); DCHECK_EQ(object, _label);
if ([styleKeys containsObject:key]) { if ([styleKeys containsObject:key]) {
[self performActions:_styleActions]; [self performActions:_styleActions];
} else if ([layoutKeys containsObject:key]) { } else if ([layoutKeys containsObject:key]) {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// The TextFrame created by |-frameText|. Will be nil before |-frameText| is // The TextFrame created by |-frameText|. Will be nil before |-frameText| is
// called. // called.
@property(nonatomic, readonly) id<TextFrame> textFrame; @property(strong, nonatomic, readonly) id<TextFrame> textFrame;
@end @end
......
...@@ -9,11 +9,14 @@ ...@@ -9,11 +9,14 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/util/core_text_util.h" #import "ios/chrome/browser/ui/util/core_text_util.h"
#import "ios/chrome/browser/ui/util/text_frame.h" #import "ios/chrome/browser/ui/util/text_frame.h"
#import "ios/chrome/browser/ui/util/unicode_util.h" #import "ios/chrome/browser/ui/util/unicode_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// NOTE: When RTL text is laid out into glyph runs, the glyphs appear in the // NOTE: When RTL text is laid out into glyph runs, the glyphs appear in the
// visual order in which they appear on screen. In other words, the glyphs are // visual order in which they appear on screen. In other words, the glyphs are
// arranged in the reverse order of their corresponding characters in the // arranged in the reverse order of their corresponding characters in the
...@@ -70,8 +73,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -70,8 +73,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// A TextFrame implementation that is manually created by ManualTextFramer. // A TextFrame implementation that is manually created by ManualTextFramer.
@interface ManualTextFrame : NSObject<TextFrame> { @interface ManualTextFrame : NSObject<TextFrame> {
// Backing objects for properties of the same name. // Backing objects for properties of the same name.
base::scoped_nsobject<NSAttributedString> _string; NSAttributedString* _string;
base::scoped_nsobject<NSMutableArray> _lines; NSMutableArray* _lines;
} }
// Designated initializer. // Designated initializer.
...@@ -99,9 +102,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -99,9 +102,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
inBounds:(CGRect)bounds { inBounds:(CGRect)bounds {
if ((self = [super init])) { if ((self = [super init])) {
DCHECK(string.string.length); DCHECK(string.string.length);
_string.reset([string retain]); _string = string;
_bounds = bounds; _bounds = bounds;
_lines.reset([[NSMutableArray alloc] init]); _lines = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
...@@ -109,11 +112,11 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -109,11 +112,11 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark Accessors #pragma mark Accessors
- (NSAttributedString*)string { - (NSAttributedString*)string {
return _string.get(); return _string;
} }
- (NSArray*)lines { - (NSArray*)lines {
return _lines.get(); return _lines;
} }
#pragma mark Private #pragma mark Private
...@@ -121,10 +124,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -121,10 +124,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
- (void)addFramedLineWithLine:(CTLineRef)line - (void)addFramedLineWithLine:(CTLineRef)line
stringRange:(NSRange)stringRange stringRange:(NSRange)stringRange
origin:(CGPoint)origin { origin:(CGPoint)origin {
base::scoped_nsobject<FramedLine> framedLine([[FramedLine alloc] FramedLine* framedLine = [[FramedLine alloc] initWithLine:line
initWithLine:line stringRange:stringRange
stringRange:stringRange origin:origin];
origin:origin]);
[_lines addObject:framedLine]; [_lines addObject:framedLine];
} }
...@@ -132,14 +134,10 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -132,14 +134,10 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark - ManualTextFramer Private Interface #pragma mark - ManualTextFramer Private Interface
@interface ManualTextFramer () { @interface ManualTextFramer ()
// Backing objects for properties of the same name.
base::scoped_nsobject<NSAttributedString> _string;
base::scoped_nsobject<ManualTextFrame> _manualTextFrame;
}
// The string passed upon initialization. // The string passed upon initialization.
@property(nonatomic, readonly) NSAttributedString* string; @property(strong, nonatomic, readonly) NSAttributedString* string;
// The bounds passed upon initialization. // The bounds passed upon initialization.
@property(nonatomic, readonly) CGRect bounds; @property(nonatomic, readonly) CGRect bounds;
...@@ -151,7 +149,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -151,7 +149,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@property(nonatomic, assign) CGFloat remainingHeight; @property(nonatomic, assign) CGFloat remainingHeight;
// The text frame constructed by |-frameText|. // The text frame constructed by |-frameText|.
@property(nonatomic, readonly) ManualTextFrame* manualTextFrame; @property(strong, nonatomic, readonly) ManualTextFrame* manualTextFrame;
// Creates a ManualTextFrame and assigns it to |_manualTextFrame|. Returns YES // Creates a ManualTextFrame and assigns it to |_manualTextFrame|. Returns YES
// if a new text frame was successfully created. // if a new text frame was successfully created.
...@@ -167,7 +165,6 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -167,7 +165,6 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@interface ParagraphFramer : ManualTextFramer { @interface ParagraphFramer : ManualTextFramer {
// Backing objects for properties of the same name. // Backing objects for properties of the same name.
base::ScopedCFTypeRef<CTLineRef> _line; base::ScopedCFTypeRef<CTLineRef> _line;
base::scoped_nsobject<NSCharacterSet> _lineEndSet;
} }
// The CTLine created from |string|. // The CTLine created from |string|.
...@@ -179,7 +176,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -179,7 +176,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// Character set containing characters that are appropriate for line endings. // Character set containing characters that are appropriate for line endings.
// These characters include whitespaces and newlines (denoting a word boundary), // These characters include whitespaces and newlines (denoting a word boundary),
// in addition to line-ending characters like hyphens, em dashes, and en dashes. // in addition to line-ending characters like hyphens, em dashes, and en dashes.
@property(nonatomic, readonly) NSCharacterSet* lineEndSet; @property(strong, nonatomic, readonly) NSCharacterSet* lineEndSet;
// The index of the current run that is being framed. Setting |runIdx| also // The index of the current run that is being framed. Setting |runIdx| also
// updates |currentRun| and |currentGlyphCount|. // updates |currentRun| and |currentGlyphCount|.
...@@ -271,6 +268,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -271,6 +268,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@synthesize currentLineWidth = _currentLineWidth; @synthesize currentLineWidth = _currentLineWidth;
@synthesize currentWhitespaceWidth = _currentWhitespaceWidth; @synthesize currentWhitespaceWidth = _currentWhitespaceWidth;
@synthesize isRTL = _isRTL; @synthesize isRTL = _isRTL;
@synthesize lineEndSet = _lineEndSet;
- (instancetype)initWithString:(NSAttributedString*)string - (instancetype)initWithString:(NSAttributedString*)string
inBounds:(CGRect)bounds { inBounds:(CGRect)bounds {
...@@ -343,7 +341,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -343,7 +341,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
NSMutableCharacterSet* lineEndSet = NSMutableCharacterSet* lineEndSet =
[NSMutableCharacterSet whitespaceAndNewlineCharacterSet]; [NSMutableCharacterSet whitespaceAndNewlineCharacterSet];
[lineEndSet addCharactersInString:@"-\u2013\u2014"]; [lineEndSet addCharactersInString:@"-\u2013\u2014"];
_lineEndSet.reset([lineEndSet retain]); _lineEndSet = lineEndSet;
} }
return _lineEndSet; return _lineEndSet;
} }
...@@ -353,7 +351,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -353,7 +351,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
self.framedGlyphCount = 0; self.framedGlyphCount = 0;
if ([self runIdxIsValid:runIdx]) { if ([self runIdxIsValid:runIdx]) {
NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(self.line)); NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(self.line));
_currentRun = static_cast<CTRunRef>(runs[_runIdx]); _currentRun = (__bridge CTRunRef)(runs[_runIdx]);
_currentGlyphCount = CTRunGetGlyphCount(self.currentRun); _currentGlyphCount = CTRunGetGlyphCount(self.currentRun);
} else { } else {
_currentRun = nullptr; _currentRun = nullptr;
...@@ -562,12 +560,14 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -562,12 +560,14 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@synthesize bounds = _bounds; @synthesize bounds = _bounds;
@synthesize boundingWidth = _boundingWidth; @synthesize boundingWidth = _boundingWidth;
@synthesize remainingHeight = _remainingHeight; @synthesize remainingHeight = _remainingHeight;
@synthesize string = _string;
@synthesize manualTextFrame = _manualTextFrame;
- (instancetype)initWithString:(NSAttributedString*)string - (instancetype)initWithString:(NSAttributedString*)string
inBounds:(CGRect)bounds { inBounds:(CGRect)bounds {
if ((self = [super init])) { if ((self = [super init])) {
DCHECK(string.string.length); DCHECK(string.string.length);
_string.reset([string retain]); _string = string;
_bounds = bounds; _bounds = bounds;
_boundingWidth = CGRectGetWidth(bounds); _boundingWidth = CGRectGetWidth(bounds);
_remainingHeight = CGRectGetHeight(bounds); _remainingHeight = CGRectGetHeight(bounds);
...@@ -586,9 +586,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -586,9 +586,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// variables for the top-level ManualTextFramer. // variables for the top-level ManualTextFramer.
CGRect remainingBounds = CGRect remainingBounds =
CGRectMake(0, 0, self.boundingWidth, self.remainingHeight); CGRectMake(0, 0, self.boundingWidth, self.remainingHeight);
base::scoped_nsobject<ParagraphFramer> framer([[ParagraphFramer alloc] ParagraphFramer* framer =
initWithString:paragraph [[ParagraphFramer alloc] initWithString:paragraph
inBounds:remainingBounds]); inBounds:remainingBounds];
[framer frameText]; [framer frameText];
id<TextFrame> frame = [framer textFrame]; id<TextFrame> frame = [framer textFrame];
DCHECK(frame); DCHECK(frame);
...@@ -611,16 +611,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -611,16 +611,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark Accessors #pragma mark Accessors
- (NSAttributedString*)string {
return _string.get();
}
- (ManualTextFrame*)manualTextFrame {
return _manualTextFrame.get();
}
- (id<TextFrame>)textFrame { - (id<TextFrame>)textFrame {
return _manualTextFrame.get(); return _manualTextFrame;
} }
#pragma mark Private #pragma mark Private
...@@ -628,8 +620,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) { ...@@ -628,8 +620,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
- (BOOL)setupManualTextFrame { - (BOOL)setupManualTextFrame {
if (_manualTextFrame) if (_manualTextFrame)
return NO; return NO;
_manualTextFrame.reset([[ManualTextFrame alloc] initWithString:self.string _manualTextFrame =
inBounds:self.bounds]); [[ManualTextFrame alloc] initWithString:self.string inBounds:self.bounds];
return YES; return YES;
} }
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
void StoreURLInPasteboard(const GURL& URL) { void StoreURLInPasteboard(const GURL& URL) {
DCHECK(URL.is_valid()); DCHECK(URL.is_valid());
NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) NSData* plainText = [base::SysUTF8ToNSString(URL.spec())
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#import "ios/chrome/browser/ui/util/snapshot_util.h" #import "ios/chrome/browser/ui/util/snapshot_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace snapshot_util { namespace snapshot_util {
UIView* GenerateSnapshot(UIView* view) { UIView* GenerateSnapshot(UIView* view) {
...@@ -16,7 +20,7 @@ UIView* GenerateSnapshot(UIView* view) { ...@@ -16,7 +20,7 @@ UIView* GenerateSnapshot(UIView* view) {
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; [view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); UIGraphicsEndImageContext();
snapshot = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; snapshot = [[UIView alloc] initWithFrame:CGRectZero];
snapshot.layer.contents = static_cast<id>(screenshot.CGImage); snapshot.layer.contents = static_cast<id>(screenshot.CGImage);
} }
return snapshot; return snapshot;
......
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#pragma mark - FramedLine #pragma mark - FramedLine
@implementation FramedLine { @implementation FramedLine {
// Backing object for property of the same name. // Backing object for property of the same name.
base::scoped_nsprotocol<id> _line; id _line;
} }
@synthesize stringRange = _stringRange; @synthesize stringRange = _stringRange;
...@@ -27,11 +30,10 @@ ...@@ -27,11 +30,10 @@
// locations, but its length should be equal to |stringRange|. // locations, but its length should be equal to |stringRange|.
NSRange lineRange; NSRange lineRange;
if (!base::mac::CFRangeToNSRange(CTLineGetStringRange(line), &lineRange)) { if (!base::mac::CFRangeToNSRange(CTLineGetStringRange(line), &lineRange)) {
[self release];
return nil; return nil;
} }
DCHECK_EQ(lineRange.length, stringRange.length); DCHECK_EQ(lineRange.length, stringRange.length);
_line.reset([static_cast<id>(line) retain]); _line = (__bridge id)(line);
_stringRange = stringRange; _stringRange = stringRange;
_origin = origin; _origin = origin;
} }
...@@ -40,7 +42,7 @@ ...@@ -40,7 +42,7 @@
- (NSString*)description { - (NSString*)description {
return [NSString stringWithFormat:@"%@ line:%@, stringRange:%@, origin:%@", return [NSString stringWithFormat:@"%@ line:%@, stringRange:%@, origin:%@",
[super description], _line.get(), [super description], _line,
NSStringFromRange(_stringRange), NSStringFromRange(_stringRange),
NSStringFromCGPoint(_origin)]; NSStringFromCGPoint(_origin)];
} }
...@@ -59,7 +61,7 @@ ...@@ -59,7 +61,7 @@
#pragma mark Accessors #pragma mark Accessors
- (CTLineRef)line { - (CTLineRef)line {
return static_cast<CTLineRef>(_line.get()); return (__bridge CTLineRef)(_line);
} }
@end @end
...@@ -68,9 +70,9 @@ ...@@ -68,9 +70,9 @@
@interface CoreTextTextFrame () { @interface CoreTextTextFrame () {
// Backing object for property of the same name. // Backing object for property of the same name.
base::scoped_nsobject<NSAttributedString> _string; NSAttributedString* _string;
base::scoped_nsprotocol<id> _frame; id _frame;
base::scoped_nsobject<NSMutableArray> _lines; NSMutableArray* _lines;
} }
// The CTFrameRef passed on initializaton. // The CTFrameRef passed on initializaton.
...@@ -90,10 +92,10 @@ ...@@ -90,10 +92,10 @@
frame:(CTFrameRef)frame { frame:(CTFrameRef)frame {
if ((self = [super self])) { if ((self = [super self])) {
DCHECK(string.string.length); DCHECK(string.string.length);
_string.reset([string retain]); _string = string;
_bounds = bounds; _bounds = bounds;
DCHECK(frame); DCHECK(frame);
_frame.reset([static_cast<id>(frame) retain]); _frame = (__bridge id)(frame);
} }
return self; return self;
} }
...@@ -101,7 +103,7 @@ ...@@ -101,7 +103,7 @@
#pragma mark Accessors #pragma mark Accessors
- (NSAttributedString*)string { - (NSAttributedString*)string {
return _string.get(); return _string;
} }
- (NSRange)framedRange { - (NSRange)framedRange {
...@@ -115,11 +117,11 @@ ...@@ -115,11 +117,11 @@
- (NSArray*)lines { - (NSArray*)lines {
if (!_lines) if (!_lines)
[self createFramedLines]; [self createFramedLines];
return _lines.get(); return _lines;
} }
- (CTFrameRef)frame { - (CTFrameRef)frame {
return static_cast<CTFrameRef>(_frame.get()); return (__bridge CTFrameRef)(_frame);
} }
#pragma mark Private #pragma mark Private
...@@ -128,17 +130,17 @@ ...@@ -128,17 +130,17 @@
NSArray* lines = base::mac::CFToNSCast(CTFrameGetLines(self.frame)); NSArray* lines = base::mac::CFToNSCast(CTFrameGetLines(self.frame));
CGPoint origins[lines.count]; CGPoint origins[lines.count];
CTFrameGetLineOrigins(self.frame, CFRangeMake(0, 0), origins); CTFrameGetLineOrigins(self.frame, CFRangeMake(0, 0), origins);
_lines.reset([[NSMutableArray alloc] initWithCapacity:lines.count]); _lines = [[NSMutableArray alloc] initWithCapacity:lines.count];
for (NSUInteger line_idx = 0; line_idx < lines.count; ++line_idx) { for (NSUInteger line_idx = 0; line_idx < lines.count; ++line_idx) {
CTLineRef line = static_cast<CTLineRef>(lines[line_idx]); CTLineRef line = (__bridge CTLineRef)(lines[line_idx]);
NSRange stringRange; NSRange stringRange;
CFRange cfStringRange = CTLineGetStringRange(line); CFRange cfStringRange = CTLineGetStringRange(line);
if (!base::mac::CFRangeToNSRange(cfStringRange, &stringRange)) if (!base::mac::CFRangeToNSRange(cfStringRange, &stringRange))
break; break;
base::scoped_nsobject<FramedLine> framedLine([[FramedLine alloc] FramedLine* framedLine =
initWithLine:line [[FramedLine alloc] initWithLine:line
stringRange:stringRange stringRange:stringRange
origin:origins[line_idx]]); origin:origins[line_idx]];
[_lines addObject:framedLine]; [_lines addObject:framedLine];
} }
} }
......
...@@ -11,38 +11,41 @@ ...@@ -11,38 +11,41 @@
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/util/core_text_util.h" #import "ios/chrome/browser/ui/util/core_text_util.h"
#import "ios/chrome/browser/ui/util/manual_text_framer.h" #import "ios/chrome/browser/ui/util/manual_text_framer.h"
#import "ios/chrome/browser/ui/util/text_frame.h" #import "ios/chrome/browser/ui/util/text_frame.h"
@interface CoreTextRegionMapper () { #if !defined(__has_feature) || !__has_feature(objc_arc)
// Backing object for property of the same name. #error "This file requires ARC support."
base::scoped_nsprotocol<id<TextFrame>> _textFrame; #endif
}
@interface CoreTextRegionMapper ()
// The TextFrame used to calculate rects. // The TextFrame used to calculate rects.
@property(nonatomic, readonly) id<TextFrame> textFrame; @property(strong, nonatomic, readonly) id<TextFrame> textFrame;
@end @end
@implementation CoreTextRegionMapper @implementation CoreTextRegionMapper
@synthesize textFrame = _textFrame;
- (instancetype)initWithAttributedString:(NSAttributedString*)string - (instancetype)initWithAttributedString:(NSAttributedString*)string
bounds:(CGRect)bounds { bounds:(CGRect)bounds {
if ((self = [super init])) { if ((self = [super init])) {
base::ScopedCFTypeRef<CTFrameRef> ctFrame = base::ScopedCFTypeRef<CTFrameRef> ctFrame =
core_text_util::CreateTextFrameForStringInBounds(string, bounds); core_text_util::CreateTextFrameForStringInBounds(string, bounds);
base::scoped_nsobject<ManualTextFramer> framer( ManualTextFramer* framer =
[[ManualTextFramer alloc] initWithString:string inBounds:bounds]); [[ManualTextFramer alloc] initWithString:string inBounds:bounds];
[framer frameText]; [framer frameText];
if (core_text_util::IsTextFrameValid(ctFrame, framer, string)) { if (core_text_util::IsTextFrameValid(ctFrame, framer, string)) {
_textFrame.reset([[CoreTextTextFrame alloc] initWithString:string _textFrame = [[CoreTextTextFrame alloc] initWithString:string
bounds:bounds bounds:bounds
frame:ctFrame]); frame:ctFrame];
} else { } else {
// Use ManualTextFramer if |ctFrame| is invalid. // Use ManualTextFramer if |ctFrame| is invalid.
_textFrame.reset([[framer textFrame] retain]); _textFrame = [framer textFrame];
} }
DCHECK(self.textFrame); DCHECK(self.textFrame);
} }
...@@ -54,10 +57,6 @@ ...@@ -54,10 +57,6 @@
return nil; return nil;
} }
- (id<TextFrame>)textFrame {
return _textFrame.get();
}
- (NSArray*)rectsForRange:(NSRange)range { - (NSArray*)rectsForRange:(NSRange)range {
NSRange framedRange = self.textFrame.framedRange; NSRange framedRange = self.textFrame.framedRange;
if (!range.length || range.location + range.length > framedRange.length) if (!range.length || range.location + range.length > framedRange.length)
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#import "ios/chrome/browser/ui/util/top_view_controller.h" #import "ios/chrome/browser/ui/util/top_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace top_view_controller { namespace top_view_controller {
UIViewController* TopPresentedViewController() { UIViewController* TopPresentedViewController() {
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
#import "ios/chrome/browser/ui/util/transparent_link_button.h" #import "ios/chrome/browser/ui/util/transparent_link_button.h"
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#import "base/ios/weak_nsobject.h"
#import "base/logging.h" #import "base/logging.h"
#import "base/mac/scoped_nsobject.h"
#import "base/strings/sys_string_conversions.h" #import "base/strings/sys_string_conversions.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Minimum tap area dimension, as specified by Apple guidelines. // Minimum tap area dimension, as specified by Apple guidelines.
const CGFloat kLinkTapAreaMinimum = 44.0; const CGFloat kLinkTapAreaMinimum = 44.0;
...@@ -21,19 +23,14 @@ const CGFloat kHighlightViewCornerRadius = 2.0; ...@@ -21,19 +23,14 @@ const CGFloat kHighlightViewCornerRadius = 2.0;
const CGFloat kHighlightViewBackgroundAlpha = 0.25; const CGFloat kHighlightViewBackgroundAlpha = 0.25;
} }
@interface TransparentLinkButton () { @interface TransparentLinkButton ()
// Backing objects for properties of the same name.
base::scoped_nsobject<UIView> _highlightView;
base::WeakNSObject<TransparentLinkButton> _previousLinkButton;
base::WeakNSObject<TransparentLinkButton> _nextLinkButton;
}
// The link frame passed upon initialization. // The link frame passed upon initialization.
@property(nonatomic, readonly) CGRect linkFrame; @property(nonatomic, readonly) CGRect linkFrame;
// Semi-transparent overlay that is shown to highlight the link text when the // Semi-transparent overlay that is shown to highlight the link text when the
// button's highlight state is set to YES. // button's highlight state is set to YES.
@property(nonatomic, readonly) UIView* highlightView; @property(nonatomic, strong, readonly) UIView* highlightView;
// Links that span multiple lines require more than one TransparentLinkButton. // Links that span multiple lines require more than one TransparentLinkButton.
// These properties are used to populate the highlight state from one button to // These properties are used to populate the highlight state from one button to
...@@ -65,6 +62,9 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25; ...@@ -65,6 +62,9 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
@synthesize URL = _URL; @synthesize URL = _URL;
@synthesize debug = _debug; @synthesize debug = _debug;
@synthesize linkFrame = _linkFrame; @synthesize linkFrame = _linkFrame;
@synthesize highlightView = _highlightView;
@synthesize previousLinkButton = _previousLinkButton;
@synthesize nextLinkButton = _nextLinkButton;
- (instancetype)initWithLinkFrame:(CGRect)linkFrame URL:(const GURL&)URL { - (instancetype)initWithLinkFrame:(CGRect)linkFrame URL:(const GURL&)URL {
CGFloat linkHeightExpansion = CGFloat linkHeightExpansion =
...@@ -91,22 +91,6 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25; ...@@ -91,22 +91,6 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
#pragma mark - Accessors #pragma mark - Accessors
- (void)setPreviousLinkButton:(TransparentLinkButton*)previousLinkButton {
_previousLinkButton.reset(previousLinkButton);
}
- (TransparentLinkButton*)previousLinkButton {
return _previousLinkButton.get();
}
- (void)setNextLinkButton:(TransparentLinkButton*)nextLinkButton {
_nextLinkButton.reset(nextLinkButton);
}
- (TransparentLinkButton*)nextLinkButton {
return _nextLinkButton.get();
}
- (void)setDebug:(BOOL)debug { - (void)setDebug:(BOOL)debug {
_debug = debug; _debug = debug;
self.layer.borderWidth = _debug ? 1.0 : 0.0; self.layer.borderWidth = _debug ? 1.0 : 0.0;
...@@ -121,7 +105,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25; ...@@ -121,7 +105,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
CGRect linkFrame = CGRect linkFrame =
[self convertRect:self.linkFrame fromView:self.superview]; [self convertRect:self.linkFrame fromView:self.superview];
linkFrame = CGRectInset(linkFrame, -kHighlightViewCornerRadius, 0); linkFrame = CGRectInset(linkFrame, -kHighlightViewCornerRadius, 0);
_highlightView.reset([[UIView alloc] initWithFrame:linkFrame]); _highlightView = [[UIView alloc] initWithFrame:linkFrame];
[_highlightView [_highlightView
setBackgroundColor:[UIColor setBackgroundColor:[UIColor
colorWithWhite:0.0 colorWithWhite:0.0
...@@ -130,7 +114,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25; ...@@ -130,7 +114,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
[_highlightView setClipsToBounds:YES]; [_highlightView setClipsToBounds:YES];
[self addSubview:_highlightView]; [self addSubview:_highlightView];
} }
return _highlightView.get(); return _highlightView;
} }
- (void)setHighlighted:(BOOL)highlighted { - (void)setHighlighted:(BOOL)highlighted {
...@@ -148,12 +132,12 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25; ...@@ -148,12 +132,12 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
accessibilityLabel:(NSString*)label { accessibilityLabel:(NSString*)label {
if (!linkFrames.count) if (!linkFrames.count)
return @[]; return @[];
base::scoped_nsobject<NSMutableArray> buttons( NSMutableArray* buttons =
[[NSMutableArray alloc] initWithCapacity:linkFrames.count]); [[NSMutableArray alloc] initWithCapacity:linkFrames.count];
for (NSValue* linkFrameValue in linkFrames) { for (NSValue* linkFrameValue in linkFrames) {
CGRect linkFrame = [linkFrameValue CGRectValue]; CGRect linkFrame = [linkFrameValue CGRectValue];
base::scoped_nsobject<TransparentLinkButton> button( TransparentLinkButton* button =
[[TransparentLinkButton alloc] initWithLinkFrame:linkFrame URL:URL]); [[TransparentLinkButton alloc] initWithLinkFrame:linkFrame URL:URL];
TransparentLinkButton* previousButton = [buttons lastObject]; TransparentLinkButton* previousButton = [buttons lastObject];
previousButton.nextLinkButton = button; previousButton.nextLinkButton = button;
[button setPreviousLinkButton:previousButton]; [button setPreviousLinkButton:previousButton];
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "base/logging.h" #include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace unicode_util { namespace unicode_util {
namespace { namespace {
// Character ranges for characters with R or AL bidirectionality. // Character ranges for characters with R or AL bidirectionality.
......
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