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

Migrate pp::Rect to gfx::Rect in PDFiumRange

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

Noteworthy point: PDFiumRange::GetScreenRects() returns a vector of
rects. Instead of converting the returned vector of gfx::Rect to a
vector of pp::Rect, the CL modifies recursively the usage of pp::Rect
to gfx::Rect of the callers. The reason of updating the callers
recursively is to prevent a copy of vector from one structure to
another at caller site. Even temporarily, the additional copy of
vectors is avoided in this way.

Additional points:
- In pp::Rect, Union() and Subtract() are utility methods which takes
in two rects and returns a rect with the specified operation of input
rects. Whereas in gfx::Rect, Union() and Subtract() are member methods
which modify the rect in-place. All usage of Union() and 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: I90dce2c8b33fcced11c4e8a03e2cfb5ae1064abc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371142Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#802889}
parent e6ed9f7f
...@@ -452,14 +452,6 @@ void ScalePoint(float scale, pp::Point* point) { ...@@ -452,14 +452,6 @@ void ScalePoint(float scale, pp::Point* point) {
point->set_y(static_cast<int>(point->y() * scale)); point->set_y(static_cast<int>(point->y() * scale));
} }
void ScaleRect(float scale, pp::Rect* rect) {
int left = static_cast<int>(floorf(rect->x() * scale));
int top = static_cast<int>(floorf(rect->y() * scale));
int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale));
int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale));
rect->SetRect(left, top, right - left, bottom - top);
}
bool IsSaveDataSizeValid(size_t size) { bool IsSaveDataSizeValid(size_t size) {
return size > 0 && size <= kMaximumSavedFileSize; return size > 0 && size <= kMaximumSavedFileSize;
} }
...@@ -1268,12 +1260,14 @@ void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { ...@@ -1268,12 +1260,14 @@ void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
} }
void OutOfProcessInstance::UpdateTickMarks( void OutOfProcessInstance::UpdateTickMarks(
const std::vector<pp::Rect>& tickmarks) { const std::vector<gfx::Rect>& tickmarks) {
float inverse_scale = 1.0f / device_scale_; float inverse_scale = 1.0f / device_scale_;
std::vector<pp::Rect> scaled_tickmarks = tickmarks; tickmarks_.clear();
for (auto& tickmark : scaled_tickmarks) tickmarks_.reserve(tickmarks.size());
ScaleRect(inverse_scale, &tickmark); for (auto& tickmark : tickmarks) {
tickmarks_ = scaled_tickmarks; tickmarks_.emplace_back(
PPRectFromRect(gfx::ScaleToEnclosingRect(tickmark, inverse_scale)));
}
} }
void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total, void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
......
...@@ -124,7 +124,7 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -124,7 +124,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
const float* y, const float* y,
const float* zoom) override; const float* zoom) override;
void UpdateCursor(PP_CursorType_Dev cursor) override; void UpdateCursor(PP_CursorType_Dev cursor) override;
void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override; void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override; void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override; void NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override; void NotifyTouchSelectionOccurred() override;
......
...@@ -169,7 +169,7 @@ class PDFEngine { ...@@ -169,7 +169,7 @@ class PDFEngine {
virtual void UpdateCursor(PP_CursorType_Dev cursor) {} virtual void UpdateCursor(PP_CursorType_Dev cursor) {}
// Updates the tick marks in the vertical scrollbar. // Updates the tick marks in the vertical scrollbar.
virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) {} virtual void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) {}
// Updates the number of find results for the current search term. If // Updates the number of find results for the current search term. If
// there are no matches 0 should be passed in. Only when the plugin has // there are no matches 0 should be passed in. Only when the plugin has
......
...@@ -108,8 +108,8 @@ void PdfViewWebPlugin::NavigateToDestination(int page, ...@@ -108,8 +108,8 @@ void PdfViewWebPlugin::NavigateToDestination(int page,
void PdfViewWebPlugin::UpdateCursor(PP_CursorType_Dev cursor) {} void PdfViewWebPlugin::UpdateCursor(PP_CursorType_Dev cursor) {}
void PdfViewWebPlugin::UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) { void PdfViewWebPlugin::UpdateTickMarks(
} const std::vector<gfx::Rect>& tickmarks) {}
void PdfViewWebPlugin::NotifyNumberOfFindResultsChanged(int total, void PdfViewWebPlugin::NotifyNumberOfFindResultsChanged(int total,
bool final_result) {} bool final_result) {}
......
...@@ -58,7 +58,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase, ...@@ -58,7 +58,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
const float* y, const float* y,
const float* zoom) override; const float* zoom) override;
void UpdateCursor(PP_CursorType_Dev cursor) override; void UpdateCursor(PP_CursorType_Dev cursor) override;
void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override; void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override; void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override; void NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override; void NotifyTouchSelectionOccurred() override;
......
This diff is collapsed.
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "third_party/pdfium/public/fpdfview.h" #include "third_party/pdfium/public/fpdfview.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/geometry/vector2d.h"
...@@ -204,17 +205,17 @@ class PDFiumEngine : public PDFEngine, ...@@ -204,17 +205,17 @@ class PDFiumEngine : public PDFEngine,
private: private:
// Returns all the currently visible selection rectangles, in screen // Returns all the currently visible selection rectangles, in screen
// coordinates. // coordinates.
std::vector<pp::Rect> GetVisibleSelections() const; std::vector<gfx::Rect> GetVisibleSelections() const;
// Invalidates |selection|, but with |selection| slightly expanded to // Invalidates |selection|, but with |selection| slightly expanded to
// compensate for any rounding errors. // compensate for any rounding errors.
void Invalidate(const pp::Rect& selection); void Invalidate(const gfx::Rect& selection);
PDFiumEngine* const engine_; PDFiumEngine* const engine_;
// The origin at the time this object was constructed. // The origin at the time this object was constructed.
const gfx::Point previous_origin_; const gfx::Point previous_origin_;
// Screen rectangles that were selected on construction. // Screen rectangles that were selected on construction.
std::vector<pp::Rect> old_selections_; std::vector<gfx::Rect> old_selections_;
}; };
// Used to store mouse down state to handle it in other mouse event handlers. // Used to store mouse down state to handle it in other mouse event handlers.
...@@ -357,7 +358,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -357,7 +358,7 @@ class PDFiumEngine : public PDFEngine,
size_t page_index, size_t page_index,
size_t num_of_pages) const; size_t num_of_pages) const;
std::vector<pp::Rect> GetAllScreenRectsUnion( std::vector<gfx::Rect> GetAllScreenRectsUnion(
const std::vector<PDFiumRange>& rect_range, const std::vector<PDFiumRange>& rect_range,
const gfx::Point& point) const; const gfx::Point& point) const;
...@@ -496,11 +497,11 @@ class PDFiumEngine : public PDFEngine, ...@@ -496,11 +497,11 @@ class PDFiumEngine : public PDFEngine,
// updated to include |rect| if |rect| has not already been highlighted. // updated to include |rect| if |rect| has not already been highlighted.
void Highlight(void* buffer, void Highlight(void* buffer,
int stride, int stride,
const pp::Rect& rect, const gfx::Rect& rect,
int color_red, int color_red,
int color_green, int color_green,
int color_blue, int color_blue,
std::vector<pp::Rect>* highlighted_rects) const; std::vector<gfx::Rect>& highlighted_rects) const;
// Helper function to convert a device to page coordinates. If the page is // Helper function to convert a device to page coordinates. If the page is
// not yet loaded, |page_x| and |page_y| will be set to 0. // not yet loaded, |page_x| and |page_y| will be set to 0.
...@@ -764,7 +765,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -764,7 +765,7 @@ class PDFiumEngine : public PDFEngine,
// Records parts of form fields that need to be highlighted at next paint, in // Records parts of form fields that need to be highlighted at next paint, in
// screen coordinates. // screen coordinates.
std::vector<pp::Rect> form_highlights_; std::vector<gfx::Rect> form_highlights_;
// Whether to render in grayscale or in color. // Whether to render in grayscale or in color.
bool render_grayscale_ = false; bool render_grayscale_ = false;
......
...@@ -151,7 +151,7 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param, ...@@ -151,7 +151,7 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
if (rect.IsEmpty()) if (rect.IsEmpty())
return; return;
engine->form_highlights_.push_back(PPRectFromRect(rect)); engine->form_highlights_.push_back(rect);
} }
// static // static
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -53,7 +53,7 @@ void PDFiumRange::SetCharCount(int char_count) { ...@@ -53,7 +53,7 @@ void PDFiumRange::SetCharCount(int char_count) {
cached_screen_rects_zoom_ = 0; cached_screen_rects_zoom_ = 0;
} }
const std::vector<pp::Rect>& PDFiumRange::GetScreenRects( const std::vector<gfx::Rect>& PDFiumRange::GetScreenRects(
const gfx::Point& point, const gfx::Point& point,
double zoom, double zoom,
PageOrientation orientation) const { PageOrientation orientation) const {
...@@ -88,7 +88,7 @@ const std::vector<pp::Rect>& PDFiumRange::GetScreenRects( ...@@ -88,7 +88,7 @@ const std::vector<pp::Rect>& PDFiumRange::GetScreenRects(
page_->PageToScreen(point, zoom, left, top, right, bottom, orientation); page_->PageToScreen(point, zoom, left, top, right, bottom, orientation);
if (rect.IsEmpty()) if (rect.IsEmpty())
continue; continue;
cached_screen_rects_.push_back(PPRectFromRect(rect)); cached_screen_rects_.push_back(rect);
} }
return cached_screen_rects_; return cached_screen_rects_;
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "pdf/page_orientation.h" #include "pdf/page_orientation.h"
#include "pdf/pdfium/pdfium_page.h" #include "pdf/pdfium/pdfium_page.h"
#include "ppapi/cpp/rect.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -40,7 +40,7 @@ class PDFiumRange { ...@@ -40,7 +40,7 @@ class PDFiumRange {
int char_count() const { return char_count_; } int char_count() const { return char_count_; }
// Gets bounding rectangles of range in screen coordinates. // Gets bounding rectangles of range in screen coordinates.
const std::vector<pp::Rect>& GetScreenRects( const std::vector<gfx::Rect>& GetScreenRects(
const gfx::Point& point, const gfx::Point& point,
double zoom, double zoom,
PageOrientation orientation) const; PageOrientation orientation) const;
...@@ -56,7 +56,7 @@ class PDFiumRange { ...@@ -56,7 +56,7 @@ class PDFiumRange {
int char_count_; int char_count_;
// Cache of ScreenRect, and the associated variables used when caching it. // Cache of ScreenRect, and the associated variables used when caching it.
mutable std::vector<pp::Rect> cached_screen_rects_; mutable std::vector<gfx::Rect> cached_screen_rects_;
mutable gfx::Point cached_screen_rects_point_; mutable gfx::Point cached_screen_rects_point_;
mutable double cached_screen_rects_zoom_ = 0; mutable double cached_screen_rects_zoom_ = 0;
}; };
......
...@@ -59,7 +59,7 @@ void PreviewModeClient::UpdateCursor(PP_CursorType_Dev cursor) { ...@@ -59,7 +59,7 @@ void PreviewModeClient::UpdateCursor(PP_CursorType_Dev cursor) {
} }
void PreviewModeClient::UpdateTickMarks( void PreviewModeClient::UpdateTickMarks(
const std::vector<pp::Rect>& tickmarks) { const std::vector<gfx::Rect>& tickmarks) {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "pdf/pdf_engine.h" #include "pdf/pdf_engine.h"
namespace gfx { namespace gfx {
class Rect;
class Vector2d; class Vector2d;
} // namespace gfx } // namespace gfx
...@@ -42,7 +43,7 @@ class PreviewModeClient : public PDFEngine::Client { ...@@ -42,7 +43,7 @@ class PreviewModeClient : public PDFEngine::Client {
void NavigateTo(const std::string& url, void NavigateTo(const std::string& url,
WindowOpenDisposition disposition) override; WindowOpenDisposition disposition) override;
void UpdateCursor(PP_CursorType_Dev cursor) override; void UpdateCursor(PP_CursorType_Dev cursor) override;
void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override; void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override; void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override; void NotifySelectedFindResultChanged(int current_find_index) override;
void GetDocumentPassword( void GetDocumentPassword(
......
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