Commit 6bca1b08 authored by sczs@chromium.org's avatar sczs@chromium.org Committed by Commit Bot

[ios] Creates TableViewTextLinkItem and uses it on HistoryTableVC.

- Creates TableViewTextLinkItem, which is a text item with link support.
- Uses this item on HistoryTableVC and re-writes updateEntriesStatusMessage to reflect this.

Screenshot:
https://drive.google.com/open?id=1r6hQfWx_Yu8QC32F3hH7_TDq6ZkumHUh

Bug: 805200
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I8ac8ad0329f9e0a6e38f9ef7b8f72d5bf0a1c899
Reviewed-on: https://chromium-review.googlesource.com/1094557
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567460}
parent 6adc519d
......@@ -120,6 +120,7 @@ source_set("history_ui") {
"//components/url_formatter",
"//components/url_formatter",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/sync",
......
......@@ -24,6 +24,8 @@ source_set("cells") {
"table_view_text_header_footer_item.mm",
"table_view_text_item.h",
"table_view_text_item.mm",
"table_view_text_link_item.h",
"table_view_text_link_item.mm",
"table_view_url_item.h",
"table_view_url_item.mm",
]
......@@ -38,8 +40,10 @@ source_set("cells") {
"//ios/chrome/browser/ui/favicon:favicon_ui",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/table_view:styler",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:constraints_ui",
"//ios/chrome/browser/ui/util:constraints_ui",
"//ios/chrome/common",
"//ios/third_party/material_components_ios:material_components_ios",
"//url:url",
]
......
// 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.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_LINK_ITEM_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_LINK_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
class GURL;
@class TableViewTextLinkCell;
// Delegate for TableViewTextLinkCell.
@protocol TableViewTextLinkCellDelegate<NSObject>
// Notifies the delegate that |URL| should be opened.
- (void)tableViewTextLinkCell:(TableViewTextLinkCell*)cell
didRequestOpenURL:(const GURL&)URL;
@end
// TableViewTextLinkItem contains the model data for a TableViewTextLinkCell.
@interface TableViewTextLinkItem : TableViewItem
// Text being stored by this item.
@property(nonatomic, readwrite, strong) NSString* text;
// URL link being stored by this item.
@property(nonatomic, assign) GURL linkURL;
@end
// UITableViewCell that displays a text label that might contain a link.
@interface TableViewTextLinkCell : UITableViewCell
// The text to display.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Delegate for the TableViewTextLinkCell. Is notified when a link is
// tapped.
@property(nonatomic, weak) id<TableViewTextLinkCellDelegate> delegate;
// Sets the |URL| link on the cell's label.
- (void)setLinkURL:(const GURL&)URL;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_LINK_ITEM_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/table_view/cells/table_view_text_link_item.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/util/label_link_controller.h"
#import "ios/chrome/common/string_util.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// The width and height of the favicon ImageView.
const CGFloat kTextCellLinkColor = 0x1A73E8;
} // namespace
#pragma mark - TableViewTextLinkItem
@implementation TableViewTextLinkItem
@synthesize text = _text;
@synthesize linkURL = _linkURL;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [TableViewTextLinkCell class];
}
return self;
}
- (void)configureCell:(UITableViewCell*)tableCell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:tableCell withStyler:styler];
TableViewTextLinkCell* cell =
base::mac::ObjCCastStrict<TableViewTextLinkCell>(tableCell);
cell.textLabel.text = self.text;
cell.textLabel.backgroundColor = styler.tableViewBackgroundColor;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setLinkURL:self.linkURL];
}
@end
#pragma mark - TableViewTextLinkCell
@interface TableViewTextLinkCell ()
// LabelLinkController that configures the link on the Cell's text.
@property(nonatomic, strong, readwrite)
LabelLinkController* labelLinkController;
@end
@implementation TableViewTextLinkCell
@synthesize delegate = _delegate;
@synthesize labelLinkController = _labelLinkController;
@synthesize textLabel = _textLabel;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Text Label, set font sizes using dynamic type.
_textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
_textLabel.numberOfLines = 0;
_textLabel.lineBreakMode = NSLineBreakByWordWrapping;
_textLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
_textLabel.textColor = [UIColor grayColor];
// Add subviews to View Hierarchy.
[self.contentView addSubview:_textLabel];
// Set and activate constraints.
[NSLayoutConstraint activateConstraints:@[
// Title Label Constraints.
[_textLabel.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
[_textLabel.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:kTableViewLabelVerticalSpacing],
[_textLabel.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-kTableViewLabelVerticalSpacing],
[_textLabel.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kTableViewHorizontalSpacing]
]];
}
return self;
}
- (void)setLinkURL:(const GURL&)URL {
// Init and configure the labelLinkController.
__weak TableViewTextLinkCell* weakSelf = self;
self.labelLinkController = [[LabelLinkController alloc]
initWithLabel:self.textLabel
action:^(const GURL& URL) {
[[weakSelf delegate] tableViewTextLinkCell:weakSelf
didRequestOpenURL:URL];
}];
[self.labelLinkController setLinkColor:UIColorFromRGB(kTextCellLinkColor)];
// Remove link delimiter from text and get ranges for links. Must be parsed
// before being added to the controller because modifying the label text
// clears all added links.
NSRange otherBrowsingDataRange;
if (URL.is_valid()) {
self.textLabel.text =
ParseStringWithLink(self.textLabel.text, &otherBrowsingDataRange);
DCHECK(otherBrowsingDataRange.location != NSNotFound &&
otherBrowsingDataRange.length);
[self.labelLinkController addLinkWithRange:otherBrowsingDataRange url:URL];
}
}
- (void)prepareForReuse {
[super prepareForReuse];
self.labelLinkController = nil;
self.delegate = nil;
}
@end
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