0

Browser controls in viz 4: OffsetTag plumbing to renderer

https://chromium-review.googlesource.com/c/chromium/src/+/5535310
plumbed to browser side objects, this cl plumbs to the renderer.

Bug: 325471990, 345261548
Change-Id: I334c13ccdf54978694c8a286f46f06e6096d6d9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5605504
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Commit-Queue: Peilin Wang <peilinwang@google.com>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1313038}
This commit is contained in:
Peilin Wang
2024-06-10 20:55:30 +00:00
committed by Chromium LUCI CQ
parent bc98184818
commit ae08e26e2a
62 changed files with 500 additions and 193 deletions
cc
chrome
components/thin_webview/internal
content
third_party/blink

@ -11,9 +11,12 @@
#include "base/check_op.h"
#include "base/memory/ptr_util.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_manager_client.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/trees/layer_tree_impl.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/quads/offset_tag.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -80,6 +83,10 @@ float BrowserControlsOffsetManager::TopControlsMinHeight() const {
return client_->TopControlsMinHeight();
}
viz::OffsetTag BrowserControlsOffsetManager::TopControlsOffsetTag() const {
return top_controls_offset_tag_;
}
float BrowserControlsOffsetManager::TopControlsMinShownRatio() const {
return TopControlsHeight() ? TopControlsMinHeight() / TopControlsHeight()
: 0.f;
@ -137,7 +144,8 @@ BrowserControlsOffsetManager::BottomControlsShownRatioRange() {
void BrowserControlsOffsetManager::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
DCHECK(!(constraints == BrowserControlsState::kShown &&
current == BrowserControlsState::kHidden));
DCHECK(!(constraints == BrowserControlsState::kHidden &&
@ -156,6 +164,10 @@ void BrowserControlsOffsetManager::UpdateBrowserControlsState(
permitted_state_ = constraints;
if (offset_tags_info.has_value()) {
top_controls_offset_tag_ = offset_tags_info.value().top_controls_offset_tag;
}
// Don't do anything if it doesn't matter which state the controls are in.
if (constraints == BrowserControlsState::kBoth &&
current == BrowserControlsState::kBoth)

@ -11,9 +11,12 @@
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/layers/layer_impl.h"
#include "cc/trees/browser_controls_params.h"
#include "components/viz/common/quads/offset_tag.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -56,6 +59,7 @@ class CC_EXPORT BrowserControlsOffsetManager {
// min-height, which is equal to the current visible min-height. Otherwise,
// this will return the same value as |TopControlsMinHeight()|.
float TopControlsMinHeightOffset() const;
viz::OffsetTag TopControlsOffsetTag() const;
// The amount of offset of the web content area, calculating from the bottom.
// Same as the current shown height of the bottom controls.
@ -87,9 +91,13 @@ class CC_EXPORT BrowserControlsOffsetManager {
AnimationDirection::kShowingControls;
}
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate);
// See UpdateBrowserControlsState in
// third_party/blink/public/mojom/frame/frame.mojom
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info);
// Return the browser control constraint that must be synced to the
// main renderer thread (to trigger viewport and related changes).
@ -197,6 +205,11 @@ class CC_EXPORT BrowserControlsOffsetManager {
// gesture, then we reorder the animation until after the scroll.
bool show_controls_when_scroll_completes_ = false;
// The tag used to accompany scroll offsets in the render frame's metadata.
// During surface aggregation, the layers with the same token will have the
// corresponding offsets applied.
viz::OffsetTag top_controls_offset_tag_;
// Class that holds and manages the state of the controls animations.
class Animation {
public:

@ -982,7 +982,8 @@ TEST(BrowserControlsOffsetManagerTest, ScrollByWithZeroHeightControlsIsNoop) {
MockBrowserControlsOffsetManagerClient client(0.f, 0.5f, 0.5f);
BrowserControlsOffsetManager* manager = client.manager();
manager->UpdateBrowserControlsState(BrowserControlsState::kBoth,
BrowserControlsState::kBoth, false);
BrowserControlsState::kBoth, false,
std::nullopt);
manager->ScrollBegin();
gfx::Vector2dF pending = manager->ScrollBy(gfx::Vector2dF(0.f, 20.f));
@ -1053,12 +1054,14 @@ TEST(BrowserControlsOffsetManagerTest,
EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
manager->UpdateBrowserControlsState(BrowserControlsState::kBoth,
BrowserControlsState::kHidden, true);
BrowserControlsState::kHidden, true,
std::nullopt);
EXPECT_TRUE(manager->HasAnimation());
EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
manager->UpdateBrowserControlsState(BrowserControlsState::kBoth,
BrowserControlsState::kShown, true);
BrowserControlsState::kShown, true,
std::nullopt);
EXPECT_FALSE(manager->HasAnimation());
EXPECT_FLOAT_EQ(1.f, client.CurrentBottomControlsShownRatio());
}
@ -1214,7 +1217,8 @@ TEST(BrowserControlsOffsetManagerTest, MinHeightChangeUpdatesAnimation) {
// Hide the controls to start an animation to min-height.
EXPECT_FLOAT_EQ(1.f, manager->TopControlsShownRatio());
manager->UpdateBrowserControlsState(BrowserControlsState::kHidden,
BrowserControlsState::kBoth, true);
BrowserControlsState::kBoth, true,
std::nullopt);
base::TimeTicks time = base::TimeTicks::Now();
manager->Animate(time);
EXPECT_TRUE(manager->HasAnimation());
@ -1314,7 +1318,8 @@ TEST(BrowserControlsOffsetManagerTest,
// Start an animation to show the controls
manager->UpdateBrowserControlsState(BrowserControlsState::kBoth,
BrowserControlsState::kShown, true);
BrowserControlsState::kShown, true,
std::nullopt);
EXPECT_TRUE(manager->IsAnimatingToShowControls());
// Start a scroll, which should cancel the animation.
@ -1349,7 +1354,8 @@ TEST(BrowserControlsOffsetManagerTest,
// Start an animation to show the controls.
manager->UpdateBrowserControlsState(BrowserControlsState::kBoth,
BrowserControlsState::kShown, true);
BrowserControlsState::kShown, true,
std::nullopt);
EXPECT_TRUE(manager->IsAnimatingToShowControls());
// Finish the scroll, and the animation should still be in progress and/or

@ -8,7 +8,9 @@
#include <memory>
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/input/actively_scrolling_type.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/paint/element_id.h"
#include "ui/gfx/geometry/size.h"
@ -136,9 +138,12 @@ class CompositorDelegateForInput {
virtual float PageScaleFactor() const = 0;
virtual gfx::Size VisualDeviceViewportSize() const = 0;
virtual const LayerTreeSettings& GetSettings() const = 0;
virtual void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) = 0;
virtual void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo>
offset_tags_info) = 0;
virtual bool HasScrollLinkedAnimation(ElementId for_scroller) const = 0;
// TODO(bokan): Temporary escape hatch for code that hasn't yet been

@ -10,9 +10,11 @@
#include "base/feature_list.h"
#include "base/notreached.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/scroll_elasticity_helper.h"
#include "cc/input/scroll_utils.h"
#include "cc/input/scrollbar_controller.h"
@ -2115,11 +2117,13 @@ void InputHandler::SetDeferBeginMainFrame(bool defer_begin_main_frame) const {
compositor_delegate_->SetDeferBeginMainFrame(defer_begin_main_frame);
}
void InputHandler::UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
void InputHandler::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
compositor_delegate_->UpdateBrowserControlsState(constraints, current,
animate);
animate, offset_tags_info);
}
void InputHandler::SetIsHandlingTouchSequence(bool is_handling_touch_sequence) {

@ -11,7 +11,9 @@
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/cc_export.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/input/compositor_input_interfaces.h"
#include "cc/input/event_listener_properties.h"
@ -438,9 +440,11 @@ class CC_EXPORT InputHandler : public InputDelegateForCompositor {
// compositor thread has had a chance to update the scroll offset.
virtual void SetDeferBeginMainFrame(bool defer_begin_main_frame) const;
virtual void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate);
virtual void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info);
virtual void SetIsHandlingTouchSequence(bool is_handling_touch_sequence);

