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 @@
# found in the LICENSE file.
source_set("util") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"CRUILabel+AttributeUtils.h",
"CRUILabel+AttributeUtils.mm",
......
......@@ -6,10 +6,13 @@
#import <objc/runtime.h>
#import "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h"
#include "base/logging.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 {
// They key under which to associate the line height with the label.
const void* const kLineHeightKey = &kLineHeightKey;
......@@ -57,15 +60,14 @@ CGFloat GetAssociatedLineHeight(UILabel* label) {
if (!self.text.length || !self.attributedText.string.length)
return;
base::scoped_nsobject<NSMutableAttributedString> newString(
[self.attributedText mutableCopy]);
NSMutableAttributedString* newString = [self.attributedText mutableCopy];
DCHECK([newString length]);
NSParagraphStyle* style = [newString attribute:NSParagraphStyleAttributeName
atIndex:0
effectiveRange:nullptr];
if (!style)
style = [NSParagraphStyle defaultParagraphStyle];
base::scoped_nsobject<NSMutableParagraphStyle> newStyle([style mutableCopy]);
NSMutableParagraphStyle* newStyle = [style mutableCopy];
[newStyle setMinimumLineHeight:lineHeight];
[newStyle setMaximumLineHeight:lineHeight];
[newString addAttribute:NSParagraphStyleAttributeName
......
......@@ -8,11 +8,14 @@
#include "base/i18n/rtl.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/text_frame.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 {
......@@ -26,11 +29,11 @@ CFRange GetValidRangeForTextFrame(CTFrameRef text_frame,
bool is_rtl =
GetEffectiveWritingDirection(string) == NSWritingDirectionRightToLeft;
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));
NSInteger run_idx = is_rtl ? runs.count - 1 : 0;
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);
if (run_range.location == range.location + range.length)
range.length += run_range.length;
......
......@@ -8,6 +8,10 @@
#include "base/strings/string16.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) {
base::string16 converted_text = base::SysNSStringToUTF16(text);
bool has_changed =
......@@ -15,5 +19,5 @@ NSString* AdjustStringForLocaleDirection(NSString* text) {
if (has_changed) {
return base::SysUTF16ToNSString(converted_text);
}
return [[text copy] autorelease];
return [text copy];
}
......@@ -35,7 +35,7 @@ class GURL;
// Sets the link color for any defined links, updating the controlled label's
// 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
// label's attributed text accordingly.
......@@ -43,7 +43,7 @@ class GURL;
// Sets the link font for any defined links, updating the controlled label's
// 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
// the block called for any tapped link.
......
......@@ -6,11 +6,12 @@
#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"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// The key under which LabelObservers are associated with their labels.
const void* const kLabelObserverKey = &kLabelObserverKey;
......@@ -26,11 +27,11 @@ NSString* GetStringValue(id value) {
@interface LabelObserver () {
// The label being observed.
base::WeakNSObject<UILabel> _label;
__weak UILabel* _label;
// Arrays used to store registered actions.
base::scoped_nsobject<NSMutableArray> _styleActions;
base::scoped_nsobject<NSMutableArray> _layoutActions;
base::scoped_nsobject<NSMutableArray> _textActions;
NSMutableArray* _styleActions;
NSMutableArray* _layoutActions;
NSMutableArray* _textActions;
}
// Whether or not observer actions are currently being executed. This is used
......@@ -89,7 +90,7 @@ static NSSet* textKeys;
- (instancetype)initWithLabel:(UILabel*)label {
if ((self = [super init])) {
DCHECK(label);
_label.reset(label);
_label = label;
[self resetLabelAttributes];
}
return self;
......@@ -98,7 +99,6 @@ static NSSet* textKeys;
- (void)dealloc {
objc_setAssociatedObject(_label, kLabelObserverKey, nil,
OBJC_ASSOCIATION_ASSIGN);
[super dealloc];
}
#pragma mark - Public interface
......@@ -111,7 +111,6 @@ static NSSet* textKeys;
observer = [[LabelObserver alloc] initWithLabel:label];
objc_setAssociatedObject(label, kLabelObserverKey, observer,
OBJC_ASSOCIATION_ASSIGN);
[observer autorelease];
}
return observer;
}
......@@ -136,24 +135,24 @@ static NSSet* textKeys;
- (void)addStyleChangedAction:(LabelObserverAction)action {
DCHECK(action);
if (!_styleActions)
_styleActions.reset([[NSMutableArray alloc] init]);
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]);
_styleActions = [[NSMutableArray alloc] init];
LabelObserverAction actionCopy = [action copy];
[_styleActions addObject:actionCopy];
}
- (void)addLayoutChangedAction:(LabelObserverAction)action {
DCHECK(action);
if (!_layoutActions)
_layoutActions.reset([[NSMutableArray alloc] init]);
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]);
_layoutActions = [[NSMutableArray alloc] init];
LabelObserverAction actionCopy = [action copy];
[_layoutActions addObject:actionCopy];
}
- (void)addTextChangedAction:(LabelObserverAction)action {
DCHECK(action);
if (!_textActions)
_textActions.reset([[NSMutableArray alloc] init]);
base::mac::ScopedBlock<LabelObserverAction> actionCopy([action copy]);
_textActions = [[NSMutableArray alloc] init];
LabelObserverAction actionCopy = [action copy];
[_textActions addObject:actionCopy];
}
......@@ -190,8 +189,8 @@ static NSSet* textKeys;
[NSMutableDictionary dictionaryWithCapacity:styleKeys.count];
for (NSString* property in styleKeys)
labelStyle[property] = [_label valueForKey:property];
base::scoped_nsobject<NSAttributedString> attributedText(
[[NSAttributedString alloc] initWithString:[_label text]]);
NSAttributedString* attributedText =
[[NSAttributedString alloc] initWithString:[_label text]];
[_label setAttributedText:attributedText];
for (NSString* property in styleKeys)
[_label setValue:labelStyle[property] forKey:property];
......@@ -204,7 +203,7 @@ static NSSet* textKeys;
if (self.respondingToKVO)
return;
self.respondingToKVO = YES;
DCHECK_EQ(object, _label.get());
DCHECK_EQ(object, _label);
if ([styleKeys containsObject:key]) {
[self performActions:_styleActions];
} else if ([layoutKeys containsObject:key]) {
......
......@@ -29,7 +29,7 @@
// The TextFrame created by |-frameText|. Will be nil before |-frameText| is
// called.
@property(nonatomic, readonly) id<TextFrame> textFrame;
@property(strong, nonatomic, readonly) id<TextFrame> textFrame;
@end
......
......@@ -9,11 +9,14 @@
#include "base/i18n/rtl.h"
#include "base/logging.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/text_frame.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
// 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
......@@ -70,8 +73,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// A TextFrame implementation that is manually created by ManualTextFramer.
@interface ManualTextFrame : NSObject<TextFrame> {
// Backing objects for properties of the same name.
base::scoped_nsobject<NSAttributedString> _string;
base::scoped_nsobject<NSMutableArray> _lines;
NSAttributedString* _string;
NSMutableArray* _lines;
}
// Designated initializer.
......@@ -99,9 +102,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
inBounds:(CGRect)bounds {
if ((self = [super init])) {
DCHECK(string.string.length);
_string.reset([string retain]);
_string = string;
_bounds = bounds;
_lines.reset([[NSMutableArray alloc] init]);
_lines = [[NSMutableArray alloc] init];
}
return self;
}
......@@ -109,11 +112,11 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark Accessors
- (NSAttributedString*)string {
return _string.get();
return _string;
}
- (NSArray*)lines {
return _lines.get();
return _lines;
}
#pragma mark Private
......@@ -121,10 +124,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
- (void)addFramedLineWithLine:(CTLineRef)line
stringRange:(NSRange)stringRange
origin:(CGPoint)origin {
base::scoped_nsobject<FramedLine> framedLine([[FramedLine alloc]
initWithLine:line
stringRange:stringRange
origin:origin]);
FramedLine* framedLine = [[FramedLine alloc] initWithLine:line
stringRange:stringRange
origin:origin];
[_lines addObject:framedLine];
}
......@@ -132,14 +134,10 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark - ManualTextFramer Private Interface
@interface ManualTextFramer () {
// Backing objects for properties of the same name.
base::scoped_nsobject<NSAttributedString> _string;
base::scoped_nsobject<ManualTextFrame> _manualTextFrame;
}
@interface ManualTextFramer ()
// The string passed upon initialization.
@property(nonatomic, readonly) NSAttributedString* string;
@property(strong, nonatomic, readonly) NSAttributedString* string;
// The bounds passed upon initialization.
@property(nonatomic, readonly) CGRect bounds;
......@@ -151,7 +149,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@property(nonatomic, assign) CGFloat remainingHeight;
// 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
// if a new text frame was successfully created.
......@@ -167,7 +165,6 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@interface ParagraphFramer : ManualTextFramer {
// Backing objects for properties of the same name.
base::ScopedCFTypeRef<CTLineRef> _line;
base::scoped_nsobject<NSCharacterSet> _lineEndSet;
}
// The CTLine created from |string|.
......@@ -179,7 +176,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// Character set containing characters that are appropriate for line endings.
// These characters include whitespaces and newlines (denoting a word boundary),
// 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
// updates |currentRun| and |currentGlyphCount|.
......@@ -271,6 +268,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@synthesize currentLineWidth = _currentLineWidth;
@synthesize currentWhitespaceWidth = _currentWhitespaceWidth;
@synthesize isRTL = _isRTL;
@synthesize lineEndSet = _lineEndSet;
- (instancetype)initWithString:(NSAttributedString*)string
inBounds:(CGRect)bounds {
......@@ -343,7 +341,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
NSMutableCharacterSet* lineEndSet =
[NSMutableCharacterSet whitespaceAndNewlineCharacterSet];
[lineEndSet addCharactersInString:@"-\u2013\u2014"];
_lineEndSet.reset([lineEndSet retain]);
_lineEndSet = lineEndSet;
}
return _lineEndSet;
}
......@@ -353,7 +351,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
self.framedGlyphCount = 0;
if ([self runIdxIsValid:runIdx]) {
NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(self.line));
_currentRun = static_cast<CTRunRef>(runs[_runIdx]);
_currentRun = (__bridge CTRunRef)(runs[_runIdx]);
_currentGlyphCount = CTRunGetGlyphCount(self.currentRun);
} else {
_currentRun = nullptr;
......@@ -562,12 +560,14 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
@synthesize bounds = _bounds;
@synthesize boundingWidth = _boundingWidth;
@synthesize remainingHeight = _remainingHeight;
@synthesize string = _string;
@synthesize manualTextFrame = _manualTextFrame;
- (instancetype)initWithString:(NSAttributedString*)string
inBounds:(CGRect)bounds {
if ((self = [super init])) {
DCHECK(string.string.length);
_string.reset([string retain]);
_string = string;
_bounds = bounds;
_boundingWidth = CGRectGetWidth(bounds);
_remainingHeight = CGRectGetHeight(bounds);
......@@ -586,9 +586,9 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
// variables for the top-level ManualTextFramer.
CGRect remainingBounds =
CGRectMake(0, 0, self.boundingWidth, self.remainingHeight);
base::scoped_nsobject<ParagraphFramer> framer([[ParagraphFramer alloc]
initWithString:paragraph
inBounds:remainingBounds]);
ParagraphFramer* framer =
[[ParagraphFramer alloc] initWithString:paragraph
inBounds:remainingBounds];
[framer frameText];
id<TextFrame> frame = [framer textFrame];
DCHECK(frame);
......@@ -611,16 +611,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
#pragma mark Accessors
- (NSAttributedString*)string {
return _string.get();
}
- (ManualTextFrame*)manualTextFrame {
return _manualTextFrame.get();
}
- (id<TextFrame>)textFrame {
return _manualTextFrame.get();
return _manualTextFrame;
}
#pragma mark Private
......@@ -628,8 +620,8 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
- (BOOL)setupManualTextFrame {
if (_manualTextFrame)
return NO;
_manualTextFrame.reset([[ManualTextFrame alloc] initWithString:self.string
inBounds:self.bounds]);
_manualTextFrame =
[[ManualTextFrame alloc] initWithString:self.string inBounds:self.bounds];
return YES;
}
......
......@@ -11,6 +11,10 @@
#import "net/base/mac/url_conversions.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) {
DCHECK(URL.is_valid());
NSData* plainText = [base::SysUTF8ToNSString(URL.spec())
......
......@@ -4,6 +4,10 @@
#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 {
UIView* GenerateSnapshot(UIView* view) {
......@@ -16,7 +20,7 @@ UIView* GenerateSnapshot(UIView* view) {
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
snapshot = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
snapshot = [[UIView alloc] initWithFrame:CGRectZero];
snapshot.layer.contents = static_cast<id>(screenshot.CGImage);
}
return snapshot;
......
......@@ -6,13 +6,16 @@
#include "base/logging.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
@implementation FramedLine {
// Backing object for property of the same name.
base::scoped_nsprotocol<id> _line;
id _line;
}
@synthesize stringRange = _stringRange;
......@@ -27,11 +30,10 @@
// locations, but its length should be equal to |stringRange|.
NSRange lineRange;
if (!base::mac::CFRangeToNSRange(CTLineGetStringRange(line), &lineRange)) {
[self release];
return nil;
}
DCHECK_EQ(lineRange.length, stringRange.length);
_line.reset([static_cast<id>(line) retain]);
_line = (__bridge id)(line);
_stringRange = stringRange;
_origin = origin;
}
......@@ -40,7 +42,7 @@
- (NSString*)description {
return [NSString stringWithFormat:@"%@ line:%@, stringRange:%@, origin:%@",
[super description], _line.get(),
[super description], _line,
NSStringFromRange(_stringRange),
NSStringFromCGPoint(_origin)];
}
......@@ -59,7 +61,7 @@
#pragma mark Accessors
- (CTLineRef)line {
return static_cast<CTLineRef>(_line.get());
return (__bridge CTLineRef)(_line);
}
@end
......@@ -68,9 +70,9 @@
@interface CoreTextTextFrame () {
// Backing object for property of the same name.
base::scoped_nsobject<NSAttributedString> _string;
base::scoped_nsprotocol<id> _frame;
base::scoped_nsobject<NSMutableArray> _lines;
NSAttributedString* _string;
id _frame;
NSMutableArray* _lines;
}
// The CTFrameRef passed on initializaton.
......@@ -90,10 +92,10 @@
frame:(CTFrameRef)frame {
if ((self = [super self])) {
DCHECK(string.string.length);
_string.reset([string retain]);
_string = string;
_bounds = bounds;
DCHECK(frame);
_frame.reset([static_cast<id>(frame) retain]);
_frame = (__bridge id)(frame);
}
return self;
}
......@@ -101,7 +103,7 @@
#pragma mark Accessors
- (NSAttributedString*)string {
return _string.get();
return _string;
}
- (NSRange)framedRange {
......@@ -115,11 +117,11 @@
- (NSArray*)lines {
if (!_lines)
[self createFramedLines];
return _lines.get();
return _lines;
}
- (CTFrameRef)frame {
return static_cast<CTFrameRef>(_frame.get());
return (__bridge CTFrameRef)(_frame);
}
#pragma mark Private
......@@ -128,17 +130,17 @@
NSArray* lines = base::mac::CFToNSCast(CTFrameGetLines(self.frame));
CGPoint origins[lines.count];
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) {
CTLineRef line = static_cast<CTLineRef>(lines[line_idx]);
CTLineRef line = (__bridge CTLineRef)(lines[line_idx]);
NSRange stringRange;
CFRange cfStringRange = CTLineGetStringRange(line);
if (!base::mac::CFRangeToNSRange(cfStringRange, &stringRange))
break;
base::scoped_nsobject<FramedLine> framedLine([[FramedLine alloc]
initWithLine:line
stringRange:stringRange
origin:origins[line_idx]]);
FramedLine* framedLine =
[[FramedLine alloc] initWithLine:line
stringRange:stringRange
origin:origins[line_idx]];
[_lines addObject:framedLine];
}
}
......
......@@ -11,38 +11,41 @@
#include "base/ios/ios_util.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.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/manual_text_framer.h"
#import "ios/chrome/browser/ui/util/text_frame.h"
@interface CoreTextRegionMapper () {
// Backing object for property of the same name.
base::scoped_nsprotocol<id<TextFrame>> _textFrame;
}
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CoreTextRegionMapper ()
// The TextFrame used to calculate rects.
@property(nonatomic, readonly) id<TextFrame> textFrame;
@property(strong, nonatomic, readonly) id<TextFrame> textFrame;
@end
@implementation CoreTextRegionMapper
@synthesize textFrame = _textFrame;
- (instancetype)initWithAttributedString:(NSAttributedString*)string
bounds:(CGRect)bounds {
if ((self = [super init])) {
base::ScopedCFTypeRef<CTFrameRef> ctFrame =
core_text_util::CreateTextFrameForStringInBounds(string, bounds);
base::scoped_nsobject<ManualTextFramer> framer(
[[ManualTextFramer alloc] initWithString:string inBounds:bounds]);
ManualTextFramer* framer =
[[ManualTextFramer alloc] initWithString:string inBounds:bounds];
[framer frameText];
if (core_text_util::IsTextFrameValid(ctFrame, framer, string)) {
_textFrame.reset([[CoreTextTextFrame alloc] initWithString:string
bounds:bounds
frame:ctFrame]);
_textFrame = [[CoreTextTextFrame alloc] initWithString:string
bounds:bounds
frame:ctFrame];
} else {
// Use ManualTextFramer if |ctFrame| is invalid.
_textFrame.reset([[framer textFrame] retain]);
_textFrame = [framer textFrame];
}
DCHECK(self.textFrame);
}
......@@ -54,10 +57,6 @@
return nil;
}
- (id<TextFrame>)textFrame {
return _textFrame.get();
}
- (NSArray*)rectsForRange:(NSRange)range {
NSRange framedRange = self.textFrame.framedRange;
if (!range.length || range.location + range.length > framedRange.length)
......
......@@ -4,6 +4,10 @@
#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 {
UIViewController* TopPresentedViewController() {
......
......@@ -5,12 +5,14 @@
#import "ios/chrome/browser/ui/util/transparent_link_button.h"
#include "base/ios/ios_util.h"
#import "base/ios/weak_nsobject.h"
#import "base/logging.h"
#import "base/mac/scoped_nsobject.h"
#import "base/strings/sys_string_conversions.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.
const CGFloat kLinkTapAreaMinimum = 44.0;
......@@ -21,19 +23,14 @@ const CGFloat kHighlightViewCornerRadius = 2.0;
const CGFloat kHighlightViewBackgroundAlpha = 0.25;
}
@interface TransparentLinkButton () {
// Backing objects for properties of the same name.
base::scoped_nsobject<UIView> _highlightView;
base::WeakNSObject<TransparentLinkButton> _previousLinkButton;
base::WeakNSObject<TransparentLinkButton> _nextLinkButton;
}
@interface TransparentLinkButton ()
// The link frame passed upon initialization.
@property(nonatomic, readonly) CGRect linkFrame;
// Semi-transparent overlay that is shown to highlight the link text when the
// 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.
// These properties are used to populate the highlight state from one button to
......@@ -65,6 +62,9 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
@synthesize URL = _URL;
@synthesize debug = _debug;
@synthesize linkFrame = _linkFrame;
@synthesize highlightView = _highlightView;
@synthesize previousLinkButton = _previousLinkButton;
@synthesize nextLinkButton = _nextLinkButton;
- (instancetype)initWithLinkFrame:(CGRect)linkFrame URL:(const GURL&)URL {
CGFloat linkHeightExpansion =
......@@ -91,22 +91,6 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
#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 {
_debug = debug;
self.layer.borderWidth = _debug ? 1.0 : 0.0;
......@@ -121,7 +105,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
CGRect linkFrame =
[self convertRect:self.linkFrame fromView:self.superview];
linkFrame = CGRectInset(linkFrame, -kHighlightViewCornerRadius, 0);
_highlightView.reset([[UIView alloc] initWithFrame:linkFrame]);
_highlightView = [[UIView alloc] initWithFrame:linkFrame];
[_highlightView
setBackgroundColor:[UIColor
colorWithWhite:0.0
......@@ -130,7 +114,7 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
[_highlightView setClipsToBounds:YES];
[self addSubview:_highlightView];
}
return _highlightView.get();
return _highlightView;
}
- (void)setHighlighted:(BOOL)highlighted {
......@@ -148,12 +132,12 @@ const CGFloat kHighlightViewBackgroundAlpha = 0.25;
accessibilityLabel:(NSString*)label {
if (!linkFrames.count)
return @[];
base::scoped_nsobject<NSMutableArray> buttons(
[[NSMutableArray alloc] initWithCapacity:linkFrames.count]);
NSMutableArray* buttons =
[[NSMutableArray alloc] initWithCapacity:linkFrames.count];
for (NSValue* linkFrameValue in linkFrames) {
CGRect linkFrame = [linkFrameValue CGRectValue];
base::scoped_nsobject<TransparentLinkButton> button(
[[TransparentLinkButton alloc] initWithLinkFrame:linkFrame URL:URL]);
TransparentLinkButton* button =
[[TransparentLinkButton alloc] initWithLinkFrame:linkFrame URL:URL];
TransparentLinkButton* previousButton = [buttons lastObject];
previousButton.nextLinkButton = button;
[button setPreviousLinkButton:previousButton];
......
......@@ -6,6 +6,10 @@
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace unicode_util {
namespace {
// 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