Commit 14dcb3e2 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Update SnapshotGeneratorDelegate

This CL renames SnapshotGeneratorDelegate protocol methods to be
unique to SnapshotGenerator.

Bug: 904992
Change-Id: I6357931f782a7d533a74a0b438751b4d5a78aab4
Reviewed-on: https://chromium-review.googlesource.com/c/1345128
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611847}
parent 075e36f1
...@@ -12,27 +12,33 @@ ...@@ -12,27 +12,33 @@
@synthesize view = _view; @synthesize view = _view;
- (BOOL)canTakeSnapshotForWebState:(web::WebState*)webState { - (BOOL)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
canTakeSnapshotForWebState:(web::WebState*)webState {
return YES; return YES;
} }
- (UIEdgeInsets)snapshotEdgeInsetsForWebState:(web::WebState*)webState { - (UIEdgeInsets)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
snapshotEdgeInsetsForWebState:(web::WebState*)webState {
return UIEdgeInsetsZero; return UIEdgeInsetsZero;
} }
- (NSArray<SnapshotOverlay*>*)snapshotOverlaysForWebState: - (NSArray<SnapshotOverlay*>*)snapshotGenerator:
(web::WebState*)webState { (SnapshotGenerator*)snapshotGenerator
snapshotOverlaysForWebState:(web::WebState*)webState {
return nil; return nil;
} }
- (void)willUpdateSnapshotForWebState:(web::WebState*)webState { - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
willUpdateSnapshotForWebState:(web::WebState*)webState {
} }
- (void)didUpdateSnapshotForWebState:(web::WebState*)webState - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
withImage:(UIImage*)snapshot { didUpdateSnapshotForWebState:(web::WebState*)webState
withImage:(UIImage*)snapshot {
} }
- (UIView*)viewForWebState:(web::WebState*)webState { - (UIView*)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
baseViewForWebState:(web::WebState*)webState {
return self.view; return self.view;
} }
......
...@@ -220,7 +220,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -220,7 +220,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
- (void)updateWebViewSnapshotWithCompletion:(void (^)(UIImage*))completion { - (void)updateWebViewSnapshotWithCompletion:(void (^)(UIImage*))completion {
DCHECK(_webState); DCHECK(_webState);
UIView* snapshotView = [self.delegate viewForWebState:_webState]; UIView* snapshotView = [self.delegate snapshotGenerator:self
baseViewForWebState:_webState];
CGRect snapshotFrame = [self snapshotFrameVisibleFrameOnly:YES]; CGRect snapshotFrame = [self snapshotFrameVisibleFrameOnly:YES];
snapshotFrame = snapshotFrame =
[_webState->GetView() convertRect:snapshotFrame fromView:snapshotView]; [_webState->GetView() convertRect:snapshotFrame fromView:snapshotView];
...@@ -238,8 +239,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -238,8 +239,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
<< ": snapshotFrame.size.width=" << size.width; << ": snapshotFrame.size.width=" << size.width;
DCHECK(std::isnormal(size.height) && (size.height > 0)) DCHECK(std::isnormal(size.height) && (size.height > 0))
<< ": snapshotFrame.size.height=" << size.height; << ": snapshotFrame.size.height=" << size.height;
NSArray<SnapshotOverlay*>* overlays = NSArray<SnapshotOverlay*>* overlays = [_delegate snapshotGenerator:self
[_delegate snapshotOverlaysForWebState:_webState]; snapshotOverlaysForWebState:_webState];
UIImage* snapshot = UIImage* snapshot =
[_coalescingSnapshotContext cachedSnapshotWithOverlays:overlays [_coalescingSnapshotContext cachedSnapshotWithOverlays:overlays
visibleFrameOnly:YES]; visibleFrameOnly:YES];
...@@ -253,7 +254,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -253,7 +254,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
return; return;
} }
[_delegate willUpdateSnapshotForWebState:_webState]; [_delegate snapshotGenerator:self willUpdateSnapshotForWebState:_webState];
__weak SnapshotGenerator* weakSelf = self; __weak SnapshotGenerator* weakSelf = self;
_webState->TakeSnapshot( _webState->TakeSnapshot(
snapshotFrame, base::BindOnce(^(gfx::Image image) { snapshotFrame, base::BindOnce(^(gfx::Image image) {
...@@ -274,7 +275,9 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -274,7 +275,9 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
[_coalescingSnapshotContext setCachedSnapshot:snapshot [_coalescingSnapshotContext setCachedSnapshot:snapshot
withOverlays:overlays withOverlays:overlays
visibleFrameOnly:YES]; visibleFrameOnly:YES];
[_delegate didUpdateSnapshotForWebState:_webState withImage:snapshot]; [_delegate snapshotGenerator:self
didUpdateSnapshotForWebState:_webState
withImage:snapshot];
if (completion) if (completion)
completion(snapshot); completion(snapshot);
})); }));
...@@ -287,7 +290,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -287,7 +290,8 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
return nil; return nil;
NSArray<SnapshotOverlay*>* overlays = NSArray<SnapshotOverlay*>* overlays =
shouldAddOverlay ? [_delegate snapshotOverlaysForWebState:_webState] shouldAddOverlay ? [_delegate snapshotGenerator:self
snapshotOverlaysForWebState:_webState]
: nil; : nil;
UIImage* snapshot = UIImage* snapshot =
[_coalescingSnapshotContext cachedSnapshotWithOverlays:overlays [_coalescingSnapshotContext cachedSnapshotWithOverlays:overlays
...@@ -296,14 +300,17 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -296,14 +300,17 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
if (snapshot) if (snapshot)
return snapshot; return snapshot;
[_delegate willUpdateSnapshotForWebState:_webState]; [_delegate snapshotGenerator:self willUpdateSnapshotForWebState:_webState];
UIView* view = [_delegate viewForWebState:_webState]; UIView* view = [_delegate snapshotGenerator:self
baseViewForWebState:_webState];
snapshot = snapshot =
[self generateSnapshotForView:view withRect:frame overlays:overlays]; [self generateSnapshotForView:view withRect:frame overlays:overlays];
[_coalescingSnapshotContext setCachedSnapshot:snapshot [_coalescingSnapshotContext setCachedSnapshot:snapshot
withOverlays:overlays withOverlays:overlays
visibleFrameOnly:visibleFrameOnly]; visibleFrameOnly:visibleFrameOnly];
[_delegate didUpdateSnapshotForWebState:_webState withImage:snapshot]; [_delegate snapshotGenerator:self
didUpdateSnapshotForWebState:_webState
withImage:snapshot];
return snapshot; return snapshot;
} }
...@@ -338,14 +345,17 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) { ...@@ -338,14 +345,17 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
// Do not generate a snapshot if the delegate says the WebState view is // Do not generate a snapshot if the delegate says the WebState view is
// not ready (this generally mean a placeholder is displayed). // not ready (this generally mean a placeholder is displayed).
if (_delegate && ![_delegate canTakeSnapshotForWebState:_webState]) if (_delegate && ![_delegate snapshotGenerator:self
canTakeSnapshotForWebState:_webState])
return CGRectZero; return CGRectZero;
UIView* view = [_delegate viewForWebState:_webState]; UIView* view = [_delegate snapshotGenerator:self
baseViewForWebState:_webState];
CGRect frame = [view bounds]; CGRect frame = [view bounds];
UIEdgeInsets headerInsets = UIEdgeInsetsZero; UIEdgeInsets headerInsets = UIEdgeInsetsZero;
if (visibleFrameOnly) { if (visibleFrameOnly) {
headerInsets = [_delegate snapshotEdgeInsetsForWebState:_webState]; headerInsets = [_delegate snapshotGenerator:self
snapshotEdgeInsetsForWebState:_webState];
} else if (base::FeatureList::IsEnabled( } else if (base::FeatureList::IsEnabled(
web::features::kBrowserContainerFullscreen)) { web::features::kBrowserContainerFullscreen)) {
headerInsets = UIEdgeInsetsMake(StatusBarHeight(), 0, 0, 0); headerInsets = UIEdgeInsetsMake(StatusBarHeight(), 0, 0, 0);
......
...@@ -18,33 +18,39 @@ class WebState; ...@@ -18,33 +18,39 @@ class WebState;
@protocol SnapshotGeneratorDelegate @protocol SnapshotGeneratorDelegate
// Returns whether it is possible to capture a snapshot for |webState|. // Returns whether it is possible to capture a snapshot for |webState|.
- (BOOL)canTakeSnapshotForWebState:(web::WebState*)webState; - (BOOL)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
canTakeSnapshotForWebState:(web::WebState*)webState;
// Returns the edge insets to use to crop the snapshot for |webState| during // Returns the edge insets to use to crop the snapshot for |webState| during
// generation. If the snapshot should not be cropped, then UIEdgeInsetsZero // generation. If the snapshot should not be cropped, then UIEdgeInsetsZero
// can be returned. The returned insets should be in the coordinate system of // can be returned. The returned insets should be in the coordinate system of
// the view returned by |-viewForWebState:|. // the view returned by |-baseViewForWebState:|.
- (UIEdgeInsets)snapshotEdgeInsetsForWebState:(web::WebState*)webState; - (UIEdgeInsets)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
snapshotEdgeInsetsForWebState:(web::WebState*)webState;
// Returns the list of SnapshotOverlays that should be rendered over the // Returns the list of SnapshotOverlays that should be rendered over the
// page when generating the snapshot for |webState|. If no overlays should // page when generating the snapshot for |webState|. If no overlays should
// be rendered, the list may be nil or empty. // be rendered, the list may be nil or empty.
- (NSArray<SnapshotOverlay*>*)snapshotOverlaysForWebState: - (NSArray<SnapshotOverlay*>*)snapshotGenerator:
(web::WebState*)webState; (SnapshotGenerator*)snapshotGenerator
snapshotOverlaysForWebState:(web::WebState*)webState;
// Invoked before capturing a snapshot for |webState|. The delegate can remove // Invoked before capturing a snapshot for |webState|. The delegate can remove
// subviews from the hierarchy or take other actions to ensure the snapshot // subviews from the hierarchy or take other actions to ensure the snapshot
// is correclty captured. // is correclty captured.
- (void)willUpdateSnapshotForWebState:(web::WebState*)webState; - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
willUpdateSnapshotForWebState:(web::WebState*)webState;
// Invoked after capturing a snapshot for |webState|. The delegate can insert // Invoked after capturing a snapshot for |webState|. The delegate can insert
// subviews that were removed during -willUpdateSnapshotForWebState: or take // subviews that were removed during -willUpdateSnapshotForWebState: or take
// other actions necessary after a snapshot has been captured. // other actions necessary after a snapshot has been captured.
- (void)didUpdateSnapshotForWebState:(web::WebState*)webState - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
withImage:(UIImage*)snapshot; didUpdateSnapshotForWebState:(web::WebState*)webState
withImage:(UIImage*)snapshot;
// Returns the base view to be snapshotted. // Returns the base view to be snapshotted.
- (UIView*)viewForWebState:(web::WebState*)webState; - (UIView*)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
baseViewForWebState:(web::WebState*)webState;
@end @end
......
...@@ -49,11 +49,13 @@ using ui::test::uiimage_utils::UIImageWithSizeAndSolidColor; ...@@ -49,11 +49,13 @@ using ui::test::uiimage_utils::UIImageWithSizeAndSolidColor;
#pragma mark - SnapshotGeneratorDelegate #pragma mark - SnapshotGeneratorDelegate
- (BOOL)canTakeSnapshotForWebState:(web::WebState*)webState { - (BOOL)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
canTakeSnapshotForWebState:(web::WebState*)webState {
return !_canTakeSnapshot; return !_canTakeSnapshot;
} }
- (void)willUpdateSnapshotForWebState:(web::WebState*)webState { - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
willUpdateSnapshotForWebState:(web::WebState*)webState {
++_snapshotTakenCount; ++_snapshotTakenCount;
} }
......
...@@ -2939,7 +2939,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -2939,7 +2939,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
#pragma mark - SnapshotGeneratorDelegate methods #pragma mark - SnapshotGeneratorDelegate methods
- (BOOL)canTakeSnapshotForWebState:(web::WebState*)webState { - (BOOL)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
canTakeSnapshotForWebState:(web::WebState*)webState {
DCHECK(webState); DCHECK(webState);
PagePlaceholderTabHelper* pagePlaceholderTabHelper = PagePlaceholderTabHelper* pagePlaceholderTabHelper =
PagePlaceholderTabHelper::FromWebState(webState); PagePlaceholderTabHelper::FromWebState(webState);
...@@ -2947,7 +2948,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -2947,7 +2948,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
!pagePlaceholderTabHelper->will_add_placeholder_for_next_navigation(); !pagePlaceholderTabHelper->will_add_placeholder_for_next_navigation();
} }
- (UIEdgeInsets)snapshotEdgeInsetsForWebState:(web::WebState*)webState { - (UIEdgeInsets)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
snapshotEdgeInsetsForWebState:(web::WebState*)webState {
DCHECK(webState); DCHECK(webState);
// The NTP's snapshot should be inset |headerHeight| from the top to remove // The NTP's snapshot should be inset |headerHeight| from the top to remove
// the fake NTP toolbar from the snapshot. // the fake NTP toolbar from the snapshot.
...@@ -2974,8 +2976,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -2974,8 +2976,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
return insets; return insets;
} }
- (NSArray<SnapshotOverlay*>*)snapshotOverlaysForWebState: - (NSArray<SnapshotOverlay*>*)snapshotGenerator:
(web::WebState*)webState { (SnapshotGenerator*)snapshotGenerator
snapshotOverlaysForWebState:(web::WebState*)webState {
DCHECK(webState); DCHECK(webState);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState); Tab* tab = LegacyTabHelper::GetTabForWebState(webState);
DCHECK([self.tabModel indexOfTab:tab] != NSNotFound); DCHECK([self.tabModel indexOfTab:tab] != NSNotFound);
...@@ -3017,7 +3020,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -3017,7 +3020,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
return overlays; return overlays;
} }
- (void)willUpdateSnapshotForWebState:(web::WebState*)webState { - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
willUpdateSnapshotForWebState:(web::WebState*)webState {
DCHECK(webState); DCHECK(webState);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState); Tab* tab = LegacyTabHelper::GetTabForWebState(webState);
DCHECK([self.tabModel indexOfTab:tab] != NSNotFound); DCHECK([self.tabModel indexOfTab:tab] != NSNotFound);
...@@ -3028,15 +3032,17 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -3028,15 +3032,17 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
[tab willUpdateSnapshot]; [tab willUpdateSnapshot];
} }
- (void)didUpdateSnapshotForWebState:(web::WebState*)webState - (void)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
withImage:(UIImage*)snapshot { didUpdateSnapshotForWebState:(web::WebState*)webState
withImage:(UIImage*)snapshot {
DCHECK(webState); DCHECK(webState);
Tab* tab = LegacyTabHelper::GetTabForWebState(webState); Tab* tab = LegacyTabHelper::GetTabForWebState(webState);
DCHECK([self.tabModel indexOfTab:tab] != NSNotFound); DCHECK([self.tabModel indexOfTab:tab] != NSNotFound);
[self.tabModel notifyTabSnapshotChanged:tab withImage:snapshot]; [self.tabModel notifyTabSnapshotChanged:tab withImage:snapshot];
} }
- (UIView*)viewForWebState:(web::WebState*)webState { - (UIView*)snapshotGenerator:(SnapshotGenerator*)snapshotGenerator
baseViewForWebState:(web::WebState*)webState {
NewTabPageTabHelper* NTPHelper = NewTabPageTabHelper::FromWebState(webState); NewTabPageTabHelper* NTPHelper = NewTabPageTabHelper::FromWebState(webState);
if (NTPHelper && NTPHelper->IsActive()) { if (NTPHelper && NTPHelper->IsActive()) {
return _ntpCoordinatorsForWebStates[webState].viewController.view; return _ntpCoordinatorsForWebStates[webState].viewController.view;
...@@ -4577,9 +4583,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -4577,9 +4583,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
// Add animations only if the tab strip isn't shown. // Add animations only if the tab strip isn't shown.
UIView* snapshotView = [self.view snapshotViewAfterScreenUpdates:NO]; UIView* snapshotView = [self.view snapshotViewAfterScreenUpdates:NO];
// TODO(crbug.com/904992): Do not repurpose SnapshotGeneratorDelegate.
SwipeView* swipeView = [[SwipeView alloc] SwipeView* swipeView = [[SwipeView alloc]
initWithFrame:self.contentArea.frame initWithFrame:self.contentArea.frame
topMargin:[self topMargin:[self snapshotGenerator:nil
snapshotEdgeInsetsForWebState:webStateBeingActivated] snapshotEdgeInsetsForWebState:webStateBeingActivated]
.top]; .top];
......
...@@ -506,9 +506,11 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -506,9 +506,11 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
CGRect frame = [[swipeDelegate_ sideSwipeContentView] frame]; CGRect frame = [[swipeDelegate_ sideSwipeContentView] frame];
// Add horizontal stack view controller. // Add horizontal stack view controller.
// TODO(crbug.com/904992): Do not use SnapshotGeneratorDelegate from
// SideSwipeController.
CGFloat headerHeight = CGFloat headerHeight =
[self.snapshotDelegate [self.snapshotDelegate snapshotGenerator:nil
snapshotEdgeInsetsForWebState:currentTab.webState] snapshotEdgeInsetsForWebState:currentTab.webState]
.top; .top;
if (tabSideSwipeView_) { if (tabSideSwipeView_) {
......
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