@ -22,6 +22,7 @@ component("shared_mojom_traits") {
mojom("mojom") {
generate_java = true
sources = [
"browser_controls_offset_tags_info.mojom",
"browser_controls_params.mojom",
"browser_controls_state.mojom",
"overscroll_behavior.mojom",
@ -86,6 +87,17 @@ mojom("mojom") {
traits_headers = [ "//cc/ipc/cc_param_traits_macros.h" ]
traits_public_deps = [ "//cc/ipc" ]
},
{
types = [
{
mojom = "cc.mojom.BrowserControlsOffsetTagsInfo"
cpp = "::cc::BrowserControlsOffsetTagsInfo"
},
]
traits_headers =
[ "//cc/mojom/browser_controls_offset_tags_info_mojom_traits.h" ]
traits_public_deps = [ "//components/viz/common" ]
},
{
types = [
{

@ -1,5 +1,6 @@
include_rules = [
"+mojo/public",
"+services/viz/public/cpp/compositing",
"+services/viz/public/mojom/compositing",
"+skia/public/mojom",
]

@ -0,0 +1,15 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module cc.mojom;
import "services/viz/public/mojom/compositing/offset_tag.mojom";
// Only sent from browser to renderer. See
// cc/input/browser_controls_offset_tags_info.h for more details.
struct BrowserControlsOffsetTagsInfo {
viz.mojom.OffsetTag top_controls_offset_tag;
int32 top_controls_height;
int32 top_controls_width;
};

@ -0,0 +1,41 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_MOJOM_BROWSER_CONTROLS_OFFSET_TAGS_INFO_MOJOM_TRAITS_H_
#define CC_MOJOM_BROWSER_CONTROLS_OFFSET_TAGS_INFO_MOJOM_TRAITS_H_
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/mojom/browser_controls_offset_tags_info.mojom-shared.h"
#include "components/viz/common/quads/offset_tag.h"
#include "services/viz/public/cpp/compositing/offset_tag_mojom_traits.h"
namespace mojo {
template <>
struct StructTraits<cc::mojom::BrowserControlsOffsetTagsInfoDataView,
cc::BrowserControlsOffsetTagsInfo> {
static const viz::OffsetTag& top_controls_offset_tag(
const cc::BrowserControlsOffsetTagsInfo& input) {
return input.top_controls_offset_tag;
}
static int top_controls_height(
const cc::BrowserControlsOffsetTagsInfo& input) {
return input.top_controls_height;
}
static int top_controls_width(
const cc::BrowserControlsOffsetTagsInfo& input) {
return input.top_controls_width;
}
static bool Read(cc::mojom::BrowserControlsOffsetTagsInfoDataView data,
cc::BrowserControlsOffsetTagsInfo* out) {
return data.ReadTopControlsOffsetTag(&out->top_controls_offset_tag);
}
};
} // namespace mojo
#endif // CC_MOJOM_BROWSER_CONTROLS_OFFSET_TAGS_INFO_MOJOM_TRAITS_H_

@ -9,6 +9,8 @@
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/paint_holding_reason.h"
#include "cc/trees/proxy.h"
@ -50,9 +52,12 @@ class FakeProxy : public Proxy {
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) override;
bool MainFrameWillHappenForTesting() override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) override {}
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info)
override {}
void RequestBeginMainFrameNotExpected(bool new_state) override {}
void SetSourceURL(ukm::SourceId source_id, const GURL& url) override {}
void SetUkmSmoothnessDestination(

@ -30,12 +30,14 @@
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/base/features.h"
#include "cc/base/histograms.h"
#include "cc/base/math_util.h"
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/layer_selection_bound.h"
#include "cc/input/overscroll_behavior.h"
#include "cc/input/page_scale_animation.h"
@ -1200,13 +1202,16 @@ void LayerTreeHost::DetachInputDelegateAndRenderFrameObserver() {
proxy_->DetachInputDelegateAndRenderFrameObserver();
}
void LayerTreeHost::UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
void LayerTreeHost::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
DCHECK(IsMainThread());
// Browser controls are only used in threaded mode but Blink layout tests may
// call into this. The single threaded version is a no-op.
proxy_->UpdateBrowserControlsState(constraints, current, animate);
proxy_->UpdateBrowserControlsState(constraints, current, animate,
offset_tags_info);
}
void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {

@ -27,10 +27,12 @@
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/base/completion_event.h"
#include "cc/benchmarks/micro_benchmark.h"
#include "cc/benchmarks/micro_benchmark_controller.h"
#include "cc/cc_export.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/input/compositor_input_interfaces.h"
#include "cc/input/event_listener_properties.h"
@ -380,9 +382,11 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
// Input Handling ---------------------------------------------
// Sets the state of the browser controls. (Used for URL bar animations).
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate);
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info);
// Returns the delegate that the input handler uses to communicate with the
// LayerTreeHostImpl on the compositor thread. Must be dereferenced only on

@ -41,6 +41,7 @@
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "base/trace_event/typed_macros.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/base/devtools_instrumentation.h"
@ -51,6 +52,7 @@
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/page_scale_animation.h"
#include "cc/input/scrollbar_animation_controller.h"
#include "cc/layers/append_quads_data.h"
@ -354,9 +356,10 @@ void LayerTreeHostImpl::SetDeferBeginMainFrame(
void LayerTreeHostImpl::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
browser_controls_offset_manager_->UpdateBrowserControlsState(
constraints, current, animate);
constraints, current, animate, offset_tags_info);
}
bool LayerTreeHostImpl::HasScrollLinkedAnimation(ElementId for_scroller) const {

@ -27,10 +27,12 @@
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/benchmarks/micro_benchmark_controller_impl.h"
#include "cc/cc_export.h"
#include "cc/input/actively_scrolling_type.h"
#include "cc/input/browser_controls_offset_manager_client.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/input_handler.h"
#include "cc/input/scrollbar_animation_controller.h"
#include "cc/layers/layer_collections.h"
@ -386,9 +388,12 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
LayerTreeHostImpl& GetImplDeprecated() override;
const LayerTreeHostImpl& GetImplDeprecated() const override;
void SetDeferBeginMainFrame(bool defer_begin_main_frame) const override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info)
override;
bool HasScrollLinkedAnimation(ElementId for_scroller) const override;
void DetachInputDelegateAndRenderFrameObserver();

@ -8178,7 +8178,8 @@ TEST_F(LayerTreeHostImplBrowserControlsTest,
// Kick off an animation to show the browser controls.
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, true);
BrowserControlsState::kBoth, BrowserControlsState::kShown, true,
std::nullopt);
base::TimeTicks start_time = base::TimeTicks::Now();
viz::BeginFrameArgs begin_frame_args =
viz::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
@ -12370,7 +12371,8 @@ TEST_F(LayerTreeHostImplWithBrowserControlsTest,
UpdateDrawProperties(host_impl_->active_tree());
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, false);
BrowserControlsState::kBoth, BrowserControlsState::kShown, false,
std::nullopt);
DrawFrame();
// First, scroll just the browser controls and verify that the scroll
@ -12452,7 +12454,8 @@ TEST_F(LayerTreeHostImplWithBrowserControlsTest,
host_impl_->active_tree()->SetBrowserControlsParams(
{top_controls_height_, 0, 0, 0, false, true});
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, false);
BrowserControlsState::kBoth, BrowserControlsState::kShown, false,
std::nullopt);
DrawFrame();
LayerImpl* viewport_layer = InnerViewportScrollLayer();
@ -12499,7 +12502,8 @@ TEST_F(LayerTreeHostImplWithBrowserControlsTest,
UpdateDrawProperties(host_impl_->active_tree());
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, false);
BrowserControlsState::kBoth, BrowserControlsState::kShown, false,
std::nullopt);
DrawFrame();
const float residue = 35;
@ -12580,7 +12584,8 @@ TEST_F(LayerTreeHostImplWithBrowserControlsTest,
UpdateDrawProperties(host_impl_->active_tree());
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, false);
BrowserControlsState::kBoth, BrowserControlsState::kShown, false,
std::nullopt);
float initial_scroll_offset = 50;
scroll_layer->layer_tree_impl()
->property_trees()
@ -12664,7 +12669,8 @@ TEST_F(LayerTreeHostImplWithBrowserControlsTest,
UpdateDrawProperties(host_impl_->active_tree());
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kBoth, BrowserControlsState::kShown, false);
BrowserControlsState::kBoth, BrowserControlsState::kShown, false,
std::nullopt);
DrawFrame();
float offset = 50;

