Commit 2d2bc27e authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Remove dependency of //ios/chrome on GTMFadeTruncatingLabel

The omnibox already had a reimplentation of GTMFadeTruncatingLabel
that used NSAttributedText property to perform the fade-truncation
as OmniboxPopupTruncatingLabel.

Move it to a shared location and rename it to FadeTruncatingLabel
and convert TabView to use the new class thus removing another
dependency on third_party/google_toolbox_for_mac.

Before: https://drive.google.com/file/d/1YeEL6jkm-P9cNeEgS0vJxlPu-HIEo3_r/view
After:  https://drive.google.com/file/d/1U1jAVeXYg4RFiw98UzZ-yoBBoOG2e1MD/view

Bug: none
Change-Id: Ic43f0973d36ba6b74c0ad0a2fa9068d5a3be9bb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901082
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713397}
parent 2c112e7e
......@@ -115,12 +115,12 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
// Open the suggestion. The suggestion needs to be the first suggestion to
// have the prerenderer activated.
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(pageString),
grey_kindOfClassName(
@"OmniboxPopupTruncatingLabel"),
grey_ancestor(grey_accessibilityID(
@"omnibox suggestion 0")),
grey_sufficientlyVisible(), nil)]
selectElementWithMatcher:grey_allOf(
grey_accessibilityLabel(pageString),
grey_kindOfClassName(@"FadeTruncatingLabel"),
grey_ancestor(grey_accessibilityID(
@"omnibox suggestion 0")),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
[ChromeEarlGrey waitForWebStateContainingText:kPageLoadedString];
......
......@@ -7,6 +7,8 @@ source_set("elements") {
sources = [
"extended_touch_target_button.h",
"extended_touch_target_button.mm",
"fade_truncating_label.h",
"fade_truncating_label.mm",
"gray_highlight_button.h",
"gray_highlight_button.mm",
"selector_coordinator.h",
......
......@@ -2,30 +2,28 @@
// 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_TRUNCATING_LABEL_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_TRUNCATING_LABEL_H_
#ifndef IOS_CHROME_BROWSER_UI_ELEMENTS_FADE_TRUNCATING_LABEL_H_
#define IOS_CHROME_BROWSER_UI_ELEMENTS_FADE_TRUNCATING_LABEL_H_
#import <UIKit/UIKit.h>
typedef enum {
OmniboxPopupTruncatingTail = 0x1,
OmniboxPopupTruncatingHead = 0x2,
OmniboxPopupTruncatingHeadAndTail =
OmniboxPopupTruncatingHead | OmniboxPopupTruncatingTail
} OmniboxPopupTruncatingMode;
FadeTruncatingTail = 0x1,
FadeTruncatingHead = 0x2,
FadeTruncatingHeadAndTail = FadeTruncatingHead | FadeTruncatingTail
} FadeTruncatingMode;
// A label which applies a fade-to-background color gradient to one or both ends
// of the string if it is too large to fit the available area. It is based on
// GTMFadeTruncatingLabel but uses the attributedText property of UILabel rather
// than the text and font properties.
@interface OmniboxPopupTruncatingLabel : UILabel
// of the string if it is too large to fit the available area. It uses the
// attributedText property of UILabel to implement the fading.
@interface FadeTruncatingLabel : UILabel
// Which side(s) to truncate.
@property(nonatomic, assign) OmniboxPopupTruncatingMode truncateMode;
@property(nonatomic, assign) FadeTruncatingMode truncateMode;
// Whether the text being displayed should be treated as a URL.
@property(nonatomic, assign) BOOL displayAsURL;
@end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_TRUNCATING_LABEL_H_
#endif // IOS_CHROME_BROWSER_UI_ELEMENTS_FADE_TRUNCATING_LABEL_H_
......@@ -2,28 +2,28 @@
// 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_truncating_label.h"
#import "ios/chrome/browser/ui/elements/fade_truncating_label.h"
#include <algorithm>
#include "base/mac/scoped_cftyperef.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface OmniboxPopupTruncatingLabel ()
@interface FadeTruncatingLabel ()
// Gradient used to create fade effect. Changes based on view.frame size.
@property(nonatomic, strong) UIImage* gradient;
@end
@implementation OmniboxPopupTruncatingLabel
@implementation FadeTruncatingLabel
- (void)setup {
self.backgroundColor = [UIColor clearColor];
_truncateMode = OmniboxPopupTruncatingTail;
_truncateMode = FadeTruncatingTail;
}
- (id)initWithFrame:(CGRect)frame {
......@@ -83,11 +83,11 @@
- (void)setTextAlignment:(NSTextAlignment)textAlignment {
if (textAlignment == NSTextAlignmentLeft) {
self.truncateMode = OmniboxPopupTruncatingTail;
self.truncateMode = FadeTruncatingTail;
} else if (textAlignment == NSTextAlignmentRight) {
self.truncateMode = OmniboxPopupTruncatingHead;
self.truncateMode = FadeTruncatingHead;
} else if (textAlignment == NSTextAlignmentNatural) {
self.truncateMode = OmniboxPopupTruncatingTail;
self.truncateMode = FadeTruncatingTail;
} else {
NOTREACHED();
}
......@@ -103,7 +103,7 @@
// Create an opaque context.
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context =
CGBitmapContextCreate(NULL, rect.size.width, rect.size.height, 8,
CGBitmapContextCreate(nullptr, rect.size.width, rect.size.height, 8,
4 * rect.size.width, colorSpace, kCGImageAlphaNone);
// White background will mask opaque, black gradient will mask transparent.
......@@ -122,13 +122,13 @@
std::min(rect.size.height * 2, (CGFloat)floor(rect.size.width / 4));
CGFloat minX = CGRectGetMinX(rect);
CGFloat maxX = CGRectGetMaxX(rect);
if (self.truncateMode & OmniboxPopupTruncatingTail) {
if (self.truncateMode & FadeTruncatingTail) {
CGFloat startX = maxX - fadeWidth;
CGPoint startPoint = CGPointMake(startX, CGRectGetMidY(rect));
CGPoint endPoint = CGPointMake(maxX, CGRectGetMidY(rect));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
}
if (self.truncateMode & OmniboxPopupTruncatingHead) {
if (self.truncateMode & FadeTruncatingHead) {
CGFloat startX = minX + fadeWidth;
CGPoint startPoint = CGPointMake(startX, CGRectGetMidY(rect));
CGPoint endPoint = CGPointMake(minX, CGRectGetMidY(rect));
......
......@@ -74,8 +74,6 @@ source_set("popup_ui") {
"omnibox_popup_row.mm",
"omnibox_popup_row_cell.h",
"omnibox_popup_row_cell.mm",
"omnibox_popup_truncating_label.h",
"omnibox_popup_truncating_label.mm",
"omnibox_popup_view_controller.h",
"omnibox_popup_view_controller.mm",
"self_sizing_table_view.h",
......
......@@ -9,10 +9,10 @@
#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/omnibox_popup_truncating_label.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"
......@@ -214,7 +214,7 @@ const CGFloat kAnswerRowHeight = 64.0;
[detailTextLabel setNeedsDisplay];
OmniboxPopupTruncatingLabel* textLabel = row.textTruncatingLabel;
FadeTruncatingLabel* textLabel = row.textTruncatingLabel;
[textLabel setTextAlignment:self.alignment];
LayoutRect textLabelLayout =
LayoutRectMake(kTextCellLeadingPadding, CGRectGetWidth(rowBounds), 0,
......
......@@ -7,7 +7,7 @@
#import <UIKit/UIKit.h>
@class OmniboxPopupTruncatingLabel;
@class FadeTruncatingLabel;
@class OmniboxPopupRow;
......@@ -23,11 +23,10 @@
@interface OmniboxPopupRow : UITableViewCell
// A truncate-by-fading version of the textLabel of a UITableViewCell.
@property(nonatomic, readonly, strong)
OmniboxPopupTruncatingLabel* textTruncatingLabel;
@property(nonatomic, readonly, strong) FadeTruncatingLabel* textTruncatingLabel;
// A truncate-by-fading version of the detailTextLabel of a UITableViewCell.
@property(nonatomic, readonly, strong)
OmniboxPopupTruncatingLabel* detailTruncatingLabel;
FadeTruncatingLabel* detailTruncatingLabel;
// A standard UILabel for answers, which truncates with ellipses to support
// multi-line text.
@property(nonatomic, readonly, strong) UILabel* detailAnswerLabel;
......
......@@ -7,8 +7,8 @@
#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/omnibox/popup/omnibox_popup_truncating_label.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"
......@@ -63,12 +63,12 @@ const CGFloat kLeadingPaddingIpadCompact = 71;
[UIColor colorNamed:kTableViewRowHighlightDarkColor]);
_textTruncatingLabel =
[[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero];
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_textTruncatingLabel.userInteractionEnabled = NO;
[self.contentView addSubview:_textTruncatingLabel];
_detailTruncatingLabel =
[[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero];
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_detailTruncatingLabel.userInteractionEnabled = NO;
[self.contentView addSubview:_detailTruncatingLabel];
......
......@@ -9,9 +9,9 @@
#include "components/omnibox/common/omnibox_features.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/elements/extended_touch_target_button.h"
#import "ios/chrome/browser/ui/elements/fade_truncating_label.h"
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_icon_view.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_truncating_label.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -45,9 +45,9 @@ NSString* const kOmniboxPopupRowSwitchTabAccessibilityIdentifier =
// Stack view containing all text labels.
@property(nonatomic, strong) UIStackView* textStackView;
// Truncating label for the main text.
@property(nonatomic, strong) OmniboxPopupTruncatingLabel* textTruncatingLabel;
@property(nonatomic, strong) FadeTruncatingLabel* textTruncatingLabel;
// Truncating label for the detail text.
@property(nonatomic, strong) OmniboxPopupTruncatingLabel* detailTruncatingLabel;
@property(nonatomic, strong) FadeTruncatingLabel* detailTruncatingLabel;
// Regular UILabel for the detail text when the suggestion is an answer.
// Answers have slightly different display requirements, like possibility of
// multiple lines and truncating with ellipses instead of a fade gradient.
......@@ -74,7 +74,7 @@ NSString* const kOmniboxPopupRowSwitchTabAccessibilityIdentifier =
[UIColor colorNamed:kTableViewRowHighlightDarkColor]);
_textTruncatingLabel =
[[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero];
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_textTruncatingLabel.translatesAutoresizingMaskIntoConstraints = NO;
[_textTruncatingLabel
setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh + 1
......@@ -87,7 +87,7 @@ NSString* const kOmniboxPopupRowSwitchTabAccessibilityIdentifier =
_textStackView.alignment = UIStackViewAlignmentLeading;
_detailTruncatingLabel =
[[OmniboxPopupTruncatingLabel alloc] initWithFrame:CGRectZero];
[[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_detailTruncatingLabel.translatesAutoresizingMaskIntoConstraints = NO;
// Answers use a UILabel with NSLineBreakByTruncatingTail to produce a
......
......@@ -48,6 +48,7 @@ source_set("tabs") {
"//ios/chrome/browser/ui/bubble",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/favicon/resources:default_world_favicon",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/browser/ui/image_util",
......@@ -64,7 +65,6 @@ source_set("tabs") {
"//ios/chrome/common/ui_util",
"//ios/third_party/material_components_ios",
"//ios/web",
"//third_party/google_toolbox_for_mac",
"//ui/base",
"//ui/gfx",
]
......
......@@ -14,6 +14,7 @@
#include "ios/chrome/browser/drag_and_drop/drop_and_navigate_delegate.h"
#include "ios/chrome/browser/drag_and_drop/drop_and_navigate_interaction.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/ui/elements/fade_truncating_label.h"
#import "ios/chrome/browser/ui/image_util/image_util.h"
#include "ios/chrome/browser/ui/util/rtl_geometry.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -22,7 +23,6 @@
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/ActivityIndicator/src/MaterialActivityIndicator.h"
#include "third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -70,7 +70,7 @@ UIImage* DefaultFaviconImage() {
UIButton* _closeButton;
// View that draws the tab title.
GTMFadeTruncatingLabel* _titleLabel;
FadeTruncatingLabel* _titleLabel;
// Background image for this tab.
UIImageView* _backgroundImageView;
......@@ -157,9 +157,9 @@ UIImage* DefaultFaviconImage() {
return;
if (base::i18n::GetStringDirection(base::SysNSStringToUTF16(title)) ==
base::i18n::RIGHT_TO_LEFT) {
[_titleLabel setTruncateMode:GTMFadeTruncatingHead];
_titleLabel.truncateMode = FadeTruncatingHead;
} else {
[_titleLabel setTruncateMode:GTMFadeTruncatingTail];
_titleLabel.truncateMode = FadeTruncatingTail;
}
_titleLabel.text = title;
[_closeButton setAccessibilityValue:title];
......@@ -301,15 +301,8 @@ UIImage* DefaultFaviconImage() {
[self addSubview:_closeButton];
// Add fade truncating label.
_titleLabel = [[GTMFadeTruncatingLabel alloc] initWithFrame:CGRectZero];
_titleLabel = [[FadeTruncatingLabel alloc] initWithFrame:CGRectZero];
[_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
// Setting NSLineBreakByCharWrapping fixes an issue where the beginning of the
// text is truncated for RTL text writing direction. Anyway since the label is
// only one line and the end of the text is faded behind a gradient mask, it
// is visually almost equivalent to NSLineBreakByClipping.
[_titleLabel setLineBreakMode:NSLineBreakByCharWrapping];
[_titleLabel setTextAlignment:NSTextAlignmentNatural];
[self addSubview:_titleLabel];
......
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