Commit a9929f15 authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Add handling for two-up view to PDFiumEngine::GetPageScreenRect().

Currently PDFiumEngine::GetPageScreenRect() calculates the area
of the |page_index| page, including the area around it such as
shadows and separators. In two-up view, when two pages are
side-by-side and one page is shorter than the other, the space
below the shorter page must be drawn as empty space to match
the height of the taller page.

This CL refactors PDFiumEngine::GetPageScreenRect() so that when
|two_up_view_| is true, it calls draw_utils::GetSurroundingRect()
with a copy of the rect for |page_index| page with its height set
to the max height of the two pages. It also adds
PDFiumEngine::GetAdjacentPageIndexForTwoUpView() which retrieves
the index of the page adjacent to the current page.

Bug: 51472
Change-Id: I869903f869e926117cd60beb92db0ce96606579a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715116
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680271}
parent 9556034c
...@@ -2867,6 +2867,22 @@ void PDFiumEngine::InsetPage(size_t page_index, ...@@ -2867,6 +2867,22 @@ void PDFiumEngine::InsetPage(size_t page_index,
static_cast<int>(ceil(inset_sizes.bottom * multiplier))); static_cast<int>(ceil(inset_sizes.bottom * multiplier)));
} }
base::Optional<size_t> PDFiumEngine::GetAdjacentPageIndexForTwoUpView(
size_t page_index,
size_t num_of_pages) const {
DCHECK_LT(page_index, num_of_pages);
if (!two_up_view_)
return base::nullopt;
int adjacent_page_offset = page_index % 2 ? -1 : 1;
size_t adjacent_page_index = page_index + adjacent_page_offset;
if (adjacent_page_index >= num_of_pages)
return base::nullopt;
return adjacent_page_index;
}
int PDFiumEngine::StartPaint(int page_index, const pp::Rect& dirty) { int PDFiumEngine::StartPaint(int page_index, const pp::Rect& dirty) {
// For the first time we hit paint, do nothing and just record the paint for // For the first time we hit paint, do nothing and just record the paint for
// the next callback. This keeps the UI responsive in case the user is doing // the next callback. This keeps the UI responsive in case the user is doing
...@@ -3143,9 +3159,20 @@ pp::Rect PDFiumEngine::GetVisibleRect() const { ...@@ -3143,9 +3159,20 @@ 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(); const pp::Rect& page_rect = pages_[page_index]->rect();
draw_utils::PageInsetSizes inset_sizes =
GetInsetSizes(page_index, pages_.size());
int max_page_height = page_rect.height();
base::Optional<size_t> adjacent_page_index =
GetAdjacentPageIndexForTwoUpView(page_index, pages_.size());
if (adjacent_page_index.has_value()) {
max_page_height = std::max(
max_page_height, pages_[adjacent_page_index.value()]->rect().height());
}
return GetScreenRect(draw_utils::GetSurroundingRect( return GetScreenRect(draw_utils::GetSurroundingRect(
page_rect.y(), page_rect.height(), kSingleViewInsets, page_rect.y(), max_page_height, inset_sizes, document_size_.width(),
document_size_.width(), kBottomSeparator)); kBottomSeparator));
} }
pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) const { pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) const {
......
...@@ -289,6 +289,13 @@ class PDFiumEngine : public PDFEngine, ...@@ -289,6 +289,13 @@ class PDFiumEngine : public PDFEngine,
double multiplier, double multiplier,
pp::Rect* rect) const; pp::Rect* rect) const;
// If |two_up_view_| is true, returns the index of the page beside
// |page_index| page. Returns base::nullopt if there is no adjacent page or
// if |two_up_view_| is false.
base::Optional<size_t> GetAdjacentPageIndexForTwoUpView(
size_t page_index,
size_t num_of_pages) const;
void GetAllScreenRectsUnion(const std::vector<PDFiumRange>& rect_range, void GetAllScreenRectsUnion(const std::vector<PDFiumRange>& rect_range,
const pp::Point& offset_point, const pp::Point& offset_point,
std::vector<pp::Rect>* rect_vector) const; std::vector<pp::Rect>* rect_vector) const;
......
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