@ -2989,7 +2989,8 @@ class LayerTreeHostScrollTestViewportAbortedCommit
void WillSendBeginMainFrameOnThread(LayerTreeHostImpl* host_impl) override {
if (is_first_frame_) {
host_impl->browser_controls_manager()->UpdateBrowserControlsState(
BrowserControlsState::kHidden, BrowserControlsState::kHidden, true);
BrowserControlsState::kHidden, BrowserControlsState::kHidden, true,
std::nullopt);
bool changed_since_last_sync = false;
BrowserControlsState permitted_constraint =
host_impl->browser_controls_manager()->PullConstraintForMainThread(

@ -10,7 +10,9 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/cc_export.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/trees/paint_holding_commit_trigger.h"
#include "cc/trees/paint_holding_reason.h"
@ -96,9 +98,12 @@ class CC_EXPORT Proxy {
virtual void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter) = 0;
virtual void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) = 0;
virtual void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo>
offset_tags_info) = 0;
virtual void RequestBeginMainFrameNotExpected(bool new_state) = 0;

@ -20,10 +20,12 @@
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/trace_event/typed_macros.h"
#include "base/types/optional_ref.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/base/features.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/metrics/compositor_timing_history.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/trees/compositor_commit_data.h"
@ -172,10 +174,11 @@ void ProxyImpl::InitializePaintWorkletLayerPainterOnImpl(
void ProxyImpl::UpdateBrowserControlsStateOnImpl(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
DCHECK(IsImplThread());
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
constraints, current, animate);
constraints, current, animate, offset_tags_info);
}
void ProxyImpl::InitializeLayerTreeFrameSinkOnImpl(

@ -12,8 +12,10 @@
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/types/optional_ref.h"
#include "cc/base/completion_event.h"
#include "cc/base/delayed_unique_notifier.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/scheduler/scheduler.h"
#include "cc/trees/layer_tree_host_impl.h"
@ -45,9 +47,11 @@ class CC_EXPORT ProxyImpl : public LayerTreeHostImplClient,
ProxyImpl& operator=(const ProxyImpl&) = delete;
void UpdateBrowserControlsStateOnImpl(BrowserControlsState constraints,
BrowserControlsState current,
bool animate);
void UpdateBrowserControlsStateOnImpl(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info);
void InitializeLayerTreeFrameSinkOnImpl(
LayerTreeFrameSink* layer_tree_frame_sink,
base::WeakPtr<ProxyMain> proxy_main_frame_sink_bound_weak_ptr);

@ -16,10 +16,12 @@
#include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/types/optional_ref.h"
#include "cc/base/completion_event.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/base/features.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/trees/latency_info_swap_promise.h"
@ -821,14 +823,17 @@ void ProxyMain::ReleaseLayerTreeFrameSink() {
completion.Wait();
}
void ProxyMain::UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
void ProxyMain::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
DCHECK(IsMainThread());
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&ProxyImpl::UpdateBrowserControlsStateOnImpl,
base::Unretained(proxy_impl_.get()),
constraints, current, animate));
FROM_HERE,
base::BindOnce(&ProxyImpl::UpdateBrowserControlsStateOnImpl,
base::Unretained(proxy_impl_.get()), constraints, current,
animate, offset_tags_info));
}
void ProxyMain::RequestBeginMainFrameNotExpected(bool new_state) {

@ -11,7 +11,9 @@
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/cc_export.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/paint_holding_reason.h"
@ -115,9 +117,12 @@ class CC_EXPORT ProxyMain : public Proxy {
std::unique_ptr<PaintWorkletLayerPainter> painter) override;
bool MainFrameWillHappenForTesting() override;
void ReleaseLayerTreeFrameSink() override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info)
override;
void RequestBeginMainFrameNotExpected(bool new_state) override;
void SetSourceURL(ukm::SourceId source_id, const GURL& url) override;
void SetUkmSmoothnessDestination(

@ -15,11 +15,13 @@
#include "base/notreached.h"
#include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "base/types/optional_ref.h"
#include "build/chromeos_buildflags.h"
#include "cc/base/completion_event.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/metrics/compositor_timing_history.h"
#include "cc/paint/paint_worklet_layer_painter.h"
#include "cc/resources/ui_resource_manager.h"
@ -995,11 +997,12 @@ double SingleThreadProxy::GetPercentDroppedFrames() const {
void SingleThreadProxy::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info) {
DCHECK(task_runner_provider_->IsMainThread());
DebugScopedSetImplThread impl(task_runner_provider_);
host_impl_->browser_controls_manager()->UpdateBrowserControlsState(
constraints, current, animate);
constraints, current, animate, offset_tags_info);
}
bool SingleThreadProxy::WillBeginImplFrame(const viz::BeginFrameArgs& args) {

@ -13,6 +13,8 @@
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/scheduler/scheduler.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/paint_holding_reason.h"
@ -86,9 +88,12 @@ class CC_EXPORT SingleThreadProxy : public Proxy,
base::OnceClosure callback) override;
double GetPercentDroppedFrames() const override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate,
base::optional_ref<const BrowserControlsOffsetTagsInfo> offset_tags_info)
override;
// SchedulerClient implementation
bool WillBeginImplFrame(const viz::BeginFrameArgs& args) override;

