12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249 |
- // Copyright 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "cc/input/input_handler.h"
- #include <utility>
- #include <vector>
- #include "base/notreached.h"
- #include "build/build_config.h"
- #include "cc/base/features.h"
- #include "cc/input/scroll_elasticity_helper.h"
- #include "cc/input/scroll_utils.h"
- #include "cc/input/scrollbar_controller.h"
- #include "cc/input/snap_selection_strategy.h"
- #include "cc/layers/viewport.h"
- #include "cc/trees/compositor_commit_data.h"
- #include "cc/trees/latency_info_swap_promise_monitor.h"
- #include "cc/trees/layer_tree_host_impl.h"
- #include "cc/trees/layer_tree_impl.h"
- #include "cc/trees/layer_tree_settings.h"
- #include "cc/trees/property_tree.h"
- #include "cc/trees/scroll_node.h"
- #include "ui/gfx/geometry/point.h"
- #include "ui/gfx/geometry/point_conversions.h"
- #include "ui/gfx/geometry/point_f.h"
- #include "ui/gfx/geometry/vector2d_f.h"
- namespace cc {
- namespace {
- enum SlowScrollMetricThread { MAIN_THREAD, CC_THREAD };
- void RecordCompositorSlowScrollMetric(ui::ScrollInputType type,
- SlowScrollMetricThread scroll_thread) {
- bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD);
- if (type == ui::ScrollInputType::kWheel) {
- UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread",
- scroll_on_main_thread);
- } else if (type == ui::ScrollInputType::kTouchscreen) {
- UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread",
- scroll_on_main_thread);
- }
- }
- } // namespace
- InputHandlerCommitData::InputHandlerCommitData() = default;
- InputHandlerCommitData::~InputHandlerCommitData() = default;
- // static
- base::WeakPtr<InputHandler> InputHandler::Create(
- CompositorDelegateForInput& compositor_delegate) {
- auto input_handler = std::make_unique<InputHandler>(compositor_delegate);
- base::WeakPtr<InputHandler> input_handler_weak = input_handler->AsWeakPtr();
- compositor_delegate.BindToInputHandler(std::move(input_handler));
- return input_handler_weak;
- }
- InputHandler::InputHandler(CompositorDelegateForInput& compositor_delegate)
- : compositor_delegate_(compositor_delegate),
- scrollbar_controller_(std::make_unique<ScrollbarController>(
- &compositor_delegate_.GetImplDeprecated())) {}
- InputHandler::~InputHandler() = default;
- //
- // =========== InputHandler Interface
- //
- base::WeakPtr<InputHandler> InputHandler::AsWeakPtr() const {
- return weak_factory_.GetWeakPtr();
- }
- void InputHandler::BindToClient(InputHandlerClient* client) {
- DCHECK(input_handler_client_ == nullptr);
- input_handler_client_ = client;
- input_handler_client_->SetPrefersReducedMotion(prefers_reduced_motion_);
- }
- InputHandler::ScrollStatus InputHandler::ScrollBegin(ScrollState* scroll_state,
- ui::ScrollInputType type) {
- DCHECK(scroll_state);
- DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
- InputHandler::ScrollStatus scroll_status;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollingOnMain;
- TRACE_EVENT0("cc", "InputHandler::ScrollBegin");
- // If this ScrollBegin is non-animated then ensure we cancel any ongoing
- // animated scrolls.
- // TODO(bokan): This preserves existing behavior when we had diverging
- // paths for animated and non-animated scrolls but we should probably
- // decide when it best makes sense to cancel a scroll animation (maybe
- // ScrollBy is a better place to do it).
- if (scroll_state->delta_granularity() ==
- ui::ScrollGranularity::kScrollByPrecisePixel) {
- compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ScrollAnimationAbort();
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- }
- if (CurrentlyScrollingNode() && type == latched_scroll_type_) {
- // It's possible we haven't yet cleared the CurrentlyScrollingNode if we
- // received a GSE but we're still animating the last scroll. If that's the
- // case, we'll simply un-defer the GSE and continue latching to the same
- // node.
- DCHECK(deferred_scroll_end_);
- deferred_scroll_end_ = false;
- return scroll_status;
- }
- ScrollNode* scrolling_node = nullptr;
- bool scroll_on_main_thread = false;
- // TODO(bokan): ClearCurrentlyScrollingNode shouldn't happen in ScrollBegin,
- // this should only happen in ScrollEnd. We should DCHECK here that the state
- // is cleared instead. https://crbug.com/1016229
- ClearCurrentlyScrollingNode();
- ElementId target_element_id = scroll_state->target_element_id();
- ScrollTree& scroll_tree = GetScrollTree();
- bool unification_enabled =
- base::FeatureList::IsEnabled(features::kScrollUnification);
- if (target_element_id && !scroll_state->is_main_thread_hit_tested()) {
- TRACE_EVENT_INSTANT0("cc", "Latched scroll node provided",
- TRACE_EVENT_SCOPE_THREAD);
- // If the caller passed in an element_id we can skip all the hit-testing
- // bits and provide a node straight-away.
- scrolling_node = scroll_tree.FindNodeFromElementId(target_element_id);
- // In unified scrolling, if we found a node we get to scroll it.
- if (!unification_enabled) {
- // We still need to confirm the targeted node exists and can scroll on
- // the compositor.
- if (scrolling_node) {
- scroll_status = TryScroll(scroll_tree, scrolling_node);
- if (IsMainThreadScrolling(scroll_status, scrolling_node))
- scroll_on_main_thread = true;
- }
- }
- } else {
- ScrollNode* starting_node = nullptr;
- if (target_element_id) {
- TRACE_EVENT_INSTANT0("cc", "Unlatched scroll node provided",
- TRACE_EVENT_SCOPE_THREAD);
- // We had an element id but we should still perform the walk up the
- // scroll tree from the targeted node to latch to a scroller that can
- // scroll in the given direction. This mode is only used when scroll
- // unification is enabled and the targeted scroller comes back from a
- // main thread hit test.
- DCHECK(scroll_state->data()->is_main_thread_hit_tested);
- DCHECK(unification_enabled);
- starting_node = scroll_tree.FindNodeFromElementId(target_element_id);
- if (!starting_node) {
- // The main thread sent us an element_id that the compositor doesn't
- // have a scroll node for. This can happen in some racy conditions, a
- // freshly created scroller hasn't yet been committed or a
- // scroller-destroying commit beats the hit test back to the compositor
- // thread. However, these cases shouldn't be user perceptible.
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNoScrollingLayer;
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- return scroll_status;
- }
- } else { // !target_element_id
- TRACE_EVENT_INSTANT0("cc", "Hit Testing for ScrollNode",
- TRACE_EVENT_SCOPE_THREAD);
- gfx::Point viewport_point(scroll_state->position_x(),
- scroll_state->position_y());
- gfx::PointF device_viewport_point =
- gfx::ScalePoint(gfx::PointF(viewport_point),
- compositor_delegate_.DeviceScaleFactor());
- if (unification_enabled) {
- if (scroll_state->data()->is_main_thread_hit_tested) {
- // The client should have discarded the scroll when the hit test came
- // back with an invalid element id. If we somehow get here, we should
- // drop the scroll as continuing could cause us to infinitely bounce
- // back and forth between here and hit testing on the main thread.
- NOTREACHED();
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNoScrollingLayer;
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- return scroll_status;
- }
- // Touch dragging the scrollbar requires falling back to main-thread
- // scrolling.
- // TODO(bokan): This could be trivially handled in the compositor by
- // the new ScrollbarController and should be removed.
- {
- LayerImpl* first_scrolling_layer_or_scrollbar =
- ActiveTree().FindFirstScrollingLayerOrScrollbarThatIsHitByPoint(
- device_viewport_point);
- if (IsTouchDraggingScrollbar(first_scrolling_layer_or_scrollbar,
- type)) {
- TRACE_EVENT_INSTANT0("cc", "Scrollbar Scrolling",
- TRACE_EVENT_SCOPE_THREAD);
- scroll_status.thread =
- InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kScrollbarScrolling;
- return scroll_status;
- }
- }
- ScrollHitTestResult scroll_hit_test =
- HitTestScrollNode(device_viewport_point);
- if (!scroll_hit_test.hit_test_successful) {
- // This result tells the client that the compositor doesn't have
- // enough information to target this scroll. The client should
- // perform a hit test in Blink and call this method again, with the
- // ElementId of the hit-tested scroll node.
- TRACE_EVENT_INSTANT0("cc", "Request Main Thread Hit Test",
- TRACE_EVENT_SCOPE_THREAD);
- scroll_status.thread =
- InputHandler::ScrollThread::SCROLL_ON_IMPL_THREAD;
- scroll_status.needs_main_thread_hit_test = true;
- return scroll_status;
- }
- starting_node = scroll_hit_test.scroll_node;
- } else { // !unification_enabled
- LayerImpl* layer_impl =
- ActiveTree().FindLayerThatIsHitByPoint(device_viewport_point);
- if (layer_impl) {
- LayerImpl* first_scrolling_layer_or_scrollbar =
- ActiveTree().FindFirstScrollingLayerOrScrollbarThatIsHitByPoint(
- device_viewport_point);
- // Touch dragging the scrollbar requires falling back to main-thread
- // scrolling.
- if (IsTouchDraggingScrollbar(first_scrolling_layer_or_scrollbar,
- type)) {
- TRACE_EVENT_INSTANT0("cc", "Scrollbar Scrolling",
- TRACE_EVENT_SCOPE_THREAD);
- scroll_status.thread =
- InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kScrollbarScrolling;
- return scroll_status;
- } else if (!IsInitialScrollHitTestReliable(
- layer_impl, first_scrolling_layer_or_scrollbar)) {
- TRACE_EVENT_INSTANT0("cc", "Failed Hit Test",
- TRACE_EVENT_SCOPE_THREAD);
- scroll_status.thread =
- InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kFailedHitTest;
- return scroll_status;
- }
- }
- starting_node = FindScrollNodeForCompositedScrolling(
- device_viewport_point, layer_impl, &scroll_on_main_thread,
- &scroll_status.main_thread_scrolling_reasons);
- }
- }
- // The above finds the ScrollNode that's hit by the given point but we
- // still need to walk up the scroll tree looking for the first node that
- // can consume delta from the scroll state.
- scrolling_node = FindNodeToLatch(scroll_state, starting_node, type);
- }
- if (scroll_on_main_thread) {
- // Under scroll unification we can request a main thread hit test, but we
- // should never send scrolls to the main thread.
- DCHECK(!unification_enabled);
- RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- return scroll_status;
- } else if (!scrolling_node) {
- // TODO(crbug.com/1155663): Make sure to set main_thread_scrolling_reasons
- // only when ScrollStatus.thread is set to
- // InputHander::ScrollThread::SCROLL_ON_MAIN_THREAD
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNoScrollingLayer;
- if (compositor_delegate_.GetSettings().is_for_embedded_frame) {
- // OOPIFs or fenced frames never have a viewport scroll node so if we
- // can't scroll we need to be bubble up to the parent frame. This happens
- // by returning SCROLL_IGNORED.
- TRACE_EVENT_INSTANT0("cc",
- "Ignored - No ScrollNode (OOPIF or FencedFrame)",
- TRACE_EVENT_SCOPE_THREAD);
- } else {
- // If we didn't hit a layer above we'd usually fallback to the
- // viewport scroll node. However, there may not be one if a scroll
- // is received before the root layer has been attached. Chrome now
- // drops input until the first commit is received so this probably
- // can't happen in a typical browser session but there may still be
- // configurations where input is allowed prior to a commit.
- TRACE_EVENT_INSTANT0("cc", "Ignored - No ScrollNode",
- TRACE_EVENT_SCOPE_THREAD);
- }
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- return scroll_status;
- }
- DCHECK_EQ(scroll_status.main_thread_scrolling_reasons,
- MainThreadScrollingReason::kNotScrollingOnMain);
- DCHECK_EQ(scroll_status.thread,
- InputHandler::ScrollThread::SCROLL_ON_IMPL_THREAD);
- DCHECK(scrolling_node);
- ActiveTree().SetCurrentlyScrollingNode(scrolling_node);
- if (unification_enabled)
- scroll_status.main_thread_repaint_reasons =
- scroll_tree.GetMainThreadRepaintReasons(*scrolling_node);
- DidLatchToScroller(*scroll_state, type);
- // If the viewport is scrolling and it cannot consume any delta hints, the
- // scroll event will need to get bubbled if the viewport is for a guest or
- // oopif.
- if (GetViewport().ShouldScroll(*CurrentlyScrollingNode()) &&
- !GetViewport().CanScroll(*CurrentlyScrollingNode(), *scroll_state)) {
- // TODO(crbug.com/1155758): This is a temporary workaround for GuestViews
- // as they create viewport nodes and want to bubble scroll if the
- // viewport cannot scroll in the given delta directions. There should be
- // a parameter to ThreadInputHandler to specify whether unused delta is
- // consumed by the viewport or bubbles to the parent.
- scroll_status.viewport_cannot_scroll = true;
- }
- return scroll_status;
- }
- InputHandler::ScrollStatus InputHandler::RootScrollBegin(
- ScrollState* scroll_state,
- ui::ScrollInputType type) {
- TRACE_EVENT0("cc", "InputHandler::RootScrollBegin");
- if (!OuterViewportScrollNode()) {
- InputHandler::ScrollStatus scroll_status;
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNoScrollingLayer;
- return scroll_status;
- }
- scroll_state->data()->set_current_native_scrolling_element(
- OuterViewportScrollNode()->element_id);
- InputHandler::ScrollStatus scroll_status = ScrollBegin(scroll_state, type);
- // Since we provided an ElementId, there should never be a need to perform a
- // hit test.
- DCHECK(!scroll_status.needs_main_thread_hit_test);
- return scroll_status;
- }
- InputHandlerScrollResult InputHandler::ScrollUpdate(
- ScrollState* scroll_state,
- base::TimeDelta delayed_by) {
- DCHECK(scroll_state);
- // The current_native_scrolling_element should only be set for ScrollBegin.
- DCHECK(!scroll_state->data()->current_native_scrolling_element());
- TRACE_EVENT2("cc", "InputHandler::ScrollUpdate", "dx",
- scroll_state->delta_x(), "dy", scroll_state->delta_y());
- if (!CurrentlyScrollingNode())
- return InputHandlerScrollResult();
- const ScrollNode& scroll_node = *CurrentlyScrollingNode();
- last_scroll_update_state_ = *scroll_state;
- // Snap on update if interacting with the scrollbar track or arrow buttons.
- // Interactions with the scrollbar thumb have kScrollByPrecisePixel
- // granularity.
- if (scroll_state->is_scrollbar_interaction() &&
- scroll_state->delta_granularity() !=
- ui::ScrollGranularity::kScrollByPrecisePixel) {
- AdjustScrollDeltaForScrollbarSnap(scroll_state);
- }
- gfx::Vector2dF resolvedScrollDelta = ResolveScrollGranularityToPixels(
- scroll_node,
- gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y()),
- scroll_state->delta_granularity());
- scroll_state->data()->delta_x = resolvedScrollDelta.x();
- scroll_state->data()->delta_y = resolvedScrollDelta.y();
- // The decision of whether or not we'll animate a scroll comes down to
- // whether the granularity is specified in precise pixels or not. Thus we
- // need to preserve a precise granularity if that's what was specified; all
- // others are animated and so can be resolved to regular pixels.
- if (scroll_state->delta_granularity() !=
- ui::ScrollGranularity::kScrollByPrecisePixel) {
- scroll_state->data()->delta_granularity =
- ui::ScrollGranularity::kScrollByPixel;
- }
- compositor_delegate_.AccumulateScrollDeltaForTracing(
- gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y()));
- compositor_delegate_.WillScrollContent(scroll_node.element_id);
- float initial_top_controls_offset = compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->ControlsTopOffset();
- ScrollLatchedScroller(scroll_state, delayed_by);
- bool did_scroll_x = scroll_state->caused_scroll_x();
- bool did_scroll_y = scroll_state->caused_scroll_y();
- did_scroll_x_for_scroll_gesture_ |= did_scroll_x;
- did_scroll_y_for_scroll_gesture_ |= did_scroll_y;
- delta_consumed_for_scroll_gesture_ |=
- scroll_state->delta_consumed_for_scroll_sequence();
- bool did_scroll_content = did_scroll_x || did_scroll_y;
- if (did_scroll_content) {
- bool is_animated_scroll = ShouldAnimateScroll(*scroll_state);
- compositor_delegate_.DidScrollContent(scroll_node.element_id,
- is_animated_scroll);
- } else {
- overscroll_delta_for_main_thread_ +=
- gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y());
- }
- SetNeedsCommit();
- // Scrolling along an axis resets accumulated root overscroll for that axis.
- if (did_scroll_x)
- accumulated_root_overscroll_.set_x(0);
- if (did_scroll_y)
- accumulated_root_overscroll_.set_y(0);
- gfx::Vector2dF unused_root_delta;
- if (GetViewport().ShouldScroll(scroll_node)) {
- unused_root_delta =
- gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y());
- }
- // When inner viewport is unscrollable, disable overscrolls.
- if (auto* inner_viewport_scroll_node = InnerViewportScrollNode()) {
- unused_root_delta =
- UserScrollableDelta(*inner_viewport_scroll_node, unused_root_delta);
- }
- accumulated_root_overscroll_ += unused_root_delta;
- bool did_scroll_top_controls =
- initial_top_controls_offset != compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->ControlsTopOffset();
- InputHandlerScrollResult scroll_result;
- scroll_result.did_scroll = did_scroll_content || did_scroll_top_controls;
- scroll_result.did_overscroll_root = !unused_root_delta.IsZero();
- scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_;
- scroll_result.unused_scroll_delta = unused_root_delta;
- scroll_result.overscroll_behavior =
- scroll_state->is_scroll_chain_cut()
- ? OverscrollBehavior(OverscrollBehavior::Type::kNone)
- : ActiveTree().overscroll_behavior();
- if (scroll_result.did_scroll) {
- // Scrolling can change the root scroll offset, so inform the synchronous
- // input handler.
- UpdateRootLayerStateForSynchronousInputHandler();
- }
- scroll_result.current_visual_offset = GetVisualScrollOffset(scroll_node);
- float scale_factor = ActiveTree().page_scale_factor_for_scroll();
- scroll_result.current_visual_offset.Scale(scale_factor);
- if (base::FeatureList::IsEnabled(features::kScrollUnification) &&
- !GetScrollTree().CanRealizeScrollsOnCompositor(scroll_node)) {
- scroll_result.needs_main_thread_repaint = true;
- }
- // Run animations which need to respond to updated scroll offset.
- compositor_delegate_.GetImplDeprecated().mutator_host()->TickScrollAnimations(
- compositor_delegate_.GetImplDeprecated()
- .CurrentBeginFrameArgs()
- .frame_time,
- GetScrollTree());
- return scroll_result;
- }
- void InputHandler::AdjustScrollDeltaForScrollbarSnap(
- ScrollState* scroll_state) {
- ScrollNode* scroll_node = CurrentlyScrollingNode();
- if (!scroll_node || !scroll_node->snap_container_data)
- return;
- // Ideally, scrollbar track and arrow interactions would have
- // kScrollByPage and kScrollByLine, respectively. Currently, both have
- // kScrollByPixel granularity.
- // TODO(crbug.com/959441): Update snap strategy once the granularity is
- // properly set. Currently, track and arrow scrolls both use a direction
- // strategy; however, the track should be using an "end and direction"
- // strategy.
- gfx::PointF current_position = GetVisualScrollOffset(*scroll_node);
- const SnapContainerData& data = scroll_node->snap_container_data.value();
- std::unique_ptr<SnapSelectionStrategy> strategy =
- SnapSelectionStrategy::CreateForDirection(
- current_position,
- gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y()),
- true);
- gfx::PointF snap_position;
- TargetSnapAreaElementIds snap_target_ids;
- if (!data.FindSnapPosition(*strategy, &snap_position, &snap_target_ids))
- return;
- scroll_state->data()->delta_x = snap_position.x() - current_position.x();
- scroll_state->data()->delta_y = snap_position.y() - current_position.y();
- }
- void InputHandler::ScrollEnd(bool should_snap) {
- scrollbar_controller_->ResetState();
- if (!CurrentlyScrollingNode())
- return;
- // Note that if we deferred the scroll end then we should not snap. We will
- // snap once we deliver the deferred scroll end.
- if (compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ImplOnlyScrollAnimatingElement()) {
- DCHECK(!deferred_scroll_end_);
- deferred_scroll_end_ = true;
- return;
- }
- if (should_snap && SnapAtScrollEnd(SnapReason::kGestureScrollEnd)) {
- deferred_scroll_end_ = true;
- return;
- }
- DCHECK(latched_scroll_type_.has_value());
- compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->ScrollEnd();
- ClearCurrentlyScrollingNode();
- deferred_scroll_end_ = false;
- scroll_gesture_did_end_ = true;
- SetNeedsCommit();
- }
- void InputHandler::RecordScrollBegin(
- ui::ScrollInputType input_type,
- ScrollBeginThreadState scroll_start_state) {
- auto tracker_type = GetTrackerTypeForScroll(input_type);
- DCHECK_NE(tracker_type, FrameSequenceTrackerType::kMaxType);
- // The main-thread is the 'scrolling thread' if:
- // (1) the scroll is driven by the main thread, or
- // (2) the scroll is driven by the compositor, but blocked on the main
- // thread.
- // Otherwise, the compositor-thread is the 'scrolling thread'.
- // TODO(crbug.com/1060712): We should also count 'main thread' as the
- // 'scrolling thread' if the layer being scrolled has scroll-event handlers.
- FrameInfo::SmoothEffectDrivingThread scrolling_thread;
- switch (scroll_start_state) {
- case ScrollBeginThreadState::kScrollingOnCompositor:
- scrolling_thread = FrameInfo::SmoothEffectDrivingThread::kCompositor;
- break;
- case ScrollBeginThreadState::kScrollingOnMain:
- case ScrollBeginThreadState::kScrollingOnCompositorBlockedOnMain:
- scrolling_thread = FrameInfo::SmoothEffectDrivingThread::kMain;
- break;
- }
- compositor_delegate_.GetImplDeprecated().frame_trackers().StartScrollSequence(
- tracker_type, scrolling_thread);
- }
- void InputHandler::RecordScrollEnd(ui::ScrollInputType input_type) {
- compositor_delegate_.GetImplDeprecated().frame_trackers().StopSequence(
- GetTrackerTypeForScroll(input_type));
- }
- InputHandlerPointerResult InputHandler::MouseMoveAt(
- const gfx::Point& viewport_point) {
- InputHandlerPointerResult result;
- if (compositor_delegate_.GetSettings()
- .compositor_threaded_scrollbar_scrolling) {
- result =
- scrollbar_controller_->HandlePointerMove(gfx::PointF(viewport_point));
- }
- // Early out if there are no animation controllers and avoid the hit test.
- // This happens on platforms without animated scrollbars.
- if (!compositor_delegate_.HasAnimatedScrollbars())
- return result;
- gfx::PointF device_viewport_point = gfx::ScalePoint(
- gfx::PointF(viewport_point), compositor_delegate_.DeviceScaleFactor());
- ScrollHitTestResult hit_test = HitTestScrollNode(device_viewport_point);
- ScrollNode* scroll_node = hit_test.scroll_node;
- // The hit test can fail in some cases, e.g. we don't know if a region of a
- // squashed layer has content or is empty.
- if (!hit_test.hit_test_successful || !scroll_node)
- return result;
- // Scrollbars for the viewport are registered with the outer viewport layer.
- if (scroll_node->scrolls_inner_viewport)
- scroll_node = OuterViewportScrollNode();
- ElementId scroll_element_id = scroll_node->element_id;
- ScrollbarAnimationController* new_animation_controller =
- compositor_delegate_.GetImplDeprecated()
- .ScrollbarAnimationControllerForElementId(scroll_element_id);
- if (scroll_element_id != scroll_element_id_mouse_currently_over_) {
- ScrollbarAnimationController* old_animation_controller =
- compositor_delegate_.GetImplDeprecated()
- .ScrollbarAnimationControllerForElementId(
- scroll_element_id_mouse_currently_over_);
- if (old_animation_controller)
- old_animation_controller->DidMouseLeave();
- scroll_element_id_mouse_currently_over_ = scroll_element_id;
- }
- if (!new_animation_controller)
- return result;
- new_animation_controller->DidMouseMove(device_viewport_point);
- return result;
- }
- PointerResultType InputHandler::HitTest(const gfx::PointF& viewport_point) {
- return compositor_delegate_.GetSettings()
- .compositor_threaded_scrollbar_scrolling
- ? scrollbar_controller_->HitTest(viewport_point)
- : PointerResultType::kUnhandled;
- }
- InputHandlerPointerResult InputHandler::MouseDown(
- const gfx::PointF& viewport_point,
- bool shift_modifier) {
- ScrollbarAnimationController* animation_controller =
- compositor_delegate_.GetImplDeprecated()
- .ScrollbarAnimationControllerForElementId(
- scroll_element_id_mouse_currently_over_);
- if (animation_controller) {
- animation_controller->DidMouseDown();
- scroll_element_id_mouse_currently_captured_ =
- scroll_element_id_mouse_currently_over_;
- }
- InputHandlerPointerResult result;
- if (compositor_delegate_.GetSettings()
- .compositor_threaded_scrollbar_scrolling) {
- result = scrollbar_controller_->HandlePointerDown(viewport_point,
- shift_modifier);
- }
- return result;
- }
- InputHandlerPointerResult InputHandler::MouseUp(
- const gfx::PointF& viewport_point) {
- if (scroll_element_id_mouse_currently_captured_) {
- ScrollbarAnimationController* animation_controller =
- compositor_delegate_.GetImplDeprecated()
- .ScrollbarAnimationControllerForElementId(
- scroll_element_id_mouse_currently_captured_);
- scroll_element_id_mouse_currently_captured_ = ElementId();
- if (animation_controller)
- animation_controller->DidMouseUp();
- }
- InputHandlerPointerResult result;
- if (compositor_delegate_.GetSettings()
- .compositor_threaded_scrollbar_scrolling)
- result = scrollbar_controller_->HandlePointerUp(viewport_point);
- return result;
- }
- void InputHandler::MouseLeave() {
- compositor_delegate_.DidMouseLeave();
- scroll_element_id_mouse_currently_over_ = ElementId();
- }
- ElementId InputHandler::FindFrameElementIdAtPoint(
- const gfx::PointF& viewport_point) {
- gfx::PointF device_viewport_point = gfx::ScalePoint(
- gfx::PointF(viewport_point), compositor_delegate_.DeviceScaleFactor());
- return ActiveTree().FindFrameElementIdAtPoint(device_viewport_point);
- }
- void InputHandler::RequestUpdateForSynchronousInputHandler() {
- UpdateRootLayerStateForSynchronousInputHandler();
- }
- void InputHandler::SetSynchronousInputHandlerRootScrollOffset(
- const gfx::PointF& root_content_offset) {
- TRACE_EVENT2("cc", "InputHandler::SetSynchronousInputHandlerRootScrollOffset",
- "offset_x", root_content_offset.x(), "offset_y",
- root_content_offset.y());
- gfx::Vector2dF physical_delta =
- root_content_offset - GetViewport().TotalScrollOffset();
- physical_delta.Scale(ActiveTree().page_scale_factor_for_scroll());
- bool changed = !GetViewport()
- .ScrollBy(physical_delta,
- /*viewport_point=*/gfx::Point(),
- /*is_direct_manipulation=*/false,
- /*affect_browser_controls=*/false,
- /*scroll_outer_viewport=*/true)
- .consumed_delta.IsZero();
- if (!changed)
- return;
- compositor_delegate_.DidScrollContent(OuterViewportScrollNode()->element_id,
- /*is_animated_scroll=*/false);
- SetNeedsCommit();
- // After applying the synchronous input handler's scroll offset, tell it what
- // we ended up with.
- UpdateRootLayerStateForSynchronousInputHandler();
- compositor_delegate_.SetNeedsFullViewportRedraw();
- }
- void InputHandler::PinchGestureBegin(const gfx::Point& anchor,
- ui::ScrollInputType source) {
- DCHECK(source == ui::ScrollInputType::kTouchscreen ||
- source == ui::ScrollInputType::kWheel);
- pinch_gesture_active_ = true;
- pinch_gesture_end_should_clear_scrolling_node_ = !CurrentlyScrollingNode();
- TRACE_EVENT_INSTANT1("cc", "SetCurrentlyScrollingNode PinchGestureBegin",
- TRACE_EVENT_SCOPE_THREAD, "isNull",
- OuterViewportScrollNode() ? false : true);
- // Some unit tests don't setup viewport scroll nodes but do initiate a pinch
- // zoom gesture. Ideally, those tests should either create the viewport
- // scroll nodes or avoid simulating a pinch gesture.
- if (OuterViewportScrollNode()) {
- ActiveTree().SetCurrentlyScrollingNode(OuterViewportScrollNode());
- ScrollStateData scroll_state_data;
- scroll_state_data.position_x = anchor.x();
- scroll_state_data.position_y = anchor.y();
- scroll_state_data.is_beginning = true;
- scroll_state_data.delta_granularity =
- ui::ScrollGranularity::kScrollByPrecisePixel;
- scroll_state_data.is_direct_manipulation =
- source == ui::ScrollInputType::kTouchscreen;
- ScrollState state(scroll_state_data);
- DidLatchToScroller(state, source);
- }
- compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->PinchBegin();
- compositor_delegate_.DidStartPinchZoom();
- }
- void InputHandler::PinchGestureUpdate(float magnify_delta,
- const gfx::Point& anchor) {
- TRACE_EVENT0("cc", "InputHandler::PinchGestureUpdate");
- if (!InnerViewportScrollNode())
- return;
- has_pinch_zoomed_ = true;
- GetViewport().PinchUpdate(magnify_delta, anchor);
- SetNeedsCommit();
- compositor_delegate_.DidUpdatePinchZoom();
- // Pinching can change the root scroll offset, so inform the synchronous input
- // handler.
- UpdateRootLayerStateForSynchronousInputHandler();
- }
- void InputHandler::PinchGestureEnd(const gfx::Point& anchor) {
- // Some tests create a pinch gesture without creating a viewport scroll node.
- // In those cases, PinchGestureBegin will not latch to a scroll node.
- DCHECK(latched_scroll_type_.has_value() || !CurrentlyScrollingNode());
- bool snap_to_min = latched_scroll_type_.has_value() &&
- latched_scroll_type_ == ui::ScrollInputType::kWheel;
- pinch_gesture_active_ = false;
- if (pinch_gesture_end_should_clear_scrolling_node_) {
- pinch_gesture_end_should_clear_scrolling_node_ = false;
- ClearCurrentlyScrollingNode();
- }
- GetViewport().PinchEnd(anchor, snap_to_min);
- compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->PinchEnd();
- SetNeedsCommit();
- compositor_delegate_.DidEndPinchZoom();
- }
- void InputHandler::SetNeedsAnimateInput() {
- compositor_delegate_.GetImplDeprecated().SetNeedsAnimateInput();
- }
- bool InputHandler::IsCurrentlyScrollingViewport() const {
- auto* node = CurrentlyScrollingNode();
- if (!node)
- return false;
- return GetViewport().ShouldScroll(*node);
- }
- EventListenerProperties InputHandler::GetEventListenerProperties(
- EventListenerClass event_class) const {
- return ActiveTree().event_listener_properties(event_class);
- }
- bool InputHandler::HasBlockingWheelEventHandlerAt(
- const gfx::Point& viewport_point) const {
- gfx::PointF device_viewport_point = gfx::ScalePoint(
- gfx::PointF(viewport_point), compositor_delegate_.DeviceScaleFactor());
- LayerImpl* layer_impl_with_wheel_event_handler =
- ActiveTree().FindLayerThatIsHitByPointInWheelEventHandlerRegion(
- device_viewport_point);
- return layer_impl_with_wheel_event_handler;
- }
- InputHandler::TouchStartOrMoveEventListenerType
- InputHandler::EventListenerTypeForTouchStartOrMoveAt(
- const gfx::Point& viewport_point,
- TouchAction* out_touch_action) {
- gfx::PointF device_viewport_point = gfx::ScalePoint(
- gfx::PointF(viewport_point), compositor_delegate_.DeviceScaleFactor());
- LayerImpl* layer_impl_with_touch_handler =
- ActiveTree().FindLayerThatIsHitByPointInTouchHandlerRegion(
- device_viewport_point);
- if (layer_impl_with_touch_handler == nullptr) {
- if (out_touch_action)
- *out_touch_action = TouchAction::kAuto;
- return InputHandler::TouchStartOrMoveEventListenerType::NO_HANDLER;
- }
- if (out_touch_action) {
- gfx::Transform layer_screen_space_transform =
- layer_impl_with_touch_handler->ScreenSpaceTransform();
- gfx::Transform inverse_layer_screen_space(
- gfx::Transform::kSkipInitialization);
- bool can_be_inversed =
- layer_screen_space_transform.GetInverse(&inverse_layer_screen_space);
- // Getting here indicates that |layer_impl_with_touch_handler| is non-null,
- // which means that the |hit| in FindClosestMatchingLayer() is true, which
- // indicates that the inverse is available.
- DCHECK(can_be_inversed);
- bool clipped = false;
- gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
- inverse_layer_screen_space, device_viewport_point, &clipped);
- gfx::PointF hit_test_point_in_layer_space =
- gfx::PointF(planar_point.x(), planar_point.y());
- const auto& region = layer_impl_with_touch_handler->touch_action_region();
- gfx::Point point = gfx::ToRoundedPoint(hit_test_point_in_layer_space);
- *out_touch_action = region.GetAllowedTouchAction(point);
- }
- if (!CurrentlyScrollingNode())
- return InputHandler::TouchStartOrMoveEventListenerType::HANDLER;
- // Check if the touch start (or move) hits on the current scrolling layer or
- // its descendant. layer_impl_with_touch_handler is the layer hit by the
- // pointer and has an event handler, otherwise it is null. We want to compare
- // the most inner layer we are hitting on which may not have an event listener
- // with the actual scrolling layer.
- LayerImpl* layer_impl =
- ActiveTree().FindLayerThatIsHitByPoint(device_viewport_point);
- bool is_ancestor = IsScrolledBy(layer_impl, CurrentlyScrollingNode());
- return is_ancestor ? InputHandler::TouchStartOrMoveEventListenerType::
- HANDLER_ON_SCROLLING_LAYER
- : InputHandler::TouchStartOrMoveEventListenerType::HANDLER;
- }
- std::unique_ptr<LatencyInfoSwapPromiseMonitor>
- InputHandler::CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency) {
- return compositor_delegate_.GetImplDeprecated()
- .CreateLatencyInfoSwapPromiseMonitor(latency);
- }
- std::unique_ptr<EventsMetricsManager::ScopedMonitor>
- InputHandler::GetScopedEventMetricsMonitor(
- EventsMetricsManager::ScopedMonitor::DoneCallback done_callback) {
- return compositor_delegate_.GetImplDeprecated().GetScopedEventMetricsMonitor(
- std::move(done_callback));
- }
- ScrollElasticityHelper* InputHandler::CreateScrollElasticityHelper() {
- DCHECK(!scroll_elasticity_helper_);
- if (compositor_delegate_.GetSettings().enable_elastic_overscroll) {
- scroll_elasticity_helper_.reset(
- ScrollElasticityHelper::CreateForLayerTreeHostImpl(
- &compositor_delegate_.GetImplDeprecated()));
- }
- return scroll_elasticity_helper_.get();
- }
- void InputHandler::DestroyScrollElasticityHelper() {
- // Remove any stretch before destroying helper.
- scroll_elasticity_helper_->SetStretchAmount(gfx::Vector2dF());
- scroll_elasticity_helper_.reset();
- }
- bool InputHandler::GetScrollOffsetForLayer(ElementId element_id,
- gfx::PointF* offset) {
- ScrollTree& scroll_tree = GetScrollTree();
- ScrollNode* scroll_node = scroll_tree.FindNodeFromElementId(element_id);
- if (!scroll_node)
- return false;
- *offset = scroll_tree.current_scroll_offset(element_id);
- return true;
- }
- bool InputHandler::ScrollLayerTo(ElementId element_id,
- const gfx::PointF& offset) {
- ScrollTree& scroll_tree = GetScrollTree();
- ScrollNode* scroll_node = scroll_tree.FindNodeFromElementId(element_id);
- if (!scroll_node)
- return false;
- scroll_tree.ScrollBy(*scroll_node,
- offset - scroll_tree.current_scroll_offset(element_id),
- &ActiveTree());
- return true;
- }
- bool InputHandler::ScrollingShouldSwitchtoMainThread() {
- DCHECK(!base::FeatureList::IsEnabled(features::kScrollUnification));
- ScrollTree& scroll_tree = GetScrollTree();
- ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
- if (!scroll_node)
- return true;
- for (; scroll_tree.parent(scroll_node);
- scroll_node = scroll_tree.parent(scroll_node)) {
- if (!!scroll_node->main_thread_scrolling_reasons)
- return true;
- }
- return false;
- }
- bool InputHandler::GetSnapFlingInfoAndSetAnimatingSnapTarget(
- const gfx::Vector2dF& natural_displacement_in_viewport,
- gfx::PointF* out_initial_position,
- gfx::PointF* out_target_position) {
- ScrollNode* scroll_node = CurrentlyScrollingNode();
- if (!scroll_node || !scroll_node->snap_container_data.has_value())
- return false;
- const SnapContainerData& data = scroll_node->snap_container_data.value();
- float scale_factor = ActiveTree().page_scale_factor_for_scroll();
- gfx::Vector2dF natural_displacement_in_content =
- gfx::ScaleVector2d(natural_displacement_in_viewport, 1.f / scale_factor);
- gfx::PointF current_offset = GetVisualScrollOffset(*scroll_node);
- *out_initial_position = current_offset;
- // CC side always uses fractional scroll deltas.
- bool use_fractional_offsets = true;
- TargetSnapAreaElementIds snap_target_ids;
- std::unique_ptr<SnapSelectionStrategy> strategy =
- SnapSelectionStrategy::CreateForEndAndDirection(
- current_offset, natural_displacement_in_content,
- use_fractional_offsets);
- if (!data.FindSnapPosition(*strategy, out_target_position, &snap_target_ids))
- return false;
- scroll_animating_snap_target_ids_ = snap_target_ids;
- out_target_position->Scale(scale_factor);
- out_initial_position->Scale(scale_factor);
- return true;
- }
- void InputHandler::ScrollEndForSnapFling(bool did_finish) {
- ScrollNode* scroll_node = CurrentlyScrollingNode();
- // When a snap fling animation reaches its intended target then we update the
- // scrolled node's snap targets. This also ensures blink learns about the new
- // snap targets for this scrolling element.
- if (did_finish && scroll_node &&
- scroll_node->snap_container_data.has_value()) {
- scroll_node->snap_container_data.value().SetTargetSnapAreaElementIds(
- scroll_animating_snap_target_ids_);
- updated_snapped_elements_[scroll_node->element_id] =
- scroll_animating_snap_target_ids_;
- SetNeedsCommit();
- }
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- ScrollEnd(false /* should_snap */);
- }
- void InputHandler::NotifyInputEvent() {
- compositor_delegate_.GetImplDeprecated().NotifyInputEvent();
- }
- //
- // =========== InputDelegateForCompositor Interface
- //
- void InputHandler::ProcessCommitDeltas(CompositorCommitData* commit_data) {
- DCHECK(commit_data);
- if (ActiveTree().LayerListIsEmpty())
- return;
- ElementId inner_viewport_scroll_element_id =
- InnerViewportScrollNode() ? InnerViewportScrollNode()->element_id
- : ElementId();
- base::flat_map<ElementId, TargetSnapAreaElementIds> snapped_elements;
- updated_snapped_elements_.swap(snapped_elements);
- // Scroll commit data is stored in the scroll tree so it has its own method
- // for getting it.
- // TODO(bokan): It's a bug that CollectScrollDeltas is here, it means the
- // compositor cannot commit scroll changes without an InputHandler which it
- // should be able to. To move it back, we'll need to split out the
- // |snapped_elements| part of ScrollTree::CollectScrollDeltas though which is
- // an input responsibility.
- GetScrollTree().CollectScrollDeltas(
- commit_data, inner_viewport_scroll_element_id,
- compositor_delegate_.GetSettings().commit_fractional_scroll_deltas,
- snapped_elements);
- // Record and reset scroll source flags.
- DCHECK(!commit_data->manipulation_info);
- if (has_scrolled_by_wheel_)
- commit_data->manipulation_info |= kManipulationInfoWheel;
- if (has_scrolled_by_touch_)
- commit_data->manipulation_info |= kManipulationInfoTouch;
- if (has_scrolled_by_precisiontouchpad_)
- commit_data->manipulation_info |= kManipulationInfoPrecisionTouchPad;
- if (has_pinch_zoomed_)
- commit_data->manipulation_info |= kManipulationInfoPinchZoom;
- if (has_scrolled_by_scrollbar_)
- commit_data->manipulation_info |= kManipulationInfoScrollbar;
- has_scrolled_by_wheel_ = false;
- has_scrolled_by_touch_ = false;
- has_scrolled_by_precisiontouchpad_ = false;
- has_pinch_zoomed_ = false;
- has_scrolled_by_scrollbar_ = false;
- commit_data->scroll_gesture_did_end = scroll_gesture_did_end_;
- scroll_gesture_did_end_ = false;
- commit_data->overscroll_delta = overscroll_delta_for_main_thread_;
- overscroll_delta_for_main_thread_ = gfx::Vector2dF();
- // Use the |last_latched_scroller_| rather than the
- // |CurrentlyScrollingNode| since the latter may be cleared by a GSE before
- // we've committed these values to the main thread.
- // TODO(bokan): This is wrong - if we also started a scroll this frame then
- // this will clear this value for that scroll. https://crbug.com/1116780.
- commit_data->scroll_latched_element_id = last_latched_scroller_;
- if (commit_data->scroll_gesture_did_end)
- last_latched_scroller_ = ElementId();
- }
- void InputHandler::TickAnimations(base::TimeTicks monotonic_time) {
- if (input_handler_client_) {
- // This does not set did_animate, because if the InputHandlerClient
- // changes anything it will be through the InputHandler interface which
- // does SetNeedsRedraw.
- input_handler_client_->Animate(monotonic_time);
- }
- }
- void InputHandler::WillShutdown() {
- if (input_handler_client_) {
- input_handler_client_.ExtractAsDangling()->WillShutdown();
- }
- if (scroll_elasticity_helper_)
- scroll_elasticity_helper_.reset();
- }
- void InputHandler::WillDraw() {
- if (input_handler_client_)
- input_handler_client_->ReconcileElasticOverscrollAndRootScroll();
- }
- void InputHandler::WillBeginImplFrame(const viz::BeginFrameArgs& args) {
- if (input_handler_client_) {
- scrollbar_controller_->WillBeginImplFrame();
- input_handler_client_->DeliverInputForBeginFrame(args);
- }
- }
- void InputHandler::DidCommit() {
- // In high latency mode commit cannot finish within the same frame. We need to
- // flush input here to make sure they got picked up by |PrepareTiles()|.
- if (input_handler_client_ && compositor_delegate_.IsInHighLatencyMode())
- input_handler_client_->DeliverInputForHighLatencyMode();
- }
- void InputHandler::DidActivatePendingTree() {
- // The previous scrolling node might no longer exist in the new tree.
- if (!CurrentlyScrollingNode())
- ClearCurrentlyScrollingNode();
- // Activation can change the root scroll offset, so inform the synchronous
- // input handler.
- UpdateRootLayerStateForSynchronousInputHandler();
- }
- void InputHandler::RootLayerStateMayHaveChanged() {
- UpdateRootLayerStateForSynchronousInputHandler();
- }
- void InputHandler::DidRegisterScrollbar(ElementId scroll_element_id,
- ScrollbarOrientation orientation) {
- scrollbar_controller_->DidRegisterScrollbar(scroll_element_id, orientation);
- }
- void InputHandler::DidUnregisterScrollbar(ElementId scroll_element_id,
- ScrollbarOrientation orientation) {
- scrollbar_controller_->DidUnregisterScrollbar(scroll_element_id, orientation);
- }
- void InputHandler::ScrollOffsetAnimationFinished() {
- TRACE_EVENT0("cc", "InputHandler::ScrollOffsetAnimationFinished");
- // ScrollOffsetAnimationFinished is called in two cases:
- // 1- smooth scrolling animation is over (IsAnimatingForSnap == false).
- // 2- snap scroll animation is over (IsAnimatingForSnap == true).
- //
- // Only for case (1) we should check and run snap scroll animation if needed.
- if (!IsAnimatingForSnap() &&
- SnapAtScrollEnd(SnapReason::kScrollOffsetAnimationFinished))
- return;
- // The end of a scroll offset animation means that the scrolling node is at
- // the target offset.
- ScrollNode* scroll_node = CurrentlyScrollingNode();
- if (scroll_node && scroll_node->snap_container_data.has_value()) {
- scroll_node->snap_container_data.value().SetTargetSnapAreaElementIds(
- scroll_animating_snap_target_ids_);
- updated_snapped_elements_[scroll_node->element_id] =
- scroll_animating_snap_target_ids_;
- SetNeedsCommit();
- }
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- // Call scrollEnd with the deferred scroll end state when the scroll animation
- // completes after GSE arrival.
- if (deferred_scroll_end_) {
- ScrollEnd(/*should_snap=*/false);
- return;
- }
- }
- void InputHandler::SetPrefersReducedMotion(bool prefers_reduced_motion) {
- if (prefers_reduced_motion_ == prefers_reduced_motion)
- return;
- prefers_reduced_motion_ = prefers_reduced_motion;
- if (input_handler_client_)
- input_handler_client_->SetPrefersReducedMotion(prefers_reduced_motion_);
- }
- bool InputHandler::IsCurrentlyScrolling() const {
- return CurrentlyScrollingNode();
- }
- ActivelyScrollingType InputHandler::GetActivelyScrollingType() const {
- if (!CurrentlyScrollingNode())
- return ActivelyScrollingType::kNone;
- if (!last_scroll_update_state_)
- return ActivelyScrollingType::kNone;
- if (!delta_consumed_for_scroll_gesture_)
- return ActivelyScrollingType::kNone;
- if (ShouldAnimateScroll(last_scroll_update_state_.value()))
- return ActivelyScrollingType::kAnimated;
- return ActivelyScrollingType::kPrecise;
- }
- ScrollNode* InputHandler::CurrentlyScrollingNode() {
- return GetScrollTree().CurrentlyScrollingNode();
- }
- const ScrollNode* InputHandler::CurrentlyScrollingNode() const {
- return GetScrollTree().CurrentlyScrollingNode();
- }
- ScrollTree& InputHandler::GetScrollTree() {
- return compositor_delegate_.GetScrollTree();
- }
- ScrollTree& InputHandler::GetScrollTree() const {
- return compositor_delegate_.GetScrollTree();
- }
- ScrollNode* InputHandler::InnerViewportScrollNode() const {
- return ActiveTree().InnerViewportScrollNode();
- }
- ScrollNode* InputHandler::OuterViewportScrollNode() const {
- return ActiveTree().OuterViewportScrollNode();
- }
- Viewport& InputHandler::GetViewport() const {
- return compositor_delegate_.GetImplDeprecated().viewport();
- }
- void InputHandler::SetNeedsCommit() {
- compositor_delegate_.SetNeedsCommit();
- }
- LayerTreeImpl& InputHandler::ActiveTree() {
- DCHECK(compositor_delegate_.GetImplDeprecated().active_tree());
- return *compositor_delegate_.GetImplDeprecated().active_tree();
- }
- LayerTreeImpl& InputHandler::ActiveTree() const {
- DCHECK(compositor_delegate_.GetImplDeprecated().active_tree());
- return *compositor_delegate_.GetImplDeprecated().active_tree();
- }
- FrameSequenceTrackerType InputHandler::GetTrackerTypeForScroll(
- ui::ScrollInputType input_type) const {
- switch (input_type) {
- case ui::ScrollInputType::kWheel:
- return FrameSequenceTrackerType::kWheelScroll;
- case ui::ScrollInputType::kTouchscreen:
- return FrameSequenceTrackerType::kTouchScroll;
- case ui::ScrollInputType::kScrollbar:
- return FrameSequenceTrackerType::kScrollbarScroll;
- case ui::ScrollInputType::kAutoscroll:
- return FrameSequenceTrackerType::kMaxType;
- }
- }
- bool InputHandler::IsMainThreadScrolling(
- const InputHandler::ScrollStatus& status,
- const ScrollNode* scroll_node) const {
- if (status.thread == InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD) {
- if (!!scroll_node->main_thread_scrolling_reasons) {
- DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons(
- status.main_thread_scrolling_reasons));
- } else {
- DCHECK(MainThreadScrollingReason::CompositorCanSetScrollReasons(
- status.main_thread_scrolling_reasons));
- }
- return true;
- }
- return false;
- }
- float InputHandler::LineStep() const {
- return kPixelsPerLineStep;
- }
- // TODO(mehdika): There is some redundancy between this function and
- // ScrollbarController::GetScrollDistanceForScrollbarPart, these two need to be
- // kept in sync.
- gfx::Vector2dF InputHandler::ResolveScrollGranularityToPixels(
- const ScrollNode& scroll_node,
- const gfx::Vector2dF& scroll_delta,
- ui::ScrollGranularity granularity) {
- gfx::Vector2dF pixel_delta = scroll_delta;
- if (granularity == ui::ScrollGranularity::kScrollByPage) {
- // Page should use a percentage of the scroller so change the parameters
- // and let the percentage case below resolve it.
- granularity = ui::ScrollGranularity::kScrollByPercentage;
- pixel_delta.Scale(kMinFractionToStepWhenPaging);
- }
- if (granularity == ui::ScrollGranularity::kScrollByPercentage) {
- gfx::SizeF scroller_size = gfx::SizeF(scroll_node.container_bounds);
- gfx::SizeF viewport_size(compositor_delegate_.VisualDeviceViewportSize());
- // Convert from rootframe coordinates to screen coordinates (physical
- // pixels if --use-zoom-for-dsf enabled, DIPs otherwise).
- scroller_size.Scale(compositor_delegate_.PageScaleFactor());
- // Convert from physical pixels to screen coordinates (if --use-zoom-for-dsf
- // enabled, `DeviceScaleFactor()` returns 1).
- viewport_size.Scale(1 / compositor_delegate_.DeviceScaleFactor());
- pixel_delta = ScrollUtils::ResolveScrollPercentageToPixels(
- pixel_delta, scroller_size, viewport_size);
- }
- if (granularity == ui::ScrollGranularity::kScrollByLine) {
- pixel_delta.Scale(LineStep(), LineStep());
- }
- return pixel_delta;
- }
- InputHandler::ScrollStatus InputHandler::TryScroll(
- const ScrollTree& scroll_tree,
- ScrollNode* scroll_node) const {
- DCHECK(!base::FeatureList::IsEnabled(features::kScrollUnification));
- InputHandler::ScrollStatus scroll_status;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollingOnMain;
- if (scroll_node->main_thread_scrolling_reasons) {
- TRACE_EVENT1("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread",
- "MainThreadScrollingReason",
- scroll_node->main_thread_scrolling_reasons);
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- scroll_status.main_thread_scrolling_reasons =
- scroll_node->main_thread_scrolling_reasons;
- return scroll_status;
- }
- gfx::Transform screen_space_transform =
- scroll_tree.ScreenSpaceTransform(scroll_node->id);
- if (!screen_space_transform.IsInvertible()) {
- TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNonInvertibleTransform;
- return scroll_status;
- }
- if (!scroll_node->scrollable) {
- TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollable;
- return scroll_status;
- }
- // If an associated scrolling layer is not found, the scroll node must not
- // support impl-scrolling. The root, secondary root, and inner viewports
- // are all exceptions to this and may not have a layer because it is not
- // required for hit testing.
- if (scroll_node->id != kRootPropertyNodeId &&
- scroll_node->id != kSecondaryRootPropertyNodeId &&
- !scroll_node->scrolls_inner_viewport &&
- !ActiveTree().LayerByElementId(scroll_node->element_id)) {
- TRACE_EVENT0("cc",
- "LayerImpl::tryScroll: Failed due to no scrolling layer");
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_ON_MAIN_THREAD;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNoScrollingLayer;
- return scroll_status;
- }
- // The a viewport node should be scrolled even if it has no scroll extent
- // since it'll scroll using the Viewport class which will generate browser
- // controls movement and overscroll delta.
- gfx::PointF max_scroll_offset = scroll_tree.MaxScrollOffset(scroll_node->id);
- if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0 &&
- !GetViewport().ShouldScroll(*scroll_node)) {
- TRACE_EVENT0("cc",
- "LayerImpl::tryScroll: Ignored. Technically scrollable,"
- " but has no affordance in either direction.");
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_IGNORED;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollable;
- return scroll_status;
- }
- scroll_status.thread = InputHandler::ScrollThread::SCROLL_ON_IMPL_THREAD;
- return scroll_status;
- }
- base::flat_set<int> InputHandler::NonFastScrollableNodes(
- const gfx::PointF& device_viewport_point) const {
- base::flat_set<int> non_fast_scrollable_nodes;
- const auto& non_fast_layers =
- ActiveTree().FindLayersHitByPointInNonFastScrollableRegion(
- device_viewport_point);
- for (const auto* layer : non_fast_layers)
- non_fast_scrollable_nodes.insert(layer->scroll_tree_index());
- return non_fast_scrollable_nodes;
- }
- ScrollNode* InputHandler::FindScrollNodeForCompositedScrolling(
- const gfx::PointF& device_viewport_point,
- LayerImpl* layer_impl,
- bool* scroll_on_main_thread,
- uint32_t* main_thread_scrolling_reasons) {
- DCHECK(!base::FeatureList::IsEnabled(features::kScrollUnification));
- DCHECK(scroll_on_main_thread);
- DCHECK(main_thread_scrolling_reasons);
- *main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollingOnMain;
- const auto& non_fast_scrollable_nodes =
- NonFastScrollableNodes(device_viewport_point);
- // Walk up the hierarchy and look for a scrollable layer.
- ScrollTree& scroll_tree = GetScrollTree();
- ScrollNode* impl_scroll_node = nullptr;
- if (layer_impl) {
- // If this is a scrollbar layer, we can't directly use the associated
- // scroll_node (because the scroll_node associated with this layer will be
- // the owning scroller's parent). Instead, we first retrieve the scrollable
- // layer corresponding to the scrollbars owner and then use its
- // scroll_tree_index instead.
- int scroll_tree_index = layer_impl->scroll_tree_index();
- if (layer_impl->IsScrollbarLayer()) {
- LayerImpl* owner_scroll_layer = ActiveTree().LayerByElementId(
- ToScrollbarLayer(layer_impl)->scroll_element_id());
- scroll_tree_index = owner_scroll_layer->scroll_tree_index();
- }
- ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index);
- for (; scroll_tree.parent(scroll_node);
- scroll_node = scroll_tree.parent(scroll_node)) {
- // The content layer can also block attempts to scroll outside the main
- // thread.
- InputHandler::ScrollStatus status = TryScroll(scroll_tree, scroll_node);
- if (IsMainThreadScrolling(status, scroll_node)) {
- *scroll_on_main_thread = true;
- *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
- return scroll_node;
- }
- if (non_fast_scrollable_nodes.contains(scroll_node->id)) {
- *scroll_on_main_thread = true;
- *main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNonFastScrollableRegion;
- return scroll_node;
- }
- if (status.thread == InputHandler::ScrollThread::SCROLL_ON_IMPL_THREAD &&
- !impl_scroll_node) {
- impl_scroll_node = scroll_node;
- }
- }
- }
- // TODO(bokan): We shouldn't need this - ordinarily all scrolls should pass
- // through the outer viewport. If we aren't able to find a scroller we should
- // return nullptr here and ignore the scroll. However, it looks like on some
- // pages (reddit.com) we start scrolling from the inner node.
- if (!impl_scroll_node)
- impl_scroll_node = InnerViewportScrollNode();
- if (!impl_scroll_node)
- return nullptr;
- impl_scroll_node = GetNodeToScroll(impl_scroll_node);
- // Ensure that final scroll node scrolls on impl thread (crbug.com/625100)
- InputHandler::ScrollStatus status = TryScroll(scroll_tree, impl_scroll_node);
- if (IsMainThreadScrolling(status, impl_scroll_node)) {
- *scroll_on_main_thread = true;
- *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
- } else if (non_fast_scrollable_nodes.contains(impl_scroll_node->id)) {
- *scroll_on_main_thread = true;
- *main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNonFastScrollableRegion;
- }
- return impl_scroll_node;
- }
- InputHandler::ScrollHitTestResult InputHandler::HitTestScrollNode(
- const gfx::PointF& device_viewport_point) const {
- ScrollHitTestResult result;
- result.scroll_node = nullptr;
- result.hit_test_successful = false;
- std::vector<const LayerImpl*> layers =
- ActiveTree().FindAllLayersUpToAndIncludingFirstScrollable(
- device_viewport_point);
- const LayerImpl* scroller_layer =
- (!layers.empty() && layers.back()->IsScrollerOrScrollbar())
- ? layers.back()
- : nullptr;
- // Go through each layer up to (and including) the scroller. Any may block
- // scrolling if they come from outside the scroller's scroll-subtree or if we
- // hit a non-fast-scrolling-region.
- for (const auto* layer_impl : layers) {
- // There are some cases where the hit layer may not be correct (e.g. layer
- // squashing, pointer-events:none layer) because the compositor doesn't
- // know what parts of the layer (if any) are actually visible to hit
- // testing. This is fine if we can determine that the scrolling node will
- // be the same regardless of whether we hit an opaque or transparent (to
- // hit testing) point of the layer. If the scrolling node may depend on
- // this, we have to get a hit test from the main thread.
- if (!IsInitialScrollHitTestReliable(layer_impl, scroller_layer)) {
- TRACE_EVENT_INSTANT0("cc", "Failed Hit Test", TRACE_EVENT_SCOPE_THREAD);
- return result;
- }
- // If we hit a non-fast scrollable region, that means there's some reason we
- // can't scroll in this region. Primarily, because there's another scroller
- // there that isn't composited and we don't know about so we'll return
- // failure.
- if (ActiveTree().PointHitsNonFastScrollableRegion(device_viewport_point,
- *layer_impl)) {
- return result;
- }
- }
- // It's theoretically possible to hit no layers or only non-scrolling layers.
- // e.g. an API hit test outside the viewport, or sending a scroll to an OOPIF
- // that does not have overflow. If we made it to here, we also don't have any
- // non-fast scroll regions. Fallback to scrolling the viewport.
- if (!scroller_layer) {
- result.hit_test_successful = true;
- if (InnerViewportScrollNode())
- result.scroll_node = GetNodeToScroll(InnerViewportScrollNode());
- return result;
- }
- // If we hit a scrollbar layer, get the ScrollNode from its associated
- // scrolling layer, rather than directly from the scrollbar layer. The latter
- // would return the parent scroller's ScrollNode.
- if (scroller_layer->IsScrollbarLayer()) {
- scroller_layer = ActiveTree().LayerByElementId(
- ToScrollbarLayer(scroller_layer)->scroll_element_id());
- DCHECK(scroller_layer);
- }
- ScrollNode* scroll_node =
- GetScrollTree().Node(scroller_layer->scroll_tree_index());
- result.scroll_node = GetNodeToScroll(scroll_node);
- result.hit_test_successful = true;
- return result;
- }
- // Requires falling back to main thread scrolling when it hit tests in scrollbar
- // from touch.
- bool InputHandler::IsTouchDraggingScrollbar(
- LayerImpl* first_scrolling_layer_or_scrollbar,
- ui::ScrollInputType type) {
- return first_scrolling_layer_or_scrollbar &&
- first_scrolling_layer_or_scrollbar->IsScrollbarLayer() &&
- type == ui::ScrollInputType::kTouchscreen;
- }
- ScrollNode* InputHandler::GetNodeToScroll(ScrollNode* node) const {
- // Blink has a notion of a "root scroller", which is the scroller in a page
- // that is considered to host the main content. Typically this will be the
- // document/LayoutView contents; however, in some situations Blink may choose
- // a sub-scroller (div, iframe) that should scroll with "viewport" behavior.
- // The "root scroller" is the node designated as the outer viewport in CC.
- // See third_party/blink/renderer/core/page/scrolling/README.md for details.
- //
- // "Viewport" scrolling ensures generation of overscroll events, top controls
- // movement, as well as correct multi-viewport panning in pinch-zoom and
- // other scenarios. We use the viewport's outer scroll node to represent the
- // viewport in the scroll chain and apply scroll delta using CC's Viewport
- // class.
- //
- // Scrolling from position: fixed layers will chain directly up to the inner
- // viewport. Whether that should use the outer viewport (and thus the
- // Viewport class) to scroll or not depends on the root scroller scenario
- // because we don't want setting a root scroller to change the scroll chain
- // order. The |prevent_viewport_scrolling_from_inner| bit is used to
- // communicate that context.
- DCHECK(!node->prevent_viewport_scrolling_from_inner ||
- node->scrolls_inner_viewport);
- if (node->scrolls_inner_viewport &&
- !node->prevent_viewport_scrolling_from_inner) {
- DCHECK(OuterViewportScrollNode());
- return OuterViewportScrollNode();
- }
- return node;
- }
- bool InputHandler::IsInitialScrollHitTestReliable(
- const LayerImpl* layer_impl,
- const LayerImpl* first_scrolling_layer_or_scrollbar) const {
- if (!first_scrolling_layer_or_scrollbar)
- return true;
- // Hit tests directly on a composited scrollbar are always reliable.
- if (layer_impl->IsScrollbarLayer()) {
- DCHECK(layer_impl == first_scrolling_layer_or_scrollbar);
- return true;
- }
- ScrollNode* closest_scroll_node = nullptr;
- auto& scroll_tree = GetScrollTree();
- ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index());
- for (; scroll_tree.parent(scroll_node);
- scroll_node = scroll_tree.parent(scroll_node)) {
- // TODO(bokan): |scrollable| appears to always be true in LayerList mode.
- // In non-LayerList, scroll hit tests should always be reliable because we
- // don't have situations where a layer can be hit testable but pass some
- // points through (e.g. squashing layers). Perhaps we can remove this
- // condition?
- if (scroll_node->scrollable) {
- closest_scroll_node = GetNodeToScroll(scroll_node);
- break;
- }
- }
- if (!closest_scroll_node)
- return false;
- // If |first_scrolling_layer_or_scrollbar| is not a scrollbar, it must be
- // a scrollabe layer with a scroll node. If this scroll node corresponds to
- // first scrollable ancestor along the scroll tree for |layer_impl|, the hit
- // test has not escaped to other areas of the scroll tree and is reliable.
- if (!first_scrolling_layer_or_scrollbar->IsScrollbarLayer()) {
- return closest_scroll_node->id ==
- first_scrolling_layer_or_scrollbar->scroll_tree_index();
- }
- return false;
- }
- gfx::Vector2dF InputHandler::ComputeScrollDelta(const ScrollNode& scroll_node,
- const gfx::Vector2dF& delta) {
- ScrollTree& scroll_tree = GetScrollTree();
- float scale_factor = compositor_delegate_.PageScaleFactor();
- gfx::Vector2dF adjusted_scroll(delta);
- adjusted_scroll.Scale(1.f / scale_factor);
- adjusted_scroll = UserScrollableDelta(scroll_node, adjusted_scroll);
- gfx::PointF old_offset =
- scroll_tree.current_scroll_offset(scroll_node.element_id);
- gfx::PointF new_offset = scroll_tree.ClampScrollOffsetToLimits(
- old_offset + adjusted_scroll, scroll_node);
- return new_offset - old_offset;
- }
- bool InputHandler::CalculateLocalScrollDeltaAndStartPoint(
- const ScrollNode& scroll_node,
- const gfx::PointF& viewport_point,
- const gfx::Vector2dF& viewport_delta,
- gfx::Vector2dF* out_local_scroll_delta,
- gfx::PointF* out_local_start_point /*= nullptr*/) {
- // Layers with non-invertible screen space transforms should not have passed
- // the scroll hit test in the first place.
- const gfx::Transform screen_space_transform =
- GetScrollTree().ScreenSpaceTransform(scroll_node.id);
- DCHECK(screen_space_transform.IsInvertible());
- gfx::Transform inverse_screen_space_transform(
- gfx::Transform::kSkipInitialization);
- bool did_invert =
- screen_space_transform.GetInverse(&inverse_screen_space_transform);
- // TODO(shawnsingh): With the advent of impl-side scrolling for non-root
- // layers, we may need to explicitly handle uninvertible transforms here.
- DCHECK(did_invert);
- float scale_from_viewport_to_screen_space =
- compositor_delegate_.DeviceScaleFactor();
- gfx::PointF screen_space_point =
- gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space);
- gfx::Vector2dF screen_space_delta = viewport_delta;
- screen_space_delta.Scale(scale_from_viewport_to_screen_space);
- // Project the scroll start and end points to local layer space to find the
- // scroll delta in layer coordinates.
- bool start_clipped, end_clipped;
- gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta;
- gfx::PointF local_start_point = MathUtil::ProjectPoint(
- inverse_screen_space_transform, screen_space_point, &start_clipped);
- gfx::PointF local_end_point = MathUtil::ProjectPoint(
- inverse_screen_space_transform, screen_space_end_point, &end_clipped);
- DCHECK(out_local_scroll_delta);
- *out_local_scroll_delta = local_end_point - local_start_point;
- if (out_local_start_point)
- *out_local_start_point = local_start_point;
- if (start_clipped || end_clipped)
- return false;
- return true;
- }
- gfx::Vector2dF InputHandler::ScrollNodeWithViewportSpaceDelta(
- const ScrollNode& scroll_node,
- const gfx::PointF& viewport_point,
- const gfx::Vector2dF& viewport_delta) {
- ScrollTree& scroll_tree = GetScrollTree();
- gfx::PointF local_start_point;
- gfx::Vector2dF local_scroll_delta;
- if (!CalculateLocalScrollDeltaAndStartPoint(
- scroll_node, viewport_point, viewport_delta, &local_scroll_delta,
- &local_start_point)) {
- return gfx::Vector2dF();
- }
- bool scrolls_outer_viewport = scroll_node.scrolls_outer_viewport;
- TRACE_EVENT2("cc", "ScrollNodeWithViewportSpaceDelta", "delta_y",
- local_scroll_delta.y(), "is_outer", scrolls_outer_viewport);
- // Apply the scroll delta.
- gfx::PointF previous_offset =
- scroll_tree.current_scroll_offset(scroll_node.element_id);
- scroll_tree.ScrollBy(scroll_node, local_scroll_delta, &ActiveTree());
- gfx::Vector2dF scrolled =
- scroll_tree.current_scroll_offset(scroll_node.element_id) -
- previous_offset;
- TRACE_EVENT_INSTANT1("cc", "ConsumedDelta", TRACE_EVENT_SCOPE_THREAD, "y",
- scrolled.y());
- // Get the end point in the layer's content space so we can apply its
- // ScreenSpaceTransform.
- gfx::PointF actual_local_end_point = local_start_point + scrolled;
- // Calculate the applied scroll delta in viewport space coordinates.
- bool end_clipped;
- const gfx::Transform screen_space_transform =
- scroll_tree.ScreenSpaceTransform(scroll_node.id);
- gfx::PointF actual_screen_space_end_point = MathUtil::MapPoint(
- screen_space_transform, actual_local_end_point, &end_clipped);
- DCHECK(!end_clipped);
- if (end_clipped)
- return gfx::Vector2dF();
- float scale_from_viewport_to_screen_space =
- compositor_delegate_.DeviceScaleFactor();
- gfx::PointF actual_viewport_end_point = gfx::ScalePoint(
- actual_screen_space_end_point, 1.f / scale_from_viewport_to_screen_space);
- return actual_viewport_end_point - viewport_point;
- }
- gfx::Vector2dF InputHandler::ScrollNodeWithLocalDelta(
- const ScrollNode& scroll_node,
- const gfx::Vector2dF& local_delta) const {
- bool scrolls_outer_viewport = scroll_node.scrolls_outer_viewport;
- TRACE_EVENT2("cc", "ScrollNodeWithLocalDelta", "delta_y", local_delta.y(),
- "is_outer", scrolls_outer_viewport);
- float page_scale_factor = compositor_delegate_.PageScaleFactor();
- ScrollTree& scroll_tree = GetScrollTree();
- gfx::PointF previous_offset =
- scroll_tree.current_scroll_offset(scroll_node.element_id);
- gfx::Vector2dF delta = local_delta;
- delta.Scale(1.f / page_scale_factor);
- scroll_tree.ScrollBy(scroll_node, delta, &ActiveTree());
- gfx::Vector2dF scrolled =
- scroll_tree.current_scroll_offset(scroll_node.element_id) -
- previous_offset;
- gfx::Vector2dF consumed_scroll(scrolled.x(), scrolled.y());
- consumed_scroll.Scale(page_scale_factor);
- TRACE_EVENT_INSTANT1("cc", "ConsumedDelta", TRACE_EVENT_SCOPE_THREAD, "y",
- consumed_scroll.y());
- return consumed_scroll;
- }
- // TODO(danakj): Make this into two functions, one with delta, one with
- // viewport_point, no bool required.
- gfx::Vector2dF InputHandler::ScrollSingleNode(const ScrollNode& scroll_node,
- const gfx::Vector2dF& delta,
- const gfx::Point& viewport_point,
- bool is_direct_manipulation) {
- gfx::Vector2dF adjusted_delta = UserScrollableDelta(scroll_node, delta);
- // Events representing direct manipulation of the screen (such as gesture
- // events) need to be transformed from viewport coordinates to local layer
- // coordinates so that the scrolling contents exactly follow the user's
- // finger. In contrast, events not representing direct manipulation of the
- // screen (such as wheel events) represent a fixed amount of scrolling so we
- // can just apply them directly, but the page scale factor is applied to the
- // scroll delta.
- if (is_direct_manipulation) {
- // For touch-scroll we need to scale the delta here, as the transform tree
- // won't know anything about the external page scale factors used by OOPIFs.
- gfx::Vector2dF scaled_delta(adjusted_delta);
- scaled_delta.Scale(1 / ActiveTree().external_page_scale_factor());
- return ScrollNodeWithViewportSpaceDelta(
- scroll_node, gfx::PointF(viewport_point), scaled_delta);
- }
- return ScrollNodeWithLocalDelta(scroll_node, adjusted_delta);
- }
- void InputHandler::ScrollLatchedScroller(ScrollState* scroll_state,
- base::TimeDelta delayed_by) {
- DCHECK(CurrentlyScrollingNode());
- DCHECK(scroll_state);
- DCHECK(latched_scroll_type_.has_value());
- ScrollNode& scroll_node = *CurrentlyScrollingNode();
- const gfx::Vector2dF delta(scroll_state->delta_x(), scroll_state->delta_y());
- TRACE_EVENT2("cc", "InputHandler::ScrollLatchedScroller", "delta_x",
- delta.x(), "delta_y", delta.y());
- gfx::Vector2dF applied_delta;
- gfx::Vector2dF delta_applied_to_content;
- // TODO(tdresser): Use a more rational epsilon. See crbug.com/510550 for
- // details.
- const float kEpsilon = 0.1f;
- if (ShouldAnimateScroll(*scroll_state)) {
- DCHECK(!scroll_state->is_in_inertial_phase());
- if (ElementId id = compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ImplOnlyScrollAnimatingElement()) {
- TRACE_EVENT_INSTANT0("cc", "UpdateExistingAnimation",
- TRACE_EVENT_SCOPE_THREAD);
- ScrollNode* animating_scroll_node =
- GetScrollTree().FindNodeFromElementId(id);
- DCHECK(animating_scroll_node);
- // Usually the CurrentlyScrollingNode will be the currently animating
- // one. The one exception is the inner viewport. Scrolling the combined
- // viewport will always set the outer viewport as the currently scrolling
- // node. However, if an animation is created on the inner viewport we
- // must use it when updating the animation curve.
- DCHECK(animating_scroll_node->id == scroll_node.id ||
- animating_scroll_node->scrolls_inner_viewport);
- bool animation_updated = ScrollAnimationUpdateTarget(
- *animating_scroll_node, delta, delayed_by);
- if (animation_updated) {
- // Because we updated the animation target, consume delta so we notify
- // the `LatencyInfoSwapPromiseMonitor` to tell it that something
- // happened that will cause a swap in the future. This will happen
- // within the scope of the dispatch of a gesture scroll update input
- // event. If we don't notify during the handling of the input event, the
- // `LatencyInfo` associated with the input event will not be added as a
- // swap promise and we won't get any swap results.
- applied_delta = delta;
- } else {
- TRACE_EVENT_INSTANT0("cc", "Didn't Update Animation",
- TRACE_EVENT_SCOPE_THREAD);
- }
- } else {
- TRACE_EVENT_INSTANT0("cc", "CreateNewAnimation",
- TRACE_EVENT_SCOPE_THREAD);
- if (scroll_node.scrolls_outer_viewport) {
- applied_delta = GetViewport().ScrollAnimated(delta, delayed_by);
- } else {
- applied_delta = ComputeScrollDelta(scroll_node, delta);
- compositor_delegate_.GetImplDeprecated().ScrollAnimationCreate(
- scroll_node, applied_delta, delayed_by);
- }
- }
- // Animated scrolling always applied only to the content (i.e. not to the
- // browser controls).
- delta_applied_to_content = delta;
- } else {
- gfx::Point viewport_point(scroll_state->position_x(),
- scroll_state->position_y());
- if (GetViewport().ShouldScroll(scroll_node)) {
- // |scrolls_outer_viewport| will only ever be false if the scroll chains
- // up to the viewport without going through the outer viewport scroll
- // node. This is because we normally terminate the scroll chain at the
- // outer viewport node. For example, if we start scrolling from an
- // element that's not a descendant of the root scroller. In these cases we
- // want to scroll *only* the inner viewport -- to allow panning while
- // zoomed -- but still use Viewport::ScrollBy to also move browser
- // controls if needed.
- Viewport::ScrollResult result = GetViewport().ScrollBy(
- delta, viewport_point, scroll_state->is_direct_manipulation(),
- latched_scroll_type_ != ui::ScrollInputType::kWheel,
- scroll_node.scrolls_outer_viewport);
- applied_delta = result.consumed_delta;
- delta_applied_to_content = result.content_scrolled_delta;
- } else {
- applied_delta = ScrollSingleNode(scroll_node, delta, viewport_point,
- scroll_state->is_direct_manipulation());
- }
- }
- // If the layer wasn't able to move, try the next one in the hierarchy.
- bool scrolled = std::abs(applied_delta.x()) > kEpsilon;
- scrolled = scrolled || std::abs(applied_delta.y()) > kEpsilon;
- if (!scrolled) {
- // TODO(bokan): This preserves existing behavior by not allowing tiny
- // scrolls to produce overscroll but is inconsistent in how delta gets
- // chained up. We need to clean this up.
- if (scroll_node.scrolls_outer_viewport)
- scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y());
- return;
- }
- if (!GetViewport().ShouldScroll(scroll_node)) {
- // If the applied delta is within 45 degrees of the input
- // delta, bail out to make it easier to scroll just one layer
- // in one direction without affecting any of its parents.
- float angle_threshold = 45;
- if (MathUtil::SmallestAngleBetweenVectors(applied_delta, delta) <
- angle_threshold) {
- applied_delta = delta;
- } else {
- // Allow further movement only on an axis perpendicular to the direction
- // in which the layer moved.
- applied_delta = MathUtil::ProjectVector(delta, applied_delta);
- }
- delta_applied_to_content = applied_delta;
- }
- scroll_state->set_caused_scroll(
- std::abs(delta_applied_to_content.x()) > kEpsilon,
- std::abs(delta_applied_to_content.y()) > kEpsilon);
- scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y());
- }
- bool InputHandler::CanPropagate(ScrollNode* scroll_node, float x, float y) {
- return (x == 0 || scroll_node->overscroll_behavior.x ==
- OverscrollBehavior::Type::kAuto) &&
- (y == 0 || scroll_node->overscroll_behavior.y ==
- OverscrollBehavior::Type::kAuto);
- }
- ScrollNode* InputHandler::FindNodeToLatch(ScrollState* scroll_state,
- ScrollNode* starting_node,
- ui::ScrollInputType type) {
- ScrollTree& scroll_tree = GetScrollTree();
- ScrollNode* scroll_node = nullptr;
- ScrollNode* first_scrollable_node = nullptr;
- for (ScrollNode* cur_node = starting_node; cur_node;
- cur_node = scroll_tree.parent(cur_node)) {
- if (GetViewport().ShouldScroll(*cur_node)) {
- // Don't chain scrolls past a viewport node. Once we reach that, we
- // should scroll using the appropriate viewport node which may not be
- // |cur_node|.
- scroll_node = GetNodeToScroll(cur_node);
- break;
- }
- if (!cur_node->scrollable)
- continue;
- if (!first_scrollable_node) {
- first_scrollable_node = cur_node;
- }
- if (CanConsumeDelta(*scroll_state, *cur_node)) {
- scroll_node = cur_node;
- break;
- }
- float delta_x = scroll_state->is_beginning() ? scroll_state->delta_x_hint()
- : scroll_state->delta_x();
- float delta_y = scroll_state->is_beginning() ? scroll_state->delta_y_hint()
- : scroll_state->delta_y();
- if (!CanPropagate(cur_node, delta_x, delta_y)) {
- // If we reach a node with non-auto overscroll-behavior and we still
- // haven't latched, we must latch to it. Consider a fully scrolled node
- // with non-auto overscroll-behavior: we are not allowed to further
- // chain scroll delta passed to it in the current direction but if we
- // reverse direction we should scroll it so we must be latched to it.
- scroll_node = cur_node;
- scroll_state->set_is_scroll_chain_cut(true);
- break;
- }
- }
- // If the root scroller can not consume delta in an autoscroll, latch on
- // to the top most autoscrollable scroller. See https://crbug.com/969150
- if ((type == ui::ScrollInputType::kAutoscroll) && first_scrollable_node) {
- // If scroll_node is nullptr or delta can not be consumed
- if (!(scroll_node && CanConsumeDelta(*scroll_state, *scroll_node)))
- scroll_node = first_scrollable_node;
- }
- return scroll_node;
- }
- void InputHandler::UpdateRootLayerStateForSynchronousInputHandler() {
- if (!input_handler_client_)
- return;
- input_handler_client_->UpdateRootLayerStateForSynchronousInputHandler(
- ActiveTree().TotalScrollOffset(), ActiveTree().TotalMaxScrollOffset(),
- ActiveTree().ScrollableSize(), ActiveTree().current_page_scale_factor(),
- ActiveTree().min_page_scale_factor(),
- ActiveTree().max_page_scale_factor());
- }
- void InputHandler::DidLatchToScroller(const ScrollState& scroll_state,
- ui::ScrollInputType type) {
- DCHECK(CurrentlyScrollingNode());
- deferred_scroll_end_ = false;
- compositor_delegate_.GetImplDeprecated()
- .browser_controls_manager()
- ->ScrollBegin();
- compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ScrollAnimationAbort();
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- last_latched_scroller_ = CurrentlyScrollingNode()->element_id;
- latched_scroll_type_ = type;
- last_scroll_begin_state_ = scroll_state;
- compositor_delegate_.DidStartScroll();
- RecordCompositorSlowScrollMetric(type, CC_THREAD);
- UpdateScrollSourceInfo(scroll_state, type);
- }
- bool InputHandler::CanConsumeDelta(const ScrollState& scroll_state,
- const ScrollNode& scroll_node) {
- gfx::Vector2dF delta_to_scroll;
- if (scroll_state.is_beginning()) {
- delta_to_scroll = gfx::Vector2dF(scroll_state.delta_x_hint(),
- scroll_state.delta_y_hint());
- } else {
- delta_to_scroll =
- gfx::Vector2dF(scroll_state.delta_x(), scroll_state.delta_y());
- }
- if (delta_to_scroll == gfx::Vector2dF())
- return true;
- if (scroll_state.is_direct_manipulation()) {
- gfx::Vector2dF local_scroll_delta;
- if (!CalculateLocalScrollDeltaAndStartPoint(
- scroll_node,
- gfx::PointF(scroll_state.position_x(), scroll_state.position_y()),
- delta_to_scroll, &local_scroll_delta)) {
- return false;
- }
- delta_to_scroll = local_scroll_delta;
- } else {
- delta_to_scroll = ResolveScrollGranularityToPixels(
- scroll_node, delta_to_scroll, scroll_state.delta_granularity());
- }
- if (ComputeScrollDelta(scroll_node, delta_to_scroll) != gfx::Vector2dF())
- return true;
- return false;
- }
- bool InputHandler::ShouldAnimateScroll(const ScrollState& scroll_state) const {
- if (!compositor_delegate_.GetSettings().enable_smooth_scroll)
- return false;
- bool has_precise_scroll_deltas = scroll_state.delta_granularity() ==
- ui::ScrollGranularity::kScrollByPrecisePixel;
- return !has_precise_scroll_deltas;
- }
- bool InputHandler::SnapAtScrollEnd(SnapReason reason) {
- ScrollNode* scroll_node = CurrentlyScrollingNode();
- if (!scroll_node || !scroll_node->snap_container_data.has_value())
- return false;
- SnapContainerData& data = scroll_node->snap_container_data.value();
- gfx::PointF current_position = GetVisualScrollOffset(*scroll_node);
- // You might think that if a scroll never received a scroll update we could
- // just drop the snap. However, if the GSB+GSE arrived while we were mid-snap
- // from a previous gesture, this would leave the scroller at a
- // non-snap-point.
- DCHECK(last_scroll_update_state_ || last_scroll_begin_state_);
- ScrollState& last_scroll_state = last_scroll_update_state_
- ? *last_scroll_update_state_
- : *last_scroll_begin_state_;
- bool imprecise_wheel_scrolling =
- latched_scroll_type_ == ui::ScrollInputType::kWheel &&
- last_scroll_state.delta_granularity() !=
- ui::ScrollGranularity::kScrollByPrecisePixel;
- gfx::Vector2dF last_scroll_delta = last_scroll_state.DeltaOrHint();
- std::unique_ptr<SnapSelectionStrategy> strategy;
- if (imprecise_wheel_scrolling && !last_scroll_delta.IsZero() &&
- reason == SnapReason::kScrollOffsetAnimationFinished) {
- // This was an imprecise wheel scroll so use direction snapping.
- // Note: gesture scroll end is delayed in anticipation of future wheel
- // scrolls so it is fired well after the scroll ends as opposed to precise
- // touch devices where we fire it as soon as the user lifts their finger.
- // TODO(crbug.com/1201678): The directional scroll should probably be
- // triggered at gesture scroll begin to improve responsiveness.
- strategy = SnapSelectionStrategy::CreateForDirection(
- current_position, last_scroll_delta, true);
- } else {
- strategy = SnapSelectionStrategy::CreateForEndPosition(
- current_position, did_scroll_x_for_scroll_gesture_,
- did_scroll_y_for_scroll_gesture_);
- }
- gfx::PointF snap_position;
- TargetSnapAreaElementIds snap_target_ids;
- if (!data.FindSnapPosition(*strategy, &snap_position, &snap_target_ids))
- return false;
- // TODO(bokan): Why only on the viewport?
- if (GetViewport().ShouldScroll(*scroll_node)) {
- compositor_delegate_.WillScrollContent(scroll_node->element_id);
- }
- gfx::Vector2dF delta = snap_position - current_position;
- bool did_animate = false;
- if (scroll_node->scrolls_outer_viewport) {
- gfx::Vector2dF scaled_delta(delta);
- scaled_delta.Scale(compositor_delegate_.PageScaleFactor());
- gfx::Vector2dF consumed_delta =
- GetViewport().ScrollAnimated(scaled_delta, base::TimeDelta());
- did_animate = !consumed_delta.IsZero();
- } else {
- did_animate =
- compositor_delegate_.GetImplDeprecated().ScrollAnimationCreate(
- *scroll_node, delta, base::TimeDelta());
- }
- DCHECK(!IsAnimatingForSnap());
- if (did_animate) {
- // The snap target will be set when the animation is completed.
- scroll_animating_snap_target_ids_ = snap_target_ids;
- } else if (data.SetTargetSnapAreaElementIds(snap_target_ids)) {
- updated_snapped_elements_[scroll_node->element_id] = snap_target_ids;
- SetNeedsCommit();
- }
- return did_animate;
- }
- bool InputHandler::IsAnimatingForSnap() const {
- return scroll_animating_snap_target_ids_ != TargetSnapAreaElementIds();
- }
- gfx::PointF InputHandler::GetVisualScrollOffset(
- const ScrollNode& scroll_node) const {
- if (scroll_node.scrolls_outer_viewport)
- return GetViewport().TotalScrollOffset();
- return GetScrollTree().current_scroll_offset(scroll_node.element_id);
- }
- void InputHandler::ClearCurrentlyScrollingNode() {
- TRACE_EVENT0("cc", "InputHandler::ClearCurrentlyScrollingNode");
- ActiveTree().ClearCurrentlyScrollingNode();
- accumulated_root_overscroll_ = gfx::Vector2dF();
- did_scroll_x_for_scroll_gesture_ = false;
- did_scroll_y_for_scroll_gesture_ = false;
- delta_consumed_for_scroll_gesture_ = false;
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- latched_scroll_type_.reset();
- last_scroll_update_state_.reset();
- last_scroll_begin_state_.reset();
- compositor_delegate_.DidEndScroll();
- }
- bool InputHandler::ScrollAnimationUpdateTarget(
- const ScrollNode& scroll_node,
- const gfx::Vector2dF& scroll_delta,
- base::TimeDelta delayed_by) {
- // TODO(bokan): Remove |scroll_node| as a parameter and just use the value
- // coming from |mutator_host|.
- DCHECK_EQ(scroll_node.element_id, compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ImplOnlyScrollAnimatingElement());
- float scale_factor = compositor_delegate_.PageScaleFactor();
- gfx::Vector2dF adjusted_delta =
- gfx::ScaleVector2d(scroll_delta, 1.f / scale_factor);
- adjusted_delta = UserScrollableDelta(scroll_node, adjusted_delta);
- bool animation_updated =
- compositor_delegate_.GetImplDeprecated()
- .mutator_host()
- ->ImplOnlyScrollAnimationUpdateTarget(
- adjusted_delta, GetScrollTree().MaxScrollOffset(scroll_node.id),
- compositor_delegate_.GetImplDeprecated()
- .CurrentBeginFrameArgs()
- .frame_time,
- delayed_by);
- if (animation_updated) {
- compositor_delegate_.DidUpdateScrollAnimationCurve();
- // The animation is no longer targeting a snap position. By clearing the
- // target, this will ensure that we attempt to resnap at the end of this
- // animation.
- scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
- }
- return animation_updated;
- }
- void InputHandler::UpdateScrollSourceInfo(const ScrollState& scroll_state,
- ui::ScrollInputType type) {
- if (type == ui::ScrollInputType::kWheel &&
- scroll_state.delta_granularity() ==
- ui::ScrollGranularity::kScrollByPrecisePixel) {
- has_scrolled_by_precisiontouchpad_ = true;
- } else if (type == ui::ScrollInputType::kWheel) {
- has_scrolled_by_wheel_ = true;
- } else if (type == ui::ScrollInputType::kTouchscreen) {
- has_scrolled_by_touch_ = true;
- } else if (type == ui::ScrollInputType::kScrollbar) {
- has_scrolled_by_scrollbar_ = true;
- }
- }
- // Return true if scrollable node for 'ancestor' is the same as 'child' or an
- // ancestor along the scroll tree.
- bool InputHandler::IsScrolledBy(LayerImpl* child, ScrollNode* ancestor) {
- DCHECK(ancestor && ancestor->scrollable);
- if (!child)
- return false;
- DCHECK_EQ(child->layer_tree_impl(), &ActiveTree());
- ScrollTree& scroll_tree = GetScrollTree();
- for (ScrollNode* scroll_node = scroll_tree.Node(child->scroll_tree_index());
- scroll_node; scroll_node = scroll_tree.parent(scroll_node)) {
- if (scroll_node->id == ancestor->id)
- return true;
- }
- return false;
- }
- gfx::Vector2dF InputHandler::UserScrollableDelta(
- const ScrollNode& node,
- const gfx::Vector2dF& delta) const {
- gfx::Vector2dF adjusted_delta = delta;
- if (!node.user_scrollable_horizontal)
- adjusted_delta.set_x(0);
- if (!node.user_scrollable_vertical)
- adjusted_delta.set_y(0);
- return adjusted_delta;
- }
- bool InputHandler::ScrollbarScrollIsActive() {
- return scrollbar_controller_->ScrollbarScrollIsActive();
- }
- void InputHandler::SetDeferBeginMainFrame(bool defer_begin_main_frame) const {
- compositor_delegate_.SetDeferBeginMainFrame(defer_begin_main_frame);
- }
- } // namespace cc
|