Skip to content

Commit

Permalink
[iOS] Temporary UI to add Search Engine Snippet
Browse files Browse the repository at this point in the history
Low-Coverage-Reason: TESTS_IN_SEPARATE_CL it will be added later
Bug: b/312459357
Change-Id: Icca383a6673f78faacaec75ee0ae09e50172a912
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5067594
Auto-Submit: Jérôme Lebel <[email protected]>
Commit-Queue: Jérôme Lebel <[email protected]>
Reviewed-by: Samar Chehade-Lepleux <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1230253}
  • Loading branch information
Jérôme Lebel authored and Chromium LUCI CQ committed Nov 28, 2023
1 parent 09bed4e commit a987ab4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
// Unique identifier that matches with one URLItem.
@property(nonatomic, strong) NSString* cellUniqueIdentifier;

// Properly configure the subview layouts once all labels' properties have been
// configured. This must be called at the end of configureCell: for all items
// that use TableViewURLCell.
- (void)configureUILayout;

@end

#endif // IOS_CHROME_BROWSER_UI_SEARCH_ENGINE_CHOICE_SEARCH_ENGINE_CHOICE_TABLE_CELLS_SNIPPET_SEARCH_ENGINE_CELL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,75 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
UIView* contentView = self.contentView;

_faviconContainerView = [[FaviconContainerView alloc] init];
_faviconContainerView.translatesAutoresizingMaskIntoConstraints = NO;
[_faviconContainerView
setFaviconBackgroundColor:[UIColor colorNamed:kBackgroundColor]];
_faviconContainerView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:_faviconContainerView];

// Add name label and snippet label.
UIView* nameSnippetLabelContainer = [[UIView alloc] init];
nameSnippetLabelContainer.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:nameSnippetLabelContainer];
_nameLabel = [[UILabel alloc] init];
_nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
_nameLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_nameLabel.adjustsFontForContentSizeCategory = YES;
[nameSnippetLabelContainer addSubview:_nameLabel];
_snippetLabel = [[UILabel alloc] init];
_snippetLabel.translatesAutoresizingMaskIntoConstraints = NO;
_snippetLabel.textColor = [UIColor colorNamed:kTextSecondaryColor];
_snippetLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_snippetLabel.adjustsFontForContentSizeCategory = YES;
_snippetLabel.textColor = [UIColor colorNamed:kTextSecondaryColor];
_snippetLabel.hidden = YES;

// Horizontal view holds vertical stack view and metadata views.
UIView* horizontalView = [[UIView alloc] init];
horizontalView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:horizontalView];

// Use stack views to layout the subviews except for the favicon.
UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ _nameLabel, _snippetLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.translatesAutoresizingMaskIntoConstraints = NO;
[horizontalView addSubview:verticalStack];

NSLayoutConstraint* heightConstraint = [self.contentView.heightAnchor
constraintGreaterThanOrEqualToConstant:kChromeTableViewCellHeight];
// Don't set the priority to required to avoid clashing with the estimated
// height.
heightConstraint.priority = UILayoutPriorityRequired - 1;
_snippetLabel.numberOfLines = 1;
[nameSnippetLabelContainer addSubview:_snippetLabel];

