Commit cd9cbb30 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Deletes c/b/ui/ntp/recent_tabs.

Since the legacy recent_tabs and history code
has been deleted these views are no longer being used.


Bug: 807330
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I27af5f605f9088356b2e59566362be53710d45be
Reviewed-on: https://chromium-review.googlesource.com/c/1259425Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596461}
parent ed55781e
gambard@chromium.org
sczs@chromium.org
# TEAM: ios-directory-owners@chromium.org
# OS: iOS
# Copyright 2016 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.
source_set("views") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"disclosure_view.h",
"disclosure_view.mm",
"generic_section_header_view.h",
"generic_section_header_view.mm",
"header_of_collapsable_section_protocol.h",
"panel_bar_view.h",
"panel_bar_view.mm",
"session_section_header_view.h",
"session_section_header_view.mm",
"session_tab_data_view.h",
"session_tab_data_view.mm",
"show_full_history_view.h",
"show_full_history_view.mm",
"signed_in_sync_in_progress_view.h",
"signed_in_sync_in_progress_view.mm",
"signed_in_sync_off_view.h",
"signed_in_sync_off_view.mm",
"signed_in_sync_on_no_sessions_view.h",
"signed_in_sync_on_no_sessions_view.mm",
"spacers_view.h",
"spacers_view.mm",
"views_utils.h",
"views_utils.mm",
]
deps = [
"//base",
"//components/browser_sync",
"//components/resources",
"//components/sessions",
"//components/strings",
"//components/sync",
"//components/sync_sessions",
"//ios/chrome/app/strings",
"//ios/chrome/app/theme:theme_grit",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/fancy_ui",
"//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui",
"//ios/chrome/browser/ui/settings/sync_utils",
"//ios/chrome/common/favicon",
"//ios/third_party/material_components_ios",
"//ios/third_party/material_roboto_font_loader_ios",
"//ui/base",
]
libs = [ "UIKit.framework" ]
}
// Copyright 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_NTP_RECENT_TABS_VIEWS_DISCLOSURE_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_DISCLOSURE_VIEW_H_
#import <UIKit/UIKit.h>
// View indicating whether a table view section is expanded or not.
@interface DisclosureView : UIImageView
// Designated initializer.
- (instancetype)init;
// Sets whether the view indicates that the section is collapsed or not, with an
// animation or not.
- (void)setTransformWhenCollapsed:(BOOL)collapsed animated:(BOOL)animated;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_DISCLOSURE_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/disclosure_view.h"
#include "base/numerics/math_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Animation duration for rotating the disclosure icon.
const NSTimeInterval kDisclosureIconRotateDuration = 0.25;
// Angles of the closure icon.
// The rotation animation privileges rotating using the smallest angle. Setting
// |kCollapsedIconAngle| to a value slightly less then 0 forces the animation to
// always happen in the same half-plane.
const CGFloat kCollapsedIconAngle = -0.00001;
const CGFloat kExpandedIconAngle = base::kPiFloat;
} // anonymous namespace
@implementation DisclosureView
- (instancetype)init {
UIImage* arrowImage = [[UIImage imageNamed:@"ntp_opentabs_recent_arrow"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self = [super initWithImage:arrowImage];
return self;
}
- (void)setTransformWhenCollapsed:(BOOL)collapsed animated:(BOOL)animated {
CGFloat angle = collapsed ? kCollapsedIconAngle : kExpandedIconAngle;
if (animated) {
[UIView animateWithDuration:kDisclosureIconRotateDuration
animations:^{
self.transform = CGAffineTransformRotate(
CGAffineTransformIdentity, angle);
}];
} else {
self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, angle);
}
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_GENERIC_SECTION_HEADER_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_GENERIC_SECTION_HEADER_VIEW_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/header_of_collapsable_section_protocol.h"
namespace recent_tabs {
enum SectionHeaderType {
RECENTLY_CLOSED_TABS_SECTION_HEADER,
OTHER_DEVICES_SECTION_HEADER
};
} // namespace recent_tabs
// View for the generic section header.
@interface GenericSectionHeaderView : UIView<HeaderOfCollapsableSectionProtocol>
// Designated initializer.
- (instancetype)initWithType:(recent_tabs::SectionHeaderType)type
sectionIsCollapsed:(BOOL)collapsed;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_GENERIC_SECTION_HEADER_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/generic_section_header_view.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/disclosure_view.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/recent_tabs/synced_sessions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#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/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/l10n/time_format.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 48;
} // namespace
@interface GenericSectionHeaderView () {
DisclosureView* _disclosureView;
UIImageView* _icon;
UILabel* _label;
}
@end
@implementation GenericSectionHeaderView
- (instancetype)initWithFrame:(CGRect)aRect {
NOTREACHED();
return nil;
}
- (instancetype)initWithType:(recent_tabs::SectionHeaderType)type
sectionIsCollapsed:(BOOL)collapsed {
self = [super initWithFrame:CGRectZero];
if (self) {
_icon = [[UIImageView alloc] initWithImage:nil];
[_icon setTranslatesAutoresizingMaskIntoConstraints:NO];
_label = [[UILabel alloc] initWithFrame:CGRectZero];
[_label setTranslatesAutoresizingMaskIntoConstraints:NO];
[_label setFont:[[MDCTypography fontLoader] regularFontOfSize:16]];
[_label setTextAlignment:NSTextAlignmentNatural];
[_label setBackgroundColor:[UIColor whiteColor]];
NSString* text = nil;
NSString* imageName = nil;
switch (type) {
case recent_tabs::RECENTLY_CLOSED_TABS_SECTION_HEADER:
text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_RECENTLY_CLOSED);
imageName = @"ntp_recently_closed";
break;
case recent_tabs::OTHER_DEVICES_SECTION_HEADER:
text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_OTHER_DEVICES);
imageName = @"ntp_opentabs_laptop";
break;
}
DCHECK(text);
DCHECK(imageName);
[_label setText:text];
[_icon setImage:
[[UIImage imageNamed:imageName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
self.isAccessibilityElement = YES;
self.accessibilityLabel = [_label accessibilityLabel];
self.accessibilityTraits |=
UIAccessibilityTraitButton | UIAccessibilityTraitHeader;
_disclosureView = [[DisclosureView alloc] init];
[_disclosureView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:_icon];
[self addSubview:_label];
[self addSubview:_disclosureView];
NSDictionary* viewsDictionary = @{
@"icon" : _icon,
@"label" : _label,
@"disclosureView" : _disclosureView,
};
NSArray* constraints = @[
@"H:|-16-[icon]-16-[label]-(>=16)-[disclosureView]-16-|",
@"V:|-12-[label]-12-|"
];
ApplyVisualConstraints(constraints, viewsDictionary);
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_disclosureView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_icon
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:_label
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self setSectionIsCollapsed:collapsed animated:NO];
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
#pragma mark - HeaderOfCollapsableSectionProtocol
- (void)setSectionIsCollapsed:(BOOL)collapsed animated:(BOOL)animated {
[_disclosureView setTransformWhenCollapsed:collapsed animated:animated];
UIColor* tintColor = (collapsed ? recent_tabs::GetIconColorGray()
: recent_tabs::GetIconColorBlue());
[self setTintColor:tintColor];
UIColor* textColor = (collapsed ? recent_tabs::GetTextColorGray()
: recent_tabs::GetTextColorBlue());
[_label setTextColor:textColor];
self.accessibilityHint =
collapsed ? l10n_util::GetNSString(
IDS_IOS_RECENT_TABS_DISCLOSURE_VIEW_COLLAPSED_HINT)
: l10n_util::GetNSString(
IDS_IOS_RECENT_TABS_DISCLOSURE_VIEW_EXPANDED_HINT);
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_HEADER_OF_COLLAPSABLE_SECTION_PROTOCOL_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_HEADER_OF_COLLAPSABLE_SECTION_PROTOCOL_H_
// Implemented by views that are headers of collapsable sections.
@protocol HeaderOfCollapsableSectionProtocol
// Sets whether the section is collapsed with or without animation.
- (void)setSectionIsCollapsed:(BOOL)collapsed animated:(BOOL)animated;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_HEADER_OF_COLLAPSABLE_SECTION_PROTOCOL_H_
// Copyright 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_NTP_RECENT_TABS_VIEWS_PANEL_BAR_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_PANEL_BAR_VIEW_H_
#import <UIKit/UIKit.h>
// View for the bar located at the top of the Recent Tabs panel.
@interface PanelBarView : UIView
// Designated initializer.
- (instancetype)init;
// Sets the target/action of the close button.
- (void)setCloseTarget:(id)target action:(SEL)action;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_PANEL_BAR_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/panel_bar_view.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#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/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const int kBackgroundColor = 0xf2f2f2;
const CGFloat kFontSize = 20;
const CGFloat kSpacing = 16;
} // namespace
@interface PanelBarView () {
UIButton* _closeButton;
NSLayoutConstraint* _statusBarSpacerConstraint;
}
// Whether the panel view extends throughout the whole screen. For example,
// when presented fullscreen, the panel bar extends to the borders of the app
// and the function returns YES.
// When presented modally as on iPad and iPhone 6 Plus landscape, it returns NO.
- (BOOL)coversFullAppWidth;
@end
@implementation PanelBarView
- (instancetype)init {
self = [super initWithFrame:CGRectZero];
if (self) {
[self setBackgroundColor:UIColorFromRGB(kBackgroundColor)];
// Create and add the bar's title.
UILabel* title = [[UILabel alloc] initWithFrame:CGRectZero];
[title setTranslatesAutoresizingMaskIntoConstraints:NO];
[title setFont:[[MDCTypography fontLoader] mediumFontOfSize:kFontSize]];
[title setTextColor:recent_tabs::GetTextColorGray()];
[title setTextAlignment:NSTextAlignmentNatural];
[title setText:l10n_util::GetNSString(IDS_IOS_NEW_TAB_RECENT_TABS)];
[title setBackgroundColor:UIColorFromRGB(kBackgroundColor)];
[self addSubview:title];
// Create and add the bar's close button.
_closeButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_closeButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[_closeButton
setTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)
.uppercaseString
forState:UIControlStateNormal];
[_closeButton setTitleColor:recent_tabs::GetTextColorGray()
forState:UIControlStateNormal];
[[_closeButton titleLabel] setFont:[MDCTypography buttonFont]];
[_closeButton setAccessibilityIdentifier:@"Exit"];
[self addSubview:_closeButton];
// Create and add the view that adds vertical padding that matches the
// status bar's height.
UIView* statusBarSpacer = [[UIView alloc] initWithFrame:CGRectZero];
[statusBarSpacer setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:statusBarSpacer];
// Add the constraints on all the subviews.
NSDictionary* viewsDictionary = @{
@"title" : title,
@"closeButton" : _closeButton,
@"statusBar" : statusBarSpacer,
};
NSArray* constraints = @[
@"V:|-0-[statusBar]-14-[closeButton]-13-|",
@"H:[title]-(>=0)-[closeButton]",
];
ApplyVisualConstraints(constraints, viewsDictionary);
id<LayoutGuideProvider> safeAreaLayoutGuide =
SafeAreaLayoutGuideForView(self);
[NSLayoutConstraint activateConstraints:@[
[title.leadingAnchor
constraintEqualToAnchor:safeAreaLayoutGuide.leadingAnchor
constant:kSpacing],
[_closeButton.trailingAnchor
constraintEqualToAnchor:safeAreaLayoutGuide.trailingAnchor
constant:-kSpacing],
]];
AddSameCenterYConstraint(self, title, _closeButton);
_statusBarSpacerConstraint =
[NSLayoutConstraint constraintWithItem:statusBarSpacer
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:0];
[self addConstraint:_statusBarSpacerConstraint];
}
return self;
}
- (void)updateConstraints {
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
// On Plus phones in landscape, the modal is not fullscreen. The panel bar
// doesn't need to take the status bar into account.
BOOL takeStatusBarIntoAccount = [self coversFullAppWidth] ||
UIInterfaceOrientationIsPortrait(orientation);
if (takeStatusBarIntoAccount) {
CGFloat statusBarHeight = StatusBarHeight();
[_statusBarSpacerConstraint setConstant:statusBarHeight];
} else {
[_statusBarSpacerConstraint setConstant:0];
}
[super updateConstraints];
}
- (void)setCloseTarget:(id)target action:(SEL)action {
[_closeButton addTarget:target
action:action
forControlEvents:UIControlEventTouchUpInside];
}
- (void)layoutSubviews {
[self setNeedsUpdateConstraints];
[super layoutSubviews];
}
- (BOOL)coversFullAppWidth {
return self.traitCollection.horizontalSizeClass ==
self.window.traitCollection.horizontalSizeClass;
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SESSION_SECTION_HEADER_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SESSION_SECTION_HEADER_VIEW_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/header_of_collapsable_section_protocol.h"
namespace synced_sessions {
class DistantSession;
} // namespace synced_sessions
// View for the header of the sessions section.
@interface SessionSectionHeaderView : UIView<HeaderOfCollapsableSectionProtocol>
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect sectionIsCollapsed:(BOOL)collapsed;
// Updates view to display information for |distantSession|.
- (void)updateWithSession:
(synced_sessions::DistantSession const*)distantSession;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SESSION_SECTION_HEADER_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/session_section_header_view.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/disclosure_view.h"
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/recent_tabs/synced_sessions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#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/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/l10n/time_format.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 72;
// The UI displays relative time for up to this number of hours and then
// switches to absolute values.
const int kRelativeTimeMaxHours = 4;
} // namespace
@interface SessionSectionHeaderView () {
UIImageView* _deviceIcon;
UILabel* _nameLabel;
UILabel* _timeLabel;
DisclosureView* _disclosureView;
}
// Returns a relative string (e.g. 15 mins ago) if the time passed in is within
// the last 4 hours. Returns the full formatted time in short style otherwise.
- (NSString*)relativeTimeStringForTime:(base::Time)time;
@end
@implementation SessionSectionHeaderView
- (instancetype)initWithFrame:(CGRect)aRect sectionIsCollapsed:(BOOL)collapsed {
self = [super initWithFrame:aRect];
if (self) {
_deviceIcon = [[UIImageView alloc] initWithImage:nil];
[_deviceIcon setTranslatesAutoresizingMaskIntoConstraints:NO];
_nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[_nameLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[_nameLabel setHighlightedTextColor:[_nameLabel textColor]];
[_nameLabel setTextAlignment:NSTextAlignmentNatural];
[_nameLabel setFont:[[MDCTypography fontLoader] regularFontOfSize:16]];
[_nameLabel setBackgroundColor:[UIColor whiteColor]];
[_nameLabel
setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:
UILayoutConstraintAxisHorizontal];
_timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[_timeLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[_timeLabel setTextAlignment:NSTextAlignmentNatural];
[_timeLabel setFont:[MDCTypography captionFont]];
[_timeLabel setHighlightedTextColor:[_timeLabel textColor]];
[_timeLabel setBackgroundColor:[UIColor whiteColor]];
_disclosureView = [[DisclosureView alloc] init];
[_disclosureView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:_deviceIcon];
[self addSubview:_nameLabel];
[self addSubview:_timeLabel];
[self addSubview:_disclosureView];
NSDictionary* viewsDictionary = @{
@"deviceIcon" : _deviceIcon,
@"nameLabel" : _nameLabel,
@"timeLabel" : _timeLabel,
@"disclosureView" : _disclosureView,
};
NSArray* constraints = @[
@"H:|-16-[deviceIcon]-16-[nameLabel]-(>=16)-[disclosureView]-16-|",
@"V:|-16-[nameLabel]-5-[timeLabel]-16-|",
@"H:[deviceIcon]-16-[timeLabel]",
];
ApplyVisualConstraints(constraints, viewsDictionary);
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_disclosureView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_deviceIcon
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:_nameLabel
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self setSectionIsCollapsed:collapsed animated:NO];
}
// TODO(jif): Add timer that refreshes the time label.
return self;
}
- (void)updateWithSession:
(synced_sessions::DistantSession const*)distantSession {
NSString* imageName = nil;
switch (distantSession->device_type) {
case sync_pb::SyncEnums::TYPE_PHONE:
imageName = @"ntp_opentabs_phone";
break;
case sync_pb::SyncEnums::TYPE_TABLET:
imageName = @"ntp_opentabs_tablet";
break;
default:
imageName = @"ntp_opentabs_laptop";
break;
}
[_deviceIcon
setImage:[[UIImage imageNamed:imageName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[_nameLabel setText:base::SysUTF8ToNSString(distantSession->name)];
NSDate* lastUsedDate = [NSDate
dateWithTimeIntervalSince1970:distantSession->modified_time.ToTimeT()];
NSString* timeString =
[self relativeTimeStringForTime:distantSession->modified_time];
NSString* dateString =
[NSDateFormatter localizedStringFromDate:lastUsedDate
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterNoStyle];
NSString* timeDateString =
[NSString stringWithFormat:@"%@ %@", timeString, dateString];
[_timeLabel setText:l10n_util::GetNSStringF(
IDS_IOS_OPEN_TABS_LAST_USED,
base::SysNSStringToUTF16(timeDateString))];
}
- (NSString*)relativeTimeStringForTime:(base::Time)time {
base::TimeDelta last_used_delta;
if (base::Time::Now() > time)
last_used_delta = base::Time::Now() - time;
if (last_used_delta.ToInternalValue() < base::Time::kMicrosecondsPerMinute)
return l10n_util::GetNSString(IDS_IOS_OPEN_TABS_RECENTLY_SYNCED);
if (last_used_delta.InHours() < kRelativeTimeMaxHours) {
return base::SysUTF16ToNSString(
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
ui::TimeFormat::LENGTH_SHORT, last_used_delta));
}
NSDate* date = [NSDate dateWithTimeIntervalSince1970:time.ToTimeT()];
return [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterShortStyle];
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
#pragma mark - HeaderOfCollapsableSectionProtocol
- (void)setSectionIsCollapsed:(BOOL)collapsed animated:(BOOL)animated {
[_disclosureView setTransformWhenCollapsed:collapsed animated:animated];
UIColor* tintColor = (collapsed ? recent_tabs::GetIconColorGray()
: recent_tabs::GetIconColorBlue());
[self setTintColor:tintColor];
UIColor* textColor = (collapsed ? recent_tabs::GetTextColorGray()
: recent_tabs::GetTextColorBlue());
[_nameLabel setTextColor:textColor];
UIColor* subtitleColor = (collapsed ? recent_tabs::GetSubtitleColorGray()
: recent_tabs::GetSubtitleColorBlue());
[_timeLabel setTextColor:subtitleColor];
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SESSION_TAB_DATA_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SESSION_TAB_DATA_VIEW_H_
#import <UIKit/UIKit.h>
#include "components/sessions/core/tab_restore_service.h"
namespace ios {
class ChromeBrowserState;
}
namespace synced_sessions {
struct DistantTab;
}
class GURL;
// View displaying a tab's title and favicon.
@interface SessionTabDataView : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect;
// Updates view to display information for the |distantTab| using |browserState|
// to obtain favicons. |browserState| and |distantTab| must not be nil.
- (void)updateWithDistantTab:(synced_sessions::DistantTab const*)distantTab
browserState:(ios::ChromeBrowserState*)browserState;
// Updates view to display information for the |entry| using |browserState| to
// obtain favicons. |browserState| and |entry| must not be nil.
- (void)updateWithTabRestoreEntry:
(const sessions::TabRestoreService::Entry*)entry
browserState:(ios::ChromeBrowserState*)browserState;
// Updates view to display the |text| and |url| using |browserState| to obtain
// favicons. |text| and |browserState| must not be nil.
- (void)setText:(NSString*)text
url:(const GURL&)url
browserState:(ios::ChromeBrowserState*)browserState;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SESSION_TAB_DATA_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/session_tab_data_view.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "components/grit/components_scaled_resources.h"
#import "ios/chrome/browser/favicon/favicon_loader.h"
#include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/recent_tabs/synced_sessions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/common/favicon/favicon_attributes.h"
#import "ios/chrome/common/favicon/favicon_view.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/resource/resource_bundle.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 48;
} // namespace
@interface SessionTabDataView () {
FaviconViewNew* _favicon;
UILabel* _label;
}
@end
@implementation SessionTabDataView
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:aRect];
if (self) {
_favicon = [[FaviconViewNew alloc] init];
[_favicon setTranslatesAutoresizingMaskIntoConstraints:NO];
_label = [[UILabel alloc] initWithFrame:CGRectZero];
[_label setLineBreakMode:NSLineBreakByTruncatingTail];
[_label setTranslatesAutoresizingMaskIntoConstraints:NO];
[_label setFont:[[MDCTypography fontLoader] regularFontOfSize:16]];
[_label setTextAlignment:NSTextAlignmentNatural];
[_label setTextColor:recent_tabs::GetTextColorGray()];
[_label setHighlightedTextColor:[_label textColor]];
[_label setBackgroundColor:[UIColor whiteColor]];
self.isAccessibilityElement = YES;
self.accessibilityTraits |= UIAccessibilityTraitButton;
[self addSubview:_favicon];
[self addSubview:_label];
NSDictionary* viewsDictionary = @{
@"favicon" : _favicon,
@"label" : _label,
};
NSArray* constraints = @[
@"H:|-56-[favicon(==16)]-16-[label]-16-|",
@"V:|-(>=0)-[favicon(==16)]-(>=0)-|"
];
ApplyVisualConstraints(constraints, viewsDictionary);
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_favicon
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_label
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
}
return self;
}
- (void)updateWithDistantTab:(synced_sessions::DistantTab const*)distantTab
browserState:(ios::ChromeBrowserState*)browserState {
DCHECK(distantTab);
DCHECK(browserState);
NSString* text = base::SysUTF16ToNSString(distantTab->title);
GURL url = distantTab->virtual_url;
[self setText:text url:url browserState:browserState];
}
- (void)setText:(NSString*)text
url:(const GURL&)url
browserState:(ios::ChromeBrowserState*)browserState {
DCHECK(text);
DCHECK(browserState);
[_label setText:text];
self.accessibilityLabel = [_label accessibilityLabel];
recent_tabs::GetFavicon(url, browserState, ^(FaviconAttributes* attributes) {
[_favicon configureWithAttributes:attributes];
});
}
- (void)updateWithTabRestoreEntry:
(const sessions::TabRestoreService::Entry*)entry
browserState:(ios::ChromeBrowserState*)browserState {
DCHECK(entry);
DCHECK(browserState);
switch (entry->type) {
case sessions::TabRestoreService::TAB: {
const sessions::TabRestoreService::Tab* tab =
static_cast<const sessions::TabRestoreService::Tab*>(entry);
const sessions::SerializedNavigationEntry& entry =
tab->navigations[tab->current_navigation_index];
// Use the page's title for the label, or its URL if title is empty.
NSString* text;
if (entry.title().size()) {
text = base::SysUTF16ToNSString(entry.title());
} else {
text = base::SysUTF8ToNSString(entry.virtual_url().spec());
}
[self setText:text url:entry.virtual_url() browserState:browserState];
break;
}
case sessions::TabRestoreService::WINDOW: {
// We only handle the TAB type.
NOTREACHED() << "TabRestoreService WINDOW session type is invalid.";
break;
}
}
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SHOW_FULL_HISTORY_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SHOW_FULL_HISTORY_VIEW_H_
#import <UIKit/UIKit.h>
// View offering to display the full history.
@interface ShowFullHistoryView : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SHOW_FULL_HISTORY_VIEW_H_
// Copyright 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.
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/show_full_history_view.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#import "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 48;
} // namespace
@implementation ShowFullHistoryView
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:aRect];
if (self) {
UIImageView* icon = [[UIImageView alloc] initWithImage:nil];
[icon setTranslatesAutoresizingMaskIntoConstraints:NO];
[icon setImage:[UIImage imageNamed:@"ntp_opentabs_clock"]];
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
[label setFont:[[MDCTypography fontLoader] regularFontOfSize:16]];
[label setTextAlignment:NSTextAlignmentNatural];
[label setTextColor:recent_tabs::GetTextColorGray()];
[label setText:l10n_util::GetNSString(IDS_HISTORY_SHOWFULLHISTORY_LINK)];
[label setBackgroundColor:[UIColor whiteColor]];
[self addSubview:icon];
[self addSubview:label];
self.isAccessibilityElement = YES;
self.accessibilityLabel = label.text;
self.accessibilityTraits |= UIAccessibilityTraitButton;
NSDictionary* viewsDictionary = @{
@"icon" : icon,
@"label" : label,
};
NSArray* constraints =
@[ @"H:|-56-[icon(==16)]-16-[label]-(>=16)-|", @"V:[icon(==16)]" ];
ApplyVisualConstraints(constraints, viewsDictionary);
[self addConstraint:[NSLayoutConstraint
constraintWithItem:icon
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:label
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
@end
// Copyright 2015 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_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_IN_PROGRESS_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_IN_PROGRESS_VIEW_H_
#import <UIKit/UIKit.h>
// View indicating that the syncing is currently occurring.
@interface SignedInSyncInProgressView : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_IN_PROGRESS_VIEW_H_
// Copyright 2015 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/ntp/recent_tabs/views/signed_in_sync_in_progress_view.h"
#import "ios/chrome/browser/ui/material_components/activity_indicator.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#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"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 48;
} // anonymous namespace
@implementation SignedInSyncInProgressView
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:CGRectZero];
if (self) {
MDCActivityIndicator* activityIndicator;
UIImageView* icon;
UILabel* label;
icon = [[UIImageView alloc] initWithImage:nil];
[icon setTranslatesAutoresizingMaskIntoConstraints:NO];
[icon setImage:
[[UIImage imageNamed:@"ntp_opentabs_laptop"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
[label setFont:[[MDCTypography fontLoader] regularFontOfSize:16]];
[label setText:l10n_util::GetNSString(IDS_IOS_RECENT_TABS_OTHER_DEVICES)];
[label setBackgroundColor:[UIColor whiteColor]];
activityIndicator = [[MDCActivityIndicator alloc] initWithFrame:CGRectZero];
[activityIndicator setCycleColors:ActivityIndicatorBrandedCycleColors()];
[activityIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];
[activityIndicator startAnimating];
self.tintColor = recent_tabs::GetIconColorGray();
self.isAccessibilityElement = YES;
self.accessibilityLabel = [label accessibilityLabel];
self.accessibilityTraits |=
UIAccessibilityTraitButton | UIAccessibilityTraitHeader;
[self addSubview:icon];
[self addSubview:label];
[self addSubview:activityIndicator];
NSDictionary* viewsDictionary = @{
@"icon" : icon,
@"label" : label,
@"activityIndicator" : activityIndicator,
};
NSArray* constraints = @[
@"H:|-16-[icon]-16-[label]-(>=16)-[activityIndicator(16)]-20-|",
@"V:|-12-[label]-12-|",
@"V:[activityIndicator(16)]",
];
ApplyVisualConstraints(constraints, viewsDictionary);
[self addConstraint:[NSLayoutConstraint
constraintWithItem:activityIndicator
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:icon
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:label
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_OFF_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_OFF_VIEW_H_
#import <UIKit/UIKit.h>
@protocol SyncPresenter;
namespace ios {
class ChromeBrowserState;
}
// View displaying a tab's title and favicon.
@interface SignedInSyncOffView : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect
browserState:(ios::ChromeBrowserState*)browserState
presenter:(id<SyncPresenter>)presenter
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_OFF_VIEW_H_
// Copyright 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/ntp/recent_tabs/views/signed_in_sync_off_view.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/fancy_ui/primary_action_button.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_presenter.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 180;
} // anonymous namespace
@interface SignedInSyncOffView ()
// Presenter for displaying UI.
@property(nonatomic, readonly, weak) id<SyncPresenter> presenter;
@end
@implementation SignedInSyncOffView {
ios::ChromeBrowserState* _browserState; // Weak.
}
@synthesize presenter = _presenter;
- (instancetype)initWithFrame:(CGRect)aRect
browserState:(ios::ChromeBrowserState*)browserState
presenter:(id<SyncPresenter>)presenter {
self = [super initWithFrame:CGRectZero];
if (self) {
_browserState = browserState;
_presenter = presenter;
// Create and add sign in label.
UILabel* enableSyncLabel = recent_tabs::CreateMultilineLabel(
l10n_util::GetNSString(IDS_IOS_OPEN_TABS_SYNC_IS_OFF_MOBILE));
[self addSubview:enableSyncLabel];
// Create and add sign in button.
PrimaryActionButton* enableSyncButton = [[PrimaryActionButton alloc] init];
[enableSyncButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[enableSyncButton
setTitle:l10n_util::GetNSString(IDS_IOS_OPEN_TABS_ENABLE_SYNC_MOBILE)
forState:UIControlStateNormal];
[enableSyncButton addTarget:self
action:@selector(showSyncSettings)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:enableSyncButton];
// Set constraints on label and button.
NSDictionary* viewsDictionary = @{
@"label" : enableSyncLabel,
@"button" : enableSyncButton,
};
// clang-format off
NSArray* constraints = @[
@"V:|-16-[label]-16-[button]-(>=16)-|",
@"H:|-16-[label]-16-|",
@"H:|-(>=16)-[button]-16-|"
];
// clang-format on
ApplyVisualConstraints(constraints, viewsDictionary);
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
- (void)showSyncSettings {
SyncSetupService::SyncServiceState syncState =
GetSyncStateForBrowserState(_browserState);
if (ShouldShowSyncSignin(syncState)) {
[self.presenter showReauthenticateSignin];
} else if (ShouldShowSyncSettings(syncState)) {
[self.presenter showSyncSettings];
} else if (ShouldShowSyncPassphraseSettings(syncState)) {
[self.presenter showSyncPassphraseSettings];
}
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_ON_NO_SESSIONS_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_ON_NO_SESSIONS_VIEW_H_
#import <UIKit/UIKit.h>
// View indicating when a user is signed in and has sync activated, but has no
// sessions.
@interface SignedInSyncOnNoSessionsView : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SIGNED_IN_SYNC_ON_NO_SESSIONS_VIEW_H_
// Copyright 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/ntp/recent_tabs/views/signed_in_sync_on_no_sessions_view.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kDesiredHeight = 130;
} // anonymous namespace
@implementation SignedInSyncOnNoSessionsView
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:CGRectZero];
if (self) {
// Create and add the label.
UILabel* noSessionLabel = recent_tabs::CreateMultilineLabel(
l10n_util::GetNSString(IDS_IOS_OPEN_TABS_NO_SESSION_INSTRUCTIONS));
[self addSubview:noSessionLabel];
// Set constraints on the label.
NSDictionary* viewsDictionary = @{ @"label" : noSessionLabel };
NSArray* constraints =
@[ @"V:|-16-[label]-(>=16)-|", @"H:|-16-[label]-16-|" ];
ApplyVisualConstraints(constraints, viewsDictionary);
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kDesiredHeight;
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_SPACERS_VIEW_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SPACERS_VIEW_H_
#import <UIKit/UIKit.h>
// View adding space at the top of the Recent Tabs view.
@interface RecentlyTabsTopSpacingHeader : UIView
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
// View adding space at the bottom of the Recently Closed section.
@interface RecentlyClosedSectionFooter : UIView
// Designated initializer.
- (instancetype)initWithFrame:(CGRect)aRect;
// Returns the desired height when included in a UITableViewCell.
+ (CGFloat)desiredHeightInUITableViewCell;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_SPACERS_VIEW_H_
// Copyright 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/ntp/recent_tabs/views/spacers_view.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Desired height of the view.
const CGFloat kHeaderDesiredHeightIPhone = 8;
const CGFloat kHeaderDesiredHeightIPad = 48;
const CGFloat kFooterDesiredHeight = 17;
// Text color.
const int kSeparatorColor = 0x5a5a5a;
const CGFloat kSeparatorAlpha = 0.1;
} // namespace
@implementation RecentlyTabsTopSpacingHeader
+ (CGFloat)desiredHeightInUITableViewCell {
if (IsIPadIdiom()) {
return kHeaderDesiredHeightIPad;
} else {
return kHeaderDesiredHeightIPhone;
}
}
@end
@implementation RecentlyClosedSectionFooter
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:CGRectZero];
if (self) {
// Create and add separator.
UIView* separator = [[UIView alloc] init];
[separator setTranslatesAutoresizingMaskIntoConstraints:NO];
UIColor* separatorColor = UIColorFromRGB(kSeparatorColor, kSeparatorAlpha);
[separator setBackgroundColor:separatorColor];
[self addSubview:separator];
// Set constraints on separator.
NSDictionary* viewsDictionary = @{ @"separator" : separator };
// This set of constraints should match the constraints set on the
// RecentTabsTableViewController.
// clang-format off
NSArray* constraints = @[
@"V:|-(8)-[separator(==1)]",
@"H:|-(16)-[separator(<=516)]-(16)-|",
@"H:[separator(==516@500)]"
];
// clang-format on
[self addConstraint:[NSLayoutConstraint
constraintWithItem:separator
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
ApplyVisualConstraints(constraints, viewsDictionary);
}
return self;
}
+ (CGFloat)desiredHeightInUITableViewCell {
return kFooterDesiredHeight;
}
@end
// Copyright 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_NTP_RECENT_TABS_VIEWS_VIEWS_UTILS_H_
#define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_VIEWS_UTILS_H_
#import <UIKit/UIKit.h>
class GURL;
@class FaviconAttributes;
@class UIImage;
namespace ios {
class ChromeBrowserState;
} // namespace ios
typedef void (^FaviconGetterCompletionBlock)(FaviconAttributes*);
namespace recent_tabs {
// Returns an autoreleased UILabel.
UILabel* CreateMultilineLabel(NSString* text);
// Color helpers.
UIColor* GetTextColorBlue();
UIColor* GetTextColorGray();
UIColor* GetSubtitleColorBlue();
UIColor* GetSubtitleColorGray();
UIColor* GetIconColorBlue();
UIColor* GetIconColorGray();
// Gets the favicon for |url|, calls |block| when loaded.
void GetFavicon(GURL const& url,
ios::ChromeBrowserState* browserState,
FaviconGetterCompletionBlock block);
} // namespace recent_tabs
#endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_VIEWS_VIEWS_UTILS_H_
// Copyright 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/ntp/recent_tabs/views/views_utils.h"
#include "base/logging.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync_sessions/open_tabs_ui_delegate.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/favicon/favicon_loader.h"
#include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/favicon/favicon_attributes.h"
#include "ios/chrome/grit/ios_theme_resources.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Text color.
const int kTextColorBlue = 0x4285f4;
const int kTextColorGray = 0x333333;
// Subtitle text color.
const int kSubtitleColorBlue = 0x7daeff;
const int kSubtitleColorGray = 0x969696;
// Colors for the icons.
const int kIconColorBlue = 0x4285f4;
const int kIconColorGray = 0x5a5a5a;
// Desired width and height of favicon.
const CGFloat kfaviconWidthHeight = 24;
// Minimum favicon pixel size to retrieve.
const CGFloat kfaviconMinWidthHeight = 16;
} // namespace
namespace recent_tabs {
UIImage* DefaultFaviconImage() {
return NativeImage(IDR_IOS_OMNIBOX_HTTP);
}
UILabel* CreateMultilineLabel(NSString* text) {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
[label setText:text];
[label setLineBreakMode:NSLineBreakByWordWrapping];
[label setNumberOfLines:0];
[label setFont:[MDCTypography body1Font]];
[label setTextColor:UIColorFromRGB(kTextColorGray)];
[label setTextAlignment:NSTextAlignmentNatural];
[label setBackgroundColor:[UIColor whiteColor]];
return label;
}
UIColor* GetTextColorBlue() {
return UIColorFromRGB(kTextColorBlue);
}
UIColor* GetTextColorGray() {
return UIColorFromRGB(kTextColorGray);
}
UIColor* GetSubtitleColorBlue() {
return UIColorFromRGB(kSubtitleColorBlue);
}
UIColor* GetSubtitleColorGray() {
return UIColorFromRGB(kSubtitleColorGray);
}
UIColor* GetIconColorBlue() {
return UIColorFromRGB(kIconColorBlue);
}
UIColor* GetIconColorGray() {
return UIColorFromRGB(kIconColorGray);
}
void GetFavicon(GURL const& url,
ios::ChromeBrowserState* browser_state,
FaviconGetterCompletionBlock block) {
DCHECK(browser_state);
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetForBrowserState(browser_state);
sync_sessions::OpenTabsUIDelegate* open_tabs =
sync_service ? sync_service->GetOpenTabsUIDelegate() : NULL;
scoped_refptr<base::RefCountedMemory> favicon;
if (open_tabs &&
open_tabs->GetSyncedFaviconForPageURL(url.spec(), &favicon)) {
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
dispatch_async(queue, ^{
NSData* pngData =
[NSData dataWithBytes:favicon->front() length:favicon->size()];
UIImage* image = [[UIImage alloc] initWithData:pngData];
dispatch_async(dispatch_get_main_queue(), ^{
// |UIImage initWithData:| may return nil.
if (image) {
block([FaviconAttributes attributesWithImage:image]);
} else {
block([FaviconAttributes attributesWithImage:DefaultFaviconImage()]);
}
});
});
block([FaviconAttributes attributesWithImage:DefaultFaviconImage()]);
return;
}
// Use the FaviconCache if there is no synced favicon.
FaviconLoader* loader =
IOSChromeFaviconLoaderFactory::GetForBrowserState(browser_state);
if (loader) {
FaviconAttributes* attr =
loader->FaviconForUrl(url, kfaviconMinWidthHeight, kfaviconWidthHeight,
/*fallback_to_google_server=*/false, block);
DCHECK(attr);
block(attr);
return;
}
// Finally returns a default image.
block([FaviconAttributes attributesWithImage:DefaultFaviconImage()]);
}
} // namespace recent_tabs
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