blob: 15f1a6a025092c7bdba6f0bd60b705c2be462232 [file] [log] [blame]
// Copyright 2018 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 "ui/compositor/overscroll/scroll_input_handler.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
#include "ui/events/types/scroll_input_type.h"
namespace ui {
namespace {
// Creates a cc::ScrollState from a ui::ScrollEvent, populating fields general
// to all event phases. Take care not to put deltas on beginning/end updates,
// since InputHandler will DCHECK if they're present.
cc::ScrollState CreateScrollState(const ScrollEvent& scroll, bool is_begin) {
cc::ScrollStateData scroll_state_data;
scroll_state_data.position_x = scroll.x();
scroll_state_data.position_y = scroll.y();
if (is_begin) {
scroll_state_data.delta_x_hint = -scroll.x_offset_ordinal();
scroll_state_data.delta_y_hint = -scroll.y_offset_ordinal();
} else {
scroll_state_data.delta_x = -scroll.x_offset_ordinal();
scroll_state_data.delta_y = -scroll.y_offset_ordinal();
scroll_state_data.is_in_inertial_phase =
scroll.momentum_phase() == EventMomentumPhase::INERTIAL_UPDATE;
scroll_state_data.is_ending = false;
scroll_state_data.is_beginning = is_begin;
return cc::ScrollState(scroll_state_data);
} // namespace
const base::WeakPtr<cc::InputHandler>& input_handler)
: input_handler_weak_ptr_(input_handler) {
ScrollInputHandler::~ScrollInputHandler() {
<< "Pointer invalidated before WillShutdown() is called.";
bool ScrollInputHandler::OnScrollEvent(const ScrollEvent& event,
Layer* layer_to_scroll) {
if (!input_handler_weak_ptr_)
return false;
// TODO(bokan): This code would ideally call Begin once at the beginning of a
// gesture and End once at the end of it. Unfortunately, the phase data is
// incomplete (only momentum phase is set and in a reduced way, e.g. we get
// an end when we transition to a fling). See the TODOs in and
// ui/events/ Until those are fixed, there's no harm in simply
// treating each event as a gesture unto itself.
cc::ScrollState scroll_state_begin = CreateScrollState(event, true);>set_current_native_scrolling_element(
// Note: the WHEEL type covers both actual wheels as well as trackpad
// scrolling.
cc::InputHandler::ScrollStatus result = input_handler_weak_ptr_->ScrollBegin(
&scroll_state_begin, ui::ScrollInputType::kWheel);
// Falling back to the main thread should never be required when an explicit
// ElementId is provided.
cc::ScrollState scroll_state = CreateScrollState(event, false);
input_handler_weak_ptr_->ScrollUpdate(&scroll_state, base::TimeDelta());
return true;
void ScrollInputHandler::WillShutdown() {
void ScrollInputHandler::Animate(base::TimeTicks time) {}
void ScrollInputHandler::ReconcileElasticOverscrollAndRootScroll() {}
void ScrollInputHandler::UpdateRootLayerStateForSynchronousInputHandler(
const gfx::ScrollOffset& total_scroll_offset,
const gfx::ScrollOffset& max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
float max_page_scale_factor) {}
void ScrollInputHandler::DeliverInputForBeginFrame(
const viz::BeginFrameArgs& args) {}
void ScrollInputHandler::DeliverInputForHighLatencyMode() {}
} // namespace ui