Commit 4f204be1 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add SideSwipeSnapshot support to ToolbarCoordinator

This CL adds the methods to the ToolbarCoordinator to support taking
snapshot for Side Swipe.
The support for the UI update will be added later.

Bug: 784911
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I45170fa89244f5645d3da8dc5e059dcb34ab1f42
Reviewed-on: https://chromium-review.googlesource.com/774280
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517444}
parent cc6c1ac6
...@@ -17,6 +17,9 @@ class WebStateList; ...@@ -17,6 +17,9 @@ class WebStateList;
namespace ios { namespace ios {
class ChromeBrowserState; class ChromeBrowserState;
} }
namespace web {
class WebState;
}
// Coordinator to run a toolbar -- a UI element housing controls. // Coordinator to run a toolbar -- a UI element housing controls.
@interface ToolbarCoordinator : NSObject<OmniboxFocuser> @interface ToolbarCoordinator : NSObject<OmniboxFocuser>
...@@ -37,6 +40,13 @@ class ChromeBrowserState; ...@@ -37,6 +40,13 @@ class ChromeBrowserState;
// Stop this coordinator. // Stop this coordinator.
- (void)stop; - (void)stop;
// Updates the toolbar so it is in a state where a snapshot for |webState| can
// be taken.
- (void)updateToolbarForSideSwipeSnapshot:(web::WebState*)webState;
// Resets the toolbar after taking a side swipe snapshot. After calling this
// method the toolbar is adapted to the current webState.
- (void)resetToolbarAfterSideSwipeSnapshot;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_COORDINATOR_H_
...@@ -28,7 +28,10 @@ ...@@ -28,7 +28,10 @@
#import "ios/chrome/browser/ui/url_loader.h" #import "ios/chrome/browser/ui/url_loader.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -110,6 +113,30 @@ ...@@ -110,6 +113,30 @@
// the mediator. Investigate how to handle it. // the mediator. Investigate how to handle it.
} }
- (void)updateToolbarForSideSwipeSnapshot:(web::WebState*)webState {
web::NavigationItem* item =
webState->GetNavigationManager()->GetVisibleItem();
GURL URL = item ? item->GetURL().GetOrigin() : GURL::EmptyGURL();
BOOL isNTP = URL == GURL(kChromeUINewTabURL);
// Don't do anything for a live non-ntp tab.
if (webState == [self getWebState] && !isNTP) {
[_locationBarView setHidden:NO];
return;
}
self.viewController.view.hidden = NO;
[_locationBarView setHidden:YES];
[self.mediator updateConsumerForWebState:webState];
[self.viewController updateForSideSwipeSnapshotOnNTP:isNTP];
}
- (void)resetToolbarAfterSideSwipeSnapshot {
[self.mediator updateConsumerForWebState:[self getWebState]];
[_locationBarView setHidden:NO];
[self.viewController resetAfterSideSwipeSnapshot];
}
#pragma mark - LocationBarDelegate #pragma mark - LocationBarDelegate
- (void)loadGURLFromLocationBar:(const GURL&)url - (void)loadGURLFromLocationBar:(const GURL&)url
......
...@@ -32,6 +32,9 @@ class WebStateList; ...@@ -32,6 +32,9 @@ class WebStateList;
// object and may be nil. // object and may be nil.
@property(nonatomic, strong) id<ToolbarConsumer> consumer; @property(nonatomic, strong) id<ToolbarConsumer> consumer;
// Updates the consumer to conforms to |webState|.
- (void)updateConsumerForWebState:(web::WebState*)webState;
// Stops observing all objects. // Stops observing all objects.
- (void)disconnect; - (void)disconnect;
......
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#pragma mark - Public #pragma mark - Public
- (void)updateConsumerForWebState:(web::WebState*)webState {
[self updateNavigationBackAndForwardStateForWebState:webState];
}
- (void)disconnect { - (void)disconnect {
self.webStateList = nullptr; self.webStateList = nullptr;
_webStateObserver.reset(); _webStateObserver.reset();
...@@ -46,17 +50,17 @@ ...@@ -46,17 +50,17 @@
#pragma mark - CRWWebStateObserver #pragma mark - CRWWebStateObserver
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
[self updateNavigationBackAndForwardState]; [self updateConsumerForWebState:self.webState];
} }
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
didStartNavigation:(web::NavigationContext*)navigation { didStartNavigation:(web::NavigationContext*)navigation {
[self updateNavigationBackAndForwardState]; [self updateConsumerForWebState:self.webState];
} }
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
didPruneNavigationItemsWithCount:(size_t)pruned_item_count { didPruneNavigationItemsWithCount:(size_t)pruned_item_count {
[self updateNavigationBackAndForwardState]; [self updateConsumerForWebState:self.webState];
} }
- (void)webStateDidStartLoading:(web::WebState*)webState { - (void)webStateDidStartLoading:(web::WebState*)webState {
...@@ -140,16 +144,16 @@ ...@@ -140,16 +144,16 @@
- (void)updateConsumer { - (void)updateConsumer {
DCHECK(self.webState); DCHECK(self.webState);
DCHECK(self.consumer); DCHECK(self.consumer);
[self updateNavigationBackAndForwardState]; [self updateConsumerForWebState:self.webState];
[self.consumer setIsLoading:self.webState->IsLoading()]; [self.consumer setIsLoading:self.webState->IsLoading()];
} }
// Updates the consumer with the new forward and back states. // Updates the consumer with the new forward and back states.
- (void)updateNavigationBackAndForwardState { - (void)updateNavigationBackAndForwardStateForWebState:
[self.consumer (web::WebState*)webState {
setCanGoForward:self.webState->GetNavigationManager()->CanGoForward()];
[self.consumer [self.consumer
setCanGoBack:self.webState->GetNavigationManager()->CanGoBack()]; setCanGoForward:webState->GetNavigationManager()->CanGoForward()];
[self.consumer setCanGoBack:webState->GetNavigationManager()->CanGoBack()];
} }
@end @end
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
- (void)contractOmnibox; - (void)contractOmnibox;
// Expands the omnibox to its expanded state, |animated| or not. // Expands the omnibox to its expanded state, |animated| or not.
- (void)expandOmniboxAnimated:(BOOL)animated; - (void)expandOmniboxAnimated:(BOOL)animated;
// Updates the view so a snapshot can be taken. It needs to be adapted,
// depending on if it is a snapshot displayed |onNTP| or not.
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP;
// Resets the view after taking a snapshot for a side swipe.
- (void)resetAfterSideSwipeSnapshot;
@end @end
......
...@@ -77,6 +77,14 @@ ...@@ -77,6 +77,14 @@
// TODO(crbug.com/785210): Implement this. // TODO(crbug.com/785210): Implement this.
} }
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP {
// TODO(crbug.com/785756): Implement this.
}
- (void)resetAfterSideSwipeSnapshot {
// TODO(crbug.com/785756): Implement this.
}
#pragma mark - View lifecyle #pragma mark - View lifecyle
- (void)viewDidLoad { - (void)viewDidLoad {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/toolbar/toolbar_adapter.h" #import "ios/chrome/browser/ui/toolbar/toolbar_adapter.h"
#import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_coordinator.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_coordinator.h"
#import "ios/chrome/browser/ui/toolbar/web_toolbar_delegate.h" #import "ios/chrome/browser/ui/toolbar/web_toolbar_delegate.h"
...@@ -81,11 +82,11 @@ ...@@ -81,11 +82,11 @@
} }
- (void)updateToolbarForSideSwipeSnapshot:(Tab*)tab { - (void)updateToolbarForSideSwipeSnapshot:(Tab*)tab {
return; [self.toolbarCoordinator updateToolbarForSideSwipeSnapshot:tab.webState];
} }
- (void)resetToolbarAfterSideSwipeSnapshot { - (void)resetToolbarAfterSideSwipeSnapshot {
return; [self.toolbarCoordinator resetToolbarAfterSideSwipeSnapshot];
} }
#pragma mark - Abstract Toolbar #pragma mark - Abstract Toolbar
......
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