Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/omnibox_popup_material_view_controller.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/mac/scoped_nsobject.h" | |
| 12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" | 13 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 15 #include "components/omnibox/browser/autocomplete_input.h" | 14 #include "components/omnibox/browser/autocomplete_input.h" |
| 16 #include "components/omnibox/browser/autocomplete_match.h" | 15 #include "components/omnibox/browser/autocomplete_match.h" |
| 17 #include "components/omnibox/browser/autocomplete_result.h" | 16 #include "components/omnibox/browser/autocomplete_result.h" |
| 18 #include "components/omnibox/browser/suggestion_answer.h" | 17 #include "components/omnibox/browser/suggestion_answer.h" |
| 19 #include "ios/chrome/browser/ui/animation_util.h" | 18 #include "ios/chrome/browser/ui/animation_util.h" |
| 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" | 19 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" |
| 21 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" | 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" |
| 22 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" | 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" |
| 23 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" | 22 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" |
| 24 #include "ios/chrome/browser/ui/rtl_geometry.h" | 23 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 25 #include "ios/chrome/browser/ui/ui_util.h" | 24 #include "ios/chrome/browser/ui/ui_util.h" |
| 26 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 25 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 27 #include "ios/chrome/grit/ios_theme_resources.h" | 26 #include "ios/chrome/grit/ios_theme_resources.h" |
| 28 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | 27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" |
| 29 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" | 28 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" |
| 30 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
| 31 | 30 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 32 #error "This file requires ARC support." | |
| 33 #endif | |
| 34 | |
| 32 namespace { | 35 namespace { |
| 33 const int kRowCount = 6; | 36 const int kRowCount = 6; |
| 34 const CGFloat kRowHeight = 48.0; | 37 const CGFloat kRowHeight = 48.0; |
| 35 const CGFloat kAnswerRowHeight = 64.0; | 38 const CGFloat kAnswerRowHeight = 64.0; |
| 36 const CGFloat kTopAndBottomPadding = 8.0; | 39 const CGFloat kTopAndBottomPadding = 8.0; |
| 37 // The color of the main text of a suggest cell. | 40 // The color of the main text of a suggest cell. |
| 38 UIColor* SuggestionTextColor() { | 41 UIColor* SuggestionTextColor() { |
| 39 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; | 42 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; |
| 40 } | 43 } |
| 41 // The color of the detail text of a suggest cell. | 44 // The color of the detail text of a suggest cell. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 90 |
| 88 OmniboxPopupViewIOS* _popupView; // weak, owns us | 91 OmniboxPopupViewIOS* _popupView; // weak, owns us |
| 89 | 92 |
| 90 // Fetcher for Answers in Suggest images. | 93 // Fetcher for Answers in Suggest images. |
| 91 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher_; | 94 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher_; |
| 92 | 95 |
| 93 // The data source. | 96 // The data source. |
| 94 AutocompleteResult _currentResult; | 97 AutocompleteResult _currentResult; |
| 95 | 98 |
| 96 // Array containing the OmniboxPopupMaterialRow objects displayed in the view. | 99 // Array containing the OmniboxPopupMaterialRow objects displayed in the view. |
| 97 base::scoped_nsobject<NSArray> _rows; | 100 NSArray* _rows; |
| 98 | 101 |
| 99 // The height of the keyboard. Used to determine the content inset for the | 102 // The height of the keyboard. Used to determine the content inset for the |
| 100 // scroll view. | 103 // scroll view. |
| 101 CGFloat keyboardHeight_; | 104 CGFloat keyboardHeight_; |
| 102 } | 105 } |
| 103 | 106 |
| 104 @end | 107 @end |
| 105 | 108 |
| 106 @implementation OmniboxPopupMaterialViewController | 109 @implementation OmniboxPopupMaterialViewController |
| 107 | 110 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 129 name:UIKeyboardDidShowNotification | 132 name:UIKeyboardDidShowNotification |
| 130 object:nil]; | 133 object:nil]; |
| 131 } | 134 } |
| 132 } | 135 } |
| 133 return self; | 136 return self; |
| 134 } | 137 } |
| 135 | 138 |
| 136 - (void)dealloc { | 139 - (void)dealloc { |
| 137 self.tableView.delegate = nil; | 140 self.tableView.delegate = nil; |
| 138 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 141 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 139 [super dealloc]; | |
| 140 } | 142 } |
| 141 | 143 |
| 142 - (UIScrollView*)scrollView { | 144 - (UIScrollView*)scrollView { |
| 143 return (UIScrollView*)self.tableView; | 145 return (UIScrollView*)self.tableView; |
| 144 } | 146 } |
| 145 | 147 |
| 146 - (void)viewDidLoad { | 148 - (void)viewDidLoad { |
| 147 [super viewDidLoad]; | 149 [super viewDidLoad]; |
| 148 | 150 |
| 149 // Initialize the same size as the parent view, autoresize will correct this. | 151 // Initialize the same size as the parent view, autoresize will correct this. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 165 UIFont* bigBoldFont = | 167 UIFont* bigBoldFont = |
| 166 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:bigFont.pointSize]; | 168 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:bigFont.pointSize]; |
| 167 _smallFont.reset(CTFontCreateWithName((CFStringRef)smallFont.fontName, | 169 _smallFont.reset(CTFontCreateWithName((CFStringRef)smallFont.fontName, |
| 168 smallFont.pointSize, NULL)); | 170 smallFont.pointSize, NULL)); |
| 169 _bigFont.reset(CTFontCreateWithName((CFStringRef)bigFont.fontName, | 171 _bigFont.reset(CTFontCreateWithName((CFStringRef)bigFont.fontName, |
| 170 bigFont.pointSize, NULL)); | 172 bigFont.pointSize, NULL)); |
| 171 _smallBoldFont.reset(CTFontCreateWithName((CFStringRef)smallBoldFont.fontName, | 173 _smallBoldFont.reset(CTFontCreateWithName((CFStringRef)smallBoldFont.fontName, |
| 172 smallBoldFont.pointSize, NULL)); | 174 smallBoldFont.pointSize, NULL)); |
| 173 _bigBoldFont.reset(CTFontCreateWithName((CFStringRef)bigBoldFont.fontName, | 175 _bigBoldFont.reset(CTFontCreateWithName((CFStringRef)bigBoldFont.fontName, |
| 174 bigBoldFont.pointSize, NULL)); | 176 bigBoldFont.pointSize, NULL)); |
| 175 NSMutableArray* rowsBuilder = [[[NSMutableArray alloc] init] autorelease]; | 177 NSMutableArray* rowsBuilder = [[NSMutableArray alloc] init]; |
| 176 for (int i = 0; i < kRowCount; i++) { | 178 for (int i = 0; i < kRowCount; i++) { |
| 177 OmniboxPopupMaterialRow* row = [[[OmniboxPopupMaterialRow alloc] | 179 OmniboxPopupMaterialRow* row = |
| 178 initWithIncognito:_incognito] autorelease]; | 180 [[OmniboxPopupMaterialRow alloc] initWithIncognito:_incognito]; |
| 179 row.accessibilityIdentifier = | 181 row.accessibilityIdentifier = |
| 180 [NSString stringWithFormat:@"omnibox suggestion %i", i]; | 182 [NSString stringWithFormat:@"omnibox suggestion %i", i]; |
| 181 row.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 183 row.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
| 182 [rowsBuilder addObject:row]; | 184 [rowsBuilder addObject:row]; |
| 183 [row.appendButton addTarget:self | 185 [row.appendButton addTarget:self |
| 184 action:@selector(appendButtonTapped:) | 186 action:@selector(appendButtonTapped:) |
| 185 forControlEvents:UIControlEventTouchUpInside]; | 187 forControlEvents:UIControlEventTouchUpInside]; |
| 186 [row.appendButton setTag:i]; | 188 [row.appendButton setTag:i]; |
| 187 row.rowHeight = kRowHeight; | 189 row.rowHeight = kRowHeight; |
| 188 } | 190 } |
| 189 _rows.reset([rowsBuilder copy]); | 191 _rows = [rowsBuilder copy]; |
| 190 | 192 |
| 191 // Table configuration. | 193 // Table configuration. |
| 192 self.tableView.allowsMultipleSelectionDuringEditing = NO; | 194 self.tableView.allowsMultipleSelectionDuringEditing = NO; |
| 193 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; | 195 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 194 self.tableView.separatorInset = UIEdgeInsetsZero; | 196 self.tableView.separatorInset = UIEdgeInsetsZero; |
| 195 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { | 197 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { |
| 196 [self.tableView setLayoutMargins:UIEdgeInsetsZero]; | 198 [self.tableView setLayoutMargins:UIEdgeInsetsZero]; |
| 197 } | 199 } |
| 198 self.automaticallyAdjustsScrollViewInsets = NO; | 200 self.automaticallyAdjustsScrollViewInsets = NO; |
| 199 [self.tableView setContentInset:UIEdgeInsetsMake(kTopAndBottomPadding, 0, | 201 [self.tableView setContentInset:UIEdgeInsetsMake(kTopAndBottomPadding, 0, |
| 200 kTopAndBottomPadding, 0)]; | 202 kTopAndBottomPadding, 0)]; |
| 201 } | 203 } |
| 202 | 204 |
| 203 - (void)didReceiveMemoryWarning { | 205 - (void)didReceiveMemoryWarning { |
| 204 [super didReceiveMemoryWarning]; | 206 [super didReceiveMemoryWarning]; |
| 205 if (![self isViewLoaded]) { | 207 if (![self isViewLoaded]) { |
| 206 _smallFont.reset(); | 208 _smallFont.reset(); |
| 207 _bigFont.reset(); | 209 _bigFont.reset(); |
| 208 _smallBoldFont.reset(); | 210 _smallBoldFont.reset(); |
| 209 _bigBoldFont.reset(); | 211 _bigBoldFont.reset(); |
| 210 _rows.reset(); | 212 _rows = nil; |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 214 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { | 216 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { |
| 215 [self layoutRows]; | 217 [self layoutRows]; |
| 216 } | 218 } |
| 217 | 219 |
| 218 #pragma mark - | 220 #pragma mark - |
| 219 #pragma mark Updating data and UI | 221 #pragma mark Updating data and UI |
| 220 | 222 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 frame = detailTextLabel.frame; | 412 frame = detailTextLabel.frame; |
| 411 frame.size.width -= kLTRTextInRTLLayoutLeftPadding - frame.origin.x; | 413 frame.size.width -= kLTRTextInRTLLayoutLeftPadding - frame.origin.x; |
| 412 frame.origin.x = kLTRTextInRTLLayoutLeftPadding; | 414 frame.origin.x = kLTRTextInRTLLayoutLeftPadding; |
| 413 detailTextLabel.frame = frame; | 415 detailTextLabel.frame = frame; |
| 414 } | 416 } |
| 415 } | 417 } |
| 416 | 418 |
| 417 - (NSMutableAttributedString*)attributedStringWithAnswerLine: | 419 - (NSMutableAttributedString*)attributedStringWithAnswerLine: |
| 418 (const SuggestionAnswer::ImageLine&)line { | 420 (const SuggestionAnswer::ImageLine&)line { |
| 419 NSMutableAttributedString* result = | 421 NSMutableAttributedString* result = |
| 420 [[[NSMutableAttributedString alloc] initWithString:@""] autorelease]; | 422 [[NSMutableAttributedString alloc] initWithString:@""]; |
| 421 | 423 |
| 422 for (size_t i = 0; i < line.text_fields().size(); i++) { | 424 for (size_t i = 0; i < line.text_fields().size(); i++) { |
| 423 const SuggestionAnswer::TextField& field = line.text_fields()[i]; | 425 const SuggestionAnswer::TextField& field = line.text_fields()[i]; |
| 424 [result | 426 [result |
| 425 appendAttributedString:[self attributedStringWithString:field.text() | 427 appendAttributedString:[self attributedStringWithString:field.text() |
| 426 type:field.type()]]; | 428 type:field.type()]]; |
| 427 } | 429 } |
| 428 | 430 |
| 429 base::scoped_nsobject<NSAttributedString> spacer( | 431 NSAttributedString* spacer = |
| 430 [[NSAttributedString alloc] initWithString:@" "]); | 432 [[NSAttributedString alloc] initWithString:@" "]; |
| 431 if (line.additional_text() != nil) { | 433 if (line.additional_text() != nil) { |
| 432 const SuggestionAnswer::TextField* field = line.additional_text(); | 434 const SuggestionAnswer::TextField* field = line.additional_text(); |
| 433 [result appendAttributedString:spacer]; | 435 [result appendAttributedString:spacer]; |
| 434 [result | 436 [result |
| 435 appendAttributedString:[self attributedStringWithString:field->text() | 437 appendAttributedString:[self attributedStringWithString:field->text() |
| 436 type:field->type()]]; | 438 type:field->type()]]; |
| 437 } | 439 } |
| 438 | 440 |
| 439 if (line.status_text() != nil) { | 441 if (line.status_text() != nil) { |
| 440 const SuggestionAnswer::TextField* field = line.status_text(); | 442 const SuggestionAnswer::TextField* field = line.status_text(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 NSString* unescapedString = | 524 NSString* unescapedString = |
| 523 base::SysUTF16ToNSString(net::UnescapeForHTML(string)); | 525 base::SysUTF16ToNSString(net::UnescapeForHTML(string)); |
| 524 // TODO(jdonnelly): Remove this tag stripping once the JSON parsing class | 526 // TODO(jdonnelly): Remove this tag stripping once the JSON parsing class |
| 525 // handles HTML tags. | 527 // handles HTML tags. |
| 526 unescapedString = [unescapedString stringByReplacingOccurrencesOfString:@"<b>" | 528 unescapedString = [unescapedString stringByReplacingOccurrencesOfString:@"<b>" |
| 527 withString:@""]; | 529 withString:@""]; |
| 528 unescapedString = | 530 unescapedString = |
| 529 [unescapedString stringByReplacingOccurrencesOfString:@"</b>" | 531 [unescapedString stringByReplacingOccurrencesOfString:@"</b>" |
| 530 withString:@""]; | 532 withString:@""]; |
| 531 | 533 |
| 532 return [[[NSAttributedString alloc] initWithString:unescapedString | 534 return [[NSAttributedString alloc] initWithString:unescapedString |
| 533 attributes:attributes] autorelease]; | 535 attributes:attributes]; |
| 534 } | 536 } |
| 535 | 537 |
| 536 - (void)updateMatches:(const AutocompleteResult&)result | 538 - (void)updateMatches:(const AutocompleteResult&)result |
| 537 withAnimation:(BOOL)animation { | 539 withAnimation:(BOOL)animation { |
| 538 AutocompleteResult oldResults; | 540 AutocompleteResult oldResults; |
| 539 AutocompleteInput emptyInput; | 541 AutocompleteInput emptyInput; |
| 540 oldResults.Swap(&_currentResult); | 542 oldResults.Swap(&_currentResult); |
| 541 _currentResult.CopyOldMatches(emptyInput, result, nil); | 543 _currentResult.CopyOldMatches(emptyInput, result, nil); |
| 542 | 544 |
| 543 [self layoutRows]; | 545 [self layoutRows]; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 #pragma mark UIScrollViewDelegate | 646 #pragma mark UIScrollViewDelegate |
| 645 | 647 |
| 646 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { | 648 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { |
| 647 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a | 649 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a |
| 648 // one time scrollViewDidScroll to |-kTopAndBottomPadding|. It's easier to | 650 // one time scrollViewDidScroll to |-kTopAndBottomPadding|. It's easier to |
| 649 // just ignore this one scroll tick. | 651 // just ignore this one scroll tick. |
| 650 if (scrollView.contentOffset.y == 0 - kTopAndBottomPadding) | 652 if (scrollView.contentOffset.y == 0 - kTopAndBottomPadding) |
| 651 return; | 653 return; |
| 652 | 654 |
| 653 _popupView->DidScroll(); | 655 _popupView->DidScroll(); |
| 654 for (OmniboxPopupMaterialRow* row in _rows.get()) { | 656 for (OmniboxPopupMaterialRow* row in _rows) { |
| 655 row.highlighted = NO; | 657 row.highlighted = NO; |
| 656 } | 658 } |
| 657 } | 659 } |
| 658 | 660 |
| 659 // Set text alignment for popup cells. | 661 // Set text alignment for popup cells. |
| 660 - (void)setTextAlignment:(NSTextAlignment)alignment { | 662 - (void)setTextAlignment:(NSTextAlignment)alignment { |
| 661 _alignment = alignment; | 663 _alignment = alignment; |
| 662 } | 664 } |
| 663 | 665 |
| 664 - (BOOL)isSearchMatch:(const AutocompleteMatch::Type&)type { | 666 - (BOOL)isSearchMatch:(const AutocompleteMatch::Type&)type { |
| 665 return (type == AutocompleteMatchType::NAVSUGGEST || | 667 return (type == AutocompleteMatchType::NAVSUGGEST || |
| 666 type == AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED || | 668 type == AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED || |
| 667 type == AutocompleteMatchType::SEARCH_HISTORY || | 669 type == AutocompleteMatchType::SEARCH_HISTORY || |
| 668 type == AutocompleteMatchType::SEARCH_SUGGEST || | 670 type == AutocompleteMatchType::SEARCH_SUGGEST || |
| 669 type == AutocompleteMatchType::SEARCH_OTHER_ENGINE); | 671 type == AutocompleteMatchType::SEARCH_OTHER_ENGINE); |
| 670 } | 672 } |
| 671 | 673 |
| 672 - (NSMutableAttributedString*) | 674 - (NSMutableAttributedString*) |
| 673 attributedStringWithString:(NSString*)text | 675 attributedStringWithString:(NSString*)text |
| 674 classifications:(const ACMatchClassifications*)classifications | 676 classifications:(const ACMatchClassifications*)classifications |
| 675 smallFont:(BOOL)smallFont | 677 smallFont:(BOOL)smallFont |
| 676 color:(UIColor*)defaultColor | 678 color:(UIColor*)defaultColor |
| 677 dimColor:(UIColor*)dimColor { | 679 dimColor:(UIColor*)dimColor { |
| 678 if (text == nil) | 680 if (text == nil) |
| 679 return nil; | 681 return nil; |
| 680 | 682 |
| 681 CTFontRef fontRef = smallFont ? _smallFont : _bigFont; | 683 CTFontRef fontRef = smallFont ? _smallFont : _bigFont; |
| 682 | 684 |
| 683 NSMutableAttributedString* as = | 685 NSMutableAttributedString* as = |
| 684 [[[NSMutableAttributedString alloc] initWithString:text] autorelease]; | 686 [[NSMutableAttributedString alloc] initWithString:text]; |
| 685 | 687 |
| 686 // Set the base attributes to the default font and color. | 688 // Set the base attributes to the default font and color. |
| 687 NSDictionary* dict = [NSDictionary | 689 NSDictionary* dict = [NSDictionary |
| 688 dictionaryWithObjectsAndKeys:(id)fontRef, (NSString*)kCTFontAttributeName, | 690 dictionaryWithObjectsAndKeys:(__bridge id)fontRef, |
|
rohitrao (ping after 24h)
2017/02/24 13:40:31
There's a CL out to remove all of the CTFont code
Justin Donnelly
2017/02/24 15:40:39
This landed yesterday: http://crrev.com/2695413003
stkhapugin
2017/03/01 17:43:58
Merged this in
| |
| 691 (NSString*)kCTFontAttributeName, | |
| 689 defaultColor.CGColor, | 692 defaultColor.CGColor, |
| 690 (NSString*)kCTForegroundColorAttributeName, | 693 (NSString*)kCTForegroundColorAttributeName, |
| 691 nil]; | 694 nil]; |
| 692 [as addAttributes:dict range:NSMakeRange(0, [text length])]; | 695 [as addAttributes:dict range:NSMakeRange(0, [text length])]; |
| 693 | 696 |
| 694 if (classifications != NULL) { | 697 if (classifications != NULL) { |
| 695 CTFontRef boldFontRef = smallFont ? _smallBoldFont : _bigBoldFont; | 698 CTFontRef boldFontRef = smallFont ? _smallBoldFont : _bigBoldFont; |
| 696 | 699 |
| 697 for (ACMatchClassifications::const_iterator i = classifications->begin(); | 700 for (ACMatchClassifications::const_iterator i = classifications->begin(); |
| 698 i != classifications->end(); ++i) { | 701 i != classifications->end(); ++i) { |
| 699 const BOOL isLast = (i + 1) == classifications->end(); | 702 const BOOL isLast = (i + 1) == classifications->end(); |
| 700 const size_t nextOffset = (isLast ? [text length] : (i + 1)->offset); | 703 const size_t nextOffset = (isLast ? [text length] : (i + 1)->offset); |
| 701 const NSInteger location = static_cast<NSInteger>(i->offset); | 704 const NSInteger location = static_cast<NSInteger>(i->offset); |
| 702 const NSInteger length = static_cast<NSInteger>(nextOffset - i->offset); | 705 const NSInteger length = static_cast<NSInteger>(nextOffset - i->offset); |
| 703 // Guard against bad, off-the-end classification ranges due to | 706 // Guard against bad, off-the-end classification ranges due to |
| 704 // crbug.com/121703 and crbug.com/131370. | 707 // crbug.com/121703 and crbug.com/131370. |
| 705 if (i->offset + length > [text length] || length <= 0) | 708 if (i->offset + length > [text length] || length <= 0) |
| 706 break; | 709 break; |
| 707 const NSRange range = NSMakeRange(location, length); | 710 const NSRange range = NSMakeRange(location, length); |
| 708 if (0 != (i->style & ACMatchClassification::MATCH)) { | 711 if (0 != (i->style & ACMatchClassification::MATCH)) { |
| 709 [as addAttribute:(id)kCTFontAttributeName | 712 [as addAttribute:(id)kCTFontAttributeName |
| 710 value:(id)boldFontRef | 713 value:(__bridge id)boldFontRef |
|
rohitrao (ping after 24h)
2017/02/24 13:40:31
What does __bridge do?
stkhapugin
2017/03/01 17:43:58
__bridge is a type of cast that tells ARC to not d
| |
| 711 range:range]; | 714 range:range]; |
| 712 } | 715 } |
| 713 | 716 |
| 714 if (0 != (i->style & ACMatchClassification::DIM)) { | 717 if (0 != (i->style & ACMatchClassification::DIM)) { |
| 715 [as addAttribute:(id)kCTForegroundColorAttributeName | 718 [as addAttribute:(id)kCTForegroundColorAttributeName |
| 716 value:(id)dimColor.CGColor | 719 value:(id)dimColor.CGColor |
| 717 range:range]; | 720 range:range]; |
| 718 } | 721 } |
| 719 } | 722 } |
| 720 } | 723 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 // The delete button never disappears if you don't call this after a tap. | 786 // The delete button never disappears if you don't call this after a tap. |
| 784 // It doesn't seem to be required anywhere else. | 787 // It doesn't seem to be required anywhere else. |
| 785 [_rows[indexPath.row] prepareForReuse]; | 788 [_rows[indexPath.row] prepareForReuse]; |
| 786 const AutocompleteMatch& match = | 789 const AutocompleteMatch& match = |
| 787 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 790 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
| 788 _popupView->DeleteMatch(match); | 791 _popupView->DeleteMatch(match); |
| 789 } | 792 } |
| 790 } | 793 } |
| 791 | 794 |
| 792 @end | 795 @end |
| OLD | NEW |