NSLayoutConstraint* heightConstraint = [_snippetLabel.bottomAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.bottomAnchor
constant:0];
heightConstraint.priority = UILayoutPriorityDefaultLow;
[NSLayoutConstraint activateConstraints:@[
[_faviconContainerView.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
[_faviconContainerView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],

// The stack view fills the remaining space, has an intrinsic height, and
// is centered vertically.
[horizontalView.leadingAnchor
constraintEqualToAnchor:_faviconContainerView.trailingAnchor
constant:kTableViewSubViewHorizontalSpacing],
[horizontalView.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kTableViewHorizontalSpacing],
[horizontalView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
[verticalStack.topAnchor
constraintEqualToAnchor:horizontalView.topAnchor],
[verticalStack.bottomAnchor
constraintEqualToAnchor:horizontalView.bottomAnchor],
[verticalStack.leadingAnchor
constraintEqualToAnchor:horizontalView.leadingAnchor],
[horizontalView.topAnchor
[nameSnippetLabelContainer.topAnchor
constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor
constant:
kTableViewTwoLabelsCellVerticalSpacing],
[horizontalView.bottomAnchor
[nameSnippetLabelContainer.bottomAnchor
constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor
constant:
-kTableViewTwoLabelsCellVerticalSpacing],
heightConstraint
[nameSnippetLabelContainer.leadingAnchor
constraintEqualToAnchor:_faviconContainerView.trailingAnchor],
[nameSnippetLabelContainer.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor],
[_nameLabel.leadingAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.leadingAnchor
constant:kTableViewSubViewHorizontalSpacing],
[_nameLabel.trailingAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.trailingAnchor
constant:-kTableViewHorizontalSpacing],
[_snippetLabel.leadingAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.leadingAnchor
constant:kTableViewSubViewHorizontalSpacing],
[_snippetLabel.trailingAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.trailingAnchor
constant:-kTableViewHorizontalSpacing],
[_nameLabel.topAnchor
constraintEqualToAnchor:nameSnippetLabelContainer.topAnchor
constant:0],
[_nameLabel.bottomAnchor constraintEqualToAnchor:_snippetLabel.topAnchor
constant:0],
heightConstraint,
]];
}
return self;
}

- (void)configureUILayout {
if ([self.snippetLabel.text length]) {
self.snippetLabel.hidden = NO;
} else {
self.snippetLabel.hidden = YES;
}
}

#pragma mark - Properties

- (FaviconView*)faviconView {
Expand All @@ -113,7 +104,7 @@ - (FaviconView*)faviconView {
- (void)prepareForReuse {
[super prepareForReuse];
[self.faviconView configureWithAttributes:nil];
self.snippetLabel.hidden = YES;
self.snippetLabel.numberOfLines = 1;
}

#pragma mark - Accessibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GURL;
// The name of the search engine.
@property(nonatomic, readwrite, copy) NSString* name;
// The text for the search engine snippet.
@property(nonatomic, readwrite, copy) NSString* snippet;
@property(nonatomic, readwrite, copy) NSString* snippetDescription;
// The URL to fetch the favicon. This can be the favicon's URL, or a "fake" web
// page URL created by filling empty query word into the search engine's
// searchable URL template(e.g. "http://www.google.com/?q=").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (void)configureCell:(TableViewCell*)tableCell
SnippetSearchEngineCell* cell =
base::apple::ObjCCastStrict<SnippetSearchEngineCell>(tableCell);
cell.nameLabel.text = self.name;
cell.snippetLabel.text = self.snippetDescription;
cell.cellUniqueIdentifier = self.uniqueIdentifier;
cell.accessibilityTraits |= UIAccessibilityTraitButton;
cell.contentView.alpha = 1.0;
Expand All @@ -52,8 +53,6 @@ - (void)configureCell:(TableViewCell*)tableCell
if (styler.cellTitleColor) {
cell.nameLabel.textColor = styler.cellTitleColor;
}

[cell configureUILayout];
}

- (BOOL)isEqual:(SnippetSearchEngineItem*)otherItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
item.URL = template_url->favicon_url();
}
item.name = base::SysUTF16ToNSString(template_url->short_name());
item.snippetDescription = [[NSString alloc]
initWithFormat:@"** Description for %@ that can be very very very very "
@"very very long. **",
item.name];
return item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ - (void)tableView:(UITableView*)tableView
textItem.accessoryType = UITableViewCellAccessoryNone;
UITableViewCell* cell =
[tableView cellForRowAtIndexPath:[model indexPathForItem:item]];
SnippetSearchEngineCell* urlCell =
base::apple::ObjCCastStrict<SnippetSearchEngineCell>(cell);
UIImageView* circleView = CreateEmptyCircle();
[cell setAccessoryView:circleView];
[urlCell setAccessoryView:circleView];
urlCell.snippetLabel.numberOfLines = 1;
}
}

Expand All @@ -132,13 +135,18 @@ - (void)tableView:(UITableView*)tableView
[model itemAtIndexPath:indexPath]);
newDefaultEngine.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
SnippetSearchEngineCell* urlCell =
base::apple::ObjCCastStrict<SnippetSearchEngineCell>(cell);

cell.accessoryType = UITableViewCellAccessoryCheckmark;
UIImageView* checkedCircleView = CreateCheckedCircle();
[cell setAccessoryView:checkedCircleView];
[urlCell setAccessoryView:checkedCircleView];
urlCell.snippetLabel.numberOfLines = 0;

CHECK(self.delegate);
[self.delegate selectSearchEngineAtRow:_selectedRow];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}

#pragma mark - UITableViewDataSource
Expand Down

0 comments on commit a987ab4

Please sign in to comment.