@ -263,7 +263,8 @@ public class TabBrowserControlsConstraintsHelper implements UserData {
mTab.getWebContents(),
constraints,
current,
animate);
animate,
new BrowserControlsOffsetTagsInfo(newTag));
mTopControlsOffsetTag = newTag;
}
@ -290,6 +291,7 @@ public class TabBrowserControlsConstraintsHelper implements UserData {
WebContents webContents,
int contraints,
int current,
boolean animate);
boolean animate,
BrowserControlsOffsetTagsInfo offsetTagsInfo);
}
}

@ -156,7 +156,8 @@ public class TabBrowserControlsConstraintsHelperTest {
Mockito.any(),
Mockito.anyInt(),
Mockito.anyInt(),
Mockito.anyBoolean());
Mockito.anyBoolean(),
Mockito.any());
}
@Test
@ -209,7 +210,8 @@ public class TabBrowserControlsConstraintsHelperTest {
Mockito.same(mWebContents),
Mockito.eq(constraints),
Mockito.eq(current),
Mockito.eq(animate));
Mockito.eq(animate),
Mockito.any());
Mockito.clearInvocations(mJniMock);
}

@ -2,6 +2,7 @@ include_rules = [
"-components/devtools_bridge",
"+components/resources/android",
"+cc/input/browser_controls_state.h",
"+cc/input/browser_controls_offset_tags_info.h",
"+cc/slim/layer.h",
"+chrome/android",
"+chrome/browser/web_share_target",

@ -166,7 +166,7 @@ void OverlayPanelContent::UpdateBrowserControlsState(
state = cc::BrowserControlsState::kHidden;
web_contents_->UpdateBrowserControlsState(
state, cc::BrowserControlsState::kBoth, false);
state, cc::BrowserControlsState::kBoth, false, std::nullopt);
}
jlong JNI_OverlayPanelContent_Init(JNIEnv* env,

@ -4,6 +4,8 @@
#include "chrome/browser/android/tab_browser_controls_constraints_helper.h"
#include "cc/input/android/offset_tag_android.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "content/public/browser/render_frame_host.h"
@ -36,7 +38,8 @@ void TabBrowserControlsConstraintsHelper::UpdateState(
const JavaParamRef<jobject>& jweb_contents,
jint constraints,
jint current,
jboolean animate) {
jboolean animate,
const JavaParamRef<jobject>& joffset_tags_info) {
cc::BrowserControlsState constraints_state =
static_cast<cc::BrowserControlsState>(constraints);
cc::BrowserControlsState current_state =
@ -47,8 +50,12 @@ void TabBrowserControlsConstraintsHelper::UpdateState(
return;
}
cc::BrowserControlsOffsetTagsInfo offset_tags_info =
cc::android::FromJavaBrowserControlsOffsetTagsInfo(env,
joffset_tags_info);
web_contents->UpdateBrowserControlsState(constraints_state, current_state,
animate);
animate, offset_tags_info);
}
static jlong JNI_TabBrowserControlsConstraintsHelper_Init(

@ -15,12 +15,14 @@ class TabBrowserControlsConstraintsHelper {
const base::android::JavaParamRef<jobject>& obj);
~TabBrowserControlsConstraintsHelper();
void UpdateState(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& jweb_contents,
jint constraints,
jint current,
jboolean animate);
void UpdateState(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& jweb_contents,
jint constraints,
jint current,
jboolean animate,
const base::android::JavaParamRef<jobject>& joffset_tags_info);
void OnDestroyed(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);

@ -592,7 +592,7 @@ void TopControlsSlideControllerChromeOS::UpdateBrowserControlsStateShown(
const cc::BrowserControlsState current_state =
cc::BrowserControlsState::kShown;
web_contents->UpdateBrowserControlsState(constraints_state, current_state,
animate);
animate, std::nullopt);
}
bool TopControlsSlideControllerChromeOS::CanEnable(

@ -53,7 +53,7 @@ void ThinWebView::PrimaryPageChanged(content::Page& page) {
// Disable browser controls when used for thin webview.
web_contents_->UpdateBrowserControlsState(cc::BrowserControlsState::kHidden,
cc::BrowserControlsState::kHidden,
false);
false, std::nullopt);
}
void ThinWebView::SetWebContents(

@ -331,7 +331,7 @@ void RestoreBrowserControlsState(RenderFrameHostImpl* cached_rfh) {
cached_rfh->GetPage().UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden,
// Do not animate as we want this to happen "instantaneously"
false);
false, std::nullopt);
}
}

