Commit 0ea7ec8e authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Refactor draw_utils::GetSurroundingRect() to not take pp::Rect.

Currently draw_utils::GetSurroundingRect() takes a pp::Rect object
and uses only the y-component and height, which means it uses only
half of the structs attributes.

This refactor makes it so GetSurroundingRect() just takes |page_y|
and |page_height| as individual int values, reducing the amount of
unnecessary data sent.

Change-Id: Ie201b4e2d5d6f3c246173782af43cb44890014ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715789Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Cr-Commit-Position: refs/heads/master@{#680132}
parent 9fca1bc1
......@@ -80,13 +80,14 @@ pp::Rect GetScreenRect(const pp::Rect& rect,
return pp::Rect(x, y, right - x, bottom - y);
}
pp::Rect GetSurroundingRect(const pp::Rect& rect,
pp::Rect GetSurroundingRect(int page_y,
int page_height,
const PageInsetSizes& inset_sizes,
int doc_width,
int bottom_separator) {
return pp::Rect(
0, rect.y() - inset_sizes.top, doc_width,
rect.height() + inset_sizes.top + inset_sizes.bottom + bottom_separator);
0, page_y - inset_sizes.top, doc_width,
page_height + inset_sizes.top + inset_sizes.bottom + bottom_separator);
}
pp::Rect GetLeftRectForTwoUpView(const pp::Size& rect_size,
......
......@@ -73,11 +73,12 @@ pp::Rect GetScreenRect(const pp::Rect& rect,
const pp::Point& position,
double zoom);
// Given |rect|, |inset_sizes|, |doc_width|, and |bottom_separator| all in the
// same coordinate space, return |rect| and its surrounding border areas and
// |bottom_separator|. This includes the sides if the page is narrower than the
// document.
pp::Rect GetSurroundingRect(const pp::Rect& rect,
// Given |page_y|, |page_height|, |inset_sizes|, |doc_width|, and
// |bottom_separator| all in the same coordinate space, return the page and its
// surrounding border areas and |bottom_separator|. This includes the sides if
// the page is narrower than the document.
pp::Rect GetSurroundingRect(int page_y,
int page_height,
const PageInsetSizes& inset_sizes,
int doc_width,
int bottom_separator);
......
......@@ -263,32 +263,29 @@ TEST(CoordinateTest, GetSurroundingRect) {
constexpr int kDocWidth = 1000;
// Test various position, sizes, and document width.
pp::Rect rect(0, 100, 200, 300);
rect =
GetSurroundingRect(rect, kSingleViewInsets, kDocWidth, kBottomSeparator);
pp::Rect rect = GetSurroundingRect(100, 300, kSingleViewInsets, kDocWidth,
kBottomSeparator);
EXPECT_EQ(0, rect.x());
EXPECT_EQ(97, rect.y());
EXPECT_EQ(1000, rect.width());
EXPECT_EQ(314, rect.height());
rect.SetRect(1000, 40, 5000, 200);
rect =
GetSurroundingRect(rect, kSingleViewInsets, kDocWidth, kBottomSeparator);
rect = GetSurroundingRect(40, 200, kSingleViewInsets, kDocWidth,
kBottomSeparator);
EXPECT_EQ(0, rect.x());
EXPECT_EQ(37, rect.y());
EXPECT_EQ(1000, rect.width());
EXPECT_EQ(214, rect.height());
rect.SetRect(-100, 200, 300, 500);
rect =
GetSurroundingRect(rect, kSingleViewInsets, kDocWidth, kBottomSeparator);
rect = GetSurroundingRect(200, 500, kSingleViewInsets, kDocWidth,
kBottomSeparator);
EXPECT_EQ(0, rect.x());
EXPECT_EQ(197, rect.y());
EXPECT_EQ(1000, rect.width());
EXPECT_EQ(514, rect.height());
rect.SetRect(10, -100, 4000, 300);
rect = GetSurroundingRect(rect, kSingleViewInsets, 200, kBottomSeparator);
rect =
GetSurroundingRect(-100, 300, kSingleViewInsets, 200, kBottomSeparator);
EXPECT_EQ(0, rect.x());
EXPECT_EQ(-103, rect.y());
EXPECT_EQ(200, rect.width());
......
......@@ -3139,7 +3139,8 @@ pp::Rect PDFiumEngine::GetVisibleRect() const {
pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const {
const pp::Rect& page_rect = pages_[page_index]->rect();
return GetScreenRect(draw_utils::GetSurroundingRect(
page_rect, kSingleViewInsets, document_size_.width(), kBottomSeparator));
page_rect.y(), page_rect.height(), kSingleViewInsets,
document_size_.width(), kBottomSeparator));
}
pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) 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