Move PdfViewPluginBase::HandleInputEvent() into PdfViewWebPlugin.
Consolidate input event handling code in PdfViewWebPlugin. Though
HandleInputEvent() gets renamed to avoid confusion, as PdfViewWebPlugin
has a method of the same name.
Bug: 1302059
Change-Id: I6a4755048d0c8a7e4021da3d280fff413549cc74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3814942
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1033634}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c34ca96951
commit
1548d2aa83
@ -274,34 +274,6 @@ void PdfViewPluginBase::DocumentFocusChanged(bool document_has_focus) {
|
||||
SendMessage(std::move(message));
|
||||
}
|
||||
|
||||
bool PdfViewPluginBase::HandleInputEvent(const blink::WebInputEvent& event) {
|
||||
// Ignore user input in read-only mode.
|
||||
if (engine()->IsReadOnly())
|
||||
return false;
|
||||
|
||||
// `engine()` expects input events in device coordinates.
|
||||
std::unique_ptr<blink::WebInputEvent> transformed_event =
|
||||
ui::TranslateAndScaleWebInputEvent(
|
||||
event, gfx::Vector2dF(-available_area_.x() / device_scale(), 0),
|
||||
device_scale());
|
||||
|
||||
const blink::WebInputEvent& event_to_handle =
|
||||
transformed_event ? *transformed_event : event;
|
||||
|
||||
if (engine()->HandleInputEvent(event_to_handle))
|
||||
return true;
|
||||
|
||||
// Middle click is used for scrolling and is handled by the container page.
|
||||
if (blink::WebInputEvent::IsMouseEventType(event_to_handle.GetType()) &&
|
||||
static_cast<const blink::WebMouseEvent&>(event_to_handle).button ==
|
||||
blink::WebPointerProperties::Button::kMiddle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true for unhandled clicks so the plugin takes focus.
|
||||
return event_to_handle.GetType() == blink::WebInputEvent::Type::kMouseDown;
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::SendLoadingProgress(double percentage) {
|
||||
DCHECK(percentage == -1 || (percentage >= 0 && percentage <= 100));
|
||||
last_progress_sent_ = percentage;
|
||||
|
@ -26,10 +26,6 @@
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
} // namespace blink
|
||||
|
||||
namespace gfx {
|
||||
class PointF;
|
||||
class Vector2d;
|
||||
@ -139,8 +135,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
// Runs when document load completes.
|
||||
virtual void OnDocumentLoadComplete() = 0;
|
||||
|
||||
bool HandleInputEvent(const blink::WebInputEvent& event);
|
||||
|
||||
// Enqueues a "message" event carrying `message` to the embedder. Messages are
|
||||
// guaranteed to be received in the order that they are sent. This method is
|
||||
// non-blocking.
|
||||
|
@ -542,7 +542,7 @@ void PdfViewWebPlugin::UpdateFocus(bool focused,
|
||||
blink::WebKeyboardEvent simulated_event(blink::WebInputEvent::Type::kKeyDown,
|
||||
modifiers, base::TimeTicks());
|
||||
simulated_event.windows_key_code = ui::KeyboardCode::VKEY_TAB;
|
||||
PdfViewPluginBase::HandleInputEvent(simulated_event);
|
||||
HandleWebInputEvent(simulated_event);
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::UpdateVisibility(bool visibility) {}
|
||||
@ -552,8 +552,8 @@ blink::WebInputEventResult PdfViewWebPlugin::HandleInputEvent(
|
||||
ui::Cursor* cursor) {
|
||||
// TODO(crbug.com/1302059): The input events received by the Pepper plugin
|
||||
// already have the viewport-to-DIP scale applied. The scaling done here
|
||||
// should be moved into `PdfViewPluginBase::HandleInputEvent()` once the
|
||||
// Pepper plugin is removed.
|
||||
// should be moved into `HandleWebInputEvent()` once the Pepper plugin is
|
||||
// removed.
|
||||
std::unique_ptr<blink::WebInputEvent> scaled_event =
|
||||
ui::ScaleWebInputEvent(event.Event(), viewport_to_dip_scale_);
|
||||
|
||||
@ -561,7 +561,7 @@ blink::WebInputEventResult PdfViewWebPlugin::HandleInputEvent(
|
||||
scaled_event ? *scaled_event : event.Event();
|
||||
|
||||
const blink::WebInputEventResult result =
|
||||
PdfViewPluginBase::HandleInputEvent(event_to_handle)
|
||||
HandleWebInputEvent(event_to_handle)
|
||||
? blink::WebInputEventResult::kHandledApplication
|
||||
: blink::WebInputEventResult::kNotHandled;
|
||||
|
||||
@ -1687,6 +1687,34 @@ bool PdfViewWebPlugin::Redo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PdfViewWebPlugin::HandleWebInputEvent(const blink::WebInputEvent& event) {
|
||||
// Ignore user input in read-only mode.
|
||||
if (engine_->IsReadOnly())
|
||||
return false;
|
||||
|
||||
// `engine_` expects input events in device coordinates.
|
||||
std::unique_ptr<blink::WebInputEvent> transformed_event =
|
||||
ui::TranslateAndScaleWebInputEvent(
|
||||
event, gfx::Vector2dF(-available_area().x() / device_scale(), 0),
|
||||
device_scale());
|
||||
|
||||
const blink::WebInputEvent& event_to_handle =
|
||||
transformed_event ? *transformed_event : event;
|
||||
|
||||
if (engine_->HandleInputEvent(event_to_handle))
|
||||
return true;
|
||||
|
||||
// Middle click is used for scrolling and is handled by the container page.
|
||||
if (blink::WebInputEvent::IsMouseEventType(event_to_handle.GetType()) &&
|
||||
static_cast<const blink::WebMouseEvent&>(event_to_handle).button ==
|
||||
blink::WebPointerProperties::Button::kMiddle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true for unhandled clicks so the plugin takes focus.
|
||||
return event_to_handle.GetType() == blink::WebInputEvent::Type::kMouseDown;
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::HandleImeCommit(const blink::WebString& text) {
|
||||
if (text.IsEmpty())
|
||||
return;
|
||||
|
@ -46,6 +46,7 @@
|
||||
|
||||
namespace blink {
|
||||
class WebAssociatedURLLoader;
|
||||
class WebInputEvent;
|
||||
class WebURL;
|
||||
class WebURLRequest;
|
||||
struct WebAssociatedURLLoaderOptions;
|
||||
@ -452,6 +453,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
bool Undo();
|
||||
bool Redo();
|
||||
|
||||
bool HandleWebInputEvent(const blink::WebInputEvent& event);
|
||||
|
||||
// Helper method for converting IME text to input events.
|
||||
// TODO(crbug.com/1253665): Consider handling composition events.
|
||||
void HandleImeCommit(const blink::WebString& text);
|
||||
|
Reference in New Issue
Block a user