@ -9,6 +9,7 @@
#include "base/i18n/character_encoding.h"
#include "base/trace_event/optional_trace_event.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "content/browser/manifest/manifest_manager_host.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/page_delegate.h"
@ -21,6 +22,7 @@
#include "content/public/browser/peak_gpu_memory_tracker.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/common/content_client.h"
#include "services/viz/public/mojom/compositing/offset_tag.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/loader_constants.h"
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
@ -321,9 +323,11 @@ RenderFrameHostImpl& PageImpl::GetMainDocument() const {
return *main_document_;
}
void PageImpl::UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
void PageImpl::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {
// TODO(crbug.com/40159655): Asking for the LocalMainFrame interface
// before the RenderFrame is created is racy.
if (!GetMainDocument().IsRenderFrameLive())
@ -332,10 +336,10 @@ void PageImpl::UpdateBrowserControlsState(cc::BrowserControlsState constraints,
if (base::FeatureList::IsEnabled(
features::kUpdateBrowserControlsWithoutProxy)) {
GetMainDocument().GetRenderWidgetHost()->UpdateBrowserControlsState(
constraints, current, animate);
constraints, current, animate, offset_tags_info);
} else {
GetMainDocument().GetAssociatedLocalMainFrame()->UpdateBrowserControlsState(
constraints, current, animate);
constraints, current, animate, offset_tags_info);
}
}

@ -13,6 +13,7 @@
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "content/browser/fenced_frame/fenced_frame_url_mapping.h"
#include "content/browser/renderer_host/stored_page.h"
@ -172,9 +173,11 @@ class CONTENT_EXPORT PageImpl : public Page {
// Hide or show the browser controls for the given Page, based on allowed
// states, desired state and whether the transition should be animated or
// not.
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate);
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info);
float GetPageScaleFactor() const;

@ -41,6 +41,7 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/trees/browser_controls_params.h"
#include "cc/trees/render_frame_metadata.h"
#include "components/input/native_web_keyboard_event.h"
@ -2683,9 +2684,10 @@ SiteInstanceGroup* RenderWidgetHostImpl::GetSiteInstanceGroup() {
void RenderWidgetHostImpl::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
GetWidgetInputHandler()->UpdateBrowserControlsState(constraints, current,
animate);
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {
GetWidgetInputHandler()->UpdateBrowserControlsState(
constraints, current, animate, offset_tags_info);
}
void RenderWidgetHostImpl::StartDragging(

@ -31,6 +31,7 @@
#include "base/timer/timer.h"
#include "base/types/pass_key.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/mojom/render_frame_metadata.mojom.h"
#include "components/input/event_with_latency_info.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
@ -932,9 +933,11 @@ class CONTENT_EXPORT RenderWidgetHostImpl
SiteInstanceGroup* GetSiteInstanceGroup();
// Updates the browser controls by directly IPCing onto the compositor thread.
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate);
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info);
void StartDragging(blink::mojom::DragDataPtr drag_data,
const url::Origin& source_origin,

@ -49,6 +49,7 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "components/attribution_reporting/features.h"
#include "components/download/public/common/download_stats.h"
#include "components/url_formatter/url_formatter.h"
@ -10786,10 +10787,12 @@ void WebContentsImpl::NotifyPrimaryMainFrameProcessIsAlive() {
void WebContentsImpl::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {
// Browser controls should be synchronised with the scroll state. Therefore,
// they are controlled from the renderer by the main RenderFrame(Host).
GetPrimaryPage().UpdateBrowserControlsState(constraints, current, animate);
GetPrimaryPage().UpdateBrowserControlsState(constraints, current, animate,
offset_tags_info);
}
void WebContentsImpl::SetV8CompileHints(base::ReadOnlySharedMemoryRegion data) {

@ -29,6 +29,7 @@
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "components/download/public/common/download_url_parameters.h"
#include "content/browser/media/audio_stream_monitor.h"
#include "content/browser/media/forwarding_audio_stream_factory.h"
@ -602,9 +603,12 @@ class CONTENT_EXPORT WebContentsImpl
const base::Location& GetCreatorLocation() override;
const std::optional<blink::mojom::PictureInPictureWindowOptions>&
GetPictureInPictureOptions() const override;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info)
override;
void SetV8CompileHints(base::ReadOnlySharedMemoryRegion data) override;
void SetTabSwitchStartTime(base::TimeTicks start_time,
bool destination_is_loaded) override;

@ -12,6 +12,7 @@
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "content/common/input/input_router_config_helper.h"
#include "content/common/input/render_widget_host_input_event_router.h"
#include "content/common/input/render_widget_host_view_input.h"
@ -93,9 +94,12 @@ class UnboundWidgetInputHandler : public blink::mojom::WidgetInputHandler {
request) override {
NOTREACHED_IN_MIGRATION() << "Input request on unbound interface";
}
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override {
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info)
override {
NOTREACHED_IN_MIGRATION() << "Input request on unbound interface";
}
};

@ -25,6 +25,7 @@
#include "base/supports_user_data.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "content/common/content_export.h"
#include "content/public/browser/invalidate_type.h"
@ -1431,9 +1432,12 @@ class WebContents : public PageNavigator,
// Hide or show the browser controls for the given WebContents, based on
// allowed states, desired state and whether the transition should be animated
// or not.
virtual void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) = 0;
virtual void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>&
offset_tags_info) = 0;
// Transmits data to V8CrowdsourcedCompileHintsConsumer in the renderer. The
// data is a model describing which JavaScript functions on the page should be

