Commit 918b4f88 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by Commit Bot

Disable stylus barrel button for a brief period after pen up.

This should prevent metalayer triggering when a user is
writing/sketching while accidentally holding down the stylus button.

Bug: 767440
Test: ash_unittests --gtest_filter=PaletteTrayTest*
Change-Id: I98a1dc4be2bb888c6cc06e3e93a60b73b56c6a8d
Reviewed-on: https://chromium-review.googlesource.com/683254
Commit-Queue: Vladislav Kaznacheev <kaznacheev@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504419}
parent 20398b86
This diff is collapsed.
......@@ -28,6 +28,10 @@ namespace {
const char kToastId[] = "palette_metalayer_mode";
const int kToastDurationMs = 2500;
// If the last stroke happened within this amount of time,
// assume writing/sketching usage.
const int kMaxStrokeGapWhenWritingMs = 1000;
} // namespace
MetalayerMode::MetalayerMode(Delegate* delegate)
......@@ -92,9 +96,21 @@ void MetalayerMode::OnTouchEvent(ui::TouchEvent* event) {
ui::EventPointerType::POINTER_TYPE_PEN)
return;
if (event->type() == ui::ET_TOUCH_RELEASED) {
previous_stroke_end_ = event->time_stamp();
return;
}
if (event->type() != ui::ET_TOUCH_PRESSED)
return;
if (event->time_stamp() - previous_stroke_end_ <
base::TimeDelta::FromMilliseconds(kMaxStrokeGapWhenWritingMs)) {
// The press is happening too soon after the release, the user is most
// likely writing/sketching and does not want the metalayer to activate.
return;
}
// The stylus "barrel" button press is encoded as ui::EF_LEFT_MOUSE_BUTTON
if (!(event->flags() & ui::EF_LEFT_MOUSE_BUTTON))
return;
......
......@@ -83,6 +83,8 @@ class ASH_EXPORT MetalayerMode : public CommonPaletteTool,
bool voice_interaction_context_enabled_ = false;
base::TimeTicks previous_stroke_end_;
base::WeakPtrFactory<MetalayerMode> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MetalayerMode);
......
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