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