Skip to content

Commit

Permalink
Modernize blink::WebPrintPresetOptions
Browse files Browse the repository at this point in the history
- Remove the `page_ranges` field, which has no users.
- Use default values.
- Combine `is_page_size_uniform` into `uniform_page_size` by making the
  latter an `absl::optional`.

Bug: 1200000
Change-Id: Iea93e11191e7c1782cac4537bb355938e4548024
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2961654
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892448}
  • Loading branch information
Daniel Hosseinian authored and Chromium LUCI CQ committed Jun 15, 2021
1 parent 9131d2a commit 8f10b00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
8 changes: 4 additions & 4 deletions components/printing/renderer/print_render_frame_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bool PDFShouldDisableScalingBasedOnPreset(
if (options.is_scaling_disabled)
return true;

if (!options.is_page_size_uniform)
if (!options.uniform_page_size.has_value())
return false;

int dpi = GetDPI(params);
Expand Down Expand Up @@ -1771,12 +1771,12 @@ int PrintRenderFrameHelper::GetFitToPageScaleFactor(
if (!frame->GetPrintPresetOptionsForPlugin(node, &preset_options))
return 100;

if (!preset_options.is_page_size_uniform)
if (!preset_options.uniform_page_size.has_value())
return 0;

// Ensure we do not divide by 0 later.
const auto& uniform_page_size = preset_options.uniform_page_size;
if (uniform_page_size.width() == 0 || uniform_page_size.height() == 0)
const gfx::Size& uniform_page_size = preset_options.uniform_page_size.value();
if (uniform_page_size.IsEmpty())
return 0;

// Figure out if the sizes have the same orientation
Expand Down
9 changes: 5 additions & 4 deletions content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1928,10 +1928,11 @@ bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument(
break;
}
preset_options->copies = options.copies;
preset_options->is_page_size_uniform =
PP_ToBool(options.is_page_size_uniform);
preset_options->uniform_page_size = gfx::Size(
options.uniform_page_size.width, options.uniform_page_size.height);

if (options.is_page_size_uniform) {
preset_options->uniform_page_size = gfx::Size(
options.uniform_page_size.width, options.uniform_page_size.height);
}

return true;
}
Expand Down
31 changes: 6 additions & 25 deletions third_party/blink/public/web/web_print_preset_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,25 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_PRINT_PRESET_OPTIONS_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_PRINT_PRESET_OPTIONS_H_

#include <vector>

#include "printing/mojom/print.mojom-shared.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/size.h"

namespace blink {

struct WebPageRange;
typedef std::vector<WebPageRange> WebPageRanges;

struct WebPageRange {
int from;
int to;
};

struct WebPrintPresetOptions {
WebPrintPresetOptions()
: is_scaling_disabled(false),
copies(0),
duplex_mode(printing::mojom::DuplexMode::kUnknownDuplexMode) {}

// Specifies whether scaling is disabled.
bool is_scaling_disabled;
bool is_scaling_disabled = false;

// Specifies the number of copies to be printed.
int copies;
int copies = 0;

// Specifies duplex mode to be used for printing.
printing::mojom::DuplexMode duplex_mode;

// Specifies page range to be used for printing.
WebPageRanges page_ranges;

// True if all the pages in the PDF are the same size.
bool is_page_size_uniform;
printing::mojom::DuplexMode duplex_mode =
printing::mojom::DuplexMode::kUnknownDuplexMode;

// Only valid if the page sizes are uniform. The page size in points.
gfx::Size uniform_page_size;
absl::optional<gfx::Size> uniform_page_size;
};

} // namespace blink
Expand Down

0 comments on commit 8f10b00

Please sign in to comment.