[unseasoned-pdf] Handle kKeyDown events
Fixes PDFiumEngine to handle kKeyDown events. Blink mostly sends kRawKeyDown events, so we erroneously assumed that we didn't have to handle kKeyDown events. For example, Blink sends kKeyDown events when tabbing between cross-site frames. Since we now handle kKeyDown and kRawKeyDown uniformly in PDFiumEngine, this change also removes the special handling for this case in pdf/ppapi_migration/input_event_conversions.cc. (Pepper will never send PP_INPUTEVENT_TYPE_RAWKEYDOWN, but the code is simpler this way.) Fixed: 1234559 Change-Id: I92801660e07fcd85ac4f705f869cc0077b67223c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169460 Commit-Queue: K. Moon <kmoon@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/main@{#922730}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
fecb0181be
commit
5fc6382e5a
pdf
@ -946,6 +946,10 @@ bool PDFiumEngine::HandleInputEvent(const blink::WebInputEvent& event) {
|
||||
case blink::WebInputEvent::Type::kMouseEnter:
|
||||
OnMouseEnter(static_cast<const blink::WebMouseEvent&>(event));
|
||||
break;
|
||||
case blink::WebInputEvent::Type::kKeyDown:
|
||||
// Blink mostly sends `kRawKeyDown`, but sometimes generates `kKeyDown`,
|
||||
// such as when tabbing between frames. Pepper treats them equivalently
|
||||
// (see content/renderer/pepper/event_conversion.cc), so we will, too.
|
||||
case blink::WebInputEvent::Type::kRawKeyDown:
|
||||
rv = OnKeyDown(static_cast<const blink::WebKeyboardEvent&>(event));
|
||||
break;
|
||||
|
@ -29,8 +29,10 @@
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/input/web_input_event.h"
|
||||
#include "third_party/blink/public/common/input/web_keyboard_event.h"
|
||||
#include "third_party/blink/public/common/input/web_mouse_event.h"
|
||||
#include "third_party/blink/public/common/input/web_pointer_properties.h"
|
||||
#include "ui/events/keycodes/keyboard_codes.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
@ -77,6 +79,8 @@ class MockTestClient : public TestClient {
|
||||
int32_t result,
|
||||
base::TimeDelta delay),
|
||||
(override));
|
||||
MOCK_METHOD(void, DocumentFocusChanged, (bool), (override));
|
||||
MOCK_METHOD(void, SetLinkUnderCursor, (const std::string&), (override));
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -597,6 +601,35 @@ TEST_F(PDFiumEngineTest, RequestThumbnailLinearized) {
|
||||
initialize_result.FinishLoading();
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTest, HandleInputEventKeyDown) {
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine =
|
||||
InitializeEngine(&client, FILE_PATH_LITERAL("hello_world2.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
EXPECT_CALL(client, DocumentFocusChanged(true));
|
||||
|
||||
blink::WebKeyboardEvent key_down_event(
|
||||
blink::WebInputEvent::Type::kKeyDown, blink::WebInputEvent::kNoModifiers,
|
||||
blink::WebInputEvent::GetStaticTimeStampForTests());
|
||||
key_down_event.windows_key_code = ui::VKEY_TAB;
|
||||
EXPECT_TRUE(engine->HandleInputEvent(key_down_event));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTest, HandleInputEventRawKeyDown) {
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine =
|
||||
InitializeEngine(&client, FILE_PATH_LITERAL("hello_world2.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
EXPECT_CALL(client, DocumentFocusChanged(true));
|
||||
|
||||
blink::WebKeyboardEvent raw_key_down_event(
|
||||
blink::WebInputEvent::Type::kRawKeyDown,
|
||||
blink::WebInputEvent::kNoModifiers,
|
||||
blink::WebInputEvent::GetStaticTimeStampForTests());
|
||||
raw_key_down_event.windows_key_code = ui::VKEY_TAB;
|
||||
EXPECT_TRUE(engine->HandleInputEvent(raw_key_down_event));
|
||||
}
|
||||
|
||||
using PDFiumEngineDeathTest = PDFiumEngineTest;
|
||||
|
||||
TEST_F(PDFiumEngineDeathTest, RequestThumbnailRedundant) {
|
||||
@ -622,18 +655,6 @@ TEST_F(PDFiumEngineDeathTest, RequestThumbnailRedundant) {
|
||||
/*page_index=*/1, /*device_pixel_ratio=*/1, mock_callback.Get()));
|
||||
}
|
||||
|
||||
class TabbingTestClient : public TestClient {
|
||||
public:
|
||||
TabbingTestClient() = default;
|
||||
~TabbingTestClient() override = default;
|
||||
TabbingTestClient(const TabbingTestClient&) = delete;
|
||||
TabbingTestClient& operator=(const TabbingTestClient&) = delete;
|
||||
|
||||
// Mock PDFEngine::Client methods.
|
||||
MOCK_METHOD(void, DocumentFocusChanged, (bool), (override));
|
||||
MOCK_METHOD(void, SetLinkUnderCursor, (const std::string&), (override));
|
||||
};
|
||||
|
||||
class PDFiumEngineTabbingTest : public PDFiumTestBase {
|
||||
public:
|
||||
PDFiumEngineTabbingTest() = default;
|
||||
@ -690,7 +711,7 @@ TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorTest) {
|
||||
scoped_feature_list.InitAndEnableFeature(
|
||||
chrome_pdf::features::kTabAcrossPDFAnnotations);
|
||||
|
||||
TabbingTestClient client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine =
|
||||
InitializeEngine(&client, FILE_PATH_LITERAL("annots.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
@ -786,7 +807,7 @@ TEST_F(PDFiumEngineTabbingTest, TabbingForwardTest) {
|
||||
* ++ Page 2
|
||||
* ++++ Annotation
|
||||
*/
|
||||
NiceMock<TabbingTestClient> client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine = InitializeEngine(
|
||||
&client, FILE_PATH_LITERAL("annotation_form_fields.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
@ -838,7 +859,7 @@ TEST_F(PDFiumEngineTabbingTest, TabbingBackwardTest) {
|
||||
* ++ Page 2
|
||||
* ++++ Annotation
|
||||
*/
|
||||
NiceMock<TabbingTestClient> client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine = InitializeEngine(
|
||||
&client, FILE_PATH_LITERAL("annotation_form_fields.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
@ -945,7 +966,7 @@ TEST_F(PDFiumEngineTabbingTest, NoFocusableItemTabbingTest) {
|
||||
* ++ Page 1
|
||||
* ++ Page 2
|
||||
*/
|
||||
NiceMock<TabbingTestClient> client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine =
|
||||
InitializeEngine(&client, FILE_PATH_LITERAL("hello_world2.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
@ -994,7 +1015,7 @@ TEST_F(PDFiumEngineTabbingTest, RestoringDocumentFocusTest) {
|
||||
* ++ Page 2
|
||||
* ++++ Annotation
|
||||
*/
|
||||
NiceMock<TabbingTestClient> client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine = InitializeEngine(
|
||||
&client, FILE_PATH_LITERAL("annotation_form_fields.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
@ -1039,7 +1060,7 @@ TEST_F(PDFiumEngineTabbingTest, RestoringAnnotFocusTest) {
|
||||
* ++ Page 2
|
||||
* ++++ Annotation
|
||||
*/
|
||||
NiceMock<TabbingTestClient> client;
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine = InitializeEngine(
|
||||
&client, FILE_PATH_LITERAL("annotation_form_fields.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
|
@ -43,15 +43,9 @@ blink::WebInputEvent::Type GetWebInputEventType(PP_InputEvent_Type event_type) {
|
||||
case PP_INPUTEVENT_TYPE_WHEEL:
|
||||
return blink::WebInputEvent::Type::kMouseWheel;
|
||||
case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
|
||||
case PP_INPUTEVENT_TYPE_KEYDOWN:
|
||||
// Blink no longer passes `kKeyDown` events into plugins, and instead
|
||||
// passes `kRawKeyDown` events. However, `kRawKeyDown` gets mapped to
|
||||
// `PP_INPUTEVENT_TYPE_KEYDOWN` for backwards compatibility. Map both
|
||||
// Pepper enums to `kRawKeyDown` to allow for a common implementation
|
||||
// between the Pepper and Pepper-free plugins.
|
||||
// See the comments inside the definition of `ConvertEventTypes()` in
|
||||
// content/renderer/pepper/event_conversion.cc.
|
||||
return blink::WebInputEvent::Type::kRawKeyDown;
|
||||
case PP_INPUTEVENT_TYPE_KEYDOWN:
|
||||
return blink::WebInputEvent::Type::kKeyDown;
|
||||
case PP_INPUTEVENT_TYPE_KEYUP:
|
||||
return blink::WebInputEvent::Type::kKeyUp;
|
||||
case PP_INPUTEVENT_TYPE_CHAR:
|
||||
@ -164,6 +158,7 @@ std::unique_ptr<blink::WebInputEvent> GetWebInputEvent(
|
||||
case blink::WebInputEvent::Type::kMouseLeave:
|
||||
return GetWebMouseEvent(pp::MouseInputEvent(event));
|
||||
case blink::WebInputEvent::Type::kRawKeyDown:
|
||||
case blink::WebInputEvent::Type::kKeyDown:
|
||||
case blink::WebInputEvent::Type::kKeyUp:
|
||||
case blink::WebInputEvent::Type::kChar:
|
||||
return GetWebKeyboardEvent(pp::KeyboardInputEvent(event));
|
||||
|
Reference in New Issue
Block a user