Skip to content

Commit

Permalink
Move GetFormattedVersion() to //pdf/ui/
Browse files Browse the repository at this point in the history
Meanwhile, rename //pdf/ui/format_page_size* to document_properties*,
since the file supports multiple properties.

This change also paves the way for adding unit tests for the function
in a future change.

Bug: 1184342
Change-Id: I8bbd4a412a91483cd9ed5f274fdb28455ef2840a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2754651
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#862462}
  • Loading branch information
Daniel Hosseinian authored and Chromium LUCI CQ committed Mar 12, 2021
1 parent 0bb2254 commit c5300c6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 57 deletions.
6 changes: 3 additions & 3 deletions pdf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ if (enable_pdf) {
"preview_mode_client.h",
"range_set.cc",
"range_set.h",
"ui/document_properties.cc",
"ui/document_properties.h",
"ui/file_name.cc",
"ui/file_name.h",
"ui/format_page_size.cc",
"ui/format_page_size.h",
"ui/thumbnail.cc",
"ui/thumbnail.h",
"url_loader_wrapper.h",
Expand Down Expand Up @@ -364,8 +364,8 @@ if (enable_pdf) {
"ppapi_migration/url_loader_unittest.cc",
"range_set_unittest.cc",
"test/run_all_unittests.cc",
"ui/document_properties_unittest.cc",
"ui/file_name_unittest.cc",
"ui/format_page_size_unittest.cc",
"ui/thumbnail_unittest.cc",
]

Expand Down
46 changes: 2 additions & 44 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "pdf/ppapi_migration/input_event_conversions.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "pdf/ppapi_migration/value_conversions.h"
#include "pdf/ui/format_page_size.h"
#include "pdf/ui/document_properties.h"
#include "pdf/ui/thumbnail.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/pp_errors.h"
Expand Down Expand Up @@ -502,48 +502,6 @@ pp::PDF::PrivateAccessibilityPageObjects ToPrivateAccessibilityPageObjects(
return pp_page_objects;
}

// Converts |version| to a formatted string.
std::u16string GetFormattedVersion(PdfVersion version) {
double value = 0;
switch (version) {
case PdfVersion::k1_0:
value = 1.0;
break;
case PdfVersion::k1_1:
value = 1.1;
break;
case PdfVersion::k1_2:
value = 1.2;
break;
case PdfVersion::k1_3:
value = 1.3;
break;
case PdfVersion::k1_4:
value = 1.4;
break;
case PdfVersion::k1_5:
value = 1.5;
break;
case PdfVersion::k1_6:
value = 1.6;
break;
case PdfVersion::k1_7:
value = 1.7;
break;
case PdfVersion::k2_0:
value = 2.0;
break;
case PdfVersion::kUnknown:
case PdfVersion::k1_8: // Not an actual version
return std::u16string();
}
// The default case is excluded from the above switch statement to ensure that
// all supported versions are determinantly handled.

DCHECK_NE(0, value);
return base::FormatDouble(value, 1);
}

} // namespace

OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
Expand Down Expand Up @@ -1583,7 +1541,7 @@ void OutOfProcessInstance::SendMetadata() {
const DocumentMetadata& document_metadata = engine()->GetDocumentMetadata();
pp::VarDictionary metadata_data;

std::u16string version = GetFormattedVersion(document_metadata.version);
std::u16string version = FormatPdfVersion(document_metadata.version);
if (!version.empty())
metadata_data.Set(pp::Var(kJSVersion), pp::Var(base::UTF16ToUTF8(version)));

Expand Down
2 changes: 1 addition & 1 deletion pdf/ui/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include_rules = [
]

specific_include_rules = {
"format_page_size_unittest.cc": [
"document_properties_unittest.cc": [
"+ui/base/resource",
],
}
4 changes: 0 additions & 4 deletions pdf/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@

This directory contains utilities for supporting PDF Viewer features other than
the main content area.

TODO(crbug.com/1184342): Accordingly move more code into this directory. For
instance, code that supports the document properties dialog belong in this
directory.
45 changes: 44 additions & 1 deletion pdf/ui/format_page_size.cc → pdf/ui/document_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "pdf/ui/format_page_size.h"
#include "pdf/ui/document_properties.h"

#include <string>

#include "base/check_op.h"
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "base/optional.h"
#include "components/strings/grit/components_strings.h"
#include "pdf/document_metadata.h"
#include "printing/units.h"
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -89,4 +91,45 @@ std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points) {
GetOrientation(size_points.value()));
}

std::u16string FormatPdfVersion(PdfVersion version) {
double value = 0;
switch (version) {
case PdfVersion::k1_0:
value = 1.0;
break;
case PdfVersion::k1_1:
value = 1.1;
break;
case PdfVersion::k1_2:
value = 1.2;
break;
case PdfVersion::k1_3:
value = 1.3;
break;
case PdfVersion::k1_4:
value = 1.4;
break;
case PdfVersion::k1_5:
value = 1.5;
break;
case PdfVersion::k1_6:
value = 1.6;
break;
case PdfVersion::k1_7:
value = 1.7;
break;
case PdfVersion::k2_0:
value = 2.0;
break;
case PdfVersion::kUnknown:
case PdfVersion::k1_8: // Not an actual version
return std::u16string();
}
// The default case is excluded from the above switch statement to ensure that
// all supported versions are determinantly handled.

DCHECK_NE(0, value);
return base::FormatDouble(value, 1);
}

} // namespace chrome_pdf
10 changes: 7 additions & 3 deletions pdf/ui/format_page_size.h → pdf/ui/document_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_UI_FORMAT_PAGE_SIZE_H_
#define PDF_UI_FORMAT_PAGE_SIZE_H_
#ifndef PDF_UI_DOCUMENT_PROPERTIES_H_
#define PDF_UI_DOCUMENT_PROPERTIES_H_

#include <string>

#include "base/optional.h"
#include "pdf/document_metadata.h"

namespace gfx {
class Size;
Expand All @@ -25,6 +26,9 @@ namespace chrome_pdf {
// Returns the string "Varies" if `size_points` is `base::nullopt`.
std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points);

// Formats `version` to a localized string suitable for display to a user.
std::u16string FormatPdfVersion(PdfVersion version);

} // namespace chrome_pdf

#endif // PDF_UI_FORMAT_PAGE_SIZE_H_
#endif // PDF_UI_DOCUMENT_PROPERTIES_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "pdf/ui/format_page_size.h"
#include "pdf/ui/document_properties.h"

#include <string>

Expand Down

0 comments on commit c5300c6

Please sign in to comment.