0

Reset cursor type when PDF Viewer enters presentation mode

Change PdfViewWebPlugin::HandleSetPresentationModeMessage() to reset the
cursor type when entering presentation mode. This prevents presentation
mode from being stuck with the most recently used cursor, which may be a
cursor used when editing.

Add a test case for HandleSetPresentationModeMessage() to check this
behavior and backfill a missing test to check PDFiumEngine correctly
enters read-only mode. Add some test-only accessors to PdfViewWebPlugin
to support this test.

Bug: 383029258
Change-Id: Ieef1a4b93ef1045c454d4826cf348ffb6b90d6f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6082220
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1395530}
This commit is contained in:
Lei Zhang
2024-12-12 11:25:25 -08:00
committed by Chromium LUCI CQ
parent a313e630df
commit df5b4a85ff
3 changed files with 36 additions and 1 deletions

@ -1771,7 +1771,12 @@ void PdfViewWebPlugin::HandleSetBackgroundColorMessage(
void PdfViewWebPlugin::HandleSetPresentationModeMessage(
const base::Value::Dict& message) {
engine_->SetReadOnly(message.FindBool("enablePresentationMode").value());
const bool presentation_mode =
message.FindBool("enablePresentationMode").value();
engine_->SetReadOnly(presentation_mode);
if (presentation_mode) {
cursor_ = ui::mojom::CursorType::kPointer;
}
}
void PdfViewWebPlugin::HandleSetTwoUpViewMessage(

@ -447,6 +447,11 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
return document_load_state_;
}
void set_cursor_type_for_testing(ui::mojom::CursorType cursor_type) {
cursor_ = cursor_type;
}
const ui::Cursor& cursor_for_testing() const { return cursor_; }
int GetContentRestrictionsForTesting() const {
return GetContentRestrictions();
}

@ -1452,6 +1452,31 @@ TEST_F(PdfViewWebPluginTest, HandleSetBackgroundColorMessage) {
EXPECT_EQ(SK_ColorGREEN, plugin_->GetBackgroundColor());
}
TEST_F(PdfViewWebPluginTest, HandleSetPresentationModeMessage) {
EXPECT_FALSE(engine_ptr_->IsReadOnly());
plugin_->set_cursor_type_for_testing(ui::mojom::CursorType::kIBeam);
base::Value::Dict message;
message.Set("type", "setPresentationMode");
message.Set("enablePresentationMode", true);
plugin_->OnMessage(message);
// After entering presentation mode, PDFiumEngine is read-only and the cursor
// type has been reset to a pointer.
EXPECT_TRUE(engine_ptr_->IsReadOnly());
EXPECT_EQ(ui::mojom::CursorType::kPointer,
plugin_->cursor_for_testing().type());
message.Set("enablePresentationMode", false);
plugin_->OnMessage(message);
// After exiting presentation mode, PDFiumEngine is no longer read-only.
// The cursor remains as a pointer until the next input event updates it.
EXPECT_FALSE(engine_ptr_->IsReadOnly());
EXPECT_EQ(ui::mojom::CursorType::kPointer,
plugin_->cursor_for_testing().type());
}
TEST_F(PdfViewWebPluginTest, HandleInputEvent) {
UpdatePluginGeometryWithoutWaiting(2.0f, {0, 0, 20, 20});