[PDF Ink Signatures] Change CheckToolSizeIsInRange() to return a bool
Currently, PdfInkBrush::CheckToolSizeIsInRange() performs CHECKs internally to validate the tool size. This is convenient but does not give the caller the ability to handle a validation failure. Change CheckToolSizeIsInRange() to return a bool, and let the caller handle the failure. This will be useful in the near future when the PDF Viewer loads previously saved PDFs with Ink objects, where there is no guarantee that the Ink objects stored in PDFs are valid. With this behavior change, rename the method to IsToolSizeInRange(). Bug: 353942910 Change-Id: I51648bfd5c205f77467d3b51958afd647ddab7f7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5913948 Reviewed-by: Andy Phan <andyphan@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1365200}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7fe4e803bd
commit
1f8e332c41
@ -114,9 +114,8 @@ std::optional<PdfInkBrush::Type> PdfInkBrush::StringToType(
|
||||
}
|
||||
|
||||
// static
|
||||
void PdfInkBrush::CheckToolSizeIsInRange(float size) {
|
||||
CHECK_GE(size, 1);
|
||||
CHECK_LE(size, 16);
|
||||
bool PdfInkBrush::IsToolSizeInRange(float size) {
|
||||
return size >= 1 && size <= 16;
|
||||
}
|
||||
|
||||
PdfInkBrush::PdfInkBrush(Type brush_type, Params brush_params)
|
||||
|
@ -52,8 +52,8 @@ class PdfInkBrush {
|
||||
// does not correspond to any `Type`.
|
||||
static std::optional<Type> StringToType(const std::string& brush_type);
|
||||
|
||||
// Validates `size` is in range.
|
||||
static void CheckToolSizeIsInRange(float size);
|
||||
// Returns whether `size` is in range or not.
|
||||
static bool IsToolSizeInRange(float size);
|
||||
|
||||
// Returns the `ink::Brush` that `this` represents.
|
||||
const ink::Brush& GetInkBrush() const;
|
||||
|
@ -44,7 +44,7 @@ SkColor GetCursorOutlineColor(SkColor color) {
|
||||
} // namespace
|
||||
|
||||
int CursorDiameterFromBrushSizeAndZoom(float brush_size, float zoom) {
|
||||
PdfInkBrush::CheckToolSizeIsInRange(brush_size);
|
||||
CHECK(PdfInkBrush::IsToolSizeInRange(brush_size));
|
||||
|
||||
constexpr float kMinSize = 4; // Cursor become very hard to see if smaller.
|
||||
float cursor_diameter = std::max(brush_size * zoom, kMinSize);
|
||||
|
@ -14,8 +14,8 @@ static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");
|
||||
namespace chrome_pdf {
|
||||
|
||||
// Converts brush size into cursor diameter, for use with GenerateToolCursor().
|
||||
// `brush_size` must be in the range that passes the validation performed by
|
||||
// PdfInkBrush::CheckToolSizeIsInRange().
|
||||
// `brush_size` must be in the range that passes the validation performed with
|
||||
// PdfInkBrush::IsToolSizeInRange().
|
||||
int CursorDiameterFromBrushSizeAndZoom(float brush_size, float zoom);
|
||||
|
||||
// Draws a custom circular cursor to represent the brush/highlighter/eraser
|
||||
|
@ -600,7 +600,7 @@ void PdfInkModule::HandleSetAnnotationBrushMessage(
|
||||
CHECK(data);
|
||||
|
||||
float size = base::checked_cast<float>(data->FindDouble("size").value());
|
||||
PdfInkBrush::CheckToolSizeIsInRange(size);
|
||||
CHECK(PdfInkBrush::IsToolSizeInRange(size));
|
||||
|
||||
const std::string& brush_type_string = *data->FindString("type");
|
||||
if (brush_type_string == "eraser") {
|
||||
|
Reference in New Issue
Block a user