Commit 711954ca authored by David Bokan's avatar David Bokan Committed by Commit Bot

[Cleanup] Use Optional for prior event dispositions

Small cleanup to avoid sentinel value and make the semantics and
lifetime clearer.

Bug: NONE
Change-Id: Icf22008e94aae436024d524a5d9eaeb5b9be63ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142514Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757933}
parent e584c102
......@@ -54,8 +54,6 @@ using perfetto::protos::pbzero::TrackEvent;
namespace {
const int32_t kEventDispositionUndefined = -1;
cc::ScrollState CreateScrollStateForGesture(const WebGestureEvent& event) {
cc::ScrollStateData scroll_state_data;
switch (event.GetType()) {
......@@ -185,8 +183,6 @@ InputHandlerProxy::InputHandlerProxy(cc::InputHandler* input_handler,
synchronous_input_handler_(nullptr),
handling_gesture_on_impl_thread_(false),
scroll_sequence_ignored_(false),
touch_result_(kEventDispositionUndefined),
mouse_wheel_result_(kEventDispositionUndefined),
current_overscroll_params_(nullptr),
has_seen_first_gesture_scroll_update_after_begin_(false),
last_injected_gesture_was_begin_(false),
......@@ -728,14 +724,15 @@ void InputHandlerProxy::RecordMainThreadScrollingReasons(
const bool is_compositor_scroll =
reasons == cc::MainThreadScrollingReason::kNotScrollingOnMain;
int32_t disposition =
base::Optional<EventDisposition> disposition =
(device == blink::WebGestureDevice::kTouchpad ? mouse_wheel_result_
: touch_result_);
// Scrolling can be handled on the compositor thread but it might be blocked
// on the main thread waiting for non-passive event handlers to process the
// wheel/touch events (i.e. were they preventDefaulted?).
bool blocked_on_main_thread_handler = disposition == DID_NOT_HANDLE;
bool blocked_on_main_thread_handler =
disposition.has_value() && disposition == DID_NOT_HANDLE;
auto scroll_start_state = RecordScrollingThread(
is_compositor_scroll, blocked_on_main_thread_handler, device);
......@@ -812,18 +809,19 @@ InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel(
// Noncancellable wheel events should have phase info.
DCHECK(wheel_event.phase != WebMouseWheelEvent::kPhaseNone ||
wheel_event.momentum_phase != WebMouseWheelEvent::kPhaseNone);
DCHECK(mouse_wheel_result_.has_value());
result = static_cast<EventDisposition>(mouse_wheel_result_);
result = mouse_wheel_result_.value();
if (wheel_event.phase == WebMouseWheelEvent::kPhaseEnded ||
wheel_event.phase == WebMouseWheelEvent::kPhaseCancelled ||
wheel_event.momentum_phase == WebMouseWheelEvent::kPhaseEnded ||
wheel_event.momentum_phase == WebMouseWheelEvent::kPhaseCancelled) {
mouse_wheel_result_ = kEventDispositionUndefined;
}
if (mouse_wheel_result_ != kEventDispositionUndefined)
mouse_wheel_result_.reset();
} else {
return result;
}
}
gfx::PointF position_in_widget = wheel_event.PositionInWidget();
if (input_handler_->HasBlockingWheelEventHandlerAt(
......@@ -1093,8 +1091,8 @@ InputHandlerProxy::EventDisposition InputHandlerProxy::HitTestTouchEvent(
// Merge |touch_result_| and |result| so the result has the highest
// priority value according to the sequence; (DROP_EVENT,
// DID_HANDLE_NON_BLOCKING, DID_NOT_HANDLE).
if (touch_result_ == kEventDispositionUndefined ||
touch_result_ == DROP_EVENT || result == DID_NOT_HANDLE)
if (!touch_result_.has_value() || touch_result_ == DROP_EVENT ||
result == DID_NOT_HANDLE)
touch_result_ = result;
return result;
}
......@@ -1140,7 +1138,7 @@ InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchMove(
const blink::WebTouchEvent& touch_event) {
// Hit test if this is the first touch move or we don't have any results
// from a previous hit test.
if (touch_result_ == kEventDispositionUndefined ||
if (!touch_result_.has_value() ||
touch_event.touch_start_or_first_touch_move) {
bool is_touching_scrolling_layer;
cc::TouchAction white_listed_touch_action = cc::TouchAction::kAuto;
......@@ -1150,13 +1148,13 @@ InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchMove(
white_listed_touch_action, touch_event.unique_touch_event_id, result);
return result;
}
return static_cast<EventDisposition>(touch_result_);
return touch_result_.value();
}
InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchEnd(
const blink::WebTouchEvent& touch_event) {
if (touch_event.touches_length == 1)
touch_result_ = kEventDispositionUndefined;
touch_result_.reset();
return DID_NOT_HANDLE;
}
......
......@@ -210,14 +210,16 @@ class InputHandlerProxy : public cc::InputHandlerClient,
std::unique_ptr<InputScrollElasticityController>
scroll_elasticity_controller_;
// The merged result of the last touch event with previous touch events.
// This value will get returned for subsequent TouchMove events to allow
// passive events not to block scrolling.
int32_t touch_result_;
// The result of the last mouse wheel event. This value is used to determine
// whether the next wheel scroll is blocked on the Main thread or not.
int32_t mouse_wheel_result_;
// The merged result of the last touch event with previous touch events
// within a single touch sequence. This value will get returned for
// subsequent TouchMove events to allow passive events not to block
// scrolling.
base::Optional<EventDisposition> touch_result_;
// The result of the last mouse wheel event in a wheel phase sequence. This
// value is used to determine whether the next wheel scroll is blocked on the
// Main thread or not.
base::Optional<EventDisposition> mouse_wheel_result_;
// Used to record overscroll notifications while an event is being
// dispatched. If the event causes overscroll, the overscroll metadata is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment