Skip to content

Commit

Permalink
Add iPadOS pointer support to NTP tiles.
Browse files Browse the repository at this point in the history
Add pointer support to the mostVisited and shortcut buttons
on the NTP.

BUG=1139054

Change-Id: I9486aca3c27871312df0051149f8ed1e6f1dea22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476957
Auto-Submit: Mike Pinkerton <pinkerton@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Mike Pinkerton <pinkerton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820328}
  • Loading branch information
Mike Pinkerton authored and Commit Bot committed Oct 23, 2020
1 parent 34522fc commit 952759a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/ui/ntp_tile_views/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ source_set("ntp_tile_views") {
"resources:ntp_readinglist_icon",
"resources:ntp_recent_icon",
"//base",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/util",
"//ios/chrome/common/ui/colors",
"//ios/chrome/common/ui/favicon",
Expand Down
4 changes: 4 additions & 0 deletions ios/chrome/browser/ui/ntp_tile_views/ntp_tile_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
// A generic NTP tile view. Provides a title label and an image container on a
// squircle-shaped background. Concrete subclasses of this are used to display
// most visited tiles and shortcut tiles on NTP and other places.
#ifdef __IPHONE_13_4
@interface NTPTileView : UIView <UIPointerInteractionDelegate>
#else
@interface NTPTileView : UIView
#endif

// Container for the image view. Used in subclasses.
@property(nonatomic, strong, readonly, nonnull) UIView* imageContainerView;
Expand Down
37 changes: 37 additions & 0 deletions ios/chrome/browser/ui/ntp_tile_views/ntp_tile_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#import "ios/chrome/browser/ui/ntp_tile_views/ntp_tile_view.h"

#include "base/feature_list.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/dynamic_type_util.h"
#import "ios/chrome/common/ui/colors/UIColor+cr_semantic_colors.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
Expand Down Expand Up @@ -68,6 +70,15 @@ - (instancetype)initWithFrame:(CGRect)frame {
@{ @"space" : @(kSpaceIconTitle) });

_imageBackgroundView = backgroundView;

#ifdef __IPHONE_13_4
if (@available(iOS 13.4, *)) {
if (base::FeatureList::IsEnabled(kPointerSupport)) {
[self addInteraction:[[UIPointerInteraction alloc]
initWithDelegate:self]];
}
}
#endif
}
return self;
}
Expand All @@ -90,4 +101,30 @@ - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
}
}

#pragma mark - UIPointerInteractionDelegate

#ifdef __IPHONE_13_4

- (UIPointerRegion*)pointerInteraction:(UIPointerInteraction*)interaction
regionForRequest:(UIPointerRegionRequest*)request
defaultRegion:(UIPointerRegion*)defaultRegion
API_AVAILABLE(ios(13.4)) {
return defaultRegion;
}

- (UIPointerStyle*)pointerInteraction:(UIPointerInteraction*)interaction
styleForRegion:(UIPointerRegion*)region
API_AVAILABLE(ios(13.4)) {
UITargetedPreview* preview =
[[UITargetedPreview alloc] initWithView:_imageContainerView];
UIPointerHighlightEffect* effect =
[UIPointerHighlightEffect effectWithPreview:preview];
UIPointerShape* shape =
[UIPointerShape shapeWithRoundedRect:_imageContainerView.frame
cornerRadius:8.0];
return [UIPointerStyle styleWithEffect:effect shape:shape];
}

#endif

@end

0 comments on commit 952759a

Please sign in to comment.