Commit 1c5da8e6 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Use constexpr where possible in src/pdf.

Change-Id: Icd771944352b9c161933c477fe714492aa38bbe7
Reviewed-on: https://chromium-review.googlesource.com/c/1265637Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597327}
parent 0b2d3330
......@@ -70,7 +70,7 @@ TEST(ChunkStreamTest, FillGap) {
TEST(ChunkStreamTest, Read) {
TestChunkStream stream;
stream.set_eof_pos(25);
const unsigned char start_value = 33;
constexpr unsigned char start_value = 33;
unsigned char value = start_value;
auto chunk_0 = CreateChunkData();
for (auto& it : *chunk_0) {
......
......@@ -25,7 +25,7 @@ namespace {
// current connection (like playing a cassette tape) and do not send new range
// request (like rewind a cassette tape, and continue playing after).
// Experimentally chosen value.
const int kChunkCloseDistance = 10;
constexpr int kChunkCloseDistance = 10;
// Return true if the HTTP response of |loader| is a successful one and loading
// should continue. 4xx error indicate subsequent requests will fail too.
......
......@@ -232,7 +232,7 @@ class TestClient : public DocumentLoader::Client {
partial_loader_data_.CallOpenCallback(0);
uint32_t length = partial_loader_data_.byte_range().length();
while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize;
constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len);
partial_loader_data_.CallReadCallback(part_len);
length -= part_len;
......@@ -468,7 +468,7 @@ TEST_F(DocumentLoaderImplTest, CompleteWithPartial) {
}
TEST_F(DocumentLoaderImplTest, PartialRequestLastChunk) {
const uint32_t kLastChunkSize = 300;
constexpr uint32_t kLastChunkSize = 300;
TestClient client;
client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
......@@ -539,8 +539,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(15 * kDefaultRequestSize,
16 * kDefaultRequestSize);
constexpr gfx::Range range_requested(15 * kDefaultRequestSize,
16 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -575,8 +575,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
// Loading should be restarted.
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
// The first requested chunk should be processed.
const gfx::Range range_requested(35 * kDefaultRequestSize,
36 * kDefaultRequestSize);
constexpr gfx::Range range_requested(35 * kDefaultRequestSize,
36 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -597,8 +597,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
// Loading should be restarted .
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
// The first requested chunk should be processed.
const gfx::Range range_requested(70 * kDefaultRequestSize,
71 * kDefaultRequestSize);
constexpr gfx::Range range_requested(70 * kDefaultRequestSize,
71 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -676,8 +676,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(13 * kDefaultRequestSize,
14 * kDefaultRequestSize);
constexpr gfx::Range range_requested(13 * kDefaultRequestSize,
14 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -694,8 +694,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(26 * kDefaultRequestSize,
27 * kDefaultRequestSize);
constexpr gfx::Range range_requested(26 * kDefaultRequestSize,
27 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -711,8 +711,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(39 * kDefaultRequestSize,
40 * kDefaultRequestSize);
constexpr gfx::Range range_requested(39 * kDefaultRequestSize,
40 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -796,8 +796,8 @@ TEST_F(DocumentLoaderImplTest, MergePendingRequests) {
// Send initial data from FullPageLoader.
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
const gfx::Range range_requested(16 * kDefaultRequestSize,
18 * kDefaultRequestSize);
constexpr gfx::Range range_requested(16 * kDefaultRequestSize,
18 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(),
......@@ -1102,7 +1102,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartial) {
client.partial_loader_data()->CallOpenCallback(0);
uint32_t length = expected_length;
while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize;
constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len);
client.partial_loader_data()->CallReadCallback(part_len);
length -= part_len;
......@@ -1144,7 +1144,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartialAtFileEnd) {
client.partial_loader_data()->CallOpenCallback(0);
uint32_t length = client.partial_loader_data()->byte_range().length();
while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize;
constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len);
client.partial_loader_data()->CallReadCallback(part_len);
length -= part_len;
......
......@@ -55,7 +55,7 @@ ShadowMatrix::ShadowMatrix(uint32_t depth, double factor, uint32_t background)
// pv - is a rounding power factor for smoothing corners.
// pv = 2.0 will make corners completely round.
const double pv = 4.0;
constexpr double pv = 4.0;
// pow_pv - cache to avoid recalculating pow(x, pv) every time.
std::vector<double> pow_pv(depth_, 0.0);
......
This diff is collapsed.
......@@ -55,7 +55,7 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
const pp::Size& plugin_size) {
// The amount of additional space in pixels to allocate to the right/bottom of
// the context.
const int kBufferSize = 50;
constexpr int kBufferSize = 50;
// Default to returning the same size.
pp::Size result = current_context_size;
......
......@@ -42,9 +42,9 @@ double CalculateScaleFactor(const gfx::Rect& content_rect,
}
void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box) {
const int kDpi = 72;
const float kPaperWidth = 8.5 * kDpi;
const float kPaperHeight = 11 * kDpi;
constexpr int kDpi = 72;
constexpr float kPaperWidth = 8.5 * kDpi;
constexpr float kPaperHeight = 11 * kDpi;
clip_box->left = 0;
clip_box->bottom = 0;
clip_box->right = rotated ? kPaperHeight : kPaperWidth;
......
......@@ -12,10 +12,10 @@ namespace chrome_pdf {
namespace {
const float kDefaultWidth = 8.5 * printing::kPointsPerInch;
const float kDefaultHeight = 11.0 * printing::kPointsPerInch;
const float kDefaultRatio = kDefaultWidth / kDefaultHeight;
const double kTolerance = 0.0001;
constexpr float kDefaultWidth = 8.5 * printing::kPointsPerInch;
constexpr float kDefaultHeight = 11.0 * printing::kPointsPerInch;
constexpr float kDefaultRatio = kDefaultWidth / kDefaultHeight;
constexpr double kTolerance = 0.0001;
void ExpectDefaultPortraitBox(const PdfRectangle& box) {
EXPECT_FLOAT_EQ(0, box.left);
......@@ -130,7 +130,7 @@ TEST(PdfTransformTest, CalculateMediaBoxAndCropBox) {
ExpectDefaultLandscapeBox(crop_box);
// Assume crop box is missing.
const PdfRectangle expected_box = {0, 0, 42, 420};
constexpr PdfRectangle expected_box = {0, 0, 42, 420};
media_box = expected_box;
InitializeBoxToInvalidValues(&crop_box);
CalculateMediaBoxAndCropBox(false, true, false, &media_box, &crop_box);
......@@ -188,7 +188,7 @@ TEST(PdfTransformTest, CalculateClipBoxBoundary) {
}
TEST(PdfTransformTest, CalculateScaledClipBoxOffset) {
const gfx::Rect rect(kDefaultWidth, kDefaultHeight);
constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box;
double offset_x;
double offset_y;
......@@ -210,7 +210,7 @@ TEST(PdfTransformTest, CalculateScaledClipBoxOffset) {
TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
int page_width = kDefaultWidth;
int page_height = kDefaultHeight;
const gfx::Rect rect(kDefaultWidth, kDefaultHeight);
constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box;
double offset_x;
double offset_y;
......@@ -280,12 +280,12 @@ TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
TEST(PdfTransformTest, ReversedMediaBox) {
int page_width = kDefaultWidth;
int page_height = kDefaultHeight;
const gfx::Rect rect(kDefaultWidth, kDefaultHeight);
constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box;
double offset_x;
double offset_y;
const PdfRectangle expected_media_box_b491160 = {0, -792, 612, 0};
constexpr PdfRectangle expected_media_box_b491160 = {0, -792, 612, 0};
PdfRectangle media_box_b491160 = {0, 0, 612, -792};
CalculateMediaBoxAndCropBox(false, true, false, &media_box_b491160,
&clip_box);
......
......@@ -76,20 +76,20 @@ static_assert(static_cast<int>(PDFEngine::FormType::kCount) == FORMTYPE_COUNT,
namespace {
const int32_t kPageShadowTop = 3;
const int32_t kPageShadowBottom = 7;
const int32_t kPageShadowLeft = 5;
const int32_t kPageShadowRight = 5;
constexpr int32_t kPageShadowTop = 3;
constexpr int32_t kPageShadowBottom = 7;
constexpr int32_t kPageShadowLeft = 5;
constexpr int32_t kPageShadowRight = 5;
const int32_t kPageSeparatorThickness = 4;
const int32_t kHighlightColorR = 153;
const int32_t kHighlightColorG = 193;
const int32_t kHighlightColorB = 218;
constexpr int32_t kPageSeparatorThickness = 4;
constexpr int32_t kHighlightColorR = 153;
constexpr int32_t kHighlightColorG = 193;
constexpr int32_t kHighlightColorB = 218;
const uint32_t kPendingPageColor = 0xFFEEEEEE;
constexpr uint32_t kPendingPageColor = 0xFFEEEEEE;
const uint32_t kFormHighlightColor = 0xFFE4DD;
const int32_t kFormHighlightAlpha = 100;
constexpr uint32_t kFormHighlightColor = 0xFFE4DD;
constexpr int32_t kFormHighlightAlpha = 100;
constexpr int kMaxPasswordTries = 3;
......@@ -105,12 +105,12 @@ constexpr bool kViewerImplementedPanning = true;
// See Table 3.20 in
// http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2;
const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11;
const uint32_t kPDFPermissionCopyMask = 1 << 4;
const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9;
constexpr uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2;
constexpr uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11;
constexpr uint32_t kPDFPermissionCopyMask = 1 << 4;
constexpr uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9;
const int32_t kLoadingTextVerticalOffset = 50;
constexpr int32_t kLoadingTextVerticalOffset = 50;
// The maximum amount of time we'll spend doing a paint before we give back
// control of the thread.
......@@ -147,8 +147,8 @@ PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) {
"PP_BrowserFont_Trusted_Weight min");
static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8,
"PP_BrowserFont_Trusted_Weight max");
const int kMinimumWeight = 100;
const int kMaximumWeight = 900;
constexpr int kMinimumWeight = 100;
constexpr int kMaximumWeight = 900;
int normalized_weight =
std::min(std::max(weight, kMinimumWeight), kMaximumWeight);
normalized_weight = (normalized_weight / 100) - 1;
......@@ -447,7 +447,7 @@ void FormatStringWithHyphens(base::string16* text) {
std::vector<HyphenPosition> hyphen_positions;
HyphenPosition current_hyphen_position;
bool current_hyphen_position_is_valid = false;
const base::char16 kPdfiumHyphenEOL = 0xfffe;
constexpr base::char16 kPdfiumHyphenEOL = 0xfffe;
for (size_t i = 0; i < text->size(); ++i) {
const base::char16& current_char = (*text)[i];
......@@ -471,7 +471,7 @@ void FormatStringWithHyphens(base::string16* text) {
// With all the hyphen positions, do the search and replace.
while (!hyphen_positions.empty()) {
static const base::char16 kCr[] = {L'\r', L'\0'};
static constexpr base::char16 kCr[] = {L'\r', L'\0'};
const HyphenPosition& position = hyphen_positions.back();
if (position.next_whitespace_position != 0) {
(*text)[position.next_whitespace_position] = L'\n';
......@@ -482,16 +482,16 @@ void FormatStringWithHyphens(base::string16* text) {
}
// Adobe Reader also get rid of trailing spaces right before a CRLF.
static const base::char16 kSpaceCrCn[] = {L' ', L'\r', L'\n', L'\0'};
static const base::char16 kCrCn[] = {L'\r', L'\n', L'\0'};
static constexpr base::char16 kSpaceCrCn[] = {L' ', L'\r', L'\n', L'\0'};
static constexpr base::char16 kCrCn[] = {L'\r', L'\n', L'\0'};
base::ReplaceSubstringsAfterOffset(text, 0, kSpaceCrCn, kCrCn);
}
// Replace CR/LF with just LF on POSIX.
void FormatStringForOS(base::string16* text) {
#if defined(OS_POSIX)
static const base::char16 kCr[] = {L'\r', L'\0'};
static const base::char16 kBlank[] = {L'\0'};
static constexpr base::char16 kCr[] = {L'\r', L'\0'};
static constexpr base::char16 kBlank[] = {L'\0'};
base::ReplaceChars(*text, kCr, kBlank, text);
#elif defined(OS_WIN)
// Do nothing
......@@ -2347,7 +2347,7 @@ pp::VarDictionary PDFiumEngine::TraverseBookmarks(FPDF_BOOKMARK bookmark,
pp::VarArray children;
// Don't trust PDFium to handle circular bookmarks.
const unsigned int kMaxDepth = 128;
constexpr unsigned int kMaxDepth = 128;
if (depth < kMaxDepth) {
int child_index = 0;
std::set<FPDF_BOOKMARK> seen_bookmarks;
......@@ -3435,7 +3435,7 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,
clip_rect.Offset(page_offset_);
// Page drop shadow parameters.
const double factor = 0.5;
constexpr double factor = 0.5;
uint32_t depth =
std::max(std::max(page_rect.x() - shadow_rect.x(),
page_rect.y() - shadow_rect.y()),
......
......@@ -432,7 +432,7 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
// Use quality = 40 as this does not significantly degrade the printed
// document relative to a normal bitmap and provides better compression than
// a higher quality setting.
const int kQuality = 40;
constexpr int kQuality = 40;
SkImageInfo info = SkImageInfo::Make(
FPDFBitmap_GetWidth(bitmap.get()), FPDFBitmap_GetHeight(bitmap.get()),
kBGRA_8888_SkColorType, kOpaque_SkAlphaType);
......
......@@ -76,15 +76,15 @@ TEST_F(PDFiumPrintTest, Basic) {
PDFiumPrint print(&engine);
const PP_PrintSettings_Dev print_settings = {kUSLetterRect,
kUSLetterRect,
kUSLetterSize,
72,
PP_PRINTORIENTATION_NORMAL,
PP_PRINTSCALINGOPTION_NONE,
PP_FALSE,
PP_PRINTOUTPUTFORMAT_PDF};
const PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
constexpr PP_PrintSettings_Dev print_settings = {kUSLetterRect,
kUSLetterRect,
kUSLetterSize,
72,
PP_PRINTORIENTATION_NORMAL,
PP_PRINTSCALINGOPTION_NONE,
PP_FALSE,
PP_PRINTOUTPUTFORMAT_PDF};
constexpr PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
{
// Print 2 pages.
......
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