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,7 +539,7 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(15 * kDefaultRequestSize,
constexpr gfx::Range range_requested(15 * kDefaultRequestSize,
16 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -575,7 +575,7 @@ 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,
constexpr gfx::Range range_requested(35 * kDefaultRequestSize,
36 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -597,7 +597,7 @@ 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,
constexpr gfx::Range range_requested(70 * kDefaultRequestSize,
71 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -676,7 +676,7 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(13 * kDefaultRequestSize,
constexpr gfx::Range range_requested(13 * kDefaultRequestSize,
14 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -694,7 +694,7 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(26 * kDefaultRequestSize,
constexpr gfx::Range range_requested(26 * kDefaultRequestSize,
27 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -711,7 +711,7 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(39 * kDefaultRequestSize,
constexpr gfx::Range range_requested(39 * kDefaultRequestSize,
40 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -796,7 +796,7 @@ TEST_F(DocumentLoaderImplTest, MergePendingRequests) {
// Send initial data from FullPageLoader.
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
const gfx::Range range_requested(16 * kDefaultRequestSize,
constexpr gfx::Range range_requested(16 * kDefaultRequestSize,
18 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start());
......@@ -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);
......
......@@ -47,118 +47,118 @@ namespace chrome_pdf {
namespace {
const char kChromePrint[] = "chrome://print/";
const char kChromeExtension[] =
constexpr char kChromePrint[] = "chrome://print/";
constexpr char kChromeExtension[] =
"chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai";
// Constants used in handling postMessage() messages.
const char kType[] = "type";
const char kJSId[] = "id";
constexpr char kType[] = "type";
constexpr char kJSId[] = "id";
// Beep messge arguments. (Plugin -> Page).
const char kJSBeepType[] = "beep";
constexpr char kJSBeepType[] = "beep";
// Viewport message arguments. (Page -> Plugin).
const char kJSViewportType[] = "viewport";
const char kJSUserInitiated[] = "userInitiated";
const char kJSXOffset[] = "xOffset";
const char kJSYOffset[] = "yOffset";
const char kJSZoom[] = "zoom";
const char kJSPinchPhase[] = "pinchPhase";
constexpr char kJSViewportType[] = "viewport";
constexpr char kJSUserInitiated[] = "userInitiated";
constexpr char kJSXOffset[] = "xOffset";
constexpr char kJSYOffset[] = "yOffset";
constexpr char kJSZoom[] = "zoom";
constexpr char kJSPinchPhase[] = "pinchPhase";
// kJSPinchX and kJSPinchY represent the center of the pinch gesture.
const char kJSPinchX[] = "pinchX";
const char kJSPinchY[] = "pinchY";
constexpr char kJSPinchX[] = "pinchX";
constexpr char kJSPinchY[] = "pinchY";
// kJSPinchVector represents the amount of panning caused by the pinch gesture.
const char kJSPinchVectorX[] = "pinchVectorX";
const char kJSPinchVectorY[] = "pinchVectorY";
constexpr char kJSPinchVectorX[] = "pinchVectorX";
constexpr char kJSPinchVectorY[] = "pinchVectorY";
// Stop scrolling message (Page -> Plugin)
const char kJSStopScrollingType[] = "stopScrolling";
constexpr char kJSStopScrollingType[] = "stopScrolling";
// Document dimension arguments (Plugin -> Page).
const char kJSDocumentDimensionsType[] = "documentDimensions";
const char kJSDocumentWidth[] = "width";
const char kJSDocumentHeight[] = "height";
const char kJSPageDimensions[] = "pageDimensions";
const char kJSPageX[] = "x";
const char kJSPageY[] = "y";
const char kJSPageWidth[] = "width";
const char kJSPageHeight[] = "height";
constexpr char kJSDocumentDimensionsType[] = "documentDimensions";
constexpr char kJSDocumentWidth[] = "width";
constexpr char kJSDocumentHeight[] = "height";
constexpr char kJSPageDimensions[] = "pageDimensions";
constexpr char kJSPageX[] = "x";
constexpr char kJSPageY[] = "y";
constexpr char kJSPageWidth[] = "width";
constexpr char kJSPageHeight[] = "height";
// Document load progress arguments (Plugin -> Page)
const char kJSLoadProgressType[] = "loadProgress";
const char kJSProgressPercentage[] = "progress";
constexpr char kJSLoadProgressType[] = "loadProgress";
constexpr char kJSProgressPercentage[] = "progress";
// Document print preview loaded (Plugin -> Page)
const char kJSPreviewLoadedType[] = "printPreviewLoaded";
constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded";
// Metadata
const char kJSMetadataType[] = "metadata";
const char kJSBookmarks[] = "bookmarks";
const char kJSTitle[] = "title";
constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSBookmarks[] = "bookmarks";
constexpr char kJSTitle[] = "title";
// Get password (Plugin -> Page)
const char kJSGetPasswordType[] = "getPassword";
constexpr char kJSGetPasswordType[] = "getPassword";
// Get password complete arguments (Page -> Plugin)
const char kJSGetPasswordCompleteType[] = "getPasswordComplete";
const char kJSPassword[] = "password";
constexpr char kJSGetPasswordCompleteType[] = "getPasswordComplete";
constexpr char kJSPassword[] = "password";
// Print (Page -> Plugin)
const char kJSPrintType[] = "print";
constexpr char kJSPrintType[] = "print";
// Save (Page -> Plugin)
const char kJSSaveType[] = "save";
constexpr char kJSSaveType[] = "save";
// Go to page (Plugin -> Page)
const char kJSGoToPageType[] = "goToPage";
const char kJSPageNumber[] = "page";
constexpr char kJSGoToPageType[] = "goToPage";
constexpr char kJSPageNumber[] = "page";
// Reset print preview mode (Page -> Plugin)
const char kJSResetPrintPreviewModeType[] = "resetPrintPreviewMode";
const char kJSPrintPreviewUrl[] = "url";
const char kJSPrintPreviewGrayscale[] = "grayscale";
const char kJSPrintPreviewPageCount[] = "pageCount";
constexpr char kJSResetPrintPreviewModeType[] = "resetPrintPreviewMode";
constexpr char kJSPrintPreviewUrl[] = "url";
constexpr char kJSPrintPreviewGrayscale[] = "grayscale";
constexpr char kJSPrintPreviewPageCount[] = "pageCount";
// Load preview page (Page -> Plugin)
const char kJSLoadPreviewPageType[] = "loadPreviewPage";
const char kJSPreviewPageUrl[] = "url";
const char kJSPreviewPageIndex[] = "index";
constexpr char kJSLoadPreviewPageType[] = "loadPreviewPage";
constexpr char kJSPreviewPageUrl[] = "url";
constexpr char kJSPreviewPageIndex[] = "index";
// Set scroll position (Plugin -> Page)
const char kJSSetScrollPositionType[] = "setScrollPosition";
const char kJSPositionX[] = "x";
const char kJSPositionY[] = "y";
constexpr char kJSSetScrollPositionType[] = "setScrollPosition";
constexpr char kJSPositionX[] = "x";
constexpr char kJSPositionY[] = "y";
// Scroll by (Plugin -> Page)
const char kJSScrollByType[] = "scrollBy";
constexpr char kJSScrollByType[] = "scrollBy";
// Cancel the stream URL request (Plugin -> Page)
const char kJSCancelStreamUrlType[] = "cancelStreamUrl";
constexpr char kJSCancelStreamUrlType[] = "cancelStreamUrl";
// Navigate to the given URL (Plugin -> Page)
const char kJSNavigateType[] = "navigate";
const char kJSNavigateUrl[] = "url";
const char kJSNavigateWindowOpenDisposition[] = "disposition";
constexpr char kJSNavigateType[] = "navigate";
constexpr char kJSNavigateUrl[] = "url";
constexpr char kJSNavigateWindowOpenDisposition[] = "disposition";
// Open the email editor with the given parameters (Plugin -> Page)
const char kJSEmailType[] = "email";
const char kJSEmailTo[] = "to";
const char kJSEmailCc[] = "cc";
const char kJSEmailBcc[] = "bcc";
const char kJSEmailSubject[] = "subject";
const char kJSEmailBody[] = "body";
constexpr char kJSEmailType[] = "email";
constexpr char kJSEmailTo[] = "to";
constexpr char kJSEmailCc[] = "cc";
constexpr char kJSEmailBcc[] = "bcc";
constexpr char kJSEmailSubject[] = "subject";
constexpr char kJSEmailBody[] = "body";
// Rotation (Page -> Plugin)
const char kJSRotateClockwiseType[] = "rotateClockwise";
const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
constexpr char kJSRotateClockwiseType[] = "rotateClockwise";
constexpr char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
// Select all text in the document (Page -> Plugin)
const char kJSSelectAllType[] = "selectAll";
constexpr char kJSSelectAllType[] = "selectAll";
// Get the selected text in the document (Page -> Plugin)
const char kJSGetSelectedTextType[] = "getSelectedText";
constexpr char kJSGetSelectedTextType[] = "getSelectedText";
// Reply with selected text (Plugin -> Page)
const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
const char kJSSelectedText[] = "selectedText";
constexpr char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
constexpr char kJSSelectedText[] = "selectedText";
// Get the named destination with the given name (Page -> Plugin)
const char kJSGetNamedDestinationType[] = "getNamedDestination";
const char kJSGetNamedDestination[] = "namedDestination";
constexpr char kJSGetNamedDestinationType[] = "getNamedDestination";
constexpr char kJSGetNamedDestination[] = "namedDestination";
// Reply with the page number of the named destination (Plugin -> Page)
const char kJSGetNamedDestinationReplyType[] = "getNamedDestinationReply";
const char kJSNamedDestinationPageNumber[] = "pageNumber";
constexpr char kJSGetNamedDestinationReplyType[] = "getNamedDestinationReply";
constexpr char kJSNamedDestinationPageNumber[] = "pageNumber";
const char kJSTransformPagePointType[] = "transformPagePoint";
const char kJSTransformPagePointReplyType[] = "transformPagePointReply";
constexpr char kJSTransformPagePointType[] = "transformPagePoint";
constexpr char kJSTransformPagePointReplyType[] = "transformPagePointReply";
// Selecting text in document (Plugin -> Page)
const char kJSSetIsSelectingType[] = "setIsSelecting";
const char kJSIsSelecting[] = "isSelecting";
constexpr char kJSSetIsSelectingType[] = "setIsSelecting";
constexpr char kJSIsSelecting[] = "isSelecting";
// Notify when a form field is focused (Plugin -> Page)
const char kJSFieldFocusType[] = "formFocusChange";
const char kJSFieldFocus[] = "focused";
constexpr char kJSFieldFocusType[] = "formFocusChange";
constexpr char kJSFieldFocus[] = "focused";
const int kFindResultCooldownMs = 100;
constexpr int kFindResultCooldownMs = 100;
// Same value as printing::COMPLETE_PREVIEW_DOCUMENT_INDEX.
constexpr int kCompletePDFIndex = -1;
......@@ -167,11 +167,11 @@ constexpr int kInvalidPDFIndex = -2;
// A delay to wait between each accessibility page to keep the system
// responsive.
const int kAccessibilityPageDelayMs = 100;
constexpr int kAccessibilityPageDelayMs = 100;
const double kMinZoom = 0.01;
constexpr double kMinZoom = 0.01;
const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
constexpr char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
// Used for UMA. Do not delete entries, and keep in sync with histograms.xml.
enum PDFFeatures {
......@@ -183,7 +183,7 @@ enum PDFFeatures {
// Used for UMA. Do not delete entries, and keep in sync with histograms.xml
// and pdfium/public/fpdf_annot.h.
const int kAnnotationTypesCount = 28;
constexpr int kAnnotationTypesCount = 28;
PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
pp::Var var;
......@@ -1648,7 +1648,7 @@ void OutOfProcessInstance::DocumentLoadComplete(
}
pp::PDF::SetContentRestriction(this, content_restrictions);
static const int32_t kMaxFileSizeInKB = 12 * 1024 * 1024;
static constexpr int32_t kMaxFileSizeInKB = 12 * 1024 * 1024;
HistogramCustomCounts("PDF.FileSizeInKB", file_size / 1024, 0,
kMaxFileSizeInKB, 50);
HistogramCustomCounts("PDF.PageCount", document_features.page_count, 1,
......
......@@ -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,7 +76,7 @@ TEST_F(PDFiumPrintTest, Basic) {
PDFiumPrint print(&engine);
const PP_PrintSettings_Dev print_settings = {kUSLetterRect,
constexpr PP_PrintSettings_Dev print_settings = {kUSLetterRect,
kUSLetterRect,
kUSLetterSize,
72,
......@@ -84,7 +84,7 @@ TEST_F(PDFiumPrintTest, Basic) {
PP_PRINTSCALINGOPTION_NONE,
PP_FALSE,
PP_PRINTOUTPUTFORMAT_PDF};
const PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
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