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