0

[PDF Ink Signatures] Ignore inputs of a different type while stroking

Fix a crash where PdfInkModule::RecordStrokePosition() complains the
inputs are made with different tool types. Check the tool type and
ignore the event if the types are different.

Bug: 391387325
Change-Id: If5fec5a9ca5e4d2aa3a6d5c95f7194ba8a53e917
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6195922
Reviewed-by: Alan Screen <awscreen@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415108}
This commit is contained in:
Lei Zhang
2025-02-03 12:04:43 -08:00
committed by Chromium LUCI CQ
parent d18749f475
commit e07c9618f6
2 changed files with 32 additions and 0 deletions

@ -516,6 +516,11 @@ bool PdfInkModule::ContinueStroke(const gfx::PointF& position,
return true;
}
if (state.input_last_event.value().tool_type != tool_type) {
// Ignore if the user is simultaneously using a different input type.
return true;
}
const int page_index = client_->VisiblePageIndexFromPoint(position);
const int last_page_index = client_->VisiblePageIndexFromPoint(last_position);
if (page_index != state.page_index && last_page_index != state.page_index) {

@ -1262,6 +1262,33 @@ TEST_F(PdfInkModuleStrokeTest, AnnotationWithMouseInterruptedByPenEvents) {
/*page_index=*/0, ink::StrokeInput::ToolType::kStylus));
}
TEST_F(PdfInkModuleStrokeTest, AnnotationWithPenIgnoresMouseEvents) {
EnableAnnotationMode();
InitializeSimpleSinglePageBasicLayout();
blink::WebTouchEvent pen_start_event =
CreatePenEvent(blink::WebInputEvent::Type::kTouchStart,
base::span_from_ref(kMouseDownPoint));
EXPECT_TRUE(ink_module().HandleInputEvent(pen_start_event));
blink::WebMouseEvent mouse_move_event =
CreateMouseMoveWithLeftButtonEventAtPoint(kMouseMovePoint);
EXPECT_TRUE(ink_module().HandleInputEvent(mouse_move_event));
blink::WebTouchEvent pen_end_event =
CreatePenEvent(blink::WebInputEvent::Type::kTouchEnd,
base::span_from_ref(kMouseUpPoint));
EXPECT_TRUE(ink_module().HandleInputEvent(pen_end_event));
EXPECT_EQ(1, client().stroke_finished_count());
EXPECT_EQ(0, ink_module().GetInputOfTypeCountForPageForTesting(
/*page_index=*/0, ink::StrokeInput::ToolType::kMouse));
EXPECT_EQ(0, ink_module().GetInputOfTypeCountForPageForTesting(
/*page_index=*/0, ink::StrokeInput::ToolType::kTouch));
EXPECT_EQ(2, ink_module().GetInputOfTypeCountForPageForTesting(
/*page_index=*/0, ink::StrokeInput::ToolType::kStylus));
}
TEST_F(PdfInkModuleStrokeTest, CanonicalAnnotationPoints) {
// Setup to support examining the page stroke points for a layout that is
// more complicated than what is provide by