[unseasoned-pdf] Derive PdfViewWebPlugin from pdf::mojom::PdfListener
The interface needs to be implemented to properly handle some touch selection events coming from the browser process. This allows more opportunity for shared code between the Pepper and Pepper-free plugins. Meanwhile fix more plugin offset issues that arose from the PDF Viewer update. Bug: 1270502 Fixed: 1277678 Change-Id: I4c68904db9e6e53a4e20aad1c3ee9aa2381bca65 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2979824 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/main@{#949394}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9fa17c860f
commit
00eb8f5066
@ -526,32 +526,18 @@ void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetCaretPosition(const pp::FloatPoint& position) {
|
||||
pp::Point new_position(position.x(), position.y());
|
||||
ScalePoint(device_scale(), &new_position);
|
||||
new_position.set_x(new_position.x() - available_area().x());
|
||||
engine()->SetCaretPosition(PointFromPPPoint(new_position));
|
||||
PdfViewPluginBase::SetCaretPosition(PointFFromPPFloatPoint(position));
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::MoveRangeSelectionExtent(
|
||||
const pp::FloatPoint& extent) {
|
||||
pp::Point new_extent(extent.x(), extent.y());
|
||||
ScalePoint(device_scale(), &new_extent);
|
||||
new_extent.set_x(new_extent.x() - available_area().x());
|
||||
engine()->MoveRangeSelectionExtent(PointFromPPPoint(new_extent));
|
||||
PdfViewPluginBase::MoveRangeSelectionExtent(PointFFromPPFloatPoint(extent));
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetSelectionBounds(const pp::FloatPoint& base,
|
||||
const pp::FloatPoint& extent) {
|
||||
pp::Point new_base_point(base.x(), base.y());
|
||||
ScalePoint(device_scale(), &new_base_point);
|
||||
new_base_point.set_x(new_base_point.x() - available_area().x());
|
||||
|
||||
pp::Point new_extent_point(extent.x(), extent.y());
|
||||
ScalePoint(device_scale(), &new_extent_point);
|
||||
new_extent_point.set_x(new_extent_point.x() - available_area().x());
|
||||
|
||||
engine()->SetSelectionBounds(PointFromPPPoint(new_base_point),
|
||||
PointFromPPPoint(new_extent_point));
|
||||
PdfViewPluginBase::SetSelectionBounds(PointFFromPPFloatPoint(base),
|
||||
PointFFromPPFloatPoint(extent));
|
||||
}
|
||||
|
||||
pp::Var OutOfProcessInstance::GetLinkAtPosition(const pp::Point& point) {
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include "ui/base/text/bytes_formatting.h"
|
||||
#include "ui/events/blink/blink_event_util.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/point_conversions.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
@ -1016,6 +1017,20 @@ int PdfViewPluginBase::GetDocumentPixelHeight() const {
|
||||
std::ceil(document_size_.height() * zoom() * device_scale()));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::SetCaretPosition(const gfx::PointF& position) {
|
||||
engine()->SetCaretPosition(FrameToPdfCoordinates(position));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::MoveRangeSelectionExtent(const gfx::PointF& extent) {
|
||||
engine()->MoveRangeSelectionExtent(FrameToPdfCoordinates(extent));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::SetSelectionBounds(const gfx::PointF& base,
|
||||
const gfx::PointF& extent) {
|
||||
engine()->SetSelectionBounds(FrameToPdfCoordinates(base),
|
||||
FrameToPdfCoordinates(extent));
|
||||
}
|
||||
|
||||
void PdfViewPluginBase::PrepareAndSetAccessibilityPageInfo(int32_t page_index) {
|
||||
// Outdated calls are ignored.
|
||||
if (page_index != next_accessibility_page_index_)
|
||||
@ -1801,4 +1816,12 @@ void PdfViewPluginBase::LoadNextPreviewPage() {
|
||||
SendPrintPreviewLoadedNotification();
|
||||
}
|
||||
|
||||
gfx::Point PdfViewPluginBase::FrameToPdfCoordinates(
|
||||
const gfx::PointF& frame_coordinates) const {
|
||||
return gfx::ToFlooredPoint(
|
||||
gfx::ScalePoint(frame_coordinates, device_scale_)) -
|
||||
plugin_rect_.OffsetFromOrigin() -
|
||||
gfx::Vector2d(available_area_.x(), 0);
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -296,6 +296,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
int GetDocumentPixelWidth() const;
|
||||
int GetDocumentPixelHeight() const;
|
||||
|
||||
// Common `pdf::mojom::PdfListener` implementations.
|
||||
void SetCaretPosition(const gfx::PointF& position);
|
||||
void MoveRangeSelectionExtent(const gfx::PointF& extent);
|
||||
void SetSelectionBounds(const gfx::PointF& base, const gfx::PointF& extent);
|
||||
|
||||
// Sets the text input type for this plugin based on `in_focus`.
|
||||
virtual void SetFormTextFieldInFocus(bool in_focus) = 0;
|
||||
|
||||
@ -532,6 +537,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
// Called after a preview page has loaded or failed to load.
|
||||
void LoadNextPreviewPage();
|
||||
|
||||
// Converts `frame_coordinates` to PDF coordinates.
|
||||
gfx::Point FrameToPdfCoordinates(const gfx::PointF& frame_coordinates) const;
|
||||
|
||||
std::unique_ptr<PDFiumEngine> engine_;
|
||||
PaintManager paint_manager_{this};
|
||||
|
||||
|
@ -273,7 +273,11 @@ PdfViewWebPlugin::PdfViewWebPlugin(
|
||||
pdf_service_remote_(std::move(pdf_service_remote)),
|
||||
initial_params_(params),
|
||||
pdf_accessibility_data_handler_(
|
||||
client_->CreateAccessibilityDataHandler(this)) {}
|
||||
client_->CreateAccessibilityDataHandler(this)) {
|
||||
auto* service = GetPdfService();
|
||||
if (service)
|
||||
service->SetListener(listener_receiver_.BindNewPipeAndPassRemote());
|
||||
}
|
||||
|
||||
PdfViewWebPlugin::~PdfViewWebPlugin() = default;
|
||||
|
||||
@ -741,6 +745,19 @@ void PdfViewWebPlugin::ScheduleTaskOnMainThread(const base::Location& from_here,
|
||||
from_here, base::BindOnce(std::move(callback), result), delay);
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::SetCaretPosition(const gfx::PointF& position) {
|
||||
PdfViewPluginBase::SetCaretPosition(position);
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::MoveRangeSelectionExtent(const gfx::PointF& extent) {
|
||||
PdfViewPluginBase::MoveRangeSelectionExtent(extent);
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::SetSelectionBounds(const gfx::PointF& base,
|
||||
const gfx::PointF& extent) {
|
||||
PdfViewPluginBase::SetSelectionBounds(base, extent);
|
||||
}
|
||||
|
||||
bool PdfViewWebPlugin::IsValid() const {
|
||||
return container_wrapper_ && container_wrapper_->GetFrame();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "cc/paint/paint_image.h"
|
||||
#include "mojo/public/cpp/bindings/associated_remote.h"
|
||||
#include "mojo/public/cpp/bindings/receiver.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "pdf/mojom/pdf.mojom.h"
|
||||
#include "pdf/pdf_accessibility_action_handler.h"
|
||||
@ -57,6 +58,7 @@ class PdfAccessibilityDataHandler;
|
||||
// Skeleton for a `blink::WebPlugin` to replace `OutOfProcessInstance`.
|
||||
class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
public blink::WebPlugin,
|
||||
public pdf::mojom::PdfListener,
|
||||
public BlinkUrlLoader::Client,
|
||||
public PostMessageReceiver::Client,
|
||||
public SkiaGraphics::Client,
|
||||
@ -242,6 +244,12 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
int32_t result,
|
||||
base::TimeDelta delay) override;
|
||||
|
||||
// pdf::mojom::PdfListener:
|
||||
void SetCaretPosition(const gfx::PointF& position) override;
|
||||
void MoveRangeSelectionExtent(const gfx::PointF& extent) override;
|
||||
void SetSelectionBounds(const gfx::PointF& base,
|
||||
const gfx::PointF& extent) override;
|
||||
|
||||
// BlinkUrlLoader::Client:
|
||||
bool IsValid() const override;
|
||||
blink::WebURL CompleteURL(const blink::WebString& partial_url) const override;
|
||||
@ -368,6 +376,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
// Used to access find-in-page interface provided by the PDF extension.
|
||||
mojo::Remote<pdf::mojom::PdfFindInPage> find_remote_;
|
||||
|
||||
mojo::Receiver<pdf::mojom::PdfListener> listener_receiver_{this};
|
||||
|
||||
// The id of the current find operation, or -1 if no current operation is
|
||||
// present.
|
||||
int find_identifier_ = -1;
|
||||
|
Reference in New Issue
Block a user