Commit c67f8730 authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Decouple Activity View Popover SourceView and SourceRect

The ActivityServiceCoordinator used to get the popover's sourceRect from
the sourceView's bounds. Since Shared Highlight requires placing the
popover at some location inside a given UIView, we had to decouple the
two properties.

Bug: 1136043
Change-Id: Ica3294313f39c32c0edef0bd4bb2aa9443c0e1fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462244
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817136}
parent 68f84ec6
......@@ -121,9 +121,10 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
// Set-up popover positioning (for iPad).
DCHECK(self.positionProvider);
UIView* inView = [self.positionProvider shareButtonView];
self.viewController.popoverPresentationController.sourceView = inView;
self.viewController.popoverPresentationController.sourceRect = inView.bounds;
self.viewController.popoverPresentationController.sourceView =
self.positionProvider.sourceView;
self.viewController.popoverPresentationController.sourceRect =
self.positionProvider.sourceRect;
// Set completion callback.
__weak __typeof(self) weakSelf = self;
......
......@@ -11,9 +11,13 @@
// activity services menu on the screen.
@protocol ActivityServicePositioner
// Returns the view whose bound defines where the UIActivityViewController
// Returns the view where the UIActivityViewController
// should be presented.
- (UIView*)shareButtonView;
- (UIView*)sourceView;
// Returns the bounds where the UIActivityViewController's popover should be
// presented.
- (CGRect)sourceRect;
@end
......
......@@ -471,36 +471,36 @@
#pragma mark - ActivityServiceCommands
- (void)sharePage {
UIView* shareButton =
[self.viewController.activityServicePositioner shareButtonView];
ActivityParams* params = [[ActivityParams alloc]
initWithScenario:ActivityScenario::TabShareButton];
self.sharingCoordinator =
[[SharingCoordinator alloc] initWithBaseViewController:self.viewController
browser:self.browser
params:params
originView:shareButton];
self.sharingCoordinator = [[SharingCoordinator alloc]
initWithBaseViewController:self.viewController
browser:self.browser
params:params
originView:self.viewController.activityServicePositioner
.sourceView
originRect:self.viewController.activityServicePositioner
.sourceRect];
[self.sharingCoordinator start];
}
- (void)shareHighlight:(ShareHighlightCommand*)command {
// TODO(crbug.com/1099268): Get the right share view origin.
UIView* shareButton =
[self.viewController.activityServicePositioner shareButtonView];
ActivityParams* params =
[[ActivityParams alloc] initWithURL:command.URL
title:command.title
additionalText:command.selectedText
scenario:ActivityScenario::SharedHighlight];
self.sharingCoordinator =
[[SharingCoordinator alloc] initWithBaseViewController:self.viewController
browser:self.browser
params:params
originView:shareButton];
// TODO(crbug.com/1099268): Get the right share view origin.
self.sharingCoordinator = [[SharingCoordinator alloc]
initWithBaseViewController:self.viewController
browser:self.browser
params:params
originView:self.viewController.activityServicePositioner
.sourceView
originRect:self.viewController.activityServicePositioner
.sourceRect];
[self.sharingCoordinator start];
}
......
......@@ -148,8 +148,12 @@
#pragma mark - ActivityServicePositioner
- (UIView*)shareButtonView {
return [self.viewController primaryActionButton];
- (UIView*)sourceView {
return self.viewController.primaryActionButton;
}
- (CGRect)sourceRect {
return self.viewController.primaryActionButton.bounds;
}
#pragma mark - ActivityServicePresentation
......
......@@ -20,11 +20,23 @@ class Browser;
// Creates a coordinator configured to share the current tab's URL using the
// base |viewController|, a |browser|, |params| with all the necessary values
// to drive the scenario, and an |originView| from which the scenario was
// triggered.
// triggered. This initializer also uses the |originView|'s bounds to position
// the activity view popover on iPad.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
params:(ActivityParams*)params
originView:(UIView*)originView;
// Creates a coordinator configured to share the current tab's URL using the
// base |viewController|, a |browser|, |params| with all the necessary values
// to drive the scenario, and an |originView| from which the scenario was
// triggered. This initializer also uses the |originRect| to position the
// activity view popover on iPad.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
params:(ActivityParams*)params
originView:(UIView*)originView
originRect:(CGRect)originRect
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -46,6 +46,8 @@ using bookmarks::BookmarkNode;
@property(nonatomic, weak) UIView* originView;
@property(nonatomic, assign) CGRect originRect;
@end
@implementation SharingCoordinator
......@@ -55,10 +57,26 @@ using bookmarks::BookmarkNode;
params:(ActivityParams*)params
originView:(UIView*)originView {
DCHECK(params);
DCHECK(originView);
self = [self initWithBaseViewController:viewController
browser:browser
params:params
originView:originView
originRect:originView.bounds];
return self;
}
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser
params:(ActivityParams*)params
originView:(UIView*)originView
originRect:(CGRect)originRect {
DCHECK(params);
if (self = [super initWithBaseViewController:viewController
browser:browser]) {
_params = params;
_originView = originView;
_originRect = originRect;
}
return self;
}
......@@ -87,10 +105,14 @@ using bookmarks::BookmarkNode;
#pragma mark - ActivityServicePositioner
- (UIView*)shareButtonView {
- (UIView*)sourceView {
return self.originView;
}
- (CGRect)sourceRect {
return self.originRect;
}
#pragma mark - ActivityServicePresentation
- (void)activityServiceDidEndPresenting {
......
......@@ -183,7 +183,9 @@ TEST_F(SharingCoordinatorTest, Start_ShareCurrentPage) {
auto activityHandler =
static_cast<id<ActivityServicePositioner, ActivityServicePresentation>>(
coordinator);
EXPECT_EQ(fake_origin_view_, activityHandler.shareButtonView);
EXPECT_EQ(fake_origin_view_, activityHandler.sourceView);
EXPECT_TRUE(
CGRectEqualToRect(fake_origin_view_.bounds, activityHandler.sourceRect));
// Verify that the presentation protocol works too.
id activity_vc_partial_mock = OCMPartialMock(activityViewController);
......
......@@ -211,10 +211,14 @@
#pragma mark - ActivityServicePositioner
- (UIView*)shareButtonView {
- (UIView*)sourceView {
return self.view.shareButton;
}
- (CGRect)sourceRect {
return self.view.shareButton.bounds;
}
#pragma mark - FullscreenUIElement
- (void)updateForFullscreenProgress:(CGFloat)progress {
......
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