Commit 4cebbb33 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Add BrowserContainerViewController class to manage BrowserContainerView.

This view controller will be used as a base view controller for Download
Manager presentation. Download Manager must be presented under toolbar
view, so using BVC as a base view controller does not work.

This CL replaces BrowserContainerView with BrowserContainerViewController
which should not cause any functional changes.

Bug: 818264
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I93d66906c671a8647589db8d9717ab2dcd26cd51
Reviewed-on: https://chromium-review.googlesource.com/981684Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550747}
parent c430ae59
......@@ -99,7 +99,7 @@ source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"browser_container_view_unittest.mm",
"browser_container_view_controller_unittest.mm",
"browser_view_controller_helper_unittest.mm",
"browser_view_controller_unittest.mm",
"chrome_web_view_factory_unittest.mm",
......@@ -263,8 +263,8 @@ source_set("external_files") {
source_set("ui_internal") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"browser_container_view.h",
"browser_container_view.mm",
"browser_container_view_controller.h",
"browser_container_view_controller.mm",
"browser_view_controller.h",
"browser_view_controller.mm",
"browser_view_controller_dependency_factory.h",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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_BROWSER_CONTAINER_VIEW_H_
#define IOS_CHROME_BROWSER_UI_BROWSER_CONTAINER_VIEW_H_
#ifndef IOS_CHROME_BROWSER_UI_BROWSER_CONTAINER_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_BROWSER_CONTAINER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
// UIView which allows displaing and removing a content view.
@interface BrowserContainerView : UIView
// UIViewController which allows displaying and removing a content view.
@interface BrowserContainerViewController : UIViewController
// Adds the given |contentView| as a subview and removes the previously added
// |contentView| if any. If |contentView| is nil then only old content view is
......@@ -17,4 +17,4 @@
@end
#endif // IOS_CHROME_BROWSER_UI_BROWSER_CONTAINER_VIEW_H_
#endif // IOS_CHROME_BROWSER_UI_BROWSER_CONTAINER_VIEW_CONTROLLER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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.
#import "ios/chrome/browser/ui/browser_container_view.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/ui/browser_container_view_controller.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation BrowserContainerView {
@interface BrowserContainerViewController () {
// Weak reference to content view, so old _contentView can be removed from
// superview when new one is added.
__weak UIView* _contentView;
}
@end
@implementation BrowserContainerViewController
- (void)dealloc {
DCHECK(![_contentView superview] || [_contentView superview] == self);
DCHECK(![_contentView superview] || [_contentView superview] == self.view);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
- (void)displayContentView:(UIView*)contentView {
......@@ -33,18 +42,18 @@
// |contentView|, regardless of the NamedGuide constraints.
// TODO(crbug.com/826093): Remove NamedGuide check and simply early return.
NamedGuide* voiceSearchGuide =
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:self];
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:self.view];
UIView* voiceSearchButton = voiceSearchGuide.constrainedView;
if ([voiceSearchButton isDescendantOfView:_contentView])
return;
}
DCHECK(![_contentView superview] || [_contentView superview] == self);
DCHECK(![_contentView superview] || [_contentView superview] == self.view);
[_contentView removeFromSuperview];
_contentView = contentView;
if (contentView)
[self addSubview:contentView];
[self.view addSubview:contentView];
}
@end
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/browser_container_view.h"
#import "ios/chrome/browser/ui/browser_container_view_controller.h"
#include "testing/platform_test.h"
......@@ -10,51 +10,47 @@
#error "This file requires ARC support."
#endif
// Fixture for BrowserContainerView testing.
class BrowserContainerViewTest : public PlatformTest {
// Fixture for BrowserContainerViewController testing.
class BrowserContainerViewControllerTest : public PlatformTest {
protected:
void SetUp() override {
PlatformTest::SetUp();
browser_container_view_ = [[BrowserContainerView alloc] init];
ASSERT_TRUE(browser_container_view_);
view_controller_ = [[BrowserContainerViewController alloc] init];
ASSERT_TRUE(view_controller_);
content_view_ = [[UIView alloc] init];
ASSERT_TRUE(content_view_);
}
BrowserContainerView* browser_container_view_;
BrowserContainerViewController* view_controller_;
UIView* content_view_;
};
// Tests adding a new content view when BrowserContainerView does not currently
// have a content view.
TEST_F(BrowserContainerViewTest, AddingContentView) {
// Tests adding a new content view when BrowserContainerViewController does not
// currently have a content view.
TEST_F(BrowserContainerViewControllerTest, AddingContentView) {
ASSERT_FALSE([content_view_ superview]);
[browser_container_view_ displayContentView:content_view_];
EXPECT_EQ(static_cast<UIView*>(browser_container_view_),
[content_view_ superview]);
[view_controller_ displayContentView:content_view_];
EXPECT_EQ(view_controller_.view, content_view_.superview);
}
// Tests removing previously added content view.
TEST_F(BrowserContainerViewTest, RemovingContentView) {
[browser_container_view_ displayContentView:content_view_];
ASSERT_EQ(static_cast<UIView*>(browser_container_view_),
[content_view_ superview]);
TEST_F(BrowserContainerViewControllerTest, RemovingContentView) {
[view_controller_ displayContentView:content_view_];
ASSERT_EQ(view_controller_.view, content_view_.superview);
[browser_container_view_ displayContentView:nil];
[view_controller_ displayContentView:nil];
EXPECT_FALSE([content_view_ superview]);
}
// Tests adding a new content view when BrowserContainerView already has a
// content view.
TEST_F(BrowserContainerViewTest, ReplacingContentView) {
[browser_container_view_ displayContentView:content_view_];
ASSERT_EQ(static_cast<UIView*>(browser_container_view_),
[content_view_ superview]);
// Tests adding a new content view when BrowserContainerViewController already
// has a content view.
TEST_F(BrowserContainerViewControllerTest, ReplacingContentView) {
[view_controller_ displayContentView:content_view_];
ASSERT_EQ(view_controller_.view, content_view_.superview);
UIView* content_view2 = [[UIView alloc] init];
[browser_container_view_ displayContentView:content_view2];
[view_controller_ displayContentView:content_view2];
EXPECT_FALSE([content_view_ superview]);
EXPECT_EQ(static_cast<UIView*>(browser_container_view_),
[content_view2 superview]);
EXPECT_EQ(view_controller_.view, content_view2.superview);
}
......@@ -19,7 +19,6 @@
@protocol ApplicationCommands;
@protocol BrowserCommands;
@class BrowserContainerView;
@class BrowserViewControllerDependencyFactory;
class GURL;
@protocol OmniboxFocuser;
......@@ -71,7 +70,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
dispatcher;
// The top-level browser container view.
@property(nonatomic, strong) BrowserContainerView* contentArea;
@property(nonatomic, strong, readonly) UIView* contentArea;
// Invisible button used to dismiss the keyboard.
@property(nonatomic, strong) UIButton* typingShield;
......
......@@ -251,7 +251,7 @@ class BrowserViewControllerTest : public BlockCleanupTest {
TEST_F(BrowserViewControllerTest, TestTabSelected) {
[bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]);
EXPECT_TRUE(webStateImpl_->IsVisible());
}
......@@ -262,7 +262,7 @@ TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) {
id tabMock = (id)tab_;
[tabMock onSelector:@selector(url) callBlockExpectation:block];
[bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]);
EXPECT_TRUE(webStateImpl_->IsVisible());
}
......
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