@ -1225,7 +1225,7 @@ void GpuBenchmarking::SetBrowserControlsShown(bool show) {
cc::BrowserControlsState::kBoth,
show ? cc::BrowserControlsState::kShown
: cc::BrowserControlsState::kHidden,
false);
false, std::nullopt);
}
float GpuBenchmarking::VisualViewportY() {

@ -6,6 +6,7 @@
#include "base/run_loop.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_gesture_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
@ -140,7 +141,8 @@ void MockWidgetInputHandler::GetFrameWidgetInputHandler(
void MockWidgetInputHandler::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {}
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {}
MockWidgetInputHandler::DispatchedMessage::DispatchedMessage(
const std::string& name)

@ -11,6 +11,7 @@
#include <utility>
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/input/input_handler.mojom.h"
@ -276,9 +277,12 @@ class MockWidgetInputHandler : public blink::mojom::WidgetInputHandler {
void GetFrameWidgetInputHandler(
mojo::PendingAssociatedReceiver<blink::mojom::FrameWidgetInputHandler>
interface_request) override;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info)
override;
using MessageVector = std::vector<std::unique_ptr<DispatchedMessage>>;
MessageVector GetAndResetDispatchedMessages();

@ -616,8 +616,8 @@ void WebTestControlHost::PrepareForWebTest(const TestInfo& test_info) {
// TODO(danakj): We no longer run web tests on android, and this is an android
// feature, so maybe this isn't needed anymore.
main_window_->web_contents()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden,
false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden, false,
std::nullopt);
// We did not track the |main_window_| RenderFrameHost during the creation of
// |main_window_|, since we need the pointer value in this class set first. So

@ -5,6 +5,7 @@
module blink.mojom;
import "cc/mojom/browser_controls_state.mojom";
import "cc/mojom/browser_controls_offset_tags_info.mojom";
import "mojo/public/mojom/base/byte_string.mojom";
import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/string16.mojom";
@ -20,6 +21,7 @@ import "services/network/public/mojom/network_types.mojom";
import "services/network/public/mojom/source_location.mojom";
import "services/network/public/mojom/url_loader_completion_status.mojom";
import "services/network/public/mojom/attribution.mojom";
import "services/viz/public/mojom/compositing/offset_tag.mojom";
import "skia/public/mojom/bitmap.mojom";
import "skia/public/mojom/skcolor.mojom";
import "skia/public/mojom/skcolor4f.mojom";
@ -1219,9 +1221,27 @@ interface LocalMainFrame {
// Notifies the renderer whether hiding/showing the browser controls is
// enabled, what the current state should be, and whether or not to
// animate to the proper state.
UpdateBrowserControlsState(cc.mojom.BrowserControlsState constraints,
cc.mojom.BrowserControlsState current,
bool animate);
//
// offset_tags_info consists of OffsetTags, and metadata for creating
// OffsetTagConstraints. It is passed to the renderer and used to tag the
// browser controls scroll offsets in the compositor frame's metadata, with
// the goal of allowing viz to scroll the top controls by applying the
// offset. The slim::Layers for the top controls in the browser must be
// tagged with the same token.
// A zero token is passed when the browser is forcing the controls to be
// shown/hidden. When this happens, the browser process will have removed
// the renderer's OffsetTagDefinition from the associated SurfaceLayer, so
// viz will not look for scroll offsets or OffsetTags in the compositor frame
// metadata anymore. The renderer should also not tag any scroll offsets with
// OffsetTags, as they won't be seen by viz.
// A null token is passed when scrolling top controls is viz is not
// applicable (ex. chromeos, UI elements that overlay on top of chrome,
// tests, etc.)
UpdateBrowserControlsState(
cc.mojom.BrowserControlsState constraints,
cc.mojom.BrowserControlsState current,
bool animate,
cc.mojom.BrowserControlsOffsetTagsInfo? offset_tags_info);
// Transmits data to V8CrowdsourcedCompileHintsConsumer in the renderer. The
// data is a Bloom filter describing which JavaScript functions on the page

@ -4,6 +4,7 @@
module blink.mojom;
import "cc/mojom/browser_controls_offset_tags_info.mojom";
import "cc/mojom/browser_controls_state.mojom";
import "cc/mojom/overscroll_behavior.mojom";
import "cc/mojom/touch_action.mojom";
@ -529,10 +530,9 @@ interface WidgetInputHandler {
GetFrameWidgetInputHandler(
pending_associated_receiver<FrameWidgetInputHandler> interface_request);
// Notifies the renderer whether hiding/showing the browser controls is
// enabled, what the current state should be, and whether or not to
// animate to the proper state.
// see UpdateBrowserControlsState in third_party/blink/public/mojom/frame/frame.mojom for details
UpdateBrowserControlsState(cc.mojom.BrowserControlsState constraints,
cc.mojom.BrowserControlsState current,
bool animate);
bool animate,
cc.mojom.BrowserControlsOffsetTagsInfo? offset_tags_info);
};

@ -1,3 +1,7 @@
include_rules = {
"+cc/input/browser_controls_offset_tags_info.h",
}
specific_include_rules = {
"ad_tracker_test\.cc": [
"+base/run_loop.h",

@ -199,7 +199,7 @@ class BrowserControlsSimTest : public SimTest {
WebView().SetDefaultPageScaleLimits(0.25f, 5);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown,
false);
false, std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(412, 604), 56.f, 50.f, true);
}
@ -857,8 +857,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(StateConstraints)) {
// Setting permitted state should change the content offset to match the
// constraint.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kShown,
false);
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kShown, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(50.f, WebView().GetBrowserControls().ContentOffset());
@ -877,7 +877,7 @@ TEST_F(BrowserControlsSimTest, MAYBE(StateConstraints)) {
// constraint.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kHidden,
false);
false, std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(0, WebView().GetBrowserControls().ContentOffset());
@ -889,7 +889,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(StateConstraints)) {
// Setting permitted state to "both" should not change content offset.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(0, WebView().GetBrowserControls().ContentOffset());
@ -919,19 +920,21 @@ TEST_F(BrowserControlsSimTest, MAYBE(StateConstraints)) {
EXPECT_FLOAT_EQ(0, WebView().GetBrowserControls().ContentOffset());
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(0, WebView().GetBrowserControls().ContentOffset());
// Setting just the constraint should affect the content offset.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
false);
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(0, WebView().GetBrowserControls().ContentOffset());
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(50, WebView().GetBrowserControls().ContentOffset());
}
@ -1015,7 +1018,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false,
std::nullopt);
Compositor().BeginFrame();
Element* abs_pos = GetDocument().getElementById(WebString::FromUTF8("abs"));
@ -1033,8 +1037,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Now lock the controls in a hidden state. The layout and elements should
// resize without a WebView::resize.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
false);
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(200.f, abs_pos->GetBoundingClientRect()->height());
@ -1045,7 +1049,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Unlock the controls, the sizes should change even though the controls are
// still hidden.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(150.f, abs_pos->GetBoundingClientRect()->height());
@ -1055,7 +1060,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Now lock the controls in a shown state.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false,
std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().BeginFrame();
@ -1067,8 +1073,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Shown -> Hidden
WebView().ResizeWithBrowserControls(gfx::Size(400, 400), 100.f, 0, false);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
false);
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(200.f, abs_pos->GetBoundingClientRect()->height());
@ -1079,7 +1085,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
// Go from Unlocked and showing, to locked and hidden but issue the resize
// before the constraint update to check for race issues.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false,
std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().BeginFrame();
ASSERT_EQ(300, GetDocument().GetFrame()->View()->GetLayoutSize().height());
@ -1087,7 +1094,7 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) {
WebView().ResizeWithBrowserControls(gfx::Size(400, 400), 100.f, 0, false);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kHidden,
false);
false, std::nullopt);
Compositor().BeginFrame();
EXPECT_FLOAT_EQ(200.f, abs_pos->GetBoundingClientRect()->height());
@ -1120,7 +1127,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectViewportConstrainedSticky)) {
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false,
std::nullopt);
Compositor().BeginFrame();
Element* sticky_pos =
@ -1139,8 +1147,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectViewportConstrainedSticky)) {
// Now lock the controls in a hidden state. The layout and elements should
// resize without a WebView::resize.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
false);
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_EQ(400, GetDocument().GetFrame()->View()->GetLayoutSize().height());
EXPECT_FLOAT_EQ(400.f, sticky_pos->GetBoundingClientRect()->bottom());
@ -1148,14 +1156,16 @@ TEST_F(BrowserControlsSimTest, MAYBE(AffectViewportConstrainedSticky)) {
// Unlock the controls, the sizes should change even though the controls are
// still hidden.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth, false,
std::nullopt);
Compositor().BeginFrame();
EXPECT_EQ(300, GetDocument().GetFrame()->View()->GetLayoutSize().height());
EXPECT_FLOAT_EQ(400.f, sticky_pos->GetBoundingClientRect()->bottom());
// Now lock the controls in a shown state.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false);
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, false,
std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().BeginFrame();
EXPECT_EQ(300, GetDocument().GetFrame()->View()->GetLayoutSize().height());
@ -1649,7 +1659,8 @@ TEST_F(BrowserControlsSimTest, MAYBE(ViewportUnitsWhenControlsLocked)) {
)HTML");
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown, false,
std::nullopt);
Compositor().BeginFrame();
ASSERT_EQ(1.f, WebView().GetBrowserControls().TopShownRatio());
@ -1663,7 +1674,7 @@ TEST_F(BrowserControlsSimTest, MAYBE(ViewportUnitsWhenControlsLocked)) {
{
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kHidden,
false);
false, std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(400, 400), 100.f, 0, false);
Compositor().BeginFrame();
@ -1685,7 +1696,7 @@ TEST_F(BrowserControlsSimTest, MAYBE(ViewportUnitsWhenControlsLocked)) {
{
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kShown,
false);
false, std::nullopt);
WebView().ResizeWithBrowserControls(gfx::Size(400, 300), 100.f, 0, true);
Compositor().BeginFrame();
@ -1893,12 +1904,12 @@ TEST_F(BrowserControlsSimTest, MixAnimatedAndNonAnimatedUpdateState) {
// Kick off a non-animated clamp to hide the top controls.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
false /* animated */);
false /* animated */, std::nullopt);
// Now kick off an animated one to do the same thing.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kHidden, cc::BrowserControlsState::kBoth,
true /* animated */);
true /* animated */, std::nullopt);
// Advance time. In https://crbug.com/861618, the animation didn't realize
// yet we're already at 0, so it would play the compositor-side up to 80ms,
@ -1941,7 +1952,7 @@ TEST_F(BrowserControlsSimTest, HideAnimated) {
// Kick off an animated hide.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden,
true /* animated */);
true /* animated */, std::nullopt);
Compositor().BeginFrame();
@ -1974,8 +1985,8 @@ TEST_F(BrowserControlsSimTest, ShowAnimated) {
Compositor().BeginFrame();
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden,
false);
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden, false,
std::nullopt);
Compositor().BeginFrame();
@ -1985,7 +1996,7 @@ TEST_F(BrowserControlsSimTest, ShowAnimated) {
// Kick off an animated show.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown,
true /* animated */);
true /* animated */, std::nullopt);
Compositor().BeginFrame();
@ -2041,7 +2052,7 @@ TEST_F(BrowserControlsSimTest, ConstraintDoesntClampRatioInBlink) {
// actually cause the controls to hide when we commit.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kHidden,
false /* animated */);
false /* animated */, std::nullopt);
Compositor().BeginFrame();
EXPECT_EQ(0.f, WebView().GetBrowserControls().TopShownRatio());
@ -2064,7 +2075,7 @@ TEST_F(BrowserControlsSimTest, ConstraintDoesntClampRatioInBlink) {
// actually cause the controls to hide when we commit.
Compositor().LayerTreeHost()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kShown,
false /* animated */);
false /* animated */, std::nullopt);
Compositor().BeginFrame();
EXPECT_EQ(1.f, WebView().GetBrowserControls().TopShownRatio());

