Commit 2036c066 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS] Remove legacy omnibox classes.

Removes pre-HL popup classes.

Bug: 943521
Change-Id: Ife98510b8d0142df487d7aef0fab08494ab2cdf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007569
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#733956}
parent 1a4af27d
......@@ -67,10 +67,6 @@ source_set("popup_ui") {
"omnibox_popup_base_view_controller+internal.h",
"omnibox_popup_base_view_controller.h",
"omnibox_popup_base_view_controller.mm",
"omnibox_popup_legacy_view_controller.h",
"omnibox_popup_legacy_view_controller.mm",
"omnibox_popup_row.h",
"omnibox_popup_row.mm",
"omnibox_popup_row_cell.h",
"omnibox_popup_row_cell.mm",
"omnibox_popup_view_controller.h",
......@@ -136,10 +132,7 @@ source_set("popup_internal") {
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"omnibox_popup_row_cell_unittest.mm",
"omnibox_popup_view_controller_unittest.mm",
]
sources = [ "omnibox_popup_row_cell_unittest.mm" ]
deps = [
":popup",
":popup_internal",
......
......@@ -10,7 +10,6 @@
#import "ios/chrome/browser/ui/commands/omnibox_suggestion_commands.h"
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_result_consumer.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_base_view_controller.h"
#include "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
@protocol ImageRetriever;
@protocol FaviconRetriever;
......
......@@ -9,7 +9,6 @@
#include "base/time/time.h"
#import "ios/chrome/browser/ui/ntp_tile_views/ntp_tile_layout_util.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_constants.h"
#include "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
#include "ios/chrome/browser/ui/omnibox/popup/self_sizing_table_view.h"
#include "ios/chrome/browser/ui/toolbar/buttons/toolbar_configuration.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
......
......@@ -14,7 +14,6 @@
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_presenter.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_view_controller.h"
......
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_LEGACY_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_LEGACY_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/ui/commands/omnibox_suggestion_commands.h"
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_result_consumer.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_base_view_controller.h"
@interface OmniboxPopupLegacyViewController : OmniboxPopupBaseViewController
@end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_LEGACY_VIEW_CONTROLLER_H_
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_base_view_controller+internal.h"
#include <memory>
#include "base/ios/ios_util.h"
#include "base/metrics/histogram_macros.h"
#import "ios/chrome/browser/ui/elements/fade_truncating_label.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_constants.h"
#import "ios/chrome/browser/ui/omnibox/popup/image_retriever.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
#import "ios/chrome/browser/ui/omnibox/popup/self_sizing_table_view.h"
#import "ios/chrome/browser/ui/toolbar/buttons/toolbar_configuration.h"
#include "ios/chrome/browser/ui/util/animation_util.h"
#include "ios/chrome/browser/ui/util/rtl_geometry.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const int kRowCount = 12;
const CGFloat kRowHeight = 48.0;
const CGFloat kAnswerRowHeight = 64.0;
} // namespace
@interface OmniboxPopupLegacyViewController () <
OmniboxPopupRowAccessibilityDelegate> {
// Array containing the OmniboxPopupRow objects displayed in the view.
NSArray* _rows;
}
// A flag to track if since the last viewWillAppear, the view ever adopted a
// non-zero size. This is a pretty sad workaround for the new iOS 13 behaviour
// where the half-autolayout, half-manual layout code of this legacy class ends
// up sizing cells to a zero width because -layoutRows is never called on the
// first appearance. This should be removed, together with this class, when the
// non-legacy OmniboxPopupViewController becomes the default.
@property(nonatomic, assign) BOOL viewHadNonZeroWidth;
@end
@implementation OmniboxPopupLegacyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Cache fonts needed for omnibox attributed string.
NSMutableArray* rowsBuilder = [[NSMutableArray alloc] init];
for (int i = 0; i < kRowCount; i++) {
OmniboxPopupRow* row =
[[OmniboxPopupRow alloc] initWithIncognito:self.incognito];
row.accessibilityIdentifier =
[NSString stringWithFormat:@"omnibox suggestion %i", i];
row.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[rowsBuilder addObject:row];
[row.trailingButton addTarget:self
action:@selector(trailingButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[row.trailingButton setTag:i];
row.rowNumber = i;
row.delegate = self;
row.rowHeight = kRowHeight;
}
_rows = [rowsBuilder copy];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if (![self isViewLoaded]) {
_rows = nil;
}
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self layoutRows];
}
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:
(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator
animateAlongsideTransition:^(
id<UIViewControllerTransitionCoordinatorContext> context) {
[self layoutRows];
}
completion:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.view.bounds.size.width == 0) {
self.viewHadNonZeroWidth = NO;
}
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// This method will be called multiple times, including after the self-sizing
// table view will have taken its final (non-zero) size. Calling -layoutRows
// will result in another viewDidLayoutSubviews call, so a flag is necessary
// to avoid an infinite loop.
if (self.view.bounds.size.width > 0 && !self.viewHadNonZeroWidth) {
self.viewHadNonZeroWidth = YES;
[self layoutRows];
}
}
#pragma mark -
#pragma mark Updating data and UI
- (void)updateRow:(OmniboxPopupRow*)row
withMatch:(id<AutocompleteSuggestion>)match {
CGFloat kTextCellLeadingPadding =
[self showsLeadingIcons] ? ([self useRegularWidthOffset] ? 192 : 100)
: 16;
kTextCellLeadingPadding = [self showsLeadingIcons] ? 221 : 24;
const CGFloat kTextCellTopPadding = 6;
const CGFloat kDetailCellTopPadding = 26;
const CGFloat kTextLabelHeight = 24;
const CGFloat kTextDetailLabelHeight = 22;
const CGFloat kTrailingButtonWidth = 40;
const CGFloat kAnswerLabelHeight = 36;
const CGFloat kAnswerImageWidth = 30;
const CGFloat kAnswerImageLeftPadding = -1;
const CGFloat kAnswerImageRightPadding = 4;
const CGFloat kAnswerImageTopPadding = 2;
const BOOL alignmentRight = self.alignment == NSTextAlignmentRight;
BOOL LTRTextInRTLLayout =
self.alignment == NSTextAlignmentLeft && UseRTLLayout();
row.rowHeight = match.hasAnswer ? kAnswerRowHeight : kRowHeight;
// Fetch the answer image if specified. Currently, no answer types specify an
// image on the first line so for now we only look at the second line.
if (match.hasImage) {
[self.imageRetriever fetchImage:match.imageURL
completion:^(UIImage* image) {
row.answerImageView.image = image;
}];
// Answers in suggest do not support RTL, left align only.
CGFloat imageLeftPadding =
kTextCellLeadingPadding + kAnswerImageLeftPadding;
if (alignmentRight) {
imageLeftPadding =
row.frame.size.width - (kAnswerImageWidth + kTrailingButtonWidth);
}
CGFloat imageTopPadding = kDetailCellTopPadding + kAnswerImageTopPadding;
row.answerImageView.frame =
CGRectMake(imageLeftPadding, imageTopPadding, kAnswerImageWidth,
kAnswerImageWidth);
row.answerImageView.hidden = NO;
} else {
row.answerImageView.hidden = YES;
}
// DetailTextLabel and textLabel are fading labels placed in each row. The
// textLabel is laid out above the detailTextLabel, and vertically centered
// if the detailTextLabel is empty.
// For the detail text label, we use either the regular detail label, which
// truncates by fading, or the answer label, which uses UILabel's standard
// truncation by ellipse for the multi-line text sometimes shown in answers.
row.detailTruncatingLabel.hidden = match.hasAnswer;
row.detailAnswerLabel.hidden = !match.hasAnswer;
// URLs have have special layout requirements that need to be invoked here.
row.detailTruncatingLabel.displayAsURL = match.isURL;
// TODO(crbug.com/697647): The complexity of managing these two separate
// labels could probably be encapusulated in the row class if we moved the
// layout logic there.
UILabel* detailTextLabel =
match.hasAnswer ? row.detailAnswerLabel : row.detailTruncatingLabel;
[detailTextLabel setTextAlignment:self.alignment];
// The width must be positive for CGContextRef to be valid.
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
CGRect rowBounds = UIEdgeInsetsInsetRect(self.view.bounds, safeAreaInsets);
CGFloat labelWidth =
MAX(40, floorf(rowBounds.size.width) - kTextCellLeadingPadding);
CGFloat labelHeight =
match.hasAnswer ? kAnswerLabelHeight : kTextDetailLabelHeight;
CGFloat answerImagePadding = kAnswerImageWidth + kAnswerImageRightPadding;
CGFloat leadingPadding =
(match.hasImage && !alignmentRight ? answerImagePadding : 0) +
kTextCellLeadingPadding;
LayoutRect detailTextLabelLayout =
LayoutRectMake(leadingPadding, CGRectGetWidth(rowBounds),
kDetailCellTopPadding, labelWidth, labelHeight);
detailTextLabel.frame = LayoutRectGetRect(detailTextLabelLayout);
detailTextLabel.attributedText = match.detailText;
// Set detail text label number of lines
if (match.hasAnswer) {
detailTextLabel.numberOfLines = match.numberOfLines;
}
[detailTextLabel setNeedsDisplay];
FadeTruncatingLabel* textLabel = row.textTruncatingLabel;
[textLabel setTextAlignment:self.alignment];
LayoutRect textLabelLayout =
LayoutRectMake(kTextCellLeadingPadding, CGRectGetWidth(rowBounds), 0,
labelWidth, kTextLabelHeight);
textLabel.frame = LayoutRectGetRect(textLabelLayout);
// Set the text.
textLabel.attributedText = match.text;
// Center the textLabel if detailLabel is empty.
if (!match.hasAnswer && [match.detailText length] == 0) {
textLabel.center = CGPointMake(textLabel.center.x, floor(kRowHeight / 2));
textLabel.frame = AlignRectToPixel(textLabel.frame);
} else {
CGRect frame = textLabel.frame;
frame.origin.y = kTextCellTopPadding;
textLabel.frame = frame;
}
// The leading image (e.g. magnifying glass, star, clock) is only shown on
// iPad.
if ([self showsLeadingIcons]) {
UIImage* image = nil;
image = match.suggestionTypeIcon;
DCHECK(image);
[row updateLeadingImage:image];
}
row.tabMatch = match.isTabMatch;
// Show append button for search history/search suggestions as the right
// control element (aka an accessory element of a table view cell).
BOOL hasVisibleTrailingButton = match.isAppendable || match.isTabMatch;
row.trailingButton.hidden = !hasVisibleTrailingButton;
[row.trailingButton cancelTrackingWithEvent:nil];
// If a right accessory element is present or the text alignment is right
// aligned, adjust the width to align with the accessory element.
if (hasVisibleTrailingButton || alignmentRight) {
LayoutRect layout =
LayoutRectForRectInBoundingRect(textLabel.frame, self.view.frame);
layout.size.width -= kTrailingButtonWidth;
textLabel.frame = LayoutRectGetRect(layout);
layout =
LayoutRectForRectInBoundingRect(detailTextLabel.frame, self.view.frame);
layout.size.width -=
kTrailingButtonWidth + (match.hasImage ? answerImagePadding : 0);
detailTextLabel.frame = LayoutRectGetRect(layout);
}
// Since it's a common use case to type in a left-to-right URL while the
// device is set to a native RTL language, make sure the left alignment looks
// good by anchoring the leading edge to the left.
if (LTRTextInRTLLayout) {
// This is really a left padding, not a leading padding.
const CGFloat kLTRTextInRTLLayoutLeftPadding =
[self showsLeadingIcons] ? ([self useRegularWidthOffset] ? 176 : 94)
: 94;
CGRect frame = textLabel.frame;
frame.size.width -= kLTRTextInRTLLayoutLeftPadding - frame.origin.x;
frame.origin.x = kLTRTextInRTLLayoutLeftPadding;
textLabel.frame = frame;
frame = detailTextLabel.frame;
frame.size.width -= kLTRTextInRTLLayoutLeftPadding - frame.origin.x;
frame.origin.x = kLTRTextInRTLLayoutLeftPadding;
detailTextLabel.frame = frame;
}
NSString* trailingButtonActionName =
row.tabMatch
? l10n_util::GetNSString(IDS_IOS_OMNIBOX_POPUP_SWITCH_TO_OPEN_TAB)
: l10n_util::GetNSString(IDS_IOS_OMNIBOX_POPUP_APPEND);
UIAccessibilityCustomAction* trailingButtonAction =
[[UIAccessibilityCustomAction alloc]
initWithName:trailingButtonActionName
target:row
selector:@selector(accessibilityTrailingButtonTapped)];
row.accessibilityCustomActions =
hasVisibleTrailingButton ? @[ trailingButtonAction ] : nil;
[textLabel setNeedsDisplay];
}
- (void)updateTableViewWithAnimation:(BOOL)animation {
[self layoutRows];
size_t size = self.currentResult.count;
if (animation && size > 0) {
[self fadeInRows];
}
}
- (void)layoutRows {
size_t size = self.currentResult.count;
[self.tableView reloadData];
for (size_t i = 0; i < kRowCount; i++) {
OmniboxPopupRow* row = _rows[i];
if (i < size) {
[self updateRow:row withMatch:self.currentResult[i]];
row.hidden = NO;
} else {
row.hidden = YES;
}
}
if (IsIPadIdiom())
[self updateContentInsetForKeyboard];
}
- (void)fadeInRows {
[CATransaction begin];
[CATransaction
setAnimationTimingFunction:[CAMediaTimingFunction
functionWithControlPoints:
0:0:0.2:1]];
for (size_t i = 0; i < kRowCount; i++) {
OmniboxPopupRow* row = _rows[i];
CGFloat beginTime = (i + 1) * .05;
CABasicAnimation* transformAnimation =
[CABasicAnimation animationWithKeyPath:@"transform"];
[transformAnimation
setFromValue:[NSValue
valueWithCATransform3D:CATransform3DMakeTranslation(
0, -20, 0)]];
[transformAnimation
setToValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]];
[transformAnimation setDuration:0.5];
[transformAnimation setBeginTime:beginTime];
CAAnimation* fadeAnimation = OpacityAnimationMake(0, 1);
[fadeAnimation setDuration:0.5];
[fadeAnimation setBeginTime:beginTime];
[[row layer]
addAnimation:AnimationGroupMake(@[ transformAnimation, fadeAnimation ])
forKey:@"animateIn"];
}
[CATransaction commit];
}
#pragma mark -
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
[super scrollViewDidScroll:scrollView];
// TODO(crbug.com/733650): Default to the dragging check once it's been tested
// on trunk.
if (!scrollView.dragging)
return;
for (OmniboxPopupRow* row in _rows) {
row.highlighted = NO;
}
}
#pragma mark -
#pragma mark Table view data source
- (CGFloat)tableView:(UITableView*)tableView
heightForRowAtIndexPath:(NSIndexPath*)indexPath {
DCHECK_EQ(0U, (NSUInteger)indexPath.section);
DCHECK_LT((NSUInteger)indexPath.row, self.currentResult.count);
return ((OmniboxPopupRow*)(_rows[indexPath.row])).rowHeight;
}
// Customize the appearance of table view cells.
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
DCHECK_EQ(0U, (NSUInteger)indexPath.section);
DCHECK_LT((NSUInteger)indexPath.row, self.currentResult.count);
return _rows[indexPath.row];
}
#pragma mark - private
- (BOOL)showsLeadingIcons {
return IsRegularXRegularSizeClass();
}
- (BOOL)useRegularWidthOffset {
return [self showsLeadingIcons] && !IsCompactWidth();
}
#pragma mark - OmniboxPopupRowAccessibilityDelegate
- (void)accessibilityTrailingButtonTappedOmniboxPopupRow:(OmniboxPopupRow*)row {
[self.delegate autocompleteResultConsumer:self
didTapTrailingButtonForRow:row.rowNumber];
}
@end
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_ROW_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_ROW_H_
#import <UIKit/UIKit.h>
@class FadeTruncatingLabel;
@class OmniboxPopupRow;
// Accessibility delegate for handling the row actions.
@protocol OmniboxPopupRowAccessibilityDelegate
// Handles the action associated with the trailing button of the |row|.
- (void)accessibilityTrailingButtonTappedOmniboxPopupRow:(OmniboxPopupRow*)row;
@end
// View used to display an omnibox autocomplete match in the omnibox popup.
@interface OmniboxPopupRow : UITableViewCell
// A truncate-by-fading version of the textLabel of a UITableViewCell.
@property(nonatomic, readonly, strong) FadeTruncatingLabel* textTruncatingLabel;
// A truncate-by-fading version of the detailTextLabel of a UITableViewCell.
@property(nonatomic, readonly, strong)
FadeTruncatingLabel* detailTruncatingLabel;
// A standard UILabel for answers, which truncates with ellipses to support
// multi-line text.
@property(nonatomic, readonly, strong) UILabel* detailAnswerLabel;
// Row number.
@property(nonatomic, assign) NSUInteger rowNumber;
// Accessibility delegate for this row.
@property(nonatomic, weak) id<OmniboxPopupRowAccessibilityDelegate> delegate;
@property(nonatomic, readonly, strong) UIImageView* imageView;
@property(nonatomic, readonly, strong) UIImageView* answerImageView;
@property(nonatomic, readonly, strong) UIButton* trailingButton;
@property(nonatomic, assign) CGFloat rowHeight;
// Whether this row is displaying a TabMatch. If YES, the trailing icon is
// updated to reflect that.
@property(nonatomic, assign, getter=isTabMatch) BOOL tabMatch;
// Initialize the row with the given incognito state. The colors and styling are
// dependent on whether or not the row is displayed in incognito mode.
- (instancetype)initWithIncognito:(BOOL)incognito;
// Update the match type icon with the supplied image ID and adjust its position
// based on the current size of the row.
- (void)updateLeadingImage:(UIImage*)image;
// Callback for the accessibility action associated with the trailing button of
// this row.
- (void)accessibilityTrailingButtonTapped;
@end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_ROW_H_
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "components/omnibox/common/omnibox_features.h"
#import "ios/chrome/browser/ui/elements/fade_truncating_label.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_accessibility_identifier_constants.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
#include "ios/chrome/browser/ui/util/rtl_geometry.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/colors/dynamic_color_util.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#include "ios/chrome/grit/ios_theme_resources.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Side (w or h) length for the leading image view.
const CGFloat kImageViewSize = 28.0;
const CGFloat kImageViewCornerRadius = 7.0;
const CGFloat kTrailingButtonTrailingMargin = 4;
const CGFloat kTrailingButtonSize = 48.0;
const CGFloat kLeadingPaddingIpad = 183;
const CGFloat kLeadingPaddingIpadCompact = 71;
}
@interface OmniboxPopupRow () {
BOOL _incognito;
}
// Set the append button normal and highlighted images.
- (void)updateTrailingButtonImages;
@end
@implementation OmniboxPopupRow
@synthesize imageView = _imageView;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
return [self initWithIncognito:NO];
}
- (instancetype)initWithIncognito:(BOOL)incognito {
self = [super initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"OmniboxPopupRow"];
if (self) {
_incognito = incognito;
self.isAccessibilityElement = YES;
self.backgroundColor = UIColor.clearColor;
self.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
self.selectedBackgroundView.backgroundColor = color::DarkModeDynamicColor(
[UIColor colorNamed:kTableViewRowHighlightColor], _incognito,
[UIColor colorNamed:kTableViewRowHighlightDarkColor]);
_textTruncatingLabel =
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_textTruncatingLabel.userInteractionEnabled = NO;
[self.contentView addSubview:_textTruncatingLabel];
_detailTruncatingLabel =
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_detailTruncatingLabel.userInteractionEnabled = NO;
[self.contentView addSubview:_detailTruncatingLabel];
// Answers use a UILabel with NSLineBreakByTruncatingTail to produce a
// truncation with an ellipse instead of fading on multi-line text.
_detailAnswerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_detailAnswerLabel.userInteractionEnabled = NO;
_detailAnswerLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[self.contentView addSubview:_detailAnswerLabel];
_trailingButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_trailingButton setContentMode:UIViewContentModeRight];
[self updateTrailingButtonImages];
// TODO(justincohen): Consider using the UITableViewCell's accessory view.
// The current implementation is from before using a UITableViewCell.
[self.contentView addSubview:_trailingButton];
// Before UI Refresh, the leading icon is only displayed on iPad. In UI
// Refresh, it's only in Regular x Regular size class.
// TODO(justincohen): Consider using the UITableViewCell's image view.
// The current implementation is from before using a UITableViewCell.
_imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
_imageView.userInteractionEnabled = NO;
_imageView.contentMode = UIViewContentModeCenter;
_imageView.layer.cornerRadius = kImageViewCornerRadius;
_imageView.backgroundColor = UIColor.clearColor;
_imageView.tintColor = color::DarkModeDynamicColor(
[UIColor colorNamed:@"omnibox_suggestion_icon_color"], _incognito,
[UIColor colorNamed:@"omnibox_suggestion_icon_dark_color"]);
_answerImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
_answerImageView.userInteractionEnabled = NO;
_answerImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:_answerImageView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
[self layoutAccessoryViews];
if ([self showsLeadingIcons]) {
[self.contentView addSubview:_imageView];
} else {
[_imageView removeFromSuperview];
}
}
- (void)layoutAccessoryViews {
CGFloat imageViewSize = kImageViewSize;
LayoutRect imageViewLayout = LayoutRectMake(
([self showsLeadingIcons] && IsCompactTablet())
? kLeadingPaddingIpadCompact
: kLeadingPaddingIpad,
CGRectGetWidth(self.contentView.bounds),
floor((_rowHeight - imageViewSize) / 2), imageViewSize, imageViewSize);
_imageView.frame = LayoutRectGetRect(imageViewLayout);
LayoutRect trailingAccessoryLayout =
LayoutRectMake(CGRectGetWidth(self.contentView.bounds) -
kTrailingButtonSize - kTrailingButtonTrailingMargin,
CGRectGetWidth(self.contentView.bounds),
floor((_rowHeight - kTrailingButtonSize) / 2),
kTrailingButtonSize, kTrailingButtonSize);
_trailingButton.frame = LayoutRectGetRect(trailingAccessoryLayout);
}
- (void)updateLeadingImage:(UIImage*)image {
_imageView.image = image;
// Adjust the vertical position based on the current size of the row.
CGFloat imageViewSize = kImageViewSize;
CGRect frame = _imageView.frame;
frame.origin.y = floor((_rowHeight - imageViewSize) / 2);
_imageView.frame = frame;
}
- (void)setTabMatch:(BOOL)tabMatch {
_tabMatch = tabMatch;
[self updateTrailingButtonImages];
}
- (void)updateTrailingButtonImages {
UIImage* appendImage = nil;
_trailingButton.accessibilityIdentifier = nil;
if (self.tabMatch) {
appendImage = [UIImage imageNamed:@"omnibox_popup_tab_match"];
appendImage = appendImage.imageFlippedForRightToLeftLayoutDirection;
_trailingButton.accessibilityIdentifier =
kOmniboxPopupRowSwitchTabAccessibilityIdentifier;
} else {
int appendResourceID = 0;
appendResourceID = IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND;
appendImage = NativeReversableImage(appendResourceID, YES);
}
appendImage =
[appendImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_trailingButton.tintColor =
color::DarkModeDynamicColor([UIColor colorNamed:kBlueColor], _incognito,
[UIColor colorNamed:kBlueDarkColor]);
[_trailingButton setImage:appendImage forState:UIControlStateNormal];
}
- (NSString*)accessibilityLabel {
return _textTruncatingLabel.attributedText.string;
}
- (NSString*)accessibilityValue {
return _detailTruncatingLabel.hidden
? _detailAnswerLabel.attributedText.string
: _detailTruncatingLabel.attributedText.string;
}
- (BOOL)showsLeadingIcons {
return IsRegularXRegularSizeClass();
}
- (void)accessibilityTrailingButtonTapped {
[self.delegate accessibilityTrailingButtonTappedOmniboxPopupRow:self];
}
@end
......@@ -5,7 +5,6 @@
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row_cell.h"
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
#include "components/omnibox/browser/autocomplete_match.h"
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_row.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
class OmniboxPopupViewControllerTest : public PlatformTest {
protected:
void SetUp() override {
PlatformTest::SetUp();
popup_view_controller_ = [[OmniboxPopupLegacyViewController alloc] init];
}
OmniboxPopupLegacyViewController* popup_view_controller_;
};
TEST_F(OmniboxPopupViewControllerTest, HasTabMatch) {
EXPECT_TRUE([popup_view_controller_
conformsToProtocol:@protocol(UITableViewDataSource)]);
id<UITableViewDataSource> datasource =
(id<UITableViewDataSource>)popup_view_controller_;
UITableView* table_view = [[UITableView alloc] init];
// Check that if the match has a tab match, the cell's trailing button is
// visible.
AutocompleteMatch match;
match.has_tab_match = true;
AutocompleteMatchFormatter* formatter =
[[AutocompleteMatchFormatter alloc] initWithMatch:match];
[popup_view_controller_ updateMatches:@[ formatter ] withAnimation:NO];
EXPECT_EQ([datasource tableView:table_view numberOfRowsInSection:0], 1);
OmniboxPopupRow* cell = static_cast<OmniboxPopupRow*>([datasource
tableView:table_view
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]);
EXPECT_FALSE(cell.trailingButton.hidden);
// Check that it is not the case if the tab match isn't visible.
match.has_tab_match = false;
formatter = [[AutocompleteMatchFormatter alloc] initWithMatch:match];
[popup_view_controller_ updateMatches:@[ formatter ] withAnimation:NO];
EXPECT_EQ([datasource tableView:table_view numberOfRowsInSection:0], 1);
cell = static_cast<OmniboxPopupRow*>([datasource
tableView:table_view
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]);
EXPECT_TRUE(cell.trailingButton.hidden);
}
} // namespace
......@@ -11,7 +11,6 @@
#include "base/strings/string16.h"
#include "components/omnibox/browser/omnibox_popup_view.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_mediator.h"
#include "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_provider.h"
......
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