Skip to content
Permalink
Browse files

[Merge M80][WebLayer] Fix top controls reappearing on scroll

On pages that had a lot of same document navigations, the top controls
would keep reappearing.

Before: https://screenshot.googleplex.com/oTUd4Omgga4
After: https://screenshot.googleplex.com/70eygfXeVvR

TBR=sky@chromium.org

(cherry picked from commit c61e413)

Bug: 1033733
Change-Id: I4021c256c524efda93c189c35d04620a5df97b8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1966356
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#725177}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071070
Reviewed-by: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/branch-heads/3987@{#955}
Cr-Branched-From: c4e8da9-refs/heads/master@{#722274}
  • Loading branch information
clarkduvall authored and Commit Bot committed Feb 25, 2020
1 parent f264383 commit 823408aeb1d7c310727f44b5dbff407548f3c056
@@ -4,6 +4,7 @@

package org.chromium.weblayer.test;

import android.os.SystemClock;
import android.support.test.filters.SmallTest;
import android.support.v4.app.Fragment;
import android.view.View;
@@ -88,6 +89,10 @@ public void testBasic() throws Exception {
mInitialVisiblePageHeight = getVisiblePageHeight();
Assert.assertTrue(mInitialVisiblePageHeight > 0);

// TODO(http://crbug.com/1034147): Remove this and find a way to pass command line arguments
// to the implementation.
SystemClock.sleep(3100);

// Move by the size of the top-controls.
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, -mTopControlsHeight);
@@ -9,10 +9,10 @@
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/browser_controls_state.h"
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
#include "ui/base/window_open_disposition.h"
#include "weblayer/browser/file_select_helper.h"
@@ -42,6 +42,14 @@ namespace weblayer {

namespace {

#if defined(OS_ANDROID)
// The time that must elapse after a navigation before the browser controls can
// be hidden. This value matches what chrome has in
// TabStateBrowserControlsVisibilityDelegate.
constexpr base::TimeDelta kBrowserControlsAllowHideDelay =
base::TimeDelta::FromSeconds(3);
#endif

NewTabType NewTabTypeFromWindowDisposition(WindowOpenDisposition disposition) {
// WindowOpenDisposition has a *ton* of types, but the following are really
// the only ones that should be hit for this code path.
@@ -291,8 +299,6 @@ void TabImpl::RunFileChooser(
}

int TabImpl::GetTopControlsHeight() {
if (is_fullscreen_)
return 0;
#if defined(OS_ANDROID)
return top_controls_container_view_
? top_controls_container_view_->GetTopControlsHeight()
@@ -327,11 +333,21 @@ void TabImpl::EnterFullscreenModeForTab(
weak_ptr_factory_.GetWeakPtr());
base::AutoReset<bool> reset(&processing_enter_fullscreen_, true);
fullscreen_delegate_->EnterFullscreen(std::move(exit_fullscreen_closure));
#if defined(OS_ANDROID)
// Make sure browser controls cannot show when the tab is fullscreen.
UpdateBrowserControlsState(content::BROWSER_CONTROLS_STATE_HIDDEN,
content::BROWSER_CONTROLS_STATE_BOTH, false);
#endif
}

void TabImpl::ExitFullscreenModeForTab(content::WebContents* web_contents) {
is_fullscreen_ = false;
fullscreen_delegate_->ExitFullscreen();
#if defined(OS_ANDROID)
// Attempt to show browser controls when exiting fullscreen.
UpdateBrowserControlsState(content::BROWSER_CONTROLS_STATE_BOTH,
content::BROWSER_CONTROLS_STATE_SHOWN, true);
#endif
}

bool TabImpl::IsFullscreenForTabOrPending(
@@ -368,16 +384,18 @@ void TabImpl::CloseContents(content::WebContents* source) {
void TabImpl::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
#if defined(OS_ANDROID)
web_contents_->GetMainFrame()->UpdateBrowserControlsState(
content::BROWSER_CONTROLS_STATE_BOTH,
content::BROWSER_CONTROLS_STATE_SHOWN, false);

if (web_contents_->ShowingInterstitialPage()) {
web_contents_->GetInterstitialPage()
->GetMainFrame()
->UpdateBrowserControlsState(content::BROWSER_CONTROLS_STATE_SHOWN,
content::BROWSER_CONTROLS_STATE_SHOWN,
false);
if (navigation_handle->IsInMainFrame() &&
!navigation_handle->IsSameDocument()) {
// Force the browser controls to show initially, then allow hiding after a
// short delay.
UpdateBrowserControlsState(content::BROWSER_CONTROLS_STATE_SHOWN,
content::BROWSER_CONTROLS_STATE_BOTH, true);
update_browser_controls_state_timer_.Start(
FROM_HERE, kBrowserControlsAllowHideDelay,
base::BindOnce(&TabImpl::UpdateBrowserControlsState,
base::Unretained(this),
content::BROWSER_CONTROLS_STATE_BOTH,
content::BROWSER_CONTROLS_STATE_BOTH, true));
}
#endif
}
@@ -403,6 +421,24 @@ void TabImpl::UpdateRendererPrefs(bool should_sync_prefs) {
web_contents_->SyncRendererPrefs();
}

#if defined(OS_ANDROID)
void TabImpl::UpdateBrowserControlsState(
content::BrowserControlsState constraints,
content::BrowserControlsState current,
bool animate) {
// Cancel the timer since the state was set explicitly.
update_browser_controls_state_timer_.Stop();
web_contents_->GetMainFrame()->UpdateBrowserControlsState(constraints,
current, animate);

if (web_contents_->ShowingInterstitialPage()) {
web_contents_->GetInterstitialPage()
->GetMainFrame()
->UpdateBrowserControlsState(constraints, current, animate);
}
}
#endif

std::unique_ptr<Tab> Tab::Create(Profile* profile) {
return std::make_unique<TabImpl>(static_cast<ProfileImpl*>(profile));
}
@@ -10,9 +10,11 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/browser_controls_state.h"
#include "weblayer/browser/i18n_util.h"
#include "weblayer/public/tab.h"

@@ -136,6 +138,12 @@ class TabImpl : public Tab,

void UpdateRendererPrefs(bool should_sync_prefs);

#if defined(OS_ANDROID)
void UpdateBrowserControlsState(content::BrowserControlsState constraints,
content::BrowserControlsState current,
bool animate);
#endif

DownloadDelegate* download_delegate_ = nullptr;
ErrorPageDelegate* error_page_delegate_ = nullptr;
FullscreenDelegate* fullscreen_delegate_ = nullptr;
@@ -148,6 +156,7 @@ class TabImpl : public Tab,
#if defined(OS_ANDROID)
TopControlsContainerView* top_controls_container_view_ = nullptr;
base::android::ScopedJavaGlobalRef<jobject> java_impl_;
base::OneShotTimer update_browser_controls_state_timer_;
#endif

bool is_fullscreen_ = false;

0 comments on commit 823408a

Please sign in to comment.
You can’t perform that action at this time.