@ -8,6 +8,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
@ -1302,7 +1303,8 @@ void LocalFrameMojoHandler::InstallCoopAccessMonitor(
void LocalFrameMojoHandler::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {
DCHECK(frame_->IsOutermostMainFrame());
TRACE_EVENT2("renderer", "LocalFrame::UpdateBrowserControlsState",
"Constraint", static_cast<int>(constraints), "Current",
@ -1310,8 +1312,8 @@ void LocalFrameMojoHandler::UpdateBrowserControlsState(
TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
"animated", animate);
frame_->GetWidgetForLocalRoot()->UpdateBrowserControlsState(constraints,
current, animate);
frame_->GetWidgetForLocalRoot()->UpdateBrowserControlsState(
constraints, current, animate, offset_tags_info);
}
void LocalFrameMojoHandler::SetV8CompileHints(

@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LOCAL_FRAME_MOJO_HANDLER_H_
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/device_posture/device_posture_provider.mojom-blink.h"
#include "third_party/blink/public/mojom/frame/back_forward_cache_controller.mojom-blink.h"
@ -253,9 +254,12 @@ class LocalFrameMojoHandler
network::mojom::blink::CrossOriginOpenerPolicyReporterParamsPtr
coop_reporter_params,
bool is_in_same_virtual_coop_related_group) final;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info)
override;
void SetV8CompileHints(base::ReadOnlySharedMemoryRegion data) override;

@ -42,9 +42,11 @@
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/animation/animation_host.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/trees/compositor_commit_data.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/swap_promise.h"
@ -1901,10 +1903,12 @@ const cc::LayerTreeSettings* WebFrameWidgetImpl::GetLayerTreeSettings() {
void WebFrameWidgetImpl::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) {
DCHECK(View()->does_composite());
widget_base_->LayerTreeHost()->UpdateBrowserControlsState(constraints,
current, animate);
widget_base_->LayerTreeHost()->UpdateBrowserControlsState(
constraints, current, animate, offset_tags_info);
}
void WebFrameWidgetImpl::SetHaveScrollEventHandlers(bool has_handlers) {

@ -35,9 +35,11 @@
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "base/types/pass_key.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/event_listener_properties.h"
#include "cc/input/overscroll_behavior.h"
#include "cc/trees/layer_tree_host.h"
@ -235,9 +237,12 @@ class CORE_EXPORT WebFrameWidgetImpl
void RequestBeginMainFrameNotExpected(bool request) final;
int GetLayerTreeId() final;
const cc::LayerTreeSettings* GetLayerTreeSettings() final;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) final;
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) final;
void SetEventListenerProperties(cc::EventListenerClass,
cc::EventListenerProperties) final;
cc::EventListenerProperties EventListenerProperties(

@ -8,6 +8,8 @@
#include <optional>
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "mojo/public/mojom/base/text_direction.mojom-blink.h"
#include "services/viz/public/mojom/compositing/frame_sink_id.mojom-blink.h"
#include "third_party/blink/public/mojom/input/input_handler.mojom-blink.h"
@ -104,9 +106,12 @@ class PLATFORM_EXPORT FrameWidget {
virtual const cc::LayerTreeSettings* GetLayerTreeSettings() = 0;
// Sets the state of the browser controls. (Used for URL bar animations.)
virtual void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) = 0;
virtual void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) = 0;
// Set or get what event handlers exist in the document contained in the
// WebWidget in order to inform the compositor thread if it is able to handle

