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) {
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) {
return size > 0 && size <= kMaximumSavedFileSize;
}
......@@ -1268,12 +1260,14 @@ void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
}
void OutOfProcessInstance::UpdateTickMarks(
const std::vector<pp::Rect>& tickmarks) {
const std::vector<gfx::Rect>& tickmarks) {
float inverse_scale = 1.0f / device_scale_;
std::vector<pp::Rect> scaled_tickmarks = tickmarks;
for (auto& tickmark : scaled_tickmarks)
ScaleRect(inverse_scale, &tickmark);
tickmarks_ = scaled_tickmarks;
tickmarks_.clear();
tickmarks_.reserve(tickmarks.size());
for (auto& tickmark : tickmarks) {
tickmarks_.emplace_back(
PPRectFromRect(gfx::ScaleToEnclosingRect(tickmark, inverse_scale)));
}
}
void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
......
......@@ -124,7 +124,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
const float* y,
const float* zoom) 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 NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override;
......
......@@ -169,7 +169,7 @@ class PDFEngine {
virtual void UpdateCursor(PP_CursorType_Dev cursor) {}
// 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
// there are no matches 0 should be passed in. Only when the plugin has
......
......@@ -108,8 +108,8 @@ void PdfViewWebPlugin::NavigateToDestination(int page,
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,
bool final_result) {}
......
......@@ -58,7 +58,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
const float* y,
const float* zoom) 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 NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override;
......
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include "third_party/pdfium/public/fpdfview.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
......@@ -204,17 +205,17 @@ class PDFiumEngine : public PDFEngine,
private:
// Returns all the currently visible selection rectangles, in screen
// coordinates.
std::vector<pp::Rect> GetVisibleSelections() const;
std::vector<gfx::Rect> GetVisibleSelections() const;
// Invalidates |selection|, but with |selection| slightly expanded to
// compensate for any rounding errors.
void Invalidate(const pp::Rect& selection);
void Invalidate(const gfx::Rect& selection);
PDFiumEngine* const engine_;
// The origin at the time this object was constructed.
const gfx::Point previous_origin_;
// 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.
......@@ -357,7 +358,7 @@ class PDFiumEngine : public PDFEngine,
size_t page_index,
size_t num_of_pages) const;
std::vector<pp::Rect> GetAllScreenRectsUnion(
std::vector<gfx::Rect> GetAllScreenRectsUnion(
const std::vector<PDFiumRange>& rect_range,
const gfx::Point& point) const;
......@@ -496,11 +497,11 @@ class PDFiumEngine : public PDFEngine,
// updated to include |rect| if |rect| has not already been highlighted.
void Highlight(void* buffer,
int stride,
const pp::Rect& rect,
const gfx::Rect& rect,
int color_red,
int color_green,
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
// not yet loaded, |page_x| and |page_y| will be set to 0.
......@@ -764,7 +765,7 @@ class PDFiumEngine : public PDFEngine,
// Records parts of form fields that need to be highlighted at next paint, in
// screen coordinates.
std::vector<pp::Rect> form_highlights_;
std::vector<gfx::Rect> form_highlights_;
// Whether to render in grayscale or in color.
bool render_grayscale_ = false;
......
......@@ -151,7 +151,7 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
if (rect.IsEmpty())
return;
engine->form_highlights_.push_back(PPRectFromRect(rect));
engine->form_highlights_.push_back(rect);
}
// static
......
......@@ -7,8 +7,8 @@
#include "base/check_op.h"
#include "base/strings/string_util.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/rect.h"
namespace chrome_pdf {
......@@ -53,7 +53,7 @@ void PDFiumRange::SetCharCount(int char_count) {
cached_screen_rects_zoom_ = 0;
}
const std::vector<pp::Rect>& PDFiumRange::GetScreenRects(
const std::vector<gfx::Rect>& PDFiumRange::GetScreenRects(
const gfx::Point& point,
double zoom,
PageOrientation orientation) const {
......@@ -88,7 +88,7 @@ const std::vector<pp::Rect>& PDFiumRange::GetScreenRects(
page_->PageToScreen(point, zoom, left, top, right, bottom, orientation);
if (rect.IsEmpty())
continue;
cached_screen_rects_.push_back(PPRectFromRect(rect));
cached_screen_rects_.push_back(rect);
}
return cached_screen_rects_;
......
......@@ -11,8 +11,8 @@
#include "base/strings/string16.h"
#include "pdf/page_orientation.h"
#include "pdf/pdfium/pdfium_page.h"
#include "ppapi/cpp/rect.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf {
......@@ -40,7 +40,7 @@ class PDFiumRange {
int char_count() const { return char_count_; }
// Gets bounding rectangles of range in screen coordinates.
const std::vector<pp::Rect>& GetScreenRects(
const std::vector<gfx::Rect>& GetScreenRects(
const gfx::Point& point,
double zoom,
PageOrientation orientation) const;
......@@ -56,7 +56,7 @@ class PDFiumRange {
int char_count_;
// 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 double cached_screen_rects_zoom_ = 0;
};
......
......@@ -59,7 +59,7 @@ void PreviewModeClient::UpdateCursor(PP_CursorType_Dev cursor) {
}
void PreviewModeClient::UpdateTickMarks(
const std::vector<pp::Rect>& tickmarks) {
const std::vector<gfx::Rect>& tickmarks) {
NOTREACHED();
}
......
......@@ -14,6 +14,7 @@
#include "pdf/pdf_engine.h"
namespace gfx {
class Rect;
class Vector2d;
} // namespace gfx
......@@ -42,7 +43,7 @@ class PreviewModeClient : public PDFEngine::Client {
void NavigateTo(const std::string& url,
WindowOpenDisposition disposition) 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 NotifySelectedFindResultChanged(int current_find_index) override;
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