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

Migrate pp::Rect to gfx::Rect in PDFiumPage

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

Bug: 1101101
Change-Id: Ibf7b57a007545d2f70ca1a4c72bb428d4b30a139
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367133
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800791}
parent 8713ecc1
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "pdf/pdf_engine.h" #include "pdf/pdf_engine.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/cpp/rect.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -196,7 +198,7 @@ bool GetAccessibilityInfo( ...@@ -196,7 +198,7 @@ bool GetAccessibilityInfo(
char_count = 0; char_count = 0;
page_info->page_index = page_index; page_info->page_index = page_index;
page_info->bounds = engine->GetPageBoundsRect(page_index); page_info->bounds = PPRectFromRect(engine->GetPageBoundsRect(page_index));
page_info->char_count = char_count; page_info->char_count = char_count;
chars->resize(page_info->char_count); chars->resize(page_info->char_count);
......
...@@ -15,6 +15,15 @@ ...@@ -15,6 +15,15 @@
namespace chrome_pdf { namespace chrome_pdf {
namespace draw_utils { namespace draw_utils {
IndexedPage::IndexedPage(int index, const gfx::Rect& rect)
: index(index), rect(rect) {}
IndexedPage::IndexedPage(const IndexedPage& other) = default;
IndexedPage& IndexedPage::operator=(const IndexedPage& other) = default;
IndexedPage::~IndexedPage() = default;
void AdjustBottomGapForRightSidePage(int page_x, gfx::Rect* bottom_gap) { void AdjustBottomGapForRightSidePage(int page_x, gfx::Rect* bottom_gap) {
bottom_gap->set_x(page_x); bottom_gap->set_x(page_x);
bottom_gap->set_width(bottom_gap->width() / 2); bottom_gap->set_width(bottom_gap->width() / 2);
......
...@@ -32,6 +32,11 @@ struct PageInsetSizes { ...@@ -32,6 +32,11 @@ struct PageInsetSizes {
// Struct for sending a page's gfx::Rect object along with its corresponding // Struct for sending a page's gfx::Rect object along with its corresponding
// index in the PDF document. // index in the PDF document.
struct IndexedPage { struct IndexedPage {
IndexedPage(int index, const gfx::Rect& rect);
IndexedPage(const IndexedPage& other);
IndexedPage& operator=(const IndexedPage& other);
~IndexedPage();
int index; int index;
gfx::Rect rect; gfx::Rect rect;
}; };
......
...@@ -405,7 +405,7 @@ class PDFEngine { ...@@ -405,7 +405,7 @@ class PDFEngine {
// Gets the index of the most visible page, or -1 if none are visible. // Gets the index of the most visible page, or -1 if none are visible.
virtual int GetMostVisiblePage() = 0; virtual int GetMostVisiblePage() = 0;
// Gets the rectangle of the page not including the shadow. // Gets the rectangle of the page not including the shadow.
virtual pp::Rect GetPageBoundsRect(int index) = 0; virtual gfx::Rect GetPageBoundsRect(int index) = 0;
// Gets the rectangle of the page excluding any additional areas. // Gets the rectangle of the page excluding any additional areas.
virtual gfx::Rect GetPageContentsRect(int index) = 0; virtual gfx::Rect GetPageContentsRect(int index) = 0;
// Returns a page's rect in screen coordinates, as well as its surrounding // Returns a page's rect in screen coordinates, as well as its surrounding
......
...@@ -1105,8 +1105,7 @@ PDFiumPage::Area PDFiumEngine::GetCharIndex(const gfx::Point& point, ...@@ -1105,8 +1105,7 @@ PDFiumPage::Area PDFiumEngine::GetCharIndex(const gfx::Point& point,
static_cast<int>((point.x() + position_.x()) / current_zoom_), static_cast<int>((point.x() + position_.x()) / current_zoom_),
static_cast<int>((point.y() + position_.y()) / current_zoom_)); static_cast<int>((point.y() + position_.y()) / current_zoom_));
for (int visible_page : visible_pages_) { for (int visible_page : visible_pages_) {
if (pages_[visible_page]->rect().Contains( if (pages_[visible_page]->rect().Contains(point_in_page)) {
PPPointFromPoint(point_in_page))) {
page = visible_page; page = visible_page;
break; break;
} }
...@@ -2443,12 +2442,12 @@ int PDFiumEngine::GetMostVisiblePage() { ...@@ -2443,12 +2442,12 @@ int PDFiumEngine::GetMostVisiblePage() {
return most_visible_page_; return most_visible_page_;
} }
pp::Rect PDFiumEngine::GetPageBoundsRect(int index) { gfx::Rect PDFiumEngine::GetPageBoundsRect(int index) {
return pages_[index]->rect(); return pages_[index]->rect();
} }
gfx::Rect PDFiumEngine::GetPageContentsRect(int index) { gfx::Rect PDFiumEngine::GetPageContentsRect(int index) {
return GetScreenRect(RectFromPPRect(pages_[index]->rect())); return GetScreenRect(pages_[index]->rect());
} }
int PDFiumEngine::GetVerticalScrollbarYPosition() { int PDFiumEngine::GetVerticalScrollbarYPosition() {
...@@ -2700,7 +2699,7 @@ void PDFiumEngine::RefreshCurrentDocumentLayout() { ...@@ -2700,7 +2699,7 @@ void PDFiumEngine::RefreshCurrentDocumentLayout() {
DCHECK_EQ(pages_.size(), layout_.page_count()); DCHECK_EQ(pages_.size(), layout_.page_count());
for (size_t i = 0; i < layout_.page_count(); ++i) { for (size_t i = 0; i < layout_.page_count(); ++i) {
// TODO(kmoon): This should be the only place that sets |PDFiumPage::rect_|. // TODO(kmoon): This should be the only place that sets |PDFiumPage::rect_|.
pages_[i]->set_rect(layout_.page_bounds_rect(i)); pages_[i]->set_rect(RectFromPPRect(layout_.page_bounds_rect(i)));
} }
layout_.clear_dirty(); layout_.clear_dirty();
...@@ -2895,9 +2894,8 @@ void PDFiumEngine::CalculateVisiblePages() { ...@@ -2895,9 +2894,8 @@ void PDFiumEngine::CalculateVisiblePages() {
std::vector<draw_utils::IndexedPage> visible_pages_rects; std::vector<draw_utils::IndexedPage> visible_pages_rects;
visible_pages_rects.reserve(visible_pages_.size()); visible_pages_rects.reserve(visible_pages_.size());
for (int visible_page_index : visible_pages_) { for (int visible_page_index : visible_pages_) {
visible_pages_rects.push_back( visible_pages_rects.emplace_back(visible_page_index,
{visible_page_index, pages_[visible_page_index]->rect());
RectFromPPRect(pages_[visible_page_index]->rect())});
} }
int most_visible_page = draw_utils::GetMostVisiblePage( int most_visible_page = draw_utils::GetMostVisiblePage(
...@@ -3126,7 +3124,7 @@ void PDFiumEngine::FillPageSides(int progressive_index) { ...@@ -3126,7 +3124,7 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
draw_utils::PageInsetSizes inset_sizes = draw_utils::PageInsetSizes inset_sizes =
GetInsetSizes(layout_.options(), page_index, pages_.size()); GetInsetSizes(layout_.options(), page_index, pages_.size());
gfx::Rect page_rect = RectFromPPRect(pages_[page_index]->rect()); gfx::Rect page_rect = pages_[page_index]->rect();
const bool is_two_up_view = layout_.options().two_up_view_enabled(); const bool is_two_up_view = layout_.options().two_up_view_enabled();
if (page_rect.x() > 0 && (!is_two_up_view || page_index % 2 == 0)) { if (page_rect.x() > 0 && (!is_two_up_view || page_index % 2 == 0)) {
// If in two-up view, only need to draw the left empty space for left pages // If in two-up view, only need to draw the left empty space for left pages
...@@ -3186,7 +3184,7 @@ void PDFiumEngine::PaintPageShadow(int progressive_index, ...@@ -3186,7 +3184,7 @@ void PDFiumEngine::PaintPageShadow(int progressive_index,
int page_index = progressive_paints_[progressive_index].page_index(); int page_index = progressive_paints_[progressive_index].page_index();
const pp::Rect& dirty_in_screen = const pp::Rect& dirty_in_screen =
progressive_paints_[progressive_index].rect(); progressive_paints_[progressive_index].rect();
pp::Rect page_rect = pages_[page_index]->rect(); pp::Rect page_rect = PPRectFromRect(pages_[page_index]->rect());
pp::Rect shadow_rect(page_rect); pp::Rect shadow_rect(page_rect);
InsetPage(layout_.options(), page_index, pages_.size(), /*multiplier=*/-1, InsetPage(layout_.options(), page_index, pages_.size(), /*multiplier=*/-1,
&shadow_rect); &shadow_rect);
...@@ -3293,8 +3291,7 @@ void PDFiumEngine::GetPDFiumRect(int page_index, ...@@ -3293,8 +3291,7 @@ void PDFiumEngine::GetPDFiumRect(int page_index,
int* start_y, int* start_y,
int* size_x, int* size_x,
int* size_y) const { int* size_y) const {
gfx::Rect page_rect = gfx::Rect page_rect = GetScreenRect(pages_[page_index]->rect());
GetScreenRect(RectFromPPRect(pages_[page_index]->rect()));
page_rect.Offset(-rect.x(), -rect.y()); page_rect.Offset(-rect.x(), -rect.y());
*start_x = page_rect.x(); *start_x = page_rect.x();
...@@ -3324,7 +3321,7 @@ pp::Rect PDFiumEngine::GetVisibleRect() const { ...@@ -3324,7 +3321,7 @@ pp::Rect PDFiumEngine::GetVisibleRect() const {
} }
pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const { pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const {
const pp::Rect& page_rect = pages_[page_index]->rect(); pp::Rect page_rect = PPRectFromRect(pages_[page_index]->rect());
draw_utils::PageInsetSizes inset_sizes = draw_utils::PageInsetSizes inset_sizes =
GetInsetSizes(layout_.options(), page_index, pages_.size()); GetInsetSizes(layout_.options(), page_index, pages_.size());
...@@ -3814,13 +3811,13 @@ void PDFiumEngine::ScrollAnnotationIntoView(FPDF_ANNOTATION annot, ...@@ -3814,13 +3811,13 @@ void PDFiumEngine::ScrollAnnotationIntoView(FPDF_ANNOTATION annot,
if (!FPDFAnnot_GetRect(annot, &annot_rect)) if (!FPDFAnnot_GetRect(annot, &annot_rect))
return; return;
pp::Rect rect = pages_[page_index]->PageToScreen( gfx::Rect rect = pages_[page_index]->PageToScreen(
gfx::Point(), /*zoom=*/1.0, annot_rect.left, annot_rect.top, gfx::Point(), /*zoom=*/1.0, annot_rect.left, annot_rect.top,
annot_rect.right, annot_rect.bottom, annot_rect.right, annot_rect.bottom,
layout_.options().default_page_orientation()); layout_.options().default_page_orientation());
pp::Rect visible_rect = GetVisibleRect(); pp::Rect visible_rect = GetVisibleRect();
if (visible_rect.Contains(rect)) if (visible_rect.Contains(PPRectFromRect(rect)))
return; return;
// Since the focus rect is not already in the visible area, scrolling // Since the focus rect is not already in the visible area, scrolling
// horizontally and/or vertically is required. // horizontally and/or vertically is required.
......
...@@ -136,7 +136,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -136,7 +136,7 @@ class PDFiumEngine : public PDFEngine,
base::Optional<PDFEngine::NamedDestination> GetNamedDestination( base::Optional<PDFEngine::NamedDestination> GetNamedDestination(
const std::string& destination) override; const std::string& destination) override;
int GetMostVisiblePage() override; int GetMostVisiblePage() override;
pp::Rect GetPageBoundsRect(int index) override; gfx::Rect GetPageBoundsRect(int index) override;
gfx::Rect GetPageContentsRect(int index) override; gfx::Rect GetPageContentsRect(int index) override;
pp::Rect GetPageScreenRect(int page_index) const override; pp::Rect GetPageScreenRect(int page_index) const override;
int GetVerticalScrollbarYPosition() override; int GetVerticalScrollbarYPosition() override;
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
#include "pdf/pdfium/pdfium_test_base.h" #include "pdf/pdfium/pdfium_test_base.h"
#include "pdf/test/test_client.h" #include "pdf/test/test_client.h"
#include "pdf/test/test_document_loader.h" #include "pdf/test/test_document_loader.h"
#include "pdf/test/test_utils.h"
#include "ppapi/c/ppb_input_event.h" #include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/size.h" #include "ppapi/cpp/size.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -66,9 +66,9 @@ class PDFiumEngineTest : public PDFiumTestBase { ...@@ -66,9 +66,9 @@ class PDFiumEngineTest : public PDFiumTestBase {
protected: protected:
void ExpectPageRect(const PDFiumEngine& engine, void ExpectPageRect(const PDFiumEngine& engine,
size_t page_index, size_t page_index,
const pp::Rect& expected_rect) { const gfx::Rect& expected_rect) {
const PDFiumPage& page = GetPDFiumPageForTest(engine, page_index); const PDFiumPage& page = GetPDFiumPageForTest(engine, page_index);
CompareRect(expected_rect, page.rect()); EXPECT_EQ(expected_rect, page.rect());
} }
// Tries to load a PDF incrementally, returning `true` if the PDF actually was // Tries to load a PDF incrementally, returning `true` if the PDF actually was
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h" #include "pdf/pdfium/pdfium_engine.h"
#include "pdf/ppapi_migration/geometry_conversions.h" #include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/cpp/rect.h"
#include "third_party/pdfium/public/fpdf_annot.h" #include "third_party/pdfium/public/fpdf_annot.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -124,11 +123,11 @@ void PDFiumFormFiller::Form_Invalidate(FPDF_FORMFILLINFO* param, ...@@ -124,11 +123,11 @@ void PDFiumFormFiller::Form_Invalidate(FPDF_FORMFILLINFO* param,
return; return;
} }
pp::Rect rect = engine->pages_[page_index]->PageToScreen( gfx::Rect rect = engine->pages_[page_index]->PageToScreen(
PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_, PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_,
left, top, right, bottom, left, top, right, bottom,
engine->layout_.options().default_page_orientation()); engine->layout_.options().default_page_orientation());
engine->client_->Invalidate(rect); engine->client_->Invalidate(PPRectFromRect(rect));
} }
// static // static
...@@ -144,14 +143,14 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param, ...@@ -144,14 +143,14 @@ void PDFiumFormFiller::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
NOTREACHED(); NOTREACHED();
return; return;
} }
pp::Rect rect = engine->pages_[page_index]->PageToScreen( gfx::Rect rect = engine->pages_[page_index]->PageToScreen(
PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_, PointFromPPPoint(engine->GetVisibleRect().point()), engine->current_zoom_,
left, top, right, bottom, left, top, right, bottom,
engine->layout_.options().default_page_orientation()); engine->layout_.options().default_page_orientation());
if (rect.IsEmpty()) if (rect.IsEmpty())
return; return;
engine->form_highlights_.push_back(rect); engine->form_highlights_.push_back(PPRectFromRect(rect));
} }
// static // static
......
...@@ -634,9 +634,9 @@ std::vector<PDFEngine::AccessibilityLinkInfo> PDFiumPage::GetLinkInfo() { ...@@ -634,9 +634,9 @@ std::vector<PDFEngine::AccessibilityLinkInfo> PDFiumPage::GetLinkInfo() {
cur_info.start_char_index = link.start_char_index; cur_info.start_char_index = link.start_char_index;
cur_info.char_count = link.char_count; cur_info.char_count = link.char_count;
pp::Rect link_rect; gfx::Rect link_rect;
for (const auto& rect : link.bounding_rects) for (const auto& rect : link.bounding_rects)
link_rect = link_rect.Union(rect); link_rect.Union(rect);
cur_info.bounds = pp::FloatRect(link_rect.x(), link_rect.y(), cur_info.bounds = pp::FloatRect(link_rect.x(), link_rect.y(),
link_rect.width(), link_rect.height()); link_rect.width(), link_rect.height());
...@@ -758,7 +758,7 @@ PDFiumPage::Area PDFiumPage::GetCharIndex(const gfx::Point& point, ...@@ -758,7 +758,7 @@ PDFiumPage::Area PDFiumPage::GetCharIndex(const gfx::Point& point,
LinkTarget* target) { LinkTarget* target) {
if (!available_) if (!available_)
return NONSELECTABLE_AREA; return NONSELECTABLE_AREA;
gfx::Point device_point = point - RectFromPPRect(rect_).OffsetFromOrigin(); gfx::Point device_point = point - rect_.OffsetFromOrigin();
double new_x; double new_x;
double new_y; double new_y;
FPDF_BOOL ret = FPDF_BOOL ret =
...@@ -933,9 +933,9 @@ int PDFiumPage::GetLink(int char_index, LinkTarget* target) { ...@@ -933,9 +933,9 @@ int PDFiumPage::GetLink(int char_index, LinkTarget* target) {
return -1; return -1;
} }
pp::Point origin(PageToScreen(gfx::Point(), 1.0, left, top, right, bottom, gfx::Point origin = PageToScreen(gfx::Point(), 1.0, left, top, right, bottom,
PageOrientation::kOriginal) PageOrientation::kOriginal)
.point()); .origin();
for (size_t i = 0; i < links_.size(); ++i) { for (size_t i = 0; i < links_.size(); ++i) {
for (const auto& rect : links_[i].bounding_rects) { for (const auto& rect : links_[i].bounding_rects) {
if (rect.Contains(origin)) { if (rect.Contains(origin)) {
...@@ -1005,8 +1005,8 @@ void PDFiumPage::PopulateWebLinks() { ...@@ -1005,8 +1005,8 @@ void PDFiumPage::PopulateWebLinks() {
double right; double right;
double bottom; double bottom;
FPDFLink_GetRect(links.get(), i, j, &left, &top, &right, &bottom); FPDFLink_GetRect(links.get(), i, j, &left, &top, &right, &bottom);
pp::Rect rect = PageToScreen(gfx::Point(), 1.0, left, top, right, bottom, gfx::Rect rect = PageToScreen(gfx::Point(), 1.0, left, top, right, bottom,
PageOrientation::kOriginal); PageOrientation::kOriginal);
if (rect.IsEmpty()) if (rect.IsEmpty())
continue; continue;
link.bounding_rects.push_back(rect); link.bounding_rects.push_back(rect);
...@@ -1400,15 +1400,15 @@ bool PDFiumPage::GetUnderlyingTextRangeForRect(const pp::FloatRect& rect, ...@@ -1400,15 +1400,15 @@ bool PDFiumPage::GetUnderlyingTextRangeForRect(const pp::FloatRect& rect,
return true; return true;
} }
pp::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point, gfx::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point,
double zoom, double zoom,
double left, double left,
double top, double top,
double right, double right,
double bottom, double bottom,
PageOrientation orientation) const { PageOrientation orientation) const {
if (!available_) if (!available_)
return pp::Rect(); return gfx::Rect();
double start_x = (rect_.x() - page_point.x()) * zoom; double start_x = (rect_.x() - page_point.x()) * zoom;
double start_y = (rect_.y() - page_point.y()) * zoom; double start_y = (rect_.y() - page_point.y()) * zoom;
...@@ -1418,7 +1418,7 @@ pp::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point, ...@@ -1418,7 +1418,7 @@ pp::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point,
!base::IsValueInRangeForNumericType<int>(start_y) || !base::IsValueInRangeForNumericType<int>(start_y) ||
!base::IsValueInRangeForNumericType<int>(size_x) || !base::IsValueInRangeForNumericType<int>(size_x) ||
!base::IsValueInRangeForNumericType<int>(size_y)) { !base::IsValueInRangeForNumericType<int>(size_y)) {
return pp::Rect(); return gfx::Rect();
} }
int new_left; int new_left;
...@@ -1451,10 +1451,10 @@ pp::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point, ...@@ -1451,10 +1451,10 @@ pp::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point,
new_size_y -= new_top; new_size_y -= new_top;
new_size_y += 1; new_size_y += 1;
if (!new_size_x.IsValid() || !new_size_y.IsValid()) if (!new_size_x.IsValid() || !new_size_y.IsValid())
return pp::Rect(); return gfx::Rect();
return pp::Rect(new_left, new_top, new_size_x.ValueOrDie(), return gfx::Rect(new_left, new_top, new_size_x.ValueOrDie(),
new_size_y.ValueOrDie()); new_size_y.ValueOrDie());
} }
PDFiumPage::ScopedUnloadPreventer::ScopedUnloadPreventer(PDFiumPage* page) PDFiumPage::ScopedUnloadPreventer::ScopedUnloadPreventer(PDFiumPage* page)
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include "pdf/page_orientation.h" #include "pdf/page_orientation.h"
#include "pdf/pdf_engine.h" #include "pdf/pdf_engine.h"
#include "ppapi/cpp/private/pdf.h" #include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/rect.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h" #include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_doc.h" #include "third_party/pdfium/public/fpdf_doc.h"
#include "third_party/pdfium/public/fpdf_formfill.h" #include "third_party/pdfium/public/fpdf_formfill.h"
#include "third_party/pdfium/public/fpdf_text.h" #include "third_party/pdfium/public/fpdf_text.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
namespace gfx { namespace gfx {
class Point; class Point;
...@@ -149,18 +149,18 @@ class PDFiumPage { ...@@ -149,18 +149,18 @@ class PDFiumPage {
int* char_len); int* char_len);
// Converts from page coordinates to screen coordinates. // Converts from page coordinates to screen coordinates.
pp::Rect PageToScreen(const gfx::Point& page_point, gfx::Rect PageToScreen(const gfx::Point& page_point,
double zoom, double zoom,
double left, double left,
double top, double top,
double right, double right,
double bottom, double bottom,
PageOrientation orientation) const; PageOrientation orientation) const;
int index() const { return index_; } int index() const { return index_; }
const pp::Rect& rect() const { return rect_; } const gfx::Rect& rect() const { return rect_; }
void set_rect(const pp::Rect& r) { rect_ = r; } void set_rect(const gfx::Rect& r) { rect_ = r; }
// Availability is a one-way transition: A page can become available, but it // Availability is a one-way transition: A page can become available, but it
// cannot become unavailable (unless deleted entirely). // cannot become unavailable (unless deleted entirely).
...@@ -208,7 +208,7 @@ class PDFiumPage { ...@@ -208,7 +208,7 @@ class PDFiumPage {
int32_t start_char_index = -1; int32_t start_char_index = -1;
// Represents the number of characters that the link overlaps with. // Represents the number of characters that the link overlaps with.
int32_t char_count = 0; int32_t char_count = 0;
std::vector<pp::Rect> bounding_rects; std::vector<gfx::Rect> bounding_rects;
LinkTarget target; LinkTarget target;
}; };
...@@ -218,7 +218,7 @@ class PDFiumPage { ...@@ -218,7 +218,7 @@ class PDFiumPage {
Image(const Image& other); Image(const Image& other);
~Image(); ~Image();
pp::Rect bounding_rect; gfx::Rect bounding_rect;
// Alt text is available only for tagged PDFs. // Alt text is available only for tagged PDFs.
std::string alt_text; std::string alt_text;
}; };
...@@ -233,7 +233,7 @@ class PDFiumPage { ...@@ -233,7 +233,7 @@ class PDFiumPage {
int32_t start_char_index = -1; int32_t start_char_index = -1;
// Number of characters encompassed by this highlight. // Number of characters encompassed by this highlight.
int32_t char_count = 0; int32_t char_count = 0;
pp::Rect bounding_rect; gfx::Rect bounding_rect;
// Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
// follows after it with each using 8 bytes. // follows after it with each using 8 bytes.
...@@ -249,7 +249,7 @@ class PDFiumPage { ...@@ -249,7 +249,7 @@ class PDFiumPage {
FormField(const FormField& other); FormField(const FormField& other);
~FormField(); ~FormField();
pp::Rect bounding_rect; gfx::Rect bounding_rect;
// Represents the name of form field as defined in the field dictionary. // Represents the name of form field as defined in the field dictionary.
std::string name; std::string name;
// Represents the flags of form field as defined in the field dictionary. // Represents the flags of form field as defined in the field dictionary.
...@@ -377,7 +377,7 @@ class PDFiumPage { ...@@ -377,7 +377,7 @@ class PDFiumPage {
ScopedFPDFTextPage text_page_; ScopedFPDFTextPage text_page_;
int index_; int index_;
int preventing_unload_count_ = 0; int preventing_unload_count_ = 0;
pp::Rect rect_; gfx::Rect rect_;
bool calculated_links_ = false; bool calculated_links_ = false;
std::vector<Link> links_; std::vector<Link> links_;
bool calculated_images_ = false; bool calculated_images_ = false;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_pdf.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/pdfium/public/fpdf_formfill.h" #include "third_party/pdfium/public/fpdf_formfill.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -116,9 +117,9 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) { ...@@ -116,9 +117,9 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) {
EXPECT_EQ(16, link.char_count); EXPECT_EQ(16, link.char_count);
ASSERT_EQ(1u, link.bounding_rects.size()); ASSERT_EQ(1u, link.bounding_rects.size());
if (is_chromeos) { if (is_chromeos) {
CompareRect({75, 192, 110, 15}, link.bounding_rects[0]); EXPECT_EQ(gfx::Rect(75, 192, 110, 15), link.bounding_rects[0]);
} else { } else {
CompareRect({75, 191, 110, 16}, link.bounding_rects[0]); EXPECT_EQ(gfx::Rect(75, 191, 110, 16), link.bounding_rects[0]);
} }
const PDFiumPage::Link& second_link = links[1]; const PDFiumPage::Link& second_link = links[1];
...@@ -127,9 +128,9 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) { ...@@ -127,9 +128,9 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) {
EXPECT_EQ(15, second_link.char_count); EXPECT_EQ(15, second_link.char_count);
ASSERT_EQ(1u, second_link.bounding_rects.size()); ASSERT_EQ(1u, second_link.bounding_rects.size());
if (is_chromeos) { if (is_chromeos) {
CompareRect({131, 120, 138, 22}, second_link.bounding_rects[0]); EXPECT_EQ(gfx::Rect(131, 120, 138, 22), second_link.bounding_rects[0]);
} else { } else {
CompareRect({131, 121, 138, 20}, second_link.bounding_rects[0]); EXPECT_EQ(gfx::Rect(131, 121, 138, 20), second_link.bounding_rects[0]);
} }
const PDFiumPage::Link& third_link = links[2]; const PDFiumPage::Link& third_link = links[2];
...@@ -137,14 +138,14 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) { ...@@ -137,14 +138,14 @@ TEST_F(PDFiumPageLinkTest, TestLinkGeneration) {
EXPECT_EQ(92, third_link.start_char_index); EXPECT_EQ(92, third_link.start_char_index);
EXPECT_EQ(17, third_link.char_count); EXPECT_EQ(17, third_link.char_count);
ASSERT_EQ(1u, third_link.bounding_rects.size()); ASSERT_EQ(1u, third_link.bounding_rects.size());
CompareRect({82, 67, 161, 21}, third_link.bounding_rects[0]); EXPECT_EQ(gfx::Rect(82, 67, 161, 21), third_link.bounding_rects[0]);
} }
TEST_F(PDFiumPageLinkTest, TestAnnotLinkGeneration) { TEST_F(PDFiumPageLinkTest, TestAnnotLinkGeneration) {
struct ExpectedLink { struct ExpectedLink {
int32_t start_char_index; int32_t start_char_index;
int32_t char_count; int32_t char_count;
std::vector<pp::Rect> bounding_rects; std::vector<gfx::Rect> bounding_rects;
std::string url; std::string url;
int page; int page;
float y_in_pixels; float y_in_pixels;
...@@ -181,8 +182,8 @@ TEST_F(PDFiumPageLinkTest, TestAnnotLinkGeneration) { ...@@ -181,8 +182,8 @@ TEST_F(PDFiumPageLinkTest, TestAnnotLinkGeneration) {
size_t bounds_size = actual_current_link.bounding_rects.size(); size_t bounds_size = actual_current_link.bounding_rects.size();
ASSERT_EQ(expected_current_link.bounding_rects.size(), bounds_size); ASSERT_EQ(expected_current_link.bounding_rects.size(), bounds_size);
for (size_t bounds_index = 0; bounds_index < bounds_size; ++bounds_index) { for (size_t bounds_index = 0; bounds_index < bounds_size; ++bounds_index) {
CompareRect(expected_current_link.bounding_rects[bounds_index], EXPECT_EQ(expected_current_link.bounding_rects[bounds_index],
actual_current_link.bounding_rects[bounds_index]); actual_current_link.bounding_rects[bounds_index]);
} }
EXPECT_EQ(expected_current_link.url, actual_current_link.target.url); EXPECT_EQ(expected_current_link.url, actual_current_link.target.url);
if (actual_current_link.target.url.empty()) { if (actual_current_link.target.url.empty()) {
...@@ -206,11 +207,11 @@ TEST_F(PDFiumPageImageTest, TestCalculateImages) { ...@@ -206,11 +207,11 @@ TEST_F(PDFiumPageImageTest, TestCalculateImages) {
PDFiumPage& page = GetPDFiumPageForTest(*engine, 0); PDFiumPage& page = GetPDFiumPageForTest(*engine, 0);
page.CalculateImages(); page.CalculateImages();
ASSERT_EQ(3u, page.images_.size()); ASSERT_EQ(3u, page.images_.size());
CompareRect({380, 78, 67, 68}, page.images_[0].bounding_rect); EXPECT_EQ(gfx::Rect(380, 78, 67, 68), page.images_[0].bounding_rect);
EXPECT_EQ("Image 1", page.images_[0].alt_text); EXPECT_EQ("Image 1", page.images_[0].alt_text);
CompareRect({380, 385, 27, 28}, page.images_[1].bounding_rect); EXPECT_EQ(gfx::Rect(380, 385, 27, 28), page.images_[1].bounding_rect);
EXPECT_EQ("Image 2", page.images_[1].alt_text); EXPECT_EQ("Image 2", page.images_[1].alt_text);
CompareRect({380, 678, 1, 1}, page.images_[2].bounding_rect); EXPECT_EQ(gfx::Rect(380, 678, 1, 1), page.images_[2].bounding_rect);
EXPECT_EQ("Image 3", page.images_[2].alt_text); EXPECT_EQ("Image 3", page.images_[2].alt_text);
} }
...@@ -224,11 +225,11 @@ TEST_F(PDFiumPageImageTest, TestImageAltText) { ...@@ -224,11 +225,11 @@ TEST_F(PDFiumPageImageTest, TestImageAltText) {
PDFiumPage& page = GetPDFiumPageForTest(*engine, 0); PDFiumPage& page = GetPDFiumPageForTest(*engine, 0);
page.CalculateImages(); page.CalculateImages();
ASSERT_EQ(3u, page.images_.size()); ASSERT_EQ(3u, page.images_.size());
CompareRect({380, 78, 67, 68}, page.images_[0].bounding_rect); EXPECT_EQ(gfx::Rect(380, 78, 67, 68), page.images_[0].bounding_rect);
EXPECT_EQ("Image 1", page.images_[0].alt_text); EXPECT_EQ("Image 1", page.images_[0].alt_text);
CompareRect({380, 385, 27, 28}, page.images_[1].bounding_rect); EXPECT_EQ(gfx::Rect(380, 385, 27, 28), page.images_[1].bounding_rect);
EXPECT_EQ("", page.images_[1].alt_text); EXPECT_EQ("", page.images_[1].alt_text);
CompareRect({380, 678, 1, 1}, page.images_[2].bounding_rect); EXPECT_EQ(gfx::Rect(380, 678, 1, 1), page.images_[2].bounding_rect);
EXPECT_EQ("", page.images_[2].alt_text); EXPECT_EQ("", page.images_[2].alt_text);
} }
...@@ -437,7 +438,7 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) { ...@@ -437,7 +438,7 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) {
struct ExpectedHighlight { struct ExpectedHighlight {
int32_t start_char_index; int32_t start_char_index;
int32_t char_count; int32_t char_count;
pp::Rect bounding_rect; gfx::Rect bounding_rect;
uint32_t color; uint32_t color;
}; };
...@@ -464,8 +465,8 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) { ...@@ -464,8 +465,8 @@ TEST_F(PDFiumPageHighlightTest, TestPopulateHighlights) {
page.highlights_[i].start_char_index); page.highlights_[i].start_char_index);
ASSERT_EQ(kExpectedHighlights[i].char_count, ASSERT_EQ(kExpectedHighlights[i].char_count,
page.highlights_[i].char_count); page.highlights_[i].char_count);
CompareRect(kExpectedHighlights[i].bounding_rect, EXPECT_EQ(kExpectedHighlights[i].bounding_rect,
page.highlights_[i].bounding_rect); page.highlights_[i].bounding_rect);
ASSERT_EQ(kExpectedHighlights[i].color, page.highlights_[i].color); ASSERT_EQ(kExpectedHighlights[i].color, page.highlights_[i].color);
} }
} }
...@@ -476,7 +477,7 @@ TEST_F(PDFiumPageTextFieldTest, TestPopulateTextFields) { ...@@ -476,7 +477,7 @@ TEST_F(PDFiumPageTextFieldTest, TestPopulateTextFields) {
struct ExpectedTextField { struct ExpectedTextField {
const char* name; const char* name;
const char* value; const char* value;
pp::Rect bounding_rect; gfx::Rect bounding_rect;
int flags; int flags;
}; };
...@@ -500,8 +501,8 @@ TEST_F(PDFiumPageTextFieldTest, TestPopulateTextFields) { ...@@ -500,8 +501,8 @@ TEST_F(PDFiumPageTextFieldTest, TestPopulateTextFields) {
for (size_t i = 0; i < text_fields_count; ++i) { for (size_t i = 0; i < text_fields_count; ++i) {
EXPECT_EQ(kExpectedTextFields[i].name, page.text_fields_[i].name); EXPECT_EQ(kExpectedTextFields[i].name, page.text_fields_[i].name);
EXPECT_EQ(kExpectedTextFields[i].value, page.text_fields_[i].value); EXPECT_EQ(kExpectedTextFields[i].value, page.text_fields_[i].value);
CompareRect(kExpectedTextFields[i].bounding_rect, EXPECT_EQ(kExpectedTextFields[i].bounding_rect,
page.text_fields_[i].bounding_rect); page.text_fields_[i].bounding_rect);
EXPECT_EQ(kExpectedTextFields[i].flags, page.text_fields_[i].flags); EXPECT_EQ(kExpectedTextFields[i].flags, page.text_fields_[i].flags);
} }
} }
...@@ -517,7 +518,7 @@ TEST_F(PDFiumPageChoiceFieldTest, TestPopulateChoiceFields) { ...@@ -517,7 +518,7 @@ TEST_F(PDFiumPageChoiceFieldTest, TestPopulateChoiceFields) {
struct ExpectedChoiceField { struct ExpectedChoiceField {
const char* name; const char* name;
std::vector<struct ExpectedChoiceFieldOption> options; std::vector<struct ExpectedChoiceFieldOption> options;
pp::Rect bounding_rect; gfx::Rect bounding_rect;
int flags; int flags;
}; };
...@@ -587,8 +588,8 @@ TEST_F(PDFiumPageChoiceFieldTest, TestPopulateChoiceFields) { ...@@ -587,8 +588,8 @@ TEST_F(PDFiumPageChoiceFieldTest, TestPopulateChoiceFields) {
EXPECT_EQ(kExpectedChoiceFields[i].options[j].is_selected, EXPECT_EQ(kExpectedChoiceFields[i].options[j].is_selected,
page.choice_fields_[i].options[j].is_selected); page.choice_fields_[i].options[j].is_selected);
} }
CompareRect(kExpectedChoiceFields[i].bounding_rect, EXPECT_EQ(kExpectedChoiceFields[i].bounding_rect,
page.choice_fields_[i].bounding_rect); page.choice_fields_[i].bounding_rect);
EXPECT_EQ(kExpectedChoiceFields[i].flags, page.choice_fields_[i].flags); EXPECT_EQ(kExpectedChoiceFields[i].flags, page.choice_fields_[i].flags);
} }
} }
...@@ -604,7 +605,7 @@ TEST_F(PDFiumPageButtonTest, TestPopulateButtons) { ...@@ -604,7 +605,7 @@ TEST_F(PDFiumPageButtonTest, TestPopulateButtons) {
bool is_checked; bool is_checked;
uint32_t control_count; uint32_t control_count;
int control_index; int control_index;
pp::Rect bounding_rect; gfx::Rect bounding_rect;
}; };
static const ExpectedButton kExpectedButtons[] = {{"readOnlyCheckbox", static const ExpectedButton kExpectedButtons[] = {{"readOnlyCheckbox",
...@@ -669,8 +670,8 @@ TEST_F(PDFiumPageButtonTest, TestPopulateButtons) { ...@@ -669,8 +670,8 @@ TEST_F(PDFiumPageButtonTest, TestPopulateButtons) {
page.buttons_[i].control_count); page.buttons_[i].control_count);
EXPECT_EQ(kExpectedButtons[i].control_index, EXPECT_EQ(kExpectedButtons[i].control_index,
page.buttons_[i].control_index); page.buttons_[i].control_index);
CompareRect(kExpectedButtons[i].bounding_rect, EXPECT_EQ(kExpectedButtons[i].bounding_rect,
page.buttons_[i].bounding_rect); page.buttons_[i].bounding_rect);
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#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"
namespace chrome_pdf { namespace chrome_pdf {
...@@ -83,11 +84,11 @@ const std::vector<pp::Rect>& PDFiumRange::GetScreenRects( ...@@ -83,11 +84,11 @@ const std::vector<pp::Rect>& PDFiumRange::GetScreenRects(
double right; double right;
double bottom; double bottom;
FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom); FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom);
pp::Rect rect = gfx::Rect rect =
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(rect); cached_screen_rects_.push_back(PPRectFromRect(rect));
} }
return cached_screen_rects_; return cached_screen_rects_;
......
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