@ -20,8 +20,10 @@
#include "base/task/single_thread_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/trace_event/trace_event.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/main_thread_scrolling_reason.h"
#include "cc/metrics/event_metrics.h"
#include "cc/trees/latency_info_swap_promise_monitor.h"
@ -1592,9 +1594,12 @@ void InputHandlerProxy::RequestAnimationForSnapFling() {
void InputHandlerProxy::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) {
DCHECK(input_handler_);
input_handler_->UpdateBrowserControlsState(constraints, current, animate);
input_handler_->UpdateBrowserControlsState(constraints, current, animate,
offset_tags_info);
}
void InputHandlerProxy::FlushQueuedEventsForTesting() {

@ -9,6 +9,8 @@
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "cc/input/input_handler.h"
#include "cc/input/snap_fling_controller.h"
@ -240,9 +242,12 @@ class PLATFORM_EXPORT InputHandlerProxy : public cc::InputHandlerClient,
void ScrollEndForSnapFling(bool did_finish) override;
void RequestAnimationForSnapFling() override;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate);
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info);
bool gesture_scroll_on_impl_thread_for_testing() const {
return handling_gesture_on_impl_thread_;

@ -16,8 +16,10 @@
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/test/trace_event_analyzer.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/main_thread_scrolling_reason.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host_impl.h"
@ -117,9 +119,12 @@ class FakeCompositorDelegateForInput : public cc::CompositorDelegateForInput {
const cc::LayerTreeHostImpl& GetImplDeprecated() const override {
return host_impl_;
}
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override {}
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) override {}
bool HasScrollLinkedAnimation(cc::ElementId for_scroller) const override {
return false;
}
@ -242,10 +247,12 @@ class MockInputHandler : public cc::InputHandler {
void SetDeferBeginMainFrame(bool defer_begin_main_frame) const override {}
MOCK_METHOD3(UpdateBrowserControlsState,
MOCK_METHOD4(UpdateBrowserControlsState,
void(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate));
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info));
private:
bool is_scrolling_root_ = true;
@ -1783,13 +1790,15 @@ TEST_P(InputHandlerProxyTest, TouchMoveBlockingAddedAfterPassiveTouchStart) {
TEST_P(InputHandlerProxyTest, UpdateBrowserControlsState) {
VERIFY_AND_RESET_MOCKS();
EXPECT_CALL(mock_input_handler_,
UpdateBrowserControlsState(cc::BrowserControlsState::kShown,
cc::BrowserControlsState::kBoth, true))
EXPECT_CALL(
mock_input_handler_,
UpdateBrowserControlsState(cc::BrowserControlsState::kShown,
cc::BrowserControlsState::kBoth, true, _))
.Times(1);
input_handler_->UpdateBrowserControlsState(
cc::BrowserControlsState::kShown, cc::BrowserControlsState::kBoth, true);
input_handler_->UpdateBrowserControlsState(cc::BrowserControlsState::kShown,
cc::BrowserControlsState::kBoth,
true, std::nullopt);
VERIFY_AND_RESET_MOCKS();
}

@ -220,9 +220,10 @@ void WidgetInputHandlerImpl::GetFrameWidgetInputHandler(
void WidgetInputHandlerImpl::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) {
input_handler_manager_->UpdateBrowserControlsState(constraints, current,
animate);
animate, offset_tags_info);
}
void WidgetInputHandlerImpl::RunOnMainThread(base::OnceClosure closure) {

@ -8,6 +8,7 @@
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/input/browser_controls_state.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/direct_receiver.h"
@ -79,9 +80,12 @@ class WidgetInputHandlerImpl : public mojom::blink::WidgetInputHandler {
void GetFrameWidgetInputHandler(
mojo::PendingAssociatedReceiver<mojom::blink::FrameWidgetInputHandler>
interface_request) override;
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) override;
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info)
override;
void InputWasProcessed();

@ -15,8 +15,10 @@
#include "base/notreached.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "cc/metrics/event_metrics.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/paint_holding_reason.h"
@ -1167,14 +1169,16 @@ void WidgetInputHandlerManager::ClearClient() {
void WidgetInputHandlerManager::UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate) {
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info) {
if (!input_handler_proxy_) {
return;
}
DCHECK(InputThreadTaskRunner()->BelongsToCurrentThread());
input_handler_proxy_->UpdateBrowserControlsState(constraints, current,
animate);
animate, offset_tags_info);
}
void WidgetInputHandlerManager::FlushCompositorQueueForTesting() {

@ -10,6 +10,7 @@
#include <optional>
#include "base/task/single_thread_task_runner.h"
#include "base/types/optional_ref.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_state.h"
#include "cc/trees/paint_holding_reason.h"
@ -172,9 +173,12 @@ class PLATFORM_EXPORT WidgetInputHandlerManager final
void ClearClient();
void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate);
void UpdateBrowserControlsState(
cc::BrowserControlsState constraints,
cc::BrowserControlsState current,
bool animate,
base::optional_ref<const cc::BrowserControlsOffsetTagsInfo>
offset_tags_info);
MainThreadEventQueue* input_event_queue() { return input_event_queue_.get(); }

@ -529,6 +529,7 @@ _CONFIG = [
'cc::kPixelsPerLineStep',
'cc::kMinFractionToStepWhenPaging',
'cc::kPercentDeltaForDirectionalScroll',
'cc::BrowserControlsOffsetTagsInfo',
'cc::MainThreadScrollingReason',
'cc::ManipulationInfo',
'cc::ScrollSnapAlign',