| 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/infobars/infobar_view.h" | 5 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
| 6 | 6 |
| 7 #import <CoreGraphics/CoreGraphics.h> | 7 #import <CoreGraphics/CoreGraphics.h> |
| 8 #import <QuartzCore/QuartzCore.h> | 8 #import <QuartzCore/QuartzCore.h> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 NSRange rangeOfLink = | 757 NSRange rangeOfLink = |
| 758 NSMakeRange(NSMaxRange(startingRange), | 758 NSMakeRange(NSMaxRange(startingRange), |
| 759 endingRange.location - NSMaxRange(startingRange)); | 759 endingRange.location - NSMaxRange(startingRange)); |
| 760 NSString* link = [string substringWithRange:rangeOfLink]; | 760 NSString* link = [string substringWithRange:rangeOfLink]; |
| 761 NSString* afterLink = [string substringFromIndex:NSMaxRange(endingRange)]; | 761 NSString* afterLink = [string substringFromIndex:NSMaxRange(endingRange)]; |
| 762 string = [NSString stringWithFormat:@"%@%@%@", beforeLink, link, afterLink]; | 762 string = [NSString stringWithFormat:@"%@%@%@", beforeLink, link, afterLink]; |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 - (void)addLabel:(NSString*)label { | 766 - (void)addLabel:(NSString*)label { |
| 767 [self addLabel:label target:nil action:nil]; | 767 [self addLabel:label action:nil]; |
| 768 } | 768 } |
| 769 | 769 |
| 770 - (void)addLabel:(NSString*)text target:(id)target action:(SEL)action { | 770 - (void)addLabel:(NSString*)text action:(void (^)(NSUInteger))action { |
| 771 markedLabel_.reset([text copy]); | 771 markedLabel_.reset([text copy]); |
| 772 if (target) | 772 if (action) |
| 773 text = [self stripMarkersFromString:text]; | 773 text = [self stripMarkersFromString:text]; |
| 774 if ([label_ superview]) { | 774 if ([label_ superview]) { |
| 775 [label_ removeFromSuperview]; | 775 [label_ removeFromSuperview]; |
| 776 } | 776 } |
| 777 | 777 |
| 778 label_ = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | 778 label_ = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; |
| 779 | 779 |
| 780 UIFont* font = [MDCTypography subheadFont]; | 780 UIFont* font = [MDCTypography subheadFont]; |
| 781 | 781 |
| 782 [label_ setBackgroundColor:[UIColor clearColor]]; | 782 [label_ setBackgroundColor:[UIColor clearColor]]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 793 | 793 |
| 794 [label_ setAttributedText:[[[NSAttributedString alloc] | 794 [label_ setAttributedText:[[[NSAttributedString alloc] |
| 795 initWithString:text | 795 initWithString:text |
| 796 attributes:attributes] autorelease]]; | 796 attributes:attributes] autorelease]]; |
| 797 | 797 |
| 798 [self addSubview:label_]; | 798 [self addSubview:label_]; |
| 799 | 799 |
| 800 if (linkRanges_.empty()) | 800 if (linkRanges_.empty()) |
| 801 return; | 801 return; |
| 802 | 802 |
| 803 DCHECK([target respondsToSelector:action]); | |
| 804 | |
| 805 labelLinkController_.reset([[LabelLinkController alloc] | 803 labelLinkController_.reset([[LabelLinkController alloc] |
| 806 initWithLabel:label_ | 804 initWithLabel:label_ |
| 807 action:^(const GURL& gurl) { | 805 action:^(const GURL& gurl) { |
| 808 NSUInteger actionTag = [base::SysUTF8ToNSString( | 806 if (action) { |
| 809 gurl.ExtractFileName()) integerValue]; | 807 NSUInteger actionTag = [base::SysUTF8ToNSString( |
| 810 [target performSelector:action withObject:@(actionTag)]; | 808 gurl.ExtractFileName()) integerValue]; |
| 809 action(actionTag); |
| 810 } |
| 811 }]); | 811 }]); |
| 812 | 812 |
| 813 [labelLinkController_ setLinkUnderlineStyle:NSUnderlineStyleSingle]; | 813 [labelLinkController_ setLinkUnderlineStyle:NSUnderlineStyleSingle]; |
| 814 [labelLinkController_ setLinkColor:[UIColor blackColor]]; | 814 [labelLinkController_ setLinkColor:[UIColor blackColor]]; |
| 815 | 815 |
| 816 std::vector<std::pair<NSUInteger, NSRange>>::const_iterator it; | 816 std::vector<std::pair<NSUInteger, NSRange>>::const_iterator it; |
| 817 for (it = linkRanges_.begin(); it != linkRanges_.end(); ++it) { | 817 for (it = linkRanges_.begin(); it != linkRanges_.end(); ++it) { |
| 818 // The last part of the URL contains the tag, so it can be retrieved in the | 818 // The last part of the URL contains the tag, so it can be retrieved in the |
| 819 // callback. This tag is generally a command ID. | 819 // callback. This tag is generally a command ID. |
| 820 std::string url = std::string(kChromeInfobarURL) + | 820 std::string url = std::string(kChromeInfobarURL) + |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 | 945 |
| 946 - (CGFloat)buttonMargin { | 946 - (CGFloat)buttonMargin { |
| 947 return kButtonMargin; | 947 return kButtonMargin; |
| 948 } | 948 } |
| 949 | 949 |
| 950 - (const std::vector<std::pair<NSUInteger, NSRange>>&)linkRanges { | 950 - (const std::vector<std::pair<NSUInteger, NSRange>>&)linkRanges { |
| 951 return linkRanges_; | 951 return linkRanges_; |
| 952 } | 952 } |
| 953 | 953 |
| 954 @end | 954 @end |
| OLD | NEW |