[ios] Removes Layout() InfobarIOS method.
Since the ContainerView size is now dependent on the InfobarView (The ContainerView autolayout constraints are anchored against the InfobarView, and we set the containerView to match the InfobarView height), there's no need to pass the ContainerView frame to layout the InfobarView. Because of this InfobarContainerVC no longer needs to import InfobarIOS and its moved to the infobars_ui BUILD.gn source_set. Bug: 892376 Change-Id: I44ca8c470b0ededbd34fe2f1564c2d651f200317 Reviewed-on: https://chromium-review.googlesource.com/c/1315987 Reviewed-by: Mark Cogan <marq@chromium.org> Commit-Queue: Sergio Collazos <sczs@chromium.org> Cr-Commit-Position: refs/heads/master@{#606504}
This commit is contained in:
ios/chrome/browser
infobars
confirm_infobar_controller.mminfobar.hinfobar.mminfobar_container_ios.mminfobar_controller+protected.hinfobar_controller.hinfobar_controller.mm
translate
after_translate_infobar_controller.mmbefore_translate_infobar_controller.mmnever_translate_infobar_controller.mmtranslate_message_infobar_controller.mm
ui
@ -55,9 +55,9 @@ typedef NS_ENUM(NSInteger, ConfirmInfoBarUITags) {
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
ConfirmInfoBarView* infoBarView =
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:frame];
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
_infoBarView = infoBarView;
|
||||
// Model data.
|
||||
gfx::Image modelIcon = self.infoBarDelegate->GetIcon();
|
||||
|
@ -24,9 +24,6 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
|
||||
std::unique_ptr<infobars::InfoBarDelegate> delegate);
|
||||
~InfoBarIOS() override;
|
||||
|
||||
// Lays out the infobar view using data from the delegate to add to superview.
|
||||
void Layout(CGRect container_bounds);
|
||||
|
||||
// Returns the infobar view holding contents of this infobar.
|
||||
UIView<InfoBarViewSizing>* view();
|
||||
|
||||
|
@ -34,12 +34,6 @@ InfoBarIOS::~InfoBarIOS() {
|
||||
controller_ = nil;
|
||||
}
|
||||
|
||||
void InfoBarIOS::Layout(CGRect container_bounds) {
|
||||
DCHECK(controller_);
|
||||
[controller_ layoutForFrame:container_bounds];
|
||||
SetTargetHeight([controller_ barHeight]);
|
||||
}
|
||||
|
||||
UIView<InfoBarViewSizing>* InfoBarIOS::view() {
|
||||
DCHECK(controller_);
|
||||
return [controller_ view];
|
||||
|
@ -29,7 +29,7 @@ InfoBarContainerIOS::~InfoBarContainerIOS() {
|
||||
void InfoBarContainerIOS::PlatformSpecificAddInfoBar(infobars::InfoBar* infobar,
|
||||
size_t position) {
|
||||
InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar);
|
||||
[consumer_ addInfoBar:infobar_ios position:position];
|
||||
[consumer_ addInfoBarView:infobar_ios->view() position:position];
|
||||
}
|
||||
|
||||
void InfoBarContainerIOS::PlatformSpecificRemoveInfoBar(
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
@interface InfoBarController ()
|
||||
|
||||
// Creates and returns a view and lays out all the infobar elements in it. Will
|
||||
// not add it as a subview yet. This method must be overriden in subclasses.
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)bounds;
|
||||
// Returns a view with all the infobar elements in it. Will not add it as a
|
||||
// subview yet. This method must be overriden in subclasses.
|
||||
- (UIView<InfoBarViewSizing>*)infobarView;
|
||||
|
||||
// Returns whether user interaction with the infobar should be ignored.
|
||||
- (BOOL)shouldIgnoreUserInteraction;
|
||||
|
@ -19,10 +19,6 @@ class InfoBarControllerDelegate;
|
||||
// InfoBar for iOS acts as a UIViewController for InfoBarView.
|
||||
@interface InfoBarController : NSObject<InfoBarViewSizingDelegate>
|
||||
|
||||
// Creates a view and lays out all the infobar elements in it. Will not add
|
||||
// it as a subview yet.
|
||||
- (void)layoutForFrame:(CGRect)bounds;
|
||||
|
||||
// Detaches view from its delegate.
|
||||
// After this function is called, no user interaction can be handled.
|
||||
- (void)detachView;
|
||||
|
@ -24,11 +24,15 @@
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize infoBarDelegate = _infoBarDelegate;
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (instancetype)initWithInfoBarDelegate:
|
||||
(infobars::InfoBarDelegate*)infoBarDelegate {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_infoBarDelegate = infoBarDelegate;
|
||||
_infoBarView = [self infobarView];
|
||||
[_infoBarView setSizingDelegate:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -41,20 +45,6 @@
|
||||
return CGRectGetHeight([_infoBarView frame]);
|
||||
}
|
||||
|
||||
- (void)layoutForFrame:(CGRect)bounds {
|
||||
if (!_infoBarView) {
|
||||
_infoBarView = [self viewForFrame:bounds];
|
||||
[_infoBarView setSizingDelegate:self];
|
||||
} else {
|
||||
[_infoBarView setFrame:bounds];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)bounds {
|
||||
NOTREACHED() << "Must be overriden in subclasses.";
|
||||
return _infoBarView;
|
||||
}
|
||||
|
||||
- (void)onHeightRecalculated:(int)newHeight {
|
||||
[_infoBarView setVisibleHeight:newHeight];
|
||||
}
|
||||
@ -73,6 +63,13 @@
|
||||
_infoBarDelegate = nullptr;
|
||||
}
|
||||
|
||||
#pragma mark - Protected
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
NOTREACHED() << "Must be overriden in subclasses.";
|
||||
return _infoBarView;
|
||||
}
|
||||
|
||||
- (BOOL)shouldIgnoreUserInteraction {
|
||||
// Ignore user interaction if view is already detached or is about to.
|
||||
return !_delegate || !_delegate->IsOwned() || !_infoBarDelegate;
|
||||
|
@ -50,9 +50,9 @@ enum AlwaysTranslateSwitchState {
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
ConfirmInfoBarView* infoBarView =
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:frame];
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
// Icon
|
||||
gfx::Image icon = self.infoBarDelegate->GetIcon();
|
||||
if (!icon.IsEmpty())
|
||||
|
@ -54,9 +54,9 @@
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
ConfirmInfoBarView* infoBarView =
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:frame];
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
_infoBarView = infoBarView;
|
||||
// Icon
|
||||
gfx::Image icon = self.infoBarDelegate->GetIcon();
|
||||
|
@ -44,9 +44,9 @@
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
ConfirmInfoBarView* infoBarView =
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:frame];
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
// Icon
|
||||
gfx::Image icon = self.infoBarDelegate->GetIcon();
|
||||
if (!icon.IsEmpty())
|
||||
|
@ -34,9 +34,9 @@
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
ConfirmInfoBarView* infoBarView =
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:frame];
|
||||
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
// Icon
|
||||
gfx::Image icon = self.infoBarDelegate->GetIcon();
|
||||
if (!icon.IsEmpty())
|
||||
|
@ -157,7 +157,6 @@ TEST_F(ReSignInInfoBarDelegateTest, TestAccept) {
|
||||
CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate(
|
||||
chrome_browser_state_.get(), presenter)));
|
||||
InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get());
|
||||
infobarIOS->Layout(CGRectZero);
|
||||
|
||||
ReSignInInfoBarDelegate* delegate =
|
||||
static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate());
|
||||
@ -179,7 +178,6 @@ TEST_F(ReSignInInfoBarDelegateTest, TestInfoBarDismissed) {
|
||||
CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate(
|
||||
chrome_browser_state_.get(), presenter)));
|
||||
InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get());
|
||||
infobarIOS->Layout(CGRectZero);
|
||||
|
||||
ReSignInInfoBarDelegate* delegate =
|
||||
static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate());
|
||||
|
@ -69,9 +69,9 @@ base::string16 GetTitleForButton(ConfirmInfoBarDelegate* delegate,
|
||||
return [super initWithInfoBarDelegate:infoBarDelegate];
|
||||
}
|
||||
|
||||
- (UIView<InfoBarViewSizing>*)viewForFrame:(CGRect)frame {
|
||||
- (UIView<InfoBarViewSizing>*)infobarView {
|
||||
SaveCardInfoBarView* infoBarView =
|
||||
[[SaveCardInfoBarView alloc] initWithFrame:frame];
|
||||
[[SaveCardInfoBarView alloc] initWithFrame:CGRectZero];
|
||||
self.infoBarView = infoBarView;
|
||||
self.infoBarView.accessibilityIdentifier =
|
||||
self.infoBarDelegate->upload() ? kSaveCardInfobarViewUploadAccessibilityID
|
||||
|
@ -5,11 +5,8 @@
|
||||
source_set("infobars") {
|
||||
configs += [ "//build/config/compiler:enable_arc" ]
|
||||
sources = [
|
||||
# TODO(crbug.com/892376): Move infobar_container_view_controller to infobars_ui.
|
||||
"infobar_container_mediator.h",
|
||||
"infobar_container_mediator.mm",
|
||||
"infobar_container_view_controller.h",
|
||||
"infobar_container_view_controller.mm",
|
||||
"infobar_coordinator.h",
|
||||
"infobar_coordinator.mm",
|
||||
]
|
||||
@ -44,10 +41,13 @@ source_set("infobars_ui") {
|
||||
"infobar_constants.h",
|
||||
"infobar_constants.mm",
|
||||
"infobar_container_consumer.h",
|
||||
"infobar_container_view_controller.h",
|
||||
"infobar_container_view_controller.mm",
|
||||
"infobar_view_sizing.h",
|
||||
"infobar_view_sizing_delegate.h",
|
||||
]
|
||||
deps = [
|
||||
":public",
|
||||
"resources:infobar_downloading",
|
||||
"resources:infobar_popup_blocker",
|
||||
"resources:infobar_warning",
|
||||
|
@ -7,13 +7,11 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
class InfoBarIOS;
|
||||
|
||||
// Protocol to communicate with the Infobar container.
|
||||
@protocol InfobarContainerConsumer
|
||||
|
||||
// Add a new infobar to the Infobar container view at position |position|.
|
||||
- (void)addInfoBar:(InfoBarIOS*)infoBarIOS position:(NSInteger)position;
|
||||
- (void)addInfoBarView:(UIView*)infoBarView position:(NSInteger)position;
|
||||
|
||||
// Sets the Infobar container user interaction to |enabled|.
|
||||
- (void)setUserInteractionEnabled:(BOOL)enabled;
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "ios/chrome/browser/infobars/infobar_container_state_delegate.h"
|
||||
#import "ios/chrome/browser/ui/infobars/infobar_container_consumer.h"
|
||||
|
||||
@protocol InfobarPositioner;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#import "ios/chrome/browser/ui/infobars/infobar_container_view_controller.h"
|
||||
|
||||
#include "base/ios/block_types.h"
|
||||
#include "ios/chrome/browser/infobars/infobar.h"
|
||||
#include "base/logging.h"
|
||||
#import "ios/chrome/browser/ui/infobars/infobar_positioner.h"
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
@ -21,18 +21,16 @@ const CGFloat kAlphaChangeAnimationDuration = 0.35;
|
||||
|
||||
#pragma mark - InfobarConsumer
|
||||
|
||||
- (void)addInfoBar:(InfoBarIOS*)infoBarIOS position:(NSInteger)position {
|
||||
- (void)addInfoBarView:(UIView*)infoBarView position:(NSInteger)position {
|
||||
DCHECK_LE(static_cast<NSUInteger>(position), [[self.view subviews] count]);
|
||||
CGRect containerBounds = [self.view bounds];
|
||||
infoBarIOS->Layout(containerBounds);
|
||||
UIView<InfoBarViewSizing>* view = infoBarIOS->view();
|
||||
[self.view insertSubview:view atIndex:position];
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.view insertSubview:infoBarView atIndex:position];
|
||||
infoBarView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[view.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||
[view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||||
[view.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
||||
[view.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
|
||||
[infoBarView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||
[infoBarView.trailingAnchor
|
||||
constraintEqualToAnchor:self.view.trailingAnchor],
|
||||
[infoBarView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
||||
[infoBarView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
|
||||
]];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user