Skip to content

Commit

Permalink
Migrate OnGeometryChanged(), SetZoom(), kMinZoom to PdfViewPluginBase.
Browse files Browse the repository at this point in the history
In OutOfProcessInstance, private methods OnGeometryChanged() and
SetZoom() and the local variable `kMinZoom` will be used for drawing
graphics by PdfViewWebPlugin in the future. This CL migrates these
methods to PdfViewPluginBase as protected methods and moves the
definition of `kMinZoom` to PdfViewPluginBase, so that they can be
shared by both plugin instances.

Bug: 1140629
Change-Id: I4016bf05871c2112b653ce0e043261c94580c534
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602518
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839461}
  • Loading branch information
Hui Yingst authored and Chromium LUCI CQ committed Dec 28, 2020
1 parent 3c00471 commit d758b98
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
8 changes: 0 additions & 8 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ constexpr int kInvalidPDFIndex = -2;
constexpr base::TimeDelta kAccessibilityPageDelay =
base::TimeDelta::FromMilliseconds(100);

constexpr double kMinZoom = 0.01;

constexpr char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;

PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
Expand Down Expand Up @@ -2228,12 +2226,6 @@ std::unique_ptr<UrlLoader> OutOfProcessInstance::CreateUrlLoaderInternal() {
return loader;
}

void OutOfProcessInstance::SetZoom(double scale) {
double old_zoom = zoom();
set_zoom(scale);
OnGeometryChanged(old_zoom, device_scale());
}

void OutOfProcessInstance::AppendBlankPrintPreviewPages() {
engine()->AppendBlankPages(print_preview_page_count_);
LoadNextPreviewPage();
Expand Down
8 changes: 1 addition & 7 deletions pdf/out_of_process_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
void OnGeometryChanged(double old_zoom, float old_device_scale) override;

private:
// Message handlers.
Expand All @@ -210,10 +211,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,

void ResetRecentlySentFindUpdate(int32_t);

// Called whenever the plugin geometry changes to update the location of the
// background parts, and notifies the pdf engine.
void OnGeometryChanged(double old_zoom, float old_device_scale);

// Figures out the location of any background rectangles (i.e. those that
// aren't painted by the PDF engine).
void CalculateBackgroundParts();
Expand Down Expand Up @@ -267,9 +264,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
kEdited = 2,
};

// Set new zoom scale.
void SetZoom(double scale);

// Reduces the document to 1 page and appends |print_preview_page_count_| - 1
// blank pages to the document for print preview.
void AppendBlankPrintPreviewPages();
Expand Down
9 changes: 9 additions & 0 deletions pdf/pdf_view_plugin_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

namespace chrome_pdf {

// static
constexpr double PdfViewPluginBase::kMinZoom;

PdfViewPluginBase::PdfViewPluginBase() = default;

PdfViewPluginBase::~PdfViewPluginBase() = default;
Expand Down Expand Up @@ -56,4 +59,10 @@ void PdfViewPluginBase::LoadUrl(const std::string& url, bool is_print_preview) {
GetWeakPtr(), std::move(loader)));
}

void PdfViewPluginBase::SetZoom(double scale) {
double old_zoom = zoom_;
zoom_ = scale;
OnGeometryChanged(old_zoom, device_scale_);
}

} // namespace chrome_pdf
11 changes: 10 additions & 1 deletion pdf/pdf_view_plugin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
std::vector<gfx::Rect>* pending) override;

protected:
// The mininum zoom level allowed.
static constexpr double kMinZoom = 0.01;

PdfViewPluginBase();
~PdfViewPluginBase() override;

Expand Down Expand Up @@ -76,6 +79,10 @@ class PdfViewPluginBase : public PDFEngine::Client,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) = 0;

// Called whenever the plugin geometry changes to update the location of the
// background parts, and notifies the pdf engine.
virtual void OnGeometryChanged(double old_zoom, float old_device_scale) = 0;

void SetBackgroundColor(uint32_t background_color) {
background_color_ = background_color;
}
Expand All @@ -88,8 +95,10 @@ class PdfViewPluginBase : public PDFEngine::Client,
top_toolbar_height_in_viewport_coords_ = height;
}

// Sets the new zoom scale.
void SetZoom(double scale);

double zoom() const { return zoom_; }
void set_zoom(double zoom) { zoom_ = zoom; }

float device_scale() const { return device_scale_; }
void set_device_scale(float device_scale) { device_scale_ = device_scale; }
Expand Down
5 changes: 5 additions & 0 deletions pdf/pdf_view_web_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,9 @@ void PdfViewWebPlugin::DoPaint(const std::vector<gfx::Rect>& paint_rects,
NOTIMPLEMENTED_LOG_ONCE();
}

// TODO(https://crbug.com/1099020): To be implemented as a Pepper-free version
// of `OutOfProcessInstance::OnGeometryChanged()`
void PdfViewWebPlugin::OnGeometryChanged(double old_zoom,
float old_device_scale) {}

} // namespace chrome_pdf
1 change: 1 addition & 0 deletions pdf/pdf_view_web_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) override;
void OnGeometryChanged(double old_zoom, float old_device_scale) override;

private:
// Call `Destroy()` instead.
Expand Down

0 comments on commit d758b98

Please sign in to comment.