Commit 56d27510 authored by Ankit Kumar 🌪️'s avatar Ankit Kumar 🌪️ Committed by Commit Bot

Migrate pp::Rect to gfx::Rect in PDFiumEngine

Update PDFiumEngine to use gfx::Rect instead of pp::Rect. Update
callers to expect gfx::Rect as return value instead of pp::Rect.

Noteworthy points:
- In pp::Rect, Subtract() is a utility methods which takes in two
rects and returns the subtracted rect. Whereas in gfx::Rect, Subtract()
is a member method which modifies the rect in-place. All usage of
Subtract() which are replaced in the CL modify the rect in-place.
- In pp::Rect, Intersect() is a utility method which takes in two
rects and returns the intersected rect. The counterpart in gfx::Rect
is IntersectRects() and not Intersect().

Bug: 1101101
Change-Id: Ib071e3a987c2c234b8e2348744700f9cf07edc96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379397Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#804462}
parent f2875ba4
......@@ -835,10 +835,10 @@ void OutOfProcessInstance::SendAccessibilityViewportInfo() {
pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info);
}
void OutOfProcessInstance::SelectionChanged(const pp::Rect& left,
const pp::Rect& right) {
pp::Point l(left.point().x() + available_area_.x(), left.point().y());
pp::Point r(right.x() + available_area_.x(), right.point().y());
void OutOfProcessInstance::SelectionChanged(const gfx::Rect& left,
const gfx::Rect& right) {
pp::Point l(left.x() + available_area_.x(), left.y());
pp::Point r(right.x() + available_area_.x(), right.y());
float inverse_scale = 1.0f / device_scale_;
ScalePoint(inverse_scale, &l);
......@@ -1033,16 +1033,18 @@ void OutOfProcessInstance::OnPaint(const std::vector<gfx::Rect>& paint_rects,
if (!pdf_rect.IsEmpty()) {
pdf_rect.Offset(available_area_.x() * -1, 0);
std::vector<pp::Rect> pdf_ready;
std::vector<pp::Rect> pdf_pending;
engine()->Paint(pdf_rect, skia_image_data_, pdf_ready, pdf_pending);
std::vector<gfx::Rect> pdf_ready;
std::vector<gfx::Rect> pdf_pending;
engine()->Paint(RectFromPPRect(pdf_rect), skia_image_data_, pdf_ready,
pdf_pending);
for (auto& ready_rect : pdf_ready) {
ready_rect.Offset(available_area_.point());
ready->push_back(PaintReadyRect(ready_rect, image_data_));
ready_rect.Offset(VectorFromPPPoint(available_area_.point()));
ready->push_back(
PaintReadyRect(PPRectFromRect(ready_rect), image_data_));
}
for (auto& pending_rect : pdf_pending) {
pending_rect.Offset(available_area_.point());
pending->push_back(RectFromPPRect(pending_rect));
pending_rect.Offset(VectorFromPPPoint(available_area_.point()));
pending->push_back(pending_rect);
}
}
......@@ -1185,15 +1187,15 @@ void OutOfProcessInstance::ProposeDocumentLayout(const DocumentLayout& layout) {
PostMessage(dimensions);
}
void OutOfProcessInstance::Invalidate(const pp::Rect& rect) {
void OutOfProcessInstance::Invalidate(const gfx::Rect& rect) {
if (in_paint_) {
deferred_invalidates_.push_back(rect);
return;
}
pp::Rect offset_rect(rect);
offset_rect.Offset(available_area_.point());
paint_manager_.InvalidateRect(RectFromPPRect(offset_rect));
gfx::Rect offset_rect(rect);
offset_rect.Offset(VectorFromPPPoint(available_area_.point()));
paint_manager_.InvalidateRect(offset_rect);
}
void OutOfProcessInstance::DidScroll(const gfx::Vector2d& offset) {
......@@ -2324,7 +2326,7 @@ void OutOfProcessInstance::OnPrint(int32_t /*unused_but_required*/) {
void OutOfProcessInstance::InvalidateAfterPaintDone(
int32_t /*unused_but_required*/) {
DCHECK(!in_paint_);
for (const pp::Rect& rect : deferred_invalidates_)
for (const gfx::Rect& rect : deferred_invalidates_)
Invalidate(rect);
deferred_invalidates_.clear();
}
......
......@@ -111,7 +111,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// PdfViewPluginBase implementation.
void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const pp::Rect& rect) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
......@@ -159,7 +159,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
bool IsPrintPreview() override;
uint32_t GetBackgroundColor() override;
void IsSelectingChanged(bool is_selecting) override;
void SelectionChanged(const pp::Rect& left, const pp::Rect& right) override;
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
void EnteredEditMode() override;
float GetToolbarHeightInScreenCoords() override;
void DocumentFocusChanged(bool document_has_focus) override;
......@@ -393,7 +393,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Whether OnPaint() is in progress or not.
bool in_paint_ = false;
// Deferred invalidates while |in_paint_| is true.
std::vector<pp::Rect> deferred_invalidates_;
std::vector<gfx::Rect> deferred_invalidates_;
struct BackgroundPart {
pp::Rect location;
......
......@@ -23,7 +23,6 @@
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var_array.h"
#include "ui/base/window_open_disposition.h"
......@@ -52,7 +51,6 @@ class Vector2d;
} // namespace gfx
namespace pp {
class Rect;
class VarDictionary;
} // namespace pp
......@@ -134,7 +132,7 @@ class PDFEngine {
virtual void ProposeDocumentLayout(const DocumentLayout& layout) = 0;
// Informs the client that the given rect needs to be repainted.
virtual void Invalidate(const pp::Rect& rect) {}
virtual void Invalidate(const gfx::Rect& rect) {}
// Informs the client to scroll the plugin area by the given offset.
virtual void DidScroll(const gfx::Vector2d& offset) {}
......@@ -262,8 +260,8 @@ class PDFEngine {
// Sets selection status.
virtual void IsSelectingChanged(bool is_selecting) {}
virtual void SelectionChanged(const pp::Rect& left, const pp::Rect& right) {
}
virtual void SelectionChanged(const gfx::Rect& left,
const gfx::Rect& right) {}
// Notifies the client that the PDF has been edited.
virtual void EnteredEditMode() {}
......@@ -333,10 +331,10 @@ class PDFEngine {
// Paint is called a series of times. Before these n calls are made, PrePaint
// is called once. After Paint is called n times, PostPaint is called once.
virtual void PrePaint() = 0;
virtual void Paint(const pp::Rect& rect,
virtual void Paint(const gfx::Rect& rect,
SkBitmap& image_data,
std::vector<pp::Rect>& ready,
std::vector<pp::Rect>& pending) = 0;
std::vector<gfx::Rect>& ready,
std::vector<gfx::Rect>& pending) = 0;
virtual void PostPaint() = 0;
virtual bool HandleDocumentLoad(scoped_refptr<UrlLoader> loader) = 0;
virtual bool HandleEvent(const InputEvent& event) = 0;
......@@ -411,7 +409,7 @@ class PDFEngine {
virtual gfx::Rect GetPageContentsRect(int index) = 0;
// Returns a page's rect in screen coordinates, as well as its surrounding
// border areas and bottom separator.
virtual pp::Rect GetPageScreenRect(int page_index) const = 0;
virtual gfx::Rect GetPageScreenRect(int page_index) const = 0;
// Gets the offset of the vertical scrollbar from the top in document
// coordinates.
virtual int GetVerticalScrollbarYPosition() = 0;
......
......@@ -141,7 +141,7 @@ void PdfViewWebPlugin::DidFailLoading(const blink::WebURLError& error) {}
void PdfViewWebPlugin::ProposeDocumentLayout(const DocumentLayout& layout) {}
void PdfViewWebPlugin::Invalidate(const pp::Rect& rect) {}
void PdfViewWebPlugin::Invalidate(const gfx::Rect& rect) {}
void PdfViewWebPlugin::DidScroll(const gfx::Vector2d& offset) {}
......@@ -245,8 +245,8 @@ uint32_t PdfViewWebPlugin::GetBackgroundColor() {
void PdfViewWebPlugin::IsSelectingChanged(bool is_selecting) {}
void PdfViewWebPlugin::SelectionChanged(const pp::Rect& left,
const pp::Rect& right) {}
void PdfViewWebPlugin::SelectionChanged(const gfx::Rect& left,
const gfx::Rect& right) {}
void PdfViewWebPlugin::EnteredEditMode() {}
......
......@@ -45,7 +45,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// PdfViewPluginBase:
void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const pp::Rect& rect) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
......@@ -93,7 +93,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
bool IsPrintPreview() override;
uint32_t GetBackgroundColor() override;
void IsSelectingChanged(bool is_selecting) override;
void SelectionChanged(const pp::Rect& left, const pp::Rect& right) override;
void SelectionChanged(const gfx::Rect& left, const gfx::Rect& right) override;
void EnteredEditMode() override;
float GetToolbarHeightInScreenCoords() override;
void DocumentFocusChanged(bool document_has_focus) override;
......
This diff is collapsed.
......@@ -28,7 +28,6 @@
#include "pdf/pdfium/pdfium_range.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/var_array.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
......@@ -89,10 +88,10 @@ class PDFiumEngine : public PDFEngine,
void ScrolledToXPosition(int position) override;
void ScrolledToYPosition(int position) override;
void PrePaint() override;
void Paint(const pp::Rect& rect,
void Paint(const gfx::Rect& rect,
SkBitmap& image_data,
std::vector<pp::Rect>& ready,
std::vector<pp::Rect>& pending) override;
std::vector<gfx::Rect>& ready,
std::vector<gfx::Rect>& pending) override;
void PostPaint() override;
bool HandleDocumentLoad(scoped_refptr<UrlLoader> loader) override;
bool HandleEvent(const InputEvent& event) override;
......@@ -138,7 +137,7 @@ class PDFiumEngine : public PDFEngine,
int GetMostVisiblePage() override;
gfx::Rect GetPageBoundsRect(int index) override;
gfx::Rect GetPageContentsRect(int index) override;
pp::Rect GetPageScreenRect(int page_index) const override;
gfx::Rect GetPageScreenRect(int page_index) const override;
int GetVerticalScrollbarYPosition() override;
void SetGrayscale(bool grayscale) override;
int GetCharCount(int page_index) override;
......@@ -349,7 +348,7 @@ class PDFiumEngine : public PDFEngine,
size_t page_index,
size_t num_of_pages,
double multiplier,
pp::Rect* rect) const;
gfx::Rect& rect) const;
// If two-up view is enabled, returns the index of the page beside
// |page_index| page. Returns base::nullopt if there is no adjacent page or
......@@ -434,7 +433,7 @@ class PDFiumEngine : public PDFEngine,
// Starts a progressive paint operation given a rectangle in screen
// coordinates. Returns the index in progressive_rects_.
int StartPaint(int page_index, const pp::Rect& dirty);
int StartPaint(int page_index, const gfx::Rect& dirty);
// Continues a paint operation that was started earlier. Returns true if the
// paint is done, or false if it needs to be continued.
......@@ -462,7 +461,7 @@ class PDFiumEngine : public PDFEngine,
// Paints an page that hasn't finished downloading.
void PaintUnavailablePage(int page_index,
const pp::Rect& dirty,
const gfx::Rect& dirty,
SkBitmap& image_data);
// Given a page index, returns the corresponding index in progressive_rects_,
......@@ -470,13 +469,13 @@ class PDFiumEngine : public PDFEngine,
int GetProgressiveIndex(int page_index) const;
// Creates a FPDF_BITMAP from a rectangle in screen coordinates.
ScopedFPDFBitmap CreateBitmap(const pp::Rect& rect,
ScopedFPDFBitmap CreateBitmap(const gfx::Rect& rect,
SkBitmap& image_data) const;
// Given a rectangle in screen coordinates, returns the coordinates in the
// units that PDFium rendering functions expect.
void GetPDFiumRect(int page_index,
const pp::Rect& rect,
const gfx::Rect& rect,
int* start_x,
int* start_y,
int* size_x,
......@@ -486,7 +485,7 @@ class PDFiumEngine : public PDFEngine,
int GetRenderingFlags() const;
// Returns the currently visible rectangle in document coordinates.
pp::Rect GetVisibleRect() const;
gfx::Rect GetVisibleRect() const;
// Given |rect| in document coordinates, returns the rectangle in screen
// coordinates. (i.e. 0,0 is top left corner of plugin area)
......@@ -518,9 +517,9 @@ class PDFiumEngine : public PDFEngine,
// triggers as necessary.
void SetCurrentPage(int index);
void DrawPageShadow(const pp::Rect& page_rect,
const pp::Rect& shadow_rect,
const pp::Rect& clip_rect,
void DrawPageShadow(const gfx::Rect& page_rect,
const gfx::Rect& shadow_rect,
const gfx::Rect& clip_rect,
SkBitmap& image_data);
void GetRegion(const gfx::Point& location,
......@@ -568,13 +567,13 @@ class PDFiumEngine : public PDFEngine,
unsigned int depth);
void ScrollBasedOnScrollAlignment(
const pp::Rect& scroll_rect,
const gfx::Rect& scroll_rect,
const PP_PdfAccessibilityScrollAlignment& horizontal_scroll_alignment,
const PP_PdfAccessibilityScrollAlignment& vertical_scroll_alignment);
// Scrolls top left of a rect in page |target_rect| to |global_point|.
// Global point is point relative to viewport in screen.
void ScrollToGlobalPoint(const pp::Rect& target_rect,
void ScrollToGlobalPoint(const gfx::Rect& target_rect,
const gfx::Point& global_point);
// Set if the document has any local edits.
......@@ -779,13 +778,13 @@ class PDFiumEngine : public PDFEngine,
// Pending progressive paints.
class ProgressivePaint {
public:
ProgressivePaint(int page_index, const pp::Rect& rect);
ProgressivePaint(int page_index, const gfx::Rect& rect);
ProgressivePaint(ProgressivePaint&& that);
ProgressivePaint& operator=(ProgressivePaint&& that);
~ProgressivePaint();
int page_index() const { return page_index_; }
const pp::Rect& rect() const { return rect_; }
const gfx::Rect& rect() const { return rect_; }
FPDF_BITMAP bitmap() const { return bitmap_.get(); }
bool painted() const { return painted_; }
......@@ -794,7 +793,7 @@ class PDFiumEngine : public PDFEngine,
private:
int page_index_;
pp::Rect rect_; // In screen coordinates.
gfx::Rect rect_; // In screen coordinates.
SkBitmap image_data_; // Maintains reference while |bitmap_| exists.
ScopedFPDFBitmap bitmap_; // Must come after |image_data_|.
// Temporary used to figure out if in a series of Paint() calls whether this
......
......@@ -12,7 +12,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "pdf/ppapi_migration/input_event_conversions.h"
#include "third_party/pdfium/public/fpdf_annot.h"
#include "ui/gfx/geometry/rect.h"
......@@ -125,10 +124,9 @@ void PDFiumFormFiller::Form_Invalidate(FPDF_FORMFILLINFO* param,
}
gfx::Rect rect = engine->pages_[page_index]->PageToScreen(
PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_,
left, top, right, bottom,
engine->layout_.options().default_page_orientation());
engine->client_->Invalidate(PPRectFromRect(rect));
engine->GetVisibleRect().origin(), engine->current_zoom_, left, top,
right, bottom, engine->layout_.options().default_page_orientation());
engine->client_->Invalidate(rect);
}
// static
......@@ -145,9 +143,8 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
return;
}
gfx::Rect rect = engine->pages_[page_index]->PageToScreen(
PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_,
left, top, right, bottom,
engine->layout_.options().default_page_orientation());
engine->GetVisibleRect().origin(), engine->current_zoom_, left, top,
right, bottom, engine->layout_.options().default_page_orientation());
if (rect.IsEmpty())
return;
......
......@@ -24,7 +24,7 @@ void PreviewModeClient::ProposeDocumentLayout(const DocumentLayout& layout) {
// occurs if and only if loading a non-PDF document with more than 1 page.
}
void PreviewModeClient::Invalidate(const pp::Rect& rect) {
void PreviewModeClient::Invalidate(const gfx::Rect& rect) {
NOTREACHED();
}
......
......@@ -34,7 +34,7 @@ class PreviewModeClient : public PDFEngine::Client {
// PDFEngine::Client implementation.
void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const pp::Rect& rect) override;
void Invalidate(const gfx::Rect& rect) override;
void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment