Commit ed44ca7a authored by sczs's avatar sczs Committed by Commit Bot

[ios] Deletes Infobar Sizing Delegates

Before this CL Infobar.cc was informing InfobarContainer of an InfobarView
resize. Also, the InfobarView was being set by Infobar.cc it now sets its
own height.

This CL:
- Adds functionality so InfobarContainer resizing is driven by UiKit.
- Deletes InfobarViewSizing and InfobarViewSizingDelegate.
- Removes the plumbing from InfobarView that informs Infobar.cc of a
resize.
- Removes InfobarIOS and InfobarController methods that were used to
resize the InfobarView.

Bug: 892376
Change-Id: Iaae3c0ec36ce226fc89fb405cb3d9c40376d3a79
Reviewed-on: https://chromium-review.googlesource.com/c/1321849
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606589}
parent d27bb543
......@@ -55,7 +55,7 @@ typedef NS_ENUM(NSInteger, ConfirmInfoBarUITags) {
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
ConfirmInfoBarView* infoBarView =
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
_infoBarView = infoBarView;
......
......@@ -5,12 +5,12 @@
#ifndef IOS_CHROME_BROWSER_INFOBARS_INFOBAR_H_
#define IOS_CHROME_BROWSER_INFOBARS_INFOBAR_H_
#import <UIKit/UIKit.h>
#include <memory>
#include "base/macros.h"
#include "components/infobars/core/infobar.h"
#import "ios/chrome/browser/infobars/infobar_controller_delegate.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing.h"
@class InfoBarController;
namespace infobars {
......@@ -25,17 +25,13 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
~InfoBarIOS() override;
// Returns the infobar view holding contents of this infobar.
UIView<InfoBarViewSizing>* view();
UIView* view();
// Remove the infobar view from infobar container view.
void RemoveView();
private:
// infobars::InfoBar overrides:
void PlatformSpecificOnHeightRecalculated() override;
// InfoBarControllerDelegate overrides:
void SetInfoBarTargetHeight(int height) override;
bool IsOwned() override;
void RemoveInfoBar() override;
......
......@@ -12,7 +12,6 @@
#import "ios/chrome/browser/infobars/confirm_infobar_controller.h"
#include "ios/chrome/browser/infobars/infobar_controller.h"
#include "ios/chrome/browser/translate/translate_infobar_tags.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -34,7 +33,7 @@ InfoBarIOS::~InfoBarIOS() {
controller_ = nil;
}
UIView<InfoBarViewSizing>* InfoBarIOS::view() {
UIView* InfoBarIOS::view() {
DCHECK(controller_);
return [controller_ view];
}
......@@ -44,17 +43,8 @@ void InfoBarIOS::RemoveView() {
[controller_ removeView];
}
void InfoBarIOS::PlatformSpecificOnHeightRecalculated() {
DCHECK(controller_);
[controller_ onHeightRecalculated:computed_height()];
}
#pragma mark - InfoBarControllerDelegate
void InfoBarIOS::SetInfoBarTargetHeight(int height) {
SetTargetHeight(height);
}
bool InfoBarIOS::IsOwned() {
return owner() != nullptr;
}
......
......@@ -11,7 +11,7 @@
// 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;
- (UIView*)infobarView;
// Returns whether user interaction with the infobar should be ignored.
- (BOOL)shouldIgnoreUserInteraction;
......
......@@ -7,33 +7,24 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing_delegate.h"
namespace infobars {
class InfoBarDelegate;
} // namespace infobars
class InfoBarControllerDelegate;
@protocol InfoBarViewSizing;
// InfoBar for iOS acts as a UIViewController for InfoBarView.
@interface InfoBarController : NSObject<InfoBarViewSizingDelegate>
@interface InfoBarController : NSObject
// Detaches view from its delegate.
// After this function is called, no user interaction can be handled.
- (void)detachView;
// Returns the actual height in pixels of this infobar instance.
- (int)barHeight;
// Adjusts visible portion of this infobar.
- (void)onHeightRecalculated:(int)newHeight;
// Removes the view.
- (void)removeView;
// Accesses the view.
- (UIView<InfoBarViewSizing>*)view;
- (UIView*)view;
@property(nonatomic, assign) InfoBarControllerDelegate* delegate; // weak
......
......@@ -8,14 +8,13 @@
#include "base/logging.h"
#include "ios/chrome/browser/infobars/infobar_controller_delegate.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface InfoBarController () {
UIView<InfoBarViewSizing>* _infoBarView;
UIView* _infoBarView;
}
@end
......@@ -32,7 +31,6 @@
if (self) {
_infoBarDelegate = infoBarDelegate;
_infoBarView = [self infobarView];
[_infoBarView setSizingDelegate:self];
}
return self;
}
......@@ -41,15 +39,7 @@
[_infoBarView removeFromSuperview];
}
- (int)barHeight {
return CGRectGetHeight([_infoBarView frame]);
}
- (void)onHeightRecalculated:(int)newHeight {
[_infoBarView setVisibleHeight:newHeight];
}
- (UIView<InfoBarViewSizing>*)view {
- (UIView*)view {
return _infoBarView;
}
......@@ -58,14 +48,13 @@
}
- (void)detachView {
[_infoBarView setSizingDelegate:nil];
_delegate = nullptr;
_infoBarDelegate = nullptr;
}
#pragma mark - Protected
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
NOTREACHED() << "Must be overriden in subclasses.";
return _infoBarView;
}
......@@ -75,13 +64,4 @@
return !_delegate || !_delegate->IsOwned() || !_infoBarDelegate;
}
#pragma mark - InfoBarViewDelegate
- (void)didSetInfoBarTargetHeight:(CGFloat)height {
if (!_delegate)
return;
_delegate->SetInfoBarTargetHeight(height);
}
@end
......@@ -10,9 +10,6 @@
// Interface for delegating events from infobar.
class InfoBarControllerDelegate {
public:
// Notifies that the target size has been changed (e.g. after rotation).
virtual void SetInfoBarTargetHeight(int height) = 0;
// Returns whether the infobar is owned.
virtual bool IsOwned() = 0;
......
......@@ -50,7 +50,7 @@ enum AlwaysTranslateSwitchState {
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
ConfirmInfoBarView* infoBarView =
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
// Icon
......
......@@ -54,7 +54,7 @@
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
ConfirmInfoBarView* infoBarView =
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
_infoBarView = infoBarView;
......
......@@ -44,7 +44,7 @@
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
ConfirmInfoBarView* infoBarView =
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
// Icon
......
......@@ -34,7 +34,7 @@
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
ConfirmInfoBarView* infoBarView =
[[ConfirmInfoBarView alloc] initWithFrame:CGRectZero];
// Icon
......
......@@ -13,7 +13,6 @@
#include "ios/chrome/browser/infobars/infobar_controller_delegate.h"
#import "ios/chrome/browser/ui/autofill/save_card_infobar_view.h"
#import "ios/chrome/browser/ui/autofill/save_card_infobar_view_delegate.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing_delegate.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_theme_resources.h"
......@@ -69,7 +68,7 @@ base::string16 GetTitleForButton(ConfirmInfoBarDelegate* delegate,
return [super initWithInfoBarDelegate:infoBarDelegate];
}
- (UIView<InfoBarViewSizing>*)infobarView {
- (UIView*)infobarView {
SaveCardInfoBarView* infoBarView =
[[SaveCardInfoBarView alloc] initWithFrame:CGRectZero];
self.infoBarView = infoBarView;
......
......@@ -9,8 +9,6 @@
#include <vector>
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing.h"
class GURL;
@protocol SaveCardInfoBarViewDelegate;
......@@ -32,7 +30,7 @@ class GURL;
// the card's label, and the card's sublabel. In the following section, optional
// legal messages appear. The bottom section is the footer which contains a
// an optional confirm button and an optional cancel button.
@interface SaveCardInfoBarView : UIView<InfoBarViewSizing>
@interface SaveCardInfoBarView : UIView
@property(nonatomic, weak) id<SaveCardInfoBarViewDelegate> delegate;
......
......@@ -10,7 +10,6 @@
#import "ios/chrome/browser/ui/autofill/save_card_infobar_view_delegate.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/infobars/infobar_constants.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing_delegate.h"
#import "ios/chrome/browser/ui/util/label_link_controller.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
......@@ -87,6 +86,10 @@ UIFont* InfoBarMessageFont() {
// Constraint used to add bottom margin to the view.
@property(nonatomic) NSLayoutConstraint* footerViewBottomAnchorConstraint;
// How much of the infobar (in points) is visible (e.g., during showing/hiding
// animation).
@property(nonatomic, assign) CGFloat visibleHeight;
// Creates and adds subviews.
- (void)setupSubviews;
......@@ -127,7 +130,6 @@ UIFont* InfoBarMessageFont() {
@implementation SaveCardInfoBarView
@synthesize visibleHeight = _visibleHeight;
@synthesize sizingDelegate = _sizingDelegate;
@synthesize delegate = _delegate;
@synthesize icon = _icon;
@synthesize googlePayIcon = _googlePayIcon;
......@@ -167,8 +169,6 @@ UIFont* InfoBarMessageFont() {
layoutGuide.layoutFrame.size.height;
[super layoutSubviews];
[self.sizingDelegate didSetInfoBarTargetHeight:CGRectGetHeight(self.frame)];
}
- (CGSize)sizeThatFits:(CGSize)size {
......
......@@ -43,8 +43,6 @@ source_set("infobars_ui") {
"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",
......
......@@ -8,10 +8,9 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing.h"
// An inforbar with an optional message, icon, two action buttons, and a switch.
@interface ConfirmInfoBarView : BidiContainerView<InfoBarViewSizing>
@interface ConfirmInfoBarView : BidiContainerView
// Label text with links initialized with |stringAsLink:|.
@property(nonatomic, strong, readonly) NSString* markedLabel;
......
......@@ -15,7 +15,6 @@
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/infobars/infobar_constants.h"
#import "ios/chrome/browser/ui/infobars/infobar_view_sizing_delegate.h"
#import "ios/chrome/browser/ui/util/label_link_controller.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
......@@ -330,6 +329,10 @@ UIImage* InfoBarCloseImage() {
// Returns the marker delimiting the end of a link.
+ (NSString*)closingMarkerForLink;
// How much of the infobar (in points) is visible (e.g., during showing/hiding
// animation).
@property(nonatomic, assign) CGFloat visibleHeight;
@end
@implementation ConfirmInfoBarView {
......@@ -363,7 +366,6 @@ UIImage* InfoBarCloseImage() {
}
@synthesize visibleHeight = visibleHeight_;
@synthesize sizingDelegate = sizingDelegate_;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
......@@ -760,10 +762,7 @@ UIImage* InfoBarCloseImage() {
- (void)layoutSubviews {
// Lays out the position of the icon.
[imageView_ setFrame:[self frameOfIcon]];
targetHeight_ = [self computeRequiredHeightAndLayoutSubviews:YES];
if (sizingDelegate_)
[sizingDelegate_ didSetInfoBarTargetHeight:targetHeight_];
self.visibleHeight = [self computeRequiredHeightAndLayoutSubviews:YES];
[self resetBackground];
// Asks the BidiContainerView to reposition of all the subviews.
......
......@@ -19,6 +19,13 @@ const CGFloat kAlphaChangeAnimationDuration = 0.35;
@implementation InfobarContainerViewController
// Whenever the container or contained views are re-drawn update the layout to
// match their new size or position.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self updateLayoutAnimated:YES];
}
#pragma mark - InfobarConsumer
- (void)addInfoBarView:(UIView*)infoBarView position:(NSInteger)position {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_H_
#import <UIKit/UIKit.h>
@protocol InfoBarViewSizingDelegate;
// Protocol implemented by UIView subclasses representing an infobar. It has
// information about the infobar's visible height and a reference to the
// delegate that gets notified of infobar's height changes.
@protocol InfoBarViewSizing
// How much of the infobar (in points) is visible (e.g., during showing/hiding
// animation).
@property(nonatomic, assign) CGFloat visibleHeight;
// The delegate that gets notified of infobar's height changes.
@property(nonatomic, weak) id<InfoBarViewSizingDelegate> sizingDelegate;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_DELEGATE_H_
#import <Foundation/Foundation.h>
// A protocol implemented by a delegate of InfoBarViewSizing.
@protocol InfoBarViewSizingDelegate
// Notifies that the target size has been changed (e.g. after rotation).
- (void)didSetInfoBarTargetHeight:(CGFloat)height;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_VIEW_SIZING_DELEGATE_H_
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