Commit e2ec670f authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Move content below header the first time a WebState is activated.

This CL also renames UpdateFullscreenWebViewProxyForReplacedScrollView()
to MoveContentBelowHeader(), as it is used in additional places other
than just for replaced scroll views.

Bug: 769379
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I330e20e33501429140a8ea3dfd9e8afa34d47fcf
Reviewed-on: https://chromium-review.googlesource.com/933921
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538925}
parent 9f37416d
......@@ -46,6 +46,8 @@ source_set("coordinators") {
source_set("internal") {
sources = [
"fullscreen_content_adjustment_util.h",
"fullscreen_content_adjustment_util.mm",
"fullscreen_controller_factory.mm",
"fullscreen_controller_impl.h",
"fullscreen_controller_impl.mm",
......@@ -63,8 +65,6 @@ source_set("internal") {
"fullscreen_web_state_observer.mm",
"fullscreen_web_view_proxy_observer.h",
"fullscreen_web_view_proxy_observer.mm",
"fullscreen_web_view_scroll_view_replacement_util.h",
"fullscreen_web_view_scroll_view_replacement_util.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
......@@ -129,6 +129,7 @@ source_set("unit_tests") {
"//ios/web/public",
"//ios/web/public/test/fakes",
"//testing/gtest",
"//third_party/ocmock",
]
}
......
......@@ -2,8 +2,8 @@
// 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_FULLSCREEN_FULLSCREEN_WEB_VIEW_SCROLL_VIEW_REPLACEMENT_UTIL_H_
#define IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_WEB_VIEW_SCROLL_VIEW_REPLACEMENT_UTIL_H_
#ifndef IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTENT_ADJUSTMENT_UTIL_H_
#define IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTENT_ADJUSTMENT_UTIL_H_
#import <Foundation/Foundation.h>
......@@ -11,9 +11,7 @@
class FullscreenModel;
// Updates |proxy|'s content offset and top padding to ensure that the content
// is fully visible under the toolbar when its scroll view is replaced.
void UpdateFullscreenWebViewProxyForReplacedScrollView(
id<CRWWebViewProxy> proxy,
FullscreenModel* model);
// is fully visible under the hdeader.
void MoveContentBelowHeader(id<CRWWebViewProxy> proxy, FullscreenModel* model);
#endif // IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_WEB_VIEW_SCROLL_VIEW_REPLACEMENT_UTIL_H_
#endif // IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTENT_ADJUSTMENT_UTIL_H_
......@@ -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/fullscreen/fullscreen_web_view_scroll_view_replacement_util.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_content_adjustment_util.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
......@@ -13,9 +13,7 @@
#error "This file requires ARC support."
#endif
void UpdateFullscreenWebViewProxyForReplacedScrollView(
id<CRWWebViewProxy> proxy,
FullscreenModel* model) {
void MoveContentBelowHeader(id<CRWWebViewProxy> proxy, FullscreenModel* model) {
DCHECK(proxy);
DCHECK(model);
CGFloat padding = model->progress() * model->GetToolbarHeight();
......
......@@ -5,6 +5,8 @@
#ifndef IOS_CLEAN_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_WEB_STATE_LIST_OBSERVER_H_
#define IOS_CLEAN_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_WEB_STATE_LIST_OBSERVER_H_
#include <set>
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_state_observer.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer.h"
#include "ios/web/public/web_state/web_state_observer.h"
......@@ -40,6 +42,16 @@ class FullscreenWebStateListObserver : public WebStateListObserver {
web::WebState* new_web_state,
int active_index,
int reason) override;
void WebStateDetachedAt(WebStateList* web_state_list,
web::WebState* web_state,
int index) override;
void WillCloseWebStateAt(WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool user_action) override;
// Whether |web_state| has been activated during the lifetime of this object.
bool HasWebStateBeenActivated(web::WebState* web_state);
// The model passed on construction.
FullscreenModel* model_;
......@@ -47,6 +59,8 @@ class FullscreenWebStateListObserver : public WebStateListObserver {
WebStateList* web_state_list_;
// The observer for the active WebState.
FullscreenWebStateObserver web_state_observer_;
// The WebStates that have been activated in |web_state_list_|.
std::set<web::WebState*> activated_web_states_;
};
#endif // IOS_CLEAN_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_WEB_STATE_LIST_OBSERVER_H_
......@@ -5,8 +5,8 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_state_list_observer.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_content_adjustment_util.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_view_scroll_view_replacement_util.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/web/public/web_state/web_state.h"
......@@ -44,13 +44,15 @@ void FullscreenWebStateListObserver::WebStateReplacedAt(
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) {
if (HasWebStateBeenActivated(old_web_state))
activated_web_states_.erase(old_web_state);
if (new_web_state == web_state_list->GetActiveWebState()) {
// Reset the model if the active WebState is replaced.
web_state_observer_.SetWebState(new_web_state);
model_->ResetForNavigation();
if (new_web_state) {
UpdateFullscreenWebViewProxyForReplacedScrollView(
new_web_state->GetWebViewProxy(), model_);
MoveContentBelowHeader(new_web_state->GetWebViewProxy(), model_);
activated_web_states_.insert(new_web_state);
}
}
}
......@@ -62,4 +64,32 @@ void FullscreenWebStateListObserver::WebStateActivatedAt(
int active_index,
int reason) {
web_state_observer_.SetWebState(new_web_state);
// If this is the first time the WebState was activated, move its content
// below the header.
if (new_web_state && !HasWebStateBeenActivated(new_web_state)) {
MoveContentBelowHeader(new_web_state->GetWebViewProxy(), model_);
activated_web_states_.insert(new_web_state);
}
}
void FullscreenWebStateListObserver::WebStateDetachedAt(
WebStateList* web_state_list,
web::WebState* web_state,
int index) {
if (HasWebStateBeenActivated(web_state))
activated_web_states_.erase(web_state);
}
void FullscreenWebStateListObserver::WillCloseWebStateAt(
WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool user_action) {
if (HasWebStateBeenActivated(web_state))
activated_web_states_.erase(web_state);
}
bool FullscreenWebStateListObserver::HasWebStateBeenActivated(
web::WebState* web_state) {
return activated_web_states_.find(web_state) != activated_web_states_.end();
}
......@@ -18,12 +18,36 @@
#import "ios/web/public/test/fakes/fake_navigation_context.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
#import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// A TestWebState subclass that returns mock objects for the view proxies.
class TestWebStateWithProxy : public web::TestWebState {
public:
TestWebStateWithProxy() {
scroll_view_proxy_ = OCMClassMock([CRWWebViewScrollViewProxy class]);
id web_view_proxy_mock = OCMProtocolMock(@protocol(CRWWebViewProxy));
[[[web_view_proxy_mock stub] andReturn:scroll_view_proxy_] scrollViewProxy];
web_view_proxy_ = web_view_proxy_mock;
}
id<CRWWebViewProxy> GetWebViewProxy() const override {
return web_view_proxy_;
}
private:
// The mocked proxy objects.
__strong CRWWebViewScrollViewProxy* scroll_view_proxy_;
__strong id<CRWWebViewProxy> web_view_proxy_;
};
} // namespace
class FullscreenWebStateListObserverTest : public PlatformTest {
public:
FullscreenWebStateListObserverTest()
......@@ -54,9 +78,9 @@ class FullscreenWebStateListObserverTest : public PlatformTest {
TEST_F(FullscreenWebStateListObserverTest, ObserveActiveWebState) {
// Insert a WebState into the list. The observer should create a
// FullscreenWebStateObserver for the newly activated WebState.
std::unique_ptr<web::TestWebState> inserted_web_state =
std::make_unique<web::TestWebState>();
web::TestWebState* web_state = inserted_web_state.get();
std::unique_ptr<TestWebStateWithProxy> inserted_web_state =
std::make_unique<TestWebStateWithProxy>();
TestWebStateWithProxy* web_state = inserted_web_state.get();
web_state_list().InsertWebState(0, std::move(inserted_web_state),
WebStateList::INSERT_ACTIVATE,
WebStateOpener());
......
......@@ -5,9 +5,10 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_view_proxy_observer.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_content_adjustment_util.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_mediator.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_view_scroll_view_replacement_util.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
#import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
......@@ -51,7 +52,7 @@
- (void)webViewScrollViewProxyDidSetScrollView:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy {
UpdateFullscreenWebViewProxyForReplacedScrollView(self.proxy, self.model);
MoveContentBelowHeader(self.proxy, self.model);
}
- (BOOL)webViewScrollViewShouldScrollToTop:
......
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